POSIX.2ification, from my work with NetBSD.
authorJ.T. Conklin <jtc@FreeBSD.org>
Tue, 23 Nov 1993 00:02:23 +0000 (00:02 +0000)
committerJ.T. Conklin <jtc@FreeBSD.org>
Tue, 23 Nov 1993 00:02:23 +0000 (00:02 +0000)
usr.bin/basename/Makefile
usr.bin/basename/basename.1
usr.bin/basename/basename.c
usr.bin/dirname/Makefile
usr.bin/dirname/dirname.c
usr.bin/nice/Makefile
usr.bin/nice/nice.1
usr.bin/nice/nice.c

index f31a89a..adcd001 100644 (file)
@@ -1,4 +1,5 @@
-#      @(#)Makefile    5.2 (Berkeley) 5/11/90
+#      from: @(#)Makefile      5.2 (Berkeley) 5/11/90
+#      $Id: Makefile,v 1.2 1993/07/31 15:25:43 mycroft Exp $
 
 PROG=  basename
 MLINKS=        basename.1 dirname.1
 
 PROG=  basename
 MLINKS=        basename.1 dirname.1
index 2568d44..8377b31 100644 (file)
@@ -32,7 +32,8 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"     @(#)basename.1 6.7 (Berkeley) 6/27/91
+.\"     from: @(#)basename.1   6.7 (Berkeley) 6/27/91
+.\"    $Id: basename.1,v 1.5 1993/10/01 22:42:23 jtc Exp $
 .\"
 .Dd June 27, 1991
 .Dt BASENAME 1
 .\"
 .Dd June 27, 1991
 .Dt BASENAME 1
@@ -56,14 +57,6 @@ and a
 .Ar suffix ,
 if given.
 The resulting filename is written to the standard output.
 .Ar suffix ,
 if given.
 The resulting filename is written to the standard output.
-If
-.Ar string
-ends in the slash character,
-.Ql / ,
-or is the same as the
-.Ar suffix
-argument,
-a newline is output.
 A non-existant suffix is ignored.
 .Pp
 .Nm Dirname
 A non-existant suffix is ignored.
 .Pp
 .Nm Dirname
@@ -85,13 +78,15 @@ Both the
 .Nm basename
 and
 .Nm dirname
 .Nm basename
 and
 .Nm dirname
+utilities
 exit 0 on success, and >0 if an error occurs.
 .Sh SEE ALSO
 exit 0 on success, and >0 if an error occurs.
 .Sh SEE ALSO
-.Xr csh 1
+.Xr csh 1 ,
 .Xr sh 1
 .Sh STANDARDS
 The
 .Nm basename
 and
 .Nm dirname
 .Xr sh 1
 .Sh STANDARDS
 The
 .Nm basename
 and
 .Nm dirname
-functions are expected to be POSIX 1003.2 compatible.
+utilities conform to
+.St -p1003.2-92 .
index 18ff636..1f176ad 100644 (file)
@@ -38,22 +38,28 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)basename.c 5.1 (Berkeley) 3/9/91";
+/*static char sccsid[] = "from: @(#)basename.c 5.1 (Berkeley) 3/9/91";*/
+static char rcsid[] = "$Id: basename.c,v 1.5 1993/11/19 19:58:46 jtc Exp $";
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <locale.h>
 
 
+static void usage __P((void));
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int optind;
        register char *p;
        int ch;
 
        register char *p;
        int ch;
 
