GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
getopt.c File Reference

GNU style option parsing. More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for getopt.c:

Go to the source code of this file.

Data Structures

struct  GNoption
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
 
#define LOG_STRERROR(kind, syscall)    GNUNET_log_from_strerror (kind, "util-getopt", syscall)
 
#define _(msgid)   (msgid)
 
#define SWAP_FLAGS(ch1, ch2)
 
#define NONOPTION_P   (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0')
 

Enumerations

enum  { REQUIRE_ORDER , PERMUTE , RETURN_IN_ORDER }
 

Functions

char * getenv ()
 
static char * my_index (const char *str, int chr)
 
static void exchange (char **argv)
 
static const char * _getopt_initialize (int argc, char *const *argv, const char *optstring)
 
static int GN_getopt_internal (int argc, char *const *argv, const char *optstring, const struct GNoption *longopts, int *longind, int long_only)
 
static int GNgetopt_long (int argc, char *const *argv, const char *options, const struct GNoption *long_options, int *opt_index)
 
int GNUNET_GETOPT_run (const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
 Parse the command line.
 

Variables

static char * GNoptarg = NULL
 
static int GNoptind = 1
 
static char * nextchar
 
static enum { ... }  ordering
 
static char * posixly_correct
 
static int first_nonopt
 
static int last_nonopt
 

Detailed Description

GNU style option parsing.

TODO: get rid of statistics (make reentrant) and replace main GNU getopt parser with one that actually fits our API.

Definition in file getopt.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)

Definition at line 51 of file getopt.c.

◆ LOG_STRERROR

#define LOG_STRERROR (   kind,
  syscall 
)     GNUNET_log_from_strerror (kind, "util-getopt", syscall)

Definition at line 53 of file getopt.c.

