summaryrefslogtreecommitdiffstats
path: root/m_option.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-07-03 15:42:04 +0300
committerUoti Urpala <uau@mplayer2.org>2011-07-03 18:39:26 +0300
commit774bb252aa0bda6a6ef927cd9287b0a6c01da0e6 (patch)
treee37802ce0f999f67da92b31ac542f565a8f0b3ee /m_option.c
parent1a8384401b8df76b07be93f8994fbfee152a20ad (diff)
downloadmpv-774bb252aa0bda6a6ef927cd9287b0a6c01da0e6.tar.bz2
mpv-774bb252aa0bda6a6ef927cd9287b0a6c01da0e6.tar.xz
cosmetics: reformat demux_lavf.c, m_option.[ch] and m_property.c
Diffstat (limited to 'm_option.c')
-rw-r--r--m_option.c3651
1 files changed, 1908 insertions, 1743 deletions
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(ds