fix err routine, make everyone use it; minor ANSI cleanups
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 4 Jun 1991 07:55:45 +0000 (23:55 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 4 Jun 1991 07:55:45 +0000 (23:55 -0800)
SCCS-vsn: bin/ps/keyword.c 5.8
SCCS-vsn: bin/ps/nlist.c 5.2
SCCS-vsn: bin/ps/print.c 5.7
SCCS-vsn: bin/ps/ps.c 5.41
SCCS-vsn: bin/ps/ps.h 5.3

usr/src/bin/ps/keyword.c
usr/src/bin/ps/nlist.c
usr/src/bin/ps/print.c
usr/src/bin/ps/ps.c
usr/src/bin/ps/ps.h

index 48adebe..fa72529 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)keyword.c  5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)keyword.c  5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -15,6 +15,7 @@ static char sccsid[] = "@(#)keyword.c 5.7 (Berkeley) %G%";
 #include <sys/proc.h>
 #include <errno.h>
 #include <stdio.h>
 #include <sys/proc.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
 #include "ps.h"
 #include <stddef.h>
 #include <string.h>
 #include "ps.h"
@@ -270,11 +271,8 @@ parsefmt(p)
                        /* void */;
                if (!(v = findvar(cp)))
                        continue;
                        /* void */;
                if (!(v = findvar(cp)))
                        continue;
-               if ((vent = (struct varent *)malloc(sizeof(struct varent))) == 
-                   NULL) {
-                       (void)fprintf(stderr, "ps: no space\n");
-                       exit(1);
-               }
+               if ((vent = malloc(sizeof(struct varent))) == NULL)
+                       err("%s", strerror(errno));
                vent->var = v;
                vent->next = NULL;
                if (vhead == NULL)
                vent->var = v;
                vent->next = NULL;
                if (vhead == NULL)
@@ -284,10 +282,8 @@ parsefmt(p)
                        vtail = vent;
                }
        }
                        vtail = vent;
                }
        }
-       if (!vhead) {
-               (void)fprintf(stderr, "ps: no valid keywords\n");
-               exit(1);
-       }
+       if (!vhead)
+               err("no valid keywords\n");
 }
 
 static VAR *
 }
 
 static VAR *
index ca23965..8bdc6cc 100644 (file)
@@ -6,13 +6,14 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)nlist.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)nlist.c    5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <nlist.h>
 #include <errno.h>
 #include <stdio.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <nlist.h>
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
 
 struct nlist psnl[] = {
        {"_ecmx"},
 
 struct nlist psnl[] = {
        {"_ecmx"},
@@ -58,4 +59,3 @@ donlist()
        }
        return(rval);
 }
        }
        return(rval);
 }
-
index e93dfcd..22914f3 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -569,6 +569,6 @@ printval(bp, v)
                (void) printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
                break;
        default:
                (void) printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
                break;
        default:
-               error("unknown type %d", v->type);
+               err("unknown type %d", v->type);
        }
 }
        }
 }
index 4fa903b..1248483 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ps.c       5.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)ps.c       5.41 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -27,7 +27,6 @@ static char sccsid[] = "@(#)ps.c      5.40 (Berkeley) %G%";
 #include <kvm.h>
 #include <errno.h>
 #include <unistd.h>
 #include <kvm.h>
 #include <errno.h>
 #include <unistd.h>
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -152,7 +151,7 @@ main(argc, argv)
                        break;
                case 'T':
                        if ((optarg = ttyname(STDIN_FILENO)) == NULL)
                        break;
                case 'T':
                        if ((optarg = ttyname(STDIN_FILENO)) == NULL)
-                               error("stdin: not a terminal");
+                               err("stdin: not a terminal");
                        /* FALLTHROUGH */
                case 't': {
                        char *ttypath;
                        /* FALLTHROUGH */
                case 't': {
                        char *ttypath;
@@ -166,13 +165,10 @@ main(argc, argv)
                                    _PATH_TTY, optarg);
                        else
                                ttypath = optarg;
                                    _PATH_TTY, optarg);
                        else
                                ttypath = optarg;
-                       if (stat(ttypath, &stbuf) == -1) {
-                               (void)fprintf(stderr,
-                                   "ps: %s: %s\n", ttypath, strerror(errno));
-                               exit(1);
-                       }
+                       if (stat(ttypath, &stbuf) == -1)
+                               err("%s: %s", ttypath, strerror(errno));
                        if (!S_ISCHR(stbuf.st_mode))
                        if (!S_ISCHR(stbuf.st_mode))
-                               error("%s: not a terminal", ttypath);
+                               err("%s: not a terminal", ttypath);
                        ttydev = stbuf.st_rdev;
                        break;
                }
                        ttydev = stbuf.st_rdev;
                        break;
                }
@@ -218,7 +214,7 @@ main(argc, argv)
        }
 #endif
        if (kvm_openfiles(nlistf, memf, swapf) == -1)
        }
 #endif
        if (kvm_openfiles(nlistf, memf, swapf) == -1)
