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("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");
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
);
378 static char gaa_getchar(char *arg
)
382 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
388 static char* gaa_getstr(char *arg
)
392 static float gaa_getfloat(char *arg
)
396 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
398 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
403 /* option structures */
405 struct GAAOPTION_debug
411 struct GAAOPTION_port
416 #define GAA_REST_EXISTS
425 static int gaa_is_an_argument(char *str
)
428 if(str
[0] == '/' && str
[1] != 0)
429 return GAA_MULTIPLE_OPTION
;
432 return GAA_NOT_AN_OPTION
;
434 return GAA_NOT_AN_OPTION
;
438 return GAA_WORD_OPTION
;
440 return GAA_NOT_AN_OPTION
;
443 return GAA_LETTER_OPTION
;
445 return GAA_MULTIPLE_OPTION
;
448 static int gaa_get_option_num(char *str
, int status
)
452 case GAA_LETTER_OPTION
:
453 GAA_CHECK1STR("d", GAAOPTID_debug
);
454 GAA_CHECK1STR("p", GAAOPTID_port
);
455 case GAA_MULTIPLE_OPTION
:
457 GAA_CHECK1STR("h", GAAOPTID_help
);
458 GAA_CHECK1STR("v", GAAOPTID_version
);
459 GAA_CHECK1STR("V", GAAOPTID_verbose
);
463 case GAA_WORD_OPTION
:
464 GAA_CHECKSTR("help", GAAOPTID_help
);
465 GAA_CHECKSTR("version", GAAOPTID_version
);
466 GAA_CHECKSTR("verbose", GAAOPTID_verbose
);
467 GAA_CHECKSTR("debug", GAAOPTID_debug
);
468 GAA_CHECKSTR("port", GAAOPTID_port
);
474 return GAA_ERROR_NOMATCH
;
477 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
480 int gaa_last_non_option
;
481 struct GAAOPTION_debug GAATMP_debug
;
482 struct GAAOPTION_port GAATMP_port
;
485 #ifdef GAA_REST_EXISTS
486 struct GAAREST GAAREST_tmp
;
489 opt_list
[gaa_num
] = 1;
491 for(gaa_last_non_option
= gaa_index
;
492 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
493 gaa_last_non_option
++);
495 if(gaa_num
== GAA_REST
)
498 gaa_last_non_option
= GAAargc
;
505 #line 26 "tls_test.gaa"
506 { gaa_help(); exit(0); ;};
510 case GAAOPTID_version
:
512 #line 25 "tls_test.gaa"
513 { tls_test_version(); exit(0); ;};
517 case GAAOPTID_verbose
:
519 #line 23 "tls_test.gaa"
520 { gaaval
->more_info
+= 1 ;};
527 GAA_FILL(GAATMP_debug
.arg1
, gaa_getint
, GAATMP_debug
.size1
);
529 #line 20 "tls_test.gaa"
530 { gaaval
->debug
= GAATMP_debug
.arg1
;};
537 GAA_FILL(GAATMP_port
.arg1
, gaa_getint
, GAATMP_port
.size1
);
539 #line 17 "tls_test.gaa"
540 { gaaval
->pp
= GAATMP_port
.arg1
;};
546 GAA_FILL(GAAREST_tmp
.arg1
, gaa_getstr
, GAAREST_tmp
.size1
);
548 #line 30 "tls_test.gaa"
549 { gaaval
->rest_args
= GAAREST_tmp
.arg1
; ;};
557 return GAA_ERROR_UNKNOWN
;
560 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
569 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
571 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
577 #line 32 "tls_test.gaa"
578 { gaaval
->rest_args
=NULL
; gaaval
->pp
= 443; gaaval
->more_info
= 0; ;};
586 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
589 for(i
= 1; i
< argc
; i
++)
591 for(i
= 1; i
< argc
; i
++)
593 if(gaa_arg_used
[i
] == 0)
596 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
599 case GAA_WORD_OPTION
:
601 case GAA_LETTER_OPTION
:
603 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
604 if(tmp2
== GAA_ERROR_NOMATCH
)
606 printf("Invalid option '%s'\n", argv
[i
]+j
);
609 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
611 case GAA_ERROR_NOTENOUGH_ARGS
:
612 printf("'%s': not enough arguments\n",gaa_current_option
);
614 case GAA_ERROR_INVALID_ARG
:
615 printf("Invalid arguments\n");
620 printf("Unknown error\n");
624 case GAA_MULTIPLE_OPTION
:
625 for(j
= 1; j
< strlen(argv
[i
]); j
++)
627 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
628 if(tmp2
== GAA_ERROR_NOMATCH
)
630 printf("Invalid option '%c'\n", *(argv
[i
]+j
));
633 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
635 case GAA_ERROR_NOTENOUGH_ARGS
:
636 printf("'%s': not enough arguments\n",gaa_current_option
);
638 case GAA_ERROR_INVALID_ARG
:
639 printf("Invalid arguments\n");
644 printf("Unknown error\n");
653 if(gaa_processing_file
== 0)
657 #ifdef GAA_REST_EXISTS
658 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
660 case GAA_ERROR_NOTENOUGH_ARGS
:
661 printf("Rest: not enough arguments\n");
663 case GAA_ERROR_INVALID_ARG
:
664 printf("Invalid arguments\n");
669 printf("Unknown error\n");
673 for(i
= 1; i
< argc
; i
++)
675 if(gaa_arg_used
[i
] == 0)
677 printf("Too many arguments\n");
689 struct gaastrnode
*next
;
692 typedef struct gaastrnode gaa_str_node
;
694 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
698 int i
= 0, len
= 0, newline
= 0;
706 if (a
== EOF
) return 0;
708 while(a
== ' ' || a
== 9 || a
== '\n')
716 if (a
== EOF
) return 0;
719 pos_ini
= ftell(file
) - 1;
721 while(a
!= ' ' && a
!= 9 && a
!= '\n')
726 if(a
==EOF
) return 0; /* a = ' '; */
730 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
734 tmp_str
->str
[0] = '-';
735 tmp_str
->str
[1] = '-';
743 fseek(file
,pos_ini
, SEEK_SET
);
755 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
757 tmp_str
->str
[i
- 1] = 0;
759 fseek(file
,- 1, SEEK_CUR
);
760 /* printf("%d\n", ftell(file)); */
765 int gaa_file(const char *name
, gaainfo
*gaaval
)
767 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
773 gaa_processing_file
= 1;
775 if((file
= fopen(name
, "r")) == NULL
)
777 printf("Couldn't open '%s' configuration file for reading\n", name
);
781 tmp_str
= &first_str
;
785 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
787 (*tmp_str
)->str
= NULL
;
788 (*tmp_str
)->next
= NULL
;
790 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
791 tmp_str
= &((*tmp_str
)->next
);
798 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
800 tmp_str2
= first_str
;
802 for(i
= 1; i
< argc
; i
++)
804 argv
[i
] = tmp_str2
->str
;
805 tmp_str2
= tmp_str2
->next
;
808 rval
= gaa(argc
, argv
, gaaval
);
809 gaa_processing_file
= 0;