diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/basename.c | 2 | ||||
-rw-r--r-- | src/date.c | 2 | ||||
-rw-r--r-- | src/dirname.c | 2 | ||||
-rw-r--r-- | src/echo.c | 2 | ||||
-rw-r--r-- | src/env.c | 2 | ||||
-rw-r--r-- | src/id.c | 2 | ||||
-rw-r--r-- | src/logname.c | 2 | ||||
-rw-r--r-- | src/nice.c | 2 | ||||
-rw-r--r-- | src/pathchk.c | 2 | ||||
-rw-r--r-- | src/printenv.c | 119 | ||||
-rw-r--r-- | src/printf.c | 2 | ||||
-rw-r--r-- | src/sleep.c | 1 | ||||
-rw-r--r-- | src/stty.c | 2 | ||||
-rw-r--r-- | src/su.c | 2 | ||||
-rw-r--r-- | src/tee.c | 2 | ||||
-rw-r--r-- | src/test.c | 2 | ||||
-rw-r--r-- | src/tty.c | 2 | ||||
-rw-r--r-- | src/uname.c | 2 | ||||
-rw-r--r-- | src/who.c | 2 | ||||
-rw-r--r-- | src/whoami.c | 84 | ||||
-rw-r--r-- | src/yes.c | 61 |
21 files changed, 253 insertions, 46 deletions
diff --git a/src/basename.c b/src/basename.c index 9b7ccae8a..c89b13c27 100644 --- a/src/basename.c +++ b/src/basename.c @@ -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 diff --git a/src/date.c b/src/date.c index 65a41d911..3b2959565 100644 --- a/src/date.c +++ b/src/date.c @@ -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 diff --git a/src/dirname.c b/src/dirname.c index 802713543..b615ba13d 100644 --- a/src/dirname.c +++ b/src/dirname.c @@ -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 diff --git a/src/echo.c b/src/echo.c index 65864ecf3..29f9dd5b7 100644 --- a/src/echo.c +++ b/src/echo.c @@ -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. @@ -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 @@ -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 diff --git a/src/logname.c b/src/logname.c index 86f648c3d..413b22fcd 100644 --- a/src/logname.c +++ b/src/logname.c @@ -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 diff --git a/src/nice.c b/src/nice.c index ca989cda5..a0814651f 100644 --- a/src/nice.c +++ b/src/nice.c @@ -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 diff --git a/src/pathchk.c b/src/pathchk.c index e98b75ede..0a0d40a7f 100644 --- a/src/pathchk.c +++ b/src/pathchk.c @@ -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 diff --git a/src/printenv.c b/src/printenv.c index ac4511cc5..b5e3c8940 100644 --- a/src/printenv.c +++ b/src/printenv.c @@ -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 @@ -27,12 +27,65 @@ 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); } diff --git a/src/printf.c b/src/printf.c index 0fe108fb6..a26ee9e12 100644 --- a/src/printf.c +++ b/src/printf.c @@ -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 diff --git a/src/sleep.c b/src/sleep.c index bf15f81a4..41e775563 100644 --- a/src/sleep.c +++ b/src/sleep.c @@ -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 diff --git a/src/stty.c b/src/stty.c index 032972051..eba0f11d1 100644 --- a/src/stty.c +++ b/src/stty.c @@ -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 @@ -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 @@ -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 diff --git a/src/test.c b/src/test.c index a4fd543dc..2e2bae34e 100644 --- a/src/test.c +++ b/src/test.c @@ -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. @@ -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 diff --git a/src/uname.c b/src/uname.c index 65fad1c36..e63c2298a 100644 --- a/src/uname.c +++ b/src/uname.c @@ -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 @@ -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 diff --git a/src/whoami.c b/src/whoami.c index 4a12406f1..833ae1421 100644 --- a/src/whoami.c +++ b/src/whoami.c @@ -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 @@ -18,11 +18,62 @@ /* 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); } @@ -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 @@ -15,25 +15,70 @@ 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' : ' '); + } + } } |