diff options
author | Guillem Jover <guillem@debian.org> | 2018-10-26 09:44:16 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2019-01-15 04:49:02 +0100 |
commit | 2d5b58849369c7d27be2f4271ff9e8d96a773288 (patch) | |
tree | 78deb5b64a218ad7a36f29dbda8d8744ddf325bf | |
parent | 1a18c981857ab0e635907f83c4a63765a25aa96b (diff) | |
download | dpkg-2d5b58849369c7d27be2f4271ff9e8d96a773288.tar.gz |
u-a: Switch verbose selection into an enum
This makes the values and comparisons immediately clear.
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | utils/update-alternatives.c | 18 |
2 files changed, 13 insertions, 6 deletions
diff --git a/debian/changelog b/debian/changelog index 1eba3f45f..b3c86a11e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -68,6 +68,7 @@ dpkg (1.19.3) UNRELEASED; urgency=medium like a boolean. - start-stop-daemon: Switch code to use new info() and debug() functions. - update-alternatives: Use enums for actions instead of strings. + - update-alternatives: Switch verbose selection into an enum. * Build system: - get-version: Use a format string with printf. - run-script: Use $() instead of deprecated ``. diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c index c943f6e4f..61e07bc8f 100644 --- a/utils/update-alternatives.c +++ b/utils/update-alternatives.c @@ -90,12 +90,18 @@ struct action_name { { ACTION_DISPLAY, "display" }, }; +enum output_mode { + OUTPUT_QUIET = -1, + OUTPUT_NORMAL = 0, + OUTPUT_VERBOSE = 1, +}; + /* Action to perform */ static enum action action = ACTION_NONE; static const char *log_file = LOGDIR "/alternatives.log"; /* Skip alternatives properly configured in auto mode (for --config) */ static int opt_skip_auto = 0; -static int opt_verbose = 0; +static int opt_verbose = OUTPUT_NORMAL; static int opt_force = 0; /* @@ -212,7 +218,7 @@ warning(char const *fmt, ...) { va_list args; - if (opt_verbose < 0) + if (opt_verbose < OUTPUT_NORMAL) return; fprintf(stderr, "%s: %s: ", PROGNAME, _("warning")); @@ -241,7 +247,7 @@ verbose(char const *fmt, ...) { va_list args; - if (opt_verbose < 1) + if (opt_verbose < OUTPUT_VERBOSE) return; printf("%s: ", PROGNAME); @@ -256,7 +262,7 @@ info(char const *fmt, ...) { va_list args; - if (opt_verbose < 0) + if (opt_verbose < OUTPUT_NORMAL) return; printf("%s: ", PROGNAME); @@ -2630,9 +2636,9 @@ main(int argc, char **argv) version(); exit(0); } else if (strcmp("--verbose", argv[i]) == 0) { - opt_verbose++; + opt_verbose = OUTPUT_VERBOSE; } else if (strcmp("--quiet", argv[i]) == 0) { - opt_verbose--; + opt_verbose = OUTPUT_QUIET; } else if (strcmp("--install", argv[i]) == 0) { char *prio_str, *prio_end; long prio; |