88{
89 const char *name;
90 /* has_arg can't be an enum because some compilers complain about
91 * type mismatches in all the code that assumes it is an int. */
92 int has_arg;
93 int *flag;
94 int val;
95};
96
97
98/* This version of `getopt' appears to the caller like standard Unix `getopt'
99 but it behaves differently for the user, since it allows the user
100 to intersperse the options with the other arguments.
101
102 As `getopt' works, it permutes the elements of ARGV so that,
103 when it is done, all the options precede everything else. Thus
104 all application programs are extended to handle flexible argument order.
105
106 Setting the environment variable POSIXLY_CORRECT disables permutation.
107 Then the behavior is completely standard.
108
109 GNU application programs can use a third alternative mode in which
110 they can distinguish the relative order of options and other arguments. */
111
112/* For communication from `getopt' to the caller.
113 When `getopt' finds an option that takes an argument,
114 the argument value is returned here.
115 Also, when `ordering' is RETURN_IN_ORDER,
116 each non-option ARGV-element is returned here. */
117
118static char *GNoptarg = NULL;
119
120/* Index in ARGV of the next element to be scanned.
121 This is used for communication to and from the caller
122 and for communication between successive calls to `getopt'.
123
124 On entry to `getopt', zero means this is the first call; initialize.
125
126 When `getopt' returns -1, this is the index of the first of the
127 non-option elements that the caller should itself scan.
128
129 Otherwise, `GNoptind' communicates from one call to the next
130 how much of ARGV has been scanned so far. */
131
132/* 1003.2 says this must be 1 before any call. */
133static int GNoptind = 1;
134
135/* The next char to be scanned in the option-element
136 in which the last option character we returned was found.
137 This allows us to pick up the scan where we left off.
138
139 If this is zero, or a null string, it means resume the scan
140 by advancing to the next ARGV-element. */
141
142static char *nextchar;
143
144
145/* Describe how to deal with options that follow non-option ARGV-elements.
146
147 If the caller did not specify anything,
148 the default is REQUIRE_ORDER if the environment variable
149 POSIXLY_CORRECT is defined, PERMUTE otherwise.
150
151 REQUIRE_ORDER means don't recognize them as options;
152 stop option processing when the first non-option is seen.
153 This is what Unix does.
154 This mode of operation is selected by either setting the environment
155 variable POSIXLY_CORRECT, or using `+' as the first character
156 of the list of option characters.
157
158 PERMUTE is the default. We GNUNET_CRYPTO_random_permute the contents of ARGV as we scan,
159 so that eventually all the non-options are at the end. This allows options
160 to be given in any order, even with programs that were not written to
161 expect this.
162
163 RETURN_IN_ORDER is an option available to programs that were written
164 to expect GNoptions and other ARGV-elements in any order and that care about
165 the ordering of the two. We describe each non-option ARGV-element
166 as if it were the argument of an option with character code 1.
167 Using `-' as the first character of the list of option characters
168 selects this mode of operation.
169
170 The special argument `--' forces an end of option-scanning regardless
171 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
172 `--' can cause `getopt' to return -1 with `GNoptind' != ARGC. */
173
175
176/* Value of POSIXLY_CORRECT environment variable. */
177static char *posixly_correct;
178
179#if defined(__GNU_LIBRARY__) || defined(__GLIBC__) || defined(DARWIN)
180/* We want to avoid inclusion of string.h with non-GNU libraries
181 because there are many ways it can cause trouble.
182 On some systems, it contains special magic macros that don't work
183 in GCC. */
184#include <string.h>
185#define my_index strchr
186#else
187
188/* Avoid depending on library functions or files
189 whose names are inconsistent. */
190
191char *
192getenv ();
193
194static char *
195my_index (const char *str, int chr)
196{
197 while (*str)
198 {
199 if (*str == chr)
200 return (char *) str;
201 str++;
202 }
203 return 0;
204}
205
206
207/* If using GCC, we can safely declare strlen this way.
208 If not using GCC, it is ok not to declare it. */
209#ifdef __GNUC__
210/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
211 That was relevant to code that was here before. */
212#if ! defined(__STDC__) || ! __STDC__
213/* gcc with -traditional declares the built-in strlen to return int,
214 and has done so at least since version 2.4.5. -- rms. */
215extern int
216strlen (const char *);
217
218#endif /* not __STDC__ */
219#endif /* __GNUC__ */
220
221#endif /* not __GNU_LIBRARY__ */
222
223/* Handle permutation of arguments. */
224
225/* Describe the part of ARGV that contains non-options that have
226 been skipped. `first_nonopt' is the index in ARGV of the first of them;
227 `last_nonopt' is the index after the last of them. */
228
229static int first_nonopt;
230static int last_nonopt;
231
232#define SWAP_FLAGS(ch1, ch2)
233
234/* Exchange two adjacent subsequences of ARGV.
235 One subsequence is elements [first_nonopt,last_nonopt)
236 which contains all the non-options that have been skipped so far.
237 The other is elements [last_nonopt,GNoptind), which contains all
238 the options processed since those non-options were skipped.
239
240 `first_nonopt' and `last_nonopt' are relocated so that they describe
241 the new indices of the non-options in ARGV after they are moved. */
242
243#if defined(__STDC__) && __STDC__
244static void
245exchange (char **);
246
247#endif
248
249static void
250exchange (char **argv)
251{
252 int bottom = first_nonopt;
253 int middle = last_nonopt;
254 int top = GNoptind;
255 char *tem;
256
257 /* Exchange the shorter segment with the far end of the longer segment.
258 * That puts the shorter segment into the right place.
259 * It leaves the longer segment in the right place overall,
260 * but it consists of two parts that need to be swapped next. */
261
262 while (top > middle && middle > bottom)
263 {
264 if (top - middle > middle - bottom)
265 {
266 /* Bottom segment is the short one. */
267 int len = middle - bottom;
268 register int i;
269
270 /* Swap it with the top part of the top segment. */
271 for (i = 0; i < len; i++)
272 {
273 tem = argv[bottom + i];
274 argv[bottom + i] = argv[top - (middle - bottom) + i];
275 argv[top - (middle - bottom) + i] = tem;
276 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
277 }
278 /* Exclude the moved bottom segment from further swapping. */
279 top -= len;
280 }
281 else
282 {
283 /* Top segment is the short one. */
284 int len = top - middle;
285 register int i;
286
287 /* Swap it with the bottom part of the bottom segment. */
288 for (i = 0; i < len; i++)
289 {
290 tem = argv[bottom + i];
291 argv[bottom + i] = argv[middle + i];
292 argv[middle + i] = tem;
293 SWAP_FLAGS (bottom + i, middle + i);
294 }
295 /* Exclude the moved top segment from further swapping. */
296 bottom += len;
297 }
298 }
299
300 /* Update records for the slots the non-options now occupy. */
301
304}
305
306
307/* Initialize the internal data when the first call is made. */
308
309#if defined(__STDC__) && __STDC__
310static const char *
311_getopt_initialize (int, char *const *, const char *);
312
313#endif
314static const char *
315_getopt_initialize (int argc, char *const *argv, const char *optstring)
316{
317 /* Start processing options with ARGV-element 1 (since ARGV-element 0
318 * is the program name); the sequence of previously skipped
319 * non-option ARGV-elements is empty. */
320
322
323 nextchar = NULL;
324
325 posixly_correct = getenv ("POSIXLY_CORRECT");
326
327 /* Determine how to handle the ordering of options and nonoptions. */
328
329 if (optstring[0] == '-')
330 {
332 ++optstring;
333 }
334 else if (optstring[0] == '+')
335 {
337 ++optstring;
338 }
339 else if (posixly_correct != NULL)
341 else
343
344 return optstring;
345}
346
347
348/* Scan elements of ARGV (whose length is ARGC) for option characters
349 given in OPTSTRING.
350
351 If an element of ARGV starts with '-', and is not exactly "-" or "--",
352 then it is an option element. The characters of this element
353 (aside from the initial '-') are option characters. If `getopt'
354 is called repeatedly, it returns successively each of the option characters
355 from each of the option elements.
356
357 If `getopt' finds another option character, it returns that character,
358 updating `GNoptind' and `nextchar' so that the next call to `getopt' can
359 resume the scan with the following option character or ARGV-element.
360
361 If there are no more option characters, `getopt' returns -1.
362 Then `GNoptind' is the index in ARGV of the first ARGV-element
363 that is not an option. (The ARGV-elements have been permuted
364 so that those that are not options now come last.)
365
366 OPTSTRING is a string containing the legitimate option characters.
367 If an option character is seen that is not listed in OPTSTRING,
368 return '?' after printing an error message. If you set `GNopterr' to
369 zero, the error message is suppressed but we still return '?'.
370
371 If a char in OPTSTRING is followed by a colon, that means it wants an arg,
372 so the following text in the same ARGV-element, or the text of the following
373 ARGV-element, is returned in `GNoptarg'. Two colons mean an option that
374 wants an optional arg; if there is text in the current ARGV-element,
375 it is returned in `GNoptarg', otherwise `GNoptarg' is set to zero.
376
377 If OPTSTRING starts with `-' or `+', it requests different methods of
378 handling the non-option ARGV-elements.
379 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
380
381 Long-named options begin with `--' instead of `-'.
382 Their names may be abbreviated as long as the abbreviation is unique
383 or is an exact match for some defined option. If they have an
384 argument, it follows the option name in the same ARGV-element, separated
385 from the option name by a `=', or else the in next ARGV-element.
386 When `getopt' finds a long-named option, it returns 0 if that option's
387 `flag' field is nonzero, the value of the option's `val' field
388 if the `flag' field is zero.
389
390 The elements of ARGV aren't really const, because we GNUNET_CRYPTO_random_permute them.
391 But we pretend they're const in the prototype to be compatible
392 with other systems.
393
394 LONGOPTS is a vector of `struct GNoption' terminated by an
395 element containing a name which is zero.
396
397 LONGIND returns the index in LONGOPT of the long-named option found.
398 It is only valid when a long-named option has been found by the most
399 recent call.
400
401 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
402 long-named options. */
403
404static int
405GN_getopt_internal (int argc,
406 char *const *argv,
407 const char *optstring,
408 const struct GNoption *longopts,
409 int *longind,
410 int long_only)
411{
412 static int __getopt_initialized = 0;
413 static int GNopterr = 1;
414
415 GNoptarg = NULL;
416
417 if ((GNoptind == 0) || ! __getopt_initialized)
418 {
419 if (GNoptind == 0)
420 GNoptind = 1; /* Don't scan ARGV[0], the program name. */
421 optstring = _getopt_initialize (argc, argv, optstring);
422 __getopt_initialized = 1;
423 }
424
425 /* Test whether ARGV[GNoptind] points to a non-option argument.
426 * Either it does not have option syntax, or there is an environment flag
427 * from the shell indicating it is not an option. The later information
428 * is only used when the used in the GNU libc. */
429#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0')
430
431 if ((nextchar == NULL) || (*nextchar == '\0'))
432 {
433 /* Advance to the next ARGV-element. */
434
435 /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been
436 * moved back by the user (who may also have changed the arguments). */
437 if (last_nonopt > GNoptind)
441
442 if (ordering == PERMUTE)
443 {
444 /* If we have just processed some options following some non-options,
445 * exchange them so that the options come first. */
446
448 exchange ((char **) argv);
449 else if (last_nonopt != GNoptind)
451
452 /* Skip any additional non-options
453 * and extend the range of non-options previously skipped. */
454
455 while (GNoptind < argc && NONOPTION_P)
456 GNoptind++;
458 }
459
460 /* The special ARGV-element `--' means premature end of options.
461 * Skip it like a null option,
462 * then exchange with previous non-options as if it were an option,
463 * then skip everything else like a non-option. */
464 if ((GNoptind != argc) && ! strcmp (argv[GNoptind], "--"))
465 {
466 GNoptind++;
467
469 exchange ((char **) argv);
470 else if (first_nonopt == last_nonopt)
472 last_nonopt = argc;
473
474 GNoptind = argc;
475 }
476
477 /* If we have done all the ARGV-elements, stop the scan
478 * and back over any non-options that we skipped and permuted. */
479
480 if (GNoptind == argc)
481 {
482 /* Set the next-arg-index to point at the non-options
483 * that we previously skipped, so the caller will digest them. */
486 return -1;
487 }
488
489 /* If we have come to a non-option and did not permute it,
490 * either stop the scan or describe it to the caller and pass it by. */
491
492 if (NONOPTION_P)
493 {
494 if (ordering == REQUIRE_ORDER)
495 return -1;
496 GNoptarg = argv[GNoptind++];
497 return 1;
498 }
499
500 /* We have found another option-ARGV-element.
501 * Skip the initial punctuation. */
502
503 nextchar =
504 (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
505 }
506
507 /* Decode the current option-ARGV-element. */
508
509 /* Check whether the ARGV-element is a long option.
510 *
511 * If long_only and the ARGV-element has the form "-f", where f is
512 * a valid short option, don't consider it an abbreviated form of
513 * a long option that starts with f. Otherwise there would be no
514 * way to give the -f short option.
515 *
516 * On the other hand, if there's a long option "fubar" and
517 * the ARGV-element is "-fu", do consider that an abbreviation of
518 * the long option, just like "--fu", and not "-f" with arg "u".
519 *
520 * This distinction seems to be the most useful approach. */if ((longopts != NULL) &&
521 ((argv[GNoptind][1] == '-') ||
522 (long_only &&
523 (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1])))))
524 {
525 char *nameend;
526 const struct GNoption *p;
527 const struct GNoption *pfound = NULL;
528 int exact = 0;
529 int ambig = 0;
530 int indfound = -1;
531 int option_index;
532
533 for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
534 /* Do nothing. */;
535
536 /* Test all long options for either exact match
537 * or abbreviated matches. */
538 for (p = longopts, option_index = 0; p->name; p++, option_index++)
539 if (! strncmp (p->name, nextchar, nameend - nextchar))
540 {
541 if ((unsigned int) (nameend - nextchar) ==
542 (unsigned int) strlen (p->name))
543 {
544 /* Exact match found. */
545 pfound = p;
546 indfound = option_index;
547 exact = 1;
548 break;
549 }
550 else if (pfound == NULL)
551 {
552 /* First nonexact match found. */
553 pfound = p;
554 indfound = option_index;
555 }
556 else
557 /* Second or later nonexact match found. */
558 ambig = 1;
559 }
560
561 if (ambig && ! exact)
562 {
563 if (GNopterr)
564 fprintf (stderr,
565 _ ("%s: option `%s' is ambiguous\n"),
566 argv[0],
567 argv[GNoptind]);
568 nextchar += strlen (nextchar);
569 GNoptind++;
570 return '?';
571 }
572
573 if (pfound != NULL)
574 {
575 option_index = indfound;
576 GNoptind++;
577 if (*nameend)
578 {
579 /* Don't test has_arg with >, because some C compilers don't
580 * allow it to be used on enums. */
581 if (pfound->has_arg)
582 GNoptarg = nameend + 1;
583 else
584 {
585 if (GNopterr)
586 {
587 if (argv[GNoptind - 1][1] == '-')
588 /* --option */
589 fprintf (stderr,
590 _ ("%s: option `--%s' does not allow an argument\n"),
591 argv[0],
592 pfound->name);
593 else
594 /* +option or -option */
595 fprintf (stderr,
596 _ ("%s: option `%c%s' does not allow an argument\n"),
597 argv[0],
598 argv[GNoptind - 1][0],
599 pfound->name);
600 }
601 nextchar += strlen (nextchar);
602 return '?';
603 }
604 }
605 else if (pfound->has_arg == 1)
606 {
607 if (GNoptind < argc)
608 {
609 GNoptarg = argv[GNoptind++];
610 }
611 else
612 {
613 if (GNopterr)
614 {
615 fprintf (stderr,
616 _ ("%s: option `%s' requires an argument\n"),
617 argv[0],
618 argv[GNoptind - 1]);
619 }
620 nextchar += strlen (nextchar);
621 return (optstring[0] == ':') ? ':' : '?';
622 }
623 }
624 nextchar += strlen (nextchar);
625 if (longind != NULL)
626 *longind = option_index;
627 if (pfound->flag)
628 {
629 *(pfound->flag) = pfound->val;
630 return 0;
631 }
632 return pfound->val;
633 }
634
635 /* Can't find it as a long option. If this is not getopt_long_only,
636 * or the option starts with '--' or is not a valid short
637 * option, then it's an error.
638 * Otherwise interpret it as a short option. */
639 if (! long_only || (argv[GNoptind][1] == '-') ||
640 (my_index (optstring, *nextchar) == NULL) )
641 {
642 if (GNopterr)
643 {
644 if (argv[GNoptind][1] == '-')
645 /* --option */
646 fprintf (stderr,
647 _ ("%s: unrecognized option `--%s'\n"),
648 argv[0],
649 nextchar);
650 else
651 /* +option or -option */
652 fprintf (stderr,
653 _ ("%s: unrecognized option `%c%s'\n"),
654 argv[0],
655 argv[GNoptind][0],
656 nextchar);
657 }
658 nextchar = (char *) "";
659 GNoptind++;
660 return '?';
661 }
662 }
663
664 /* Look at and handle the next short option-character. */
665
666 {
667 char c = *nextchar++;
668 char *temp = my_index (optstring, c);
669
670 /* Increment `GNoptind' when we start to process its last character. */
671 if (*nextchar == '\0')
672 ++GNoptind;
673
674 if ((temp == NULL) || (c == ':'))
675 {
676 if (GNopterr)
677 {
678 if (posixly_correct)
679 /* 1003.2 specifies the format of this message. */
680 fprintf (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
681 else
682 fprintf (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
683 }
684 return '?';
685 }
686 /* Convenience. Treat POSIX -W foo same as long option --foo */
687 if ((temp[0] == 'W') && (temp[1] == ';'))
688 {
689 char *nameend;
690 const struct GNoption *p;
691 const struct GNoption *pfound = NULL;
692 int exact = 0;
693 int ambig = 0;
694 int indfound = 0;
695 int option_index;
696
697 /* This is an option that requires an argument. */
698 if (*nextchar != '\0')
699 {
701 /* If we end this ARGV-element by taking the rest as an arg,
702 * we must advance to the next element now. */
703 GNoptind++;
704 }
705 else if (GNoptind == argc)
706 {
707 if (GNopterr)
708 {
709 /* 1003.2 specifies the format of this message. */
710 fprintf (stderr,
711 _ ("%s: option requires an argument -- %c\n"),
712 argv[0],
713 c);
714 }
715 if (optstring[0] == ':')
716 c = ':';
717 else
718 c = '?';
719 return c;
720 }
721 else
722 /* We already incremented `GNoptind' once;
723 * increment it again when taking next ARGV-elt as argument. */
724 GNoptarg = argv[GNoptind++];
725
726 /* GNoptarg is now the argument, see if it's in the
727 * table of longopts. */
728
729 for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
730 nameend++)
731 /* Do nothing. */;
732
733 /* Test all long options for either exact match
734 * or abbreviated matches. */
735 if (longopts != NULL)
736 for (p = longopts, option_index = 0; p->name; p++, option_index++)
737 if (! strncmp (p->name, nextchar, nameend - nextchar))
738 {
739 if ((unsigned int) (nameend - nextchar) == strlen (p->name))
740 {
741 /* Exact match found. */
742 pfound = p;
743 indfound = option_index;
744 exact = 1;
745 break;
746 }
747 else if (pfound == NULL)
748 {
749 /* First nonexact match found. */
750 pfound = p;
751 indfound = option_index;
752 }
753 else
754 /* Second or later nonexact match found. */
755 ambig = 1;
756 }
757 if (ambig && ! exact)
758 {
759 if (GNopterr)
760 fprintf (stderr,
761 _ ("%s: option `-W %s' is ambiguous\n"),
762 argv[0],
763 argv[GNoptind]);
764 nextchar += strlen (nextchar);
765 GNoptind++;
766 return '?';
767 }
768 if (pfound != NULL)
769 {
770 option_index = indfound;
771 if (*nameend)
772 {
773 /* Don't test has_arg with >, because some C compilers don't
774 * allow it to be used on enums. */
775 if (pfound->has_arg)
776 GNoptarg = nameend + 1;
777 else
778 {
779 if (GNopterr)
780 fprintf (stderr,
781 _ ("%s: option `-W %s' does not allow an argument\n"),
782 argv[0],
783 pfound->name);
784
785 nextchar += strlen (nextchar);
786 return '?';
787 }
788 }
789 else if (pfound->has_arg == 1)
790 {
791 if (GNoptind < argc)
792 GNoptarg = argv[GNoptind++];
793 else
794 {
795 if (GNopterr)
796 fprintf (stderr,
797 _ ("%s: option `%s' requires an argument\n"),
798 argv[0],
799 argv[GNoptind - 1]);
800 nextchar += strlen (nextchar);
801 return optstring[0] == ':' ? ':' : '?';
802 }
803 }
804 nextchar += strlen (nextchar);
805 if (longind != NULL)
806 *longind = option_index;
807 if (pfound->flag)
808 {
809 *(pfound->flag) = pfound->val;
810 return 0;
811 }
812 return pfound->val;
813 }
814 nextchar = NULL;
815 return 'W'; /* Let the application handle it. */
816 }
817 if (temp[1] == ':')
818 {
819 if (temp[2] == ':')
820 {
821 /* This is an option that accepts an argument optionally. */
822 if (*nextchar != '\0')
823 {
825 GNoptind++;
826 }
827 else
828 GNoptarg = NULL;
829 nextchar = NULL;
830 }
831 else
832 {
833 /* This is an option that requires an argument. */
834 if (*nextchar != '\0')
835 {
837 /* If we end this ARGV-element by taking the rest as an arg,
838 * we must advance to the next element now. */
839 GNoptind++;
840 }
841 else if (GNoptind == argc)
842 {
843 if (GNopterr)
844 {
845 /* 1003.2 specifies the format of this message. */
846 fprintf (stderr,
847 _ ("%s: option requires an argument -- %c\n"),
848 argv[0],
849 c);
850 }
851 if (optstring[0] == ':')
852 c = ':';
853 else
854 c = '?';
855 }
856 else
857 /* We already incremented `GNoptind' once;
858 * increment it again when taking next ARGV-elt as argument. */
859 GNoptarg = argv[GNoptind++];
860 nextchar = NULL;
861 }
862 }
863 return c;
864 }
865}
866
867
868static int
869GNgetopt_long (int argc,
870 char *const *argv,
871 const char *options,
872 const struct GNoption *long_options,
873 int *opt_index)
874{
875 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
876}
877
878
879/* ******************** now the GNUnet specific modifications... ********************* */
880
881
882int
883GNUNET_GETOPT_run (const char *binaryOptions,
884 const struct GNUNET_GETOPT_CommandLineOption *allOptions,
885 unsigned int argc,
886 char *const *argv)
887{
888 struct GNoption *long_options;
890 int count;
891 char *shorts;
892 int spos;
894 uint8_t *seen;
895 unsigned int optmatch = 0;
896 const char *have_exclusive = NULL;
897
898 GNUNET_assert (argc > 0);
899 GNoptind = 0;
900 clpc.binaryName = argv[0];
901 clpc.binaryOptions = binaryOptions;
902 clpc.allOptions = allOptions;
903 clpc.argv = argv;
904 clpc.argc = argc;
905 for (count = 0; NULL != allOptions[count].name; count++)
906 ;
907
908 /* transform our option representation into the format
909 used by the GNU getopt copylib */
910 long_options = GNUNET_new_array (count + 1, struct GNoption);
911 seen = GNUNET_new_array (count, uint8_t);
912 shorts = GNUNET_malloc (count * 2 + 1);
913 spos = 0;
914 for (unsigned i = 0; i < count; i++)
915 {
916 long_options[i].name = allOptions[i].name;
917 long_options[i].has_arg = allOptions[i].require_argument;
918 long_options[i].flag = NULL;
919 long_options[i].val = allOptions[i].shortName;
920 shorts[spos++] = allOptions[i].shortName;
921 if (allOptions[i].require_argument != 0)
922 shorts[spos++] = ':';
923 }
924 long_options[count].name = NULL;
925 long_options[count].has_arg = 0;
926 long_options[count].flag = NULL;
927 long_options[count].val = '\0';
928 shorts[spos] = '\0';
929 cont = GNUNET_OK;
930
931 /* main getopt loop */
932 while (1)
933 {
934 int option_index = 0;
935 unsigned int i;
936 int c;
937
938 c = GNgetopt_long (argc,
939 argv,
940 shorts,
941 long_options,
942 &option_index);
943 if (c == GNUNET_SYSERR)
944 break; /* No more flags to process */
945
946 /* Check which of our program's options was given by the user */
947 for (i = 0; i < count; i++)
948 {
949 clpc.currentArgument = GNoptind - 1;
950 if ((char) c == allOptions[i].shortName)
951 {
952 optmatch++;
953 if (allOptions[i].option_exclusive)
954 have_exclusive = allOptions[i].name;
955 if (GNUNET_OK == cont)
956 {
957 /* parse the option using the option-specific processor */
958 cont = allOptions[i].processor (&clpc,
959 allOptions[i].scls,
960 allOptions[i].name,
961 GNoptarg);
962 }
963 seen[i] = 1;
964 break;
965 }
966 }
967 if (i == count)
968 {
969 fprintf (stderr,
970 _ ("Use %s to get a list of options.\n"),
971 "--help");
972 cont = GNUNET_SYSERR;
973 }
974 }
975 GNUNET_free (shorts);
976 GNUNET_free (long_options);
977
978 /* check that if any option that was marked as exclusive
979 is the only option that was provided */
980 if ((NULL != have_exclusive) && (optmatch > 1))
981 {
982 fprintf (stderr,
983 _ ("Option `%s' can't be used with other options.\n"),
984 have_exclusive);
985 cont = GNUNET_SYSERR;
986 }
987 if (GNUNET_YES == cont)
988 {
989 /* check that all mandatory options are present */
990 for (count = 0; NULL != allOptions[count].name; count++)
991 {
992 if ((0 == seen[count]) && (allOptions[count].option_mandatory))
993 {
994 fprintf (stderr,
995 _ ("Missing mandatory option `%s'.\n"),
996 allOptions[count].name);
997 cont = GNUNET_SYSERR;
998 }
999 }
1000 }
1001 GNUNET_free (seen);
1002
1003 /* call cleaners, if available */
1004 for (unsigned int i = 0; NULL != allOptions[i].name; i++)
1005 if (NULL != allOptions[i].cleaner)
1006 allOptions[i].cleaner (allOptions[i].scls);
1007
1008 if (GNUNET_OK != cont)
1009 return cont;
1010 return GNoptind;
1011}
1012
1013
1014/* end of getopt.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static int GNoptind
Definition getopt.c:134
static int GNgetopt_long(int argc, char *const *argv, const char *options, const struct GNoption *long_options, int *opt_index)
Definition getopt.c:870
static char * GNoptarg
Definition getopt.c:119
@ REQUIRE_ORDER
Definition getopt.c:175
@ RETURN_IN_ORDER
Definition getopt.c:175
@ PERMUTE
Definition getopt.c:175
static void exchange(char **argv)
Definition getopt.c:251
static char * nextchar
Definition getopt.c:143
static const char * _getopt_initialize(int argc, char *const *argv, const char *optstring)
Definition getopt.c:316
static char * my_index(const char *str, int chr)
Definition getopt.c:196
static int last_nonopt
Definition getopt.c:231
static int GN_getopt_internal(int argc, char *const *argv, const char *optstring, const struct GNoption *longopts, int *longind, int long_only)
Definition getopt.c:406
#define SWAP_FLAGS(ch1, ch2)
Definition getopt.c:233
#define NONOPTION_P
static int first_nonopt
Definition getopt.c:230
#define _(msgid)
Definition getopt.c:63
static enum @36 ordering
char * getenv()
static char * posixly_correct
Definition getopt.c:178
static char * name
Name (label) of the records to list.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition gnunet-uri.c:38
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
Definition getopt.c:884
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Definition of a command line option.
int require_argument
Is an argument required? GNUNET_NO (includes optional) or GNUNET_YES (required)
const char * name
Long name of the option (may not be NULL)
GNUNET_GETOPT_CommandLineOptionProcessor processor
Handler for the option.
const char shortName
Short name of the option.
void(* cleaner)(void *cls)
Function to call on scls to clean up after processing all the arguments.
General context for command line processors.
const char * binaryOptions
Name of application with option summary.
const struct GNUNET_GETOPT_CommandLineOption * allOptions
Array with all command line options.
char *const * argv
Original command line.
unsigned int argc
Total number of argv's.
int has_arg
Definition getopt.c:93
int val
Definition getopt.c:95
const char * name
Definition getopt.c:90
int * flag
Definition getopt.c:94

◆ _

#define _ (   msgid)    (msgid)

Definition at line 63 of file getopt.c.

◆ SWAP_FLAGS

#define SWAP_FLAGS (   ch1,
  ch2 
)

Definition at line 233 of file getopt.c.

◆ NONOPTION_P

#define NONOPTION_P   (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0')

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REQUIRE_ORDER 
PERMUTE 
RETURN_IN_ORDER 

Definition at line 175 of file getopt.c.

Function Documentation

◆ getenv()

◆ my_index()

static char * my_index ( const char *  str,
int  chr 
)
static

Definition at line 196 of file getopt.c.

197{
198 while (*str)
199 {
200 if (*str == chr)
201 return (char *) str;
202 str++;
203 }
204 return 0;
205}

Referenced by GN_getopt_internal().

Here is the caller graph for this function:

◆ exchange()

static void exchange ( char **  argv)
static

Definition at line 251 of file getopt.c.

252{
253 int bottom = first_nonopt;
254 int middle = last_nonopt;
255 int top = GNoptind;
256 char *tem;
257
258 /* Exchange the shorter segment with the far end of the longer segment.
259 * That puts the shorter segment into the right place.
260 * It leaves the longer segment in the right place overall,
261 * but it consists of two parts that need to be swapped next. */
262
263 while (top > middle && middle > bottom)
264 {
265 if (top - middle > middle - bottom)
266 {
267 /* Bottom segment is the short one. */
268 int len = middle - bottom;
269 register int i;
270
271 /* Swap it with the top part of the top segment. */
272 for (i = 0; i < len; i++)
273 {
274 tem = argv[bottom + i];
275 argv[bottom + i] = argv[top - (middle - bottom) + i];
276 argv[top - (middle - bottom) + i] = tem;
277 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
278 }
279 /* Exclude the moved bottom segment from further swapping. */
280 top -= len;
281 }
282 else
283 {
284 /* Top segment is the short one. */
285 int len = top - middle;
286 register int i;
287
288 /* Swap it with the bottom part of the bottom segment. */
289 for (i = 0; i < len; i++)
290 {
291 tem = argv[bottom + i];
292 argv[bottom + i] = argv[middle + i];
293 argv[middle + i] = tem;
294 SWAP_FLAGS (bottom + i, middle + i);
295 }
296 /* Exclude the moved top segment from further swapping. */
297 bottom += len;
298 }
299 }
300
301 /* Update records for the slots the non-options now occupy. */
302
305}

