diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2012-05-14 22:54:58 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2012-05-14 22:54:58 +0000 |
commit | 901a3ba023fd64e29309637f5ad835218e1bb2ac (patch) | |
tree | d0f024b5f8820e6bfdba5d599c607859e2f15a0d /cli_output.c | |
parent | 2cef9164ef1e35e4d1f347ff58722104e8143454 (diff) | |
download | flashrom-git-901a3ba023fd64e29309637f5ad835218e1bb2ac.tar.gz |
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 <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'cli_output.c')
-rw-r--r-- | cli_output.c | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/cli_output.c b/cli_output.c index 2a67bea2..231f2a80 100644 --- a/cli_output.c +++ b/cli_output.c @@ -22,34 +22,25 @@ #include <stdarg.h> #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; } |