-               error("kvm_openfiles: %s", kvm_geterr());
+               err("kvm_openfiles: %s", kvm_geterr());
 
        if (!fmt)
                parsefmt(dfmt);
 
        if (!fmt)
                parsefmt(dfmt);
@@ -246,15 +242,11 @@ main(argc, argv)
        /*
         * select procs
         */
        /*
         * select procs
         */
-       if ((nentries = kvm_getprocs(what, flag)) == -1) {
-               (void) fprintf(stderr, "ps: %s\n", kvm_geterr());
-               exit(1);
-       }
-       kinfo = (KINFO *)malloc(nentries * sizeof(KINFO));
-       if (kinfo == NULL) {
-               (void)fprintf(stderr, "ps: %s\n", strerror(ENOMEM));
-               exit(1);
-       }
+       if ((nentries = kvm_getprocs(what, flag)) == -1)
+               err("%s", kvm_geterr());
+       kinfo = malloc(nentries * sizeof(KINFO));
+       if (kinfo == NULL)
+               err("%s", strerror(errno));
        for (nentries = 0; p = kvm_nextproc(); ++nentries) {
                kinfo[nentries].ki_p = p;
                kinfo[nentries].ki_e = kvm_geteproc(p);
        for (nentries = 0; p = kvm_nextproc(); ++nentries) {
                kinfo[nentries].ki_p = p;
                kinfo[nentries].ki_e = kvm_geteproc(p);
@@ -321,10 +313,8 @@ saveuser(ki)
        register struct usave *usp;
        register struct user *up;
 
        register struct usave *usp;
        register struct user *up;
 
-       if ((usp = (struct usave *)calloc(1, sizeof(struct usave))) == NULL) {
-               (void)fprintf(stderr, "ps: %s\n", strerror(errno));
-               exit(1);
-       }
+       if ((usp = calloc(1, sizeof(struct usave))) == NULL)
+               err("%s", strerror(errno));
        ki->ki_u = usp;
        up = kvm_getu(ki->ki_p);
        /*
        ki->ki_u = usp;
        up = kvm_getu(ki->ki_p);
        /*
@@ -389,10 +379,8 @@ kludge_oldps_options(s)
        char *newopts, *ns, *cp;
 
        len = strlen(s);
        char *newopts, *ns, *cp;
 
        len = strlen(s);
-       if ((newopts = ns = malloc(len + 2)) == NULL) {
-               (void)fprintf(stderr, "ps: %s\n", strerror(errno));
-               exit(1);
-       }
+       if ((newopts = ns = malloc(len + 2)) == NULL)
+               err("%s", strerror(errno));
        /*
         * options begin with '-'
         */
        /*
         * options begin with '-'
         */
@@ -432,27 +420,38 @@ kludge_oldps_options(s)
        return (newopts);
 }
 
        return (newopts);
 }
 
-#ifdef lint
-/* VARARGS1 */
-error(fmt) char *fmt; { (void) fputs(fmt, stderr); exit(1); /* NOTREACHED */ }
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+void
+#if __STDC__
+err(const char *fmt, ...)
 #else
 #else
-error(fmt)
+err(fmt, va_alist)
        char *fmt;
        char *fmt;
+        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
-
+#if __STDC__
        va_start(ap, fmt);
        va_start(ap, fmt);
-       (void) fprintf(stderr, "ps: ");
-       (void) vfprintf(stderr, fmt, ap);
-       (void) fprintf(stderr, "\n");
+#else
+       va_start(ap);
+#endif
+       (void)fprintf(stderr, "ps: ");
+       (void)vfprintf(stderr, fmt, ap);
        va_end(ap);
        va_end(ap);
+       (void)fprintf(stderr, "\n");
        exit(1);
        exit(1);
+       /* NOTREACHED */
 }
 }
-#endif
 
 usage()
 {
        (void) fprintf(stderr,
 
 usage()
 {
        (void) fprintf(stderr,
-           "usage:\tps [ -aChjlmrSsTuvwx ] [ -O|o fmt ] [ -p pid ] [ -t tty ] [ system ] [ core ] [ swap ]\n\t ps [ -L ]\n");
+"usage: ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]\n\t  [-M core] [-N system] [-W swap]\n       ps [-L]\n");
        exit(1);
 }
        exit(1);
 }
index 21e7cab..bccf764 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ps.h        5.2 (Berkeley) %G%
+ *     @(#)ps.h        5.3 (Berkeley) %G%
  */
 
 #define        UNLIMITED       0       /* unlimited terminal width */
  */
 
 #define        UNLIMITED       0       /* unlimited terminal width */
@@ -56,5 +56,4 @@ struct varent {
        struct varent *next;
 };
 
        struct varent *next;
 };
 
-extern VAR var[];
-extern struct varent *vhead, *vtail;
+#include "extern.h"