merge with 1.8.1a
authorJim Meyering <jim@meyering.net>
Mon, 4 Oct 1993 21:20:37 +0000 (21:20 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 4 Oct 1993 21:20:37 +0000 (21:20 +0000)
lib/getdate.y
lib/getopt.c
lib/getopt1.c
lib/strftime.c
old/sh-utils/ChangeLog
src/echo.c
src/expr.c
src/pathchk.c
src/tee.c
src/who.c

index cdc2b55..ebfb7c9 100644 (file)
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
 #ifdef HAVE_CONFIG_H
+#if defined (emacs) || defined (CONFIG_BROKETS)
+#include <config.h>
+#else
 #include "config.h"
 #endif
+#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
@@ -115,7 +119,7 @@ static int yyerror ();
 
 #if    !defined(lint) && !defined(SABER)
 static char RCS[] =
-       "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
+       "$Header: /w/src/cvsroot/shellutils/lib/getdate.y,v 1.5 1993/09/08 18:23:16 meyering Exp $";
 #endif /* !defined(lint) && !defined(SABER) */
 
 
index 49db998..7a4673b 100644 (file)
    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 \f
 #ifdef HAVE_CONFIG_H
+#if defined (emacs) || 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 getopt.c was found in $srcdir).  */
+   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
+#else
+#include "config.h"
+#endif
 #endif
 
 #ifndef __STDC__
index 2b93f78..f784b57 100644 (file)
    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 \f
 #ifdef HAVE_CONFIG_H
+#if defined (emacs) || 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 getopt1.c was found in $srcdir).  */
+   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
+#else
+#include "config.h"
+#endif
 #endif
 
 #include "getopt.h"
index a075717..cfd41ad 100644 (file)
@@ -104,7 +104,13 @@ static char const * const months[] =
 /* Add character C to STRING and increment LENGTH,
    unless LENGTH would exceed MAX. */
 
-#define add_char(c) (length + 1 <= max) && (string[length++] = (c))
+#define add_char(c)                                                    \
+  do                                                                   \
+    {                                                                  \
+      if (length + 1 <= max)                                           \
+       string[length++] = (c);                                         \
+    }                                                                  \
+  while (0)
 
 /* Add a 2 digit number to STRING, padding if specified.
    Return the number of characters added, up to MAX. */
index a2d3629..f51c3b4 100644 (file)
@@ -1,9 +1,32 @@
+Mon Oct 04 22:15:07 1993  Jim Meyering (meyering@comco.com)
+
+       * who.c (print_entry, print_heading, who_am_i):
+       Cast printf field width arguments to int to avoid warnings.
+       (idle_string): Cast idle seconds and minutes to int.
+       Declare functions read_utmp and idle_string to be static.
+       Don't declare ttyname as static.
+
+       * echo.c (just_echo): Use putchar instead of printf.
+
+       * expr.c (parse_long_options): New function.
+       (main): Use it to handle --version and --help properly.
+
+       * tee.c (main): Put entire #ifdef inside if-braces to make structure
+       clearer.
+       (main, tee): Compare close() != 0 rather than close () == -1.
+
+       * pathchk.c (portable_chars_only, dir_ok): Make a couple variables
+       const.
+
 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.
 
+       * basename.c, date.c, dirname.c, env.c, id.c, logname.c, nice.c:
+       Add --help and --version options.
+
 Sat Jul 24 08:52:18 1993  Jim Meyering (meyering@comco.com)
 
        * configure.in: Check for -lshadow.  Linux needs it when using shadow
index b7ca351..ddf3b17 100644 (file)
@@ -179,6 +179,6 @@ just_echo:
        }
     }
   if (display_return)
-    printf ("\n");
+    putchar ('\n');
   exit (0);
 }
index c4fbc21..a9f3769 100644 (file)
@@ -32,6 +32,7 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <regex.h>
+#include <getopt.h>
 
 #include "system.h"
 #include "version.h"
@@ -98,6 +99,13 @@ static void tostring ();
 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 ()
 {
@@ -106,28 +114,50 @@ usage ()
   exit (1);
 }
 
