annotate parser-cfg.c @ 29169:5c48a1cdd1d7

small typo fixes
author diego
date Mon, 20 Apr 2009 15:35:34 +0000
parents 7a36d5941fd8
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
1
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
2 /// \defgroup ConfigParsers Config parsers
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
3 ///
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
4 /// The \ref ConfigParsers make use of the \ref Config to setup the config variables,
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
5 /// the command line parsers also build the playlist.
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
6 ///@{
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
7
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
8 /// \file
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
9
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
10 #include "config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
11
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
12 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
13 #include <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
14 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
15 #include <errno.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
16 #include <ctype.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
17
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
18 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
19 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
20 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
21
26263
65d1238b3631 Include some .h files in corresponding .c files
uau
parents: 23806
diff changeset
22 #include "parser-cfg.h"
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
23 #include "mp_msg.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24 #include "m_option.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 #include "m_config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
26
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
27 /// Maximal include depth.
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
28 #define MAX_RECURSION_DEPTH 8
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
29
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
30 /// Current include depth.
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
31 static int recursion_depth = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
32
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
33 /// Setup the \ref Config from a config file.
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
34 /** \param config The config object.
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
35 * \param conffile Path to the config file.
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
36 * \return 1 on sucess, -1 on error.
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
37 */
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
38 int m_config_parse_config_file(m_config_t* config, char *conffile)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
39 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
40 #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num)
9813
b0141de527df longer option buffers, needed for tv options
henry
parents: 9578
diff changeset
41 #define MAX_LINE_LEN 10000
b0141de527df longer option buffers, needed for tv options
henry
parents: 9578
diff changeset
42 #define MAX_OPT_LEN 1000
21799
a6911070ac6e increased a bit max param length as it can be too short to declare tv channels when you have a long list of
ben
parents: 19462
diff changeset
43 #define MAX_PARAM_LEN 1500
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
44 FILE *fp;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
45 char *line;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
46 char opt[MAX_OPT_LEN + 1];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
47 char param[MAX_PARAM_LEN + 1];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
48 char c; /* for the "" and '' check */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
49 int tmp;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
50 int line_num = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
51 int line_pos; /* line pos */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
52 int opt_pos; /* opt pos */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
53 int param_pos; /* param pos */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
54 int ret = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
55 int errors = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
56 int prev_mode = config->mode;
17471
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
57 m_profile_t* profile = NULL;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
58
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
59 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
60 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
61 // assert(conf_list != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
62 #endif
13946
e632b43f0598 Reduce excessive verbosity.
diego
parents: 10595
diff changeset
63 mp_msg(MSGT_CFGPARSER,MSGL_V,"Reading config file %s", conffile);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
64
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
65 if (recursion_depth > MAX_RECURSION_DEPTH) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
66 mp_msg(MSGT_CFGPARSER,MSGL_ERR,": too deep 'include'. check your configfiles\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
67 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
68 goto out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
69 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
70
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
71 config->mode = M_CONFIG_FILE;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
72
23806
0a38ad149c5c Remove some more useless *alloc casts
reimar
parents: 21799
diff changeset
73 if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
74 mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"\ncan't get memory for 'line': %s", strerror(errno));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
75 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
76 goto out;
19462
08fc089138f4 Fix stray newline that should only be printed in verbose mode.
diego
parents: 18265
diff changeset
77 } else
08fc089138f4 Fix stray newline that should only be printed in verbose mode.
diego
parents: 18265
diff changeset
78
08fc089138f4 Fix stray newline that should only be printed in verbose mode.
diego
parents: 18265
diff changeset
79 mp_msg(MSGT_CFGPARSER,MSGL_V,"\n");
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
80
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
81 if ((fp = fopen(conffile, "r")) == NULL) {
13946
e632b43f0598 Reduce excessive verbosity.
diego
parents: 10595
diff changeset
82 mp_msg(MSGT_CFGPARSER,MSGL_V,": %s\n", strerror(errno));
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
83 free(line);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
84 ret = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
85 goto out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
86 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
87
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
88 while (fgets(line, MAX_LINE_LEN, fp)) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
89 if (errors >= 16) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
90 mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"too many errors\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
91 goto out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
92 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
93
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
94 line_num++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
95 line_pos = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
96
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
97 /* skip whitespaces */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
98 while (isspace(line[line_pos]))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
99 ++line_pos;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
100
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
101 /* EOL / comment */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
102 if (line[line_pos] == '\0' || line[line_pos] == '#')
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
103 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
104
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
105 /* read option. */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
106 for (opt_pos = 0; isprint(line[line_pos]) &&
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
107 line[line_pos] != ' ' &&
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
108 line[line_pos] != '#' &&
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
109 line[line_pos] != '='; /* NOTHING */) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
110 opt[opt_pos++] = line[line_pos++];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
111 if (opt_pos >= MAX_OPT_LEN) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
112 PRINT_LINENUM;
9578
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
113 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long option at line %d\n",line_num);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
114 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
115 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
116 goto nextline;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
117 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
118 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
119 if (opt_pos == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
120 PRINT_LINENUM;
9578
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
121 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"parse error at line %d\n",line_num);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
122 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
123 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
124 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
125 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
126 opt[opt_pos] = '\0';
17471
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
127
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
128 /* Profile declaration */
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
129 if(opt_pos > 2 && opt[0] == '[' && opt[opt_pos-1] == ']') {
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
130 opt[opt_pos-1] = '\0';
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
131 if(strcmp(opt+1,"default"))
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
132 profile = m_config_add_profile(config,opt+1);
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
133 else
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
134 profile = NULL;
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
135 continue;
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
136 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
137
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
138 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
139 PRINT_LINENUM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
140 mp_msg(MSGT_CFGPARSER,MSGL_V,"option: %s\n", opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
141 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
142
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
143 /* skip whitespaces */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
144 while (isspace(line[line_pos]))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
145 ++line_pos;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
146
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
147 /* check '=' */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
148 if (line[line_pos++] != '=') {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
149 PRINT_LINENUM;
10245
a660de2556c2 1000l! crashing on broken config files finally fixed!
rfelker
parents: 9813
diff changeset
150 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Option %s needs a parameter at line %d\n",opt,line_num);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
151 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
152 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
153 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
154 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
155
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
156 /* whitespaces... */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
157 while (isspace(line[line_pos]))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
158 ++line_pos;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
159
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
160 /* read the parameter */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
161 if (line[line_pos] == '"' || line[line_pos] == '\'') {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
162 c = line[line_pos];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
163 ++line_pos;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
164 for (param_pos = 0; line[line_pos] != c; /* NOTHING */) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
165 param[param_pos++] = line[line_pos++];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
166 if (param_pos >= MAX_PARAM_LEN) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
167 PRINT_LINENUM;
10245
a660de2556c2 1000l! crashing on broken config files finally fixed!
rfelker
parents: 9813
diff changeset
168 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Option %s has a too long parameter at line %d\n",opt,line_num);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
169 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
170 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
171 goto nextline;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
172 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
173 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
174 line_pos++; /* skip the closing " or ' */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
175 } else {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
176 for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos])
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
177 && line[line_pos] != '#'; /* NOTHING */) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
178 param[param_pos++] = line[line_pos++];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
179 if (param_pos >= MAX_PARAM_LEN) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
180 PRINT_LINENUM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
181 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long parameter\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
182 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
183 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
184 goto nextline;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
185 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
186 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
187 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
188 param[param_pos] = '\0';
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
189
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
190 /* did we read a parameter? */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
191 if (param_pos == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
192 PRINT_LINENUM;
10245
a660de2556c2 1000l! crashing on broken config files finally fixed!
rfelker
parents: 9813
diff changeset
193 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Option %s needs a parameter at line %d\n",opt,line_num);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
194 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
195 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
196 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
197 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
198
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
199 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
200 PRINT_LINENUM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
201 mp_msg(MSGT_CFGPARSER,MSGL_V,"parameter: %s\n", param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
202 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
203
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
204 /* now, check if we have some more chars on the line */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
205 /* whitespace... */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
206 while (isspace(line[line_pos]))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
207 ++line_pos;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
208
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
209 /* EOL / comment */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
210 if (line[line_pos] != '\0' && line[line_pos] != '#') {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
211 PRINT_LINENUM;
9578
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
212 mp_msg(MSGT_CFGPARSER,MSGL_WARN,"extra characters on line %d: %s\n",line_num, line+line_pos);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
213 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
214 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
215
17471
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
216 if(profile) {
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
217 if(!strcmp(opt,"profile-desc"))
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
218 m_profile_set_desc(profile,param), tmp = 1;
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
219 else
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
220 tmp = m_config_set_profile_option(config,profile,
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
221 opt,param);
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
222 } else
63909962d3fc Profiles support.
albeu
parents: 13946
diff changeset
223 tmp = m_config_set_option(config, opt, param);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
224 if (tmp < 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
225 PRINT_LINENUM;
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
226 if(tmp == M_OPT_UNKNOWN) {
9578
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
227 mp_msg(MSGT_CFGPARSER,MSGL_WARN,"Warning unknown option %s at line %d\n", opt,line_num);
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
228 continue;
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
229 }
0c5454233dcf Better error messages (with line number now) and make unknow option
albeu
parents: 8164
diff changeset
230 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Error parsing option %s=%s at line %d\n",opt,param,line_num);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
231 ret = -1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
232 errors++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
233 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
234 /* break */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
235 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
236 nextline:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
237 ;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
238 }
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 free(line);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
241 fclose(fp);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
242 out:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
243 config->mode = prev_mode;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
244 --recursion_depth;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
245 return ret;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
246 }
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
247
26408
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
248 extern int mp_msg_levels[];
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
249
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
250 /// Parse the command line option that must be handled at startup.
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
251 int m_config_preparse_command_line(m_config_t *config, int argc, char **argv)
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
252 {
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
253 int msg_lvl, i, r, ret = 0;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
254 char* arg;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
255 m_option_t* opt;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
256
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
257 // Hack to shutup the parser error messages.
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
258 msg_lvl = mp_msg_levels[MSGT_CFGPARSER];
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
259 mp_msg_levels[MSGT_CFGPARSER] = -11;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
260
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
261 config->mode = M_COMMAND_LINE_PRE_PARSE;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
262
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
263 for(i = 1 ; i < argc ; i++) {
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
264 arg = argv[i];
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
265 // Ignore non option
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
266 if(arg[0] != '-' || arg[1] == 0) continue;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
267 arg++;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
268 // No more options after --
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
269 if(arg[0] == '-' && arg[1] == 0) break;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
270
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
271 opt = m_config_get_option(config,arg);
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
272 // Ignore invalid option
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
273 if(!opt) continue;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
274 // Set, non-pre-parse options will be ignored
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
275 r = m_config_set_option(config,arg,
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
276 i+1 < argc ? argv[i+1] : NULL);
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
277 if(r < 0) ret = r;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
278 else i += r;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
279 }
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
280
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
281 mp_msg_levels[MSGT_CFGPARSER] = msg_lvl;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
282
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
283 return ret;
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
284 }
7a36d5941fd8 Replace the trivial command line preparser with a more robust version
albeu
parents: 26263
diff changeset
285
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 17471
diff changeset
286 ///@}