Skip to content

Commit

Permalink
cmdutils: remove OPT_FUNC2
Browse files Browse the repository at this point in the history
Make ff* tools only accept opt_* functions taking two arguments.

The distinction between functions with one and two arguments is quite
pointless. Simplify parse_options() code.
  • Loading branch information
Stefano Sabatini committed May 28, 2011
1 parent 78046da commit eb8bc57
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 133 deletions.
10 changes: 4 additions & 6 deletions cmdutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@ void parse_options(int argc, char **argv, const OptionDef *options,
*po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
} else if (po->flags & OPT_FLOAT) {
*po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
} else if (po->flags & OPT_FUNC2) {
if (po->u.func2_arg(opt, arg) < 0) {
fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
exit(1);
}
} else if (po->flags & OPT_DUMMY) {
/* Do nothing for this option */
} else {
po->u.func_arg(arg);
if (po->u.func_arg(opt, arg) < 0) {
fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
exit(1);
}
}
if(po->flags & OPT_EXIT)
exit(0);
Expand Down
12 changes: 5 additions & 7 deletions cmdutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,15 @@ typedef struct {
#define OPT_INT 0x0080
#define OPT_FLOAT 0x0100
#define OPT_SUBTITLE 0x0200
#define OPT_FUNC2 0x0400
#define OPT_INT64 0x0800
#define OPT_EXIT 0x1000
#define OPT_DATA 0x2000
#define OPT_DUMMY 0x4000
#define OPT_INT64 0x0400
#define OPT_EXIT 0x0800
#define OPT_DATA 0x1000
#define OPT_DUMMY 0x2000
union {
void (*func_arg)(const char *); //FIXME passing error code as int return would be nicer then exit() in the func
int *int_arg;
char **str_arg;
float *float_arg;
int (*func2_arg)(const char *, const char *);
int (*func_arg)(const char *, const char *);
int64_t *int64_arg;
} u;
const char *help;
Expand Down
2 changes: 1 addition & 1 deletion cmdutils_common_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
{ "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" },
{ "filters", OPT_EXIT, {(void*)show_filters }, "show available filters" },
{ "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel formats" },
{ "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
{ "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
Loading

0 comments on commit eb8bc57

Please sign in to comment.