annotate m_config.c @ 34040:02ffd25c7733

configure: drop extra standard compiler/linker flags for *BSD systems Adding the standard library locations to the search path is doubtful behavior and unnecessary at least on FreeBSD.
author diego
date Fri, 23 Sep 2011 16:08:15 +0000
parents a5a0019e1c28
children 389d43c448b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
1 /*
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
3 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
8 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
13 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
17 */
18258
96568be4bfdc Doxygen attack!
albeu
parents: 17856
diff changeset
18
96568be4bfdc Doxygen attack!
albeu
parents: 17856
diff changeset
19 /// \file
96568be4bfdc Doxygen attack!
albeu
parents: 17856
diff changeset
20 /// \ingroup Config
96568be4bfdc Doxygen attack!
albeu
parents: 17856
diff changeset
21
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
22 #include "config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
23
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24 #include <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
26 #include <errno.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
27 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
28 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
29 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
30 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
31
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
32 #include "m_config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
33 #include "m_option.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
34 #include "mp_msg.h"
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
35 #include "help_mp.h"
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
36
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
37 #define MAX_PROFILE_DEPTH 20
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
38
32301
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
39
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
40 static int parse_profile(const m_option_t *opt, const char *name,
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
41 const char *param, void *dst, int src)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
42 {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
43 m_config_t *config = opt->priv;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
44 char **list = NULL;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
45 int i, r;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
46 if (param && !strcmp(param, "help")) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
47 m_profile_t *p;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
48 if (!config->profiles) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
49 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_NoProfileDefined);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
50 return M_OPT_EXIT-1;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
51 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
52 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_AvailableProfiles);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
53 for (p = config->profiles; p; p = p->next)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
54 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n", p->name,
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
55 p->desc ? p->desc : "");
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
56 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
57 return M_OPT_EXIT-1;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
58 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
59
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
60 r = m_option_type_string_list.parse(opt, name, param, &list,src);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
61 if (r < 0)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
62 return r;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
63 if (!list || !list[0])
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
64 return M_OPT_INVALID;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
65 for (i = 0; list[i]; i++)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
66 if (!m_config_get_profile(config,list[i])) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
67 mp_msg(MSGT_CFGPARSER, MSGL_WARN, MSGTR_UnknownProfile, list[i]);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
68 r = M_OPT_INVALID;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
69 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
70 if (dst)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
71 m_option_copy(opt, dst, &list);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
72 else
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
73 m_option_free(opt, &list);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
74 return r;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
75 }
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
76
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
77 static void
32301
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
78 set_profile(const m_option_t *opt, void *dst, const void *src)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
79 {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
80 m_config_t *config = opt->priv;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
81 m_profile_t *p;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
82 char **list = NULL;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
83 int i;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
84 if (!src || !*(char***)src)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
85 return;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
86 m_option_copy(opt,&list,src);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
87 for (i = 0; list[i]; i++) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
88 p = m_config_get_profile(config, list[i]);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
89 if (!p)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
90 continue;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
91 m_config_set_profile(config, p);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
92 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
93 m_option_free(opt, &list);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
94 }
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
95
32301
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
96 static int show_profile(m_option_t *opt, char* name, char *param)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
97 {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
98 m_config_t *config = opt->priv;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
99 m_profile_t *p;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
100 int i, j;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
101 if (!param)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
102 return M_OPT_MISSING_PARAM;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
103 if (!(p = m_config_get_profile(config, param))) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
104 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownProfile, param);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
105 return M_OPT_EXIT - 1;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
106 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
107 if (!config->profile_depth)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
108 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_Profile, param,
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
109 p->desc ? p->desc : "");
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
110 config->profile_depth++;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
111 for (i = 0; i < p->num_opts; i++) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
112 char spc[config->profile_depth + 1];
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
113 for (j = 0; j < config->profile_depth; j++)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
114 spc[j] = ' ';
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
115 spc[config->profile_depth] = '\0';
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
116
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
117 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc,
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
118 p->opts[2 * i], p->opts[2 * i + 1]);
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
119
32301
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
120 if (config->profile_depth < MAX_PROFILE_DEPTH &&
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
121 !strcmp(p->opts[2*i],"profile")) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
122 char *e, *list = p->opts[2 * i + 1];
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
123 while ((e = strchr(list, ','))) {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
124 int l = e-list;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
125 char tmp[l+1];
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
126 if (!l)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
127 continue;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
128 memcpy(tmp, list, l);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
129 tmp[l] = '\0';
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
130 show_profile(opt, name, tmp);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
131 list = e+1;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
132 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
133 if (list[0] != '\0')
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
134 show_profile(opt, name, list);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
135 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
136 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
137 config->profile_depth--;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
138 if (!config->profile_depth)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
139 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
140 return M_OPT_EXIT - 1;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
141 }
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
142
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
143 static int list_options(m_option_t *opt, char* name, char *param)
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
144 {
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
145 m_config_t *config = opt->priv;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
146 m_config_print_option_list(config);
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
147 return M_OPT_EXIT;
a65635702512 cosmetics: Move some functions around to avoid ugly forward declarations.
diego
parents: 32300
diff changeset
148 }
17472
526abfe30498 Make -list-options work in both MPlayer and MEncoder.
albeu
parents: 17471
diff changeset
149
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
150 m_config_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
151 m_config_new(void) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
152 m_config_t* config;
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25634
diff changeset
153 static int initialized = 0;
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
154 static m_option_type_t profile_opt_type;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
155 static m_option_t ref_opts[] = {
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
156 { "profile", NULL, &profile_opt_type, CONF_NOSAVE, 0, 0, NULL },
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
157 { "show-profile", show_profile, CONF_TYPE_PRINT_FUNC, CONF_NOCFG, 0, 0, NULL },
17472
526abfe30498 Make -list-options work in both MPlayer and MEncoder.
albeu
parents: 17471
diff changeset
158 { "list-options", list_options, CONF_TYPE_PRINT_FUNC, CONF_NOCFG, 0, 0, NULL },
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
159 { NULL, NULL, NULL, 0, 0, 0, NULL }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
160 };
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
161 int i;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
162
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18335
diff changeset
163 config = calloc(1,sizeof(m_config_t));
33479
a5a0019e1c28 Pass m_config_new() error information to caller.
ib
parents: 33397
diff changeset
164 if (!config) return NULL;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
165 config->lvl = 1; // 0 Is the defaults
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25634
diff changeset
166 if(!initialized) {
afa125da85cf typo fix: inited --> initialized
diego
parents: 25634
diff changeset
167 initialized = 1;
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
168 profile_opt_type = m_option_type_string_list;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
169 profile_opt_type.parse = parse_profile;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
170 profile_opt_type.set = set_profile;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
171 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
172 config->self_opts = malloc(sizeof(ref_opts));
33479
a5a0019e1c28 Pass m_config_new() error information to caller.
ib
parents: 33397
diff changeset
173 if (!config->self_opts) {
a5a0019e1c28 Pass m_config_new() error information to caller.
ib
parents: 33397
diff changeset
174 free(config);
a5a0019e1c28 Pass m_config_new() error information to caller.
ib
parents: 33397
diff changeset
175 return NULL;
a5a0019e1c28 Pass m_config_new() error information to caller.
ib
parents: 33397
diff changeset
176 }
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
177 memcpy(config->self_opts,ref_opts,sizeof(ref_opts));
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
178 for(i = 0 ; config->self_opts[i].name ; i++)
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
179 config->self_opts[i].priv = config;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
180 m_config_register_options(config,config->self_opts);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
181
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
182 return config;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
183 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
184
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
185 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
186 m_config_free(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
187 m_config_option_t *i = config->opts, *ct;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
188 m_config_save_slot_t *sl,*st;
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
189 m_profile_t *p,*pn;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
190 int j;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
191
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
192 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
193 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
194 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
195
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
196 while(i) {
13824
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
197 if (i->flags & M_CFG_OPT_ALIAS)
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
198 sl = NULL;
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
199 else
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
200 sl = i->slots;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
201 while(sl) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
202 m_option_free(i->opt,sl->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
203 st = sl->prev;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
204 free(sl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
205 sl = st;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
206 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
207 if(i->name != i->opt->name)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
208 free(i->name);
33397
30e60125c2f4 Add missing m_option_free() to m_config_free().
ib
parents: 32511
diff changeset
209 if(i->opt->p && (i->opt->type->flags & M_OPT_TYPE_DYNAMIC))
30e60125c2f4 Add missing m_option_free() to m_config_free().
ib
parents: 32511
diff changeset
210 m_option_free(i->opt, i->opt->p);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
211 ct = i->next;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
212 free(i);
13824
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
213 i = ct;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
214 }
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
215 for(p = config->profiles ; p ; p = pn) {
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
216 pn = p->next;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
217 free(p->name);
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32301
diff changeset
218 free(p->desc);
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
219 for(j = 0 ; j < p->num_opts ; j++) {
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
220 free(p->opts[2*j]);
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32301
diff changeset
221 free(p->opts[2*j + 1]);
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
222 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
223 free(p->opts);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
224 free(p);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
225 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
226 free(config->self_opts);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
227 free(config);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
228 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
229
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
230 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
231 m_config_push(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
232 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
233 m_config_save_slot_t *slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
234
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
235 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
236 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
237 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
238 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
239
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
240 config->lvl++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
241
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
242 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
243 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
244 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
245 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
246 continue;
21054
7d5035aafcc6 Fix obvious typo, although the exact effect is still unclear to me, see also bug #593.
reimar
parents: 18879
diff changeset
247 if((co->opt->flags & M_OPT_OLD) && !(co->flags & M_CFG_OPT_SET))
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
248 continue;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
249 if(co->flags & M_CFG_OPT_ALIAS)
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
250 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
251
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
252 // Update the current status
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
253 m_option_save(co->opt,co->slots->data,co->opt->p);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
254
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
255 // Allocate a new slot
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18335
diff changeset
256 slot = calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
257 slot->lvl = config->lvl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
258 slot->prev = co->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
259 co->slots = slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
260 m_option_copy(co->opt,co->slots->data,co->slots->prev->data);
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
261 // Reset our set flag
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
262 co->flags &= ~M_CFG_OPT_SET;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
263 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
264
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
265 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level is now %d\n",config->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
266 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
267
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
268 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
269 m_config_pop(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
270 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
271 m_config_save_slot_t *slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
272
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
273 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
274 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
275 assert(config->lvl > 1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
276 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
277
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
278 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
279 int pop = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
280 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
281 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
282 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
283 continue;
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
284 if(co->flags & M_CFG_OPT_ALIAS)
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
285 continue;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
286 if(co->slots->lvl > config->lvl)
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
287 mp_msg(MSGT_CFGPARSER, MSGL_WARN,MSGTR_SaveSlotTooOld,config->lvl,co->slots->lvl);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
288
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
289 while(co->slots->lvl >= config->lvl) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
290 m_option_free(co->opt,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
291 slot = co->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
292 co->slots = slot->prev;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
293 free(slot);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
294 pop++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
295 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
296 if(pop) // We removed some ctx -> set the previous value
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
297 m_option_set(co->opt,co->opt->p,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
298 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
299
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
300 config->lvl--;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
301 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config poped level=%d\n",config->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
302 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
303
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
304 static void
25225
51c23a18a17b First try to mark some things in m_config correctly as const
reimar
parents: 23868
diff changeset
305 m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefix) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
306 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
307 m_config_save_slot_t* sl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
308
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
309 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
310 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
311 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
312 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
313 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
314
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
315 // Allocate a new entry for this option
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18335
diff changeset
316 co = calloc(1,sizeof(m_config_option_t) + arg->type->size);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
317 co->opt = arg;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
318
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
319 // Fill in the full name
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
320 if(prefix && strlen(prefix) > 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
321 int l = strlen(prefix) + 1 + strlen(arg->name) + 1;
23806
0a38ad149c5c Remove some more useless *alloc casts
reimar
parents: 21054
diff changeset
322 co->name = malloc(l);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
323 sprintf(co->name,"%s:%s",prefix,arg->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
324 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
325 co->name = arg->name;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
326
23868
09c2fe1e021d Fix some typos in comments
reimar
parents: 23806
diff changeset
327 // Option with children -> add them
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
328 if(arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
25225
51c23a18a17b First try to mark some things in m_config correctly as const
reimar
parents: 23868
diff changeset
329 const m_option_t *ol = arg->p;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
330 int i;
13824
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
331 co->slots = NULL;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
332 for(i = 0 ; ol[i].name != NULL ; i++)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
333 m_config_add_option(config,&ol[i], co->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
334 } else {
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
335 m_config_option_t *i;
23868
09c2fe1e021d Fix some typos in comments
reimar
parents: 23806
diff changeset
336 // Check if there is already an option pointing to this address
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
337 if(arg->p) {
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
338 for(i = config->opts ; i ; i = i->next ) {
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
339 if(i->opt->p == arg->p) { // So we don't save the same vars more than 1 time
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
340 co->slots = i->slots;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
341 co->flags |= M_CFG_OPT_ALIAS;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
342 break;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
343 }
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
344 }
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
345 }
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
346 if(!(co->flags & M_CFG_OPT_ALIAS)) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
347 // Allocate a slot for the defaults
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18335
diff changeset
348 sl = calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
349 m_option_save(arg,sl->data,(void**)arg->p);
23868
09c2fe1e021d Fix some typos in comments
reimar
parents: 23806
diff changeset
350 // Hack to avoid too much trouble with dynamically allocated data :
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
351 // We always use a dynamic version
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
352 if((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p && (*(void**)arg->p)) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
353 *(void**)arg->p = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
354 m_option_set(arg,arg->p,sl->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
355 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
356 sl->lvl = 0;
13824
bad703951cf9 a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
faust3
parents: 13699
diff changeset
357 sl->prev = NULL;
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18335
diff changeset
358 co->slots = calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
359 co->slots->prev = sl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
360 co->slots->lvl = config->lvl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
361 m_option_copy(co->opt,co->slots->data,sl->data);
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
362 } // !M_OPT_ALIAS
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
363 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
364 co->next = config->opts;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
365 config->opts = co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
366 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
367
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
368 int
25225
51c23a18a17b First try to mark some things in m_config correctly as const
reimar
parents: 23868
diff changeset
369 m_config_register_options(m_config_t *config, const m_option_t *args) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
370 int i;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
371
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
372 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
373 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
374 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
375 assert(args != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
376 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
377
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
378 for(i = 0 ; args[i].name != NULL ; i++)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
379 m_config_add_option(config,&args[i],NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
380
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
381 return 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
382 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
383
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
384 static m_config_option_t*
32300
1ca3d798b518 Mark some function parameters that are not modified as const.
diego
parents: 30728
diff changeset
385 m_config_get_co(const m_config_t *config, char *arg) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
386 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
387
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
388 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
389 int l = strlen(co->name) - 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26408
diff changeset
390 if((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) &&
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
391 (co->name[l] == '*')) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
392 if(strncasecmp(co->name,arg,l) == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
393 return co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
394 } else if(strcasecmp(co->name,arg) == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
395 return co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
396 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
397 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
398 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
399
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
400 static int
32300
1ca3d798b518 Mark some function parameters that are not modified as const.
diego
parents: 30728
diff changeset
401 m_config_parse_option(const m_config_t *config, char *arg, char *param, int set) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
402 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
403 int r = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
404
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
405 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
406 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
407 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
408 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
409 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
410
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
411 co = m_config_get_co(config,arg);
8892
06843e67a04b print meaningful error message
arpi
parents: 8512
diff changeset
412 if(!co){
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
413 // mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Unknown option: %s\n",arg);
10595
522afd56703c 100l to albeu for his english grammar, and 10l to me becouse I noticed that lately (my backward compatibilty macro uses M_OPT_UNKNOWN)
alex
parents: 10594
diff changeset
414 return M_OPT_UNKNOWN;
8892
06843e67a04b print meaningful error message
arpi
parents: 8512
diff changeset
415 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
416
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
417 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
418 // This is the only mandatory function
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
419 assert(co->opt->type->parse);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
420 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
421
23868
09c2fe1e021d Fix some typos in comments
reimar
parents: 23806
diff changeset
422 // Check if this option isn't forbidden in the current mode
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
423 if((config->mode == M_CONFIG_FILE) && (co->opt->flags & M_OPT_NOCFG)) {
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
424 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCfgfileOption,arg);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
425 return M_OPT_INVALID;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
426 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
427 if((config->mode == M_COMMAND_LINE) && (co->opt->flags & M_OPT_NOCMD)) {
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
428 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCmdlineOption,arg);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
429 return M_OPT_INVALID;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
430 }
26408
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
431 // During command line preparse set only pre-parse options
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
432 // Otherwise only set pre-parse option if they were not already set.
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
433 if(((config->mode == M_COMMAND_LINE_PRE_PARSE) &&
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
434 !(co->opt->flags & M_OPT_PRE_PARSE)) ||
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
435 ((config->mode != M_COMMAND_LINE_PRE_PARSE) &&
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
436 (co->opt->flags & M_OPT_PRE_PARSE) && (co->flags & M_CFG_OPT_SET)))
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26288
diff changeset
437 set = 0;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
438
23868
09c2fe1e021d Fix some typos in comments
reimar
parents: 23806
diff changeset
439 // Option with children are a bit different to parse
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
440 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
441 char** lst = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
442 int i,sr;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
443 // Parse the child options
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9222
diff changeset
444 r = m_option_parse(co->opt,arg,param,&lst,M_COMMAND_LINE);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
445 // Set them now
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
446 if(r >= 0)
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
447 for(i = 0 ; lst && lst[2*i] ; i++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
448 int l = strlen(co->name) + 1 + strlen(lst[2*i]) + 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
449 if(r >= 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
450 // Build the full name
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
451 char n[l];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
452 sprintf(n,"%s:%s",co->name,lst[2*i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
453 sr = m_config_parse_option(config,n,lst[2*i+1],set);
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
454 if(sr < 0){
10595
522afd56703c 100l to albeu for his english grammar, and 10l to me becouse I noticed that lately (my backward compatibilty macro uses M_OPT_UNKNOWN)
alex
parents: 10594
diff changeset
455 if(sr == M_OPT_UNKNOWN){
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
456 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidSuboption,co->name,lst[2*i]);
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
457 r = M_OPT_INVALID;
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
458 } else
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
459 if(sr == M_OPT_MISSING_PARAM){
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
460 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_MissingSuboptionParameter,lst[2*i],co->name);
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
461 r = M_OPT_INVALID;
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
462 } else
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
463 r = sr;
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
464 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
465 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
466 free(lst[2*i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
467 free(lst[2*i+1]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
468 }
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32301
diff changeset
469 free(lst);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
470 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
471 r = m_option_parse(co->opt,arg,param,set ? co->slots->data : NULL,config->mode);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
472
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
473 // Parsing failed ?
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
474 if(r < 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
475 return r;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
476 // Set the option
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
477 if(set) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
478 m_option_set(co->opt,co->opt->p,co->slots->data);
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
479 co->flags |= M_CFG_OPT_SET;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
480 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
481
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
482 return r;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
483 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
484
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
485 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
486 m_config_set_option(m_config_t *config, char* arg, char* param) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
487 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Setting %s=%s\n",arg,param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
488 return m_config_parse_option(config,arg,param,1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
489 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
490
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
491 int
32300
1ca3d798b518 Mark some function parameters that are not modified as const.
diego
parents: 30728
diff changeset
492 m_config_check_option(const m_config_t *config, char *arg, char *param) {
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
493 int r;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
494 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Checking %s=%s\n",arg,param);
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
495 r=m_config_parse_option(config,arg,param,0);
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
496 if(r==M_OPT_MISSING_PARAM){
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
497 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_MissingOptionParameter,arg);
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
498 return M_OPT_INVALID;
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
499 }
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
500 return r;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
501 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
502
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
503
25225
51c23a18a17b First try to mark some things in m_config correctly as const
reimar
parents: 23868
diff changeset
504 const m_option_t*
32300
1ca3d798b518 Mark some function parameters that are not modified as const.
diego
parents: 30728
diff changeset
505 m_config_get_option(const m_config_t *config, char *arg) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
506 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
507
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
508 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
509 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
510 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
511 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
512 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
513
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
514 co = m_config_get_co(config,arg);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
515 if(co)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
516 return co->opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
517 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
518 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
519 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
520
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
521
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
522 void
32300
1ca3d798b518 Mark some function parameters that are not modified as const.
diego
parents: 30728
diff changeset
523 m_config_print_option_list(const m_config_t *config) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
524 char min[50],max[50];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
525 m_config_option_t* co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
526 int count = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
527
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
528 if(!config->opts) return;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
529
17481
99c0caec4677 Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents: 17472
diff changeset
530 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_OptionListHeader);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
531 for(co = config->opts ; co ; co = co->next) {
25225
51c23a18a17b First try to mark some things in m_config correctly as const
reimar
parents: 23868
diff changeset
532 const m_option_t* opt = co->opt;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
533 if(opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
534 if(opt->flags & M_OPT_MIN)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
535 sprintf(min,"%-8.0f",opt->min);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
536 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
537 strcpy(min,"No");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
538 if(opt->flags & M_OPT_MAX)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
539 sprintf(max,"%-8.0f",opt->max);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
540 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
541 strcpy(max,"No");
17481
99c0caec4677 Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents: 17472
diff changeset
542 mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-20.20s %-15.15s %-10.10s %-10.10s %-3.3s %-3.3s %-3.3s\n",
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
543 co->name,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
544 co->opt->type->name,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
545 min,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
546 max,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
547 opt->flags & CONF_GLOBAL ? "Yes" : "No",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
548 opt->flags & CONF_NOCMD ? "No" : "Yes",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
549 opt->flags & CONF_NOCFG ? "No" : "Yes");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
550 count++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
551 }
17481
99c0caec4677 Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents: 17472
diff changeset
552 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_TotalOptions,count);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
553 }
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
554
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
555 m_profile_t*
32300
1ca3d798b518 Mark some function parameters that are not modified as const.
diego
parents: 30728
diff changeset
556 m_config_get_profile(const m_config_t *config, char *name) {
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
557 m_profile_t* p;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
558 for(p = config->profiles ; p ; p = p->next)
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
559 if(!strcmp(p->name,name)) return p;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
560 return NULL;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
561 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
562
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
563 m_profile_t*
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
564 m_config_add_profile(m_config_t* config, char* name) {
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
565 m_profile_t* p = m_config_get_profile(config,name);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
566 if(p) return p;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
567 p = calloc(1,sizeof(m_profile_t));
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
568 p->name = strdup(name);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
569 p->next = config->profiles;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
570 config->profiles = p;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
571 return p;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
572 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
573
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
574 void
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
575 m_profile_set_desc(m_profile_t* p, char* desc) {
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32301
diff changeset
576 free(p->desc);
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
577 p->desc = desc ? strdup(desc) : NULL;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
578 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
579
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
580 int
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
581 m_config_set_profile_option(m_config_t* config, m_profile_t* p,
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
582 char* name, char* val) {
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
583 int i = m_config_check_option(config,name,val);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
584 if(i < 0) return i;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
585 if(p->opts) p->opts = realloc(p->opts,2*(p->num_opts+2)*sizeof(char*));
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
586 else p->opts = malloc(2*(p->num_opts+2)*sizeof(char*));
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
587 p->opts[p->num_opts*2] = strdup(name);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
588 p->opts[p->num_opts*2+1] = val ? strdup(val) : NULL;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
589 p->num_opts++;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
590 p->opts[p->num_opts*2] = p->opts[p->num_opts*2+1] = NULL;
17856
98f0e0542cb6 10L fix missing return statement.
albeu
parents: 17481
diff changeset
591 return 1;
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
592 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
593
25634
4344e84f7a9f export m_config_set_profile()
ben
parents: 25225
diff changeset
594 void
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
595 m_config_set_profile(m_config_t* config, m_profile_t* p) {
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
596 int i;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
597 if(config->profile_depth > MAX_PROFILE_DEPTH) {
18335
5766a9d21992 Rename some misspelled and misnamed messages.
diego
parents: 18258
diff changeset
598 mp_msg(MSGT_CFGPARSER, MSGL_WARN, MSGTR_ProfileInclusionTooDeep);
17471
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
599 return;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
600 }
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
601 config->profile_depth++;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
602 for(i = 0 ; i < p->num_opts ; i++)
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
603 m_config_set_option(config,p->opts[2*i],p->opts[2*i+1]);
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
604 config->profile_depth--;
63909962d3fc Profiles support.
albeu
parents: 13824
diff changeset
605 }