This is the first step to removing the globals plague from avtools.
return 0;
}
-static void opt_output_file(const char *filename)
+static void opt_output_file(void *optctx, const char *filename)
{
AVFormatContext *oc;
int i, err;
show_banner();
/* parse options */
- parse_options(argc, argv, options, opt_output_file);
+ parse_options(NULL, argc, argv, options, opt_output_file);
if(nb_output_files <= 0 && nb_input_files == 0) {
show_usage();
);
}
-static void opt_input_file(const char *filename)
+static void opt_input_file(void *optctx, const char *filename)
{
if (input_filename) {
fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
show_banner();
- parse_options(argc, argv, options, opt_input_file);
+ parse_options(NULL, argc, argv, options, opt_input_file);
if (!input_filename) {
show_usage();
return 0;
}
-static void opt_input_file(const char *arg)
+static void opt_input_file(void *optctx, const char *arg)
{
if (input_filename) {
fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
#endif
show_banner();
- parse_options(argc, argv, options, opt_input_file);
+ parse_options(NULL, argc, argv, options, opt_input_file);
if (!input_filename) {
show_usage();
my_program_dir = getcwd(0, 0);
avserver_daemon = 1;
- parse_options(argc, argv, options, NULL);
+ parse_options(NULL, argc, argv, options, NULL);
unsetenv("http_proxy"); /* Kill the http_proxy */
}
#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;
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);
} 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);
}
exit_program(0);
} else {
if (parse_arg_function)
- parse_arg_function(opt);
+ parse_arg_function(optctx, opt);
}
}
}
#define OPT_INT64 0x0400
#define OPT_EXIT 0x0800
#define OPT_DATA 0x1000
+#define OPT_FUNC2 0x2000
+#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
union {
void *dst_ptr;
int (*func_arg)(const char *, const char *);
+ int (*func2_arg)(void *, const char *, const char *);
+ size_t off;
} u;
const char *help;
const char *argname;
/**
* Parse the command line arguments.
+ *
+ * @param optctx an opaque options context
* @param options Array with the definitions required to interpret every
* option of the form: -option_name [argument]
* @param parse_arg_function Name of the function called to process every
* argument without a leading option name flag. NULL if such arguments do
* not have to be processed.
*/
-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 *optctx, const char*));
/**
* Check if the given stream matches a stream specifier.
return 0;
}
-static void opt_output_file(const char *filename)
+static void opt_output_file(void *optctx, const char *filename)
{
AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle, use_data;
"(see Changelog for the list of incompatible changes).\n");
/* parse options */
- parse_options(argc, argv, options, opt_output_file);
+ parse_options(NULL, argc, argv, options, opt_output_file);
if(nb_output_files <= 0 && nb_input_files == 0) {
show_usage();