diff options
author | fgsch <> | 2004-01-06 23:44:28 +0000 |
---|---|---|
committer | fgsch <> | 2004-01-06 23:44:28 +0000 |
commit | fb71e6d74e28bafd286d30793edbe19ab742fd32 (patch) | |
tree | 96bdc0606de878acd335021754e088f7224e10d1 | |
parent | 1a8fc65df94f2ed1c26b132c61f37a1aff433f1f (diff) | |
download | openbsd-fb71e6d74e28bafd286d30793edbe19ab742fd32.tar.gz openbsd-fb71e6d74e28bafd286d30793edbe19ab742fd32.tar.bz2 openbsd-fb71e6d74e28bafd286d30793edbe19ab742fd32.zip |
- Rename index to longindex and explain its use.
- Talk about zeroing the last element of the longopts array.
- Remove '?' from the switch and some KNF to the code.
- Change 0's to NULL where appropriate.
jmc@ ok.
-rw-r--r-- | src/lib/libc/stdlib/getopt_long.3 | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/lib/libc/stdlib/getopt_long.3 b/src/lib/libc/stdlib/getopt_long.3 index 6226dfe99f..978583ef96 100644 --- a/src/lib/libc/stdlib/getopt_long.3 +++ b/src/lib/libc/stdlib/getopt_long.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getopt_long.3,v 1.9 2003/09/02 18:24:21 jmc Exp $ | 1 | .\" $OpenBSD: getopt_long.3,v 1.10 2004/01/06 23:44:28 fgsch Exp $ |
2 | .\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $ | 2 | .\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $ |
3 | .\" | 3 | .\" |
4 | .\" Copyright (c) 1988, 1991, 1993 | 4 | .\" Copyright (c) 1988, 1991, 1993 |
@@ -45,9 +45,9 @@ | |||
45 | .Vt extern int opterr; | 45 | .Vt extern int opterr; |
46 | .Vt extern int optreset; | 46 | .Vt extern int optreset; |
47 | .Ft int | 47 | .Ft int |
48 | .Fn getopt_long "int argc" "char * const *argv" "const char *optstring" "const struct option *longopts" "int *index" | 48 | .Fn getopt_long "int argc" "char * const *argv" "const char *optstring" "const struct option *longopts" "int *longindex" |
49 | .Ft int | 49 | .Ft int |
50 | .Fn getopt_long_only "int argc" "char * const *argv" "const char *optstring" "const struct option *longopts" "int *index" | 50 | .Fn getopt_long_only "int argc" "char * const *argv" "const char *optstring" "const struct option *longopts" "int *longindex" |
51 | .Sh DESCRIPTION | 51 | .Sh DESCRIPTION |
52 | The | 52 | The |
53 | .Fn getopt_long | 53 | .Fn getopt_long |
@@ -147,6 +147,18 @@ to the corresponding short option will make this function act just | |||
147 | like | 147 | like |
148 | .Xr getopt 3 . | 148 | .Xr getopt 3 . |
149 | .Pp | 149 | .Pp |
150 | If the | ||
151 | .Fa longindex | ||
152 | field is not | ||
153 | .Dv NULL , | ||
154 | then the integer pointed to by it will be set to the index of the long | ||
155 | option relative to | ||
156 | .Fa longopts . | ||
157 | .Pp | ||
158 | The last element of the | ||
159 | .Fa longopts | ||
160 | array has to be filled with zeroes. | ||
161 | .Pp | ||
150 | The | 162 | The |
151 | .Fn getopt_long_only | 163 | .Fn getopt_long_only |
152 | function behaves identically to | 164 | function behaves identically to |
@@ -193,15 +205,15 @@ int daggerset; | |||
193 | 205 | ||
194 | /* options descriptor */ | 206 | /* options descriptor */ |
195 | static struct option longopts[] = { | 207 | static struct option longopts[] = { |
196 | { "buffy", no_argument, 0, 'b' }, | 208 | { "buffy", no_argument, NULL, 'b' }, |
197 | { "fluoride", required_argument, 0, 'f' }, | 209 | { "fluoride", required_argument, NULL, 'f' }, |
198 | { "daggerset", no_argument, &daggerset, 1 }, | 210 | { "daggerset", no_argument, &daggerset, 1 }, |
199 | { 0, 0, 0, 0 } | 211 | { NULL, 0, NULL, 0 } |
200 | }; | 212 | }; |
201 | 213 | ||
202 | bflag = 0; | 214 | bflag = 0; |
203 | while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) | 215 | while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) |
204 | switch(ch) { | 216 | switch (ch) { |
205 | case 'b': | 217 | case 'b': |
206 | bflag = 1; | 218 | bflag = 1; |
207 | break; | 219 | break; |
@@ -212,10 +224,9 @@ while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) | |||
212 | case 0: | 224 | case 0: |
213 | if (daggerset) { | 225 | if (daggerset) { |
214 | fprintf(stderr,"Buffy will use her dagger to " | 226 | fprintf(stderr,"Buffy will use her dagger to " |
215 | "apply fluoride to dracula's teeth\en"); | 227 | "apply fluoride to dracula's teeth\en"); |
216 | } | 228 | } |
217 | break; | 229 | break; |
218 | case '?': | ||
219 | default: | 230 | default: |
220 | usage(); | 231 | usage(); |
221 | } | 232 | } |