aboutsummaryrefslogtreecommitdiffstats
path: root/cmdutils.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-08-28 14:43:54 +0200
committerAnton Khirnov <anton@khirnov.net>2011-09-04 13:12:00 +0200
commit7cc8d6385aaf1005700305f21d5d56b51b38c537 (patch)
tree73aff2665f8eef3fb60f7babe7403692f3d67b0f /cmdutils.c
parent7efe05ab298ae18437c9796f43b9f47474763a39 (diff)
downloadffmpeg-7cc8d6385aaf1005700305f21d5d56b51b38c537.tar.gz
cmdutils: add support for caller-provided option context.
This is the first step to removing the globals plague from avtools.
Diffstat (limited to 'cmdutils.c')
-rw-r--r--cmdutils.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/cmdutils.c b/cmdutils.c
index 53ef7aed3c..ea25836f8f 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -203,8 +203,8 @@ static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
}
#endif /* WIN32 && !__MINGW32CE__ */
-void parse_options(int argc, char **argv, const OptionDef *options,
- void (* parse_arg_function)(const char*))
+void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
+ void (* parse_arg_function)(void *, const char*))
{
const char *opt, *arg;
int optindex, handleoptions=1;
@@ -249,7 +249,9 @@ unknown_opt:
exit_program(1);
}
}
- dst = po->u.dst_ptr;
+ /* new-style options contain an offset into optctx, old-style address of
+ * a global var*/
+ dst = po->flags & OPT_OFFSET ? (uint8_t*)optctx + po->u.off : po->u.dst_ptr;
if (po->flags & OPT_STRING) {
char *str;
str = av_strdup(arg);
@@ -263,7 +265,9 @@ unknown_opt:
} else if (po->flags & OPT_FLOAT) {
*(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
} else if (po->u.func_arg) {
- if (po->u.func_arg(opt, arg) < 0) {
+ int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) :
+ po->u.func_arg(opt, arg);
+ if (ret < 0) {
fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
exit_program(1);
}
@@ -272,7 +276,7 @@ unknown_opt:
exit_program(0);
} else {
if (parse_arg_function)
- parse_arg_function(opt);
+ parse_arg_function(optctx, opt);
}
}
}