correct const usage in the option handling code so that tables can be

declared const and moved from .data to .text/rodata sections.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24994 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
rfelker 2007-11-09 06:50:53 +00:00
parent d1ba6a710e
commit 452c2c5652
4 changed files with 137 additions and 137 deletions

View File

@ -23,7 +23,7 @@
//#define NO_FREE
#endif
m_option_t* m_option_list_find(m_option_t* list,const char* name) {
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++) {
@ -40,7 +40,7 @@ m_option_t* m_option_list_find(m_option_t* list,const char* name) {
// Default function that just does a memcpy
static void copy_opt(m_option_t* opt,void* dst,void* src) {
static void copy_opt(const m_option_t* opt,void* dst,void* src) {
if(dst && src)
memcpy(dst,src,opt->type->size);
}
@ -76,7 +76,7 @@ static char* dup_printf(const char *fmt, ...) {
#define VAL(x) (*(int*)(x))
static int parse_flag(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_flag(const m_option_t* opt,const char *name, 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? */
@ -114,14 +114,14 @@ static int parse_flag(m_option_t* opt,char *name, char *param, void* dst, int sr
}
}
static char* print_flag(m_option_t* opt, void* val) {
static char* print_flag(const m_option_t* opt, void* val) {
if(VAL(val) == opt->min)
return strdup("no");
else
return strdup("yes");
}
m_option_type_t m_option_type_flag = {
const m_option_type_t m_option_type_flag = {
"Flag",
"need yes or no in config files",
sizeof(int),
@ -136,7 +136,7 @@ m_option_type_t m_option_type_flag = {
// Integer
static int parse_int(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_int(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
long tmp_int;
char *endptr;
src = 0;
@ -167,12 +167,12 @@ static int parse_int(m_option_t* opt,char *name, char *param, void* dst, int src
return 1;
}
static char* print_int(m_option_t* opt, void* val) {
static char* print_int(const m_option_t* opt, void* val) {
opt = NULL;
return dup_printf("%d",VAL(val));
}
m_option_type_t m_option_type_int = {
const m_option_type_t m_option_type_int = {
"Integer",
"",
sizeof(int),
@ -190,7 +190,7 @@ m_option_type_t m_option_type_int = {
#undef VAL
#define VAL(x) (*(double*)(x))
static int parse_double(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_double(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
double tmp_float;
char* endptr;
src = 0;
@ -239,12 +239,12 @@ static int parse_double(m_option_t* opt,char *name, char *param, void* dst, int
return 1;
}
static char* print_double(m_option_t* opt, void* val) {
static char* print_double(const m_option_t* opt, void* val) {
opt = NULL;
return dup_printf("%f",VAL(val));
}
m_option_type_t m_option_type_double = {
const m_option_type_t m_option_type_double = {
"Double",
"double precission floating point number or ratio (numerator[:/]denominator)",
sizeof(double),
@ -260,19 +260,19 @@ m_option_type_t m_option_type_double = {
#undef VAL
#define VAL(x) (*(float*)(x))
static int parse_float(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_float(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
double tmp;
int r= parse_double(opt, name, param, &tmp, src);
if(r==1 && dst) VAL(dst) = tmp;
return r;
}
static char* print_float(m_option_t* opt, void* val) {
static char* print_float(const m_option_t* opt, void* val) {
opt = NULL;
return dup_printf("%f",VAL(val));
}
m_option_type_t m_option_type_float = {
const m_option_type_t m_option_type_float = {
"Float",
"floating point number or ratio (numerator[:/]denominator)",
sizeof(float),
@ -289,7 +289,7 @@ m_option_type_t m_option_type_float = {
#undef VAL
#define VAL(x) (*(off_t*)(x))
static int parse_position(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_position(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
off_t tmp_off;
char dummy;
@ -322,11 +322,11 @@ static int parse_position(m_option_t* opt,char *name, char *param, void* dst, in
return 1;
}
static char* print_position(m_option_t* opt, void* val) {
static char* print_position(const m_option_t* opt, void* val) {
return dup_printf("%"PRId64,(int64_t)VAL(val));
}
m_option_type_t m_option_type_position = {
const m_option_type_t m_option_type_position = {
"Position",
"Integer (off_t)",
sizeof(off_t),
@ -345,7 +345,7 @@ m_option_type_t m_option_type_position = {
#undef VAL
#define VAL(x) (*(char**)(x))
static int parse_str(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_str(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
if (param == NULL)
@ -373,11 +373,11 @@ static int parse_str(m_option_t* opt,char *name, char *param, void* dst, int src
}
static char* print_str(m_option_t* opt, void* val) {
static char* print_str(const m_option_t* opt, void* val) {
return (val && VAL(val) && strlen(VAL(val)) > 0) ? strdup(VAL(val)) : NULL;
}
static void copy_str(m_option_t* opt,void* dst, void* src) {
static void copy_str(const m_option_t* opt,void* dst, void* src) {
if(dst && src) {
#ifndef NO_FREE
if(VAL(dst)) free(VAL(dst)); //FIXME!!!
@ -395,7 +395,7 @@ static void free_str(void* src) {
}
}
m_option_type_t m_option_type_string = {
const m_option_type_t m_option_type_string = {
"String",
"",
sizeof(char*),
@ -525,14 +525,14 @@ static char *get_nextsep(char *ptr, char sep, int modify) {
return ptr;
}
static int parse_str_list(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_str_list(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
int n = 0,len = strlen(opt->name);
char *str;
char *ptr = param, *last_ptr, **res;
int op = OP_NONE;
if(opt->name[len-1] == '*' && ((int)strlen(name) > len - 1)) {
char* n = &name[len-1];
const char* n = &name[len-1];
if(strcasecmp(n,"-add") == 0)
op = OP_ADD;
else if(strcasecmp(n,"-pre") == 0)
@ -612,7 +612,7 @@ static int parse_str_list(m_option_t* opt,char *name, char *param, void* dst, in
return 1;
}
static void copy_str_list(m_option_t* opt,void* dst, void* src) {
static void copy_str_list(const m_option_t* opt,void* dst, void* src) {
int n;
char **d,**s;
@ -636,7 +636,7 @@ static void copy_str_list(m_option_t* opt,void* dst, void* src) {
VAL(dst) = d;
}
static char* print_str_list(m_option_t* opt, void* src) {
static char* print_str_list(const m_option_t* opt, void* src) {
char **lst = NULL;
char *ret = NULL,*last = NULL;
int i;
@ -656,7 +656,7 @@ static char* print_str_list(m_option_t* opt, void* src) {
return ret;
}
m_option_type_t m_option_type_string_list = {
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"
@ -707,7 +707,7 @@ static void free_func_pf(void* src) {
}
// Parser for func_param and func_full
static int parse_func_pf(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_func_pf(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
m_func_save_t *s,*p;
if(!dst)
@ -728,7 +728,7 @@ static int parse_func_pf(m_option_t* opt,char *name, char *param, void* dst, int
return 1;
}
static void copy_func_pf(m_option_t* opt,void* dst, void* src) {
static void copy_func_pf(const m_option_t* opt,void* dst, void* src) {
m_func_save_t *d = NULL, *s,* last = NULL;
if(!(dst && src)) return;
@ -754,7 +754,7 @@ static void copy_func_pf(m_option_t* opt,void* dst, void* src) {
/////////////////// Func_param
static void set_func_param(m_option_t* opt, void* dst, void* src) {
static void set_func_param(const m_option_t* opt, void* dst, void* src) {
m_func_save_t* s;
if(!src) return;
@ -768,7 +768,7 @@ static void set_func_param(m_option_t* opt, void* dst, void* src) {
((m_opt_func_param_t) opt->p)(opt,s->param);
}
m_option_type_t m_option_type_func_param = {
const m_option_type_t m_option_type_func_param = {
"Func param",
"",
sizeof(m_func_save_t*),
@ -783,7 +783,7 @@ m_option_type_t m_option_type_func_param = {
/////////////////// Func_full
static void set_func_full(m_option_t* opt, void* dst, void* src) {
static void set_func_full(const m_option_t* opt, void* dst, void* src) {
m_func_save_t* s;
if(!src) return;
@ -795,7 +795,7 @@ static void set_func_full(m_option_t* opt, void* dst, void* src) {
}
}
m_option_type_t m_option_type_func_full = {
const m_option_type_t m_option_type_func_full = {
"Func full",
"",
sizeof(m_func_save_t*),
@ -813,20 +813,20 @@ m_option_type_t m_option_type_func_full = {
#undef VAL
#define VAL(x) (*(int*)(x))
static int parse_func(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_func(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
if(dst)
VAL(dst) += 1;
return 0;
}
static void set_func(m_option_t* opt,void* dst, void* src) {
static void set_func(const m_option_t* opt,void* dst, void* src) {
int i;
if(opt->priv) ((m_opt_default_func_t)opt->priv)(opt,opt->name);
for(i = 0 ; i < VAL(src) ; i++)
((m_opt_func_t) opt->p)(opt);
}
m_option_type_t m_option_type_func = {
const m_option_type_t m_option_type_func = {
"Func",
"",
sizeof(int),
@ -841,7 +841,7 @@ m_option_type_t m_option_type_func = {
/////////////////// Print
static int parse_print(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_print(const m_option_t* opt,const char *name, 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)
@ -854,7 +854,7 @@ static int parse_print(m_option_t* opt,char *name, char *param, void* dst, int s
return 1;
}
m_option_type_t m_option_type_print = {
const m_option_type_t m_option_type_print = {
"Print",
"",
0,
@ -867,7 +867,7 @@ m_option_type_t m_option_type_print = {
NULL
};
m_option_type_t m_option_type_print_indirect = {
const m_option_type_t m_option_type_print_indirect = {
"Print",
"",
0,
@ -880,7 +880,7 @@ m_option_type_t m_option_type_print_indirect = {
NULL
};
m_option_type_t m_option_type_print_func = {
const m_option_type_t m_option_type_print_func = {
"Print",
"",
0,
@ -898,12 +898,12 @@ m_option_type_t m_option_type_print_func = {
#undef VAL
#define VAL(x) (*(char***)(x))
static int parse_subconf(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_subconf(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
char *subparam;
char *subopt;
int nr = 0,i,r;
m_option_t *subopts;
char *p;
const m_option_t *subopts;
const char *p;
char** lst = NULL;
if (param == NULL || strlen(param) == 0)
@ -938,7 +938,7 @@ static int parse_subconf(m_option_t* opt,char *name, char *param, void* dst, int
p = &p[1];
} else if (p[0] == '%') {
p = &p[1];
optlen = (int)strtol(p, &p, 0);
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;
@ -993,7 +993,7 @@ static int parse_subconf(m_option_t* opt,char *name, char *param, void* dst, int
return 1;
}
m_option_type_t m_option_type_subconfig = {
const m_option_type_t m_option_type_subconfig = {
"Subconfig",
"The syntax is -option opt1=foo:flag:opt2=blah",
sizeof(int),
@ -1054,7 +1054,7 @@ static struct {
{ NULL, 0 }
};
static int parse_imgfmt(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_imgfmt(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
uint32_t fmt = 0;
int i;
@ -1089,7 +1089,7 @@ static int parse_imgfmt(m_option_t* opt,char *name, char *param, void* dst, int
return 1;
}
m_option_type_t m_option_type_imgfmt = {
const m_option_type_t m_option_type_imgfmt = {
"Image format",
"Please report any missing colorspaces.",
sizeof(uint32_t),
@ -1142,7 +1142,7 @@ static struct {
{ NULL, 0 }
};
static int parse_afmt(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_afmt(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
uint32_t fmt = 0;
int i;
@ -1177,7 +1177,7 @@ static int parse_afmt(m_option_t* opt,char *name, char *param, void* dst, int sr
return 1;
}
m_option_type_t m_option_type_afmt = {
const m_option_type_t m_option_type_afmt = {
"Audio format",
"Please report any missing formats.",
sizeof(uint32_t),
@ -1191,7 +1191,7 @@ m_option_type_t m_option_type_afmt = {
};
static double parse_timestring(char *str)
static double parse_timestring(const char *str)
{
int a, b;
double d;
@ -1205,7 +1205,7 @@ static double parse_timestring(char *str)
}
static int parse_time(m_option_t* opt,char *name, char *param, void* dst, int src)
static int parse_time(const m_option_t* opt,const char *name, char *param, void* dst, int src)
{
double time;
@ -1224,7 +1224,7 @@ static int parse_time(m_option_t* opt,char *name, char *param, void* dst, int sr
return 1;
}
m_option_type_t m_option_type_time = {
const m_option_type_t m_option_type_time = {
"Time",
"",
sizeof(double),
@ -1240,7 +1240,7 @@ m_option_type_t m_option_type_time = {
// Time or size (-endpos)
static int parse_time_size(m_option_t* opt,char *name, char *param, void* dst, int src) {
static int parse_time_size(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
m_time_size_t ts;
char unit[4];
double end_at;
@ -1285,7 +1285,7 @@ out:
return 1;
}
m_option_type_t m_option_type_time_size = {
const m_option_type_t m_option_type_time_size = {
"Time or size",
"",
sizeof(m_time_size_t),
@ -1306,7 +1306,7 @@ m_option_type_t m_option_type_time_size = {
#undef VAL
#define VAL(x) (*(m_obj_settings_t**)(x))
static int find_obj_desc(char* name,m_obj_list_t* l,m_struct_t** ret) {
static int find_obj_desc(const char* name,const m_obj_list_t* l,const m_struct_t** ret) {
int i;
char* n;
@ -1320,10 +1320,10 @@ static int find_obj_desc(char* name,m_obj_list_t* l,m_struct_t** ret) {
return 0;
}
static int get_obj_param(const char* opt_name,const char* obj_name, m_struct_t* desc,
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;
m_option_t* opt;
const m_option_t* opt;
int r;
eq = strchr(str,'=');
@ -1374,7 +1374,7 @@ static int get_obj_param(const char* opt_name,const char* obj_name, m_struct_t*
}
static int get_obj_params(const char* opt_name, const char* name,char* params,
m_struct_t* desc,char separator, char*** _ret) {
const m_struct_t* desc,char separator, char*** _ret) {
int n = 0,nold = 0, nopts,r;
char* ptr,*last_ptr = params;
char** ret;
@ -1387,7 +1387,7 @@ static int get_obj_params(const char* opt_name, const char* name,char* params,
}
printf("\n Name Type Min Max\n\n");
for(n = 0 ; desc->fields[n].name ; n++) {
m_option_t* opt = &desc->fields[n];
const m_option_t* opt = &desc->fields[n];
if(opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue;
if(opt->flags & M_OPT_MIN)
sprintf(min,"%-8.0f",opt->min);
@ -1470,12 +1470,12 @@ static int get_obj_params(const char* opt_name, const char* name,char* params,
return 1;
}
static int parse_obj_params(m_option_t* opt,char *name,
static int parse_obj_params(const m_option_t* opt,const char *name,
char *param, void* dst, int src) {
char** opts;
int r;
m_obj_params_t* p = opt->priv;
m_struct_t* desc;
const m_struct_t* desc;
char* cpy = strdup(param);
// We need the object desc
@ -1499,7 +1499,7 @@ static int parse_obj_params(m_option_t* opt,char *name,
}
m_option_type_t m_option_type_obj_params = {
const m_option_type_t m_option_type_obj_params = {
"Object params",
"",
0,
@ -1515,28 +1515,28 @@ m_option_type_t m_option_type_obj_params = {
/// Some predefined types as a definition would be quite lengthy
/// Span arguments
static m_span_t m_span_params_dflts = { -1, -1 };
static m_option_t m_span_params_fields[] = {
static const m_span_t m_span_params_dflts = { -1, -1 };
static const m_option_t m_span_params_fields[] = {
{"start", M_ST_OFF(m_span_t,start), CONF_TYPE_INT, M_OPT_MIN, 1 ,0, NULL},
{"end", M_ST_OFF(m_span_t,end), CONF_TYPE_INT, M_OPT_MIN , 1 ,0, NULL},
{ NULL, NULL, 0, 0, 0, 0, NULL }
};
static struct m_struct_st m_span_opts = {
static const struct m_struct_st m_span_opts = {
"m_span",
sizeof(m_span_t),
&m_span_params_dflts,
m_span_params_fields
};
m_obj_params_t m_span_params_def = {
const m_obj_params_t m_span_params_def = {
&m_span_opts,
'-'
};
static int parse_obj_settings(char* opt,char* str,m_obj_list_t* list,
static int parse_obj_settings(const char* opt,char* str,const m_obj_list_t* list,
m_obj_settings_t **_ret, int ret_n) {
int r;
char *param,**plist = NULL;
m_struct_t* desc;
const m_struct_t* desc;
m_obj_settings_t *ret = _ret ? *_ret : NULL;
@ -1584,11 +1584,11 @@ static int parse_obj_settings(char* opt,char* str,m_obj_list_t* list,
static void free_obj_settings_list(void* dst);
static int obj_settings_list_del(char *opt_name,char *param,void* dst, int src) {
static int obj_settings_list_del(const char *opt_name,char *param,void* dst, int src) {
char** str_list = NULL;
int r,i,idx_max = 0;
char* rem_id = "_removed_marker_";
m_option_t list_opt = {opt_name , NULL, CONF_TYPE_STRING_LIST,
const m_option_t list_opt = {opt_name , NULL, CONF_TYPE_STRING_LIST,
0, 0, 0, NULL };
m_obj_settings_t* obj_list = dst ? VAL(dst) : NULL;
@ -1642,7 +1642,7 @@ static int obj_settings_list_del(char *opt_name,char *param,void* dst, int src)
return 1;
}
static int parse_obj_settings_list(m_option_t* opt,char *name,
static int parse_obj_settings_list(const m_option_t* opt,const char *name,
char *param, void* dst, int src) {
int n = 0,r,len = strlen(opt->name);
char *str;
@ -1655,7 +1655,7 @@ static int parse_obj_settings_list(m_option_t* opt,char *name,
return M_OPT_INVALID;
if(opt->name[len-1] == '*' && ((int)strlen(name) > len - 1)) {
char* n = &name[len-1];
const char* n = &name[len-1];
if(strcasecmp(n,"-add") == 0)
op = OP_ADD;
else if(strcasecmp(n,"-pre") == 0)
@ -1796,7 +1796,7 @@ static void free_obj_settings_list(void* dst) {
VAL(dst) = NULL;
}
static void copy_obj_settings_list(m_option_t* opt,void* dst, void* src) {
static void copy_obj_settings_list(const m_option_t* opt,void* dst, void* src) {
m_obj_settings_t *d,*s;
int n;
@ -1824,7 +1824,7 @@ static void copy_obj_settings_list(m_option_t* opt,void* dst, void* src) {
VAL(dst) = d;
}
m_option_type_t m_option_type_obj_settings_list = {
const m_option_type_t m_option_type_obj_settings_list = {
"Object settings list",
"",
sizeof(m_obj_settings_t*),
@ -1839,7 +1839,7 @@ m_option_type_t m_option_type_obj_settings_list = {
static int parse_obj_presets(m_option_t* opt,char *name,
static int parse_obj_presets(const m_option_t* opt,const char *name,
char *param, void* dst, int src) {
m_obj_presets_t* obj_p = (m_obj_presets_t*)opt->priv;
m_struct_t *in_desc,*out_desc;
@ -1886,7 +1886,7 @@ static int parse_obj_presets(m_option_t* opt,char *name,
if(!dst) return 1;
for(i = 0 ; in_desc->fields[i].name ; i++) {
m_option_t* out_opt = m_option_list_find(out_desc->fields,
const m_option_t* out_opt = m_option_list_find(out_desc->fields,
in_desc->fields[i].name);
if(!out_opt) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: Unable to find the target option for field %s.\nPlease report this to the developers.\n",name,in_desc->fields[i].name);
@ -1898,7 +1898,7 @@ static int parse_obj_presets(m_option_t* opt,char *name,
}
m_option_type_t m_option_type_obj_presets = {
const m_option_type_t m_option_type_obj_presets = {
"Object presets",
"",
0,
@ -1911,7 +1911,7 @@ m_option_type_t m_option_type_obj_presets = {
NULL
};
static int parse_custom_url(m_option_t* opt,char *name,
static int parse_custom_url(const m_option_t* opt,const char *name,
char *url, void* dst, int src) {
int pos1, pos2, r, v6addr = 0;
char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL, *ptr4=NULL;
@ -2108,7 +2108,7 @@ static int parse_custom_url(m_option_t* opt,char *name,
}
/// TODO : Write the other needed funcs for 'normal' options
m_option_type_t m_option_type_custom_url = {
const m_option_type_t m_option_type_custom_url = {
"Custom URL",
"",
0,

View File

@ -21,39 +21,39 @@ struct m_struct_st;
///////////////////////////// Options types declarations ////////////////////////////
// Simple types
extern m_option_type_t m_option_type_flag;
extern m_option_type_t m_option_type_int;
extern m_option_type_t m_option_type_float;
extern m_option_type_t m_option_type_double;
extern m_option_type_t m_option_type_string;
extern m_option_type_t m_option_type_string_list;
extern m_option_type_t m_option_type_position;
extern m_option_type_t m_option_type_time;
extern m_option_type_t m_option_type_time_size;
extern const m_option_type_t m_option_type_flag;
extern const m_option_type_t m_option_type_int;
extern const m_option_type_t m_option_type_float;
extern const m_option_type_t m_option_type_double;
extern const m_option_type_t m_option_type_string;
extern const m_option_type_t m_option_type_string_list;
extern const m_option_type_t m_option_type_position;
extern const m_option_type_t m_option_type_time;
extern const m_option_type_t m_option_type_time_size;
extern m_option_type_t m_option_type_print;
extern m_option_type_t m_option_type_print_indirect;
extern m_option_type_t m_option_type_print_func;
extern m_option_type_t m_option_type_subconfig;
extern m_option_type_t m_option_type_imgfmt;
extern m_option_type_t m_option_type_afmt;
extern const m_option_type_t m_option_type_print;
extern const m_option_type_t m_option_type_print_indirect;
extern const m_option_type_t m_option_type_print_func;
extern const m_option_type_t m_option_type_subconfig;
extern const m_option_type_t m_option_type_imgfmt;
extern const m_option_type_t m_option_type_afmt;
// Func-based types
extern m_option_type_t m_option_type_func_full;
extern m_option_type_t m_option_type_func_param;
extern m_option_type_t m_option_type_func;
extern const m_option_type_t m_option_type_func_full;
extern const m_option_type_t m_option_type_func_param;
extern const m_option_type_t m_option_type_func;
/// Callback used to reset func options.
typedef void (*m_opt_default_func_t)(m_option_t *, char*);
typedef void (*m_opt_default_func_t)(const m_option_t *, const char*);
/// Callback used by m_option_type_func_full options.
typedef int (*m_opt_func_full_t)(m_option_t *, char *, char *);
typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, char *);
/// Callback used by m_option_type_func_param options.
typedef int (*m_opt_func_param_t)(m_option_t *, char *);
typedef int (*m_opt_func_param_t)(const m_option_t *, const char *);
/// Callback used by m_option_type_func options.
typedef int (*m_opt_func_t)(m_option_t *);
typedef int (*m_opt_func_t)(const m_option_t *);
// Backwards compatibility
typedef m_opt_default_func_t cfg_default_func_t;
@ -95,7 +95,7 @@ typedef struct m_obj_settings {
* field (\ref m_option::priv) must point to a \ref m_obj_list_t describing
* the available object types.
*/
extern m_option_type_t m_option_type_obj_settings_list;
extern const m_option_type_t m_option_type_obj_settings_list;
/// Extra definition needed for \ref m_option_type_obj_presets options.
typedef struct {
@ -116,18 +116,18 @@ typedef struct {
* The option priv field (\ref m_option::priv) must point to a correctly
* filled \ref m_obj_presets_t.
*/
extern m_option_type_t m_option_type_obj_presets;
extern const m_option_type_t m_option_type_obj_presets;
/// Parse an URL into a struct.
/** The option priv field (\ref m_option::priv) must point to a
* \ref m_struct_st describing which fields of the URL must be used.
*/
extern m_option_type_t m_option_type_custom_url;
extern const m_option_type_t m_option_type_custom_url;
/// Extra definition needed for \ref m_option_type_obj_params options.
typedef struct {
/// Field descriptions.
struct m_struct_st* desc;
const struct m_struct_st* desc;
/// Field separator to use.
char separator;
} m_obj_params_t;
@ -137,14 +137,14 @@ typedef struct {
* successively sets a field from the struct. The option priv field
* (\ref m_option::priv) must point to a \ref m_obj_params_t.
*/
extern m_option_type_t m_option_type_obj_params;
extern const m_option_type_t m_option_type_obj_params;
typedef struct {
int start;
int end;
} m_span_t;
/// Ready made settings to parse a \ref m_span_t with a start-end syntax.
extern m_obj_params_t m_span_params_def;
extern const m_obj_params_t m_span_params_def;
// FIXME: backward compatibility
@ -196,7 +196,7 @@ struct m_option_type {
* \return On error a negative value is returned, on success the number of arguments
* consumed. For details see \ref OptionParserReturn.
*/
int (*parse)(m_option_t* opt,char *name, char *param, void* dst, int src);
int (*parse)(const m_option_t* opt,const char *name, char *param, void* dst, int src);
/// Print back a value in string form.
/** \param opt The option to print.
@ -204,7 +204,7 @@ struct m_option_type {
* \return An allocated string containing the text value or (void*)-1
* on error.
*/
char* (*print)(m_option_t* opt, void* val);
char* (*print)(const m_option_t* opt, void* val);
/** \name
* These functions are called to save/set/restore the status of the
@ -219,21 +219,21 @@ struct m_option_type {
* \param dst Pointer to the destination memory.
* \param src Pointer to the source memory.
*/
void (*save)(m_option_t* opt,void* dst, void* src);
void (*save)(const m_option_t* opt,void* dst, void* src);
/// Set the value in the program (dst) from a save slot.
/** \param opt The option to copy.
* \param dst Pointer to the destination memory.
* \param src Pointer to the source memory.
*/
void (*set)(m_option_t* opt,void* dst, void* src);
void (*set)(const m_option_t* opt,void* dst, void* src);
/// Copy the data between two save slots. If NULL and size is > 0 a memcpy will be used.
/** \param opt The option to copy.
* \param dst Pointer to the destination memory.
* \param src Pointer to the source memory.
*/
void (*copy)(m_option_t* opt,void* dst, void* src);
void (*copy)(const m_option_t* opt,void* dst, void* src);
//@}
/// Free the data allocated for a save slot.
@ -251,7 +251,7 @@ struct m_option_type {
*/
struct m_option {
/// Option name.
char *name;
const char *name;
/// Reserved for higher level APIs, it shouldn't be used by parsers.
/** The suboption parser and func types do use it. They should instead
@ -261,7 +261,7 @@ struct m_option {
void *p;
/// Option type.
m_option_type_t* type;
const m_option_type_t* type;
/// See \ref OptionFlags.
unsigned int flags;
@ -451,17 +451,17 @@ struct m_option {
* \param name Name of the option.
* \return The matching option or NULL.
*/
m_option_t* m_option_list_find(m_option_t* list,const char* name);
const m_option_t* m_option_list_find(const m_option_t* list,const char* name);
/// Helper to parse options, see \ref m_option_type::parse.
inline static int
m_option_parse(m_option_t* opt,char *name, char *param, void* dst, int src) {
m_option_parse(const m_option_t* opt,const char *name, char *param, void* dst, int src) {
return opt->type->parse(opt,name,param,dst,src);
}
/// Helper to print options, see \ref m_option_type::print.
inline static char*
m_option_print(m_option_t* opt, void* val_ptr) {
m_option_print(const m_option_t* opt, void* val_ptr) {
if(opt->type->print)
return opt->type->print(opt,val_ptr);
else
@ -470,21 +470,21 @@ m_option_print(m_option_t* opt, void* val_ptr) {
/// Helper around \ref m_option_type::save.
inline static void
m_option_save(m_option_t* opt,void* dst, void* src) {
m_option_save(const m_option_t* opt,void* dst, void* src) {
if(opt->type->save)
opt->type->save(opt,dst,src);
}
/// Helper around \ref m_option_type::set.
inline static void
m_option_set(m_option_t* opt,void* dst, void* src) {
m_option_set(const m_option_t* opt,void* dst, void* src) {
if(opt->type->set)
opt->type->set(opt,dst,src);
}
/// Helper around \ref m_option_type::copy.
inline static void
m_option_copy(m_option_t* opt,void* dst, void* src) {
m_option_copy(const m_option_t* opt,void* dst, void* src) {
if(opt->type->copy)
opt->type->copy(opt,dst,src);
else if(opt->type->size > 0)
@ -493,7 +493,7 @@ m_option_copy(m_option_t* opt,void* dst, void* src) {
/// Helper around \ref m_option_type::free.
inline static void
m_option_free(m_option_t* opt,void* dst) {
m_option_free(const m_option_t* opt,void* dst) {
if(opt->type->free)
opt->type->free(dst);
}

View File

@ -11,8 +11,8 @@
#include "m_struct.h"
#include "mp_msg.h"
m_option_t*
m_struct_get_field(m_struct_t* st,const char* f) {
const m_option_t*
m_struct_get_field(const m_struct_t* st,const char* f) {
int i;
for(i = 0 ; st->fields[i].name ; i++) {
@ -23,7 +23,7 @@ m_struct_get_field(m_struct_t* st,const char* f) {
}
void*
m_struct_alloc(m_struct_t* st) {
m_struct_alloc(const m_struct_t* st) {
int i;
void* r;
@ -51,8 +51,8 @@ m_struct_alloc(m_struct_t* st) {
}
int
m_struct_set(m_struct_t* st, void* obj, char* field, char* param) {
m_option_t* f = m_struct_get_field(st,field);
m_struct_set(const m_struct_t* st, void* obj, char* field, char* param) {
const m_option_t* f = m_struct_get_field(st,field);
if(!f) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s doesn't have any %s field\n",
@ -70,8 +70,8 @@ m_struct_set(m_struct_t* st, void* obj, char* field, char* param) {
}
void
m_struct_reset(m_struct_t* st, void* obj, const char* field) {
m_option_t* f;
m_struct_reset(const m_struct_t* st, void* obj, const char* field) {
const m_option_t* f;
if(!field) { // Reset all options
int i;
@ -92,7 +92,7 @@ m_struct_reset(m_struct_t* st, void* obj, const char* field) {
/// Free an allocated struct
void
m_struct_free(m_struct_t* st, void* obj) {
m_struct_free(const m_struct_t* st, void* obj) {
int i;
for(i = 0 ; st->fields[i].name ; i++)
@ -101,7 +101,7 @@ m_struct_free(m_struct_t* st, void* obj) {
}
void*
m_struct_copy(m_struct_t* st, void* obj) {
m_struct_copy(const m_struct_t* st, void* obj) {
void* r = malloc(st->size);
int i;

View File

@ -22,7 +22,7 @@ typedef struct m_struct_st {
/** The p field of the \ref m_option struct must contain the offset
* of the member in the struct (use M_ST_OFF macro for this).
*/
struct m_option* fields;
const struct m_option* fields;
} m_struct_t;
@ -60,7 +60,7 @@ typedef struct m_struct_st {
* \return The newly allocated object set to default.
*/
void*
m_struct_alloc(m_struct_t* st);
m_struct_alloc(const m_struct_t* st);
/// Set a field of the struct.
/** \param st Struct definition.
@ -70,7 +70,7 @@ m_struct_alloc(m_struct_t* st);
* \return 0 on error, 1 on success.
*/
int
m_struct_set(m_struct_t* st, void* obj, char* field, char* param);
m_struct_set(const m_struct_t* st, void* obj, char* field, char* param);
/// Reset a field (or all if field == NULL) to defaults.
/** \param st Struct definition.
@ -78,7 +78,7 @@ m_struct_set(m_struct_t* st, void* obj, char* field, char* param);
* \param field Name of the field to reset, if NULL all fields are reseted.
*/
void
m_struct_reset(m_struct_t* st, void* obj, const char* field);
m_struct_reset(const m_struct_t* st, void* obj, const char* field);
/// Create a copy of an existing struct.
/** \param st Struct definition.
@ -86,22 +86,22 @@ m_struct_reset(m_struct_t* st, void* obj, const char* field);
* \return Newly allocated copy of obj.
*/
void*
m_struct_copy(m_struct_t* st, void* obj);
m_struct_copy(const m_struct_t* st, void* obj);
/// Free an allocated struct.
/** \param st Struct definition.
* \param obj Pointer to the struct to copy.
*/
void
m_struct_free(m_struct_t* st, void* obj);
m_struct_free(const m_struct_t* st, void* obj);
/// Get a field description.
/** \param st Struct definition.
* \param f Name of the field.
* \return The \ref m_option struct describing the field or NULL if not found.
*/
struct m_option*
m_struct_get_field(m_struct_t* st,const char* f);
const struct m_option*
m_struct_get_field(const m_struct_t* st,const char* f);
///@}