.
authorJim Meyering <jim@meyering.net>
Tue, 1 Feb 1994 14:11:50 +0000 (14:11 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 1 Feb 1994 14:11:50 +0000 (14:11 +0000)
21 files changed:
src/basename.c
src/date.c
src/dirname.c
src/echo.c
src/env.c
src/id.c
src/logname.c
src/nice.c
src/pathchk.c
src/printenv.c
src/printf.c
src/sleep.c
src/stty.c
src/su.c
src/tee.c
src/test.c
src/tty.c
src/uname.c
src/who.c
src/whoami.c
src/yes.c

index 9b7ccae..c89b13c 100644 (file)
@@ -1,5 +1,5 @@
 /* basename -- strip directory and suffix from filenames
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 65a41d9..3b29595 100644 (file)
@@ -1,5 +1,5 @@
 /* date - print or set the system date and time
-   Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+   Copyright (C) 89, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 8027135..b615ba1 100644 (file)
@@ -1,5 +1,5 @@
 /* dirname -- strip filename suffix from pathname
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 65864ec..29f9dd5 100644 (file)
@@ -1,5 +1,5 @@
 /* echo.c, taken from Bash.
-Copyright (C) 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
+   Copyright (C) 87, 89, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
index 743cf5d..db40c61 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -1,5 +1,5 @@
 /* env - run a program in a modified environment
-   Copyright (C) 1986, 1991 Free Software Foundation, Inc.
+   Copyright (C) 86, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 6af0129..957e4aa 100644 (file)
--- a/src/id.c
+++ b/src/id.c
@@ -1,5 +1,5 @@
 /* id -- print real and effective UIDs and GIDs
-   Copyright (C) 1989, 1991 Free Software Foundation.
+   Copyright (C) 89, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 86f648c..413b22f 100644 (file)
@@ -1,5 +1,5 @@
 /* logname -- print user's login name
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index ca989cd..a081465 100644 (file)
@@ -1,5 +1,5 @@
 /* nice -- run a program with modified scheduling priority
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index e98b75e..0a0d40a 100644 (file)
@@ -1,5 +1,5 @@
 /* pathchk -- check whether pathnames are valid or portable
-   Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+   Copyright (C) 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index ac4511c..b5e3c89 100644 (file)
@@ -1,5 +1,5 @@
 /* printenv -- print all or part of environment
-   Copyright (C) 1989, 1991 Free Software Foundation.
+   Copyright (C) 89, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    David MacKenzie and Richard Mlynarik */
 
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+   (which it would do because it found this file in $srcdir).  */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
 #include <stdio.h>
 #include <sys/types.h>
+#include <getopt.h>
+
+#include "version.h"
 #include "system.h"
 
+void error ();
+
+/* The name this program was run with. */
+char *program_name;
+
+/* If non-zero, display usage information and exit.  */
+static int show_help;
+
+/* If non-zero, print the version on standard output and exit.  */
+static int show_version;
+
+static struct option const long_options[] =
+{
+  {"help", no_argument, &show_help, 1},
+  {"version", no_argument, &show_version, 1},
+  {0, 0, 0, 0}
+};
+
 extern char **environ;
 
+static void
+usage (status)
+     int status;
+{
+  if (status != 0)
+    fprintf (stderr, "Try `%s --help' for more information.\n",
+            program_name);
+  else
+    {
+      printf ("Usage: %s [OPTION]... [VARIABLE]...\n", program_name);
+      printf ("\
+\n\
+  --help      display this help and exit\n\
+  --version   output version information and exit\n\
+\n\
+If no VARIABLE, print them all.\n\
+");
+    }
+  exit (status);
+}
+
 void
 main (argc, argv)
      int argc;
@@ -42,28 +95,62 @@ main (argc, argv)
   char *ep, *ap;
   int i;
   int matches = 0;
+  int c;
+  int exit_status;
+
+  program_name = argv[0];
 
-  if (argc == 1)
+  while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
     {
-      for (env = environ; *env; ++env)
-       puts (*env);
+      switch (c)
+       {
+       case 0:
+         break;
+
+       default:
+         usage (1);
+       }
+    }
+
+  if (show_version)
+    {
+      printf ("%s\n", version_string);
       exit (0);
     }
 
-  for (i = 1; i < argc; ++i)
+  if (show_help)
+    usage (0);
+
+  if (optind == argc)
+    {
+      for (env = environ; *env != NULL; ++env)
+       puts (*env);
+      exit_status = 0;
+    }
+  else
     {
-      for (env = environ; *env; ++env)
+      for (i = optind; i < argc; ++i)
        {
-         ep = *env;
-         ap = argv[i];
-         while (*ep != '\0' && *ap != '\0' && *ep++ == *ap++)
-           if (*ep == '=' && *ap == '\0')
-             {
-               puts (ep + 1);
-               ++matches;
-               break;
-             }
+         for (env = environ; *env; ++env)
+           {
+             ep = *env;
+             ap = argv[i];
+             while (*ep != '\0' && *ap != '\0' && *ep++ == *ap++)
+               {
+                 if (*ep == '=' && *ap == '\0')
+                   {
+                     puts (ep + 1);
+                     ++matches;
+                     break;
+                   }
+               }
+           }
        }
+      exit_status = (matches != argc - optind);
     }
-  exit (matches != argc - 1);
+
+  if (ferror (stdout) || fclose (stdout) == EOF)
+    error (2, errno, "standard output");
+
+  exit (exit_status);
 }