References first_nonopt, GNoptind, last_nonopt, and SWAP_FLAGS.

Referenced by GN_getopt_internal().

Here is the caller graph for this function:

◆ _getopt_initialize()

static const char * _getopt_initialize ( int  argc,
char *const *  argv,
const char *  optstring 
)
static

Definition at line 316 of file getopt.c.

317{
318 /* Start processing options with ARGV-element 1 (since ARGV-element 0
319 * is the program name); the sequence of previously skipped
320 * non-option ARGV-elements is empty. */
321
323
324 nextchar = NULL;
325
326 posixly_correct = getenv ("POSIXLY_CORRECT");
327
328 /* Determine how to handle the ordering of options and nonoptions. */
329
330 if (optstring[0] == '-')
331 {
333 ++optstring;
334 }
335 else if (optstring[0] == '+')
336 {
338 ++optstring;
339 }
340 else if (posixly_correct != NULL)
342 else
344
345 return optstring;
346}

References first_nonopt, getenv(), GNoptind, last_nonopt, nextchar, ordering, PERMUTE, posixly_correct, REQUIRE_ORDER, and RETURN_IN_ORDER.

Referenced by GN_getopt_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GN_getopt_internal()

static int GN_getopt_internal ( int  argc,
char *const *  argv,
const char *  optstring,
const struct GNoption longopts,
int *  longind,
int  long_only 
)
static

