aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/getopt.c')
-rw-r--r--src/util/getopt.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 8ec148e15..acc1b6535 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -203,6 +203,7 @@ my_index (const char *str, int chr)
203 return 0; 203 return 0;
204} 204}
205 205
206
206/* If using GCC, we can safely declare strlen this way. 207/* If using GCC, we can safely declare strlen this way.
207 If not using GCC, it is ok not to declare it. */ 208 If not using GCC, it is ok not to declare it. */
208#ifdef __GNUC__ 209#ifdef __GNUC__
@@ -213,6 +214,7 @@ my_index (const char *str, int chr)
213 and has done so at least since version 2.4.5. -- rms. */ 214 and has done so at least since version 2.4.5. -- rms. */
214extern int 215extern int
215strlen (const char *); 216strlen (const char *);
217
216#endif /* not __STDC__ */ 218#endif /* not __STDC__ */
217#endif /* __GNUC__ */ 219#endif /* __GNUC__ */
218 220
@@ -241,6 +243,7 @@ static int last_nonopt;
241#if defined(__STDC__) && __STDC__ 243#if defined(__STDC__) && __STDC__
242static void 244static void
243exchange (char **); 245exchange (char **);
246
244#endif 247#endif
245 248
246static void 249static void
@@ -300,11 +303,13 @@ exchange (char **argv)
300 last_nonopt = GNoptind; 303 last_nonopt = GNoptind;
301} 304}
302 305
306
303/* Initialize the internal data when the first call is made. */ 307/* Initialize the internal data when the first call is made. */
304 308
305#if defined(__STDC__) && __STDC__ 309#if defined(__STDC__) && __STDC__
306static const char * 310static const char *
307_getopt_initialize (int, char *const *, const char *); 311_getopt_initialize (int, char *const *, const char *);
312
308#endif 313#endif
309static const char * 314static const char *
310_getopt_initialize (int argc, char *const *argv, const char *optstring) 315_getopt_initialize (int argc, char *const *argv, const char *optstring)
@@ -339,6 +344,7 @@ _getopt_initialize (int argc, char *const *argv, const char *optstring)
339 return optstring; 344 return optstring;
340} 345}
341 346
347
342/* Scan elements of ARGV (whose length is ARGC) for option characters 348/* Scan elements of ARGV (whose length is ARGC) for option characters
343 given in OPTSTRING. 349 given in OPTSTRING.
344 350
@@ -408,7 +414,7 @@ GN_getopt_internal (int argc,
408 414
409 GNoptarg = NULL; 415 GNoptarg = NULL;
410 416
411 if ((GNoptind == 0)|| ! __getopt_initialized) 417 if ((GNoptind == 0) || ! __getopt_initialized)
412 { 418 {
413 if (GNoptind == 0) 419 if (GNoptind == 0)
414 GNoptind = 1; /* Don't scan ARGV[0], the program name. */ 420 GNoptind = 1; /* Don't scan ARGV[0], the program name. */
@@ -422,7 +428,7 @@ GN_getopt_internal (int argc,
422 * is only used when the used in the GNU libc. */ 428 * is only used when the used in the GNU libc. */
423#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0') 429#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0')
424 430
425 if ((nextchar == NULL)||(*nextchar == '\0')) 431 if ((nextchar == NULL) || (*nextchar == '\0'))
426 { 432 {
427 /* Advance to the next ARGV-element. */ 433 /* Advance to the next ARGV-element. */
428 434
@@ -438,7 +444,7 @@ GN_getopt_internal (int argc,
438 /* If we have just processed some options following some non-options, 444 /* If we have just processed some options following some non-options,
439 * exchange them so that the options come first. */ 445 * exchange them so that the options come first. */
440 446
441 if ((first_nonopt != last_nonopt) &&(last_nonopt != GNoptind) ) 447 if ((first_nonopt != last_nonopt) && (last_nonopt != GNoptind) )
442 exchange ((char **) argv); 448 exchange ((char **) argv);
443 else if (last_nonopt != GNoptind) 449 else if (last_nonopt != GNoptind)
444 first_nonopt = GNoptind; 450 first_nonopt = GNoptind;
@@ -459,7 +465,7 @@ GN_getopt_internal (int argc,
459 { 465 {
460 GNoptind++; 466 GNoptind++;
461 467
462 if ((first_nonopt != last_nonopt) &&(last_nonopt != GNoptind) ) 468 if ((first_nonopt != last_nonopt) && (last_nonopt != GNoptind) )
463 exchange ((char **) argv); 469 exchange ((char **) argv);
464 else if (first_nonopt == last_nonopt) 470 else if (first_nonopt == last_nonopt)
465 first_nonopt = GNoptind; 471 first_nonopt = GNoptind;
@@ -511,10 +517,8 @@ GN_getopt_internal (int argc,
511 * the ARGV-element is "-fu", do consider that an abbreviation of 517 * the ARGV-element is "-fu", do consider that an abbreviation of
512 * the long option, just like "--fu", and not "-f" with arg "u". 518 * the long option, just like "--fu", and not "-f" with arg "u".
513 * 519 *
514 * This distinction seems to be the most useful approach. */ 520 * This distinction seems to be the most useful approach. */if ((longopts != NULL) &&
515 521 ((argv[GNoptind][1] == '-') ||
516 if ((longopts != NULL)&&
517 ((argv[GNoptind][1] == '-')||
518 (long_only && 522 (long_only &&
519 (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1]))))) 523 (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1])))))
520 { 524 {
@@ -632,7 +636,7 @@ GN_getopt_internal (int argc,
632 * or the option starts with '--' or is not a valid short 636 * or the option starts with '--' or is not a valid short
633 * option, then it's an error. 637 * option, then it's an error.
634 * Otherwise interpret it as a short option. */ 638 * Otherwise interpret it as a short option. */
635 if (! long_only ||(argv[GNoptind][1] == '-') || 639 if (! long_only || (argv[GNoptind][1] == '-') ||
636 (my_index (optstring, *nextchar) == NULL) ) 640 (my_index (optstring, *nextchar) == NULL) )
637 { 641 {
638 if (GNopterr) 642 if (GNopterr)
@@ -667,7 +671,7 @@ GN_getopt_internal (int argc,
667 if (*nextchar == '\0') 671 if (*nextchar == '\0')
668 ++GNoptind; 672 ++GNoptind;
669 673
670 if ((temp == NULL)||(c == ':')) 674 if ((temp == NULL) || (c == ':'))
671 { 675 {
672 if (GNopterr) 676 if (GNopterr)
673 { 677 {
@@ -680,7 +684,7 @@ GN_getopt_internal (int argc,
680 return '?'; 684 return '?';
681 } 685 }
682 /* Convenience. Treat POSIX -W foo same as long option --foo */ 686 /* Convenience. Treat POSIX -W foo same as long option --foo */
683 if ((temp[0] == 'W')&&(temp[1] == ';')) 687 if ((temp[0] == 'W') && (temp[1] == ';'))
684 { 688 {
685 char *nameend; 689 char *nameend;
686 const struct GNoption *p; 690 const struct GNoption *p;
@@ -871,6 +875,7 @@ GNgetopt_long (int argc,
871 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0); 875 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
872} 876}
873 877
878
874/* ******************** now the GNUnet specific modifications... ********************* */ 879/* ******************** now the GNUnet specific modifications... ********************* */
875 880
876/** 881/**
@@ -1008,4 +1013,5 @@ GNUNET_GETOPT_run (const char *binaryOptions,
1008 return GNoptind; 1013 return GNoptind;
1009} 1014}
1010 1015
1016
1011/* end of getopt.c */ 1017/* end of getopt.c */