index 0fe108f..a26ee9e 100644 (file)
@@ -1,5 +1,5 @@
 /* printf - format and print data
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index bf15f81..41e7755 100644 (file)
@@ -1,5 +1,6 @@
 /* sleep - delay for a specified amount of time.
    Copyright (C) 1984, 1991 Free Software Foundation, Inc.
+   Copyright (C) 84, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 0329720..eba0f11 100644 (file)
@@ -1,5 +1,5 @@
 /* stty -- change and print terminal line settings
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 6ea70e5..2f7e0ec 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -1,5 +1,5 @@
 /* su for GNU.  Run a shell with substitute user and group IDs.
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright (C) 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index ea257d1..707de90 100644 (file)
--- a/src/tee.c
+++ b/src/tee.c
@@ -1,5 +1,5 @@
 /* tee - read from standard input and write to standard output and files.
-   Copyright (C) 1985, 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 85, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index a4fd543..2e2bae3 100644 (file)
@@ -2,7 +2,7 @@
 
 /* Modified to run with the GNU shell by bfox. */
 
-/* Copyright (C) 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1987-1993, 1994 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
index 4b7aaa0..a7a100a 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -1,5 +1,5 @@
 /* tty -- print the path of the terminal connected to standard input
-   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
+   Copyright (C) 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 65fad1c..e63c229 100644 (file)
@@ -1,5 +1,5 @@
 /* uname -- print system information
-   Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+   Copyright (C) 89, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 78fb0ce..1acf7f2 100644 (file)
--- a/src/who.c
+++ b/src/who.c
@@ -1,5 +1,5 @@
 /* GNU's who.
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright (C) 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
index 4a12406..833ae14 100644 (file)
@@ -1,5 +1,5 @@
 /* whoami -- print effective userid
-   Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+   Copyright (C) 89, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 /* Equivalent to `id -un'. */
 /* Written by Richard Mlynarik. */
 
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+   (which it would do because it found this file in $srcdir).  */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <pwd.h>
+#include <getopt.h>
+
+#include "version.h"
 #include "system.h"
 
+/* The name this program was run with. */
+char *program_name;
+
+/* If non-zero, display usage information and exit.  */
+static int show_help;
+
+/* If non-zero, print the version on standard output and exit.  */
+static int show_version;
+
+static struct option const long_options[] =
+{
+  {"help", no_argument, &show_help, 1},
+  {"version", no_argument, &show_version, 1},
+  {0, 0, 0, 0}
+};
+
+static void
+usage (status)
+     int status;
+{
+  if (status != 0)
+    fprintf (stderr, "Try `%s --help' for more information.\n",
+            program_name);
+  else
+    {
+      printf ("Usage: %s [OPTION]...\n", program_name);
+      printf ("\
+\n\
+  --help      display this help and exit\n\
+  --version   output version information and exit\n\
+\n\
+Same as id -un.\n\
+");
+    }
+  exit (status);
+}
+
 void
 main (argc, argv)
      int argc;
@@ -30,13 +81,35 @@ main (argc, argv)
 {
   register struct passwd *pw;
   register uid_t uid;
+  int c;
+
+  program_name = argv[0];
+
+  while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
+    {
+      switch (c)
+       {
+       case 0:
+         break;
+
+       default:
+         usage (1);
+       }
+    }
 
-  if (argc != 1)
+  if (show_version)
     {
-      fprintf (stderr, "Usage: %s\n", argv[0]);
-      exit (1);
+      printf ("%s\n", version_string);
+      exit (0);
     }
 
+  if (show_help)
+    usage (0);
+
+
+  if (optind != argc)
+    usage (1);
+
   uid = geteuid ();
   pw = getpwuid (uid);
   if (pw)
@@ -44,6 +117,7 @@ main (argc, argv)
       puts (pw->pw_name);
       exit (0);
     }
-  fprintf (stderr,"%s: cannot find username for UID %u\n", argv[0], uid);
+  fprintf (stderr, "%s: cannot find username for UID %u\n",
+          program_name, (unsigned) uid);
   exit (1);
 }
index 71eabb0..55d1300 100644 (file)
--- a/src/yes.c
+++ b/src/yes.c
@@ -1,5 +1,5 @@
 /* yes - output a string repeatedly until killed
-   Copyright (C) 1991 Free Software Foundation, Inc.
+   Copyright (C) 91, 92, 93, 1994 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-/* David MacKenzie <djm@ai.mit.edu> */
+/* David MacKenzie <djm@gnu.ai.mit.edu> */
+
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+   (which it would do because it found this file in $srcdir).  */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
 
 #include <stdio.h>
+#include <getopt.h>
+
+#include "version.h"
+#include "long-options.h"
+
+/* The name this program was run with. */
+char *program_name;
+
+static void
+usage (status)
+     int status;
+{
+  if (status != 0)
+    fprintf (stderr, "Try `%s --help' for more information.\n",
+            program_name);
+  else
+    {
+      printf ("Usage: %s [OPTION]... [STRING]...\n", program_name);
+      printf ("\
+\n\
+  --help      display this help and exit\n\
+  --version   output version information and exit\n\
+\n\
+Without any STRING, assume `y'.\n\
+");
+    }
+  exit (status);
+}
 
 void
 main (argc, argv)
      int argc;
      char **argv;
 {
-  int i;
+  program_name = argv[0];
+
+  parse_long_options (argc, argv, usage);
 
   if (argc == 1)
     while (1)
       puts ("y");
 
   while (1)
-    for (i = 1; i < argc; i++)
-      {
-       fputs (argv[i], stdout);
-       putchar (i == argc - 1 ? '\n' : ' ');
-      }
+    {
+      int i;
+
+      for (i = 1; i < argc; i++)
+       {
+         fputs (argv[i], stdout);
+         putchar (i == argc - 1 ? '\n' : ' ');
+       }
+    }
 }