From 901a3ba023fd64e29309637f5ad835218e1bb2ac Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Mon, 14 May 2012 22:54:58 +0000 Subject: Convert printf to msg_* where appropriate Clean up cli_output.c to be more readable. Use enum instead of #define for message levels. Kill a few exit(0) calls. Print the command line arguments in verbose mode. Move actions (--list-supported etc.) after argument sanity checks. Reduce the number of code paths which have their own programmer_shutdown(). Corresponding to flashrom svn r1536. Signed-off-by: Carl-Daniel Hailfinger Acked-by: Stefan Tauner --- cli_output.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'cli_output.c') diff --git a/cli_output.c b/cli_output.c index 2a67bea..231f2a8 100644 --- a/cli_output.c +++ b/cli_output.c @@ -22,34 +22,25 @@ #include #include "flash.h" -int print(int type, const char *fmt, ...) +/* Please note that level is the verbosity, not the importance of the message. */ +int print(enum msglevel level, const char *fmt, ...) { va_list ap; - int ret; - FILE *output_type; + int ret = 0; + FILE *output_type = stdout; - switch (type) { - case MSG_ERROR: + if (level == MSG_ERROR) output_type = stderr; - break; - case MSG_BARF: - if (verbose < 3) - return 0; - case MSG_DEBUG2: - if (verbose < 2) - return 0; - case MSG_DEBUG: - if (verbose < 1) - return 0; - case MSG_INFO: - default: - output_type = stdout; - break; - } - va_start(ap, fmt); - ret = vfprintf(output_type, fmt, ap); - va_end(ap); - fflush(output_type); + if (level <= verbose) { + va_start(ap, fmt); + ret = vfprintf(output_type, fmt, ap); + va_end(ap); + /* msg_*spew usually happens inside chip accessors in possibly + * time-critical operations. Don't slow them down by flushing. + */ + if (level != MSG_SPEW) + fflush(output_type); + } return ret; } -- cgit v1.1