diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-04-07 21:11:46 -0400 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-04-12 21:26:35 -0400 |
commit | 74da141e618ef99959d509cb2e7be35a348a39db (patch) | |
tree | 88ebc38b381a1021fc2d74864a71e230ae591c3d /gl/getopt1.c | |
parent | c63a4f726a0b6ad8cf6040f947754a81fd4683bb (diff) | |
download | monitoring-plugins-74da141e618ef99959d509cb2e7be35a348a39db.tar.gz |
Sync with the latest Gnulib code (177f525)
Signed-off-by: Thomas Guyot-Sionnest <dermoth@aei.ca>
Diffstat (limited to 'gl/getopt1.c')
-rw-r--r-- | gl/getopt1.c | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/gl/getopt1.c b/gl/getopt1.c index ba115c47..046d69f9 100644 --- a/gl/getopt1.c +++ b/gl/getopt1.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* getopt_long and getopt_long_only entry points for GNU getopt. | 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. |
2 | Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006,2009 | 2 | Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, |
3 | Free Software Foundation, Inc. | 3 | 1998, 2004, 2006, 2009, 2010 Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
5 | 5 | ||
6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
@@ -32,25 +32,25 @@ | |||
32 | #include <stdlib.h> | 32 | #include <stdlib.h> |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #ifndef NULL | 35 | #ifndef NULL |
36 | #define NULL 0 | 36 | #define NULL 0 |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | int | 39 | int |
40 | getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, | 40 | getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, |
41 | const struct option *long_options, int *opt_index) | 41 | const struct option *long_options, int *opt_index) |
42 | { | 42 | { |
43 | return _getopt_internal (argc, (char **) argv, options, long_options, | 43 | return _getopt_internal (argc, (char **) argv, options, long_options, |
44 | opt_index, 0, 0); | 44 | opt_index, 0, 0); |
45 | } | 45 | } |
46 | 46 | ||
47 | int | 47 | int |
48 | _getopt_long_r (int argc, char **argv, const char *options, | 48 | _getopt_long_r (int argc, char **argv, const char *options, |
49 | const struct option *long_options, int *opt_index, | 49 | const struct option *long_options, int *opt_index, |
50 | struct _getopt_data *d) | 50 | struct _getopt_data *d) |
51 | { | 51 | { |
52 | return _getopt_internal_r (argc, argv, options, long_options, opt_index, | 52 | return _getopt_internal_r (argc, argv, options, long_options, opt_index, |
53 | 0, 0, d); | 53 | 0, d, 0); |
54 | } | 54 | } |
55 | 55 | ||
56 | /* Like getopt_long, but '-' as well as '--' can indicate a long option. | 56 | /* Like getopt_long, but '-' as well as '--' can indicate a long option. |
@@ -60,20 +60,20 @@ _getopt_long_r (int argc, char **argv, const char *options, | |||
60 | 60 | ||
61 | int | 61 | int |
62 | getopt_long_only (int argc, char *__getopt_argv_const *argv, | 62 | getopt_long_only (int argc, char *__getopt_argv_const *argv, |
63 | const char *options, | 63 | const char *options, |
64 | const struct option *long_options, int *opt_index) | 64 | const struct option *long_options, int *opt_index) |
65 | { | 65 | { |
66 | return _getopt_internal (argc, (char **) argv, options, long_options, | 66 | return _getopt_internal (argc, (char **) argv, options, long_options, |
67 | opt_index, 1, 0); | 67 | opt_index, 1, 0); |
68 | } | 68 | } |
69 | 69 | ||
70 | int | 70 | int |
71 | _getopt_long_only_r (int argc, char **argv, const char *options, | 71 | _getopt_long_only_r (int argc, char **argv, const char *options, |
72 | const struct option *long_options, int *opt_index, | 72 | const struct option *long_options, int *opt_index, |
73 | struct _getopt_data *d) | 73 | struct _getopt_data *d) |
74 | { | 74 | { |
75 | return _getopt_internal_r (argc, argv, options, long_options, opt_index, | 75 | return _getopt_internal_r (argc, argv, options, long_options, opt_index, |
76 | 1, 0, d); | 76 | 1, d, 0); |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
@@ -93,74 +93,74 @@ main (int argc, char **argv) | |||
93 | int option_index = 0; | 93 | int option_index = 0; |
94 | static const struct option long_options[] = | 94 | static const struct option long_options[] = |
95 | { | 95 | { |
96 | {"add", 1, 0, 0}, | 96 | {"add", 1, 0, 0}, |
97 | {"append", 0, 0, 0}, | 97 | {"append", 0, 0, 0}, |
98 | {"delete", 1, 0, 0}, | 98 | {"delete", 1, 0, 0}, |
99 | {"verbose", 0, 0, 0}, | 99 | {"verbose", 0, 0, 0}, |
100 | {"create", 0, 0, 0}, | 100 | {"create", 0, 0, 0}, |
101 | {"file", 1, 0, 0}, | 101 | {"file", 1, 0, 0}, |
102 | {0, 0, 0, 0} | 102 | {0, 0, 0, 0} |
103 | }; | 103 | }; |
104 | 104 | ||
105 | c = getopt_long (argc, argv, "abc:d:0123456789", | 105 | c = getopt_long (argc, argv, "abc:d:0123456789", |
106 | long_options, &option_index); | 106 | long_options, &option_index); |
107 | if (c == -1) | 107 | if (c == -1) |
108 | break; | 108 | break; |
109 | 109 | ||
110 | switch (c) | 110 | switch (c) |
111 | { | 111 | { |
112 | case 0: | 112 | case 0: |
113 | printf ("option %s", long_options[option_index].name); | 113 | printf ("option %s", long_options[option_index].name); |
114 | if (optarg) | 114 | if (optarg) |
115 | printf (" with arg %s", optarg); | 115 | printf (" with arg %s", optarg); |
116 | printf ("\n"); | 116 | printf ("\n"); |
117 | break; | 117 | break; |
118 | 118 | ||
119 | case '0': | 119 | case '0': |
120 | case '1': | 120 | case '1': |
121 | case '2': | 121 | case '2': |
122 | case '3': | 122 | case '3': |
123 | case '4': | 123 | case '4': |
124 | case '5': | 124 | case '5': |
125 | case '6': | 125 | case '6': |
126 | case '7': | 126 | case '7': |
127 | case '8': | 127 | case '8': |
128 | case '9': | 128 | case '9': |
129 | if (digit_optind != 0 && digit_optind != this_option_optind) | 129 | if (digit_optind != 0 && digit_optind != this_option_optind) |
130 | printf ("digits occur in two different argv-elements.\n"); | 130 | printf ("digits occur in two different argv-elements.\n"); |
131 | digit_optind = this_option_optind; | 131 | digit_optind = this_option_optind; |
132 | printf ("option %c\n", c); | 132 | printf ("option %c\n", c); |
133 | break; | 133 | break; |
134 | 134 | ||
135 | case 'a': | 135 | case 'a': |
136 | printf ("option a\n"); | 136 | printf ("option a\n"); |
137 | break; | 137 | break; |
138 | 138 | ||
139 | case 'b': | 139 | case 'b': |
140 | printf ("option b\n"); | 140 | printf ("option b\n"); |
141 | break; | 141 | break; |
142 | 142 | ||
143 | case 'c': | 143 | case 'c': |
144 | printf ("option c with value `%s'\n", optarg); | 144 | printf ("option c with value `%s'\n", optarg); |
145 | break; | 145 | break; |
146 | 146 | ||
147 | case 'd': | 147 | case 'd': |
148 | printf ("option d with value `%s'\n", optarg); | 148 | printf ("option d with value `%s'\n", optarg); |
149 | break; | 149 | break; |
150 | 150 | ||
151 | case '?': | 151 | case '?': |
152 | break; | 152 | break; |
153 | 153 | ||
154 | default: | 154 | default: |
155 | printf ("?? getopt returned character code 0%o ??\n", c); | 155 | printf ("?? getopt returned character code 0%o ??\n", c); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | if (optind < argc) | 159 | if (optind < argc) |
160 | { | 160 | { |
161 | printf ("non-option ARGV-elements: "); | 161 | printf ("non-option ARGV-elements: "); |
162 | while (optind < argc) | 162 | while (optind < argc) |
163 | printf ("%s ", argv[optind++]); | 163 | printf ("%s ", argv[optind++]); |
164 | printf ("\n"); | 164 | printf ("\n"); |
165 | } | 165 | } |
166 | 166 | ||