From 182cbe433aea20b0d9627d40de7c75713ec736db Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 26 Sep 2011 08:15:37 +0200 Subject: avtools: parse loglevel before all the other options. This way it can be applied to cmdutils too -- e.g. showing the banner and printing startup messages. --- cmdutils.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'cmdutils.c') diff --git a/cmdutils.c b/cmdutils.c index b6ed475fba..2b2fea827e 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -304,6 +304,41 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options } } +/* + * Return index of option opt in argv or 0 if not found. + */ +static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname) +{ + const OptionDef *po; + int i; + + for (i = 1; i < argc; i++) { + const char *cur_opt = argv[i]; + + if (*cur_opt++ != '-') + continue; + + po = find_option(options, cur_opt); + if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o') + po = find_option(options, cur_opt + 2); + + if ((!po->name && !strcmp(cur_opt, optname)) || + (po->name && !strcmp(optname, po->name))) + return i; + + if (!po || po->flags & HAS_ARG) + i++; + } + return 0; +} + +void parse_loglevel(int argc, char **argv, const OptionDef *options) +{ + int idx = locate_option(argc, argv, options, "loglevel"); + if (idx && argv[idx + 1]) + opt_loglevel("loglevel", argv[idx + 1]); +} + #define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 int opt_default(const char *opt, const char *arg) { -- cgit v1.2.3