| 115 | } |
| 116 | |
| 117 | void parse_options(int argc, char **argv, const OptionDef *options, |
| 118 | void (* parse_arg_function)(const char*)) |
| 119 | { |
| 120 | const char *opt, *arg; |
| 121 | int optindex, handleoptions=1; |
| 122 | const OptionDef *po; |
| 123 | |
| 124 | /* parse options */ |
| 125 | optindex = 1; |
| 126 | while (optindex < argc) { |
| 127 | opt = argv[optindex++]; |
| 128 | |
| 129 | if (handleoptions && opt[0] == '-' && opt[1] != '\0') { |
| 130 | int bool_val = 1; |
| 131 | if (opt[1] == '-' && opt[2] == '\0') { |
| 132 | handleoptions = 0; |
| 133 | continue; |
| 134 | } |
| 135 | opt++; |
| 136 | po= find_option(options, opt); |
| 137 | if (!po->name && opt[0] == 'n' && opt[1] == 'o') { |
| 138 | /* handle 'no' bool option */ |
| 139 | po = find_option(options, opt + 2); |
| 140 | if (!(po->name && (po->flags & OPT_BOOL))) |
| 141 | goto unknown_opt; |
| 142 | bool_val = 0; |
| 143 | } |
| 144 | if (!po->name) |
| 145 | po= find_option(options, "default"); |
| 146 | if (!po->name) { |
| 147 | unknown_opt: |
| 148 | fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt); |
| 149 | exit(1); |
| 150 | } |
| 151 | arg = NULL; |
| 152 | if (po->flags & HAS_ARG) { |
| 153 | arg = argv[optindex++]; |
| 154 | if (!arg) { |
| 155 | fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt); |
| 156 | exit(1); |
| 157 | } |
| 158 | } |
| 159 | if (po->flags & OPT_STRING) { |
| 160 | char *str; |
| 161 | str = av_strdup(arg); |
| 162 | *po->u.str_arg = str; |
| 163 | } else if (po->flags & OPT_BOOL) { |
| 164 | *po->u.int_arg = bool_val; |
| 165 | } else if (po->flags & OPT_INT) { |
| 166 | *po->u.int_arg = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); |
| 167 | } else if (po->flags & OPT_INT64) { |
| 168 | *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); |
| 169 | } else if (po->flags & OPT_FLOAT) { |
| 170 | *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -1.0/0.0, 1.0/0.0); |
| 171 | } else if (po->flags & OPT_FUNC2) { |
| 172 | if (po->u.func2_arg(opt, arg) < 0) { |
| 173 | fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt); |
| 174 | exit(1); |
no test coverage detected