cmdutils: declare only one pointer type in OptionDef

This will be useful in the following commit.
pull/2/head
Anton Khirnov 14 years ago
parent cac651c834
commit 7efe05ab29
  1. 12
      cmdutils.c
  2. 5
      cmdutils.h

@ -216,6 +216,7 @@ void parse_options(int argc, char **argv, const OptionDef *options,
/* parse options */ /* parse options */
optindex = 1; optindex = 1;
while (optindex < argc) { while (optindex < argc) {
void *dst;
opt = argv[optindex++]; opt = argv[optindex++];
if (handleoptions && opt[0] == '-' && opt[1] != '\0') { if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
@ -248,18 +249,19 @@ unknown_opt:
exit_program(1); exit_program(1);
} }
} }
dst = po->u.dst_ptr;
if (po->flags & OPT_STRING) { if (po->flags & OPT_STRING) {
char *str; char *str;
str = av_strdup(arg); str = av_strdup(arg);
*po->u.str_arg = str; *(char**)dst = str;
} else if (po->flags & OPT_BOOL) { } else if (po->flags & OPT_BOOL) {
*po->u.int_arg = bool_val; *(int*)dst = bool_val;
} else if (po->flags & OPT_INT) { } else if (po->flags & OPT_INT) {
*po->u.int_arg = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); *(int*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
} else if (po->flags & OPT_INT64) { } else if (po->flags & OPT_INT64) {
*po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); *(int64_t*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
} else if (po->flags & OPT_FLOAT) { } else if (po->flags & OPT_FLOAT) {
*po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); *(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
} else if (po->u.func_arg) { } else if (po->u.func_arg) {
if (po->u.func_arg(opt, arg) < 0) { if (po->u.func_arg(opt, arg) < 0) {
fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt); fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);

@ -125,11 +125,8 @@ typedef struct {
#define OPT_EXIT 0x0800 #define OPT_EXIT 0x0800
#define OPT_DATA 0x1000 #define OPT_DATA 0x1000
union { union {
int *int_arg; void *dst_ptr;
char **str_arg;
float *float_arg;
int (*func_arg)(const char *, const char *); int (*func_arg)(const char *, const char *);
int64_t *int64_arg;
} u; } u;
const char *help; const char *help;
const char *argname; const char *argname;

Loading…
Cancel
Save