1 /* File generated by GAA 1.6.6
14 void tls_test_version(void);
21 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
26 static void* gaa_malloc( size_t size) {
30 fprintf(stderr, "gaa: could not allocate memory");
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;
42 col1 = 5; /* Default values */
47 for(i = 0; i < col1; i++)
56 printf("-%c, ", short_name);
61 printf("-%c ", short_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);
80 if(opt_help) /* let's print the option's help body */
82 const char *str = opt_help;
102 while((curr - col3) % tabsize != 0 && curr < col4);
109 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
110 && str[i] != '\t'; i++);
111 if(curr + i - 1 >= col4)
131 printf("GnuTLS 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");
144 #ifndef GAA_HEADER_POKY
145 #define GAA_HEADER_POKY
147 typedef struct _gaainfo gaainfo;
151 #line 29 "tls_test.gaa"
153 #line 22 "tls_test.gaa"
155 #line 19 "tls_test.gaa"
157 #line 16 "tls_test.gaa"
168 int gaa(int argc, char *argv[], gaainfo *gaaval);
172 int gaa_file(const char *name, gaainfo *gaaval);
185 #define GAAERROR(x) \
191 static char *gaa_current_option;
192 static int gaa_error = 0;
194 /* Generated by gaa */
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
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
222 #define GAA_CHECK1STR(a,b) \
225 gaa_current_option = a; \
229 #define GAA_CHECKSTR(a,b) \
230 if(strcmp(a,str) == 0) \
232 gaa_current_option = a; \
236 #define GAA_TESTMOREARGS \
239 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
241 if(gaa_last_non_option == gaa_index) \
242 return GAA_ERROR_NOTENOUGH_ARGS; \
245 #define GAA_TESTMOREOPTIONALARGS \
248 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
250 if(gaa_last_non_option == gaa_index) \
254 #define GAA_FILL_2ARGS(target, func) \
255 target = func(GAAargv[gaa_index]); \
256 gaa_arg_used[gaa_index] = 1; \
260 return GAA_ERROR_INVALID_ARG; \
265 #define GAA_FILL(target, func, num) \
268 target = func(GAAargv[gaa_index]); \
269 gaa_arg_used[gaa_index] = 1; \
273 return GAA_ERROR_INVALID_ARG; \
282 #define GAA_LIST_FILL(target, func, type ,num) \
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); \
298 return GAA_ERROR_NOTENOUGH_ARGS; \
301 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
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); \
318 #define GAA_OBLIGAT(str) \
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"); \
328 if(opt_list[j] == 1) \
333 if(strlen(str) == 1) \
334 printf("You must give the -%s option\n", str); \
336 printf("You must give at least one option of '%s'\n", str); \
340 #define GAA_INCOMP(str) \
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"); \
350 if(opt_list[j] == 1) \
355 printf("The options '%s' are incompatible\n", str); \
360 static char **GAAargv;
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)
370 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
372 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
379 static char* gaa_getstr(char *arg)
384 /* option structures */
386 struct GAAOPTION_debug
392 struct GAAOPTION_port
397 #define GAA_REST_EXISTS
406 static int gaa_is_an_argument(char *str)
409 if(str[0] == '/' && str[1] != 0)
410 return GAA_MULTIPLE_OPTION;
413 return GAA_NOT_AN_OPTION;
415 return GAA_NOT_AN_OPTION;
419 return GAA_WORD_OPTION;
421 return GAA_NOT_AN_OPTION;
424 return GAA_LETTER_OPTION;
426 return GAA_MULTIPLE_OPTION;
429 static int gaa_get_option_num(char *str, int status)
433 case GAA_LETTER_OPTION:
434 GAA_CHECK1STR("d", GAAOPTID_debug);
435 GAA_CHECK1STR("p", GAAOPTID_port);
436 case GAA_MULTIPLE_OPTION:
438 GAA_CHECK1STR("h", GAAOPTID_help);
439 GAA_CHECK1STR("v", GAAOPTID_version);
440 GAA_CHECK1STR("V", GAAOPTID_verbose);
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);
455 return GAA_ERROR_NOMATCH;
458 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
461 int gaa_last_non_option;
462 struct GAAOPTION_debug GAATMP_debug;
463 struct GAAOPTION_port GAATMP_port;
466 #ifdef GAA_REST_EXISTS
467 struct GAAREST GAAREST_tmp;
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)
479 gaa_last_non_option = GAAargc;
486 #line 26 "tls_test.gaa"
487 { gaa_help(); exit(0); ;};
491 case GAAOPTID_version:
493 #line 25 "tls_test.gaa"
494 { tls_test_version(); exit(0); ;};
498 case GAAOPTID_verbose:
500 #line 23 "tls_test.gaa"
501 { gaaval->more_info += 1 ;};
508 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
510 #line 20 "tls_test.gaa"
511 { gaaval->debug = GAATMP_debug.arg1 ;};
518 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
520 #line 17 "tls_test.gaa"
521 { gaaval->pp = GAATMP_port.arg1 ;};
527 GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
529 #line 30 "tls_test.gaa"
530 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
538 return GAA_ERROR_UNKNOWN;
541 int gaa(int argc, char **argv, gaainfo *gaaval)
553 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
555 for(l = 0; l < GAA_NB_OPTION + 1; l++)
561 #line 32 "tls_test.gaa"
562 { gaaval->rest_args=NULL; gaaval->pp = 443; gaaval->more_info = 0; ;};
570 gaa_arg_used = gaa_malloc(argc * sizeof(char));
573 for(l = 1; l < argc; l++)
575 for(l = 1; l < argc; l++)
577 if(gaa_arg_used[l] == 0)
580 tmp1 = gaa_is_an_argument(GAAargv[l]);
583 case GAA_WORD_OPTION:
585 case GAA_LETTER_OPTION:
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);
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);
598 case GAA_ERROR_INVALID_ARG:
599 printf("Invalid arguments\n");
604 printf("Unknown error\n");
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));
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);
622 case GAA_ERROR_INVALID_ARG:
623 printf("Invalid arguments\n");
628 printf("Unknown error\n");
637 if(gaa_processing_file == 0)
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");
647 case GAA_ERROR_INVALID_ARG:
648 printf("Invalid arguments\n");
653 printf("Unknown error\n");
657 for(l = 1; l < argc; l++)
659 if(gaa_arg_used[l] == 0)
661 printf("Too many arguments\n");
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)
682 int i = 0, len = 0, newline = 0;
690 if (a == EOF) return 0;
692 while(a == ' ' || a == 9 || a == '\n')
700 if (a == EOF) return 0;
703 pos_ini = ftell(file) - 1;
705 while(a != ' ' && a != 9 && a != '\n')
710 if(a==EOF) return 0; /* a = ' '; */
714 tmp_str->str = gaa_malloc((len) * sizeof(char));
718 tmp_str->str[0] = '-';
719 tmp_str->str[1] = '-';
727 fseek(file,pos_ini, SEEK_SET);
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)); */
749 int gaa_file(const char *name, gaainfo *gaaval)
751 gaa_str_node *first_str, **tmp_str, *tmp_str2;
757 gaa_processing_file = 1;
759 if((file = fopen(name, "r")) == NULL)
761 printf("Couldn't open '%s' configuration file for reading\n", name);
765 tmp_str = &first_str;
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);
782 argv = gaa_malloc((1 + argc) * sizeof(char*));
784 tmp_str2 = first_str;
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;