lint; if using getopt, probably using stdio -- simplify
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 6 Mar 1989 04:26:56 +0000 (20:26 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 6 Mar 1989 04:26:56 +0000 (20:26 -0800)
SCCS-vsn: lib/libc/stdlib/getopt.c 4.8

usr/src/lib/libc/stdlib/getopt.c

index 63e3eef..cf2c994 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getopt.c   4.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)getopt.c   4.8 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
@@ -31,15 +31,6 @@ char *optarg;                /* argument associated with option */
 
 #define        BADCH   (int)'?'
 #define        EMSG    ""
 
 #define        BADCH   (int)'?'
 #define        EMSG    ""
-#define        tell(s) { \
-       if (opterr) { \
-               fputs(*nargv, stderr); \
-               fputs(s, stderr); \
-               fputc(optopt, stderr); \
-               fputc((int)'\n', stderr); \
-       } \
-       return(BADCH); \
-}
 
 getopt(nargc, nargv, ostr)
        int nargc;
 
 getopt(nargc, nargv, ostr)
        int nargc;
@@ -61,7 +52,10 @@ getopt(nargc, nargv, ostr)
            !(oli = index(ostr, optopt))) {
                if (!*place)
                        ++optind;
            !(oli = index(ostr, optopt))) {
                if (!*place)
                        ++optind;
-               tell(": illegal option -- ");
+               if (opterr)
+                       (void)fprintf(stderr, "%s: illegal option -- %c\n",
+                           *nargv, optopt);
+               return(BADCH);
        }
        if (*++oli != ':') {                    /* don't need argument */
                optarg = NULL;
        }
        if (*++oli != ':') {                    /* don't need argument */
                optarg = NULL;
@@ -73,7 +67,11 @@ getopt(nargc, nargv, ostr)
                        optarg = place;
                else if (nargc <= ++optind) {   /* no arg */
                        place = EMSG;
                        optarg = place;
                else if (nargc <= ++optind) {   /* no arg */
                        place = EMSG;
-                       tell(": option requires an argument -- ");
+                       if (opterr)
+                               (void)fprintf(stderr,
+                                   "%s: option requires an argument -- %c\n",
+                                   *nargv, optopt);
+                       return(BADCH);
                }
                else                            /* white space */
                        optarg = nargv[optind];
                }
                else                            /* white space */
                        optarg = nargv[optind];