From 75a474834b90ba6f7e9a083025f03af41979b876 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 1 Feb 1994 14:11:50 +0000 Subject: [PATCH] . --- src/basename.c | 2 +- src/date.c | 2 +- src/dirname.c | 2 +- src/echo.c | 2 +- src/env.c | 2 +- src/id.c | 2 +- src/logname.c | 2 +- src/nice.c | 2 +- src/pathchk.c | 2 +- src/printenv.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++-------- src/printf.c | 2 +- src/sleep.c | 1 + src/stty.c | 2 +- src/su.c | 2 +- src/tee.c | 2 +- src/test.c | 2 +- src/tty.c | 2 +- src/uname.c | 2 +- src/who.c | 2 +- src/whoami.c | 84 +++++++++++++++++++++++++++++++++++++--- src/yes.c | 61 +++++++++++++++++++++++++---- 21 files changed, 253 insertions(+), 46 deletions(-) diff --git a/src/basename.c b/src/basename.c index 9b7ccae..c89b13c 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 65a41d9..3b29595 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 8027135..b615ba1 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 65864ec..29f9dd5 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. diff --git a/src/env.c b/src/env.c index 743cf5d..db40c61 100644 --- 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 diff --git a/src/id.c b/src/id.c index 6af0129..957e4aa 100644 --- 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 diff --git a/src/logname.c b/src/logname.c index 86f648c..413b22f 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 ca989cd..a081465 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 e98b75e..0a0d40a 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 ac4511c..b5e3c89 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 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 +#else +#include "config.h" +#endif +#endif + #include #include +#include + +#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 0fe108f..a26ee9e 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 bf15f81..41e7755 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 0329720..eba0f11 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 diff --git a/src/su.c b/src/su.c index 6ea70e5..2f7e0ec 100644 --- 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 diff --git a/src/tee.c b/src/tee.c index ea257d1..707de90 100644 --- 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 diff --git a/src/test.c b/src/test.c index a4fd543..2e2bae3 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. diff --git a/src/tty.c b/src/tty.c index 4b7aaa0..a7a100a 100644 --- 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 diff --git a/src/uname.c b/src/uname.c index 65fad1c..e63c229 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 diff --git a/src/who.c b/src/who.c index 78fb0ce..1acf7f2 100644 --- 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 diff --git a/src/whoami.c b/src/whoami.c index 4a12406..833ae14 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 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 +#else +#include "config.h" +#endif +#endif + #include #include #include +#include + +#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); } diff --git a/src/yes.c b/src/yes.c index 71eabb0..55d1300 100644 --- 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 @@ -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 */ +/* David MacKenzie */ + +#ifdef HAVE_CONFIG_H +#if defined (CONFIG_BROKETS) +/* We use 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 +#else +#include "config.h" +#endif +#endif #include +#include + +#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' : ' '); + } + } } -- 2.7.4