/[mcrypt]/shash/src/gaaout.c
ViewVC logotype

Contents of /shash/src/gaaout.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sat Aug 31 14:11:33 2002 UTC (21 years, 7 months ago) by nmav
Branch: MAIN
CVS Tags: shash_0_2_6, HEAD
Changes since 1.2: +91 -73 lines
File MIME type: text/plain
removed the 'nolocks' option. Updated documentation.

1 /* File generated by GAA 1.6.2
2 */
3 #define GAA_NO_WIN32
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7
8 #ifndef GAA_NO_WIN32
9 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
10 #define GAA_WIN32
11 #endif
12 #endif
13
14 void* gaa_malloc( size_t size) {
15 void* ret;
16 ret = malloc(size);
17 if (ret==NULL) {
18 fprintf(stderr, "gaa: could not allocate memory");
19 exit(1);
20 }
21 return ret;
22 }
23
24 void __gaa_helpsingle(char short_name, char *name,
25 char *arg_desc, char *opt_help)
26 {
27 int col1, col3, col4, tabsize = 3, curr;
28 int i;
29
30 col1 = 5; /* Default values */
31 col3 = 30;
32 col4 = 70;
33
34 curr = 0;
35 for(i = 0; i < col1; i++)
36 {
37 printf(" ");
38 curr++;
39 }
40 if(short_name)
41 {
42 if(name && *name)
43 {
44 printf("-%c, ", short_name);
45 curr += 4;
46 }
47 else
48 {
49 printf("-%c ", short_name);
50 curr += 3;
51 }
52 }
53 if(name && *name)
54 {
55 printf("--%s ", name);
56 curr += 3 + strlen(name);
57 }
58 if(arg_desc && *arg_desc)
59 {
60 printf("%s ", arg_desc);
61 curr += 1 + strlen(arg_desc);
62 }
63 if(curr >= col3)
64 {
65 printf("\n");
66 curr = 0;
67 }
68 if(opt_help) /* let's print the option's help body */
69 {
70 const char *str = opt_help;
71 while(*str)
72 {
73 while(curr < col3)
74 {
75 printf(" ");
76 curr++;
77 }
78 switch(*str)
79 {
80 case '\n':
81 printf("\n");
82 curr = 0;
83 break;
84 case '\t':
85 do
86 {
87 printf(" ");
88 curr++;
89 }
90 while((curr - col3) % tabsize != 0 && curr < col4);
91 case ' ':
92 if(*str == ' ')
93 {
94 curr++;
95 printf(" ");
96 }
97 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
98 && str[i] != '\t'; i++);
99 if(curr + i - 1 >= col4)
100 curr = col4;
101 break;
102 default:
103 printf("%c", *str);
104 curr++;
105 }
106 if(curr >= col4)
107 {
108 printf("\n");
109 curr = 0;
110 }
111 str++;
112 }
113 }
114 printf("\n");
115 }
116
117 void gaa_help(void)
118 {
119 printf("Usage : shash [options] file1 file2 ...\n\n");
120 __gaa_helpsingle('V', "verbose", "", "some more information is displayed.");
121 __gaa_helpsingle('q', "quiet", "", "suppress some non critical warnings.");
122 __gaa_helpsingle(0, "nosalt", "", "Do not use salt.");
123 __gaa_helpsingle(0, "time", "", "Show time elapsed.");
124 __gaa_helpsingle('m', "hmac", "", "Use password to hash (hmac).");
125 __gaa_helpsingle('d', "doublecheck", "", "Double check passwords.");
126 __gaa_helpsingle('c', "check", "", "check files.");
127 __gaa_helpsingle('b', "binary", "", "treat input files as binary.");
128 __gaa_helpsingle('t', "text", "", "treat input files as text.");
129 __gaa_helpsingle('o', "keymode", "kmode ", "keyword mode""Use the --listkeygen parameter to view all supported modes.");
130 __gaa_helpsingle('i', "config", "config ", "Use configuration file FILE.");
131 __gaa_helpsingle('a', "algorithm", "algorithm ", "specify the algorithm. ""Use the --list parameter to show the supported algorithms.");
132 __gaa_helpsingle('l', "list", "", "Prints a list of the algorithms supported.");
133 __gaa_helpsingle('k', "key", "key ", "specify the key");
134 __gaa_helpsingle(0, "listkeygen", "", "Prints a list of the key generation algorithms supported.");
135 __gaa_helpsingle('h', "help", "", "prints this help");
136 __gaa_helpsingle('v', "version", "", "prints the version number");
137 __gaa_helpsingle('L', "license", "", "displays license information.");
138
139 #line 100 "gaa.skel"
140 }
141 /* Copy of C area */
142
143 #line 104 "gaa.skel"
144 /* GAA HEADER */
145 #ifndef GAA_HEADER_POKY
146 #define GAA_HEADER_POKY
147
148 typedef struct _gaainfo gaainfo;
149
150 struct _gaainfo
151 {
152 #line 52 "shash.gaa"
153 char **input;
154 #line 51 "shash.gaa"
155 int size;
156 #line 42 "shash.gaa"
157 char *keys;
158 #line 36 "shash.gaa"
159 char *algorithm;
160 #line 33 "shash.gaa"
161 char *config_file;
162 #line 32 "shash.gaa"
163 int config;
164 #line 28 "shash.gaa"
165 char *kmode;
166 #line 25 "shash.gaa"
167 int text;
168 #line 22 "shash.gaa"
169 int binary;
170 #line 19 "shash.gaa"
171 int check;
172 #line 16 "shash.gaa"
173 int double_check;
174 #line 13 "shash.gaa"
175 int hmac;
176 #line 10 "shash.gaa"
177 int show_time;
178 #line 7 "shash.gaa"
179 int nosalt;
180 #line 3 "shash.gaa"
181 int quiet;
182
183 #line 114 "gaa.skel"
184 };
185
186 #ifdef __cplusplus
187 extern "C"
188 {
189 #endif
190
191 int gaa(int argc, char *argv[], gaainfo *gaaval);
192
193 void gaa_help(void);
194
195 int gaa_file(char *name, gaainfo *gaaval);
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201
202 #endif
203
204 #line 135 "gaa.skel"
205
206 /* C declarations */
207
208 #define GAAERROR(x) \
209 { \
210 gaa_error = 1; \
211 return x; \
212 }
213
214 char *gaa_current_option;
215 int gaa_error = 0;
216
217 /* Generated by gaa */
218
219 #include <string.h>
220 #include <stdlib.h>
221
222
223 #define GAA_OK -1
224
225 #define GAA_ERROR_NOMATCH 0
226 #define GAA_ERROR_NOTENOUGH_ARGS 1
227 #define GAA_ERROR_INVALID_ARG 2
228 #define GAA_ERROR_UNKNOWN 3
229
230 #define GAA_NOT_AN_OPTION 0
231 #define GAA_WORD_OPTION 1
232 #define GAA_LETTER_OPTION 2
233 #define GAA_MULTIPLE_OPTION 3
234
235 #define GAA_REST 0
236 #define GAA_NB_OPTION 18
237 #define GAAOPTID_license 1
238 #define GAAOPTID_version 2
239 #define GAAOPTID_help 3
240 #define GAAOPTID_listkeygen 4
241 #define GAAOPTID_key 5
242 #define GAAOPTID_list 6
243 #define GAAOPTID_algorithm 7
244 #define GAAOPTID_config 8
245 #define GAAOPTID_keymode 9
246 #define GAAOPTID_text 10
247 #define GAAOPTID_binary 11
248 #define GAAOPTID_check 12
249 #define GAAOPTID_doublecheck 13
250 #define GAAOPTID_hmac 14
251 #define GAAOPTID_time 15
252 #define GAAOPTID_nosalt 16
253 #define GAAOPTID_quiet 17
254 #define GAAOPTID_verbose 18
255
256 #line 168 "gaa.skel"
257
258 #define GAA_CHECK1STR(a,b) \
259 if(a[0] == str[0]) \
260 { \
261 gaa_current_option = a; \
262 return b; \
263 }
264
265 #define GAA_CHECKSTR(a,b) \
266 if(strcmp(a,str) == 0) \
267 { \
268 gaa_current_option = a; \
269 return b; \
270 }
271
272 #define GAA_TESTMOREARGS \
273 if(!OK) \
274 { \
275 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
276 gaa_index++; \
277 if(gaa_last_non_option == gaa_index) \
278 return GAA_ERROR_NOTENOUGH_ARGS; \
279 }
280
281 #define GAA_TESTMOREOPTIONALARGS \
282 if(!OK) \
283 { \
284 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
285 gaa_index++; \
286 if(gaa_last_non_option == gaa_index) \
287 OK = 1; \
288 }
289
290 #define GAA_FILL_2ARGS(target, func) \
291 target = func(GAAargv[gaa_index]); \
292 gaa_arg_used[gaa_index] = 1; \
293 if(gaa_error == 1) \
294 { \
295 gaa_error = 0; \
296 return GAA_ERROR_INVALID_ARG; \
297 }
298
299
300
301 #define GAA_FILL(target, func, num) \
302 if(!OK) \
303 { \
304 target = func(GAAargv[gaa_index]); \
305 gaa_arg_used[gaa_index] = 1; \
306 if(gaa_error == 1) \
307 { \
308 gaa_error = 0; \
309 return GAA_ERROR_INVALID_ARG; \
310 } \
311 num = 1; \
312 } \
313 else \
314 { \
315 num = 0; \
316 }
317
318 #define GAA_LIST_FILL(target, func, type ,num) \
319 if(!OK) \
320 { \
321 num = 0; \
322 target = NULL; \
323 if ( gaa_last_non_option - gaa_index > 0) \
324 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
325 for(; gaa_index < gaa_last_non_option; gaa_index++) \
326 { \
327 if(gaa_arg_used[gaa_index] == 0) \
328 { \
329 GAA_FILL_2ARGS(target[num], func); \
330 num++; \
331 } \
332 } \
333 if(num == 0) \
334 return GAA_ERROR_NOTENOUGH_ARGS; \
335 }
336
337 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
338 if(!OK) \
339 { \
340 num = 0; \
341 target = NULL; \
342 if ( gaa_last_non_option - gaa_index > 0) \
343 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
344 for(; gaa_index < gaa_last_non_option; gaa_index++) \
345 { \
346 if(gaa_arg_used[gaa_index] == 0) \
347 { \
348 GAA_FILL_2ARGS(target[num], func); \
349 num++; \
350 } \
351 } \
352 }
353
354 #define GAA_OBLIGAT(str) \
355 k = 0; \
356 for(i = 0; i < strlen(str); i++) \
357 { \
358 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
359 if(j == GAA_ERROR_NOMATCH) \
360 { \
361 printf("Error: invalid 'obligat' set\n"); \
362 exit(-1); \
363 } \
364 if(opt_list[j] == 1) \
365 k = 1; \
366 } \
367 if(k == 0) \
368 { \
369 if(strlen(str) == 1) \
370 printf("You must give the -%s option\n", str); \
371 else \
372 printf("You must give at least one option of '%s'\n", str); \
373 return 0; \
374 }
375
376 #define GAA_INCOMP(str) \
377 k = 0; \
378 for(i = 0; i < strlen(str); i++) \
379 { \
380 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
381 if(j == GAA_ERROR_NOMATCH) \
382 { \
383 printf("Error: invalid 'obligat' set\n"); \
384 exit(-1); \
385 } \
386 if(opt_list[j] == 1) \
387 k++; \
388 } \
389 if(k > 1) \
390 { \
391 printf("The options '%s' are incompatible\n", str); \
392 return 0; \
393 }
394
395
396 char **GAAargv;
397 int GAAargc;
398 char *gaa_arg_used;
399 int gaa_processing_file = 0;
400 int inited = 0;
401
402 int gaa_getint(char *arg)
403 {
404 int tmp;
405 char a;
406 if(sscanf(arg, "%d%c", &tmp, &a) != 1)
407 {
408 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
409 GAAERROR(-1);
410 }
411 return tmp;
412 }
413
414 char gaa_getchar(char *arg)
415 {
416 if(strlen(arg) != 1)
417 {
418 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
419 GAAERROR(-1);
420 }
421 return arg[0];
422 }
423
424 char* gaa_getstr(char *arg)
425 {
426 return arg;
427 }
428 float gaa_getfloat(char *arg)
429 {
430 float tmp;
431 char a;
432 if(sscanf(arg, "%f%c", &tmp, &a) != 1)
433 {
434 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
435 GAAERROR(-1);
436 }
437 return tmp;
438 }
439 /* option structures */
440
441 struct GAAOPTION_key
442 {
443 char* arg1;
444 int size1;
445 };
446
447 struct GAAOPTION_algorithm
448 {
449 char* arg1;
450 int size1;
451 };
452
453 struct GAAOPTION_config
454 {
455 char* arg1;
456 int size1;
457 };
458
459 struct GAAOPTION_keymode
460 {
461 char* arg1;
462 int size1;
463 };
464 #define GAA_REST_EXISTS
465
466 struct GAAREST
467 {
468 char** arg1;
469 int size1;
470 };
471
472 #line 349 "gaa.skel"
473 int gaa_is_an_argument(char *str)
474 {
475 #ifdef GAA_WIN32
476 if(str[0] == '/' && str[1] != 0)
477 return GAA_MULTIPLE_OPTION;
478 #endif
479 if(str[0] != '-')
480 return GAA_NOT_AN_OPTION;
481 if(str[1] == 0)
482 return GAA_NOT_AN_OPTION;
483 if(str[1] == '-')
484 {
485 if(str[2] != 0)
486 return GAA_WORD_OPTION;
487 else
488 return GAA_NOT_AN_OPTION;
489 }
490 if(str[2] == 0)
491 return GAA_LETTER_OPTION;
492 else
493 return GAA_MULTIPLE_OPTION;
494 }
495
496 int gaa_get_option_num(char *str, int status)
497 {
498 switch(status)
499 {
500 case GAA_LETTER_OPTION:
501 GAA_CHECK1STR("k", GAAOPTID_key);
502 GAA_CHECK1STR("a", GAAOPTID_algorithm);
503 GAA_CHECK1STR("i", GAAOPTID_config);
504 GAA_CHECK1STR("o", GAAOPTID_keymode);
505 case GAA_MULTIPLE_OPTION:
506 #line 375 "gaa.skel"
507 GAA_CHECK1STR("L", GAAOPTID_license);
508 GAA_CHECK1STR("v", GAAOPTID_version);
509 GAA_CHECK1STR("h", GAAOPTID_help);
510 GAA_CHECK1STR("", GAAOPTID_listkeygen);
511 GAA_CHECK1STR("l", GAAOPTID_list);
512 GAA_CHECK1STR("t", GAAOPTID_text);
513 GAA_CHECK1STR("b", GAAOPTID_binary);
514 GAA_CHECK1STR("c", GAAOPTID_check);
515 GAA_CHECK1STR("d", GAAOPTID_doublecheck);
516 GAA_CHECK1STR("m", GAAOPTID_hmac);
517 GAA_CHECK1STR("", GAAOPTID_time);
518 GAA_CHECK1STR("", GAAOPTID_nosalt);
519 GAA_CHECK1STR("q", GAAOPTID_quiet);
520 GAA_CHECK1STR("V", GAAOPTID_verbose);
521
522 #line 277 "gaa.skel"
523 break;
524 case GAA_WORD_OPTION:
525 GAA_CHECKSTR("license", GAAOPTID_license);
526 GAA_CHECKSTR("version", GAAOPTID_version);
527 GAA_CHECKSTR("help", GAAOPTID_help);
528 GAA_CHECKSTR("listkeygen", GAAOPTID_listkeygen);
529 GAA_CHECKSTR("key", GAAOPTID_key);
530 GAA_CHECKSTR("list", GAAOPTID_list);
531 GAA_CHECKSTR("algorithm", GAAOPTID_algorithm);
532 GAA_CHECKSTR("config", GAAOPTID_config);
533 GAA_CHECKSTR("keymode", GAAOPTID_keymode);
534 GAA_CHECKSTR("text", GAAOPTID_text);
535 GAA_CHECKSTR("binary", GAAOPTID_binary);
536 GAA_CHECKSTR("check", GAAOPTID_check);
537 GAA_CHECKSTR("doublecheck", GAAOPTID_doublecheck);
538 GAA_CHECKSTR("hmac", GAAOPTID_hmac);
539 GAA_CHECKSTR("time", GAAOPTID_time);
540 GAA_CHECKSTR("nosalt", GAAOPTID_nosalt);
541 GAA_CHECKSTR("quiet", GAAOPTID_quiet);
542 GAA_CHECKSTR("verbose", GAAOPTID_verbose);
543
544 #line 281 "gaa.skel"
545 break;
546 default: break;
547 }
548 return GAA_ERROR_NOMATCH;
549 }
550
551 int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
552 {
553 int OK = 0;
554 int gaa_last_non_option;
555 struct GAAOPTION_key GAATMP_key;
556 struct GAAOPTION_algorithm GAATMP_algorithm;
557 struct GAAOPTION_config GAATMP_config;
558 struct GAAOPTION_keymode GAATMP_keymode;
559
560 #line 393 "gaa.skel"
561 #ifdef GAA_REST_EXISTS
562 struct GAAREST GAAREST_tmp;
563 #endif
564
565 opt_list[gaa_num] = 1;
566
567 for(gaa_last_non_option = gaa_index;
568 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
569 gaa_last_non_option++);
570
571 if(gaa_num == GAA_REST)
572 {
573 gaa_index = 1;
574 gaa_last_non_option = GAAargc;
575 }
576
577 switch(gaa_num)
578 {
579 case GAAOPTID_license:
580 OK = 0;
581 #line 49 "shash.gaa"
582 { hash_license(); exit(0); ;};
583
584 return GAA_OK;
585 break;
586 case GAAOPTID_version:
587 OK = 0;
588 #line 48 "shash.gaa"
589 { hash_version(); exit(0); ;};
590
591 return GAA_OK;
592 break;
593 case GAAOPTID_help:
594 OK = 0;
595 #line 47 "shash.gaa"
596 { gaa_help(); exit(0); ;};
597
598 return GAA_OK;
599 break;
600 case GAAOPTID_listkeygen:
601 OK = 0;
602 #line 46 "shash.gaa"
603 { list_keygen_algorithms(); exit(0); ;};
604
605 return GAA_OK;
606 break;
607 case GAAOPTID_key:
608 OK = 0;
609 GAA_TESTMOREARGS;
610 GAA_FILL(GAATMP_key.arg1, gaa_getstr, GAATMP_key.size1);
611 gaa_index++;
612 #line 43 "shash.gaa"
613 { gaaval->keys = GAATMP_key.arg1; ;};
614
615 return GAA_OK;
616 break;
617 case GAAOPTID_list:
618 OK = 0;
619 #line 40 "shash.gaa"
620 { hash_list(); ;};
621
622 return GAA_OK;
623 break;
624 case GAAOPTID_algorithm:
625 OK = 0;
626 GAA_TESTMOREARGS;
627 GAA_FILL(GAATMP_algorithm.arg1, gaa_getstr, GAATMP_algorithm.size1);
628 gaa_index++;
629 #line 37 "shash.gaa"
630 { gaaval->algorithm = GAATMP_algorithm.arg1 ;};
631
632 return GAA_OK;
633 break;
634 case GAAOPTID_config:
635 OK = 0;
636 GAA_TESTMOREARGS;
637 GAA_FILL(GAATMP_config.arg1, gaa_getstr, GAATMP_config.size1);
638 gaa_index++;
639 #line 34 "shash.gaa"
640 { gaaval->config=1; if (GAATMP_config.size1==1) gaaval->config_file = GAATMP_config.arg1 ;};
641
642 return GAA_OK;
643 break;
644 case GAAOPTID_keymode:
645 OK = 0;
646 GAA_TESTMOREARGS;
647 GAA_FILL(GAATMP_keymode.arg1, gaa_getstr, GAATMP_keymode.size1);
648 gaa_index++;
649 #line 29 "shash.gaa"
650 { gaaval->kmode = GAATMP_keymode.arg1 ;};
651
652 return GAA_OK;
653 break;
654 case GAAOPTID_text:
655 OK = 0;
656 #line 26 "shash.gaa"
657 { gaaval->text = 1 ;};
658
659 return GAA_OK;
660 break;
661 case GAAOPTID_binary:
662 OK = 0;
663 #line 23 "shash.gaa"
664 { gaaval->binary = 1 ;};
665
666 return GAA_OK;
667 break;
668 case GAAOPTID_check:
669 OK = 0;
670 #line 20 "shash.gaa"
671 { gaaval->check = 1 ;};
672
673 return GAA_OK;
674 break;
675 case GAAOPTID_doublecheck:
676 OK = 0;
677 #line 17 "shash.gaa"
678 { gaaval->double_check = 1 ;};
679
680 return GAA_OK;
681 break;
682 case GAAOPTID_hmac:
683 OK = 0;
684 #line 14 "shash.gaa"
685 { gaaval->hmac = 1 ;};
686
687 return GAA_OK;
688 break;
689 case GAAOPTID_time:
690 OK = 0;
691 #line 11 "shash.gaa"
692 { gaaval->show_time = 1 ;};
693
694 return GAA_OK;
695 break;
696 case GAAOPTID_nosalt:
697 OK = 0;
698 #line 8 "shash.gaa"
699 { gaaval->nosalt = 1 ;};
700
701 return GAA_OK;
702 break;
703 case GAAOPTID_quiet:
704 OK = 0;
705 #line 5 "shash.gaa"
706 { gaaval->quiet = 2 ;};
707
708 return GAA_OK;
709 break;
710 case GAAOPTID_verbose:
711 OK = 0;
712 #line 4 "shash.gaa"
713 { gaaval->quiet = 0 ;};
714
715 return GAA_OK;
716 break;
717 case GAA_REST:
718 GAA_OPTIONALLIST_FILL(GAAREST_tmp.arg1, gaa_getstr, char*, GAAREST_tmp.size1);
719 #line 53 "shash.gaa"
720 { gaaval->input = GAAREST_tmp.arg1; gaaval->size = GAAREST_tmp.size1 ;};
721
722 return GAA_OK;
723 break;
724
725 #line 413 "gaa.skel"
726 default: break;
727 }
728 return GAA_ERROR_UNKNOWN;
729 }
730
731 int gaa(int argc, char **argv, gaainfo *gaaval)
732 {
733 int tmp1, tmp2;
734 int i, j, k;
735 char *opt_list;
736
737 GAAargv = argv;
738 GAAargc = argc;
739
740 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
741
742 for(i = 0; i < GAA_NB_OPTION + 1; i++)
743 opt_list[i] = 0;
744 /* initialization */
745 if(inited == 0)
746 {
747
748 #line 55 "shash.gaa"
749 { gaaval->quiet=1; gaaval->config=0; gaaval->kmode = NULL; gaaval->hmac = 0;
750 gaaval->algorithm=NULL; gaaval->keys=NULL; gaaval->config_file=NULL; gaaval->input=NULL;
751 gaaval->double_check=0; gaaval->nosalt=0; gaaval->check=0; gaaval->text=0;
752 gaaval->binary=0; gaaval->show_time=0; ;};
753
754 }
755 inited = 1;
756 #line 438 "gaa.skel"
757 gaa_arg_used = NULL;
758
759 if (argc > 0) {
760 gaa_arg_used = gaa_malloc(argc * sizeof(char));
761 }
762
763 for(i = 1; i < argc; i++)
764 gaa_arg_used[i] = 0;
765 for(i = 1; i < argc; i++)
766 {
767 if(gaa_arg_used[i] == 0)
768 {
769 j = 0;
770 tmp1 = gaa_is_an_argument(GAAargv[i]);
771 switch(tmp1)
772 {
773 case GAA_WORD_OPTION:
774 j++;
775 case GAA_LETTER_OPTION:
776 j++;
777 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
778 if(tmp2 == GAA_ERROR_NOMATCH)
779 {
780 printf("Invalid option '%s'\n", argv[i]+j);
781 return 0;
782 }
783 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
784 {
785 case GAA_ERROR_NOTENOUGH_ARGS:
786 printf("'%s': not enough arguments\n",gaa_current_option);
787 return 0;
788 case GAA_ERROR_INVALID_ARG:
789 printf("Invalid arguments\n");
790 return 0;
791 case GAA_OK:
792 break;
793 default:
794 printf("Unknown error\n");
795 }
796 gaa_arg_used[i] = 1;
797 break;
798 case GAA_MULTIPLE_OPTION:
799 for(j = 1; j < strlen(argv[i]); j++)
800 {
801 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
802 if(tmp2 == GAA_ERROR_NOMATCH)
803 {
804 printf("Invalid option '%c'\n", *(argv[i]+j));
805 return 0;
806 }
807 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
808 {
809 case GAA_ERROR_NOTENOUGH_ARGS:
810 printf("'%s': not enough arguments\n",gaa_current_option);
811 return 0;
812 case GAA_ERROR_INVALID_ARG:
813 printf("Invalid arguments\n");
814 return 0;
815 case GAA_OK:
816 break;
817 default:
818 printf("Unknown error\n");
819 }
820 }
821 gaa_arg_used[i] = 1;
822 break;
823 default: break;
824 }
825 }
826 }
827 if(gaa_processing_file == 0)
828 {
829 GAA_INCOMP("bt");
830
831 #line 507 "gaa.skel"
832 #ifdef GAA_REST_EXISTS
833 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
834 {
835 case GAA_ERROR_NOTENOUGH_ARGS:
836 printf("Rest: not enough arguments\n");
837 return 0;
838 case GAA_ERROR_INVALID_ARG:
839 printf("Invalid arguments\n");
840 return 0;
841 case GAA_OK:
842 break;
843 default:
844 printf("Unknown error\n");
845 }
846 #endif
847 }
848 for(i = 1; i < argc; i++)
849 {
850 if(gaa_arg_used[i] == 0)
851 {
852 printf("Too many arguments\n");
853 return 0;
854 }
855 }
856 free(gaa_arg_used);
857 free(opt_list);
858 return -1;
859 }
860
861 struct gaastrnode
862 {
863 char *str;
864 struct gaastrnode *next;
865 };
866
867 typedef struct gaastrnode gaa_str_node;
868
869 int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
870 {
871 int pos_ini;
872 char a;
873 int i = 0, len = 0, newline = 0;
874
875 if(argc == 1) {
876 newline = 1;
877 len = 2;
878 }
879
880 if(fscanf(file,"%c", &a) != 1) return 0;
881
882 while(a == ' ' || a == 9 || a == '\n')
883 {
884 if(a == '\n')
885 {
886 newline=1;
887 len = 2;
888 }
889 if(fscanf(file,"%c", &a) != 1) return 0;
890 }
891
892 pos_ini = ftell(file) - 1;
893
894 while(a != ' ' && a != 9 && a != '\n')
895 {
896
897 len++;
898 if(fscanf(file,"%c", &a) != 1) a = ' ';
899 }
900
901 len += 1;
902 tmp_str->str = gaa_malloc((len) * sizeof(char));
903
904 if(newline == 1)
905 {
906 tmp_str->str[0] = '-';
907 tmp_str->str[1] = '-';
908 i = 2;
909 }
910 else
911 {
912 i = 0;
913 }
914
915 fseek(file,pos_ini, SEEK_SET);
916 do
917 {
918 if(fscanf(file, "%c", &a) != 1)
919 {
920 i+=2;
921 break;
922 }
923 tmp_str->str[i] = a;
924 i++;
925 }
926 while(a != ' ' && a != 9 && a != '\n' && i < len);
927
928 tmp_str->str[i - 1] = 0;
929
930 fseek(file,- 1, SEEK_CUR);
931 /* printf("%d\n", ftell(file)); */
932
933 return -1;
934 }
935
936 int gaa_file(char *name, gaainfo *gaaval)
937 {
938 gaa_str_node *first_str, **tmp_str, *tmp_str2;
939 int rval, i;
940 char **argv;
941 int argc = 0;
942 FILE *file;
943
944 gaa_processing_file = 1;
945
946 if((file = fopen(name, "r")) == NULL)
947 {
948 printf("Couldn't open '%s' configuration file for reading\n", name);
949 return 0;
950 }
951
952 tmp_str = &first_str;
953 do
954 {
955 argc++;
956 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
957
958 (*tmp_str)->str = NULL;
959 (*tmp_str)->next = NULL;
960
961 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
962 tmp_str = &((*tmp_str)->next);
963 }
964 while(rval == -1);
965
966 if(rval == 1)
967 return 0;
968
969 argv = gaa_malloc((1 + argc) * sizeof(char*));
970
971 tmp_str2 = first_str;
972 argv[0] = "cfg";
973 for(i = 1; i < argc; i++)
974 {
975 argv[i] = tmp_str2->str;
976 tmp_str2 = tmp_str2->next;
977 }
978
979 rval = gaa(argc, argv, gaaval);
980 gaa_processing_file = 0;
981 return rval;
982 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26