annotate cfgparser.c @ 979:3bcc435cd5a2

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