Browse Source

tidy up examples

- use err() for error handling
- add lint hints
- spacing nits and missing braces
ok otto
OPENBSD_3_9
jaredy 19 years ago
parent
commit
04a4c1a148
3 changed files with 16 additions and 17 deletions
  1. +4
    -7
      src/lib/libc/stdlib/getopt.3
  2. +5
    -5
      src/lib/libc/stdlib/getopt_long.3
  3. +7
    -5
      src/lib/libc/stdlib/getsubopt.3

+ 4
- 7
src/lib/libc/stdlib/getopt.3 View File

@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $OpenBSD: getopt.3,v 1.36 2005/07/26 13:38:41 jmc Exp $
.\" $OpenBSD: getopt.3,v 1.37 2005/10/11 01:23:41 jaredy Exp $
.\"
.Dd December 17, 2002
.Dt GETOPT 3
@ -187,15 +187,12 @@ while ((ch = getopt(argc, argv, "bf:")) != -1) {
bflag = 1;
break;
case 'f':
if ((fd = open(optarg, O_RDONLY, 0)) < 0) {
(void)fprintf(stderr,
"myname: %s: %s\en", optarg, strerror(errno));
exit(1);
}
if ((fd = open(optarg, O_RDONLY, 0)) == -1)
err(1, "%s", optarg);
break;
case '?':
default:
usage();
/* NOTREACHED */
}
}
argc -= optind;


+ 5
- 5
src/lib/libc/stdlib/getopt_long.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: getopt_long.3,v 1.11 2005/07/26 04:17:44 jaredy Exp $
.\" $OpenBSD: getopt_long.3,v 1.12 2005/10/11 01:23:41 jaredy Exp $
.\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
@ -223,14 +223,14 @@ while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1)
err(1, "unable to open %s", optarg);
break;
case 0:
if (daggerset) {
fprintf(stderr,"Buffy will use her dagger to "
if (daggerset)
fprintf(stderr, "Buffy will use her dagger to "
"apply fluoride to dracula's teeth\en");
}
break;
default:
usage();
}
/* NOTREACHED */
}
argc -= optind;
argv += optind;
.Ed


+ 7
- 5
src/lib/libc/stdlib/getsubopt.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: getsubopt.3,v 1.10 2005/07/26 04:20:23 jaredy Exp $
.\" $OpenBSD: getsubopt.3,v 1.11 2005/10/11 01:23:41 jaredy Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -104,15 +104,15 @@ char *tokens[] = {
extern char *optarg, *suboptarg;
char *options, *value;
while ((ch = getopt(argc, argv, "ab:")) != \-1) {
switch(ch) {
while ((ch = getopt(argc, argv, "ab:")) != -1) {
switch (ch) {
case 'a':
/* process ``a'' option */
break;
case 'b':
options = optarg;
while (*options) {
switch(getsubopt(&options, tokens, &value)) {
switch (getsubopt(&options, tokens, &value)) {
case ONE:
/* process ``one'' sub option */
break;
@ -122,16 +122,18 @@ while ((ch = getopt(argc, argv, "ab:")) != \-1) {
error("no value for two");
i = atoi(value);
break;
case \-1:
case -1:
if (suboptarg)
error("illegal sub option %s",
suboptarg);
else
error("missing sub option");
break;
}
}
break;
}
}
.Ed
.Sh SEE ALSO
.Xr getopt 3 ,


Loading…
Cancel
Save