annotate cfgparser.c @ 596:6a6b7c471c34

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