-       while ((ch = getopt(argc, argv, "")) != EOF)
+       setlocale(LC_ALL, "");
+
+       while ((ch = getopt(argc, argv, "")) != -1)
                switch(ch) {
                case '?':
                default:
                switch(ch) {
                case '?':
                default:
@@ -89,8 +95,10 @@ main(argc, argv)
         * (3) If there are any trailing slash characters in string, they
         *     shall be removed.
         */
         * (3) If there are any trailing slash characters in string, they
         *     shall be removed.
         */
-       for (; *p; ++p);
-       while (*--p == '/');
+       for (; *p; ++p)
+               ;
+       while (*--p == '/')
+               ;
        *++p = '\0';
 
        /*
        *++p = '\0';
 
        /*
@@ -125,6 +133,7 @@ main(argc, argv)
        exit(0);
 }
 
        exit(0);
 }
 
+static void
 usage()
 {
        (void)fprintf(stderr, "usage: basename string [suffix]\n");
 usage()
 {
        (void)fprintf(stderr, "usage: basename string [suffix]\n");
index 446ed1a..9a969de 100644 (file)
@@ -1,4 +1,5 @@
-#      @(#)Makefile    5.2 (Berkeley) 5/11/90
+#      from: @(#)Makefile      5.2 (Berkeley) 5/11/90
+#      $Id: Makefile,v 1.2 1993/07/31 15:23:57 mycroft Exp $
 
 PROG=  dirname
 NOMAN= noman
 
 PROG=  dirname
 NOMAN= noman
index 662cd5b..5b8a826 100644 (file)
@@ -38,21 +38,27 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)dirname.c  5.6 (Berkeley) 3/9/91";
+/*static char sccsid[] = "from: @(#)dirname.c  5.6 (Berkeley) 3/9/91";*/
+static char rcsid[] = "$Id: dirname.c,v 1.4 1993/10/01 22:23:58 jtc Exp $";
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <locale.h>
 
 
+static void usage      __P((void));
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int optind;
        register char *p;
        int ch;
 
        register char *p;
        int ch;
 
-       while ((ch = getopt(argc, argv, "")) != EOF)
+       setlocale(LC_ALL, "");
+
+       while ((ch = getopt(argc, argv, "")) != -1)
                switch(ch) {
                case '?':
                default:
                switch(ch) {
                case '?':
                default:
@@ -86,8 +92,10 @@ main(argc, argv)
         * (3) If there are any trailing slash characters in string, they
         *     shall be removed.
         */
         * (3) If there are any trailing slash characters in string, they
         *     shall be removed.
         */
-       for (; *p; ++p);
-       while (*--p == '/');
+       for (; *p; ++p)
+               ;
+       while (*--p == '/')
+               ;
        *++p = '\0';
 
        /*
        *++p = '\0';
 
        /*
@@ -132,6 +140,7 @@ main(argc, argv)
        exit(0);
 }
 
        exit(0);
 }
 
+static void
 usage()
 {
        (void)fprintf(stderr, "usage: dirname path\n");
 usage()
 {
        (void)fprintf(stderr, "usage: dirname path\n");
index ca6b03f..54c5d5f 100644 (file)
@@ -1,4 +1,5 @@
-#      @(#)Makefile    5.5 (Berkeley) 5/11/90
+#      from: @(#)Makefile      5.5 (Berkeley) 5/11/90
+#      $Id: Makefile,v 1.2 1993/07/31 15:18:30 mycroft Exp $
 
 PROG=  nice
 
 
 PROG=  nice
 
index 2d95baf..5b9bf5a 100644 (file)
@@ -1,7 +1,6 @@
 .\" Copyright (c) 1980, 1990 The Regents of the University of California.
 .\" All rights reserved.
 .\"
 .\" Copyright (c) 1980, 1990 The Regents of the University of California.
 .\" All rights reserved.
 .\"
-.\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
 .\" are met:
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
 .\" are met:
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"    @(#)nice.1      6.7 (Berkeley) 7/24/91
+.\"    from: @(#)nice.1        6.7 (Berkeley) 7/24/91
+.\"    $Id: nice.1,v 1.3 1993/08/27 20:22:04 jtc Exp $
 .\"
 .Dd July 24, 1991
 .Dt NICE 1
 .\"
 .Dd July 24, 1991
 .Dt NICE 1
-.Os BSD 4
+.Os 
 .Sh NAME
 .Nm nice
 .Sh NAME
 .Nm nice
-.Nd execute a Bourne shell command at a low scheduling priority
+.Nd execute a utility with an altered scheduling priority
 .Sh SYNOPSIS
 .Nm nice
 .Sh SYNOPSIS
 .Nm nice
-.Op Fl Ns Ar number
-.Ar command
-.Op Ar arguments
+.Op Fl n Ar increment
+.Ar utility
+.Op Ar argument ...
 .Sh DESCRIPTION
 .Nm Nice
 runs
 .Sh DESCRIPTION
 .Nm Nice
 runs
-.Ar command
-at a low priority.
-(Think of low and slow).
-If
-.Fl Ns Ar number
-is specified, and if it is greater than or equal
-to 10 (the default),
+.Ar utility
+at an altered scheduling priority.
+If an 
+.Ar increment 
+is given, it is used; otherwise
+an increment of 10 is assumed.
+The super-user can run utilities with priorities higher than normal by using
+a negative 
+.Ar increment .
+The priority can be adjusted over a
+range of -20 (the higest) to 20 (the lowest).
+.Pp
+Available options:
+.Bl -tag -width indent
+.It Fl n Ar increment
+A positive or negative decimal integer used to modify the system scheduling
+priority of 
+.Ar utility.
+.El
+.Sh DIAGNOSTICS
+The
 .Nm nice
 .Nm nice
-will execute
-.Ar command
-at that priority.
-The upper bound, or lowest priority that
+utility shall exit with one of the following values:
+.Bl -tag -width indent
+.It 1-125
+An error occured in the 
 .Nm nice
 .Nm nice
-will run a command is 20.
-The lower bounds or
-higher priorities (integers less than 10)
-can only be requested by the super-user.
-Negative numbers are expressed as
-.Fl - Ns Ar number .
+utility.
+.It 126
+The 
+.Ar utility
+was found but could not be invoked.
+.It 127
+The 
+.Ar utility
+could not be found.
+.El
 .Pp
 .Pp
-The returned exit status is the exit value from the
-command executed by
-.Nm nice .
+Otherwise, the exit status of 
+.Nm nice
+shall be that of 
+.Ar utility .
+.Sh COMPATIBILITY
+The historic 
+.Fl Ns Ar increment 
+option has been deprecated but is still supported in this implementation.
 .Sh SEE ALSO
 .Xr csh 1 ,
 .Xr renice 8
 .Sh SEE ALSO
 .Xr csh 1 ,
 .Xr renice 8
+.Sh STANDARDS
+The
+.Nm nice
+utility conforms to 
+.St -p1003.2-92 .
 .Sh HISTORY
 A
 .Nm nice
 .Sh HISTORY
 A
 .Nm nice
-command appeared in
+utility appeared in
 .At v6 .
 .Sh BUGS
 .Nm Nice
 .At v6 .
 .Sh BUGS
 .Nm Nice
-is particular to
-.Xr sh  1  .
-If you use
-.Xr csh  1  ,
-then commands executed with ``&'' are automatically immune to hangup
-signals while in the background.
-.Pp
-.Nm Nice
 is built into
 .Xr csh  1
 with a slightly different syntax than described here.  The form
 is built into
 .Xr csh  1
 with a slightly different syntax than described here.  The form
index 5e3f09f..4f5fc41 100644 (file)
@@ -38,61 +38,78 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)nice.c     5.4 (Berkeley) 6/1/90";
+/*static char sccsid[] = "from: @(#)nice.c     5.4 (Berkeley) 6/1/90";*/
+static char rcsid[] = "$Id: nice.c,v 1.7 1993/11/19 20:07:13 jtc Exp $";
 #endif /* not lint */
 
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <stdio.h>
 #endif /* not lint */
 
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
 #include <ctype.h>
 #include <ctype.h>
+#include <errno.h>
+#include <err.h>
+#include <unistd.h>
 
 #define        DEFNICE 10
 
 
 #define        DEFNICE 10
 
-/* ARGSUSED */
+static void usage();
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int errno;
-       int niceness;
-       char *strerror();
+       int niceness = DEFNICE;
+       int c;
 
 
-       niceness = DEFNICE;
-       if (argv[1][0] == '-')
-               if (isdigit(argv[1][1])) {
-                       niceness = atoi(argv[1] + 1);
-                       ++argv;
-               }
-               else {
-                       (void)fprintf(stderr, "nice: illegal option -- %c\n",
-                           argv[1][1]);
+       setlocale(LC_ALL, "");
+
+        /* handle obsolete -number syntax */
+        if (argc > 1 && argv[1][0] == '-' && isdigit(argv[1][1])) {
+               niceness = atoi (argv[1] + 1);
+                argc--; argv++;
+        }
+
+       while ((c = getopt (argc, argv, "n:")) != -1) {
+               switch (c) {
+               case 'n':
+                       niceness = atoi (optarg);
+                       break;
+
+               case '?':
+               default:
                        usage();
                        usage();
+                       break;
                }
                }
+       }
+       argc -= optind; argv += optind;
 
 
-       if (!argv[1])
+       if (argc == 0)
                usage();
 
        errno = 0;
        niceness += getpriority(PRIO_PROCESS, 0);
        if (errno) {
                usage();
 
        errno = 0;
        niceness += getpriority(PRIO_PROCESS, 0);
        if (errno) {
-               (void)fprintf(stderr, "nice: getpriority: %s\n",
-                   strerror(errno));
-               exit(1);
+               err (1, "getpriority");
+               /* NOTREACHED */
        }
        if (setpriority(PRIO_PROCESS, 0, niceness)) {
        }
        if (setpriority(PRIO_PROCESS, 0, niceness)) {
-               (void)fprintf(stderr,
-                   "nice: setpriority: %s\n", strerror(errno));
-               exit(1);
+               warn ("setpriority");
        }
        }
-       execvp(argv[1], &argv[1]);
-       (void)fprintf(stderr,
-           "nice: %s: %s\n", argv[1], strerror(errno));
-       exit(1);
+
+       execvp(argv[0], &argv[0]);
+       err ((errno == ENOENT) ? 127 : 126, "%s", argv[0]);
+       /* NOTREACHED */
 }
 
 }
 
+static void
 usage()
 {
        (void)fprintf(stderr,
 usage()
 {
        (void)fprintf(stderr,
-           "nice [ -# ] command [ options ] [ operands ]\n");
+           "usage: nice [ -n increment ] utility [ argument ...]\n");
+       
        exit(1);
 }
        exit(1);
 }