1 /* File generated by GAA 1.6.6
14 void psktool_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("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('s', "keysize", "SIZE ", "specify the key size in bytes.");
135 __gaa_helpsingle('v', "version", "", "prints the program's version number");
136 __gaa_helpsingle('h', "help", "", "shows this help text");
144 #ifndef GAA_HEADER_POKY
145 #define GAA_HEADER_POKY
147 typedef struct _gaainfo gaainfo
;
166 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
170 int gaa_file(const char *name
, gaainfo
*gaaval
);
183 #define GAAERROR(x) \
189 static char *gaa_current_option
;
190 static int gaa_error
= 0;
192 /* Generated by gaa */
200 #define GAA_ERROR_NOMATCH 0
201 #define GAA_ERROR_NOTENOUGH_ARGS 1
202 #define GAA_ERROR_INVALID_ARG 2
203 #define GAA_ERROR_UNKNOWN 3
205 #define GAA_NOT_AN_OPTION 0
206 #define GAA_WORD_OPTION 1
207 #define GAA_LETTER_OPTION 2
208 #define GAA_MULTIPLE_OPTION 3
211 #define GAA_NB_OPTION 5
212 #define GAAOPTID_help 1
213 #define GAAOPTID_version 2
214 #define GAAOPTID_keysize 3
215 #define GAAOPTID_passwd 4
216 #define GAAOPTID_username 5
220 #define GAA_CHECK1STR(a,b) \
223 gaa_current_option = a; \
227 #define GAA_CHECKSTR(a,b) \
228 if(strcmp(a,str) == 0) \
230 gaa_current_option = a; \
234 #define GAA_TESTMOREARGS \
237 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
239 if(gaa_last_non_option == gaa_index) \
240 return GAA_ERROR_NOTENOUGH_ARGS; \
243 #define GAA_TESTMOREOPTIONALARGS \
246 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
248 if(gaa_last_non_option == gaa_index) \
252 #define GAA_FILL_2ARGS(target, func) \
253 target = func(GAAargv[gaa_index]); \
254 gaa_arg_used[gaa_index] = 1; \
258 return GAA_ERROR_INVALID_ARG; \
263 #define GAA_FILL(target, func, num) \
266 target = func(GAAargv[gaa_index]); \
267 gaa_arg_used[gaa_index] = 1; \
271 return GAA_ERROR_INVALID_ARG; \
280 #define GAA_LIST_FILL(target, func, type ,num) \
285 if ( gaa_last_non_option - gaa_index > 0) \
286 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
287 for(; gaa_index < gaa_last_non_option; gaa_index++) \
289 if(gaa_arg_used[gaa_index] == 0) \
291 GAA_FILL_2ARGS(target[num], func); \
296 return GAA_ERROR_NOTENOUGH_ARGS; \
299 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
304 if ( gaa_last_non_option - gaa_index > 0) \
305 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
306 for(; gaa_index < gaa_last_non_option; gaa_index++) \
308 if(gaa_arg_used[gaa_index] == 0) \
310 GAA_FILL_2ARGS(target[num], func); \
316 #define GAA_OBLIGAT(str) \
318 for(i = 0; i < strlen(str); i++) \
320 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
321 if(j == GAA_ERROR_NOMATCH) \
323 printf("Error: invalid 'obligat' set\n"); \
326 if(opt_list[j] == 1) \
331 if(strlen(str) == 1) \
332 printf("You must give the -%s option\n", str); \
334 printf("You must give at least one option of '%s'\n", str); \
338 #define GAA_INCOMP(str) \
340 for(i = 0; i < strlen(str); i++) \
342 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
343 if(j == GAA_ERROR_NOMATCH) \
345 printf("Error: invalid 'obligat' set\n"); \
348 if(opt_list[j] == 1) \
353 printf("The options '%s' are incompatible\n", str); \
358 static char **GAAargv
;
360 static char *gaa_arg_used
;
361 static int gaa_processing_file
= 0;
362 static int inited
= 0;
364 static int gaa_getint(char *arg
)
368 if(sscanf(arg
, "%d%c", &tmp
, &a
) < 1)
370 printf("Option %s: '%s' isn't an integer\n", gaa_current_option
, arg
);
376 static char gaa_getchar(char *arg
)
380 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
386 static char* gaa_getstr(char *arg
)
390 static float gaa_getfloat(char *arg
)
394 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
396 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
401 /* option structures */
403 struct GAAOPTION_keysize
409 struct GAAOPTION_passwd
415 struct GAAOPTION_username
422 static int gaa_is_an_argument(char *str
)
425 if(str
[0] == '/' && str
[1] != 0)
426 return GAA_MULTIPLE_OPTION
;
429 return GAA_NOT_AN_OPTION
;
431 return GAA_NOT_AN_OPTION
;
435 return GAA_WORD_OPTION
;
437 return GAA_NOT_AN_OPTION
;
440 return GAA_LETTER_OPTION
;
442 return GAA_MULTIPLE_OPTION
;
445 static int gaa_get_option_num(char *str
, int status
)
449 case GAA_LETTER_OPTION
:
450 GAA_CHECK1STR("s", GAAOPTID_keysize
);
451 GAA_CHECK1STR("p", GAAOPTID_passwd
);
452 GAA_CHECK1STR("u", GAAOPTID_username
);
453 case GAA_MULTIPLE_OPTION
:
455 GAA_CHECK1STR("h", GAAOPTID_help
);
456 GAA_CHECK1STR("v", GAAOPTID_version
);
460 case GAA_WORD_OPTION
:
461 GAA_CHECKSTR("help", GAAOPTID_help
);
462 GAA_CHECKSTR("version", GAAOPTID_version
);
463 GAA_CHECKSTR("keysize", GAAOPTID_keysize
);
464 GAA_CHECKSTR("passwd", GAAOPTID_passwd
);
465 GAA_CHECKSTR("username", GAAOPTID_username
);
471 return GAA_ERROR_NOMATCH
;
474 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
477 int gaa_last_non_option
;
478 struct GAAOPTION_keysize GAATMP_keysize
;
479 struct GAAOPTION_passwd GAATMP_passwd
;
480 struct GAAOPTION_username GAATMP_username
;
483 #ifdef GAA_REST_EXISTS
484 struct GAAREST GAAREST_tmp
;
487 opt_list
[gaa_num
] = 1;
489 for(gaa_last_non_option
= gaa_index
;
490 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
491 gaa_last_non_option
++);
493 if(gaa_num
== GAA_REST
)
496 gaa_last_non_option
= GAAargc
;
504 { gaa_help(); exit(0); ;};
508 case GAAOPTID_version
:
511 { psktool_version(); exit(0); ;};
515 case GAAOPTID_keysize
:
518 GAA_FILL(GAATMP_keysize
.arg1
, gaa_getint
, GAATMP_keysize
.size1
);
521 { gaaval
->key_size
= GAATMP_keysize
.arg1
;};
525 case GAAOPTID_passwd
:
528 GAA_FILL(GAATMP_passwd
.arg1
, gaa_getstr
, GAATMP_passwd
.size1
);
531 { gaaval
->passwd
= GAATMP_passwd
.arg1
;};
535 case GAAOPTID_username
:
538 GAA_FILL(GAATMP_username
.arg1
, gaa_getstr
, GAATMP_username
.size1
);
541 { gaaval
->username
= GAATMP_username
.arg1
;};
549 return GAA_ERROR_UNKNOWN
;
552 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
561 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
563 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
570 { gaaval
->username
=NULL
; gaaval
->passwd
=NULL
; gaaval
->key_size
= NULL
; ;};
578 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
581 for(i
= 1; i
< argc
; i
++)
583 for(i
= 1; i
< argc
; i
++)
585 if(gaa_arg_used
[i
] == 0)
588 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
591 case GAA_WORD_OPTION
:
593 case GAA_LETTER_OPTION
:
595 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
596 if(tmp2
== GAA_ERROR_NOMATCH
)
598 printf("Invalid option '%s'\n", argv
[i
]+j
);
601 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
603 case GAA_ERROR_NOTENOUGH_ARGS
:
604 printf("'%s': not enough arguments\n",gaa_current_option
);
606 case GAA_ERROR_INVALID_ARG
:
607 printf("Invalid arguments\n");
612 printf("Unknown error\n");
616 case GAA_MULTIPLE_OPTION
:
617 for(j
= 1; j
< strlen(argv
[i
]); j
++)
619 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
620 if(tmp2
== GAA_ERROR_NOMATCH
)
622 printf("Invalid option '%c'\n", *(argv
[i
]+j
));
625 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
627 case GAA_ERROR_NOTENOUGH_ARGS
:
628 printf("'%s': not enough arguments\n",gaa_current_option
);
630 case GAA_ERROR_INVALID_ARG
:
631 printf("Invalid arguments\n");
636 printf("Unknown error\n");
645 if(gaa_processing_file
== 0)
649 #ifdef GAA_REST_EXISTS
650 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
652 case GAA_ERROR_NOTENOUGH_ARGS
:
653 printf("Rest: not enough arguments\n");
655 case GAA_ERROR_INVALID_ARG
:
656 printf("Invalid arguments\n");
661 printf("Unknown error\n");
665 for(i
= 1; i
< argc
; i
++)
667 if(gaa_arg_used
[i
] == 0)
669 printf("Too many arguments\n");
681 struct gaastrnode
*next
;
684 typedef struct gaastrnode gaa_str_node
;
686 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
690 int i
= 0, len
= 0, newline
= 0;
698 if (a
== EOF
) return 0;
700 while(a
== ' ' || a
== 9 || a
== '\n')
708 if (a
== EOF
) return 0;
711 pos_ini
= ftell(file
) - 1;
713 while(a
!= ' ' && a
!= 9 && a
!= '\n')
718 if(a
==EOF
) return 0; /* a = ' '; */
722 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
726 tmp_str
->str
[0] = '-';
727 tmp_str
->str
[1] = '-';
735 fseek(file
,pos_ini
, SEEK_SET
);
747 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
749 tmp_str
->str
[i
- 1] = 0;
751 fseek(file
,- 1, SEEK_CUR
);
752 /* printf("%d\n", ftell(file)); */
757 int gaa_file(const char *name
, gaainfo
*gaaval
)
759 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
765 gaa_processing_file
= 1;
767 if((file
= fopen(name
, "r")) == NULL
)
769 printf("Couldn't open '%s' configuration file for reading\n", name
);
773 tmp_str
= &first_str
;
777 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
779 (*tmp_str
)->str
= NULL
;
780 (*tmp_str
)->next
= NULL
;
782 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
783 tmp_str
= &((*tmp_str
)->next
);
790 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
792 tmp_str2
= first_str
;
794 for(i
= 1; i
< argc
; i
++)
796 argv
[i
] = tmp_str2
->str
;
797 tmp_str2
= tmp_str2
->next
;
800 rval
= gaa(argc
, argv
, gaaval
);
801 gaa_processing_file
= 0;