merge with 1.8.1a

This commit is contained in:
Jim Meyering 1993-10-04 21:20:37 +00:00
parent ae0074289c
commit 3134fad324
10 changed files with 113 additions and 42 deletions

View File

@ -14,8 +14,12 @@
/* 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) */

View File

@ -21,10 +21,14 @@
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#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__

View File

@ -17,10 +17,14 @@
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#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"

View 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. */

View 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

View File

@ -179,6 +179,6 @@ just_echo:
}
}
if (display_return)
printf ("\n");
putchar ('\n');
exit (0);
}

View 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,6 +114,39 @@ 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;
@ -115,18 +156,7 @@ main (argc, argv)
program_name = argv[0];
if (argc > 1)
{
if (strcmp (argv[1], "--version") == 0)
{
printf ("%s\n", version_string);
exit (0);
}
else if (strcmp (argv[1], "--help") == 0)
{
usage ();
}
}
parse_long_options (argc, argv);
if (argc == 1)
usage ();

View 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;

View File

@ -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;

View File

@ -57,12 +57,12 @@
#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 ";