summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/getdate.y117
-rw-r--r--lib/putenv.c21
-rw-r--r--lib/strftime.c4
-rw-r--r--old/sh-utils/ChangeLog71
-rw-r--r--src/basename.c60
-rw-r--r--src/date.c27
-rw-r--r--src/dirname.c56
-rw-r--r--src/echo.c15
-rw-r--r--src/env.c26
-rw-r--r--src/expr.c53
-rw-r--r--src/id.c35
-rw-r--r--src/logname.c56
-rw-r--r--src/nice.c24
-rw-r--r--src/printf.c1
-rw-r--r--src/stty.c4
-rw-r--r--src/su.c4
-rw-r--r--src/test.c35
-rw-r--r--src/tty.c2
-rw-r--r--src/uname.c2
19 files changed, 485 insertions, 128 deletions
diff --git a/lib/getdate.y b/lib/getdate.y
index 4d2af5c5e..cdc2b5565 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -1,6 +1,5 @@
%{
-/* $Revision: 1.2 $
-**
+/*
** Originally written by Steven M. Bellovin <smb@research.att.com> while
** at the University of North Carolina at Chapel Hill. Later tweaked by
** a couple of people on Usenet. Completely overhauled by Rich $alz
@@ -18,7 +17,18 @@
#include "config.h"
#endif
+/* Since the code of getdate.y is not included in the Emacs executable
+ itself, there is no need to #define static in this file. Even if
+ the code were included in the Emacs executable, it probably
+ wouldn't do any harm to #undef it here; this will only cause
+ problems if we try to write to a static variable, which I don't
+ think this code needs to do. */
+#ifdef emacs
+#undef static
+#endif
+
#ifdef __GNUC__
+#undef alloca
#define alloca __builtin_alloca
#else
#ifdef HAVE_ALLOCA_H
@@ -49,33 +59,36 @@ char *alloca ();
#include <sys/types.h>
-#if sgi
-#undef timezone
-#endif
-
-#if !(defined (USG) || defined (sgi) || defined (__386BSD__)) || defined(BSD4_2) || defined(BSD4_1C) || (defined (hp9000) && !defined (hpux)) || defined(_AIX)
+#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
+#endif
-#if defined(USG) || !defined(HAVE_FTIME)
+#ifdef timezone
+#undef timezone /* needed for sgi */
+#endif
+
+#if defined(HAVE_SYS_TIMEB_H) || (!defined(USG) && defined(HAVE_FTIME))
+#include <sys/timeb.h>
+#else
/*
-** If you need to do a tzset() call to set the
-** timezone, and don't have ftime().
+** We use the obsolete `struct timeb' as part of our interface!
+** Since the system doesn't have it, we define it here;
+** our callers must do likewise.
*/
struct timeb {
time_t time; /* Seconds since the epoch */
unsigned short millitm; /* Field not used */
- short timezone;
+ short timezone; /* Minutes west of GMT */
short dstflag; /* Field not used */
};
-
-#else
-
-#include <sys/timeb.h>
-
-#endif /* defined(USG) && !defined(HAVE_FTIME) */
+#endif /* defined(HAVE_SYS_TIMEB_H) */
#endif /* defined(vms) */
@@ -83,6 +96,14 @@ struct timeb {
#include <string.h>
#endif
+/* Some old versions of bison generate parsers that use bcopy.
+ That loses on systems that don't provide the function, so we have
+ to redefine it here. */
+#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
+#define bcopy(from, to, len) memcpy ((to), (from), (len))
+#endif
+
+extern struct tm *gmtime();
extern struct tm *localtime();
#define yyparse getdate_yyparse
@@ -94,7 +115,7 @@ static int yyerror ();
#if !defined(lint) && !defined(SABER)
static char RCS[] =
- "$Header: /w/src/cvsroot/fileutils/lib/getdate.y,v 1.2 1993/04/04 15:21:49 meyering Exp $";
+ "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
#endif /* !defined(lint) && !defined(SABER) */
@@ -847,12 +868,38 @@ yylex()
}
+#define TM_YEAR_ORIGIN 1900
+
+/* Yield A - B, measured in seconds. */
+static time_t
+difftm(a, b)
+ struct tm *a, *b;
+{
+ int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
+ int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
+ return
+ (
+ (
+ (
+ /* difference in day of year */
+ a->tm_yday - b->tm_yday
+ /* + intervening leap days */
+ + ((ay >> 2) - (by >> 2))
+ - (ay/100 - by/100)
+ + ((ay/100 >> 2) - (by/100 >> 2))
+ /* + difference in years * 365 */
+ + (time_t)(ay-by) * 365
+ )*24 + (a->tm_hour - b->tm_hour)
+ )*60 + (a->tm_min - b->tm_min)
+ )*60 + (a->tm_sec - b->tm_sec);
+}
+
time_t
get_date(p, now)
char *p;
struct timeb *now;
{
- struct tm *tm;
+ struct tm *tm, gmt;
struct timeb ftz;
time_t Start;
time_t tod;
@@ -860,34 +907,12 @@ get_date(p, now)
yyInput = p;
if (now == NULL) {
now = &ftz;
-#if !defined(HAVE_FTIME)
(void)time(&ftz.time);
- /* Set the timezone global. */
- tzset();
- {
-#if sgi
- ftz.timezone = (int) _timezone / 60;
-#else /* not sgi */
-#ifdef __386BSD__
- ftz.timezone = 0;
-#else /* neither sgi nor 386BSD */
-#if defined (USG)
- extern time_t timezone;
-
- ftz.timezone = (int) timezone / 60;
-#else /* neither sgi nor 386BSD nor USG */
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday (&tv, &tz);
- ftz.timezone = (int) tz.tz_minuteswest;
-#endif /* neither sgi nor 386BSD nor USG */
-#endif /* neither sgi nor 386BSD */
-#endif /* not sgi */
- }
-#else /* HAVE_FTIME */
- (void)ftime(&ftz);
-#endif /* HAVE_FTIME */
+
+ if (! (tm = gmtime (&ftz.time)))
+ return -1;
+ gmt = *tm; /* Make a copy, in case localtime modifies *tm. */
+ ftz.timezone = difftm (&gmt, localtime (&ftz.time)) / 60;
}
tm = localtime(&now->time);
diff --git a/lib/putenv.c b/lib/putenv.c
index d1fb726f3..c39d1b71e 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -18,13 +18,20 @@ Cambridge, MA 02139, USA. */
#include <sys/types.h>
#include <errno.h>
-#ifdef STDC_HEADERS
+
+/* This needs to come after some library #include
+ to get __GNU_LIBRARY__ defined. */
+#ifdef __GNU_LIBRARY__
+/* Don't include stdlib.h for non-GNU C libraries because some of them
+ contain conflicting prototypes for getopt. */
#include <stdlib.h>
-#else
+#endif /* GNU C library. */
+
+#ifndef STDC_HEADERS
extern int errno;
#endif
-#if defined(STDC_HEADERS) || defined(USG)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#ifndef index
#define index strchr
@@ -32,9 +39,9 @@ extern int errno;
#ifndef bcopy
#define bcopy(s, d, n) memcpy((d), (s), (n))
#endif
-#else /* not (STDC_HEADERS or USG) */
+#else
#include <strings.h>
-#endif /* STDC_HEADERS or USG */
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -44,10 +51,6 @@ extern int errno;
#define NULL 0
#endif
-#if !__STDC__
-#define const
-#endif
-
extern char **environ;
/* Put STRING, which is of the form "NAME=VALUE", in the environment. */
diff --git a/lib/strftime.c b/lib/strftime.c
index b6695342a..a07571750 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -84,10 +84,6 @@
extern char *tzname[2];
#endif
-#if !__STDC__
-#define const
-#endif
-
/* Types of padding for numbers in date and time. */
enum padding
{
diff --git a/old/sh-utils/ChangeLog b/old/sh-utils/ChangeLog
index 8b830d654..a2d3629fb 100644
--- a/old/sh-utils/ChangeLog
+++ b/old/sh-utils/ChangeLog
@@ -1,3 +1,64 @@
+Wed Sep 08 00:07:36 1993 Jim Meyering (meyering@comco.com)
+
+ * test.c [advance, unary_advance]: Rewrite using do{...}while(0)
+ paradigm instead of comma expressions that make Alpha OSFv1.3
+ C compiler segfault.
+
+Sat Jul 24 08:52:18 1993 Jim Meyering (meyering@comco.com)
+
+ * configure.in: Check for -lshadow. Linux needs it when using shadow
+ passwords. Reported by Mattias Olofsson <mattias@lysator.liu.se>.
+
+Thu May 27 20:05:50 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu)
+
+ * configure.in (c_line test): Add missing `fi'.
+
+Tue May 18 23:49:26 1993 Jim Meyering (meyering@comco.com)
+
+ * mkinstalldirs: New file.
+ * Makefile.in (installdirs): Use it.
+
+Thu May 13 01:03:16 1993 Jim Meyering (meyering@comco.com)
+
+ * Makefile.in (installdirs): New rules for creating installation
+ directories. (install): depend on it.
+
+Mon May 3 22:09:24 1993 Jim Meyering (meyering@comco.com)
+
+ * configure.in: Add AC_GETGROUPS_T.
+ * id.c, test.c: Don't define GETGROUPS_T. Now configure does it.
+
+Sun May 2 00:21:05 1993 Jim Meyering (meyering@comco.com)
+
+ * expr.c (eval6): Terminate result with a zero byte.
+ The command `expr substr xx 1 2' would fail on systems with
+ tight malloc. From Steve James <smj@cats.COM>.
+
+ * expr.c (null): Recognize the string `0' as zero.
+ (divide, mod): Upon request to divide by zero, give an error
+ message instead of dumping core.
+ From J.T. Conklin <jtc@wimsey.com>.
+
+ * configure.in: Check for sys/time.h; getdate.y needs it for
+ structs timeval and timezone on some systems.
+ * Check for gettimeofday and for `struct tm'.
+ * Add existence tests for memcpy and bcopy.
+
+ * configure.in: Find a parser generator.
+
+ * putenv.c: Include stdlib.h only if __GNU_LIBRARY__ is defined.
+ Many vendor-supplied <stdlib.h> have a declaration of putenv that
+ conflicts with ours.
+
+Tue Apr 20 02:33:24 1993 David J. MacKenzie (djm@kropotkin.gnu.ai.mit.edu)
+
+ * stty.c: Use GWINSZ_IN_SYS_IOCTL, not _AIX, to determine
+ whether sys/ioctl.h is needed to support `stty size'.
+
+Thu Apr 1 18:03:47 1993 Jim Meyering (meyering@comco.com)
+
+ * printf.c, expr.c [isascii]: Undefine before redefining.
+
Sun Mar 28 00:07:45 1993 Jim Meyering (meyering@comco.com)
* stty.c: Accept `flush' option. From Arne H. Juul arnej@lise.unit.no
@@ -17,7 +78,7 @@ Sun Dec 6 23:17:09 1992 Jim Meyering (meyering@comco.com)
* date.c: Remove unused definition of isdigit.
* expr.c (toarith): Change single use of isdigit to ISDIGIT.
- * printf.c (print_formatted, print_esc): Define ISXDIGIT and
+ * printf.c (print_formatted, print_esc): Define ISDIGIT and
ISXDIGIT and use them instead of isdigit and isxdigit.
Wed Dec 2 12:49:11 1992 Jim Meyering (meyering@comco.com)
@@ -27,12 +88,20 @@ Wed Dec 2 12:49:11 1992 Jim Meyering (meyering@comco.com)
to use new macros from getopt.h: no_argument, required_argument,
and optional_argument.
+Tue Nov 24 09:46:02 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * echo.c: Use V9_DEFAULT instead of USG. Define it always.
+
+ * system.h: Use HAVE_FCNTL_H and HAVE_STRING_H instead of USG.
+
Wed Nov 11 18:19:10 1992 Jim Meyering (meyering@hal.gnu.ai.mit.edu)
* All files in src: Make all functions and extern variables static.
Make all longopts arrays const as well as static.
Make a couple statically initialized aggregates `const.'
+ * pathchk.c (portable_chars_only): Cast char used as array index.
+
* echo.c (main), su.c (restricted_shell): Add parentheses to
assignment statements used in boolean context.
diff --git a/src/basename.c b/src/basename.c
index f8d9e17f6..01e3d4375 100644
--- a/src/basename.c
+++ b/src/basename.c
@@ -27,6 +27,9 @@
#include <stdio.h>
#include <sys/types.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
char *basename ();
@@ -34,25 +37,70 @@ void strip_trailing_slashes ();
static void remove_suffix ();
+/* 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 error. */
+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}] name [suffix]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
char **argv;
{
char *name;
+ 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 (argc == 1 || argc > 3)
+ if (show_version)
{
- fprintf (stderr, "Usage: %s name [suffix]\n", argv[0]);
- exit (1);
+ printf ("%s\n", version_string);
+ exit (0);
}
- strip_trailing_slashes (argv[1]);
+ if (show_help)
+ usage ();
+
+ if (argc - optind == 0 || argc - optind > 2)
+ usage ();
+
+ strip_trailing_slashes (argv[optind]);
- name = basename (argv[1]);
+ name = basename (argv[optind]);
if (argc == 3)
- remove_suffix (name, argv[2]);
+ remove_suffix (name, argv[optind + 1]);
puts (name);
diff --git a/src/date.c b/src/date.c
index 0806c6713..e97ef43d7 100644
--- a/src/date.c
+++ b/src/date.c
@@ -42,6 +42,8 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
+#include "version.h"
#include "system.h"
#ifdef TM_IN_SYS_TIME
@@ -80,12 +82,20 @@ static void usage ();
/* 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 error. */
+static int show_version;
+
static struct option const long_options[] =
{
{"date", required_argument, NULL, 'd'},
+ {"help", no_argument, &show_help, 1},
{"set", required_argument, NULL, 's'},
- {"universal", no_argument, NULL, 'u'},
{"uct", no_argument, NULL, 'u'},
+ {"universal", no_argument, NULL, 'u'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -106,6 +116,8 @@ main (argc, argv)
!= EOF)
switch (optc)
{
+ case 0:
+ break;
case 'd':
datestr = optarg;
break;
@@ -120,6 +132,15 @@ main (argc, argv)
usage ();
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (argc - optind > 1)
usage ();
@@ -192,7 +213,9 @@ static void
usage ()
{
fprintf (stderr, "\
-Usage: %s [-u] [-d datestr] [-s datestr] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]\n",
+Usage: %s [{--help,--version}] [-u] [-d datestr] [-s datestr]\n\
+ [--date datestr] [--set datestr] [--uct] [--universal]\n\
+ [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]\n",
program_name);
exit (1);
}
diff --git a/src/dirname.c b/src/dirname.c
index 05612353a..d6227db2f 100644
--- a/src/dirname.c
+++ b/src/dirname.c
@@ -19,10 +19,36 @@
#include <stdio.h>
#include <sys/types.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
void strip_trailing_slashes ();
+/* 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 error. */
+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}] path\n", program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
@@ -30,14 +56,35 @@ main (argc, argv)
{
register char *path;
register char *slash;
+ int c;
- if (argc != 2)
+ 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)
{
- fprintf (stderr, "Usage: %s path\n", argv[0]);
- exit (1);
+ printf ("%s\n", version_string);
+ exit (0);
}
- path = argv[1];
+ if (show_help)
+ usage ();
+
+ if (argc - optind != 1)
+ usage ();
+
+ path = argv[optind];
strip_trailing_slashes (path);
slash = rindex (path, '/');
@@ -54,4 +101,3 @@ main (argc, argv)
exit (0);
}
-
diff --git a/src/echo.c b/src/echo.c
index b8c4e58d1..b7ca351e0 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -40,14 +40,19 @@ You can explicitly turn off the interpretation of the above characters
on System V systems with the -E option.
*/
+/* If defined, interpret backslash escapes if -e is given. */
#define V9_ECHO
+/* If defined, interpret backslash escapes unless -E is given.
+ V9_ECHO must also be defined. */
+#define V9_DEFAULT
+
#if defined (V9_ECHO)
-# if defined (USG)
+# if defined (V9_DEFAULT)
# define VALID_ECHO_OPTIONS "neE"
# else
# define VALID_ECHO_OPTIONS "ne"
-# endif /* !USG */
+# endif /* !V9_DEFAULT */
#else /* !V9_ECHO */
# define VALID_ECHO_OPTIONS "n"
#endif /* !V9_ECHO */
@@ -65,7 +70,7 @@ main (argc, argv)
/* 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 defined (V9_ECHO) && defined (USG)
+#if defined (V9_ECHO) && defined (V9_DEFAULT)
do_v9 = 1;
#endif
@@ -100,10 +105,10 @@ main (argc, argv)
#if defined (V9_ECHO)
else if (*temp == 'e')
do_v9 = 1;
-#if defined (USG)
+#if defined (V9_DEFAULT)
else if (*temp == 'E')
do_v9 = 0;
-#endif /* USG */
+#endif /* V9_DEFAULT */
#endif /* V9_ECHO */
else
goto just_echo;
diff --git a/src/env.c b/src/env.c
index f80285604..283e88ad4 100644
--- a/src/env.c
+++ b/src/env.c
@@ -80,6 +80,9 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
int putenv ();
@@ -92,10 +95,18 @@ extern char **environ;
/* 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 error. */
+static int show_version;
+
static struct option const longopts[] =
{
+ {"help", no_argument, &show_help, 1},
{"ignore-environment", no_argument, NULL, 'i'},
{"unset", required_argument, NULL, 'u'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -115,6 +126,8 @@ main (argc, argv, envp)
{
switch (optc)
{
+ case 0:
+ break;
case 'i':
ignore_environment = 1;
break;
@@ -125,6 +138,15 @@ main (argc, argv, envp)
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind != argc && !strcmp (argv[optind], "-"))
ignore_environment = 1;
@@ -162,8 +184,8 @@ static void
usage ()
{
fprintf (stderr, "\
-Usage: %s [-] [-i] [-u name] [--ignore-environment] [--unset=name]\n\
- [name=value]... [command [args...]]\n",
+Usage: %s [{--help,--version}] [-] [-i] [-u name] [--ignore-environment]\n\
+ [--unset=name] [name=value]... [command [args...]]\n",
program_name);
exit (2);
}
diff --git a/src/expr.c b/src/expr.c
index 4a1f22c5b..c4fbc2161 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -32,9 +32,12 @@
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>
+
#include "system.h"
+#include "version.h"
#if !defined (isascii) || defined (STDC_HEADERS)
+#undef isascii
#define isascii(c) 1
#endif
@@ -95,6 +98,14 @@ static void tostring ();
static void trace ();
#endif
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] expression...\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
@@ -104,11 +115,21 @@ main (argc, argv)
program_name = argv[0];
- if (argc == 1)
+ if (argc > 1)
{
- fprintf (stderr, "Usage: %s expression...\n", argv[0]);
- exit (1);
+ if (strcmp (argv[1], "--version") == 0)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+ else if (strcmp (argv[1], "--help") == 0)
+ {
+ usage ();
+ }
}
+
+ if (argc == 1)
+ usage ();
args = argv + 1;
v = eval ();
@@ -172,6 +193,8 @@ printv (v)
case string:
printf ("%s\n", v->u.s);
break;
+ default:
+ abort ();
}
}
@@ -186,7 +209,9 @@ null (v)
case integer:
return v->u.i == 0;
case string:
- return v->u.s[0] == '\0';
+ return v->u.s[0] == '\0' || strcmp(v->u.s, "0") == 0;
+ default:
+ abort ();
}
}
@@ -217,6 +242,8 @@ tostring (v)
break;
case string:
break;
+ default:
+ abort ();
}
}
@@ -251,6 +278,8 @@ toarith (v)
v->u.i = i * (neg ? -1 : 1);
v->type = integer;
return 1;
+ default:
+ abort ();
}
}
@@ -309,13 +338,24 @@ int name (l, r) VALUE *l; VALUE *r; \
return l->u.i op r->u.i; \
}
+#define arithdivf(name, op) \
+int name (l, r) VALUE *l; VALUE *r; \
+{ \
+ if (!toarith (l) || !toarith (r)) \
+ error (2, 0, "non-numeric argument"); \
+ if (r->u.i == 0) \
+ error (2, 0, "division by zero"); \
+ return l->u.i op r->u.i; \
+}
+
arithf (plus, +)
arithf (minus, -)
arithf (multiply, *)
-arithf (divide, /)
-arithf (mod, %)
+arithdivf (divide, /)
+arithdivf (mod, %)
#undef arithf
+#undef arithdivf
#ifdef EVAL_TRACE
/* Print evaluation trace and args remaining. */
@@ -474,6 +514,7 @@ eval6 ()
v->type = string;
v->u.s = strncpy ((char *) xmalloc (i2->u.i + 1),
l->u.s + i1->u.i - 1, i2->u.i);
+ v->u.s[i2->u.i] = 0;
}
freev (l);
freev (i1);
diff --git a/src/id.c b/src/id.c
index a6708fbe4..7d55d7105 100644
--- a/src/id.c
+++ b/src/id.c
@@ -23,6 +23,9 @@
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
#ifdef _POSIX_VERSION
@@ -31,16 +34,6 @@
#define NGROUPS_MAX sysconf (_SC_NGROUPS_MAX)
#endif /* !NGROUPS_MAX */
-/* Even though SunOS 4, Ultrix 4, and 386BSD are mostly POSIX.1 compliant,
- their getgroups system call (except in the `System V' environment, which
- is troublesome in other ways) fills in an array of int, not gid_t
- (which is `short' on those systems). Kludge, kludge. */
-
-#if !defined(sun) && !defined(ultrix) && !defined(__386BSD__)
-#define GETGROUPS_T gid_t
-#else /* sun or ultrix or 386BSD */
-#define GETGROUPS_T int
-#endif /* sun or ultrix or 386BSD */
#else /* not _POSIX_VERSION */
struct passwd *getpwuid ();
struct group *getgrgid ();
@@ -52,7 +45,6 @@ gid_t getegid ();
#if !defined(NGROUPS_MAX) && defined(NGROUPS)
#define NGROUPS_MAX NGROUPS
#endif /* not NGROUPS_MAX and NGROUPS */
-#define GETGROUPS_T int
#endif /* not _POSIX_VERSION */
char *xmalloc ();
@@ -90,13 +82,21 @@ static gid_t rgid, egid;
/* The number of errors encountered so far. */
static int problems = 0;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, print the version on standard error. */
+static int show_version;
+
static struct option const longopts[] =
{
{"group", no_argument, NULL, 'g'},
+ {"groups", no_argument, NULL, 'G'},
+ {"help", no_argument, &show_help, 1},
{"name", no_argument, NULL, 'n'},
{"real", no_argument, NULL, 'r'},
{"user", no_argument, NULL, 'u'},
- {"groups", no_argument, NULL, 'G'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -114,6 +114,8 @@ main (argc, argv)
{
switch (optc)
{
+ case 0:
+ break;
case 'g':
just_group = 1;
break;
@@ -134,6 +136,15 @@ main (argc, argv)
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (just_user + just_group + just_group_list > 1)
error (1, 0, "cannot print only user and only group");
diff --git a/src/logname.c b/src/logname.c
index 39d213709..19fea40cb 100644
--- a/src/logname.c
+++ b/src/logname.c
@@ -17,27 +17,77 @@
#include <stdio.h>
#include <sys/types.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 error. */
+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}]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
char **argv;
{
register char *cp;
+ int c;
+
+ program_name = argv[0];
- if (argc != 1)
+ while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
{
- fprintf (stderr, "Usage: %s\n", argv[0]);
- exit (1);
+ switch (c)
+ {
+ case 0:
+ break;
+
+ default:
+ usage ();
+ }
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
+ if (argc - optind != 0)
+ usage ();
+
+ /* POSIX.2 requires using getlogin (or equivalent code). */
cp = getlogin ();
if (cp)
{
puts (cp);
exit (0);
}
+ /* POSIX.2 prohibits using a fallback technique. */
fprintf (stderr,"%s: no login name\n", argv[0]);
exit (1);
}
diff --git a/src/nice.c b/src/nice.c
index 6386e519a..51218d8e7 100644
--- a/src/nice.c
+++ b/src/nice.c
@@ -15,7 +15,7 @@
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> */
#include <stdio.h>
#include <getopt.h>
@@ -24,6 +24,8 @@
#include <sys/time.h>
#include <sys/resource.h>
#endif
+
+#include "version.h"
#include "system.h"
void error ();
@@ -34,9 +36,17 @@ static void usage ();
/* 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 error. */
+static int show_version;
+
static struct option const longopts[] =
{
{"adjustment", required_argument, NULL, 'n'},
+ {"help", no_argument, &show_help, 1},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -60,6 +70,9 @@ main (argc, argv)
{
case '?':
usage ();
+
+ case 0:
+ break;
case 'n':
if (!isinteger (optarg))
@@ -78,6 +91,15 @@ main (argc, argv)
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (minusflag)
adjustment = -adjustment;
if (!adjustment_given)
diff --git a/src/printf.c b/src/printf.c
index 99ed49397..0c0da37fe 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -49,6 +49,7 @@
#include "system.h"
#if !defined (isascii) || defined (STDC_HEADERS)
+#undef isascii
#define isascii(c) 1
#endif
diff --git a/src/stty.c b/src/stty.c
index b9daf0a12..1e0a59a3e 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -30,8 +30,8 @@
#include <stdio.h>
#include <sys/types.h>
#include <termios.h>
-#ifdef _AIX
-#include <sys/ioctl.h> /* Needed to get window size. */
+#ifdef GWINSZ_IN_SYS_IOCTL
+#include <sys/ioctl.h>
#endif
#ifdef WINSIZE_IN_PTEM
#include <sys/stream.h>
diff --git a/src/su.c b/src/su.c
index ff2bfe5fc..c94db90f0 100644
--- a/src/su.c
+++ b/src/su.c
@@ -78,7 +78,7 @@
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
static void log_su ();
-#else
+#else /* !HAVE_SYSLOG_H */
#ifdef SYSLOG_SUCCESS
#undef SYSLOG_SUCCESS
#endif
@@ -88,7 +88,7 @@ static void log_su ();
#ifdef SYSLOG_NON_ROOT
#undef SYSLOG_NON_ROOT
#endif
-#endif
+#endif /* !HAVE_SYSLOG_H */
#ifdef _POSIX_VERSION
#include <limits.h>
diff --git a/src/test.c b/src/test.c
index 0bc44e5dc..b2cb92d22 100644
--- a/src/test.c
+++ b/src/test.c
@@ -67,22 +67,6 @@ extern int errno;
# define member(c, s) (int)((c) ? index ((s), (c)) : 0)
#endif /* !member */
-#if defined (_POSIX_VERSION)
-
-/* Even though SunOS 4, Ultrix 4, and 386BSD are mostly POSIX.1 compliant,
- their getgroups system call (except in the `System V' environment, which
- is troublesome in other ways) fills in an array of int, not gid_t
- (which is `short' on those systems). Kludge, kludge. */
-
-#if !defined(sun) && !defined(ultrix) && !defined(__386BSD__)
-#define GETGROUPS_T gid_t
-#else
-#define GETGROUPS_T int
-#endif
-#else /* !_POSIX_VERSION */
-#define GETGROUPS_T int
-#endif /* !_POSIX_VERSION */
-
extern gid_t getgid (), getegid ();
extern uid_t geteuid ();
@@ -248,9 +232,14 @@ group_member (gid)
/* Increment our position in the argument list. Check that we're not
past the end of the argument list. This check is supressed if the
argument is FALSE. Made a macro for efficiency. */
-#if !defined (lint)
-#define advance(f) (++pos, f && (pos < argc ? 0 : beyond()))
-#endif
+#define advance(f) \
+ do \
+ { \
+ ++pos; \
+ if ((f) && pos >= argc) \
+ beyond (); \
+ } \
+ while (0)
#if !defined (advance)
static int
@@ -264,7 +253,13 @@ advance (f)
}
#endif /* advance */
-#define unary_advance() (advance (1),++pos)
+#define unary_advance() \
+ do \
+ { \
+ advance (1); \
+ ++pos; \
+ } \
+ while (0)
/*
* beyond - call when we're beyond the end of the argument list (an
diff --git a/src/tty.c b/src/tty.c
index 12ead35b0..79e1759e2 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -19,7 +19,7 @@
Displays nothing if -s option is given.
Exit status 0 if stdin is a tty, 1 if not, 2 if usage error.
- Written by David MacKenzie (djm@ai.mit.edu). */
+ Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <stdio.h>
#include <getopt.h>
diff --git a/src/uname.c b/src/uname.c
index 71d311207..c247aecdd 100644
--- a/src/uname.c
+++ b/src/uname.c
@@ -26,7 +26,7 @@
The default behavior is equivalent to `-s'.
- David MacKenzie <djm@ai.mit.edu> */
+ David MacKenzie <djm@gnu.ai.mit.edu> */
#include <stdio.h>
#include <sys/types.h>