helpers.c: New function, printv()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-07-02 12:43:41 +02:00
parent cd947a69a8
commit cda5938215
3 changed files with 23 additions and 15 deletions
+4 -5
View File
@@ -153,7 +153,6 @@ int run_interactive(char *cmd, char *fmt, ...)
{
int status, oldout = 1, olderr = 2;
char line[LINE_SIZE];
va_list ap;
FILE *fp;
if (!cmd) {
@@ -162,11 +161,11 @@ int run_interactive(char *cmd, char *fmt, ...)
}
if (fmt) {
va_start(ap, fmt);
vsnprintf(line, sizeof(line), fmt, ap);
va_end(ap);
va_list ap;
print_desc("", line);
va_start(ap, fmt);
printv(fmt, ap);
va_end(ap);
}
/* Redirect output from cmd to a tempfile */
+18 -10
View File
@@ -77,31 +77,39 @@ static int print_timestamp(void)
return 0;
}
void print(int action, const char *fmt, ...)
void printv(const char *fmt, va_list ap)
{
char buf[80];
size_t len;
const char dots[] = " .....................................................................";
if (!fmt || log_is_silent())
return;
len = vsnprintf(buf, sizeof(buf), fmt, ap);
delline();
print_timestamp();
write(STDERR_FILENO, "\r", 1);
write(STDERR_FILENO, buf, len);
write(STDERR_FILENO, dots, 60 - len); /* pad with dots. */
}
void print(int action, const char *fmt, ...)
{
va_list ap;
const char success[] = " \e[1m[ OK ]\e[0m\n";
const char failure[] = " \e[7m[FAIL]\e[0m\n";
const char warning[] = " \e[7m[WARN]\e[0m\n";
const char pending[] = " \e[1m[ \\/ ]\e[0m\n";
const char dots[] = " .....................................................................";
if (log_is_silent())
return;
if (fmt) {
va_start(ap, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
printv(fmt, ap);
va_end(ap);
delline();
print_timestamp();
write(STDERR_FILENO, "\r", 1);
write(STDERR_FILENO, buf, len);
write(STDERR_FILENO, dots, 60 - len); /* pad with dots. */
}
switch (action) {
+1
View File
@@ -50,6 +50,7 @@ char *strip_line (char *line);
int pid_alive (pid_t pid);
char *pid_get_name (pid_t pid, char *name, size_t len);
void printv (const char *fmt, va_list ap);
void print (int action, const char *fmt, ...);
void print_desc (char *action, char *desc);
int print_result (int fail);