From 774bb252aa0bda6a6ef927cd9287b0a6c01da0e6 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sun, 3 Jul 2011 15:42:04 +0300 Subject: cosmetics: reformat demux_lavf.c, m_option.[ch] and m_property.c --- m_option.c | 3651 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 1908 insertions(+), 1743 deletions(-) (limited to 'm_option.c') diff --git a/m_option.c b/m_option.c index 2fe53f5f17..c0fd8b43b0 100644 --- a/m_option.c +++ b/m_option.c @@ -40,185 +40,204 @@ //#define NO_FREE #endif -const m_option_t* m_option_list_find(const m_option_t* list,const char* name) { - int i; - - for(i = 0 ; list[i].name ; i++) { - int l = strlen(list[i].name) - 1; - if((list[i].type->flags & M_OPT_TYPE_ALLOW_WILDCARD) && - (l > 0) && (list[i].name[l] == '*')) { - if(strncasecmp(list[i].name,name,l) == 0) - return &list[i]; - } else if(strcasecmp(list[i].name,name) == 0) - return &list[i]; - } - return NULL; +const m_option_t *m_option_list_find(const m_option_t *list, const char *name) +{ + int i; + + for (i = 0; list[i].name; i++) { + int l = strlen(list[i].name) - 1; + if ((list[i].type->flags & M_OPT_TYPE_ALLOW_WILDCARD) + && (l > 0) && (list[i].name[l] == '*')) { + if (strncasecmp(list[i].name, name, l) == 0) + return &list[i]; + } else if (strcasecmp(list[i].name, name) == 0) + return &list[i]; + } + return NULL; } // Default function that just does a memcpy -static void copy_opt(const m_option_t* opt,void* dst,const void* src) { - if(dst && src) - memcpy(dst,src,opt->type->size); +static void copy_opt(const m_option_t *opt, void *dst, const void *src) +{ + if (dst && src) + memcpy(dst, src, opt->type->size); } // Helper for the print funcs (from man printf) -static char* dup_printf(const char *fmt, ...) { - /* Guess we need no more than 50 bytes. */ - int n, size = 50; - char *p; - va_list ap; - if ((p = malloc (size)) == NULL) - return NULL; - while (1) { - /* Try to print in the allocated space. */ - va_start(ap, fmt); - n = vsnprintf (p, size, fmt, ap); - va_end(ap); - /* If that worked, return the string. */ - if (n > -1 && n < size) - return p; - /* Else try again with more space. */ - if (n > -1) /* glibc 2.1 */ - size = n+1; /* precisely what is needed */ - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ - if ((p = realloc (p, size)) == NULL) - return NULL; - } +static char *dup_printf(const char *fmt, ...) +{ + /* Guess we need no more than 50 bytes. */ + int n, size = 50; + char *p; + va_list ap; + if ((p = malloc(size)) == NULL) + return NULL; + while (1) { + /* Try to print in the allocated space. */ + va_start(ap, fmt); + n = vsnprintf(p, size, fmt, ap); + va_end(ap); + /* If that worked, return the string. */ + if (n > -1 && n < size) + return p; + /* Else try again with more space. */ + if (n > -1) /* glibc 2.1 */ + size = n + 1; /* precisely what is needed */ + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ + if ((p = realloc(p, size)) == NULL) + return NULL; + } } // Flag -#define VAL(x) (*(int*)(x)) - -static int parse_flag(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - if (src == M_CONFIG_FILE) { - if(!param) return M_OPT_MISSING_PARAM; - if (!strcasecmp(param, "yes") || /* any other language? */ - !strcasecmp(param, "on") || - !strcasecmp(param, "ja") || - !strcasecmp(param, "si") || - !strcasecmp(param, "igen") || - !strcasecmp(param, "y") || - !strcasecmp(param, "j") || - !strcasecmp(param, "i") || - !strcasecmp(param, "tak") || - !strcasecmp(param, "ja") || - !strcasecmp(param, "true") || - !strcmp(param, "1")) { - if(dst) VAL(dst) = opt->max; - } else if (!strcasecmp(param, "no") || - !strcasecmp(param, "off") || - !strcasecmp(param, "nein") || - !strcasecmp(param, "nicht") || - !strcasecmp(param, "nem") || - !strcasecmp(param, "n") || - !strcasecmp(param, "nie") || - !strcasecmp(param, "nej") || - !strcasecmp(param, "false") || - !strcmp(param, "0")) { - if(dst) VAL(dst) = opt->min; +#define VAL(x) (*(int *)(x)) + +static int parse_flag(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + if (src == M_CONFIG_FILE) { + if (!param) + return M_OPT_MISSING_PARAM; + if (!strcasecmp(param, "yes") || /* any other language? */ + !strcasecmp(param, "on") || + !strcasecmp(param, "ja") || + !strcasecmp(param, "si") || + !strcasecmp(param, "igen") || + !strcasecmp(param, "y") || + !strcasecmp(param, "j") || + !strcasecmp(param, "i") || + !strcasecmp(param, "tak") || + !strcasecmp(param, "ja") || + !strcasecmp(param, "true") || + !strcmp(param, "1")) { + if (dst) + VAL(dst) = opt->max; + } else if (!strcasecmp(param, "no") || + !strcasecmp(param, "off") || + !strcasecmp(param, "nein") || + !strcasecmp(param, "nicht") || + !strcasecmp(param, "nem") || + !strcasecmp(param, "n") || + !strcasecmp(param, "nie") || + !strcasecmp(param, "nej") || + !strcasecmp(param, "false") || + !strcmp(param, "0")) { + if (dst) + VAL(dst) = opt->min; + } else { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Invalid parameter for %s flag: %s\n", name, param); + return M_OPT_INVALID; + } + return 1; } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid parameter for %s flag: %s\n",name, param); - return M_OPT_INVALID; + if (dst) + VAL(dst) = opt->max; + return 0; } - return 1; - } else { - if(dst) VAL(dst) = opt->max; - return 0; - } } -static char* print_flag(const m_option_t* opt, const void* val) { - if(VAL(val) == opt->min) - return strdup("no"); - else - return strdup("yes"); +static char *print_flag(const m_option_t *opt, const void *val) +{ + if (VAL(val) == opt->min) + return strdup("no"); + else + return strdup("yes"); } const m_option_type_t m_option_type_flag = { - "Flag", - "need yes or no in config files", - sizeof(int), - 0, - parse_flag, - print_flag, - copy_opt, - copy_opt, - NULL, - NULL + "Flag", + "need yes or no in config files", + sizeof(int), + 0, + parse_flag, + print_flag, + copy_opt, + copy_opt, + NULL, + NULL }; // Integer -static int parse_int(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - long long tmp_int; - char *endptr; - src = 0; +static int parse_int(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + long long tmp_int; + char *endptr; + src = 0; - if (param == NULL) - return M_OPT_MISSING_PARAM; + if (param == NULL) + return M_OPT_MISSING_PARAM; - tmp_int = strtoll(param, &endptr, 10); - if (*endptr) - tmp_int = strtoll(param, &endptr, 0); - if (*endptr) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be an integer: %s\n",name, param); - return M_OPT_INVALID; - } + tmp_int = strtoll(param, &endptr, 10); + if (*endptr) + tmp_int = strtoll(param, &endptr, 0); + if (*endptr) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be an integer: %s\n", name, param); + return M_OPT_INVALID; + } - if ((opt->flags & M_OPT_MIN) && (tmp_int < opt->min)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be >= %d: %s\n", name, (int) opt->min, param); - return M_OPT_OUT_OF_RANGE; - } + if ((opt->flags & M_OPT_MIN) && (tmp_int < opt->min)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be >= %d: %s\n", + name, (int) opt->min, param); + return M_OPT_OUT_OF_RANGE; + } - if ((opt->flags & M_OPT_MAX) && (tmp_int > opt->max)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be <= %d: %s\n",name, (int) opt->max, param); - return M_OPT_OUT_OF_RANGE; - } + if ((opt->flags & M_OPT_MAX) && (tmp_int > opt->max)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be <= %d: %s\n", + name, (int) opt->max, param); + return M_OPT_OUT_OF_RANGE; + } - if(dst) { - if (opt->type->size == sizeof(int64_t)) - *(int64_t *)dst = tmp_int; - else - VAL(dst) = tmp_int; - } + if (dst) { + if (opt->type->size == sizeof(int64_t)) + *(int64_t *)dst = tmp_int; + else + VAL(dst) = tmp_int; + } - return 1; + return 1; } -static char* print_int(const m_option_t* opt, const void* val) { - if (opt->type->size == sizeof(int64_t)) - return dup_printf("%"PRId64, *(const int64_t *)val); - return dup_printf("%d",VAL(val)); +static char *print_int(const m_option_t *opt, const void *val) +{ + if (opt->type->size == sizeof(int64_t)) + return dup_printf("%"PRId64, *(const int64_t *)val); + return dup_printf("%d", VAL(val)); } const m_option_type_t m_option_type_int = { - "Integer", - "", - sizeof(int), - 0, - parse_int, - print_int, - copy_opt, - copy_opt, - NULL, - NULL + "Integer", + "", + sizeof(int), + 0, + parse_int, + print_int, + copy_opt, + copy_opt, + NULL, + NULL }; const m_option_type_t m_option_type_int64 = { - "Integer64", - "", - sizeof(int64_t), - 0, - parse_int, - print_int, - copy_opt, - copy_opt, - NULL, - NULL + "Integer64", + "", + sizeof(int64_t), + 0, + parse_int, + print_int, + copy_opt, + copy_opt, + NULL, + NULL }; static int parse_intpair(const struct m_option *opt, const char *name, @@ -253,7 +272,7 @@ static int parse_intpair(const struct m_option *opt, const char *name, return 1; - bad: +bad: mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid integer range " "specification for option %s: %s\n", name, param); return M_OPT_INVALID; @@ -292,7 +311,7 @@ static int parse_choice(const struct m_option *opt, const char *name, return 1; } -static char *print_choice(const m_option_t *opt, const void *val) +static char *print_choice(const m_option_t *opt, const void *val) { int v = *(int *)val; struct m_opt_choice_alternatives *alt; @@ -314,229 +333,251 @@ const struct m_option_type m_option_type_choice = { // Float #undef VAL -#define VAL(x) (*(double*)(x)) - -static int parse_double(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - double tmp_float; - char* endptr; - src = 0; - - if (param == NULL) - return M_OPT_MISSING_PARAM; - - tmp_float = strtod(param, &endptr); - - switch(*endptr) { - case ':': - case '/': - tmp_float /= strtod(endptr+1, &endptr); - break; - case '.': - case ',': - /* we also handle floats specified with - * non-locale decimal point ::atmos - */ - if(tmp_float<0) - tmp_float -= 1.0/pow(10,strlen(endptr+1)) * strtod(endptr+1, &endptr); - else - tmp_float += 1.0/pow(10,strlen(endptr+1)) * strtod(endptr+1, &endptr); - break; - } +#define VAL(x) (*(double *)(x)) - if (*endptr) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be a floating point " - "number or a ratio (numerator[:/]denominator): %s\n",name, param); - return M_OPT_INVALID; - } +static int parse_double(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + double tmp_float; + char *endptr; + src = 0; + + if (param == NULL) + return M_OPT_MISSING_PARAM; - if (opt->flags & M_OPT_MIN) - if (tmp_float < opt->min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be >= %f: %s\n", name, opt->min, param); - return M_OPT_OUT_OF_RANGE; + tmp_float = strtod(param, &endptr); + + switch (*endptr) { + case ':': + case '/': + tmp_float /= strtod(endptr + 1, &endptr); + break; + case '.': + case ',': + /* we also handle floats specified with + * non-locale decimal point ::atmos + */ + if (tmp_float < 0) + tmp_float -= 1.0 / pow(10, strlen(endptr + 1)) * + strtod(endptr + 1, &endptr); + else + tmp_float += 1.0 / pow(10, strlen(endptr + 1)) * + strtod(endptr + 1, &endptr); + break; } - if (opt->flags & M_OPT_MAX) - if (tmp_float > opt->max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be <= %f: %s\n", name, opt->max, param); - return M_OPT_OUT_OF_RANGE; + if (*endptr) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be a floating point number or a " + "ratio (numerator[:/]denominator): %s\n", name, param); + return M_OPT_INVALID; } - if(dst) VAL(dst) = tmp_float; - return 1; + if (opt->flags & M_OPT_MIN) + if (tmp_float < opt->min) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be >= %f: %s\n", name, opt->min, param); + return M_OPT_OUT_OF_RANGE; + } + + if (opt->flags & M_OPT_MAX) + if (tmp_float > opt->max) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be <= %f: %s\n", name, opt->max, param); + return M_OPT_OUT_OF_RANGE; + } + + if (dst) + VAL(dst) = tmp_float; + return 1; } -static char* print_double(const m_option_t* opt, const void* val) { - opt = NULL; - return dup_printf("%f",VAL(val)); +static char *print_double(const m_option_t *opt, const void *val) +{ + opt = NULL; + return dup_printf("%f", VAL(val)); } const m_option_type_t m_option_type_double = { - "Double", - "double precision floating point number or ratio (numerator[:/]denominator)", - sizeof(double), - 0, - parse_double, - print_double, - copy_opt, - copy_opt, - NULL, - NULL + "Double", + "double precision floating point number or ratio (numerator[:/]denominator)", + sizeof(double), + 0, + parse_double, + print_double, + copy_opt, + copy_opt, + NULL, + NULL }; #undef VAL -#define VAL(x) (*(float*)(x)) +#define VAL(x) (*(float *)(x)) -static int parse_float(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { +static int parse_float(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ double tmp; - int r= parse_double(opt, name, param, &tmp, src); - if(r==1 && dst) VAL(dst) = tmp; + int r = parse_double(opt, name, param, &tmp, src); + if (r == 1 && dst) + VAL(dst) = tmp; return r; } -static char* print_float(const m_option_t* opt, const void* val) { - opt = NULL; - return dup_printf("%f",VAL(val)); +static char *print_float(const m_option_t *opt, const void *val) +{ + opt = NULL; + return dup_printf("%f", VAL(val)); } const m_option_type_t m_option_type_float = { - "Float", - "floating point number or ratio (numerator[:/]denominator)", - sizeof(float), - 0, - parse_float, - print_float, - copy_opt, - copy_opt, - NULL, - NULL + "Float", + "floating point number or ratio (numerator[:/]denominator)", + sizeof(float), + 0, + parse_float, + print_float, + copy_opt, + copy_opt, + NULL, + NULL }; ///////////// Position #undef VAL -#define VAL(x) (*(off_t*)(x)) +#define VAL(x) (*(off_t *)(x)) -static int parse_position(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - off_t tmp_off; - char dummy; - - if (param == NULL) - return M_OPT_MISSING_PARAM; - if (sscanf(param, sizeof(off_t) == sizeof(int) ? - "%d%c" : "%"PRId64"%c", &tmp_off, &dummy) != 1) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The %s option must be an integer: %s\n",opt->name,param); - return M_OPT_INVALID; - } +static int parse_position(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + off_t tmp_off; + char dummy; - if (opt->flags & M_OPT_MIN) - if (tmp_off < opt->min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %s option must be >= %"PRId64": %s\n", - name, (int64_t) opt->min, param); - return M_OPT_OUT_OF_RANGE; + if (param == NULL) + return M_OPT_MISSING_PARAM; + if (sscanf(param, sizeof(off_t) == sizeof(int) ? + "%d%c" : "%"PRId64"%c", &tmp_off, &dummy) != 1) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be an integer: %s\n", opt->name, param); + return M_OPT_INVALID; } - if (opt->flags & M_OPT_MAX) - if (tmp_off > opt->max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %s option must be <= %"PRId64": %s\n", - name, (int64_t) opt->max, param); - return M_OPT_OUT_OF_RANGE; - } + if (opt->flags & M_OPT_MIN) + if (tmp_off < opt->min) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be >= %"PRId64 ": %s\n", + name, (int64_t) opt->min, param); + return M_OPT_OUT_OF_RANGE; + } - if(dst) - VAL(dst) = tmp_off; - return 1; + if (opt->flags & M_OPT_MAX) + if (tmp_off > opt->max) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "The %s option must be <= %"PRId64 ": %s\n", + name, (int64_t) opt->max, param); + return M_OPT_OUT_OF_RANGE; + } + + if (dst) + VAL(dst) = tmp_off; + return 1; } -static char* print_position(const m_option_t* opt, const void* val) { - return dup_printf("%"PRId64,(int64_t)VAL(val)); +static char *print_position(const m_option_t *opt, const void *val) +{ + return dup_printf("%"PRId64, (int64_t)VAL(val)); } const m_option_type_t m_option_type_position = { - "Position", - "Integer (off_t)", - sizeof(off_t), - 0, - parse_position, - print_position, - copy_opt, - copy_opt, - NULL, - NULL + "Position", + "Integer (off_t)", + sizeof(off_t), + 0, + parse_position, + print_position, + copy_opt, + copy_opt, + NULL, + NULL }; ///////////// String #undef VAL -#define VAL(x) (*(char**)(x)) +#define VAL(x) (*(char **)(x)) -static int parse_str(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { +static int parse_str(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ - if (param == NULL) - return M_OPT_MISSING_PARAM; + if (param == NULL) + return M_OPT_MISSING_PARAM; - if ((opt->flags & M_OPT_MIN) && (strlen(param) < opt->min)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Parameter must be >= %d chars: %s\n", - (int) opt->min, param); - return M_OPT_OUT_OF_RANGE; - } + if ((opt->flags & M_OPT_MIN) && (strlen(param) < opt->min)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Parameter must be >= %d chars: %s\n", + (int) opt->min, param); + return M_OPT_OUT_OF_RANGE; + } - if ((opt->flags & M_OPT_MAX) && (strlen(param) > opt->max)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Parameter must be <= %d chars: %s\n", - (int) opt->max, param); - return M_OPT_OUT_OF_RANGE; - } + if ((opt->flags & M_OPT_MAX) && (strlen(param) > opt->max)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Parameter must be <= %d chars: %s\n", + (int) opt->max, param); + return M_OPT_OUT_OF_RANGE; + } - if(dst) { - free(VAL(dst)); - VAL(dst) = strdup(param); - } + if (dst) { + free(VAL(dst)); + VAL(dst) = strdup(param); + } - return 1; + return 1; } -static char* print_str(const m_option_t* opt, const void* val) { - return (val && VAL(val) && strlen(VAL(val)) > 0) ? strdup(VAL(val)) : NULL; +static char *print_str(const m_option_t *opt, const void *val) +{ + return (val && VAL(val) && strlen(VAL(val)) > 0) ? strdup(VAL(val)) : NULL; } -static void copy_str(const m_option_t* opt,void* dst, const void* src) { - if(dst && src) { +static void copy_str(const m_option_t *opt, void *dst, const void *src) +{ + if (dst && src) { #ifndef NO_FREE - free(VAL(dst)); //FIXME!!! + free(VAL(dst)); //FIXME!!! #endif - VAL(dst) = VAL(src) ? strdup(VAL(src)) : NULL; - } + VAL(dst) = VAL(src) ? strdup(VAL(src)) : NULL; + } } -static void free_str(void* src) { - if(src && VAL(src)){ +static void free_str(void *src) +{ + if (src && VAL(src)) { #ifndef NO_FREE - free(VAL(src)); //FIXME!!! + free(VAL(src)); //FIXME!!! #endif - VAL(src) = NULL; - } + VAL(src) = NULL; + } } const m_option_type_t m_option_type_string = { - "String", - "", - sizeof(char*), - M_OPT_TYPE_DYNAMIC, - parse_str, - print_str, - copy_str, - copy_str, - copy_str, - free_str + "String", + "", + sizeof(char *), + M_OPT_TYPE_DYNAMIC, + parse_str, + print_str, + copy_str, + copy_str, + copy_str, + free_str }; //////////// String list #undef VAL -#define VAL(x) (*(char***)(x)) +#define VAL(x) (*(char ***)(x)) #define OP_NONE 0 #define OP_ADD 1 @@ -544,263 +585,283 @@ const m_option_type_t m_option_type_string = { #define OP_DEL 3 #define OP_CLR 4 -static void free_str_list(void* dst) { - char** d; - int i; +static void free_str_list(void *dst) +{ + char **d; + int i; - if(!dst || !VAL(dst)) return; - d = VAL(dst); + if (!dst || !VAL(dst)) + return; + d = VAL(dst); // FIXME!!! #ifndef NO_FREE - for(i = 0 ; d[i] != NULL ; i++) - free(d[i]); - free(d); + for (i = 0; d[i] != NULL; i++) + free(d[i]); + free(d); #endif - VAL(dst) = NULL; + VAL(dst) = NULL; } -static int str_list_add(char** add, int n,void* dst,int pre) { - char** lst = VAL(dst); - int ln; +static int str_list_add(char **add, int n, void *dst, int pre) +{ + char **lst = VAL(dst); + int ln; - if(!dst) return M_OPT_PARSER_ERR; - lst = VAL(dst); + if (!dst) + return M_OPT_PARSER_ERR; + lst = VAL(dst); - for(ln = 0 ; lst && lst[ln] ; ln++) - /**/; + for (ln = 0; lst && lst[ln]; ln++) + /**/; - lst = realloc(lst,(n+ln+1)*sizeof(char*)); + lst = realloc(lst, (n + ln + 1) * sizeof(char *)); - if(pre) { - memmove(&lst[n],lst,ln*sizeof(char*)); - memcpy(lst,add,n*sizeof(char*)); - } else - memcpy(&lst[ln],add,n*sizeof(char*)); - // (re-)add NULL-termination - lst[ln+n] = NULL; + if (pre) { + memmove(&lst[n], lst, ln * sizeof(char *)); + memcpy(lst, add, n * sizeof(char *)); + } else + memcpy(&lst[ln], add, n * sizeof(char *)); + // (re-)add NULL-termination + lst[ln + n] = NULL; - free(add); + free(add); - VAL(dst) = lst; + VAL(dst) = lst; - return 1; + return 1; } -static int str_list_del(char** del, int n,void* dst) { - char **lst,*ep,**d; - int i,ln,s; - long idx; - - if(!dst) return M_OPT_PARSER_ERR; - lst = VAL(dst); - - for(ln = 0 ; lst && lst[ln] ; ln++) - /**/; - s = ln; - - for(i = 0 ; del[i] != NULL ; i++) { - idx = strtol(del[i], &ep, 0); - if(*ep) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid index: %s\n",del[i]); - free(del[i]); - continue; - } - free(del[i]); - if(idx < 0 || idx >= ln) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Index %ld is out of range.\n",idx); - continue; - } else if(!lst[idx]) - continue; - free(lst[idx]); - lst[idx] = NULL; - s--; - } - free(del); - - if(s == 0) { - free(lst); - VAL(dst) = NULL; - return 1; - } +static int str_list_del(char **del, int n, void *dst) +{ + char **lst, *ep, **d; + int i, ln, s; + long idx; + + if (!dst) + return M_OPT_PARSER_ERR; + lst = VAL(dst); + + for (ln = 0; lst && lst[ln]; ln++) + /**/; + s = ln; + + for (i = 0; del[i] != NULL; i++) { + idx = strtol(del[i], &ep, 0); + if (*ep) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid index: %s\n", del[i]); + free(del[i]); + continue; + } + free(del[i]); + if (idx < 0 || idx >= ln) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Index %ld is out of range.\n", idx); + continue; + } else if (!lst[idx]) + continue; + free(lst[idx]); + lst[idx] = NULL; + s--; + } + free(del); - d = calloc(s+1,sizeof(char*)); - for(i = 0, n = 0 ; i < ln ; i++) { - if(!lst[i]) continue; - d[n] = lst[i]; - n++; - } - d[s] = NULL; + if (s == 0) { + free(lst); + VAL(dst) = NULL; + return 1; + } - free(lst); - VAL(dst) = d; + d = calloc(s + 1, sizeof(char *)); + for (i = 0, n = 0; i < ln; i++) { + if (!lst[i]) + continue; + d[n] = lst[i]; + n++; + } + d[s] = NULL; - return 1; + free(lst); + VAL(dst) = d; + + return 1; } -static char *get_nextsep(char *ptr, char sep, int modify) { +static char *get_nextsep(char *ptr, char sep, int modify) +{ char *last_ptr = ptr; - for(;;){ + for (;;) { ptr = strchr(ptr, sep); - if(ptr && ptr>last_ptr && ptr[-1]=='\\'){ - if (modify) memmove(ptr-1, ptr, strlen(ptr)+1); - else ptr++; - }else + if (ptr && ptr > last_ptr && ptr[-1] == '\\') { + if (modify) + memmove(ptr - 1, ptr, strlen(ptr) + 1); + else + ptr++; + } else break; } return ptr; } -static int parse_str_list(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - int n = 0,len = strlen(opt->name); - char *str; - char *ptr = (char *)param, *last_ptr, **res; - int op = OP_NONE; - - if(opt->name[len-1] == '*' && ((int)strlen(name) > len - 1)) { - const char* n = &name[len-1]; - if(strcasecmp(n,"-add") == 0) - op = OP_ADD; - else if(strcasecmp(n,"-pre") == 0) - op = OP_PRE; - else if(strcasecmp(n,"-del") == 0) - op = OP_DEL; - else if(strcasecmp(n,"-clr") == 0) - op = OP_CLR; - else - return M_OPT_UNKNOWN; - } +static int parse_str_list(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + int n = 0, len = strlen(opt->name); + char *str; + char *ptr = (char *)param, *last_ptr, **res; + int op = OP_NONE; + + if (opt->name[len - 1] == '*' && ((int)strlen(name) > len - 1)) { + const char *n = &name[len - 1]; + if (strcasecmp(n, "-add") == 0) + op = OP_ADD; + else if (strcasecmp(n, "-pre") == 0) + op = OP_PRE; + else if (strcasecmp(n, "-del") == 0) + op = OP_DEL; + else if (strcasecmp(n, "-clr") == 0) + op = OP_CLR; + else + return M_OPT_UNKNOWN; + } - // Clear the list ?? - if(op == OP_CLR) { - if(dst) - free_str_list(dst); - return 0; - } - - // All other ops need a param - if (param == NULL || strlen(param) == 0) - return M_OPT_MISSING_PARAM; - - // custom type for "profile" calls this but uses ->priv for something else - char separator = opt->type == &m_option_type_string_list && opt->priv ? - *(char *)opt->priv : OPTION_LIST_SEPARATOR; - while(ptr[0] != '\0') { - ptr = get_nextsep(ptr, separator, 0); - if(!ptr) { - n++; - break; - } - ptr++; - n++; - } - if(n == 0) - return M_OPT_INVALID; - if( ((opt->flags & M_OPT_MIN) && (n < opt->min)) || - ((opt->flags & M_OPT_MAX) && (n > opt->max)) ) - return M_OPT_OUT_OF_RANGE; - - if(!dst) return 1; - - res = malloc((n+2)*sizeof(char*)); - ptr = str = strdup(param); - n = 0; - - while(1) { - last_ptr = ptr; - ptr = get_nextsep(ptr, separator, 1); - if(!ptr) { - res[n] = strdup(last_ptr); - n++; - break; - } - len = ptr - last_ptr; - res[n] = malloc(len + 1); - if(len) strncpy(res[n],last_ptr,len); - res[n][len] = '\0'; - ptr++; - n++; - } - res[n] = NULL; - free(str); - - switch(op) { - case OP_ADD: - return str_list_add(res,n,dst,0); - case OP_PRE: - return str_list_add(res,n,dst,1); - case OP_DEL: - return str_list_del(res,n,dst); - } - - if(VAL(dst)) - free_str_list(dst); - VAL(dst) = res; - - return 1; -} + // Clear the list ?? + if (op == OP_CLR) { + if (dst) + free_str_list(dst); + return 0; + } -static void copy_str_list(const m_option_t* opt,void* dst, const void* src) { - int n; - char **d,**s; + // All other ops need a param + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; - if(!(dst && src)) return; - s = VAL(src); + // custom type for "profile" calls this but uses ->priv for something else + char separator = opt->type == &m_option_type_string_list && opt->priv ? + *(char *)opt->priv : OPTION_LIST_SEPARATOR; + while (ptr[0] != '\0') { + ptr = get_nextsep(ptr, separator, 0); + if (!ptr) { + n++; + break; + } + ptr++; + n++; + } + if (n == 0) + return M_OPT_INVALID; + if (((opt->flags & M_OPT_MIN) && (n < opt->min)) || + ((opt->flags & M_OPT_MAX) && (n > opt->max))) + return M_OPT_OUT_OF_RANGE; + + if (!dst) + return 1; + + res = malloc((n + 2) * sizeof(char *)); + ptr = str = strdup(param); + n = 0; + + while (1) { + last_ptr = ptr; + ptr = get_nextsep(ptr, separator, 1); + if (!ptr) { + res[n] = strdup(last_ptr); + n++; + break; + } + len = ptr - last_ptr; + res[n] = malloc(len + 1); + if (len) + strncpy(res[n], last_ptr, len); + res[n][len] = '\0'; + ptr++; + n++; + } + res[n] = NULL; + free(str); + + switch (op) { + case OP_ADD: + return str_list_add(res, n, dst, 0); + case OP_PRE: + return str_list_add(res, n, dst, 1); + case OP_DEL: + return str_list_del(res, n, dst); + } - if(VAL(dst)) - free_str_list(dst); + if (VAL(dst)) + free_str_list(dst); + VAL(dst) = res; - if(!s) { - VAL(dst) = NULL; - return; - } + return 1; +} - for(n = 0 ; s[n] != NULL ; n++) - /* NOTHING */; - d = malloc((n+1)*sizeof(char*)); - for( ; n >= 0 ; n--) - d[n] = s[n] ? strdup(s[n]) : NULL; +static void copy_str_list(const m_option_t *opt, void *dst, const void *src) +{ + int n; + char **d, **s; - VAL(dst) = d; -} + if (!(dst && src)) + return; + s = VAL(src); -static char* print_str_list(const m_option_t* opt, const void* src) { - char **lst = NULL; - char *ret = NULL,*last = NULL; - int i; + if (VAL(dst)) + free_str_list(dst); - if(!(src && VAL(src))) return NULL; - lst = VAL(src); + if (!s) { + VAL(dst) = NULL; + return; + } - for(i = 0 ; lst[i] ; i++) { - if(last) { - ret = dup_printf("%s,%s",last,lst[i]); - free(last); - } else - ret = strdup(lst[i]); - last = ret; - } - if(last && last != ret) free(last); - return ret; + for (n = 0; s[n] != NULL; n++) + /* NOTHING */; + d = malloc((n + 1) * sizeof(char *)); + for (; n >= 0; n--) + d[n] = s[n] ? strdup(s[n]) : NULL; + + VAL(dst) = d; +} + +static char *print_str_list(const m_option_t *opt, const void *src) +{ + char **lst = NULL; + char *ret = NULL, *last = NULL; + int i; + + if (!(src && VAL(src))) + return NULL; + lst = VAL(src); + + for (i = 0; lst[i]; i++) { + if (last) { + ret = dup_printf("%s,%s", last, lst[i]); + free(last); + } else + ret = strdup(lst[i]); + last = ret; + } + if (last && last != ret) + free(last); + return ret; } const m_option_type_t m_option_type_string_list = { - "String list", - "A list of strings separated by ','\n" - "Option with a name ending in an * permits using the following suffix: \n" - "\t-add: Add the given parameters at the end of the list.\n" - "\t-pre: Add the given parameters at the beginning of the list.\n" - "\t-del: Remove the entry at the given indices.\n" - "\t-clr: Clear the list.\n" - "e.g: -vf-add flip,mirror -vf-del 2,5\n", - sizeof(char**), - M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD, - parse_str_list, - print_str_list, - copy_str_list, - copy_str_list, - copy_str_list, - free_str_list + "String list", + "A list of strings separated by ','\n" + "Option with a name ending in an * permits using the following suffix: \n" + "\t-add: Add the given parameters at the end of the list.\n" + "\t-pre: Add the given parameters at the beginning of the list.\n" + "\t-del: Remove the entry at the given indices.\n" + "\t-clr: Clear the list.\n" + "e.g: -vf-add flip,mirror -vf-del 2,5\n", + sizeof(char **), + M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD, + parse_str_list, + print_str_list, + copy_str_list, + copy_str_list, + copy_str_list, + free_str_list }; @@ -809,623 +870,650 @@ const m_option_type_t m_option_type_string_list = { // A chained list to save the various calls for func_param typedef struct m_func_save m_func_save_t; struct m_func_save { - m_func_save_t* next; - char* name; - char* param; + m_func_save_t *next; + char *name; + char *param; }; #undef VAL -#define VAL(x) (*(m_func_save_t**)(x)) +#define VAL(x) (*(m_func_save_t **)(x)) -static void free_func_pf(void* src) { - m_func_save_t *s,*n; +static void free_func_pf(void *src) +{ + m_func_save_t *s, *n; - if(!src) return; + if (!src) + return; - s = VAL(src); + s = VAL(src); - while(s) { - n = s->next; - free(s->name); - free(s->param); - free(s); - s = n; - } - VAL(src) = NULL; + while (s) { + n = s->next; + free(s->name); + free(s->param); + free(s); + s = n; + } + VAL(src) = NULL; } // Parser for func_param -static int parse_func_pf(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - m_func_save_t *s,*p; +static int parse_func_pf(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + m_func_save_t *s, *p; - if(!dst) - return 1; + if (!dst) + return 1; - s = calloc(1,sizeof(m_func_save_t)); - s->name = strdup(name); - s->param = param ? strdup(param) : NULL; + s = calloc(1, sizeof(m_func_save_t)); + s->name = strdup(name); + s->param = param ? strdup(param) : NULL; - p = VAL(dst); - if(p) { - for( ; p->next != NULL ; p = p->next) - /**/; - p->next = s; - } else - VAL(dst) = s; + p = VAL(dst); + if (p) { + for (; p->next != NULL; p = p->next) + /**/; + p->next = s; + } else + VAL(dst) = s; - return 1; + return 1; } -static void copy_func_pf(const m_option_t* opt,void* dst, const void* src) { - m_func_save_t *d = NULL, *s,* last = NULL; - - if(!(dst && src)) return; - s = VAL(src); - - if(VAL(dst)) - free_func_pf(dst); - - while(s) { - d = calloc(1,sizeof(m_func_save_t)); - d->name = strdup(s->name); - d->param = s->param ? strdup(s->param) : NULL; - if(last) - last->next = d; - else - VAL(dst) = d; - last = d; - s = s->next; - } +static void copy_func_pf(const m_option_t *opt, void *dst, const void *src) +{ + m_func_save_t *d = NULL, *s, *last = NULL; + + if (!(dst && src)) + return; + s = VAL(src); + + if (VAL(dst)) + free_func_pf(dst); + + while (s) { + d = calloc(1, sizeof(m_func_save_t)); + d->name = strdup(s->name); + d->param = s->param ? strdup(s->param) : NULL; + if (last) + last->next = d; + else + VAL(dst) = d; + last = d; + s = s->next; + } } /////////////////// Func_param -static void set_func_param(const m_option_t* opt, void* dst, const void* src) { - m_func_save_t* s; +static void set_func_param(const m_option_t *opt, void *dst, const void *src) +{ + m_func_save_t *s; - if(!src) return; - s = VAL(src); + if (!src) + return; + s = VAL(src); - if(!s) return; + if (!s) + return; - for( ; s != NULL ; s = s->next) - ((m_opt_func_param_t) opt->p)(opt,s->param); + for (; s != NULL; s = s->next) + ((m_opt_func_param_t) opt->p)(opt, s->param); } const m_option_type_t m_option_type_func_param = { - "Func param", - "", - sizeof(m_func_save_t*), - M_OPT_TYPE_INDIRECT, - parse_func_pf, - NULL, - NULL, // Nothing to do on save - set_func_param, - copy_func_pf, - free_func_pf + "Func param", + "", + sizeof(m_func_save_t *), + M_OPT_TYPE_INDIRECT, + parse_func_pf, + NULL, + NULL, // Nothing to do on save + set_func_param, + copy_func_pf, + free_func_pf }; /////////////// Func #undef VAL -static int parse_func(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - return 0; +static int parse_func(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + return 0; } -static void set_func(const m_option_t* opt,void* dst, const void* src) { +static void set_func(const m_option_t *opt, void *dst, const void *src) +{ ((m_opt_func_t) opt->p)(opt); } const m_option_type_t m_option_type_func = { - "Func", - "", - sizeof(int), - M_OPT_TYPE_INDIRECT, - parse_func, - NULL, - NULL, // Nothing to do on save - set_func, - NULL, - NULL + "Func", + "", + sizeof(int), + M_OPT_TYPE_INDIRECT, + parse_func, + NULL, + NULL, // Nothing to do on save + set_func, + NULL, + NULL }; /////////////////// Print -static int parse_print(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - if(opt->type == CONF_TYPE_PRINT_INDIRECT) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", *(char **) opt->p); - else if(opt->type == CONF_TYPE_PRINT_FUNC) - return ((m_opt_func_full_t) opt->p)(opt,name,param); - else - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", mp_gtext(opt->p)); - - if(opt->priv == NULL) - return M_OPT_EXIT; - return 0; +static int parse_print(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + if (opt->type == CONF_TYPE_PRINT_INDIRECT) + mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", *(char **) opt->p); + else if (opt->type == CONF_TYPE_PRINT_FUNC) + return ((m_opt_func_full_t) opt->p)(opt, name, param); + else + mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", mp_gtext(opt->p)); + + if (opt->priv == NULL) + return M_OPT_EXIT; + return 0; } const m_option_type_t m_option_type_print = { - "Print", - "", - 0, - 0, - parse_print, - NULL, - NULL, - NULL, - NULL, - NULL + "Print", + "", + 0, + 0, + parse_print, + NULL, + NULL, + NULL, + NULL, + NULL }; const m_option_type_t m_option_type_print_indirect = { - "Print", - "", - 0, - 0, - parse_print, - NULL, - NULL, - NULL, - NULL, - NULL + "Print", + "", + 0, + 0, + parse_print, + NULL, + NULL, + NULL, + NULL, + NULL }; const m_option_type_t m_option_type_print_func = { - "Print", - "", - 0, - M_OPT_TYPE_ALLOW_WILDCARD, - parse_print, - NULL, - NULL, - NULL, - NULL, - NULL + "Print", + "", + 0, + M_OPT_TYPE_ALLOW_WILDCARD, + parse_print, + NULL, + NULL, + NULL, + NULL, + NULL }; /////////////////////// Subconfig #undef VAL -#define VAL(x) (*(char***)(x)) - -static int parse_subconf(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - char *subparam; - char *subopt; - int nr = 0,i,r; - const m_option_t *subopts; - const char *p; - char** lst = NULL; - - if (param == NULL || strlen(param) == 0) - return M_OPT_MISSING_PARAM; - - subparam = malloc(strlen(param)+1); - subopt = malloc(strlen(param)+1); - p = param; - - subopts = opt->p; - - while(p[0]) - { - int sscanf_ret = 1; - int optlen = strcspn(p, ":="); - /* clear out */ - subopt[0] = subparam[0] = 0; - av_strlcpy(subopt, p, optlen + 1); - p = &p[optlen]; - if (p[0] == '=') { - sscanf_ret = 2; - p = &p[1]; - if (p[0] == '"') { - p = &p[1]; - optlen = strcspn(p, "\""); - av_strlcpy(subparam, p, optlen + 1); - p = &p[optlen]; - if (p[0] != '"') { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Terminating '\"' missing for '%s'\n", subopt); - return M_OPT_INVALID; - } - p = &p[1]; - } else if (p[0] == '%') { - p = &p[1]; - optlen = (int)strtol(p, (char**)&p, 0); - if (!p || p[0] != '%' || (optlen > strlen(p) - 1)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid length %i for '%s'\n", optlen, subopt); +#define VAL(x) (*(char ***)(x)) + +static int parse_subconf(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + char *subparam; + char *subopt; + int nr = 0, i, r; + const m_option_t *subopts; + const char *p; + char **lst = NULL; + + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; + + subparam = malloc(strlen(param) + 1); + subopt = malloc(strlen(param) + 1); + p = param; + + subopts = opt->p; + + while (p[0]) { + int sscanf_ret = 1; + int optlen = strcspn(p, ":="); + /* clear out */ + subopt[0] = subparam[0] = 0; + av_strlcpy(subopt, p, optlen + 1); + p = &p[optlen]; + if (p[0] == '=') { + sscanf_ret = 2; + p = &p[1]; + if (p[0] == '"') { + p = &p[1]; + optlen = strcspn(p, "\""); + av_strlcpy(subparam, p, optlen + 1); + p = &p[optlen]; + if (p[0] != '"') { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Terminating '\"' missing for '%s'\n", subopt); + return M_OPT_INVALID; + } + p = &p[1]; + } else if (p[0] == '%') { + p = &p[1]; + optlen = (int)strtol(p, (char **)&p, 0); + if (!p || p[0] != '%' || (optlen > strlen(p) - 1)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Invalid length %i for '%s'\n", optlen, subopt); + return M_OPT_INVALID; + } + p = &p[1]; + av_strlcpy(subparam, p, optlen + 1); + p = &p[optlen]; + } else { + optlen = strcspn(p, ":"); + av_strlcpy(subparam, p, optlen + 1); + p = &p[optlen]; + } + } + if (p[0] == ':') + p = &p[1]; + else if (p[0]) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Incorrect termination for '%s'\n", subopt); return M_OPT_INVALID; - } - p = &p[1]; - av_strlcpy(subparam, p, optlen + 1); - p = &p[optlen]; - } else { - optlen = strcspn(p, ":"); - av_strlcpy(subparam, p, optlen + 1); - p = &p[optlen]; } - } - if (p[0] == ':') - p = &p[1]; - else if (p[0]) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Incorrect termination for '%s'\n", subopt); - return M_OPT_INVALID; - } - - switch(sscanf_ret) - { - case 1: - subparam[0] = 0; - case 2: - for(i = 0 ; subopts[i].name ; i++) { - if(!strcmp(subopts[i].name,subopt)) break; - } - if(!subopts[i].name) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: Unknown suboption %s\n",name,subopt); - return M_OPT_UNKNOWN; - } - r = m_option_parse(&subopts[i],subopt, - subparam[0] == 0 ? NULL : subparam,NULL,src); - if(r < 0) return r; - if(dst) { - lst = realloc(lst,2 * (nr+2) * sizeof(char*)); - lst[2*nr] = strdup(subopt); - lst[2*nr+1] = subparam[0] == 0 ? NULL : strdup(subparam); - memset(&lst[2*(nr+1)],0,2*sizeof(char*)); - nr++; - } - break; - } - } - - free(subparam); - free(subopt); - if(dst) - VAL(dst) = lst; - return 1; + switch (sscanf_ret) { + case 1: + subparam[0] = 0; + case 2: + for (i = 0; subopts[i].name; i++) + if (!strcmp(subopts[i].name, subopt)) + break; + if (!subopts[i].name) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Option %s: Unknown suboption %s\n", name, subopt); + return M_OPT_UNKNOWN; + } + r = m_option_parse(&subopts[i], subopt, + subparam[0] == 0 ? NULL : subparam, NULL, src); + if (r < 0) + return r; + if (dst) { + lst = realloc(lst, 2 * (nr + 2) * sizeof(char *)); + lst[2 * nr] = strdup(subopt); + lst[2 * nr + 1] = subparam[0] == 0 ? NULL : strdup(subparam); + memset(&lst[2 * (nr + 1)], 0, 2 * sizeof(char *)); + nr++; + } + break; + } + } + + free(subparam); + free(subopt); + if (dst) + VAL(dst) = lst; + + return 1; } const m_option_type_t m_option_type_subconfig = { - "Subconfig", - "The syntax is -option opt1=foo:flag:opt2=blah", - sizeof(int), - M_OPT_TYPE_HAS_CHILD, - parse_subconf, - NULL, - NULL, - NULL, - NULL, - NULL + "Subconfig", + "The syntax is -option opt1=foo:flag:opt2=blah", + sizeof(int), + M_OPT_TYPE_HAS_CHILD, + parse_subconf, + NULL, + NULL, + NULL, + NULL, + NULL }; #include "libmpcodecs/img_format.h" /* FIXME: snyc with img_format.h */ static struct { - const char* name; - unsigned int fmt; + const char *name; + unsigned int fmt; } mp_imgfmt_list[] = { - {"444p16le", IMGFMT_444P16_LE}, - {"444p16be", IMGFMT_444P16_BE}, - {"444p10le", IMGFMT_444P10_LE}, - {"444p10be", IMGFMT_444P10_BE}, - {"444p9le", IMGFMT_444P9_LE}, - {"444p9be", IMGFMT_444P9_BE}, - {"422p16le", IMGFMT_422P16_LE}, - {"422p16be", IMGFMT_422P16_BE}, - {"422p10le", IMGFMT_422P10_LE}, - {"422p10be", IMGFMT_422P10_BE}, - {"420p16le", IMGFMT_420P16_LE}, - {"420p16be", IMGFMT_420P16_BE}, - {"420p10le", IMGFMT_420P10_LE}, - {"420p10be", IMGFMT_420P10_BE}, - {"420p9le", IMGFMT_420P9_LE}, - {"420p9be", IMGFMT_420P9_BE}, - {"444p16", IMGFMT_444P16}, - {"444p10", IMGFMT_444P10}, - {"444p9", IMGFMT_444P9}, - {"422p16", IMGFMT_422P16}, - {"422p10", IMGFMT_422P10}, - {"420p10", IMGFMT_420P10}, - {"420p9", IMGFMT_420P9}, - {"420p16", IMGFMT_420P16}, - {"420a", IMGFMT_420A}, - {"444p", IMGFMT_444P}, - {"422p", IMGFMT_422P}, - {"411p", IMGFMT_411P}, - {"440p", IMGFMT_440P}, - {"yuy2", IMGFMT_YUY2}, - {"uyvy", IMGFMT_UYVY}, - {"yvu9", IMGFMT_YVU9}, - {"if09", IMGFMT_IF09}, - {"yv12", IMGFMT_YV12}, - {"i420", IMGFMT_I420}, - {"iyuv", IMGFMT_IYUV}, - {"clpl", IMGFMT_CLPL}, - {"hm12", IMGFMT_HM12}, - {"y800", IMGFMT_Y800}, - {"y8", IMGFMT_Y8}, - {"nv12", IMGFMT_NV12}, - {"nv21", IMGFMT_NV21}, - {"bgr24", IMGFMT_BGR24}, - {"bgr32", IMGFMT_BGR32}, - {"bgr16", IMGFMT_BGR16}, - {"bgr15", IMGFMT_BGR15}, - {"bgr12", IMGFMT_BGR12}, - {"bgr8", IMGFMT_BGR8}, - {"bgr4", IMGFMT_BGR4}, - {"bg4b", IMGFMT_BG4B}, - {"bgr1", IMGFMT_BGR1}, - {"rgb48be", IMGFMT_RGB48BE}, - {"rgb48le", IMGFMT_RGB48LE}, - {"rgb48ne", IMGFMT_RGB48NE}, - {"rgb24", IMGFMT_RGB24}, - {"rgb32", IMGFMT_RGB32}, - {"rgb16", IMGFMT_RGB16}, - {"rgb15", IMGFMT_RGB15}, - {"rgb12", IMGFMT_RGB12}, - {"rgb8", IMGFMT_RGB8}, - {"rgb4", IMGFMT_RGB4}, - {"rg4b", IMGFMT_RG4B}, - {"rgb1", IMGFMT_RGB1}, - {"rgba", IMGFMT_RGBA}, - {"argb", IMGFMT_ARGB}, - {"bgra", IMGFMT_BGRA}, - {"abgr", IMGFMT_ABGR}, - {"mjpeg", IMGFMT_MJPEG}, - {"mjpg", IMGFMT_MJPEG}, - { NULL, 0 } + {"444p16le", IMGFMT_444P16_LE}, + {"444p16be", IMGFMT_444P16_BE}, + {"444p10le", IMGFMT_444P10_LE}, + {"444p10be", IMGFMT_444P10_BE}, + {"444p9le", IMGFMT_444P9_LE}, + {"444p9be", IMGFMT_444P9_BE}, + {"422p16le", IMGFMT_422P16_LE}, + {"422p16be", IMGFMT_422P16_BE}, + {"422p10le", IMGFMT_422P10_LE}, + {"422p10be", IMGFMT_422P10_BE}, + {"420p16le", IMGFMT_420P16_LE}, + {"420p16be", IMGFMT_420P16_BE}, + {"420p10le", IMGFMT_420P10_LE}, + {"420p10be", IMGFMT_420P10_BE}, + {"420p9le", IMGFMT_420P9_LE}, + {"420p9be", IMGFMT_420P9_BE}, + {"444p16", IMGFMT_444P16}, + {"444p10", IMGFMT_444P10}, + {"444p9", IMGFMT_444P9}, + {"422p16", IMGFMT_422P16}, + {"422p10", IMGFMT_422P10}, + {"420p10", IMGFMT_420P10}, + {"420p9", IMGFMT_420P9}, + {"420p16", IMGFMT_420P16}, + {"420a", IMGFMT_420A}, + {"444p", IMGFMT_444P}, + {"422p", IMGFMT_422P}, + {"411p", IMGFMT_411P}, + {"440p", IMGFMT_440P}, + {"yuy2", IMGFMT_YUY2}, + {"uyvy", IMGFMT_UYVY}, + {"yvu9", IMGFMT_YVU9}, + {"if09", IMGFMT_IF09}, + {"yv12", IMGFMT_YV12}, + {"i420", IMGFMT_I420}, + {"iyuv", IMGFMT_IYUV}, + {"clpl", IMGFMT_CLPL}, + {"hm12", IMGFMT_HM12}, + {"y800", IMGFMT_Y800}, + {"y8", IMGFMT_Y8}, + {"nv12", IMGFMT_NV12}, + {"nv21", IMGFMT_NV21}, + {"bgr24", IMGFMT_BGR24}, + {"bgr32", IMGFMT_BGR32}, + {"bgr16", IMGFMT_BGR16}, + {"bgr15", IMGFMT_BGR15}, + {"bgr12", IMGFMT_BGR12}, + {"bgr8", IMGFMT_BGR8}, + {"bgr4", IMGFMT_BGR4}, + {"bg4b", IMGFMT_BG4B}, + {"bgr1", IMGFMT_BGR1}, + {"rgb48be", IMGFMT_RGB48BE}, + {"rgb48le", IMGFMT_RGB48LE}, + {"rgb48ne", IMGFMT_RGB48NE}, + {"rgb24", IMGFMT_RGB24}, + {"rgb32", IMGFMT_RGB32}, + {"rgb16", IMGFMT_RGB16}, + {"rgb15", IMGFMT_RGB15}, + {"rgb12", IMGFMT_RGB12}, + {"rgb8", IMGFMT_RGB8}, + {"rgb4", IMGFMT_RGB4}, + {"rg4b", IMGFMT_RG4B}, + {"rgb1", IMGFMT_RGB1}, + {"rgba", IMGFMT_RGBA}, + {"argb", IMGFMT_ARGB}, + {"bgra", IMGFMT_BGRA}, + {"abgr", IMGFMT_ABGR}, + {"mjpeg", IMGFMT_MJPEG}, + {"mjpg", IMGFMT_MJPEG}, + { NULL, 0 } }; -static int parse_imgfmt(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - uint32_t fmt = 0; - int i; - - if (param == NULL || strlen(param) == 0) - return M_OPT_MISSING_PARAM; - - if(!strcmp(param,"help")) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:"); - for(i = 0 ; mp_imgfmt_list[i].name ; i++) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s",mp_imgfmt_list[i].name); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - return M_OPT_EXIT - 1; - } - - if (sscanf(param, "0x%x", &fmt) != 1) - { - for(i = 0 ; mp_imgfmt_list[i].name ; i++) { - if(!strcasecmp(param,mp_imgfmt_list[i].name)) { - fmt=mp_imgfmt_list[i].fmt; - break; - } - } - if(!mp_imgfmt_list[i].name) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: unknown format name: '%s'\n",name,param); - return M_OPT_INVALID; - } - } +static int parse_imgfmt(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + uint32_t fmt = 0; + int i; + + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; - if(dst) - *((uint32_t*)dst) = fmt; + if (!strcmp(param, "help")) { + mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:"); + for (i = 0; mp_imgfmt_list[i].name; i++) + mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", mp_imgfmt_list[i].name); + mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + return M_OPT_EXIT - 1; + } - return 1; + if (sscanf(param, "0x%x", &fmt) != 1) { + for (i = 0; mp_imgfmt_list[i].name; i++) { + if (!strcasecmp(param, mp_imgfmt_list[i].name)) { + fmt = mp_imgfmt_list[i].fmt; + break; + } + } + if (!mp_imgfmt_list[i].name) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Option %s: unknown format name: '%s'\n", name, param); + return M_OPT_INVALID; + } + } + + if (dst) + *((uint32_t *)dst) = fmt; + + return 1; } const m_option_type_t m_option_type_imgfmt = { - "Image format", - "Please report any missing colorspaces.", - sizeof(uint32_t), - 0, - parse_imgfmt, - NULL, - copy_opt, - copy_opt, - NULL, - NULL + "Image format", + "Please report any missing colorspaces.", + sizeof(uint32_t), + 0, + parse_imgfmt, + NULL, + copy_opt, + copy_opt, + NULL, + NULL }; #include "libaf/af_format.h" /* FIXME: snyc with af_format.h */ static struct { - const char* name; - unsigned int fmt; + const char *name; + unsigned int fmt; } mp_afmt_list[] = { - // SPECIAL - {"mulaw", AF_FORMAT_MU_LAW}, - {"alaw", AF_FORMAT_A_LAW}, - {"mpeg2", AF_FORMAT_MPEG2}, - {"ac3le", AF_FORMAT_AC3_LE}, - {"ac3be", AF_FORMAT_AC3_BE}, - {"ac3ne", AF_FORMAT_AC3_NE}, - {"imaadpcm", AF_FORMAT_IMA_ADPCM}, - // ORDINARY - {"u8", AF_FORMAT_U8}, - {"s8", AF_FORMAT_S8}, - {"u16le", AF_FORMAT_U16_LE}, - {"u16be", AF_FORMAT_U16_BE}, - {"u16ne", AF_FORMAT_U16_NE}, - {"s16le", AF_FORMAT_S16_LE}, - {"s16be", AF_FORMAT_S16_BE}, - {"s16ne", AF_FORMAT_S16_NE}, - {"u24le", AF_FORMAT_U24_LE}, - {"u24be", AF_FORMAT_U24_BE}, - {"u24ne", AF_FORMAT_U24_NE}, - {"s24le", AF_FORMAT_S24_LE}, - {"s24be", AF_FORMAT_S24_BE}, - {"s24ne", AF_FORMAT_S24_NE}, - {"u32le", AF_FORMAT_U32_LE}, - {"u32be", AF_FORMAT_U32_BE}, - {"u32ne", AF_FORMAT_U32_NE}, - {"s32le", AF_FORMAT_S32_LE}, - {"s32be", AF_FORMAT_S32_BE}, - {"s32ne", AF_FORMAT_S32_NE}, - {"floatle", AF_FORMAT_FLOAT_LE}, - {"floatbe", AF_FORMAT_FLOAT_BE}, - {"floatne", AF_FORMAT_FLOAT_NE}, - { NULL, 0 } + // SPECIAL + {"mulaw", AF_FORMAT_MU_LAW}, + {"alaw", AF_FORMAT_A_LAW}, + {"mpeg2", AF_FORMAT_MPEG2}, + {"ac3le", AF_FORMAT_AC3_LE}, + {"ac3be", AF_FORMAT_AC3_BE}, + {"ac3ne", AF_FORMAT_AC3_NE}, + {"imaadpcm", AF_FORMAT_IMA_ADPCM}, + // ORDINARY + {"u8", AF_FORMAT_U8}, + {"s8", AF_FORMAT_S8}, + {"u16le", AF_FORMAT_U16_LE}, + {"u16be", AF_FORMAT_U16_BE}, + {"u16ne", AF_FORMAT_U16_NE}, + {"s16le", AF_FORMAT_S16_LE}, + {"s16be", AF_FORMAT_S16_BE}, + {"s16ne", AF_FORMAT_S16_NE}, + {"u24le", AF_FORMAT_U24_LE}, + {"u24be", AF_FORMAT_U24_BE}, + {"u24ne", AF_FORMAT_U24_NE}, + {"s24le", AF_FORMAT_S24_LE}, + {"s24be", AF_FORMAT_S24_BE}, + {"s24ne", AF_FORMAT_S24_NE}, + {"u32le", AF_FORMAT_U32_LE}, + {"u32be", AF_FORMAT_U32_BE}, + {"u32ne", AF_FORMAT_U32_NE}, + {"s32le", AF_FORMAT_S32_LE}, + {"s32be", AF_FORMAT_S32_BE}, + {"s32ne", AF_FORMAT_S32_NE}, + {"floatle", AF_FORMAT_FLOAT_LE}, + {"floatbe", AF_FORMAT_FLOAT_BE}, + {"floatne", AF_FORMAT_FLOAT_NE}, + { NULL, 0 } }; -static int parse_afmt(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - uint32_t fmt = 0; - int i; - - if (param == NULL || strlen(param) == 0) - return M_OPT_MISSING_PARAM; - - if(!strcmp(param,"help")) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:"); - for(i = 0 ; mp_afmt_list[i].name ; i++) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s",mp_afmt_list[i].name); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - return M_OPT_EXIT - 1; - } - - if (sscanf(param, "0x%x", &fmt) != 1) - { - for(i = 0 ; mp_afmt_list[i].name ; i++) { - if(!strcasecmp(param,mp_afmt_list[i].name)) { - fmt=mp_afmt_list[i].fmt; - break; - } - } - if(!mp_afmt_list[i].name) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: unknown format name: '%s'\n",name,param); - return M_OPT_INVALID; - } - } +static int parse_afmt(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + uint32_t fmt = 0; + int i; + + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; + + if (!strcmp(param, "help")) { + mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:"); + for (i = 0; mp_afmt_list[i].name; i++) + mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", mp_afmt_list[i].name); + mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + return M_OPT_EXIT - 1; + } + + if (sscanf(param, "0x%x", &fmt) != 1) { + for (i = 0; mp_afmt_list[i].name; i++) { + if (!strcasecmp(param, mp_afmt_list[i].name)) { + fmt = mp_afmt_list[i].fmt; + break; + } + } + if (!mp_afmt_list[i].name) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Option %s: unknown format name: '%s'\n", name, param); + return M_OPT_INVALID; + } + } - if(dst) - *((uint32_t*)dst) = fmt; + if (dst) + *((uint32_t *)dst) = fmt; - return 1; + return 1; } const m_option_type_t m_option_type_afmt = { - "Audio format", - "Please report any missing formats.", - sizeof(uint32_t), - 0, - parse_afmt, - NULL, - copy_opt, - copy_opt, - NULL, - NULL + "Audio format", + "Please report any missing formats.", + sizeof(uint32_t), + 0, + parse_afmt, + NULL, + copy_opt, + copy_opt, + NULL, + NULL }; int parse_timestring(const char *str, double *time, char endchar) { - int a, b, len; - double d; - *time = 0; /* ensure initialization for error cases */ - if (sscanf(str, "%d:%d:%lf%n", &a, &b, &d, &len) >= 3) - *time = 3600*a + 60*b + d; - else if (sscanf(str, "%d:%lf%n", &a, &d, &len) >= 2) - *time = 60*a + d; - else if (sscanf(str, "%lf%n", &d, &len) >= 1) - *time = d; - else - return 0; /* unsupported time format */ - if (str[len] && str[len] != endchar) - return 0; /* invalid extra characters at the end */ - return len; + int a, b, len; + double d; + *time = 0; /* ensure initialization for error cases */ + if (sscanf(str, "%d:%d:%lf%n", &a, &b, &d, &len) >= 3) + *time = 3600 * a + 60 * b + d; + else if (sscanf(str, "%d:%lf%n", &a, &d, &len) >= 2) + *time = 60 * a + d; + else if (sscanf(str, "%lf%n", &d, &len) >= 1) + *time = d; + else + return 0; /* unsupported time format */ + if (str[len] && str[len] != endchar) + return 0; /* invalid extra characters at the end */ + return len; } -static int parse_time(const m_option_t* opt,const char *name, const char *param, void* dst, int src) +static int parse_time(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) { - double time; + double time; - if (param == NULL || strlen(param) == 0) - return M_OPT_MISSING_PARAM; + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; - if (!parse_timestring(param, &time, 0)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time: '%s'\n", - name,param); - return M_OPT_INVALID; - } + if (!parse_timestring(param, &time, 0)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time: '%s'\n", + name, param); + return M_OPT_INVALID; + } - if (dst) - *(double *)dst = time; - return 1; + if (dst) + *(double *)dst = time; + return 1; } const m_option_type_t m_option_type_time = { - "Time", - "", - sizeof(double), - 0, - parse_time, - print_double, - copy_opt, - copy_opt, - NULL, - NULL + "Time", + "", + sizeof(double), + 0, + parse_time, + print_double, + copy_opt, + copy_opt, + NULL, + NULL }; // Time or size (-endpos) -static int parse_time_size(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { - m_time_size_t ts; - char unit[4]; - double end_at; - - if (param == NULL || strlen(param) == 0) - return M_OPT_MISSING_PARAM; - - ts.pos=0; - /* End at size parsing */ - if(sscanf(param, "%lf%3s", &end_at, unit) == 2) { - ts.type = END_AT_SIZE; - if(!strcasecmp(unit, "b")) - ; - else if(!strcasecmp(unit, "kb")) - end_at *= 1024; - else if(!strcasecmp(unit, "mb")) - end_at *= 1024*1024; - else if(!strcasecmp(unit, "gb")) - end_at *= 1024*1024*1024; - else - ts.type = END_AT_NONE; +static int parse_time_size(const m_option_t *opt, const char *name, + const char *param, void *dst, int src) +{ + m_time_size_t ts; + char unit[4]; + double end_at; + + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; - if (ts.type == END_AT_SIZE) { - ts.pos = end_at; - goto out; + ts.pos = 0; + /* End at size parsing */ + if (sscanf(param, "%lf%3s", &end_at, unit) == 2) { + ts.type = END_AT_SIZE; + if (!strcasecmp(unit, "b")) + ; + else if (!strcasecmp(unit, "kb")) + end_at *= 1024; + else if (!strcasecmp(unit, "mb")) + end_at *= 1024 * 1024; + else if (!strcasecmp(unit, "gb")) + end_at *= 1024 * 1024 * 1024; + else + ts.type = END_AT_NONE; + + if (ts.type == END_AT_SIZE) { + ts.pos = end_at; + goto out; + } } - } - /* End at time parsing. This has to be last because the parsing accepts - * even a number followed by garbage */ - if (!parse_timestring(param, &end_at, 0)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time or size: '%s'\n", - name,param); - return M_OPT_INVALID; - } + /* End at time parsing. This has to be last because the parsing accepts + * even a number followed by garbage */ + if (!parse_timestring(param, &end_at, 0)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Option %s: invalid time or size: '%s'\n", + name, param); + return M_OPT_INVALID; + } - ts.type = END_AT_TIME; - ts.pos = end_at; + ts.type = END_AT_TIME; + ts.pos = end_at; out: - if(dst) - *(m_time_size_t *)dst = ts; - return 1; + if (dst) + *(m_time_size_t *)dst = ts; + return 1; } const m_option_type_t m_option_type_time_size = { - "Time or size", - "", - sizeof(m_time_size_t), - 0, - parse_time_size, - NULL, - copy_opt, - copy_opt, - NULL, - NULL + "Time or size", + "", + sizeof(m_time_size_t), + 0, + parse_time_size, + NULL, + copy_opt, + copy_opt, + NULL, + NULL }; @@ -1434,819 +1522,896 @@ const m_option_type_t m_option_type_time_size = { #include "m_struct.h" #undef VAL -#define VAL(x) (*(m_obj_settings_t**)(x)) - -static int find_obj_desc(const char* name,const m_obj_list_t* l,const m_struct_t** ret) { - int i; - char* n; +#define VAL(x) (*(m_obj_settings_t **)(x)) - for(i = 0 ; l->list[i] ; i++) { - n = M_ST_MB(char*,l->list[i],l->name_off); - if(!strcmp(n,name)) { - *ret = M_ST_MB(m_struct_t*,l->list[i],l->desc_off); - return 1; +static int find_obj_desc(const char *name, const m_obj_list_t *l, + const m_struct_t **ret) +{ + int i; + char *n; + + for (i = 0; l->list[i]; i++) { + n = M_ST_MB(char *, l->list[i], l->name_off); + if (!strcmp(n, name)) { + *ret = M_ST_MB(m_struct_t *, l->list[i], l->desc_off); + return 1; + } } - } - return 0; -} - -static int get_obj_param(const char* opt_name,const char* obj_name, const m_struct_t* desc, - char* str,int* nold,int oldmax,char** dst) { - char* eq; - const m_option_t* opt; - int r; - - eq = strchr(str,'='); - if(eq && eq == str) - eq = NULL; - - if(eq) { - char* p = eq + 1; - if(p[0] == '\0') p = NULL; - eq[0] = '\0'; - opt = m_option_list_find(desc->fields,str); - if(!opt) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: %s doesn't have a %s parameter.\n",opt_name,obj_name,str); - return M_OPT_UNKNOWN; - } - r = m_option_parse(opt,str,p,NULL,M_CONFIG_FILE); - if(r < 0) { - if(r > M_OPT_EXIT) - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: Error while parsing %s parameter %s (%s)\n",opt_name,obj_name,str,p); - eq[0] = '='; - return r; - } - if(