-void
-main (argc, argv)
+/* Process long options that precede all other command line arguments.  */
+
+static void
+parse_long_options (argc, argv)
      int argc;
      char **argv;
 {
-  VALUE *v;
-
-  program_name = argv[0];
+  int c;
 
-  if (argc > 1)
+  while ((c = getopt_long (argc, argv, "+", long_options, (int *) 0)) != EOF)
     {
-      if (strcmp (argv[1], "--version") == 0)
-       {
+      switch (c)
+        {
+       case 'h':
+          usage ();
+
+       case 'v':
          printf ("%s\n", version_string);
          exit (0);
-       }
-      else if (strcmp (argv[1], "--help") == 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;
+     char **argv;
+{
+  VALUE *v;
+
+  program_name = argv[0];
+
+  parse_long_options (argc, argv);
+
   if (argc == 1)
     usage ();
   args = argv + 1;
index 6a0bf79..7302e38 100644 (file)
@@ -32,7 +32,7 @@
                        pathname and its components against the POSIX.1
                        minimum limits for portability, _POSIX_NAME_MAX
                        and _POSIX_PATH_MAX in 2.9.2.  Also check that
-                       the pathname contains no characters not in the
+                       the pathname contains no character not in the
                        portable filename character set.
 
    David MacKenzie <djm@gnu.ai.mit.edu>
@@ -87,7 +87,7 @@
 #define NAME_MAX_FOR(p) NAME_MAX
 #endif
 
-char *xstrdup();
+char *xstrdup ();
 void error ();
 
 static int validate_path ();
@@ -137,7 +137,7 @@ main (argc, argv)
 /* Each element is nonzero if the corresponding ASCII character is
    in the POSIX portable character set, and zero if it is not.
    In addition, the entry for `/' is nonzero to simplify checking. */
-static char const portable_chars[] =
+static char const portable_chars[256] =
 {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-15 */
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-31 */
@@ -161,12 +161,12 @@ static char const portable_chars[] =
 
 static int
 portable_chars_only (path)
-     char *path;
+     const char *path;
 {
-  char *p;
+  const char *p;
 
   for (p = path; *p; ++p)
-    if (portable_chars[(unsigned char)*p] == 0)
+    if (portable_chars[(const unsigned char) *p] == 0)
       {
        error (0, 0, "path `%s' contains nonportable character `%c'",
               path, *p);
@@ -180,7 +180,7 @@ portable_chars_only (path)
 
 static int
 dir_ok (path)
-     char *path;
+     const char *path;
 {
   struct stat stats;
 
index b97821c..941507f 100644 (file)
--- a/src/tee.c
+++ b/src/tee.c
@@ -77,23 +77,23 @@ Usage: %s [-ai] [--append] [--ignore-interrupts] [file...]\n",
     }
 
   if (ignore_interrupts)
-#ifdef _POSIX_VERSION
     {
+#ifdef _POSIX_VERSION
       struct sigaction sigact;
 
       sigact.sa_handler = SIG_IGN;
       sigemptyset (&sigact.sa_mask);
       sigact.sa_flags = 0;
       sigaction (SIGINT, &sigact, NULL);
-    }
 #else                          /* !_POSIX_VERSION */
-    signal (SIGINT, SIG_IGN);
+      signal (SIGINT, SIG_IGN);
 #endif                         /* _POSIX_VERSION */
+    }
 
   errs = tee (argc - optind, &argv[optind]);
-  if (close (0) == -1)
+  if (close (0) != 0)
     error (1, errno, "standard input");
-  if (close (1) == -1)
+  if (close (1) != 0)
     error (1, errno, "standard output");
   exit (errs);
 }
@@ -143,7 +143,7 @@ tee (nfiles, files)
     }
 
   for (i = 0; i < nfiles; i++)
-    if (descriptors[i] != -1 && close (descriptors[i]) == -1)
+    if (descriptors[i] != -1 && close (descriptors[i]) != 0)
       {
        error (0, errno, "%s", files[i]);
        ret = 1;
index 381a51f..1edec4e 100644 (file)
--- a/src/who.c
+++ b/src/who.c
 #define MESG_BIT 020           /* Group write bit. */
 
 
-char *idle_string ();
 char *xmalloc ();
 void error ();
+char *ttyname ();
 
-
-static char *ttyname ();
+static int read_utmp ();
+static char *idle_string ();
 static struct utmp *search_entries ();
 static void list_entries ();
 static void print_entry ();
@@ -222,7 +222,7 @@ read_utmp (filename)
   if (read (desc, utmp_contents, file_stats.st_size) < file_stats.st_size)
     error (1, errno, "%s", filename);
 
-  if (close (desc))
+  if (close (desc) != 0)
     error (1, errno, "%s", filename);
 
   return file_stats.st_size / sizeof (struct utmp);
@@ -253,12 +253,12 @@ print_entry (this)
     }
   
   printf ("%-*.*s",
-         sizeof (this->ut_name), sizeof (this->ut_name),
+         (int) sizeof (this->ut_name), (int) sizeof (this->ut_name),
          this->ut_name);
   if (include_mesg)
     printf ("  %c  ", mesg);
   printf (" %-*.*s",
-         sizeof (this->ut_line), sizeof (this->ut_line),
+         (int) sizeof (this->ut_line), (int) sizeof (this->ut_line),
          this->ut_line);
   printf (" %-12.12s", ctime (&this->ut_time) + 4);
   if (include_idle)
@@ -270,7 +270,7 @@ print_entry (this)
     }
 #ifdef HAVE_UT_HOST
   if (this->ut_host[0])
-    printf (" (%-.*s)", sizeof (this->ut_host), this->ut_host);
+    printf (" (%-.*s)", (int) sizeof (this->ut_host), this->ut_host);
 #endif
 
   putchar ('\n');
@@ -307,10 +307,10 @@ print_heading ()
 {
   struct utmp *ut;
 
-  printf ("%-*s ", sizeof (ut->ut_name), "USER");
+  printf ("%-*s ", (int) sizeof (ut->ut_name), "USER");
   if (include_mesg)
     printf ("MESG ");
-  printf ("%-*s ", sizeof (ut->ut_line), "LINE");
+  printf ("%-*s ", (int) sizeof (ut->ut_line), "LINE");
   printf ("LOGIN-TIME   ");
   if (include_idle)
     printf ("IDLE  ");
@@ -381,7 +381,7 @@ who_am_i (filename)
 
   if (include_heading)
     {
-      printf ("%*s ", strlen (hostname), " ");
+      printf ("%*s ", (int) strlen (hostname), " ");
       print_heading ();
     }
 
@@ -418,8 +418,8 @@ idle_string (when)
   if (seconds_idle < (24 * 60 * 60)) /* One day. */
     {
       sprintf (idle, "%02d:%02d",
-              seconds_idle / (60 * 60),
-              (seconds_idle % (60 * 60)) / 60);
+              (int) (seconds_idle / (60 * 60)),
+              (int) ((seconds_idle % (60 * 60)) / 60));
       return idle;
     }
   return " old ";