aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/util/getopt.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/util/getopt.c')
-rw-r--r--src/util/getopt.c75
1 files changed, 33 insertions, 42 deletions
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 2a35ab278..db81d1c3d 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -410,8 +410,8 @@ _getopt_initialize (argc, argv, optstring)
410 { 410 {
411 if (nonoption_flags_max_len == 0) 411 if (nonoption_flags_max_len == 0)
412 { 412 {
413 if (__getopt_nonoption_flags == NULL 413 if (__getopt_nonoption_flags == NULL ||
414 || __getopt_nonoption_flags[0] == '\0') 414 __getopt_nonoption_flags[0] == '\0')
415 nonoption_flags_max_len = -1; 415 nonoption_flags_max_len = -1;
416 else 416 else
417 { 417 {
@@ -497,11 +497,9 @@ _getopt_initialize (argc, argv, optstring)
497 long-named options. */ 497 long-named options. */
498 498
499static int 499static int
500GN_getopt_internal (int argc, 500GN_getopt_internal (int argc, char *const *argv, const char *optstring,
501 char *const *argv, 501 const struct GNoption *longopts, int *longind,
502 const char *optstring, 502 int long_only)
503 const struct GNoption *longopts,
504 int *longind, int long_only)
505{ 503{
506 static int __getopt_initialized = 0; 504 static int __getopt_initialized = 0;
507 static int GNopterr = 1; 505 static int GNopterr = 1;
@@ -600,8 +598,8 @@ GN_getopt_internal (int argc,
600 /* We have found another option-ARGV-element. 598 /* We have found another option-ARGV-element.
601 * Skip the initial punctuation. */ 599 * Skip the initial punctuation. */
602 600
603 nextchar = (argv[GNoptind] + 1 601 nextchar =
604 + (longopts != NULL && argv[GNoptind][1] == '-')); 602 (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
605 } 603 }
606 604
607 /* Decode the current option-ARGV-element. */ 605 /* Decode the current option-ARGV-element. */
@@ -619,11 +617,10 @@ GN_getopt_internal (int argc,
619 * 617 *
620 * This distinction seems to be the most useful approach. */ 618 * This distinction seems to be the most useful approach. */
621 619
622 if (longopts != NULL 620 if (longopts != NULL &&
623 && (argv[GNoptind][1] == '-' 621 (argv[GNoptind][1] == '-' ||
624 || (long_only 622 (long_only &&
625 && (argv[GNoptind][2] 623 (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
626 || !my_index (optstring, argv[GNoptind][1])))))
627 { 624 {
628 char *nameend; 625 char *nameend;
629 const struct GNoption *p; 626 const struct GNoption *p;
@@ -641,8 +638,8 @@ GN_getopt_internal (int argc,
641 for (p = longopts, option_index = 0; p->name; p++, option_index++) 638 for (p = longopts, option_index = 0; p->name; p++, option_index++)
642 if (!strncmp (p->name, nextchar, nameend - nextchar)) 639 if (!strncmp (p->name, nextchar, nameend - nextchar))
643 { 640 {
644 if ((unsigned int) (nameend - nextchar) 641 if ((unsigned int) (nameend - nextchar) ==
645 == (unsigned int) strlen (p->name)) 642 (unsigned int) strlen (p->name))
646 { 643 {
647 /* Exact match found. */ 644 /* Exact match found. */
648 pfound = p; 645 pfound = p;
@@ -664,8 +661,8 @@ GN_getopt_internal (int argc,
664 if (ambig && !exact) 661 if (ambig && !exact)
665 { 662 {
666 if (GNopterr) 663 if (GNopterr)
667 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 664 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
668 argv[0], argv[GNoptind]); 665 argv[GNoptind]);
669 nextchar += strlen (nextchar); 666 nextchar += strlen (nextchar);
670 GNoptind++; 667 GNoptind++;
671 return '?'; 668 return '?';
@@ -688,14 +685,12 @@ GN_getopt_internal (int argc,
688 if (argv[GNoptind - 1][1] == '-') 685 if (argv[GNoptind - 1][1] == '-')
689 /* --option */ 686 /* --option */
690 fprintf (stderr, 687 fprintf (stderr,
691 _ 688 _("%s: option `--%s' does not allow an argument\n"),
692 ("%s: option `--%s' does not allow an argument\n"),
693 argv[0], pfound->name); 689 argv[0], pfound->name);
694 else 690 else
695 /* +option or -option */ 691 /* +option or -option */
696 fprintf (stderr, 692 fprintf (stderr,
697 _ 693 _("%s: option `%c%s' does not allow an argument\n"),
698 ("%s: option `%c%s' does not allow an argument\n"),
699 argv[0], argv[GNoptind - 1][0], pfound->name); 694 argv[0], argv[GNoptind - 1][0], pfound->name);
700 } 695 }
701 nextchar += strlen (nextchar); 696 nextchar += strlen (nextchar);
@@ -712,8 +707,7 @@ GN_getopt_internal (int argc,
712 { 707 {
713 if (GNopterr) 708 if (GNopterr)
714 { 709 {
715 fprintf (stderr, 710 fprintf (stderr, _("%s: option `%s' requires an argument\n"),
716 _("%s: option `%s' requires an argument\n"),
717 argv[0], argv[GNoptind - 1]); 711 argv[0], argv[GNoptind - 1]);
718 } 712 }
719 nextchar += strlen (nextchar); 713 nextchar += strlen (nextchar);
@@ -735,19 +729,19 @@ GN_getopt_internal (int argc,
735 * or the option starts with '--' or is not a valid short 729 * or the option starts with '--' or is not a valid short
736 * option, then it's an error. 730 * option, then it's an error.
737 * Otherwise interpret it as a short option. */ 731 * Otherwise interpret it as a short option. */
738 if (!long_only || argv[GNoptind][1] == '-' 732 if (!long_only || argv[GNoptind][1] == '-' ||
739 || my_index (optstring, *nextchar) == NULL) 733 my_index (optstring, *nextchar) == NULL)
740 { 734 {
741 if (GNopterr) 735 if (GNopterr)
742 { 736 {
743 if (argv[GNoptind][1] == '-') 737 if (argv[GNoptind][1] == '-')
744 /* --option */ 738 /* --option */
745 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), 739 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0],
746 argv[0], nextchar); 740 nextchar);
747 else 741 else
748 /* +option or -option */ 742 /* +option or -option */
749 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), 743 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0],
750 argv[0], argv[GNoptind][0], nextchar); 744 argv[GNoptind][0], nextchar);
751 } 745 }
752 nextchar = (char *) ""; 746 nextchar = (char *) "";
753 GNoptind++; 747 GNoptind++;
@@ -849,8 +843,8 @@ GN_getopt_internal (int argc,
849 if (ambig && !exact) 843 if (ambig && !exact)
850 { 844 {
851 if (GNopterr) 845 if (GNopterr)
852 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 846 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0],
853 argv[0], argv[GNoptind]); 847 argv[GNoptind]);
854 nextchar += strlen (nextchar); 848 nextchar += strlen (nextchar);
855 GNoptind++; 849 GNoptind++;
856 return '?'; 850 return '?';
@@ -881,8 +875,7 @@ GN_getopt_internal (int argc,
881 else 875 else
882 { 876 {
883 if (GNopterr) 877 if (GNopterr)
884 fprintf (stderr, 878 fprintf (stderr, _("%s: option `%s' requires an argument\n"),
885 _("%s: option `%s' requires an argument\n"),
886 argv[0], argv[GNoptind - 1]); 879 argv[0], argv[GNoptind - 1]);
887 nextchar += strlen (nextchar); 880 nextchar += strlen (nextchar);
888 return optstring[0] == ':' ? ':' : '?'; 881 return optstring[0] == ':' ? ':' : '?';
@@ -930,8 +923,8 @@ GN_getopt_internal (int argc,
930 if (GNopterr) 923 if (GNopterr)
931 { 924 {
932 /* 1003.2 specifies the format of this message. */ 925 /* 1003.2 specifies the format of this message. */
933 fprintf (stderr, 926 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
934 _("%s: option requires an argument -- %c\n"), argv[0], c); 927 argv[0], c);
935 } 928 }
936 if (optstring[0] == ':') 929 if (optstring[0] == ':')
937 c = ':'; 930 c = ':';
@@ -950,9 +943,7 @@ GN_getopt_internal (int argc,
950} 943}
951 944
952static int 945static int
953GNgetopt_long (int argc, 946GNgetopt_long (int argc, char *const *argv, const char *options,
954 char *const *argv,
955 const char *options,
956 const struct GNoption *long_options, int *opt_index) 947 const struct GNoption *long_options, int *opt_index)
957{ 948{
958 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0); 949 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
@@ -1028,9 +1019,9 @@ GNUNET_GETOPT_run (const char *binaryOptions,
1028 clpc.currentArgument = GNoptind - 1; 1019 clpc.currentArgument = GNoptind - 1;
1029 if ((char) c == allOptions[i].shortName) 1020 if ((char) c == allOptions[i].shortName)
1030 { 1021 {
1031 cont = allOptions[i].processor (&clpc, 1022 cont =
1032 allOptions[i].scls, 1023 allOptions[i].processor (&clpc, allOptions[i].scls,
1033 allOptions[i].name, GNoptarg); 1024 allOptions[i].name, GNoptarg);
1034 break; 1025 break;
1035 } 1026 }
1036 } 1027 }