#ifdef _AIX /* for Bison */
#pragma alloca
#else
-char *alloca ();
+void *alloca ();
#endif
#endif
#endif
+Sun Oct 10 14:05:23 1993 Jim Meyering meyering@comco.com
+
+ * false.sh, groups.sh, nohup.sh, true.sh: Add --help and --version.
+ * src/Makefile.in (false, groups, nohup, true): Substitute the string
+ from version.c for @VERSION@ in *.sh.
+
+Sat Oct 9 23:12:53 1993 Jim Meyering meyering@comco.com
+
+ * configure.in: Remove AC_UNISTD_H; add unistd.h to AC_HAVE_HEADERS.
+
+Tue Oct 5 22:18:05 1993 Jim Meyering meyering@comco.com
+
+ * tty.c (main): Detect write error. Use isatty (rather than
+ testing whether ttyname() is NULL) to determine exit status
+ because ttyname may return NULL when stdin is a terminal device.
+
+ * expr.c (eval7): Rewrite if-else-if-else... sequence to avoid a
+ spurious `function returns without a value' warning.
+
+ * printenv.c (main), tty.c (main): Detect and report write errors.
+
+ * echo.c, patchchk.c, printenv.c, printf.c, sleep.c, stty.c, su.c,
+ tee.c, test.c, tty.c, uname.c, yes.c: Accept --help and --version
+ options.
+
+ * long-options.c: New file. To let echo, expr, printf, test, and
+ yes accept --help and --version as unobtrusively as possible.
+ * src/Makefile.in [SORUCES]: Add it.
+
+ * configure.in: Add AC_TIME_WITH_SYS_TIME and AC_STAT_MACROS_BROKEN.
+
+ * nice.c (main) [NICE_PRIORITY]: When given an argument, don't
+ try to get current priority. nice() requires only the delta;
+ we don't need to compute the absolute priority as for setpriority.
+
Mon Oct 04 22:15:07 1993 Jim Meyering (meyering@comco.com)
* who.c (print_entry, print_heading, who_am_i):
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
# define VALID_ECHO_OPTIONS "n"
#endif /* !V9_ECHO */
+/* The name this program was run with. */
+char *program_name;
+
+void parse_long_options ();
+
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] [-ne] [string ...]\n",
+ program_name);
+ exit (1);
+}
+
/* Print the words in LIST to standard output. If the first word is
`-n', then don't print a trailing newline. We also support the
echo syntax from Version 9 unix systems. */
{
int display_return = 1, do_v9 = 0;
+ program_name = argv[0];
+
+ parse_long_options (argc, argv, usage);
+
/* System V machines already have a /bin/sh with a v9 behaviour. We
use the identical behaviour for these machines so that the
existing system shell scripts won't barf. */
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const longopts[] =
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>
-#include <getopt.h>
#include "system.h"
#include "version.h"
char *xstrdup ();
char *strstr ();
char *xmalloc ();
+void parse_long_options ();
static VALUE *docolon ();
static VALUE *eval ();
static void trace ();
#endif
-static struct option const long_options[] =
-{
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
- {0, 0, 0, 0}
-};
-
static void
usage ()
{
exit (1);
}
-/* Process long options that precede all other command line arguments. */
-
-static void
-parse_long_options (argc, argv)
- int argc;
- char **argv;
-{
- int c;
-
- while ((c = getopt_long (argc, argv, "+", long_options, (int *) 0)) != EOF)
- {
- switch (c)
- {
- case 'h':
- usage ();
-
- case 'v':
- printf ("%s\n", version_string);
- exit (0);
-
- default:
- usage ();
- }
- }
-
- /* Restore optind in case it has advanced past a leading `--'. We can use a
- simple assignment here because all brances of the above switch statement
- exit. Otherwise, we'd have to be careful to decrement only when optind
- is larger than 1 and the last argument processed was `--'. */
-
- optind = 1;
-}
-
void
main (argc, argv)
int argc;
program_name = argv[0];
- parse_long_options (argc, argv);
+ parse_long_options (argc, argv, usage);
if (argc == 1)
usage ();
#endif
if (nomoreargs ())
error (2, 0, "syntax error");
- else if (nextarg ("("))
+
+ if (nextarg ("("))
{
args++;
v = eval ();
args++;
return v;
}
- else if (nextarg (")"))
+
+ if (nextarg (")"))
error (2, 0, "syntax error");
- else
- return str_value (*args++);
+
+ return str_value (*args++);
}
/* Handle match, substr, index, and length keywords. */
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const longopts[] =
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
#include "version.h"
#include "system.h"
+#ifdef NICE_PRIORITY
+#define GET_PRIORITY() nice (0)
+#else
+#define GET_PRIORITY() getpriority (PRIO_PROCESS, 0)
+#endif
+
void error ();
static int isinteger ();
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const longopts[] =
usage ();
/* No command given; print the priority. */
errno = 0;
-#ifndef NICE_PRIORITY
- current_priority = getpriority (PRIO_PROCESS, 0);
-#else
- current_priority = nice (0);
-#endif
+ current_priority = GET_PRIORITY ();
if (current_priority == -1 && errno != 0)
error (1, errno, "cannot get priority");
printf ("%d\n", current_priority);
exit (0);
}
- errno = 0;
#ifndef NICE_PRIORITY
- current_priority = getpriority (PRIO_PROCESS, 0);
-#else
- current_priority = nice (0);
-#endif
+ errno = 0;
+ current_priority = GET_PRIORITY ();
if (current_priority == -1 && errno != 0)
error (1, errno, "cannot get priority");
-
-#ifndef NICE_PRIORITY
if (setpriority (PRIO_PROCESS, 0, current_priority + adjustment))
#else
if (nice (adjustment) == -1)
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
+#include "version.h"
#include "system.h"
#ifdef _POSIX_VERSION
/* 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 longopts[] =
{
+ {"help", no_argument, &show_help, 1},
{"portability", no_argument, NULL, 'p'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (optc)
{
+ case 0:
+ break;
+
case 'p':
check_portability = 1;
break;
+
default:
usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind == argc)
usage ();
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
+#include <getopt.h>
+
#include "system.h"
+#include "version.h"
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
char *xmalloc ();
void error ();
+void parse_long_options ();
static double xstrtod ();
static int print_esc ();
static void print_esc_string ();
static void verify ();
+/* The value to return to the calling program. */
+static int exit_status;
+
/* The name this program was run with. */
char *program_name;
-/* The value to return to the calling program. */
-static int exit_status;
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] format [argument...]\n",
+ program_name);
+ exit (1);
+}
void
main (argc, argv)
program_name = argv[0];
exit_status = 0;
+ parse_long_options (argc, argv, usage);
+
if (argc == 1)
{
fprintf (stderr, "Usage: %s format [argument...]\n", program_name);
#include <stdio.h>
#include <sys/types.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
void error ();
/* The name by which this program was run. */
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 ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] number[smhd]...\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
{
int i;
unsigned seconds = 0;
+ int c;
program_name = argv[0];
+ while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
+ {
+ switch (c)
+ {
+ case 0:
+ break;
+
+ default:
+ usage ();
+ }
+ }
+
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (argc == 1)
{
fprintf (stderr, "Usage: %s number[smhd]...\n", argv[0]);
#include <varargs.h>
#define VA_START(args, lastarg) va_start(args)
#endif
+
#include "system.h"
+#include "version.h"
#if defined(GWINSZ_BROKEN) /* Such as for SCO UNIX 3.2.2. */
#undef TIOCGWINSZ
/* Current position, to know when to wrap. */
static int current_col;
+/* 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 longopts[] =
{
{"all", no_argument, NULL, 'a'},
+ {"help", no_argument, &show_help, 1},
{"save", no_argument, NULL, 'g'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
current_col += buflen;
}
+static void
+usage ()
+{
+ fprintf (stderr,
+ "Usage: %s [{--help,--version}] [-ag] [--all] [--save] [setting...]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
while ((optc = getopt_long (argc, argv, "ag", longopts, (int *) 0)) != EOF)
{
- if (optc == 'a')
- output_type = all;
- else if (optc == 'g')
- output_type = recoverable;
- else
- break;
+ switch (optc)
+ {
+ case 0:
+ break;
+
+ case 'a':
+ output_type = all;
+ break;
+
+ case 'g':
+ output_type = recoverable;
+ break;
+
+ default:
+ goto done;
+ }
+ }
+
+done:;
+
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
}
+ if (show_help)
+ usage ();
+
if (tcgetattr (0, &mode))
error (1, errno, "standard input");
case combination:
return NULL;
+
+ default:
+ abort ();
}
}
#include <getopt.h>
#include <sys/types.h>
#include <pwd.h>
+#include <grp.h>
#include "system.h"
#ifdef HAVE_SYSLOG_H
#include <shadow.h>
#endif
+#include "version.h"
+
/* The default PATH for simulated logins to non-superuser accounts. */
#define DEFAULT_LOGIN_PATH ":/usr/ucb:/bin:/usr/bin"
/* 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;
+
/* If nonzero, pass the `-f' option to the subshell. */
static int fast_startup;
{
{"command", required_argument, 0, 'c'},
{"fast", no_argument, &fast_startup, 1},
+ {"help", no_argument, &show_help, 1},
{"login", no_argument, &simulate_login, 1},
{"preserve-environment", no_argument, &change_environment, 0},
{"shell", required_argument, 0, 's'},
+ {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
{
case 0:
break;
+
case 'c':
command = optarg;
break;
+
case 'f':
fast_startup = 1;
break;
+
case 'l':
simulate_login = 1;
break;
+
case 'm':
case 'p':
change_environment = 0;
break;
+
case 's':
shell = optarg;
break;
+
default:
usage ();
}
}
+
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind < argc && !strcmp (argv[optind], "-"))
{
simulate_login = 1;
#include <sys/types.h>
#include <signal.h>
#include <getopt.h>
+
#include "system.h"
+#include "version.h"
char *xmalloc ();
void error ();
/* The name that 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[] =
{
{"append", no_argument, NULL, 'a'},
+ {"help", no_argument, &show_help, 1},
{"ignore-interrupts", no_argument, NULL, 'i'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
+static void
+usage ()
+{
+ fprintf (stderr, "\
+Usage: %s [{--help,--version}] [-ai] [--append]\n\
+ [--ignore-interrupts] [file...]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
{
switch (optc)
{
+ case 0:
+ break;
+
case 'a':
append = 1;
break;
+
case 'i':
ignore_interrupts = 1;
break;
+
default:
- fprintf (stderr, "\
-Usage: %s [-ai] [--append] [--ignore-interrupts] [file...]\n",
- program_name);
- exit (1);
+ usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (ignore_interrupts)
{
#ifdef _POSIX_VERSION
return (value);
}
+#if defined (TEST_STANDALONE)
+void parse_long_options ();
+
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] [expr]\n",
+ program_name);
+ exit (1);
+}
+#endif /* TEST_STANDALONE */
+
/*
* [:
* '[' expr ']'
if (margv[0] && strcmp (margv[0], "[") == 0)
{
+ parse_long_options (margc, margv, usage);
+
--margc;
if (margc < 2)
if (pos >= argc)
test_exit (SHELL_BOOLEAN (FALSE));
+ parse_long_options (argc, argv, usage);
value = posixtest ();
if (pos != argc)
/* Displays "not a tty" if stdin is not a terminal.
Displays nothing if -s option is given.
- Exit status 0 if stdin is a tty, 1 if not, 2 if usage error.
+ Exit status 0 if stdin is a tty, 1 if not, 2 if usage error,
+ 3 if write error.
- Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+ Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
#include "system.h"
+#include "version.h"
+
+void error ();
static void usage ();
/* If nonzero, return an exit status but produce no output. */
static int silent;
+/* 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 longopts[] =
{
+ {"help", no_argument, &show_help, 1},
{"silent", no_argument, NULL, 's'},
{"quiet", no_argument, NULL, 's'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (optc)
{
+ case 0:
+ break;
+
case 's':
silent = 1;
break;
+
default:
usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind != argc)
usage ();
puts (tty);
else
puts ("not a tty");
+
+ if (ferror (stdout) || fclose (stdout) == EOF)
+ error (3, errno, "standard output");
}
- exit (tty == NULL);
+ exit (isatty (0) ? 0 : 1);
}
static void
#include <sys/types.h>
#include <sys/utsname.h>
#include <getopt.h>
+
#include "system.h"
+#include "version.h"
void error ();
/* The name this program was run with, for error messages. */
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[] =
{
- {"sysname", no_argument, NULL, 's'},
+ {"help", no_argument, &show_help, 1},
+ {"machine", no_argument, NULL, 'm'},
{"nodename", no_argument, NULL, 'n'},
{"release", no_argument, NULL, 'r'},
- {"version", no_argument, NULL, 'v'},
- {"machine", no_argument, NULL, 'm'},
+ {"sysname", no_argument, NULL, 's'},
+ {"version", no_argument, &show_version, 1},
{"all", no_argument, NULL, 'a'},
{NULL, 0, NULL, 0}
};
{
switch (c)
{
+ case 0:
+ break;
+
case 's':
toprint |= PRINT_SYSNAME;
break;
+
case 'n':
toprint |= PRINT_NODENAME;
break;
+
case 'r':
toprint |= PRINT_RELEASE;
break;
+
case 'v':
toprint |= PRINT_VERSION;
break;
+
case 'm':
toprint |= PRINT_MACHINE;
break;
+
case 'a':
toprint = PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
PRINT_VERSION | PRINT_MACHINE;
break;
+
default:
usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind != argc)
usage ();
#ifndef _POSIX_SOURCE
#include <sys/param.h>
#endif
+
#include "system.h"
+#include "version.h"
#ifndef UTMP_FILE
#ifdef _PATH_UTMP /* 4.4BSD. */
/* 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;
+
/* If nonzero, display only a list of usernames and count of
the users logged on.
Ignored for `who am i'. */
static struct option const longopts[] =
{
{"count", no_argument, NULL, 'q'},
+ {"help", no_argument, &show_help, 1},
{"idle", no_argument, NULL, 'u'},
{"heading", no_argument, NULL, 'H'},
{"message", no_argument, NULL, 'T'},
{"mesg", no_argument, NULL, 'T'},
+ {"version", no_argument, &show_version, 1},
{"writable", no_argument, NULL, 'T'},
{NULL, 0, NULL, 0}
};
{
switch (optc)
{
+ case 0:
+ break;
+
case 'm':
my_line_only = 1;
break;
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (chdir ("/dev"))
error (1, errno, "cannot change directory to /dev");