Fix for GTK-DOC parse breakage.
[gnutls.git] / src / psk-gaa.c
blob82d8383e5bf7a09e296e66c4e2483658568e530b
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "psk.gaa"
7 /* C declarations */
9 #include <config.h>
10 #ifdef _WIN32
11 # include <io.h>
12 #endif
14 void psktool_version(void);
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
20 #ifndef GAA_NO_WIN32
21 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
22 #define GAA_WIN32
23 #endif
24 #endif
26 static void* gaa_malloc( size_t size) {
27 void* ret;
28 ret = malloc(size);
29 if (ret==NULL) {
30 fprintf(stderr, "gaa: could not allocate memory");
31 exit(1);
33 return ret;
36 static void __gaa_helpsingle(char short_name, char *name,
37 char *arg_desc, char *opt_help)
39 int col1, col3, col4, tabsize = 3, curr;
40 int i;
42 col1 = 5; /* Default values */
43 col3 = 30;
44 col4 = 70;
46 curr = 0;
47 for(i = 0; i < col1; i++)
49 printf(" ");
50 curr++;
52 if(short_name)
54 if(name && *name)
56 printf("-%c, ", short_name);
57 curr += 4;
59 else
61 printf("-%c ", short_name);
62 curr += 3;
65 if(name && *name)
67 printf("--%s ", name);
68 curr += 3 + strlen(name);
70 if(arg_desc && *arg_desc)
72 printf("%s ", arg_desc);
73 curr += 1 + strlen(arg_desc);
75 if(curr >= col3)
77 printf("\n");
78 curr = 0;
80 if(opt_help) /* let's print the option's help body */
82 const char *str = opt_help;
83 while(*str)
85 while(curr < col3)
87 printf(" ");
88 curr++;
90 switch(*str)
92 case '\n':
93 printf("\n");
94 curr = 0;
95 break;
96 case '\t':
99 printf(" ");
100 curr++;
102 while((curr - col3) % tabsize != 0 && curr < col4);
103 case ' ':
104 if(*str == ' ')
106 curr++;
107 printf(" ");
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++;
118 if(curr >= col4)
120 printf("\n");
121 curr = 0;
123 str++;
126 printf("\n");
129 void gaa_help(void)
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('n', "netconf-hint", "HINT ", "derive key from Netconf password, using HINT as the psk_identity_hint.");
135 __gaa_helpsingle('s', "keysize", "SIZE ", "specify the key size in bytes.");
136 __gaa_helpsingle('v', "version", "", "prints the program's version number");
137 __gaa_helpsingle('h', "help", "", "shows this help text");
139 #line 100 "gaa.skel"
141 /* Copy of C area */
143 #line 104 "gaa.skel"
144 /* GAA HEADER */
145 #ifndef GAA_HEADER_POKY
146 #define GAA_HEADER_POKY
148 typedef struct _gaainfo gaainfo;
150 struct _gaainfo
152 #line 25 "psk.gaa"
153 int key_size;
154 #line 22 "psk.gaa"
155 char *netconf_hint;
156 #line 19 "psk.gaa"
157 char *passwd;
158 #line 16 "psk.gaa"
159 char *username;
161 #line 114 "gaa.skel"
164 #ifdef __cplusplus
165 extern "C"
167 #endif
169 int gaa(int argc, char *argv[], gaainfo *gaaval);
171 void gaa_help(void);
173 int gaa_file(const char *name, gaainfo *gaaval);
175 #ifdef __cplusplus
177 #endif
180 #endif
182 #line 135 "gaa.skel"
184 /* C declarations */
186 #define GAAERROR(x) \
188 gaa_error = 1; \
189 return x; \
192 static char *gaa_current_option;
193 static int gaa_error = 0;
195 /* Generated by gaa */
197 #include <string.h>
198 #include <stdlib.h>
201 #define GAA_OK -1
203 #define GAA_ERROR_NOMATCH 0
204 #define GAA_ERROR_NOTENOUGH_ARGS 1
205 #define GAA_ERROR_INVALID_ARG 2
206 #define GAA_ERROR_UNKNOWN 3
208 #define GAA_NOT_AN_OPTION 0
209 #define GAA_WORD_OPTION 1
210 #define GAA_LETTER_OPTION 2
211 #define GAA_MULTIPLE_OPTION 3
213 #define GAA_REST 0
214 #define GAA_NB_OPTION 6
215 #define GAAOPTID_help 1
216 #define GAAOPTID_version 2
217 #define GAAOPTID_keysize 3
218 #define GAAOPTID_netconf_hint 4
219 #define GAAOPTID_passwd 5
220 #define GAAOPTID_username 6
222 #line 168 "gaa.skel"
224 #define GAA_CHECK1STR(a,b) \
225 if(a[0] == str[0]) \
227 gaa_current_option = a; \
228 return b; \
231 #define GAA_CHECKSTR(a,b) \
232 if(strcmp(a,str) == 0) \
234 gaa_current_option = a; \
235 return b; \
238 #define GAA_TESTMOREARGS \
239 if(!OK) \
241 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
242 gaa_index++; \
243 if(gaa_last_non_option == gaa_index) \
244 return GAA_ERROR_NOTENOUGH_ARGS; \
247 #define GAA_TESTMOREOPTIONALARGS \
248 if(!OK) \
250 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
251 gaa_index++; \
252 if(gaa_last_non_option == gaa_index) \
253 OK = 1; \
256 #define GAA_FILL_2ARGS(target, func) \
257 target = func(GAAargv[gaa_index]); \
258 gaa_arg_used[gaa_index] = 1; \
259 if(gaa_error == 1) \
261 gaa_error = 0; \
262 return GAA_ERROR_INVALID_ARG; \
267 #define GAA_FILL(target, func, num) \
268 if(!OK) \
270 target = func(GAAargv[gaa_index]); \
271 gaa_arg_used[gaa_index] = 1; \
272 if(gaa_error == 1) \
274 gaa_error = 0; \
275 return GAA_ERROR_INVALID_ARG; \
277 num = 1; \
279 else \
281 num = 0; \
284 #define GAA_LIST_FILL(target, func, type ,num) \
285 if(!OK) \
287 num = 0; \
288 target = NULL; \
289 if ( gaa_last_non_option - gaa_index > 0) \
290 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
291 for(; gaa_index < gaa_last_non_option; gaa_index++) \
293 if(gaa_arg_used[gaa_index] == 0) \
295 GAA_FILL_2ARGS(target[num], func); \
296 num++; \
299 if(num == 0) \
300 return GAA_ERROR_NOTENOUGH_ARGS; \
303 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
304 if(!OK) \
306 num = 0; \
307 target = NULL; \
308 if ( gaa_last_non_option - gaa_index > 0) \
309 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
310 for(; gaa_index < gaa_last_non_option; gaa_index++) \
312 if(gaa_arg_used[gaa_index] == 0) \
314 GAA_FILL_2ARGS(target[num], func); \
315 num++; \
320 #define GAA_OBLIGAT(str) \
321 k = 0; \
322 for(i = 0; i < strlen(str); i++) \
324 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
325 if(j == GAA_ERROR_NOMATCH) \
327 printf("Error: invalid 'obligat' set\n"); \
328 exit(-1); \
330 if(opt_list[j] == 1) \
331 k = 1; \
333 if(k == 0) \
335 if(strlen(str) == 1) \
336 printf("You must give the -%s option\n", str); \
337 else \
338 printf("You must give at least one option of '%s'\n", str); \
339 return 0; \
342 #define GAA_INCOMP(str) \
343 k = 0; \
344 for(i = 0; i < strlen(str); i++) \
346 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
347 if(j == GAA_ERROR_NOMATCH) \
349 printf("Error: invalid 'obligat' set\n"); \
350 exit(-1); \
352 if(opt_list[j] == 1) \
353 k++; \
355 if(k > 1) \
357 printf("The options '%s' are incompatible\n", str); \
358 return 0; \
362 static char **GAAargv;
363 static int GAAargc;
364 static char *gaa_arg_used;
365 static int gaa_processing_file = 0;
366 static int inited = 0;
368 static int gaa_getint(char *arg)
370 int tmp;
371 char a;
372 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
374 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
375 GAAERROR(-1);
377 return tmp;
381 static char* gaa_getstr(char *arg)
383 return arg;
386 /* option structures */
388 struct GAAOPTION_keysize
390 int arg1;
391 int size1;
394 struct GAAOPTION_netconf_hint
396 char* arg1;
397 int size1;
400 struct GAAOPTION_passwd
402 char* arg1;
403 int size1;
406 struct GAAOPTION_username
408 char* arg1;
409 int size1;
412 #line 349 "gaa.skel"
413 static int gaa_is_an_argument(char *str)
415 #ifdef GAA_WIN32
416 if(str[0] == '/' && str[1] != 0)
417 return GAA_MULTIPLE_OPTION;
418 #endif
419 if(str[0] != '-')
420 return GAA_NOT_AN_OPTION;
421 if(str[1] == 0)
422 return GAA_NOT_AN_OPTION;
423 if(str[1] == '-')
425 if(str[2] != 0)
426 return GAA_WORD_OPTION;
427 else
428 return GAA_NOT_AN_OPTION;
430 if(str[2] == 0)
431 return GAA_LETTER_OPTION;
432 else
433 return GAA_MULTIPLE_OPTION;
436 static int gaa_get_option_num(char *str, int status)
438 switch(status)
440 case GAA_LETTER_OPTION:
441 GAA_CHECK1STR("s", GAAOPTID_keysize);
442 GAA_CHECK1STR("n", GAAOPTID_netconf_hint);
443 GAA_CHECK1STR("p", GAAOPTID_passwd);
444 GAA_CHECK1STR("u", GAAOPTID_username);
445 case GAA_MULTIPLE_OPTION:
446 #line 375 "gaa.skel"
447 GAA_CHECK1STR("h", GAAOPTID_help);
448 GAA_CHECK1STR("v", GAAOPTID_version);
450 #line 277 "gaa.skel"
451 break;
452 case GAA_WORD_OPTION:
453 GAA_CHECKSTR("help", GAAOPTID_help);
454 GAA_CHECKSTR("version", GAAOPTID_version);
455 GAA_CHECKSTR("keysize", GAAOPTID_keysize);
456 GAA_CHECKSTR("netconf-hint", GAAOPTID_netconf_hint);
457 GAA_CHECKSTR("passwd", GAAOPTID_passwd);
458 GAA_CHECKSTR("username", GAAOPTID_username);
460 #line 281 "gaa.skel"
461 break;
462 default: break;
464 return GAA_ERROR_NOMATCH;
467 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
469 int OK = 0;
470 int gaa_last_non_option;
471 struct GAAOPTION_keysize GAATMP_keysize;
472 struct GAAOPTION_netconf_hint GAATMP_netconf_hint;
473 struct GAAOPTION_passwd GAATMP_passwd;
474 struct GAAOPTION_username GAATMP_username;
476 #line 393 "gaa.skel"
477 #ifdef GAA_REST_EXISTS
478 struct GAAREST GAAREST_tmp;
479 #endif
481 opt_list[gaa_num] = 1;
483 for(gaa_last_non_option = gaa_index;
484 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
485 gaa_last_non_option++);
487 if(gaa_num == GAA_REST)
489 gaa_index = 1;
490 gaa_last_non_option = GAAargc;
493 switch(gaa_num)
495 case GAAOPTID_help:
496 OK = 0;
497 #line 29 "psk.gaa"
498 { gaa_help(); exit(0); ;};
500 return GAA_OK;
501 break;
502 case GAAOPTID_version:
503 OK = 0;
504 #line 28 "psk.gaa"
505 { psktool_version(); exit(0); ;};
507 return GAA_OK;
508 break;
509 case GAAOPTID_keysize:
510 OK = 0;
511 GAA_TESTMOREARGS;
512 GAA_FILL(GAATMP_keysize.arg1, gaa_getint, GAATMP_keysize.size1);
513 gaa_index++;
514 #line 26 "psk.gaa"
515 { gaaval->key_size = GAATMP_keysize.arg1 ;};
517 return GAA_OK;
518 break;
519 case GAAOPTID_netconf_hint:
520 OK = 0;
521 GAA_TESTMOREARGS;
522 GAA_FILL(GAATMP_netconf_hint.arg1, gaa_getstr, GAATMP_netconf_hint.size1);
523 gaa_index++;
524 #line 23 "psk.gaa"
525 { gaaval->netconf_hint = GAATMP_netconf_hint.arg1 ;};
527 return GAA_OK;
528 break;
529 case GAAOPTID_passwd:
530 OK = 0;
531 GAA_TESTMOREARGS;
532 GAA_FILL(GAATMP_passwd.arg1, gaa_getstr, GAATMP_passwd.size1);
533 gaa_index++;
534 #line 20 "psk.gaa"
535 { gaaval->passwd = GAATMP_passwd.arg1 ;};
537 return GAA_OK;
538 break;
539 case GAAOPTID_username:
540 OK = 0;
541 GAA_TESTMOREARGS;
542 GAA_FILL(GAATMP_username.arg1, gaa_getstr, GAATMP_username.size1);
543 gaa_index++;
544 #line 17 "psk.gaa"
545 { gaaval->username = GAATMP_username.arg1 ;};
547 return GAA_OK;
548 break;
550 #line 413 "gaa.skel"
551 default: break;
553 return GAA_ERROR_UNKNOWN;
556 int gaa(int argc, char **argv, gaainfo *gaaval)
558 int tmp1, tmp2;
559 int l;
560 size_t i, j;
561 char *opt_list;
563 i = 0;
565 GAAargv = argv;
566 GAAargc = argc;
568 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
570 for(l = 0; l < GAA_NB_OPTION + 1; l++)
571 opt_list[l] = 0;
572 /* initialization */
573 if(inited == 0)
576 #line 31 "psk.gaa"
577 { gaaval->username=NULL; gaaval->passwd=NULL; gaaval->key_size = 0; gaaval->netconf_hint = NULL; ;};
580 inited = 1;
581 #line 438 "gaa.skel"
582 gaa_arg_used = NULL;
584 if (argc > 0) {
585 gaa_arg_used = gaa_malloc(argc * sizeof(char));
588 for(l = 1; l < argc; l++)
589 gaa_arg_used[l] = 0;
590 for(l = 1; l < argc; l++)
592 if(gaa_arg_used[l] == 0)
594 j = 0;
595 tmp1 = gaa_is_an_argument(GAAargv[l]);
596 switch(tmp1)
598 case GAA_WORD_OPTION:
599 j++;
600 case GAA_LETTER_OPTION:
601 j++;
602 tmp2 = gaa_get_option_num(argv[l]+j, tmp1);
603 if(tmp2 == GAA_ERROR_NOMATCH)
605 printf("Invalid option '%s'\n", argv[l]+j);
606 return 0;
608 switch(gaa_try(tmp2, l+1, gaaval, opt_list))
610 case GAA_ERROR_NOTENOUGH_ARGS:
611 printf("'%s': not enough arguments\n",gaa_current_option);
612 return 0;
613 case GAA_ERROR_INVALID_ARG:
614 printf("Invalid arguments\n");
615 return 0;
616 case GAA_OK:
617 break;
618 default:
619 printf("Unknown error\n");
621 gaa_arg_used[l] = 1;
622 break;
623 case GAA_MULTIPLE_OPTION:
624 for(j = 1; j < strlen(argv[l]); j++)
626 tmp2 = gaa_get_option_num(argv[l]+j, tmp1);
627 if(tmp2 == GAA_ERROR_NOMATCH)
629 printf("Invalid option '%c'\n", *(argv[l]+j));
630 return 0;
632 switch(gaa_try(tmp2, l+1, gaaval, opt_list))
634 case GAA_ERROR_NOTENOUGH_ARGS:
635 printf("'%s': not enough arguments\n",gaa_current_option);
636 return 0;
637 case GAA_ERROR_INVALID_ARG:
638 printf("Invalid arguments\n");
639 return 0;
640 case GAA_OK:
641 break;
642 default:
643 printf("Unknown error\n");
646 gaa_arg_used[l] = 1;
647 break;
648 default: break;
652 if(gaa_processing_file == 0)
655 #line 507 "gaa.skel"
656 #ifdef GAA_REST_EXISTS
657 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
659 case GAA_ERROR_NOTENOUGH_ARGS:
660 printf("Rest: not enough arguments\n");
661 return 0;
662 case GAA_ERROR_INVALID_ARG:
663 printf("Invalid arguments\n");
664 return 0;
665 case GAA_OK:
666 break;
667 default:
668 printf("Unknown error\n");
670 #endif
672 for(l = 1; l < argc; l++)
674 if(gaa_arg_used[l] == 0)
676 printf("Too many arguments\n");
677 return 0;
680 free(gaa_arg_used);
681 free(opt_list);
682 return -1;
685 struct gaastrnode
687 char *str;
688 struct gaastrnode *next;
691 typedef struct gaastrnode gaa_str_node;
693 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
695 int pos_ini;
696 int a;
697 int i = 0, len = 0, newline = 0;
699 if(argc == 1) {
700 newline = 1;
701 len = 2;
704 a = fgetc( file);
705 if (a == EOF) return 0;
707 while(a == ' ' || a == 9 || a == '\n')
709 if(a == '\n')
711 newline=1;
712 len = 2;
714 a = fgetc( file);
715 if (a == EOF) return 0;
718 pos_ini = ftell(file) - 1;
720 while(a != ' ' && a != 9 && a != '\n')
723 len++;
724 a = fgetc( file);
725 if(a==EOF) return 0; /* a = ' '; */
728 len += 1;
729 tmp_str->str = gaa_malloc((len) * sizeof(char));
731 if(newline == 1)
733 tmp_str->str[0] = '-';
734 tmp_str->str[1] = '-';
735 i = 2;
737 else
739 i = 0;
742 fseek(file,pos_ini, SEEK_SET);
745 a = fgetc( file);
747 if (a == EOF) {
748 i+=2;
749 break;
751 tmp_str->str[i] = a;
752 i++;
754 while(a != ' ' && a != 9 && a != '\n' && i < len);
756 tmp_str->str[i - 1] = 0;
758 fseek(file,- 1, SEEK_CUR);
759 /* printf("%d\n", ftell(file)); */
761 return -1;
764 int gaa_file(const char *name, gaainfo *gaaval)
766 gaa_str_node *first_str, **tmp_str, *tmp_str2;
767 int rval, i;
768 char **argv;
769 int argc = 0;
770 FILE *file;
772 gaa_processing_file = 1;
774 if((file = fopen(name, "r")) == NULL)
776 printf("Couldn't open '%s' configuration file for reading\n", name);
777 return 1;
780 tmp_str = &first_str;
783 argc++;
784 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
786 (*tmp_str)->str = NULL;
787 (*tmp_str)->next = NULL;
789 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
790 tmp_str = &((*tmp_str)->next);
792 while(rval == -1);
794 if(rval == 1)
795 return 0;
797 argv = gaa_malloc((1 + argc) * sizeof(char*));
799 tmp_str2 = first_str;
800 argv[0] = "cfg";
801 for(i = 1; i < argc; i++)
803 argv[i] = tmp_str2->str;
804 tmp_str2 = tmp_str2->next;
807 rval = gaa(argc, argv, gaaval);
808 gaa_processing_file = 0;
809 return rval;