5 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
10 void __gaa_helpsingle(char short_name
, char *name
,
11 char *arg_desc
, char *opt_help
)
13 int col1
, col3
, col4
, tabsize
= 3, curr
;
16 col1
= 5; /* Default values */
21 for(i
= 0; i
< col1
; i
++)
30 printf("-%c, ", short_name
);
35 printf("-%c ", short_name
);
41 printf("--%s ", name
);
42 curr
+= 3 + strlen(name
);
44 if(arg_desc
&& *arg_desc
)
46 printf("%s ", arg_desc
);
47 curr
+= 1 + strlen(arg_desc
);
54 if(opt_help
) /* let's print the option's help body */
56 const char *str
= opt_help
;
76 while((curr
- col3
) % tabsize
!= 0 && curr
< col4
);
83 for(i
= 1; str
[i
] && str
[i
] != ' ' && str
[i
] != '\n'
84 && str
[i
] != '\t'; i
++);
85 if(curr
+ i
- 1 >= col4
)
105 printf("Crypt help\nUsage : prime [options]""\n");
106 __gaa_helpsingle(0, "bits", """BITS"" ", "specify the number of bits for prime numbers (used only when create_conf option is specified).");
107 __gaa_helpsingle('h', "help", "", "shows this help text");
115 #ifndef GAA_HEADER_POKY
116 #define GAA_HEADER_POKY
118 typedef struct _gaainfo gaainfo
;
133 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
137 int gaa_file(char *name
, gaainfo
*gaaval
);
156 char *gaa_current_option
;
159 /* Generated by gaa */
167 #define GAA_ERROR_NOMATCH 0
168 #define GAA_ERROR_NOTENOUGH_ARGS 1
169 #define GAA_ERROR_INVALID_ARG 2
170 #define GAA_ERROR_UNKNOWN 3
172 #define GAA_NOT_AN_OPTION 0
173 #define GAA_WORD_OPTION 1
174 #define GAA_LETTER_OPTION 2
175 #define GAA_MULTIPLE_OPTION 3
178 #define GAA_NB_OPTION 2
179 #define GAAOPTID_help 1
180 #define GAAOPTID_bits 2
184 #define GAA_CHECK1STR(a,b) \
187 gaa_current_option = a; \
191 #define GAA_CHECKSTR(a,b) \
192 if(strcmp(a,str) == 0) \
194 gaa_current_option = a; \
198 #define GAA_TESTMOREARGS \
201 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
203 if(gaa_last_non_option == gaa_index) \
204 return GAA_ERROR_NOTENOUGH_ARGS; \
207 #define GAA_TESTMOREOPTIONALARGS \
210 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
212 if(gaa_last_non_option == gaa_index) \
216 #define GAA_FILL_2ARGS(target, func) \
217 target = func(GAAargv[gaa_index]); \
218 gaa_arg_used[gaa_index] = 1; \
222 return GAA_ERROR_INVALID_ARG; \
227 #define GAA_FILL(target, func, num) \
230 target = func(GAAargv[gaa_index]); \
231 gaa_arg_used[gaa_index] = 1; \
235 return GAA_ERROR_INVALID_ARG; \
244 #define GAA_LIST_FILL(target, func, type ,num) \
248 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type)); \
249 for(; gaa_index < gaa_last_non_option; gaa_index++) \
251 if(gaa_arg_used[gaa_index] == 0) \
253 GAA_FILL_2ARGS(target[num], func); \
258 return GAA_ERROR_NOTENOUGH_ARGS; \
261 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
265 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type)); \
266 for(; gaa_index < gaa_last_non_option; gaa_index++) \
268 if(gaa_arg_used[gaa_index] == 0) \
270 GAA_FILL_2ARGS(target[num], func); \
276 #define GAA_OBLIGAT(str) \
278 for(i = 0; i < strlen(str); i++) \
280 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
281 if(j == GAA_ERROR_NOMATCH) \
283 printf("Error : invalid 'obligat' set\n"); \
286 if(opt_list[j] == 1) \
291 if(strlen(str) == 1) \
292 printf("You must give the -%s option\n", str); \
294 printf("You must give at least one option of '%s'\n", str); \
298 #define GAA_INCOMP(str) \
300 for(i = 0; i < strlen(str); i++) \
302 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
303 if(j == GAA_ERROR_NOMATCH) \
305 printf("Error : invalid 'obligat' set\n"); \
308 if(opt_list[j] == 1) \
313 printf("The options '%s' are incompatible\n", str); \
321 int gaa_processing_file
= 0;
324 int gaa_getint(char *arg
)
328 if(sscanf(arg
, "%d%c", &tmp
, &a
) != 1)
330 printf("Option %s : '%s' isn't an integer\n", gaa_current_option
, arg
);
336 char gaa_getchar(char *arg
)
340 printf("Option %s : '%s' isn't an character\n", gaa_current_option
, arg
);
346 char* gaa_getstr(char *arg
)
350 float gaa_getfloat(char *arg
)
354 if(sscanf(arg
, "%f%c", &tmp
, &a
) != 1)
356 printf("Option %s : '%s' isn't a float number\n", gaa_current_option
, arg
);
361 /* option structures */
363 struct GAAOPTION_bits
370 int gaa_is_an_argument(char *str
)
373 if(str
[0] == '/' && str
[1] != 0)
374 return GAA_MULTIPLE_OPTION
;
377 return GAA_NOT_AN_OPTION
;
379 return GAA_NOT_AN_OPTION
;
383 return GAA_WORD_OPTION
;
385 return GAA_NOT_AN_OPTION
;
388 return GAA_LETTER_OPTION
;
390 return GAA_MULTIPLE_OPTION
;
393 int gaa_get_option_num(char *str
, int status
)
397 case GAA_LETTER_OPTION
:
398 GAA_CHECK1STR("", GAAOPTID_bits
);
399 case GAA_MULTIPLE_OPTION
:
401 GAA_CHECK1STR("h", GAAOPTID_help
);
405 case GAA_WORD_OPTION
:
406 GAA_CHECKSTR("help", GAAOPTID_help
);
407 GAA_CHECKSTR("bits", GAAOPTID_bits
);
413 return GAA_ERROR_NOMATCH
;
416 int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
419 int gaa_last_non_option
;
420 struct GAAOPTION_bits GAATMP_bits
;
423 #ifdef GAA_REST_EXISTS
424 struct GAAREST GAAREST_tmp
;
427 opt_list
[gaa_num
] = 1;
429 for(gaa_last_non_option
= gaa_index
;
430 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
431 gaa_last_non_option
++);
433 if(gaa_num
== GAA_REST
)
436 gaa_last_non_option
= GAAargc
;
444 { gaa_help(); exit(0); ;};
451 GAA_FILL(GAATMP_bits
.arg1
, gaa_getint
, GAATMP_bits
.size1
);
454 { gaaval
->bits
= GAATMP_bits
.arg1
;};
462 return GAA_ERROR_UNKNOWN
;
465 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
474 opt_list
= (char*) malloc(GAA_NB_OPTION
+ 1);
475 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
482 { gaaval
->bits
=1040; ;};
487 gaa_arg_used
= malloc(argc
* sizeof(char));
488 for(i
= 1; i
< argc
; i
++)
490 for(i
= 1; i
< argc
; i
++)
492 if(gaa_arg_used
[i
] == 0)
495 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
498 case GAA_WORD_OPTION
:
500 case GAA_LETTER_OPTION
:
502 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
503 if(tmp2
== GAA_ERROR_NOMATCH
)
505 printf("Invalid option '%s'\n", argv
[i
]+j
);
508 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
510 case GAA_ERROR_NOTENOUGH_ARGS
:
511 printf("'%s' : not enough arguments\n",gaa_current_option
);
513 case GAA_ERROR_INVALID_ARG
:
514 printf("Invalid arguments\n");
519 printf("Unknown error\n");
523 case GAA_MULTIPLE_OPTION
:
524 for(j
= 1; j
< strlen(argv
[i
]); j
++)
526 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
527 if(tmp2
== GAA_ERROR_NOMATCH
)
529 printf("Invalid option '%c'\n", *(argv
[i
]+j
));
532 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
534 case GAA_ERROR_NOTENOUGH_ARGS
:
535 printf("'%s' : not enough arguments\n",gaa_current_option
);
537 case GAA_ERROR_INVALID_ARG
:
538 printf("Invalid arguments\n");
543 printf("Unknown error\n");
552 if(gaa_processing_file
== 0)
556 #ifdef GAA_REST_EXISTS
557 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
559 case GAA_ERROR_NOTENOUGH_ARGS
:
560 printf("Rest : not enough arguments\n");
562 case GAA_ERROR_INVALID_ARG
:
563 printf("Invalid arguments\n");
568 printf("Unknown error\n");
572 for(i
= 1; i
< argc
; i
++)
574 if(gaa_arg_used
[i
] == 0)
576 printf("Too many arguments\n");
588 struct gaastrnode
*next
;
591 typedef struct gaastrnode gaa_str_node
;
593 int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
597 int i
= 0, len
= 0, newline
= 0;
602 if(fscanf(file
,"%c", &a
) != 1) return 0;
604 while(a
== ' ' || a
== 9 || a
== '\n')
611 if(fscanf(file
,"%c", &a
) != 1) return 0;
614 pos_ini
= ftell(file
) - 1;
616 while(a
!= ' ' && a
!= 9 && a
!= '\n')
620 if(fscanf(file
,"%c", &a
) != 1) a
= ' ';
623 tmp_str
->str
= malloc((len
+ 1) * sizeof(char));
626 tmp_str
->str
[0] = '-';
627 tmp_str
->str
[1] = '-';
635 fseek(file
,pos_ini
, SEEK_SET
);
638 if(fscanf(file
, "%c", &a
) != 1)
646 while(a
!= ' ' && a
!= 9 && a
!= '\n');
648 tmp_str
->str
[i
- 1] = 0;
650 fseek(file
,- 1, SEEK_CUR
);
655 int gaa_file(char *name
, gaainfo
*gaaval
)
657 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
663 gaa_processing_file
= 1;
665 if((file
= fopen(name
, "r")) == NULL
)
667 printf("Couldn't open '%s' configuration file for reading\n", name
);
671 tmp_str
= &first_str
;
675 *tmp_str
= malloc(sizeof(gaa_str_node
));
676 (*tmp_str
)->str
= NULL
;
677 (*tmp_str
)->next
= NULL
;
679 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
680 tmp_str
= &((*tmp_str
)->next
);
687 argv
= malloc((1 + argc
) * sizeof(char*));
688 tmp_str2
= first_str
;
690 for(i
= 1; i
< argc
; i
++)
692 argv
[i
] = tmp_str2
->str
;
693 tmp_str2
= tmp_str2
->next
;
696 rval
= gaa(argc
, argv
, gaaval
);
697 gaa_processing_file
= 0;