File: | src/psk-gaa.c |
Location: | line 539, column 3 |
Description: | Value stored to 'gaa_index' is never read |
1 | /* File generated by GAA 1.6.6 |
2 | */ |
3 | #define GAA_NO_WIN32 |
4 | #line 1 "psk.gaa" |
5 | |
6 | |
7 | /* C declarations */ |
8 | |
9 | #include <config.h> |
10 | #ifdef _WIN32 |
11 | # include <io.h> |
12 | #endif |
13 | |
14 | void psktool_version(void); |
15 | |
16 | #include <stdio.h> |
17 | #include <string.h> |
18 | #include <stdlib.h> |
19 | |
20 | #ifndef GAA_NO_WIN32 |
21 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS) |
22 | #define GAA_WIN32 |
23 | #endif |
24 | #endif |
25 | |
26 | static void* gaa_malloc( size_t size) { |
27 | void* ret; |
28 | ret = malloc(size); |
29 | if (ret==NULL((void*)0)) { |
30 | fprintf(stderrstderr, "gaa: could not allocate memory"); |
31 | exit(1); |
32 | } |
33 | return ret; |
34 | } |
35 | |
36 | static void __gaa_helpsingle(char short_name, char *name, |
37 | char *arg_desc, char *opt_help) |
38 | { |
39 | int col1, col3, col4, tabsize = 3, curr; |
40 | int i; |
41 | |
42 | col1 = 5; /* Default values */ |
43 | col3 = 30; |
44 | col4 = 70; |
45 | |
46 | curr = 0; |
47 | for(i = 0; i < col1; i++) |
48 | { |
49 | printf(" "); |
50 | curr++; |
51 | } |
52 | if(short_name) |
53 | { |
54 | if(name && *name) |
55 | { |
56 | printf("-%c, ", short_name); |
57 | curr += 4; |
58 | } |
59 | else |
60 | { |
61 | printf("-%c ", short_name); |
62 | curr += 3; |
63 | } |
64 | } |
65 | if(name && *name) |
66 | { |
67 | printf("--%s ", name); |
68 | curr += 3 + strlen(name); |
69 | } |
70 | if(arg_desc && *arg_desc) |
71 | { |
72 | printf("%s ", arg_desc); |
73 | curr += 1 + strlen(arg_desc); |
74 | } |
75 | if(curr >= col3) |
76 | { |
77 | printf("\n"); |
78 | curr = 0; |
79 | } |
80 | if(opt_help) /* let's print the option's help body */ |
81 | { |
82 | const char *str = opt_help; |
83 | while(*str) |
84 | { |
85 | while(curr < col3) |
86 | { |
87 | printf(" "); |
88 | curr++; |
89 | } |
90 | switch(*str) |
91 | { |
92 | case '\n': |
93 | printf("\n"); |
94 | curr = 0; |
95 | break; |
96 | case '\t': |
97 | do |
98 | { |
99 | printf(" "); |
100 | curr++; |
101 | } |
102 | while((curr - col3) % tabsize != 0 && curr < col4); |
103 | case ' ': |
104 | if(*str == ' ') |
105 | { |
106 | curr++; |
107 | printf(" "); |
108 | } |
109 | for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n' |
110 | && str[i] != '\t'; i++); |
111 | if(curr + i - 1 >= col4) |
112 | curr = col4; |
113 | break; |
114 | default: |
115 | printf("%c", *str); |
116 | curr++; |
117 | } |
118 | if(curr >= col4) |
119 | { |
120 | printf("\n"); |
121 | curr = 0; |
122 | } |
123 | str++; |
124 | } |
125 | } |
126 | printf("\n"); |
127 | } |
128 | |
129 | void gaa_help(void) |
130 | { |
131 | printf("PSKtool help\nUsage : psktool [options]\n"); |
132 | __gaa_helpsingle('u', "username", "username ", "specify username."); |
133 | __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file."); |
134 | __gaa_helpsingle('s', "keysize", "SIZE ", "specify the key size in bytes."); |
135 | __gaa_helpsingle('v', "version", "", "prints the program's version number"); |
136 | __gaa_helpsingle('h', "help", "", "shows this help text"); |
137 | |
138 | #line 100 "gaa.skel" |
139 | } |
140 | /* Copy of C area */ |
141 | |
142 | #line 104 "gaa.skel" |
143 | /* GAA HEADER */ |
144 | #ifndef GAA_HEADER_POKY |
145 | #define GAA_HEADER_POKY |
146 | |
147 | typedef struct _gaainfo gaainfo; |
148 | |
149 | struct _gaainfo |
150 | { |
151 | #line 22 "psk.gaa" |
152 | int key_size; |
153 | #line 19 "psk.gaa" |
154 | char *passwd; |
155 | #line 16 "psk.gaa" |
156 | char *username; |
157 | |
158 | #line 114 "gaa.skel" |
159 | }; |
160 | |
161 | #ifdef __cplusplus |
162 | extern "C" |
163 | { |
164 | #endif |
165 | |
166 | int gaa(int argc, char *argv[], gaainfo *gaaval); |
167 | |
168 | void gaa_help(void); |
169 | |
170 | int gaa_file(const char *name, gaainfo *gaaval); |
171 | |
172 | #ifdef __cplusplus |
173 | } |
174 | #endif |
175 | |
176 | |
177 | #endif |
178 | |
179 | #line 135 "gaa.skel" |
180 | |
181 | /* C declarations */ |
182 | |
183 | #define GAAERROR(x){ gaa_error = 1; return x; } \ |
184 | { \ |
185 | gaa_error = 1; \ |
186 | return x; \ |
187 | } |
188 | |
189 | static char *gaa_current_option; |
190 | static int gaa_error = 0; |
191 | |
192 | /* Generated by gaa */ |
193 | |
194 | #include <string.h> |
195 | #include <stdlib.h> |
196 | |
197 | |
198 | #define GAA_OK-1 -1 |
199 | |
200 | #define GAA_ERROR_NOMATCH0 0 |
201 | #define GAA_ERROR_NOTENOUGH_ARGS1 1 |
202 | #define GAA_ERROR_INVALID_ARG2 2 |
203 | #define GAA_ERROR_UNKNOWN3 3 |
204 | |
205 | #define GAA_NOT_AN_OPTION0 0 |
206 | #define GAA_WORD_OPTION1 1 |
207 | #define GAA_LETTER_OPTION2 2 |
208 | #define GAA_MULTIPLE_OPTION3 3 |
209 | |
210 | #define GAA_REST0 0 |
211 | #define GAA_NB_OPTION5 5 |
212 | #define GAAOPTID_help1 1 |
213 | #define GAAOPTID_version2 2 |
214 | #define GAAOPTID_keysize3 3 |
215 | #define GAAOPTID_passwd4 4 |
216 | #define GAAOPTID_username5 5 |
217 | |
218 | #line 168 "gaa.skel" |
219 | |
220 | #define GAA_CHECK1STR(a,b)if(a[0] == str[0]) { gaa_current_option = a; return b; } \ |
221 | if(a[0] == str[0]) \ |
222 | { \ |
223 | gaa_current_option = a; \ |
224 | return b; \ |
225 | } |
226 | |
227 | #define GAA_CHECKSTR(a,b)if(strcmp(a,str) == 0) { gaa_current_option = a; return b; } \ |
228 | if(strcmp(a,str) == 0) \ |
229 | { \ |
230 | gaa_current_option = a; \ |
231 | return b; \ |
232 | } |
233 | |
234 | #define GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; } \ |
235 | if(!OK) \ |
236 | { \ |
237 | while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \ |
238 | gaa_index++; \ |
239 | if(gaa_last_non_option == gaa_index) \ |
240 | return GAA_ERROR_NOTENOUGH_ARGS1; \ |
241 | } |
242 | |
243 | #define GAA_TESTMOREOPTIONALARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) OK = 1; } \ |
244 | if(!OK) \ |
245 | { \ |
246 | while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \ |
247 | gaa_index++; \ |
248 | if(gaa_last_non_option == gaa_index) \ |
249 | OK = 1; \ |
250 | } |
251 | |
252 | #define GAA_FILL_2ARGS(target, func)target = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1 ; if(gaa_error == 1) { gaa_error = 0; return 2; } \ |
253 | target = func(GAAargv[gaa_index]); \ |
254 | gaa_arg_used[gaa_index] = 1; \ |
255 | if(gaa_error == 1) \ |
256 | { \ |
257 | gaa_error = 0; \ |
258 | return GAA_ERROR_INVALID_ARG2; \ |
259 | } |
260 | |
261 | |
262 | |
263 | #define GAA_FILL(target, func, num)if(!OK) { target = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index ] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } num = 1 ; } else { num = 0; } \ |
264 | if(!OK) \ |
265 | { \ |
266 | target = func(GAAargv[gaa_index]); \ |
267 | gaa_arg_used[gaa_index] = 1; \ |
268 | if(gaa_error == 1) \ |
269 | { \ |
270 | gaa_error = 0; \ |
271 | return GAA_ERROR_INVALID_ARG2; \ |
272 | } \ |
273 | num = 1; \ |
274 | } \ |
275 | else \ |
276 | { \ |
277 | num = 0; \ |
278 | } |
279 | |
280 | #define GAA_LIST_FILL(target, func, type ,num)if(!OK) { num = 0; target = ((void*)0); if ( gaa_last_non_option - gaa_index > 0) target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));for(; gaa_index < gaa_last_non_option ; gaa_index++) { if(gaa_arg_used[gaa_index] == 0) { target[num ] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if (gaa_error == 1) { gaa_error = 0; return 2; }; num++; } } if( num == 0) return 1; } \ |
281 | if(!OK) \ |
282 | { \ |
283 | num = 0; \ |
284 | target = NULL((void*)0); \ |
285 | if ( gaa_last_non_option - gaa_index > 0) \ |
286 | target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\ |
287 | for(; gaa_index < gaa_last_non_option; gaa_index++) \ |
288 | { \ |
289 | if(gaa_arg_used[gaa_index] == 0) \ |
290 | { \ |
291 | GAA_FILL_2ARGS(target[num], func)target[num] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index ] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; }; \ |
292 | num++; \ |
293 | } \ |
294 | } \ |
295 | if(num == 0) \ |
296 | return GAA_ERROR_NOTENOUGH_ARGS1; \ |
297 | } |
298 | |
299 | #define GAA_OPTIONALLIST_FILL(target, func, type ,num)if(!OK) { num = 0; target = ((void*)0); if ( gaa_last_non_option - gaa_index > 0) target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));for(; gaa_index < gaa_last_non_option ; gaa_index++) { if(gaa_arg_used[gaa_index] == 0) { target[num ] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if (gaa_error == 1) { gaa_error = 0; return 2; }; num++; } } } \ |
300 | if(!OK) \ |
301 | { \ |
302 | num = 0; \ |
303 | target = NULL((void*)0); \ |
304 | if ( gaa_last_non_option - gaa_index > 0) \ |
305 | target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\ |
306 | for(; gaa_index < gaa_last_non_option; gaa_index++) \ |
307 | { \ |
308 | if(gaa_arg_used[gaa_index] == 0) \ |
309 | { \ |
310 | GAA_FILL_2ARGS(target[num], func)target[num] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index ] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; }; \ |
311 | num++; \ |
312 | } \ |
313 | } \ |
314 | } |
315 | |
316 | #define GAA_OBLIGAT(str)k = 0; for(i = 0; i < strlen(str); i++) { j = gaa_get_option_num (str + i, 2); if(j == 0) { printf("Error: invalid 'obligat' set\n" ); exit(-1); } if(opt_list[j] == 1) k = 1; } if(k == 0) { if( strlen(str) == 1) printf("You must give the -%s option\n", str ); else printf("You must give at least one option of '%s'\n", str); return 0; } \ |
317 | k = 0; \ |
318 | for(i = 0; i < strlen(str); i++) \ |
319 | { \ |
320 | j = gaa_get_option_num(str + i, GAA_LETTER_OPTION2); \ |
321 | if(j == GAA_ERROR_NOMATCH0) \ |
322 | { \ |
323 | printf("Error: invalid 'obligat' set\n"); \ |
324 | exit(-1); \ |
325 | } \ |
326 | if(opt_list[j] == 1) \ |
327 | k = 1; \ |
328 | } \ |
329 | if(k == 0) \ |
330 | { \ |
331 | if(strlen(str) == 1) \ |
332 | printf("You must give the -%s option\n", str); \ |
333 | else \ |
334 | printf("You must give at least one option of '%s'\n", str); \ |
335 | return 0; \ |
336 | } |
337 | |
338 | #define GAA_INCOMP(str)k = 0; for(i = 0; i < strlen(str); i++) { j = gaa_get_option_num (str + i, 2); if(j == 0) { printf("Error: invalid 'obligat' set\n" ); exit(-1); } if(opt_list[j] == 1) k++; } if(k > 1) { printf ("The options '%s' are incompatible\n", str); return 0; } \ |
339 | k = 0; \ |
340 | for(i = 0; i < strlen(str); i++) \ |
341 | { \ |
342 | j = gaa_get_option_num(str + i, GAA_LETTER_OPTION2); \ |
343 | if(j == GAA_ERROR_NOMATCH0) \ |
344 | { \ |
345 | printf("Error: invalid 'obligat' set\n"); \ |
346 | exit(-1); \ |
347 | } \ |
348 | if(opt_list[j] == 1) \ |
349 | k++; \ |
350 | } \ |
351 | if(k > 1) \ |
352 | { \ |
353 | printf("The options '%s' are incompatible\n", str); \ |
354 | return 0; \ |
355 | } |
356 | |
357 | |
358 | static char **GAAargv; |
359 | static int GAAargc; |
360 | static char *gaa_arg_used; |
361 | static int gaa_processing_file = 0; |
362 | static int inited = 0; |
363 | |
364 | static int gaa_getint(char *arg) |
365 | { |
366 | int tmp; |
367 | char a; |
368 | if(sscanf(arg, "%d%c", &tmp, &a) < 1) |
369 | { |
370 | printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg); |
371 | GAAERROR(-1){ gaa_error = 1; return -1; }; |
372 | } |
373 | return tmp; |
374 | } |
375 | |
376 | static char gaa_getchar(char *arg) |
377 | { |
378 | if(strlen(arg) != 1) |
379 | { |
380 | printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg); |
381 | GAAERROR(-1){ gaa_error = 1; return -1; }; |
382 | } |
383 | return arg[0]; |
384 | } |
385 | |
386 | static char* gaa_getstr(char *arg) |
387 | { |
388 | return arg; |
389 | } |
390 | static float gaa_getfloat(char *arg) |
391 | { |
392 | float tmp; |
393 | char a; |
394 | if(sscanf(arg, "%f%c", &tmp, &a) < 1) |
395 | { |
396 | printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg); |
397 | GAAERROR(-1){ gaa_error = 1; return -1; }; |
398 | } |
399 | return tmp; |
400 | } |
401 | /* option structures */ |
402 | |
403 | struct GAAOPTION_keysize |
404 | { |
405 | int arg1; |
406 | int size1; |
407 | }; |
408 | |
409 | struct GAAOPTION_passwd |
410 | { |
411 | char* arg1; |
412 | int size1; |
413 | }; |
414 | |
415 | struct GAAOPTION_username |
416 | { |
417 | char* arg1; |
418 | int size1; |
419 | }; |
420 | |
421 | #line 349 "gaa.skel" |
422 | static int gaa_is_an_argument(char *str) |
423 | { |
424 | #ifdef GAA_WIN32 |
425 | if(str[0] == '/' && str[1] != 0) |
426 | return GAA_MULTIPLE_OPTION3; |
427 | #endif |
428 | if(str[0] != '-') |
429 | return GAA_NOT_AN_OPTION0; |
430 | if(str[1] == 0) |
431 | return GAA_NOT_AN_OPTION0; |
432 | if(str[1] == '-') |
433 | { |
434 | if(str[2] != 0) |
435 | return GAA_WORD_OPTION1; |
436 | else |
437 | return GAA_NOT_AN_OPTION0; |
438 | } |
439 | if(str[2] == 0) |
440 | return GAA_LETTER_OPTION2; |
441 | else |
442 | return GAA_MULTIPLE_OPTION3; |
443 | } |
444 | |
445 | static int gaa_get_option_num(char *str, int status) |
446 | { |
447 | switch(status) |
448 | { |
449 | case GAA_LETTER_OPTION2: |
450 | GAA_CHECK1STR("s", GAAOPTID_keysize)if("s"[0] == str[0]) { gaa_current_option = "s"; return 3; }; |
451 | GAA_CHECK1STR("p", GAAOPTID_passwd)if("p"[0] == str[0]) { gaa_current_option = "p"; return 4; }; |
452 | GAA_CHECK1STR("u", GAAOPTID_username)if("u"[0] == str[0]) { gaa_current_option = "u"; return 5; }; |
453 | case GAA_MULTIPLE_OPTION3: |
454 | #line 375 "gaa.skel" |
455 | GAA_CHECK1STR("h", GAAOPTID_help)if("h"[0] == str[0]) { gaa_current_option = "h"; return 1; }; |
456 | GAA_CHECK1STR("v", GAAOPTID_version)if("v"[0] == str[0]) { gaa_current_option = "v"; return 2; }; |
457 | |
458 | #line 277 "gaa.skel" |
459 | break; |
460 | case GAA_WORD_OPTION1: |
461 | GAA_CHECKSTR("help", GAAOPTID_help)if(strcmp("help",str) == 0) { gaa_current_option = "help"; return 1; }; |
462 | GAA_CHECKSTR("version", GAAOPTID_version)if(strcmp("version",str) == 0) { gaa_current_option = "version" ; return 2; }; |
463 | GAA_CHECKSTR("keysize", GAAOPTID_keysize)if(strcmp("keysize",str) == 0) { gaa_current_option = "keysize" ; return 3; }; |
464 | GAA_CHECKSTR("passwd", GAAOPTID_passwd)if(strcmp("passwd",str) == 0) { gaa_current_option = "passwd" ; return 4; }; |
465 | GAA_CHECKSTR("username", GAAOPTID_username)if(strcmp("username",str) == 0) { gaa_current_option = "username" ; return 5; }; |
466 | |
467 | #line 281 "gaa.skel" |
468 | break; |
469 | default: break; |
470 | } |
471 | return GAA_ERROR_NOMATCH0; |
472 | } |
473 | |
474 | static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) |
475 | { |
476 | int OK = 0; |
477 | int gaa_last_non_option; |
478 | struct GAAOPTION_keysize GAATMP_keysize; |
479 | struct GAAOPTION_passwd GAATMP_passwd; |
480 | struct GAAOPTION_username GAATMP_username; |
481 | |
482 | #line 393 "gaa.skel" |
483 | #ifdef GAA_REST_EXISTS |
484 | struct GAAREST GAAREST_tmp; |
485 | #endif |
486 | |
487 | opt_list[gaa_num] = 1; |
488 | |
489 | for(gaa_last_non_option = gaa_index; |
490 | (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION0); |
491 | gaa_last_non_option++); |
492 | |
493 | if(gaa_num == GAA_REST0) |
494 | { |
495 | gaa_index = 1; |
496 | gaa_last_non_option = GAAargc; |
497 | } |
498 | |
499 | switch(gaa_num) |
500 | { |
501 | case GAAOPTID_help1: |
502 | OK = 0; |
503 | #line 26 "psk.gaa" |
504 | { gaa_help(); exit(0); ;}; |
505 | |
506 | return GAA_OK-1; |
507 | break; |
508 | case GAAOPTID_version2: |
509 | OK = 0; |
510 | #line 25 "psk.gaa" |
511 | { psktool_version(); exit(0); ;}; |
512 | |
513 | return GAA_OK-1; |
514 | break; |
515 | case GAAOPTID_keysize3: |
516 | OK = 0; |
517 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
518 | GAA_FILL(GAATMP_keysize.arg1, gaa_getint, GAATMP_keysize.size1)if(!OK) { GAATMP_keysize.arg1 = gaa_getint(GAAargv[gaa_index] ); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_keysize.size1 = 1; } else { GAATMP_keysize .size1 = 0; }; |
519 | gaa_index++; |
520 | #line 23 "psk.gaa" |
521 | { gaaval->key_size = GAATMP_keysize.arg1 ;}; |
522 | |
523 | return GAA_OK-1; |
524 | break; |
525 | case GAAOPTID_passwd4: |
526 | OK = 0; |
527 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
528 | GAA_FILL(GAATMP_passwd.arg1, gaa_getstr, GAATMP_passwd.size1)if(!OK) { GAATMP_passwd.arg1 = gaa_getstr(GAAargv[gaa_index]) ; gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_passwd.size1 = 1; } else { GAATMP_passwd .size1 = 0; }; |
529 | gaa_index++; |
530 | #line 20 "psk.gaa" |
531 | { gaaval->passwd = GAATMP_passwd.arg1 ;}; |
532 | |
533 | return GAA_OK-1; |
534 | break; |
535 | case GAAOPTID_username5: |
536 | OK = 0; |
537 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
538 | GAA_FILL(GAATMP_username.arg1, gaa_getstr, GAATMP_username.size1)if(!OK) { GAATMP_username.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_username.size1 = 1; } else { GAATMP_username .size1 = 0; }; |
539 | gaa_index++; |
Value stored to 'gaa_index' is never read | |
540 | #line 17 "psk.gaa" |
541 | { gaaval->username = GAATMP_username.arg1 ;}; |
542 | |
543 | return GAA_OK-1; |
544 | break; |
545 | |
546 | #line 413 "gaa.skel" |
547 | default: break; |
548 | } |
549 | return GAA_ERROR_UNKNOWN3; |
550 | } |
551 | |
552 | int gaa(int argc, char **argv, gaainfo *gaaval) |
553 | { |
554 | int tmp1, tmp2; |
555 | int i, j; |
556 | char *opt_list; |
557 | |
558 | GAAargv = argv; |
559 | GAAargc = argc; |
560 | |
561 | opt_list = (char*) gaa_malloc(GAA_NB_OPTION5 + 1); |
562 | |
563 | for(i = 0; i < GAA_NB_OPTION5 + 1; i++) |
564 | opt_list[i] = 0; |
565 | /* initialization */ |
566 | if(inited == 0) |
567 | { |
568 | |
569 | #line 28 "psk.gaa" |
570 | { gaaval->username=NULL((void*)0); gaaval->passwd=NULL((void*)0); gaaval->key_size = 0; ;}; |
571 | |
572 | } |
573 | inited = 1; |
574 | #line 438 "gaa.skel" |
575 | gaa_arg_used = NULL((void*)0); |
576 | |
577 | if (argc > 0) { |
578 | gaa_arg_used = gaa_malloc(argc * sizeof(char)); |
579 | } |
580 | |
581 | for(i = 1; i < argc; i++) |
582 | gaa_arg_used[i] = 0; |
583 | for(i = 1; i < argc; i++) |
584 | { |
585 | if(gaa_arg_used[i] == 0) |
586 | { |
587 | j = 0; |
588 | tmp1 = gaa_is_an_argument(GAAargv[i]); |
589 | switch(tmp1) |
590 | { |
591 | case GAA_WORD_OPTION1: |
592 | j++; |
593 | case GAA_LETTER_OPTION2: |
594 | j++; |
595 | tmp2 = gaa_get_option_num(argv[i]+j, tmp1); |
596 | if(tmp2 == GAA_ERROR_NOMATCH0) |
597 | { |
598 | printf("Invalid option '%s'\n", argv[i]+j); |
599 | return 0; |
600 | } |
601 | switch(gaa_try(tmp2, i+1, gaaval, opt_list)) |
602 | { |
603 | case GAA_ERROR_NOTENOUGH_ARGS1: |
604 | printf("'%s': not enough arguments\n",gaa_current_option); |
605 | return 0; |
606 | case GAA_ERROR_INVALID_ARG2: |
607 | printf("Invalid arguments\n"); |
608 | return 0; |
609 | case GAA_OK-1: |
610 | break; |
611 | default: |
612 | printf("Unknown error\n"); |
613 | } |
614 | gaa_arg_used[i] = 1; |
615 | break; |
616 | case GAA_MULTIPLE_OPTION3: |
617 | for(j = 1; j < strlen(argv[i]); j++) |
618 | { |
619 | tmp2 = gaa_get_option_num(argv[i]+j, tmp1); |
620 | if(tmp2 == GAA_ERROR_NOMATCH0) |
621 | { |
622 | printf("Invalid option '%c'\n", *(argv[i]+j)); |
623 | return 0; |
624 | } |
625 | switch(gaa_try(tmp2, i+1, gaaval, opt_list)) |
626 | { |
627 | case GAA_ERROR_NOTENOUGH_ARGS1: |
628 | printf("'%s': not enough arguments\n",gaa_current_option); |
629 | return 0; |
630 | case GAA_ERROR_INVALID_ARG2: |
631 | printf("Invalid arguments\n"); |
632 | return 0; |
633 | case GAA_OK-1: |
634 | break; |
635 | default: |
636 | printf("Unknown error\n"); |
637 | } |
638 | } |
639 | gaa_arg_used[i] = 1; |
640 | break; |
641 | default: break; |
642 | } |
643 | } |
644 | } |
645 | if(gaa_processing_file == 0) |
646 | { |
647 | |
648 | #line 507 "gaa.skel" |
649 | #ifdef GAA_REST_EXISTS |
650 | switch(gaa_try(GAA_REST0, 1, gaaval, opt_list)) |
651 | { |
652 | case GAA_ERROR_NOTENOUGH_ARGS1: |
653 | printf("Rest: not enough arguments\n"); |
654 | return 0; |
655 | case GAA_ERROR_INVALID_ARG2: |
656 | printf("Invalid arguments\n"); |
657 | return 0; |
658 | case GAA_OK-1: |
659 | break; |
660 | default: |
661 | printf("Unknown error\n"); |
662 | } |
663 | #endif |
664 | } |
665 | for(i = 1; i < argc; i++) |
666 | { |
667 | if(gaa_arg_used[i] == 0) |
668 | { |
669 | printf("Too many arguments\n"); |
670 | return 0; |
671 | } |
672 | } |
673 | free(gaa_arg_used); |
674 | free(opt_list); |
675 | return -1; |
676 | } |
677 | |
678 | struct gaastrnode |
679 | { |
680 | char *str; |
681 | struct gaastrnode *next; |
682 | }; |
683 | |
684 | typedef struct gaastrnode gaa_str_node; |
685 | |
686 | static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) |
687 | { |
688 | int pos_ini; |
689 | int a; |
690 | int i = 0, len = 0, newline = 0; |
691 | |
692 | if(argc == 1) { |
693 | newline = 1; |
694 | len = 2; |
695 | } |
696 | |
697 | a = fgetc( file); |
698 | if (a == EOF(-1)) return 0; |
699 | |
700 | while(a == ' ' || a == 9 || a == '\n') |
701 | { |
702 | if(a == '\n') |
703 | { |
704 | newline=1; |
705 | len = 2; |
706 | } |
707 | a = fgetc( file); |
708 | if (a == EOF(-1)) return 0; |
709 | } |
710 | |
711 | pos_ini = ftell(file) - 1; |
712 | |
713 | while(a != ' ' && a != 9 && a != '\n') |
714 | { |
715 | |
716 | len++; |
717 | a = fgetc( file); |
718 | if(a==EOF(-1)) return 0; //a = ' '; |
719 | } |
720 | |
721 | len += 1; |
722 | tmp_str->str = gaa_malloc((len) * sizeof(char)); |
723 | |
724 | if(newline == 1) |
725 | { |
726 | tmp_str->str[0] = '-'; |
727 | tmp_str->str[1] = '-'; |
728 | i = 2; |
729 | } |
730 | else |
731 | { |
732 | i = 0; |
733 | } |
734 | |
735 | fseek(file,pos_ini, SEEK_SET0); |
736 | do |
737 | { |
738 | a = fgetc( file); |
739 | |
740 | if (a == EOF(-1)) { |
741 | i+=2; |
742 | break; |
743 | } |
744 | tmp_str->str[i] = a; |
745 | i++; |
746 | } |
747 | while(a != ' ' && a != 9 && a != '\n' && i < len); |
748 | |
749 | tmp_str->str[i - 1] = 0; |
750 | |
751 | fseek(file,- 1, SEEK_CUR1); |
752 | /* printf("%d\n", ftell(file)); */ |
753 | |
754 | return -1; |
755 | } |
756 | |
757 | int gaa_file(const char *name, gaainfo *gaaval) |
758 | { |
759 | gaa_str_node *first_str, **tmp_str, *tmp_str2; |
760 | int rval, i; |
761 | char **argv; |
762 | int argc = 0; |
763 | FILE *file; |
764 | |
765 | gaa_processing_file = 1; |
766 | |
767 | if((file = fopen(name, "r")) == NULL((void*)0)) |
768 | { |
769 | printf("Couldn't open '%s' configuration file for reading\n", name); |
770 | return 1; |
771 | } |
772 | |
773 | tmp_str = &first_str; |
774 | do |
775 | { |
776 | argc++; |
777 | *tmp_str = gaa_malloc(sizeof(gaa_str_node)); |
778 | |
779 | (*tmp_str)->str = NULL((void*)0); |
780 | (*tmp_str)->next = NULL((void*)0); |
781 | |
782 | rval = gaa_internal_get_next_str(file, *tmp_str, argc); |
783 | tmp_str = &((*tmp_str)->next); |
784 | } |
785 | while(rval == -1); |
786 | |
787 | if(rval == 1) |
788 | return 0; |
789 | |
790 | argv = gaa_malloc((1 + argc) * sizeof(char*)); |
791 | |
792 | tmp_str2 = first_str; |
793 | argv[0] = "cfg"; |
794 | for(i = 1; i < argc; i++) |
795 | { |
796 | argv[i] = tmp_str2->str; |
797 | tmp_str2 = tmp_str2->next; |
798 | } |
799 | |
800 | rval = gaa(argc, argv, gaaval); |
801 | gaa_processing_file = 0; |
802 | return rval; |
803 | } |