Fix symbol export rules.
[gnutls.git] / src / tls_test-gaa.c
blobc4f396de8edc6075c3eb6a257a1cd34b3d43888a
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "tls_test.gaa"
7 /* C declarations */
9 #include <config.h>
10 #ifdef _WIN32
11 # include <io.h>
12 #endif
14 void tls_test_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("GNU TLS debug client\nUsage: gnutls-cli-debug [options] hostname\n\n\n");
132 __gaa_helpsingle('p', "port", "integer ", "The port to connect to.");
133 __gaa_helpsingle('d', "debug", "integer ", "Enable debugging");
134 __gaa_helpsingle('V', "verbose", "", "More verbose output");
135 __gaa_helpsingle('v', "version", "", "prints the program's version number");
136 __gaa_helpsingle('h', "help", "", "prints this help");
138 #line 100 "gaa.skel"
140 /* Copy of C area */
142 #line 104 "gaa.skel"
143 /* GAA HEADER */
144 #ifndef GAA_HEADER_POKY
145 #define GAA_HEADER_POKY
147 typedef struct _gaainfo gaainfo;
149 struct _gaainfo
151 #line 29 "tls_test.gaa"
152 char *rest_args;
153 #line 22 "tls_test.gaa"
154 int more_info;
155 #line 19 "tls_test.gaa"
156 int debug;
157 #line 16 "tls_test.gaa"
158 int pp;
160 #line 114 "gaa.skel"
163 #ifdef __cplusplus
164 extern "C"
166 #endif
168 int gaa(int argc, char *argv[], gaainfo *gaaval);
170 void gaa_help(void);
172 int gaa_file(const char *name, gaainfo *gaaval);
174 #ifdef __cplusplus
176 #endif
179 #endif
181 #line 135 "gaa.skel"
183 /* C declarations */
185 #define GAAERROR(x) \
187 gaa_error = 1; \
188 return x; \
191 static char *gaa_current_option;
192 static int gaa_error = 0;
194 /* Generated by gaa */
196 #include <string.h>
197 #include <stdlib.h>
200 #define GAA_OK -1
202 #define GAA_ERROR_NOMATCH 0
203 #define GAA_ERROR_NOTENOUGH_ARGS 1
204 #define GAA_ERROR_INVALID_ARG 2
205 #define GAA_ERROR_UNKNOWN 3
207 #define GAA_NOT_AN_OPTION 0
208 #define GAA_WORD_OPTION 1
209 #define GAA_LETTER_OPTION 2
210 #define GAA_MULTIPLE_OPTION 3
212 #define GAA_REST 0
213 #define GAA_NB_OPTION 5
214 #define GAAOPTID_help 1
215 #define GAAOPTID_version 2
216 #define GAAOPTID_verbose 3
217 #define GAAOPTID_debug 4
218 #define GAAOPTID_port 5
220 #line 168 "gaa.skel"
222 #define GAA_CHECK1STR(a,b) \
223 if(a[0] == str[0]) \
225 gaa_current_option = a; \
226 return b; \
229 #define GAA_CHECKSTR(a,b) \
230 if(strcmp(a,str) == 0) \
232 gaa_current_option = a; \
233 return b; \
236 #define GAA_TESTMOREARGS \
237 if(!OK) \
239 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
240 gaa_index++; \
241 if(gaa_last_non_option == gaa_index) \
242 return GAA_ERROR_NOTENOUGH_ARGS; \
245 #define GAA_TESTMOREOPTIONALARGS \
246 if(!OK) \
248 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
249 gaa_index++; \
250 if(gaa_last_non_option == gaa_index) \
251 OK = 1; \
254 #define GAA_FILL_2ARGS(target, func) \
255 target = func(GAAargv[gaa_index]); \
256 gaa_arg_used[gaa_index] = 1; \
257 if(gaa_error == 1) \
259 gaa_error = 0; \
260 return GAA_ERROR_INVALID_ARG; \
265 #define GAA_FILL(target, func, num) \
266 if(!OK) \
268 target = func(GAAargv[gaa_index]); \
269 gaa_arg_used[gaa_index] = 1; \
270 if(gaa_error == 1) \
272 gaa_error = 0; \
273 return GAA_ERROR_INVALID_ARG; \
275 num = 1; \
277 else \
279 num = 0; \
282 #define GAA_LIST_FILL(target, func, type ,num) \
283 if(!OK) \
285 num = 0; \
286 target = NULL; \
287 if ( gaa_last_non_option - gaa_index > 0) \
288 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
289 for(; gaa_index < gaa_last_non_option; gaa_index++) \
291 if(gaa_arg_used[gaa_index] == 0) \
293 GAA_FILL_2ARGS(target[num], func); \
294 num++; \
297 if(num == 0) \
298 return GAA_ERROR_NOTENOUGH_ARGS; \
301 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
302 if(!OK) \
304 num = 0; \
305 target = NULL; \
306 if ( gaa_last_non_option - gaa_index > 0) \
307 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
308 for(; gaa_index < gaa_last_non_option; gaa_index++) \
310 if(gaa_arg_used[gaa_index] == 0) \
312 GAA_FILL_2ARGS(target[num], func); \
313 num++; \
318 #define GAA_OBLIGAT(str) \
319 k = 0; \
320 for(i = 0; i < strlen(str); i++) \
322 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
323 if(j == GAA_ERROR_NOMATCH) \
325 printf("Error: invalid 'obligat' set\n"); \
326 exit(-1); \
328 if(opt_list[j] == 1) \
329 k = 1; \
331 if(k == 0) \
333 if(strlen(str) == 1) \
334 printf("You must give the -%s option\n", str); \
335 else \
336 printf("You must give at least one option of '%s'\n", str); \
337 return 0; \
340 #define GAA_INCOMP(str) \
341 k = 0; \
342 for(i = 0; i < strlen(str); i++) \
344 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
345 if(j == GAA_ERROR_NOMATCH) \
347 printf("Error: invalid 'obligat' set\n"); \
348 exit(-1); \
350 if(opt_list[j] == 1) \
351 k++; \
353 if(k > 1) \
355 printf("The options '%s' are incompatible\n", str); \
356 return 0; \
360 static char **GAAargv;
361 static int GAAargc;
362 static char *gaa_arg_used;
363 static int gaa_processing_file = 0;
364 static int inited = 0;
366 static int gaa_getint(char *arg)
368 int tmp;
369 char a;
370 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
372 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
373 GAAERROR(-1);
375 return tmp;
379 static char* gaa_getstr(char *arg)
381 return arg;
384 /* option structures */
386 struct GAAOPTION_debug
388 int arg1;
389 int size1;
392 struct GAAOPTION_port
394 int arg1;
395 int size1;
397 #define GAA_REST_EXISTS
399 struct GAAREST
401 char* arg1;
402 int size1;
405 #line 349 "gaa.skel"
406 static int gaa_is_an_argument(char *str)
408 #ifdef GAA_WIN32
409 if(str[0] == '/' && str[1] != 0)
410 return GAA_MULTIPLE_OPTION;
411 #endif
412 if(str[0] != '-')
413 return GAA_NOT_AN_OPTION;
414 if(str[1] == 0)
415 return GAA_NOT_AN_OPTION;
416 if(str[1] == '-')
418 if(str[2] != 0)
419 return GAA_WORD_OPTION;
420 else
421 return GAA_NOT_AN_OPTION;
423 if(str[2] == 0)
424 return GAA_LETTER_OPTION;
425 else
426 return GAA_MULTIPLE_OPTION;
429 static int gaa_get_option_num(char *str, int status)
431 switch(status)
433 case GAA_LETTER_OPTION:
434 GAA_CHECK1STR("d", GAAOPTID_debug);
435 GAA_CHECK1STR("p", GAAOPTID_port);
436 case GAA_MULTIPLE_OPTION:
437 #line 375 "gaa.skel"
438 GAA_CHECK1STR("h", GAAOPTID_help);
439 GAA_CHECK1STR("v", GAAOPTID_version);
440 GAA_CHECK1STR("V", GAAOPTID_verbose);
442 #line 277 "gaa.skel"
443 break;
444 case GAA_WORD_OPTION:
445 GAA_CHECKSTR("help", GAAOPTID_help);
446 GAA_CHECKSTR("version", GAAOPTID_version);
447 GAA_CHECKSTR("verbose", GAAOPTID_verbose);
448 GAA_CHECKSTR("debug", GAAOPTID_debug);
449 GAA_CHECKSTR("port", GAAOPTID_port);
451 #line 281 "gaa.skel"
452 break;
453 default: break;
455 return GAA_ERROR_NOMATCH;
458 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
460 int OK = 0;
461 int gaa_last_non_option;
462 struct GAAOPTION_debug GAATMP_debug;
463 struct GAAOPTION_port GAATMP_port;
465 #line 393 "gaa.skel"
466 #ifdef GAA_REST_EXISTS
467 struct GAAREST GAAREST_tmp;
468 #endif
470 opt_list[gaa_num] = 1;
472 for(gaa_last_non_option = gaa_index;
473 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
474 gaa_last_non_option++);
476 if(gaa_num == GAA_REST)
478 gaa_index = 1;
479 gaa_last_non_option = GAAargc;
482 switch(gaa_num)
484 case GAAOPTID_help:
485 OK = 0;
486 #line 26 "tls_test.gaa"
487 { gaa_help(); exit(0); ;};
489 return GAA_OK;
490 break;
491 case GAAOPTID_version:
492 OK = 0;
493 #line 25 "tls_test.gaa"
494 { tls_test_version(); exit(0); ;};
496 return GAA_OK;
497 break;
498 case GAAOPTID_verbose:
499 OK = 0;
500 #line 23 "tls_test.gaa"
501 { gaaval->more_info += 1 ;};
503 return GAA_OK;
504 break;
505 case GAAOPTID_debug:
506 OK = 0;
507 GAA_TESTMOREARGS;
508 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
509 gaa_index++;
510 #line 20 "tls_test.gaa"
511 { gaaval->debug = GAATMP_debug.arg1 ;};
513 return GAA_OK;
514 break;
515 case GAAOPTID_port:
516 OK = 0;
517 GAA_TESTMOREARGS;
518 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
519 gaa_index++;
520 #line 17 "tls_test.gaa"
521 { gaaval->pp = GAATMP_port.arg1 ;};
523 return GAA_OK;
524 break;
525 case GAA_REST:
526 GAA_TESTMOREARGS;
527 GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
528 gaa_index++;
529 #line 30 "tls_test.gaa"
530 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
532 return GAA_OK;
533 break;
535 #line 413 "gaa.skel"
536 default: break;
538 return GAA_ERROR_UNKNOWN;
541 int gaa(int argc, char **argv, gaainfo *gaaval)
543 int tmp1, tmp2;
544 int l;
545 size_t i, j;
546 char *opt_list;
548 i = 0;
550 GAAargv = argv;
551 GAAargc = argc;
553 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
555 for(l = 0; l < GAA_NB_OPTION + 1; l++)
556 opt_list[l] = 0;
557 /* initialization */
558 if(inited == 0)
561 #line 32 "tls_test.gaa"
562 { gaaval->rest_args=NULL; gaaval->pp = 443; gaaval->more_info = 0; ;};
565 inited = 1;
566 #line 438 "gaa.skel"
567 gaa_arg_used = NULL;
569 if (argc > 0) {
570 gaa_arg_used = gaa_malloc(argc * sizeof(char));
573 for(l = 1; l < argc; l++)
574 gaa_arg_used[l] = 0;
575 for(l = 1; l < argc; l++)
577 if(gaa_arg_used[l] == 0)
579 j = 0;
580 tmp1 = gaa_is_an_argument(GAAargv[l]);
581 switch(tmp1)
583 case GAA_WORD_OPTION:
584 j++;
585 case GAA_LETTER_OPTION:
586 j++;
587 tmp2 = gaa_get_option_num(argv[l]+j, tmp1);
588 if(tmp2 == GAA_ERROR_NOMATCH)
590 printf("Invalid option '%s'\n", argv[l]+j);
591 return 0;
593 switch(gaa_try(tmp2, l+1, gaaval, opt_list))
595 case GAA_ERROR_NOTENOUGH_ARGS:
596 printf("'%s': not enough arguments\n",gaa_current_option);
597 return 0;
598 case GAA_ERROR_INVALID_ARG:
599 printf("Invalid arguments\n");
600 return 0;
601 case GAA_OK:
602 break;
603 default:
604 printf("Unknown error\n");
606 gaa_arg_used[l] = 1;
607 break;
608 case GAA_MULTIPLE_OPTION:
609 for(j = 1; j < strlen(argv[l]); j++)
611 tmp2 = gaa_get_option_num(argv[l]+j, tmp1);
612 if(tmp2 == GAA_ERROR_NOMATCH)
614 printf("Invalid option '%c'\n", *(argv[l]+j));
615 return 0;
617 switch(gaa_try(tmp2, l+1, gaaval, opt_list))
619 case GAA_ERROR_NOTENOUGH_ARGS:
620 printf("'%s': not enough arguments\n",gaa_current_option);
621 return 0;
622 case GAA_ERROR_INVALID_ARG:
623 printf("Invalid arguments\n");
624 return 0;
625 case GAA_OK:
626 break;
627 default:
628 printf("Unknown error\n");
631 gaa_arg_used[l] = 1;
632 break;
633 default: break;
637 if(gaa_processing_file == 0)
640 #line 507 "gaa.skel"
641 #ifdef GAA_REST_EXISTS
642 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
644 case GAA_ERROR_NOTENOUGH_ARGS:
645 printf("Rest: not enough arguments\n");
646 return 0;
647 case GAA_ERROR_INVALID_ARG:
648 printf("Invalid arguments\n");
649 return 0;
650 case GAA_OK:
651 break;
652 default:
653 printf("Unknown error\n");
655 #endif
657 for(l = 1; l < argc; l++)
659 if(gaa_arg_used[l] == 0)
661 printf("Too many arguments\n");
662 return 0;
665 free(gaa_arg_used);
666 free(opt_list);
667 return -1;
670 struct gaastrnode
672 char *str;
673 struct gaastrnode *next;
676 typedef struct gaastrnode gaa_str_node;
678 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
680 int pos_ini;
681 int a;
682 int i = 0, len = 0, newline = 0;
684 if(argc == 1) {
685 newline = 1;
686 len = 2;
689 a = fgetc( file);
690 if (a == EOF) return 0;
692 while(a == ' ' || a == 9 || a == '\n')
694 if(a == '\n')
696 newline=1;
697 len = 2;
699 a = fgetc( file);
700 if (a == EOF) return 0;
703 pos_ini = ftell(file) - 1;
705 while(a != ' ' && a != 9 && a != '\n')
708 len++;
709 a = fgetc( file);
710 if(a==EOF) return 0; /* a = ' '; */
713 len += 1;
714 tmp_str->str = gaa_malloc((len) * sizeof(char));
716 if(newline == 1)
718 tmp_str->str[0] = '-';
719 tmp_str->str[1] = '-';
720 i = 2;
722 else
724 i = 0;
727 fseek(file,pos_ini, SEEK_SET);
730 a = fgetc( file);
732 if (a == EOF) {
733 i+=2;
734 break;
736 tmp_str->str[i] = a;
737 i++;
739 while(a != ' ' && a != 9 && a != '\n' && i < len);
741 tmp_str->str[i - 1] = 0;
743 fseek(file,- 1, SEEK_CUR);
744 /* printf("%d\n", ftell(file)); */
746 return -1;
749 int gaa_file(const char *name, gaainfo *gaaval)
751 gaa_str_node *first_str, **tmp_str, *tmp_str2;
752 int rval, i;
753 char **argv;
754 int argc = 0;
755 FILE *file;
757 gaa_processing_file = 1;
759 if((file = fopen(name, "r")) == NULL)
761 printf("Couldn't open '%s' configuration file for reading\n", name);
762 return 1;
765 tmp_str = &first_str;
768 argc++;
769 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
771 (*tmp_str)->str = NULL;
772 (*tmp_str)->next = NULL;
774 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
775 tmp_str = &((*tmp_str)->next);
777 while(rval == -1);
779 if(rval == 1)
780 return 0;
782 argv = gaa_malloc((1 + argc) * sizeof(char*));
784 tmp_str2 = first_str;
785 argv[0] = "cfg";
786 for(i = 1; i < argc; i++)
788 argv[i] = tmp_str2->str;
789 tmp_str2 = tmp_str2->next;
792 rval = gaa(argc, argv, gaaval);
793 gaa_processing_file = 0;
794 return rval;