Definition at line 406 of file getopt.c.

412{
413 static int __getopt_initialized = 0;
414 static int GNopterr = 1;
415
416 GNoptarg = NULL;
417
418 if ((GNoptind == 0) || ! __getopt_initialized)
419 {
420 if (GNoptind == 0)
421 GNoptind = 1; /* Don't scan ARGV[0], the program name. */
422 optstring = _getopt_initialize (argc, argv, optstring);
423 __getopt_initialized = 1;
424 }
425
426 /* Test whether ARGV[GNoptind] points to a non-option argument.
427 * Either it does not have option syntax, or there is an environment flag
428 * from the shell indicating it is not an option. The later information
429 * is only used when the used in the GNU libc. */
430#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0')
431
432 if ((nextchar == NULL) || (*nextchar == '\0'))
433 {
434 /* Advance to the next ARGV-element. */
435
436 /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been
437 * moved back by the user (who may also have changed the arguments). */
438 if (last_nonopt > GNoptind)
442
443 if (ordering == PERMUTE)
444 {
445 /* If we have just processed some options following some non-options,
446 * exchange them so that the options come first. */
447
449 exchange ((char **) argv);
450 else if (last_nonopt != GNoptind)
452
453 /* Skip any additional non-options
454 * and extend the range of non-options previously skipped. */
455
456 while (GNoptind < argc && NONOPTION_P)
457 GNoptind++;
459 }
460
461 /* The special ARGV-element `--' means premature end of options.
462 * Skip it like a null option,
463 * then exchange with previous non-options as if it were an option,
464 * then skip everything else like a non-option. */
465 if ((GNoptind != argc) && ! strcmp (argv[GNoptind], "--"))
466 {
467 GNoptind++;
468
470 exchange ((char **) argv);
471 else if (first_nonopt == last_nonopt)
473 last_nonopt = argc;
474
475 GNoptind = argc;
476 }
477
478 /* If we have done all the ARGV-elements, stop the scan
479 * and back over any non-options that we skipped and permuted. */
480
481 if (GNoptind == argc)
482 {
483 /* Set the next-arg-index to point at the non-options
484 * that we previously skipped, so the caller will digest them. */
487 return -1;
488 }
489
490 /* If we have come to a non-option and did not permute it,
491 * either stop the scan or describe it to the caller and pass it by. */
492
493 if (NONOPTION_P)
494 {
495 if (ordering == REQUIRE_ORDER)
496 return -1;
497 GNoptarg = argv[GNoptind++];
498 return 1;
499 }
500
501 /* We have found another option-ARGV-element.
502 * Skip the initial punctuation. */
503
504 nextchar =
505 (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
506 }
507
508 /* Decode the current option-ARGV-element. */
509
510 /* Check whether the ARGV-element is a long option.
511 *
512 * If long_only and the ARGV-element has the form "-f", where f is
513 * a valid short option, don't consider it an abbreviated form of
514 * a long option that starts with f. Otherwise there would be no
515 * way to give the -f short option.
516 *
517 * On the other hand, if there's a long option "fubar" and
518 * the ARGV-element is "-fu", do consider that an abbreviation of
519 * the long option, just like "--fu", and not "-f" with arg "u".
520 *
521 * This distinction seems to be the most useful approach. */if ((longopts != NULL) &&
522 ((argv[GNoptind][1] == '-') ||
523 (long_only &&
524 (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1])))))
525 {
526 char *nameend;
527 const struct GNoption *p;
528 const struct GNoption *pfound = NULL;
529 int exact = 0;
530 int ambig = 0;
531 int indfound = -1;
532 int option_index;
533
534 for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
535 /* Do nothing. */;
536
537 /* Test all long options for either exact match
538 * or abbreviated matches. */
539 for (p = longopts, option_index = 0; p->name; p++, option_index++)
540 if (! strncmp (p->name, nextchar, nameend - nextchar))
541 {
542 if ((unsigned int) (nameend - nextchar) ==
543 (unsigned int) strlen (p->name))
544 {
545 /* Exact match found. */
546 pfound = p;
547 indfound = option_index;
548 exact = 1;
549 break;
550 }
551 else if (pfound == NULL)
552 {
553 /* First nonexact match found. */
554 pfound = p;
555 indfound = option_index;
556 }
557 else
558 /* Second or later nonexact match found. */
559 ambig = 1;
560 }
561
562 if (ambig && ! exact)
563 {
564 if (GNopterr)
565 fprintf (stderr,
566 _ ("%s: option `%s' is ambiguous\n"),
567 argv[0],
568 argv[GNoptind]);
569 nextchar += strlen (nextchar);
570 GNoptind++;
571 return '?';
572 }
573
574 if (pfound != NULL)
575 {
576 option_index = indfound;
577 GNoptind++;
578 if (*nameend)
579 {
580 /* Don't test has_arg with >, because some C compilers don't
581 * allow it to be used on enums. */
582 if (pfound->has_arg)
583 GNoptarg = nameend + 1;
584 else
585 {
586 if (GNopterr)
587 {
588 if (argv[GNoptind - 1][1] == '-')
589 /* --option */
590 fprintf (stderr,
591 _ ("%s: option `--%s' does not allow an argument\n"),
592 argv[0],
593 pfound->name);
594 else
595 /* +option or -option */
596 fprintf (stderr,
597 _ ("%s: option `%c%s' does not allow an argument\n"),
598 argv[0],
599 argv[GNoptind - 1][0],
600 pfound->name);
601 }
602 nextchar += strlen (nextchar);
603 return '?';
604 }
605 }
606 else if (pfound->has_arg == 1)
607 {
608 if (GNoptind < argc)
609 {
610 GNoptarg = argv[GNoptind++];
611 }
612 else
613 {
614 if (GNopterr)
615 {
616 fprintf (stderr,
617 _ ("%s: option `%s' requires an argument\n"),
618 argv[0],
619 argv[GNoptind - 1]);
620 }
621 nextchar += strlen (nextchar);
622 return (optstring[0] == ':') ? ':' : '?';
623 }
624 }
625 nextchar += strlen (nextchar);
626 if (longind != NULL)
627 *longind = option_index;
628 if (pfound->flag)
629 {
630 *(pfound->flag) = pfound->val;
631 return 0;
632 }
633 return pfound->val;
634 }
635
636 /* Can't find it as a long option. If this is not getopt_long_only,
637 * or the option starts with '--' or is not a valid short
638 * option, then it's an error.
639 * Otherwise interpret it as a short option. */
640 if (! long_only || (argv[GNoptind][1] == '-') ||
641 (my_index (optstring, *nextchar) == NULL) )
642 {
643 if (GNopterr)
644 {
645 if (argv[GNoptind][1] == '-')
646 /* --option */
647 fprintf (stderr,
648 _ ("%s: unrecognized option `--%s'\n"),
649 argv[0],
650 nextchar);
651 else
652 /* +option or -option */
653 fprintf (stderr,
654 _ ("%s: unrecognized option `%c%s'\n"),
655 argv[0],
656 argv[GNoptind][0],
657 nextchar);
658 }
659 nextchar = (char *) "";
660 GNoptind++;
661 return '?';
662 }
663 }
664
665 /* Look at and handle the next short option-character. */
666
667 {
668 char c = *nextchar++;
669 char *temp = my_index (optstring, c);
670
671 /* Increment `GNoptind' when we start to process its last character. */
672 if (*nextchar == '\0')
673 ++GNoptind;
674
675 if ((temp == NULL) || (c == ':'))
676 {
677 if (GNopterr)
678 {
679 if (posixly_correct)
680 /* 1003.2 specifies the format of this message. */
681 fprintf (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
682 else
683 fprintf (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
684 }
685 return '?';
686 }
687 /* Convenience. Treat POSIX -W foo same as long option --foo */
688 if ((temp[0] == 'W') && (temp[1] == ';'))
689 {
690 char *nameend;
691 const struct GNoption *p;
692 const struct GNoption *pfound = NULL;
693 int exact = 0;
694 int ambig = 0;
695 int indfound = 0;
696 int option_index;
697
698 /* This is an option that requires an argument. */
699 if (*nextchar != '\0')
700 {
702 /* If we end this ARGV-element by taking the rest as an arg,
703 * we must advance to the next element now. */
704 GNoptind++;
705 }
706 else if (GNoptind == argc)
707 {
708 if (GNopterr)
709 {
710 /* 1003.2 specifies the format of this message. */
711 fprintf (stderr,
712 _ ("%s: option requires an argument -- %c\n"),
713 argv[0],
714 c);
715 }
716 if (optstring[0] == ':')
717 c = ':';
718 else
719 c = '?';
720 return c;
721 }
722 else
723 /* We already incremented `GNoptind' once;
724 * increment it again when taking next ARGV-elt as argument. */
725 GNoptarg = argv[GNoptind++];
726
727 /* GNoptarg is now the argument, see if it's in the
728 * table of longopts. */
729
730 for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
731 nameend++)
732 /* Do nothing. */;
733
734 /* Test all long options for either exact match
735 * or abbreviated matches. */
736 if (longopts != NULL)
737 for (p = longopts, option_index = 0; p->name; p++, option_index++)
738 if (! strncmp (p->name, nextchar, nameend - nextchar))
739 {
740 if ((unsigned int) (nameend - nextchar) == strlen (p->name))
741 {
742 /* Exact match found. */
743 pfound = p;
744 indfound = option_index;
745 exact = 1;
746 break;
747 }
748 else if (pfound == NULL)
749 {
750 /* First nonexact match found. */
751 pfound = p;
752 indfound = option_index;
753 }
754 else
755 /* Second or later nonexact match found. */
756 ambig = 1;
757 }
758 if (ambig && ! exact)
759 {
760 if (GNopterr)
761 fprintf (stderr,
762 _ ("%s: option `-W %s' is ambiguous\n"),
763 argv[0],
764 argv[GNoptind]);
765 nextchar += strlen (nextchar);
766 GNoptind++;
767 return '?';
768 }
769 if (pfound != NULL)
770 {
771 option_index = indfound;
772 if (*nameend)
773 {
774 /* Don't test has_arg with >, because some C compilers don't
775 * allow it to be used on enums. */
776 if (pfound->has_arg)
777 GNoptarg = nameend + 1;
778 else
779 {
780 if (GNopterr)
781 fprintf (stderr,
782 _ ("%s: option `-W %s' does not allow an argument\n"),
783 argv[0],
784 pfound->name);
785
786 nextchar += strlen (nextchar);
787 return '?';
788 }
789 }
790 else if (pfound->has_arg == 1)
791 {
792 if (GNoptind < argc)
793 GNoptarg = argv[GNoptind++];
794 else
795 {
796 if (GNopterr)
797 fprintf (stderr,
798 _ ("%s: option `%s' requires an argument\n"),
799 argv[0],
800 argv[GNoptind - 1]);
801 nextchar += strlen (nextchar);
802 return optstring[0] == ':' ? ':' : '?';
803 }
804 }
805 nextchar += strlen (nextchar);
806 if (longind != NULL)
807 *longind = option_index;
808 if (pfound->flag)
809 {
810 *(pfound->flag) = pfound->val;
811 return 0;
812 }
813 return pfound->val;
814 }
815 nextchar = NULL;
816 return 'W'; /* Let the application handle it. */
817 }
818 if (temp[1] == ':')
819 {
820 if (temp[2] == ':')
821 {
822 /* This is an option that accepts an argument optionally. */
823 if (*nextchar != '\0')
824 {
826 GNoptind++;
827 }
828 else
829 GNoptarg = NULL;
830 nextchar = NULL;
831 }
832 else
833 {
834 /* This is an option that requires an argument. */
835 if (*nextchar != '\0')
836 {
838 /* If we end this ARGV-element by taking the rest as an arg,
839 * we must advance to the next element now. */
840 GNoptind++;
841 }
842 else if (GNoptind == argc)
843 {
844 if (GNopterr)
845 {
846 /* 1003.2 specifies the format of this message. */
847 fprintf (stderr,
848 _ ("%s: option requires an argument -- %c\n"),
849 argv[0],
850 c);
851 }
852 if (optstring[0] == ':')
853 c = ':';
854 else
855 c = '?';
856 }
857 else
858 /* We already incremented `GNoptind' once;
859 * increment it again when taking next ARGV-elt as argument. */
860 GNoptarg = argv[GNoptind++];
861 nextchar = NULL;
862 }
863 }
864 return c;
865 }
866}

