summaryrefslogtreecommitdiffstats
path: root/gl/getopt.c
diff options
context:
space:
mode:
authorTon Voon <ton.voon@opsera.com>2010-06-17 10:16:43 +0100
committertonvoon <ton.voon@opsera.com>2010-06-23 13:30:34 +0000
commit18f6835edaf7d640a2c9e476cb1babdbdadbfd9b (patch)
treeae11f40e48dc34658445c99012726f32bfb45c56 /gl/getopt.c
parentf61412478ceb7c821793c8356b936f64066508bf (diff)
downloadmonitoring-plugins-18f6835edaf7d640a2c9e476cb1babdbdadbfd9b.tar.gz
Added state retention APIs. Implemented for check_snmp with --rate option.
See http://nagiosplugin.org/c-api-private for more details on the API. Also updated check_snmp -l option to change the perfdata label.
Diffstat (limited to 'gl/getopt.c')
-rw-r--r--gl/getopt.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/gl/getopt.c b/gl/getopt.c
index aaabc8d1..3791f129 100644
--- a/gl/getopt.c
+++ b/gl/getopt.c
@@ -348,8 +348,6 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
348 int long_only, struct _getopt_data *d, int posixly_correct) 348 int long_only, struct _getopt_data *d, int posixly_correct)
349{ 349{
350 int print_errors = d->opterr; 350 int print_errors = d->opterr;
351 if (optstring[0] == ':')
352 print_errors = 0;
353 351
354 if (argc < 1) 352 if (argc < 1)
355 return -1; 353 return -1;
@@ -364,6 +362,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
364 posixly_correct); 362 posixly_correct);
365 d->__initialized = 1; 363 d->__initialized = 1;
366 } 364 }
365 else if (optstring[0] == '-' || optstring[0] == '+')
366 optstring++;
367 if (optstring[0] == ':')
368 print_errors = 0;
367 369
368 /* Test whether ARGV[optind] points to a non-option argument. 370 /* Test whether ARGV[optind] points to a non-option argument.
369 Either it does not have option syntax, or there is an environment flag 371 Either it does not have option syntax, or there is an environment flag
@@ -633,8 +635,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
633 char *buf; 635 char *buf;
634 636
635 if (__asprintf (&buf, _("\ 637 if (__asprintf (&buf, _("\
636%s: option '%s' requires an argument\n"), 638%s: option '--%s' requires an argument\n"),
637 argv[0], argv[d->optind - 1]) >= 0) 639 argv[0], pfound->name) >= 0)
638 { 640 {
639 _IO_flockfile (stderr); 641 _IO_flockfile (stderr);
640 642
@@ -651,8 +653,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
651 } 653 }
652#else 654#else
653 fprintf (stderr, 655 fprintf (stderr,
654 _("%s: option '%s' requires an argument\n"), 656 _("%s: option '--%s' requires an argument\n"),
655 argv[0], argv[d->optind - 1]); 657 argv[0], pfound->name);
656#endif 658#endif
657 } 659 }
658 d->__nextchar += strlen (d->__nextchar); 660 d->__nextchar += strlen (d->__nextchar);
@@ -736,13 +738,13 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
736 738
737 { 739 {
738 char c = *d->__nextchar++; 740 char c = *d->__nextchar++;
739 char *temp = strchr (optstring, c); 741 const char *temp = strchr (optstring, c);
740 742
741 /* Increment `optind' when we start to process its last character. */ 743 /* Increment `optind' when we start to process its last character. */
742 if (*d->__nextchar == '\0') 744 if (*d->__nextchar == '\0')
743 ++d->optind; 745 ++d->optind;
744 746
745 if (temp == NULL || c == ':') 747 if (temp == NULL || c == ':' || c == ';')
746 { 748 {
747 if (print_errors) 749 if (print_errors)
748 { 750 {
@@ -864,7 +866,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
864 pfound = p; 866 pfound = p;
865 indfound = option_index; 867 indfound = option_index;
866 } 868 }
867 else 869 else if (long_only
870 || pfound->has_arg != p->has_arg
871 || pfound->flag != p->flag
872 || pfound->val != p->val)
868 /* Second or later nonexact match found. */ 873 /* Second or later nonexact match found. */
869 ambig = 1; 874 ambig = 1;
870 } 875 }
@@ -876,7 +881,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
876 char *buf; 881 char *buf;
877 882
878 if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"), 883 if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
879 argv[0], argv[d->optind]) >= 0) 884 argv[0], d->optarg) >= 0)
880 { 885 {
881 _IO_flockfile (stderr); 886 _IO_flockfile (stderr);
882 887
@@ -892,7 +897,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
892 } 897 }
893#else 898#else
894 fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"), 899 fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
895 argv[0], argv[d->optind]); 900 argv[0], d->optarg);
896#endif 901#endif
897 } 902 }
898 d->__nextchar += strlen (d->__nextchar); 903 d->__nextchar += strlen (d->__nextchar);
@@ -955,8 +960,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
955 char *buf; 960 char *buf;
956 961
957 if (__asprintf (&buf, _("\ 962 if (__asprintf (&buf, _("\
958%s: option '%s' requires an argument\n"), 963%s: option '-W %s' requires an argument\n"),
959 argv[0], argv[d->optind - 1]) >= 0) 964 argv[0], pfound->name) >= 0)
960 { 965 {
961 _IO_flockfile (stderr); 966 _IO_flockfile (stderr);
962 967
@@ -972,15 +977,17 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
972 free (buf); 977 free (buf);
973 } 978 }
974#else 979#else
975 fprintf (stderr, 980 fprintf (stderr, _("\
976 _("%s: option '%s' requires an argument\n"), 981%s: option '-W %s' requires an argument\n"),
977 argv[0], argv[d->optind - 1]); 982 argv[0], pfound->name);
978#endif 983#endif
979 } 984 }
980 d->__nextchar += strlen (d->__nextchar); 985 d->__nextchar += strlen (d->__nextchar);
981 return optstring[0] == ':' ? ':' : '?'; 986 return optstring[0] == ':' ? ':' : '?';
982 } 987 }
983 } 988 }
989 else
990 d->optarg = NULL;
984 d->__nextchar += strlen (d->__nextchar); 991 d->__nextchar += strlen (d->__nextchar);
985 if (longind != NULL) 992 if (longind != NULL)
986 *longind = option_index; 993 *longind = option_index;