annotate cfgparser.c @ 245:cb4c682746c0

disabled scrollback buffer (virtual fb size set to real screen size)
author szabii
date Thu, 29 Mar 2001 13:58:54 +0000
parents 452453f82bfa
children e24fe1b5b918
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
1 /*
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
2 * command line and config file parser
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
3 */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
4
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
5 //#define DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
6
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
7 #include <stdlib.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
8 #include <stdio.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
9 #include <ctype.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
10 #include <unistd.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
11 #include <fcntl.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
12 #include <string.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
13
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
14 #define ERR_NOT_AN_OPTION -1
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
15 #define ERR_MISSING_PARAM -2
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
16 #define ERR_OUT_OF_RANGE -3
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
17 #define ERR_FUNC_ERR -4
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
18
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
19 #define COMMAND_LINE 0
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
20 #define CONFIG_FILE 1
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
21
177
szabii
parents: 167
diff changeset
22 #define MAX_RECURSION_DEPTH 8
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
23
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
24 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
25 #include <assert.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
26 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
27
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
28 #include "cfgparser.h"
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
29
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
30 static struct config *config;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
31 static int nr_options; /* number of options in 'conf' */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
32 static int parser_mode; /* COMMAND_LINE or CONFIG_FILE */
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
33 static int recursion_depth = 0;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
34
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
35 static int init_conf(struct config *conf, int mode)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
36 {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
37 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
38 assert(conf != NULL);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
39 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
40
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
41 /* calculate the number of options in 'conf' */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
42 for (nr_options = 0; conf[nr_options].name != NULL; nr_options++)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
43 /* NOTHING */;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
44
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
45 config = conf;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
46 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
47 if (mode != COMMAND_LINE && mode != CONFIG_FILE) {
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
48 printf("init_conf: wrong mode!\n");
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
49 return -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
50 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
51 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
52 parser_mode = mode;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
53 return 1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
54 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
55
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
56 static int read_option(char *opt, char *param)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
57 {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
58 int i;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
59 long tmp_int;
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
60 double tmp_float;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
61 int ret = -1;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
62 char *endptr;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
63
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
64 for (i = 0; i < nr_options; i++) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
65 if (!strcasecmp(opt, config[i].name))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
66 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
67 }
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
68 if (i == nr_options) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
69 printf("invalid option:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
70 ret = ERR_NOT_AN_OPTION;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
71 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
72 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
73 if (config[i].flags & CONF_NOCFG && parser_mode == CONFIG_FILE) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
74 printf("this option can only be used on command line:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
75 ret = ERR_NOT_AN_OPTION;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
76 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
77 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
78 if (config[i].flags & CONF_NOCMD && parser_mode == COMMAND_LINE) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
79 printf("this option can only be used in config file:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
80 ret = ERR_NOT_AN_OPTION;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
81 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
82 }
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
83
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
84 switch (config[i].type) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
85 case CONF_TYPE_FLAG:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
86 /* flags need a parameter in config file */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
87 if (parser_mode == CONFIG_FILE) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
88 if (!strcasecmp(param, "yes") || /* any other language? */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
89 !strcasecmp(param, "ja") ||
161
9008302e2dc0 Added support for spanish (Yes, I'm a C programer also ;o)
telenieko
parents: 160
diff changeset
90 !strcasecmp(param, "si") ||
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
91 !strcasecmp(param, "igen") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
92 !strcasecmp(param, "y") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
93 !strcasecmp(param, "i") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
94 !strcmp(param, "1"))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
95 *((int *) config[i].p) = config[i].max;
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
96 else if (!strcasecmp(param, "no") ||
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
97 !strcasecmp(param, "nein") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
98 !strcasecmp(param, "nicht") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
99 !strcasecmp(param, "nem") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
100 !strcasecmp(param, "n") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
101 !strcmp(param, "0"))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
102 *((int *) config[i].p) = config[i].min;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
103 else {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
104 printf("invalid parameter for flag:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
105 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
106 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
107 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
108 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
109 } else { /* parser_mode == COMMAND_LINE */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
110 *((int *) config[i].p) = config[i].max;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
111 ret = 0;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
112 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
113 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
114 case CONF_TYPE_INT:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
115 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
116 goto err_missing_param;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
117
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
118 tmp_int = strtol(param, &endptr, 0);
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
119 if (*endptr) {
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
120 printf("parameter must be an integer:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
121 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
122 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
123 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
124
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
125 if (config[i].flags & CONF_MIN)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
126 if (tmp_int < config[i].min) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
127 printf("parameter must be >= %d:\n", (int) config[i].min);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
128 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
129 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
130 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
131
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
132 if (config[i].flags & CONF_MAX)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
133 if (tmp_int > config[i].max) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
134 printf("parameter must be <= %d:\n", (int) config[i].max);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
135 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
136 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
137 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
138
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
139 *((int *) config[i].p) = tmp_int;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
140 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
141 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
142 case CONF_TYPE_FLOAT:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
143 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
144 goto err_missing_param;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
145
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
146 tmp_float = strtod(param, &endptr);
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
147 if (*endptr) {
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
148 printf("parameter must be a floating point number:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
149 ret = ERR_MISSING_PARAM;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
150 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
151 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
152
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
153 if (config[i].flags & CONF_MIN)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
154 if (tmp_float < config[i].min) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
155 printf("parameter must be >= %f:\n", config[i].min);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
156 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
157 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
158 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
159
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
160 if (config[i].flags & CONF_MAX)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
161 if (tmp_float > config[i].max) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
162 printf("parameter must be <= %f:\n", config[i].max);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
163 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
164 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
165 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
166
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
167 *((float *) config[i].p) = tmp_float;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
168 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
169 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
170 case CONF_TYPE_STRING:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
171 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
172 goto err_missing_param;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
173
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
174 if (config[i].flags & CONF_MIN)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
175 if (strlen(param) < config[i].min) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
176 printf("parameter must be >= %d chars:\n",
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
177 (int) config[i].min);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
178 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
179 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
180 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
181
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
182 if (config[i].flags & CONF_MAX)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
183 if (strlen(param) > config[i].max) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
184 printf("parameter must be <= %d chars:\n",
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
185 (int) config[i].max);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
186 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
187 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
188 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
189
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
190 *((char **) config[i].p) = strdup(param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
191 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
192 break;
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
193 case CONF_TYPE_FUNC_PARAM:
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
194 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
195 goto err_missing_param;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
196 if ((((cfg_func_param_t) config[i].p)(config + i, param)) < 0) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
197 ret = ERR_FUNC_ERR;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
198 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
199 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
200 ret = 1;
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
201 break;
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
202 case CONF_TYPE_FUNC:
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
203 if ((((cfg_func_t) config[i].p)(config + i)) < 0) {
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
204 ret = ERR_FUNC_ERR;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
205 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
206 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
207 ret = 0;
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
208 break;
152
372a9a836e86 cfgparser fix
szabii
parents: 151
diff changeset
209 case CONF_TYPE_PRINT:
372a9a836e86 cfgparser fix
szabii
parents: 151
diff changeset
210 printf("%s", (char *) config[i].p);
372a9a836e86 cfgparser fix
szabii
parents: 151
diff changeset
211 exit(1);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
212 default:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
213 printf("picsaba\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
214 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
215 }
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
216 out:
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
217 return ret;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
218 err_missing_param:
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
219 printf("missing parameter:\n");
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
220 ret = ERR_MISSING_PARAM;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
221 goto out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
222 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
223
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
224 int parse_config_file(struct config *conf, char *conffile)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
225 {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
226 #define PRINT_LINENUM printf("%s(%d): ", conffile, line_num)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
227 #define MAX_LINE_LEN 1000
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
228 #define MAX_OPT_LEN 100
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
229 #define MAX_PARAM_LEN 100
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
230 FILE *fp;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
231 char *line;
179
szabii
parents: 177
diff changeset
232 char opt[MAX_OPT_LEN + 1];
szabii
parents: 177
diff changeset
233 char param[MAX_PARAM_LEN + 1];
167
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
234 char c; /* for the "" and '' check */
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
235 int tmp;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
236 int line_num = 0;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
237 int line_pos; /* line pos */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
238 int opt_pos; /* opt pos */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
239 int param_pos; /* param pos */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
240 int ret = 1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
241
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
242 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
243 assert(conffile != NULL);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
244 #endif
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
245 if (++recursion_depth > MAX_RECURSION_DEPTH) {
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
246 printf("too deep 'include'. check your configfiles\n");
179
szabii
parents: 177
diff changeset
247 --recursion_depth;
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
248 return -1;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
249 }
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
250
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
251 printf("Reading config file: %s\n", conffile);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
252
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
253 if (init_conf(conf, CONFIG_FILE) == -1) {
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
254 ret = -1;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
255 goto out;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
256 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
257
179
szabii
parents: 177
diff changeset
258 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
259 perror("parse_config_file: can't get memory for 'line'");
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
260 ret = -1;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
261 goto out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
262 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
263
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
264 if ((fp = fopen(conffile, "r")) == NULL) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
265 perror("parse_config_file: can't open filename");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
266 free(line);
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
267 ret = 0;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
268 goto out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
269 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
270
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
271 while (fgets(line, MAX_LINE_LEN, fp)) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
272 line_num++;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
273 line_pos = 0;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
274
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
275 /* skip whitespaces */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
276 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
277 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
278
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
279 /* EOL / comment */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
280 if (line[line_pos] == '\0' || line[line_pos] == '#')
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
281 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
282
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
283 /* read option. accept char if isalnum(char) */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
284 for (opt_pos = 0; isalnum(line[line_pos]); /* NOTHING */) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
285 opt[opt_pos++] = line[line_pos++];
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
286 if (opt_pos >= MAX_OPT_LEN) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
287 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
288 printf("too long option\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
289 ret = -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
290 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
291 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
292 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
293 if (opt_pos == 0) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
294 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
295 printf("parse error\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
296 ret = -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
297 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
298 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
299 opt[opt_pos] = '\0';
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
300 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
301 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
302 printf("option: %s\n", opt);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
303 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
304
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
305 /* skip whitespaces */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
306 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
307 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
308
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
309 /* check '=' */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
310 if (line[line_pos++] != '=') {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
311 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
312 printf("option without parameter\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
313 ret = -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
314 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
315 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
316
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
317 /* whitespaces... */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
318 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
319 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
320
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
321 /* read the parameter */
167
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
322 if (line[line_pos] == '"' || line[line_pos] == '\'') {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
323 c = line[line_pos];
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
324 ++line_pos;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
325 for (param_pos = 0; line[line_pos] != c; /* NOTHING */) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
326 param[param_pos++] = line[line_pos++];
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
327 if (param_pos >= MAX_PARAM_LEN) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
328 PRINT_LINENUM;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
329 printf("too long parameter\n");
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
330 ret = -1;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
331 continue;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
332 }
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
333 }
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
334 line_pos++; /* skip the closing " or ' */
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
335 } else {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
336 for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos])
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
337 && line[line_pos] != '#'; /* NOTHING */) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
338 param[param_pos++] = line[line_pos++];
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
339 if (param_pos >= MAX_PARAM_LEN) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
340 PRINT_LINENUM;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
341 printf("too long parameter\n");
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
342 ret = -1;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
343 continue;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
344 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
345 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
346 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
347 param[param_pos] = '\0';
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
348
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
349 /* did we read a parameter? */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
350 if (param_pos == 0) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
351 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
352 printf("option without parameter\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
353 ret = -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
354 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
355 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
356 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
357 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
358 printf("parameter: %s\n", param);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
359 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
360 /* now, check if we have some more chars on the line */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
361 /* whitespace... */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
362 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
363 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
364
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
365 /* EOL / comment */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
366 if (line[line_pos] != '\0' && line[line_pos] != '#') {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
367 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
368 printf("extra characters on line: %s\n", line+line_pos);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
369 ret = -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
370 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
371
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
372 tmp = read_option(opt, param);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
373 switch (tmp) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
374 case ERR_NOT_AN_OPTION:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
375 case ERR_MISSING_PARAM:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
376 case ERR_OUT_OF_RANGE:
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
377 case ERR_FUNC_ERR:
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
378 PRINT_LINENUM;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
379 printf("%s\n", opt);
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
380 ret = -1;
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
381 continue;
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
382 /* break */
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
383 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
384 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
385
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
386 free(line);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
387 fclose(fp);
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
388 out:
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
389 --recursion_depth;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
390 return ret;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
391 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
392
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
393 int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char **filename)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
394 {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
395 int i;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
396 int found_filename = 0;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
397 int tmp;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
398 char *opt;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
399
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
400 #ifdef DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
401 assert(argv != NULL);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
402 assert(envp != NULL);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
403 assert(argc >= 1);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
404 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
405
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
406 if (init_conf(conf, COMMAND_LINE) == -1)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
407 return -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
408
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
409 for (i = 1; i < argc; i++) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
410 opt = argv[i];
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
411 if (*opt != '-')
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
412 goto not_an_option;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
413
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
414 /* remove trailing '-' */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
415 opt++;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
416
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
417 tmp = read_option(opt, argv[i + 1]);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
418
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
419 switch (tmp) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
420 case ERR_NOT_AN_OPTION:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
421 not_an_option:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
422 /* opt is not an option -> treat it as a filename */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
423 if (found_filename) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
424 /* we already have a filename */
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
425 goto err_out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
426 } else {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
427 found_filename = 1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
428 *filename = argv[i];
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
429 printf("parse_command_line: found filename: %s\n", *filename);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
430 continue; /* next option */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
431 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
432 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
433 case ERR_MISSING_PARAM:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
434 case ERR_OUT_OF_RANGE:
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
435 case ERR_FUNC_ERR:
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
436 goto err_out;
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
437 /* break; */
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
438 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
439
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
440 i += tmp; /* we already processed the params (if there was any) */
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
441 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
442 return found_filename;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
443 err_out:
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
444 printf("parse_command_line: %s\n", argv[i]);
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
445 return -1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
446 }