void parse_options(int argc, char **argv, const OptionDef *options,
                   void (* parse_arg_function)(const char*))
{
    const char *opt, *arg;
    int optindex, handleoptions=1;
    const OptionDef *po;
    optindex = 1;
    while (optindex < argc) {
        opt = argv[optindex++];
        if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
            if (opt[1] == '-' && opt[2] == '\0') {
                handleoptions = 0;
                continue;
            }
            po= find_option(options, opt + 1);
            if (!po->name)
                po= find_option(options, "default");
            if (!po->name) {
unknown_opt:
                fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
                exit(1);
            }
            arg = NULL;
            if (po->flags & HAS_ARG) {
                arg = argv[optindex++];
                if (!arg) {
                    fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
                    exit(1);
                }
            }
            if (po->flags & OPT_STRING) {
                char *str;
                str = av_strdup(arg);
                *po->u.str_arg = str;
            } else if (po->flags & OPT_BOOL) {
                *po->u.int_arg = 1;
            } else if (po->flags & OPT_INT) {
                *po->u.int_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT_MIN, INT_MAX);
            } else if (po->flags & OPT_INT64) {
                *po->u.int64_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT64_MIN, INT64_MAX);
            } else if (po->flags & OPT_FLOAT) {
                *po->u.float_arg = parse_number_or_die(opt+1, arg, OPT_FLOAT, -1.0/0.0, 1.0/0.0);
            } else if (po->flags & OPT_FUNC2) {
                if(po->u.func2_arg(opt+1, arg)<0)
                    goto unknown_opt;
            } else {
                po->u.func_arg(arg);
            }
            if(po->flags & OPT_EXIT)
                exit(0);
        } else {
            if (parse_arg_function)
                parse_arg_function(opt);
        }
    }
}
['void parse_options(int argc, char **argv, const OptionDef *options,\n                   void (* parse_arg_function)(const char*))\n{\n    const char *opt, *arg;\n    int optindex, handleoptions=1;\n    const OptionDef *po;\n    optindex = 1;\n    while (optindex < argc) {\n        opt = argv[optindex++];\n        if (handleoptions && opt[0] == \'-\' && opt[1] != \'\\0\') {\n            if (opt[1] == \'-\' && opt[2] == \'\\0\') {\n                handleoptions = 0;\n                continue;\n            }\n            po= find_option(options, opt + 1);\n            if (!po->name)\n                po= find_option(options, "default");\n            if (!po->name) {\nunknown_opt:\n                fprintf(stderr, "%s: unrecognized option \'%s\'\\n", argv[0], opt);\n                exit(1);\n            }\n            arg = NULL;\n            if (po->flags & HAS_ARG) {\n                arg = argv[optindex++];\n                if (!arg) {\n                    fprintf(stderr, "%s: missing argument for option \'%s\'\\n", argv[0], opt);\n                    exit(1);\n                }\n            }\n            if (po->flags & OPT_STRING) {\n                char *str;\n                str = av_strdup(arg);\n                *po->u.str_arg = str;\n            } else if (po->flags & OPT_BOOL) {\n                *po->u.int_arg = 1;\n            } else if (po->flags & OPT_INT) {\n                *po->u.int_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT_MIN, INT_MAX);\n            } else if (po->flags & OPT_INT64) {\n                *po->u.int64_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT64_MIN, INT64_MAX);\n            } else if (po->flags & OPT_FLOAT) {\n                *po->u.float_arg = parse_number_or_die(opt+1, arg, OPT_FLOAT, -1.0/0.0, 1.0/0.0);\n            } else if (po->flags & OPT_FUNC2) {\n                if(po->u.func2_arg(opt+1, arg)<0)\n                    goto unknown_opt;\n            } else {\n                po->u.func_arg(arg);\n            }\n            if(po->flags & OPT_EXIT)\n                exit(0);\n        } else {\n            if (parse_arg_function)\n                parse_arg_function(opt);\n        }\n    }\n}', 'double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)\n{\n    char *tail;\n    const char *error;\n    double d = strtod(numstr, &tail);\n    if (*tail)\n        error= "Expected number for %s but found: %s\\n";\n    else if (d < min || d > max)\n        error= "The value for %s was %s which is not within %f - %f\\n";\n    else if(type == OPT_INT64 && (int64_t)d != d)\n        error= "Expected int64 for %s but found %s\\n";\n    else\n        return d;\n    fprintf(stderr, error, context, numstr, min, max);\n    exit(1);\n}']