References _, _getopt_initialize(), exchange(), first_nonopt, GNoption::flag, GNoptarg, GNoptind, GNoption::has_arg, last_nonopt, my_index(), GNoption::name, nextchar, NONOPTION_P, ordering, p, PERMUTE, posixly_correct, REQUIRE_ORDER, and GNoption::val.

Referenced by GNgetopt_long().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNgetopt_long()

static int GNgetopt_long ( int  argc,
char *const *  argv,
const char *  options,
const struct GNoption long_options,
int *  opt_index 
)
static

Definition at line 870 of file getopt.c.

875{
876 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
877}

References GN_getopt_internal(), and options.

Referenced by GNUNET_GETOPT_run().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ GNoptarg

char* GNoptarg = NULL
static

Definition at line 119 of file getopt.c.

Referenced by GN_getopt_internal(), and GNUNET_GETOPT_run().

◆ GNoptind

int GNoptind = 1
static

Definition at line 134 of file getopt.c.

Referenced by _getopt_initialize(), exchange(), GN_getopt_internal(), and GNUNET_GETOPT_run().

◆ nextchar

char* nextchar
static

Definition at line 143 of file getopt.c.

Referenced by _getopt_initialize(), and GN_getopt_internal().

◆ []

enum { ... } ordering

◆ posixly_correct

char* posixly_correct
static

Definition at line 178 of file getopt.c.

Referenced by _getopt_initialize(), and GN_getopt_internal().

◆ first_nonopt

int first_nonopt
static

Definition at line 230 of file getopt.c.

Referenced by _getopt_initialize(), exchange(), and GN_getopt_internal().

◆ last_nonopt

int last_nonopt
static

Definition at line 231 of file getopt.c.

Referenced by _getopt_initialize(), exchange(), and GN_getopt_internal().