Compare commits

...

118 Commits

Author SHA1 Message Date
Jim Meyering
f2080b7714 merge with 3.8.3b 1993-10-06 16:44:26 +00:00
Jim Meyering
19cd821ddb merge with 3.8.3a 1993-10-06 00:24:55 +00:00
Jim Meyering
061697058c merge with 3.8.3a 1993-10-06 00:24:18 +00:00
Jim Meyering
712109716a merge with 1.8a 1993-10-05 18:29:39 +00:00
Jim Meyering
3b5543d431 merge with 1.8a 1993-10-05 18:29:05 +00:00
Jim Meyering
5bf316d15e . 1993-10-04 21:22:19 +00:00
Jim Meyering
3134fad324 merge with 1.8.1a 1993-10-04 21:20:37 +00:00
Jim Meyering
ae0074289c merge with 1.8.1 + partial --version and --help 1993-09-08 18:23:12 +00:00
Jim Meyering
219bbb0758 new versions 1993-09-08 05:08:08 +00:00
Jim Meyering
27049d3bfc merge with 3.8.3 1993-08-27 04:43:46 +00:00
Jim Meyering
429043125e merge with 3.8.2 1993-08-26 04:38:30 +00:00
Jim Meyering
410da16d02 merge with 3.8.1 1993-08-05 02:20:48 +00:00
Jim Meyering
08701d38a4 merge with 3.8 1993-07-24 13:00:24 +00:00
Jim Meyering
75dd041027 Initial revision 1993-06-16 15:24:57 +00:00
Jim Meyering
adcd9b9c14 merge with 1.8 1993-06-16 14:33:22 +00:00
Jim Meyering
2a33928da6 merge with 3.6 1993-05-23 19:38:14 +00:00
Jim Meyering
eb3d538fdd merge with 1.6 1993-05-23 19:18:54 +00:00
Jim Meyering
e500c52f49 merge with 1.6 1993-05-23 19:12:22 +00:00
Jim Meyering
6587c39b3a merge with 1.5.2 1993-05-22 05:06:39 +00:00
Jim Meyering
d1c5cbfcdd merge with 3.5.5 1993-05-22 02:09:05 +00:00
Jim Meyering
5ca6750d57 merge with 3.5.4 1993-05-13 01:14:47 +00:00
Jim Meyering
9a96f7c461 merge with 1.5 1993-05-07 03:09:55 +00:00
Jim Meyering
f7999d7584 merge with 3.5.2 1993-05-06 05:34:26 +00:00
Jim Meyering
236ab993af merge with 3.5.2 1993-05-06 05:34:03 +00:00
Jim Meyering
93dcd18946 merge with 3.5.1 1993-05-02 21:35:51 +00:00
Jim Meyering
a4bfda47ac merge with 1.4.2.1 1993-05-01 21:07:58 +00:00
Jim Meyering
d7fcb354de merge with 1.4.2. 1993-05-01 20:31:22 +00:00
Jim Meyering
cd3f5c47d5 merge with 1.4.1 1993-05-01 19:59:02 +00:00
Jim Meyering
2ff4fc1672 add --version and --help 1993-04-29 05:26:22 +00:00
Jim Meyering
19272693f5 add --version and --help options 1993-04-29 05:25:16 +00:00
Jim Meyering
8993498904 . 1993-04-24 03:12:02 +00:00
Jim Meyering
cff8d231ff merge with 3.5 1993-04-22 03:16:53 +00:00
Jim Meyering
adcff142d8 merge with 3.4.8 1993-04-19 00:39:16 +00:00
Jim Meyering
29c0442cad merge with 3.4.7 1993-04-15 01:58:23 +00:00
Jim Meyering
0c6e5c710b 3.4.6 merge 1993-04-08 04:10:54 +00:00
Jim Meyering
67c4edfeb2 undef isascii before redefining 1993-04-06 02:45:12 +00:00
Jim Meyering
5e292210c9 . 1993-04-06 01:15:32 +00:00
Jim Meyering
ffcc3ee57c . 1993-04-05 16:34:42 +00:00
Jim Meyering
9b8fe62dc8 Add `case 0' to getopt_long switch. 1993-04-05 15:50:18 +00:00
Jim Meyering
e5a97dc971 . 1993-04-05 03:11:13 +00:00
Jim Meyering
b93c15a217 . 1993-04-05 03:09:08 +00:00
Jim Meyering
5c0034bed5 . 1993-04-05 01:16:18 +00:00
Jim Meyering
7f7cd1d678 * system.h [rindex, incl, bcopy, bzero]: Ditto.
* userspec.c [index]: Ditto.
1993-04-05 00:53:40 +00:00
Jim Meyering
fb81d346de . 1993-04-04 23:42:45 +00:00
Jim Meyering
d059fe157a (main): Explicitly cast -1 to [ug]id_t to avoid compiler warnings. 1993-04-04 23:42:37 +00:00
Jim Meyering
cb06e8f515 . 1993-04-04 23:17:00 +00:00
Jim Meyering
4cc0ccbeba . 1993-04-04 22:16:17 +00:00
Jim Meyering
43a62704e9 . 1993-04-04 22:15:32 +00:00
Jim Meyering
5b21dc1ece . 1993-04-04 21:52:17 +00:00
Jim Meyering
7ff4e5a700 (make_path): Explicitly cast alloca return value to (char *). 1993-04-04 21:52:09 +00:00
Jim Meyering
0df7488562 . 1993-04-04 21:50:47 +00:00
Jim Meyering
7db02117a9 (do_link): Explicitly cast alloca return value to (char *). 1993-04-04 21:50:19 +00:00
Jim Meyering
dc903be45e (do_move): Explicitly cast alloca return value to (char *). 1993-04-04 21:49:36 +00:00
Jim Meyering
223b1d7604 (copy, make_path, re_protect): Explicitly cast alloca return value to (char *). 1993-04-04 21:48:43 +00:00
Jim Meyering
9cf66fe2b1 * [sgi]: Undefine timezone before including <time.h>.
* [time.h vs sys/time.h]: Fix boolean algebra typo from
Mar 31 consolidation.
* Move static dcls of yyerror and yylex to a point
following the definition of those symbols to getdate_{yyerror,yylex}.
1993-04-04 16:36:44 +00:00
Jim Meyering
febc4c49c1 update from fsf 1993-04-04 15:22:00 +00:00
Jim Meyering
0ab48a40d7 . 1993-04-04 15:05:37 +00:00
Jim Meyering
0f1b91f942 (copy): Declare to be static. 1993-04-04 15:05:24 +00:00
Jim Meyering
cf4b6ee8fe . 1993-04-04 14:42:04 +00:00
Jim Meyering
a92a94f719 (usage): Mention --help and --version.
(main): Handle flag_help and flag_version before checking for invocation errors.
1993-04-04 14:41:38 +00:00
Jim Meyering
dc932e0a18 . 1993-04-04 00:56:21 +00:00
Jim Meyering
2469b27db0 remove blank line 1993-04-04 00:56:09 +00:00
Jim Meyering
5a09fe4494 . 1993-04-04 00:40:23 +00:00
Jim Meyering
7597dbd0da . 1993-04-04 00:11:14 +00:00
Jim Meyering
6b9e1727c8 Convert usage to take no arguments. 1993-04-02 04:35:26 +00:00
Jim Meyering
32821bb3f4 . 1993-04-02 04:27:50 +00:00
Jim Meyering
4d78dd47ab . 1993-04-02 04:27:28 +00:00
Jim Meyering
ee871dbed8 Add --help and --version options. 1993-04-02 04:26:26 +00:00
Jim Meyering
0a6061f1f9 Move some dcls before first function.
Add --help and --version options.
1993-04-02 04:26:04 +00:00
Jim Meyering
326ea43a59 undef isasc before redining it. 1993-04-02 04:24:29 +00:00
Jim Meyering
5c9a84b610 Define isascii macro to be 1 also if STDC_HEADERS. 1993-04-01 04:21:00 +00:00
Jim Meyering
def996ca60 Define isascii macro to be 1 also if STDC_HEADERS. 1993-04-01 04:12:31 +00:00
Jim Meyering
0f4b670f25 . 1993-04-01 04:06:15 +00:00
Jim Meyering
d24f7571cc Add --version, --help options. 1993-04-01 04:02:20 +00:00
Jim Meyering
0f8d90bd48 sort changes from Mike 1993-03-31 06:27:07 +00:00
Jim Meyering
b681a22c29 . 1993-03-31 06:07:16 +00:00
Jim Meyering
e2780ba79b . 1993-03-31 03:45:49 +00:00
Jim Meyering
a3dc0b45fc (parse_old_offset): Allow 0X' as well as 0x' prefix to indicate hex. 1993-03-31 03:44:09 +00:00
Jim Meyering
6cc9334011 Add -G,--no-group option to inhibit display of group infomation. 1993-03-31 02:50:42 +00:00
Jim Meyering
a7c3b38bb6 updated from FSF 1993-03-31 01:23:35 +00:00
Jim Meyering
f1f04bac77 . 1993-03-30 04:36:22 +00:00
Jim Meyering
c3798f9e61 (index, bcopy): Don't redefine. 1993-03-30 04:35:36 +00:00
Jim Meyering
6a08b3a1e5 . 1993-03-30 04:24:53 +00:00
Jim Meyering
56b1029ccf Always call error with errno (not zero) after failed fclose or non-zero ferror. 1993-03-30 03:32:10 +00:00
Jim Meyering
86a2a3f5f6 . 1993-03-30 02:22:06 +00:00
Jim Meyering
80f8bd8e8c merge with 3.4.1 1993-03-29 05:09:09 +00:00
Jim Meyering
eb652720df . 1993-03-28 19:22:51 +00:00
Jim Meyering
7b90e466f9 . 1993-03-28 19:22:28 +00:00
Jim Meyering
16e01be2da . 1993-03-28 18:23:20 +00:00
Jim Meyering
4e66f13a79 (add_omitted_fs_type, fs_to_omit): New functions adding
support for --exclude-type option.  From Kaveh R. Ghazi
<ghazi@caip.rutgers.edu>.
1993-03-28 18:22:47 +00:00
Jim Meyering
d446f94a60 (decode_switches, print_long_format): New option: --full-time. 1993-03-28 18:21:25 +00:00
Jim Meyering
7735ccac5e (main): If -f is given, don't complain if no file args are given. 1993-03-28 16:29:03 +00:00
Jim Meyering
a34d7ff0ac [rindex]: Don't redefine. 1993-03-28 16:23:28 +00:00
Jim Meyering
c1c67d3295 Accept `flush' option. From Arne H. Juul arnej@lise.unit.no 1993-03-28 16:16:43 +00:00
Jim Meyering
fbc2f821ff . 1993-03-28 16:15:32 +00:00
Jim Meyering
d4f175199f Add long options. 1993-03-26 04:52:17 +00:00
Jim Meyering
c7fdeca168 . 1993-03-26 04:51:55 +00:00
Jim Meyering
c9b0bde5e6 . 1993-03-26 04:50:40 +00:00
Jim Meyering
1a34a11854 . 1993-03-26 04:43:26 +00:00
Jim Meyering
0fb79b9ee4 . 1993-03-24 06:23:42 +00:00
Jim Meyering
89ed6c2fec (gobble_file): Don't stat symlinks unless we need to.
From Mike Rendell <michael@mercury.cs.mun.ca>.
1993-03-24 06:23:26 +00:00
Jim Meyering
82bdb546d9 (copy, copy_with_block, copy_with_block): Decrement pending_spaces only
if it's > 0. The following command didn't terminate:
  perl -e 'print "a  a\n";'| dd of=/dev/null ibs=1 cbs=3 conv=unblock
With suggestions from Chris Weber <weber@bucknell.edu>,
Marlys.A.Nelson@uwrf.edu, and Albert-Lunde@nwu.edu.
1993-03-24 06:22:57 +00:00
Jim Meyering
38456f092f New option: -C, --compatible.
A few new small functions.
1993-03-23 05:27:39 +00:00
Jim Meyering
4f0f13ad00 . 1993-03-23 02:52:19 +00:00
Jim Meyering
45849c5602 (close_file): Reverse May 13, '92 change, but add the condition
that cols_ready_to_print not be decremented when printing across.
The command `echo |pr -2ta' didn't terminate.
(print_page): Rewrite conditional with side effects in second conjunct
using nested if statements to make it clear that we do indeed want
those semantics.
1993-03-22 04:39:25 +00:00
Jim Meyering
b1770970a8 fix two typos 1993-03-22 02:31:33 +00:00
Jim Meyering
a299f3cc81 Compare getenv with NULL instead of 0 -- just for aesthetics. 1993-03-06 17:06:35 +00:00
Jim Meyering
90a2952982 . 1993-03-02 14:48:18 +00:00
Jim Meyering
3855a21213 . 1993-03-02 14:41:40 +00:00
Jim Meyering
8a010c44a5 . 1993-03-02 14:36:30 +00:00
Jim Meyering
978afa51c0 . 1993-03-02 14:13:10 +00:00
Jim Meyering
d71cb4d9c7 Initial revision 1993-03-02 14:10:31 +00:00
Jim Meyering
d766e142ea (print_s_char, print_s_short): Print signed chars and signed shorts without
resorting to casts involving `signed' keyword.
(decode_one_format): Don't print leading zeroes for DECIMAL formats.
1993-02-26 15:53:47 +00:00
Jim Meyering
63354f0c3f reindent with indent-1.7 1993-02-25 16:31:52 +00:00
Jim Meyering
efd83f0b57 Reformat with GNU indent-1.7. 1993-02-25 14:28:21 +00:00
Jim Meyering
bc18a8e7f7 (print_s_char, print_s_short): Fix printing of signed chars and signed shorts. 1993-02-25 14:27:40 +00:00
Jim Meyering
f7c04842b9 Don't ask when removing symlinks. 1993-02-18 18:24:15 +00:00
Jim Meyering
8ae407c539 Add long options. 1993-02-08 05:13:43 +00:00
89 changed files with 4853 additions and 1370 deletions

3
lib/.cvsignore Normal file
View File

@@ -0,0 +1,3 @@
Makefile
getdate.c
posixtm.c

View File

@@ -1,6 +1,5 @@
# Makefile for library files used by GNU fileutils.
# Do not use this makefile directly, but only from `../Makefile'.
# Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
# Copyright (C) 1990, 1991, 1992, 1993 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
@@ -21,21 +20,28 @@ SHELL = /bin/sh
srcdir = @srcdir@
VPATH = @srcdir@
SOURCES = argmatch.c backupfile.c basename.c dirname.c eaccess.c \
CC = @CC@
AR = ar
RANLIB = @RANLIB@
DEFS = @DEFS@
CFLAGS = @CFLAGS@
SOURCES = getdate.y posixtm.y \
argmatch.c backupfile.c basename.c dirname.c eaccess.c \
error.c filemode.c fsusage.c getopt.c getopt1.c \
getversion.c idcache.c isdir.c makepath.c \
modechange.c mountlist.c savedir.c \
stripslash.c xgetcwd.c xmalloc.c xstrdup.c userspec.c yesno.c \
getdate.y posixtm.y \
fileblocks.c fnmatch.c ftruncate.c mkdir.c mktime.c rename.c stpcpy.c \
strdup.c strstr.c alloca.c
OBJECTS = argmatch.o backupfile.o basename.o dirname.o eaccess.o \
OBJECTS = getdate.o posixtm.o \
argmatch.o backupfile.o basename.o dirname.o eaccess.o \
error.o filemode.o getopt.o getopt1.o \
getversion.o idcache.o isdir.o makepath.o \
modechange.o savedir.o \
stripslash.o xgetcwd.o xmalloc.o xstrdup.o userspec.o yesno.o \
getdate.o posixtm.o @LIBOBJS@ @ALLOCA@
@LIBOBJS@ @ALLOCA@
DISTFILES = Makefile.in backupfile.h getopt.h modechange.h \
fnmatch.h fsusage.h mountlist.h pathmax.h system.h $(SOURCES)
@@ -43,7 +49,7 @@ fnmatch.h fsusage.h mountlist.h pathmax.h system.h $(SOURCES)
all: libfu.a
.c.o:
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(DEFS) -I$(srcdir) $<
$(CC) -c $(CPPFLAGS) $(DEFS) -I.. -I$(srcdir) $(CFLAGS) $<
install: all
@@ -52,6 +58,8 @@ uninstall:
TAGS: $(SOURCES)
etags $(SOURCES)
check:
clean:
rm -f *.a *.o
@@ -64,24 +72,30 @@ realclean: distclean
rm -f TAGS
dist:
ln $(DISTFILES) ../`cat ../.fname`/lib
for file in $(DISTFILES); do \
ln $$file ../`cat ../.fname`/lib \
|| cp -p $$file ../`cat ../.fname`/lib; \
done
libfu.a: $(OBJECTS)
rm -f $@
$(AR) cr $@ $(OBJECTS)
-$(RANLIB) $@
# Since this directory contains two parsers, using bison without -y
# is the only way to reliably do a parallel make.
# Since this directory contains two parsers, we have to be careful to avoid
# running two $(YACC)s during parallel makes. See below.
getdate.c: getdate.y
@echo expect 9 shift/reduce conflicts
-bison -o getdate.c $(srcdir)/getdate.y || yacc $(srcdir)/getdate.y
test ! -f y.tab.c || mv y.tab.c getdate.c
$(YACC) $(srcdir)/getdate.y
mv y.tab.c getdate.c
# Make the rename atomic, in case sed is interrupted and later rerun.
posixtm.c: posixtm.y
-bison -o posixtm.tab.c $(srcdir)/posixtm.y || yacc $(srcdir)/posixtm.y
test ! -f y.tab.c || mv y.tab.c posixtm.tab.c
# The artificial dependency on getdate.c keeps the two parsers from being
# built in parallel. Enforcing this little bit of sequentiality lets
# everyone (even those without bison) still run mostly parallel builds.
posixtm.c: posixtm.y getdate.c
$(YACC) $(srcdir)/posixtm.y
mv y.tab.c posixtm.tab.c
sed -e 's/yy/zz/g' posixtm.tab.c > tposixtm.c
mv tposixtm.c posixtm.c
rm -f posixtm.tab.c
@@ -94,5 +108,6 @@ modechange.o: modechange.h
mountlist.o: mountlist.h
xgetcwd.o: pathmax.h
# Prevent GNU make v3 from overflowing arg limit on SysV.
# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -15,40 +15,52 @@
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>.
Some algorithms adapted from GNU Emacs. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I will use ./config.h rather than /config.h
(which it would do because it found this file in ). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include "backupfile.h"
#if defined(USG) || defined(STDC_HEADERS)
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#ifndef index
#define index strchr
#endif
#ifndef rindex
#define rindex strrchr
#endif
#else
#include <strings.h>
#endif
#ifdef DIRENT
#if defined(DIRENT) || defined(_POSIX_VERSION)
#include <dirent.h>
#ifdef direct
#undef direct
#endif
#define direct dirent
#define NLENGTH(direct) (strlen((direct)->d_name))
#else /* !DIRENT */
#else /* not (DIRENT or _POSIX_VERSION) */
#define dirent direct
#define NLENGTH(direct) ((direct)->d_namlen)
#ifdef USG
#ifdef SYSNDIR
#include <sys/ndir.h>
#else /* !SYSNDIR */
#include <ndir.h>
#endif /* !SYSNDIR */
#else /* !USG */
#endif /* SYSNDIR */
#ifdef SYSDIR
#include <sys/dir.h>
#endif /* !USG */
#endif /* !DIRENT */
#endif /* SYSDIR */
#ifdef NDIR
#include <ndir.h>
#endif /* NDIR */
#endif /* DIRENT or _POSIX_VERSION */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */
@@ -63,12 +75,14 @@
char *malloc ();
#endif
#ifndef isascii
#define ISDIGIT(c) (isdigit ((unsigned char) (c)))
#else
#define ISDIGIT(c) (isascii (c) && isdigit (c))
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
#define isascii(c) 1
#endif
#define ISDIGIT(c) (isascii ((unsigned char ) c) \
&& isdigit ((unsigned char) (c)))
#if defined (HAVE_UNISTD_H)
#include <unistd.h>
#endif
@@ -138,7 +152,7 @@ max_backup_version (file, dir)
char *file, *dir;
{
DIR *dirp;
struct direct *dp;
struct dirent *dp;
int highest_version;
int this_version;
int file_name_length;
@@ -213,7 +227,7 @@ concat (str1, str2)
char *str1, *str2;
{
char *newstr;
char str1_length = strlen (str1);
int str1_length = strlen (str1);
newstr = malloc (str1_length + strlen (str2) + 1);
if (newstr == 0)

View File

@@ -15,14 +15,27 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I will use ./config.h rather than /config.h
(which it would do because it found this file in ). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#else
char *malloc ();
#endif
#if defined(USG) || defined(STDC_HEADERS)
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#ifndef rindex
#define rindex strrchr
#endif
#else
#include <strings.h>
#endif

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -15,17 +15,30 @@ License along with this library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <errno.h>
#include "fnmatch.h"
#include <fnmatch.h>
#include <ctype.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
extern int errno;
#endif
#if !__STDC__
#define const
#endif
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
int
@@ -37,40 +50,42 @@ fnmatch (pattern, string, flags)
register const char *p = pattern, *n = string;
register char c;
if ((flags & ~__FNM_FLAGS) != 0)
{
errno = EINVAL;
return -1;
}
/* Note that this evalutes C many times. */
#define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
while ((c = *p++) != '\0')
{
c = FOLD (c);
switch (c)
{
case '?':
if (*n == '\0')
return FNM_NOMATCH;
else if ((flags & FNM_PATHNAME) && *n == '/')
else if ((flags & FNM_FILE_NAME) && *n == '/')
return FNM_NOMATCH;
else if ((flags & FNM_PERIOD) && *n == '.' &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
(n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
break;
case '\\':
if (!(flags & FNM_NOESCAPE))
c = *p++;
if (*n != c)
{
c = *p++;
c = FOLD (c);
}
if (FOLD (*n) != c)
return FNM_NOMATCH;
break;
case '*':
if ((flags & FNM_PERIOD) && *n == '.' &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
(n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
if (((flags & FNM_PATHNAME) && *n == '/') ||
if (((flags & FNM_FILE_NAME) && *n == '/') ||
(c == '?' && *n == '\0'))
return FNM_NOMATCH;
@@ -79,8 +94,9 @@ fnmatch (pattern, string, flags)
{
char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
c1 = FOLD (c1);
for (--p; *n != '\0'; ++n)
if ((c == '[' || *n == c1) &&
if ((c == '[' || FOLD (*n) == c1) &&
fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
return 0;
return FNM_NOMATCH;
@@ -95,7 +111,7 @@ fnmatch (pattern, string, flags)
return FNM_NOMATCH;
if ((flags & FNM_PERIOD) && *n == '.' &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
(n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
not = (*p == '!' || *p == '^');
@@ -110,13 +126,16 @@ fnmatch (pattern, string, flags)
if (!(flags & FNM_NOESCAPE) && c == '\\')
cstart = cend = *p++;
cstart = cend = FOLD (cstart);
if (c == '\0')
/* [ (unterminated) loses. */
return FNM_NOMATCH;
c = *p++;
c = FOLD (c);
if ((flags & FNM_PATHNAME) && c == '/')
if ((flags & FNM_FILE_NAME) && c == '/')
/* [/] can never match. */
return FNM_NOMATCH;
@@ -127,10 +146,12 @@ fnmatch (pattern, string, flags)
cend = *p++;
if (cend == '\0')
return FNM_NOMATCH;
cend = FOLD (cend);
c = *p++;
}
if (*n >= cstart && *n <= cend)
if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
goto matched;
if (c == ']')
@@ -150,7 +171,7 @@ fnmatch (pattern, string, flags)
c = *p++;
if (!(flags & FNM_NOESCAPE) && c == '\\')
/* 1003.2d11 is unclear if this is right. %%% */
/* XXX 1003.2d11 is unclear if this is right. */
++p;
}
if (not)
@@ -159,15 +180,21 @@ fnmatch (pattern, string, flags)
break;
default:
if (c != *n)
if (c != FOLD (*n))
return FNM_NOMATCH;
}
++n;
}
if (*n == '\0' || ((flags & FNM_TARPATH) && *n == '/'))
if (*n == '\0')
return 0;
if ((flags & FNM_LEADING_DIR) && *n == '/')
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return 0;
return FNM_NOMATCH;
}
#endif /* _LIBC or not __GNU_LIBRARY__. */

View File

@@ -15,11 +15,26 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I will use ./config.h rather than /config.h
(which it would do because it found this file in ). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <sys/types.h>
#include "fsusage.h"
int statfs ();
#if defined (STATFS_OSF1) /* DEC Alpha running OSF/1 */
# include <sys/mount.h>
#endif
#if defined(STAT_STATFS2_BSIZE) && !defined(_IBMR2) /* 4.3BSD, SunOS 4, HP-UX, AIX PS/2. */
#include <sys/vfs.h>
#endif
@@ -54,16 +69,20 @@ int statvfs ();
#endif
/* Return the number of TOSIZE-byte blocks used by
BLOCKS FROMSIZE-byte blocks, rounding up. */
BLOCKS FROMSIZE-byte blocks, rounding away from zero. */
#define adjust_blocks(blocks, fromsize, tosize) \
(((fromsize) == (tosize)) \
? (blocks) /* E.g., from 512 to 512. */ \
: (((fromsize) > (tosize)) \
/* E.g., from 2048 to 512. */ \
? (blocks) * ((fromsize) / (tosize)) \
/* E.g., from 256 to 512. */ \
: ((blocks) + 1) / ((tosize) / (fromsize))))
static long
adjust_blocks (blocks, fromsize, tosize)
long blocks;
int fromsize, tosize;
{
if (fromsize == tosize) /* E.g., from 512 to 512. */
return blocks;
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else /* E.g., from 256 to 512. */
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
the filesystem on which PATH resides.
@@ -76,6 +95,14 @@ get_fs_usage (path, disk, fsp)
char *path, *disk;
struct fs_usage *fsp;
{
#if defined (STATFS_OSF1)
struct statfs fsd;
if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
return (-1);
#define convert_blocks(b) adjust_blocks ((b),fsd.f_fsize, 512)
#endif /* STATFS_OSF1 */
#ifdef STAT_STATFS2_FS_DATA /* Ultrix. */
struct fs_data fsd;
@@ -140,9 +167,11 @@ get_fs_usage (path, disk, fsp)
no matter what value f_bsize has. */
#define convert_blocks(b) (b)
#ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx. */
#ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
#define f_bavail f_bfree
#endif
#endif
#endif
#ifdef STAT_STATVFS /* SVR4. */
struct statvfs fsd;

View File

@@ -1,23 +1,41 @@
%{
/* $Revision: 1.1.1.1 $
**
/*
** 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
** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
** send any email to Rich.
**
** This grammar has eight shift/reduce conflicts.
** This grammar has nine shift/reduce conflicts.
**
** This code is in the public domain and has no copyright.
*/
/* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
/* 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
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 sparc
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#else
#ifdef _AIX /* for Bison */
@@ -36,10 +54,6 @@ char *alloca ();
tricks are need, but defaults to using the gettimeofday system call.
Include <sys/time.h> if that will be used. */
#if !defined (USG) && !defined (sgi) && !defined (__386BSD__)
#include <sys/time.h>
#endif
#if defined(vms)
#include <types.h>
@@ -49,32 +63,36 @@ char *alloca ();
#include <sys/types.h>
#if defined(USG) || !defined(HAVE_FTIME)
#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
#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) */
#if defined(BSD4_2) || defined(BSD4_1C) || (defined (hp9000) && !defined (hpux))
#include <sys/time.h>
#else
#if defined(_AIX)
#include <sys/time.h>
#endif
#include <time.h>
#endif /* defined(BSD4_2) */
#endif /* defined(HAVE_SYS_TIMEB_H) */
#endif /* defined(vms) */
@@ -82,19 +100,26 @@ struct timeb {
#include <string.h>
#endif
#if sgi
#undef timezone
/* 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
#define yylex getdate_yylex
#define yyerror getdate_yyerror
static int yylex ();
static int yyerror ();
#if !defined(lint) && !defined(SABER)
static char RCS[] =
"$Header: /w/src/cvsroot/shellutils/lib/getdate.y,v 1.1.1.1 1992/11/01 05:44:32 meyering Exp $";
"$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
#endif /* !defined(lint) && !defined(SABER) */
@@ -847,12 +872,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 +911,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);

View File

@@ -3,58 +3,72 @@
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
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 the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* AIX requires this to be the first thing in the file. */
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not __GNUC__ */
#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
#include <alloca.h>
#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 it found this file in $srcdir). */
#include <config.h>
#else
#ifdef _AIX
#pragma alloca
#else
char *alloca ();
#include "config.h"
#endif
#endif
#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. */
#ifndef _NO_PROTO
#define _NO_PROTO
#endif
#endif /* alloca.h */
#endif /* not __GNUC__ */
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#undef alloca
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
#else /* Not GNU C library. */
#define __alloca alloca
#endif /* GNU C library. */
#if !__STDC__
#define const
#endif
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
long-named option. Because this is not POSIX.2 compliant, it is
being phased out. */
#define GETOPT_COMPAT
/* #define GETOPT_COMPAT */
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
@@ -92,6 +106,7 @@ char *optarg = 0;
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
/* XXX 1003.2 says this must be 1 before any call. */
int optind = 0;
/* The next char to be scanned in the option-element
@@ -108,6 +123,12 @@ static char *nextchar;
int opterr = 1;
/* Set to an option character which was unrecognized.
This must be initialized on some systems to avoid linking in the
system's own getopt implementation. */
int optopt = '?';
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
@@ -149,7 +170,6 @@ static enum
in GCC. */
#include <string.h>
#define my_index strchr
#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
#else
/* Avoid depending on library functions or files
@@ -158,28 +178,32 @@ static enum
char *getenv ();
static char *
my_index (string, chr)
char *string;
my_index (str, chr)
const char *str;
int chr;
{
while (*string)
while (*str)
{
if (*string == chr)
return string;
string++;
if (*str == chr)
return (char *) str;
str++;
}
return 0;
}
static void
my_bcopy (from, to, size)
char *from, *to;
int size;
{
int i;
for (i = 0; i < size; i++)
to[i] = from[i];
}
/* If using GCC, we can safely declare strlen this way.
If not using GCC, it is ok not to declare it.
(Supposedly there are some machines where it might get a warning,
but changing this conditional to __STDC__ is too risky.) */
#ifdef __GNUC__
#ifdef IN_GCC
#include "gstddef.h"
#else
#include <stddef.h>
#endif
extern size_t strlen (const char *);
#endif
#endif /* GNU C library. */
/* Handle permutation of arguments. */
@@ -204,17 +228,51 @@ static void
exchange (argv)
char **argv;
{
int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
char **temp = (char **) __alloca (nonopts_size);
int bottom = first_nonopt;
int middle = last_nonopt;
int top = optind;
char *tem;
/* Interchange the two blocks of data in ARGV. */
/* Exchange the shorter segment with the far end of the longer segment.
That puts the shorter segment into the right place.
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
(optind - last_nonopt) * sizeof (char *));
my_bcopy ((char *) temp,
(char *) &argv[first_nonopt + optind - last_nonopt],
nonopts_size);
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
}
else
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
/* Update records for the slots the non-options now occupy. */
@@ -490,7 +548,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
fprintf (stderr, "%s: option `%s' requires an argument\n",
argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
return '?';
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
@@ -544,12 +602,18 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (opterr)
{
#if 0
if (c < 040 || c >= 0177)
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
argv[0], c);
else
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
#endif
}
optopt = c;
return '?';
}
if (temp[1] == ':')
@@ -579,9 +643,21 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else if (optind == argc)
{
if (opterr)
fprintf (stderr, "%s: option `-%c' requires an argument\n",
argv[0], c);
c = '?';
{
#if 0
fprintf (stderr, "%s: option `-%c' requires an argument\n",
argv[0], c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: option requires an argument -- %c\n",
argv[0], c);
#endif
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `optind' once;
@@ -605,6 +681,8 @@ getopt (argc, argv, optstring)
(int *) 0,
0);
}
#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST

View File

@@ -1,16 +1,16 @@
/* Declarations for getopt.
Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
Copyright (C) 1989, 1990, 1991, 1992, 1993 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 the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
@@ -49,6 +49,10 @@ extern int optind;
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is

View File

@@ -1,31 +1,62 @@
/* Getopt for GNU.
Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
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 the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include "getopt.h"
#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC)
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
#else /* STDC_HEADERS or __GNU_LIBRARY__ */
#else
char *getenv ();
#endif /* STDC_HEADERS or __GNU_LIBRARY__ */
#endif
#ifndef NULL
#define NULL 0
@@ -47,7 +78,7 @@ getopt_long (argc, argv, options, long_options, opt_index)
but does match a short option, it is parsed as a short option
instead. */
int
int
getopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
@@ -57,6 +88,9 @@ getopt_long_only (argc, argv, options, long_options, opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST

View File

@@ -18,6 +18,17 @@
/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and
Jim Meyering <meyering@cs.utexas.edu>. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I will use ./config.h rather than /config.h
(which it would do because it found this file in ). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#ifdef __GNUC__
#define alloca __builtin_alloca
#else
@@ -32,26 +43,51 @@ char *alloca ();
#endif
#endif
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I will use ./config.h rather than /config.h
(which it would do because it found this file in ). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef STAT_MACROS_BROKEN
#ifdef S_ISDIR
#undef S_ISDIR
#endif
#endif /* STAT_MACROS_BROKEN. */
#if !defined(S_ISDIR) && defined(S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#ifdef STDC_HEADERS
#include <errno.h>
#include <stdlib.h>
#else
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifndef STDC_HEADERS
extern int errno;
#endif
#if defined(USG) || defined(STDC_HEADERS)
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#ifndef index
#define index strchr
#endif
#else
#include <strings.h>
#endif
@@ -93,7 +129,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
int retval = 0;
int oldmask = umask (0);
dirpath = alloca (strlen (argpath) + 1);
dirpath = (char *) alloca (strlen (argpath) + 1);
strcpy (dirpath, argpath);
if (stat (dirpath, &stats))
@@ -145,7 +181,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
if (owner != (uid_t) -1 && group != (gid_t) -1
&& chown (dirpath, owner, group)
#ifdef AFS
#if defined(AFS) && defined (EPERM)
&& errno != EPERM
#endif
)

View File

@@ -18,19 +18,30 @@ 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
#endif
#ifndef bcopy
#define bcopy(s, d, n) memcpy((d), (s), (n))
#else /* not (STDC_HEADERS or USG) */
#endif
#else
#include <strings.h>
#endif /* STDC_HEADERS or USG */
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -40,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. */

File diff suppressed because it is too large Load Diff

View File

@@ -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
{
@@ -108,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

@@ -17,14 +17,27 @@
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I will use ./config.h rather than /config.h
(which it would do because it found this file in ). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#if defined(USG) || defined(STDC_HEADERS)
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#ifndef index
#define index strchr
#endif
#else
#include <strings.h>
#endif

View File

@@ -1,3 +1,487 @@
Tue Oct 05 14:52:02 1993 Jim Meyering (meyering@comco.com)
* configure.in: Add AC_STAT_MACROS_BROKEN.
* isdir.c, makepath.c, rename.c, system.h [STAT_MACROS_BROKEN]:
Test this.
* xmalloc.c [CONFIG_BROKETS]: Test this.
* install.c (install_file_in_dir): Use stpcpy instead of slow sprintf.
* argmatch.c, backupfile.c, basename.c, dirname.c, eaccess.c,
fileblocks.c, fsusage.c, getversion.c, idcache.c, isdir.c,
makepath.c, mountlist.c, rename.c, savedir.c, stripslash.c,
userspec.c, xgetcwd.c, xstrdup.c, yesno.c, [HAVE_CONFIG_H,
CONFIG_BROKETS]: Include <config.h> or "config.h".
* lib/Makefile.in, src/Makefile.in [.c.o]: Put -I.. before
-I$(srcdir) so <config.h> will get the right file.
* chgrp.c, chmod.c, chown.c, cp-aux.c, cp-hash.c, cp.c, dd.c,
df.c, du.c, install.c, ln.c, ls.c, mkdir.c, mkfifo.c, mknod.c,
mv.c, mvdir.c, rm.c, rmdir.c, touch.c, version.c [HAVE_CONFIG_H,
CONFIG_BROKETS]: Include <config.h> or "config.h".
* configure.in [AC_CONFIG_HEADER]: Use it.
* configure.in (rename.o) [MVDIR definition]: Remove it.
* src/Makefile.in [DEFS]: Put it here instead.
* config.h.in, acconfig.h: New files
* Makefile [DISTFILES]: Add them.
(config.h.in): Add a rule to warn if it may need to be rebuilt.
Thu Sep 9 08:52:10 1993 Jim Meyering (meyering@comco.com)
* src/*.c: Print version on standard output, not stderr.
Fri Aug 27 23:53:50 1993 Jim Meyering (meyering@comco.com)
* cp.c (copy), ls.c (get_link_name): Don't use PATH_MAX as array
length in declarations because on some systems it gets defined
to the function pathconf. Use dynamic allocation instead.
* fsusage.c (adjust_blocks): Use `1' instead of `+1'. Many
compilers don't parse the latter. From Kaveh R. Ghazi.
Fri Aug 27 10:27:13 1993 Paul Eggert (eggert@twinsun.com)
* xmalloc.c: Include "config.h" if HAVE_CONFIG_H. Use size_t,
not int, when needed.
(VOID): New macro. Use it when needed.
(error): Declaration uses varargs if required.
Thu Aug 26 22:26:09 1993 Jim Meyering (meyering@comco.com)
* ls.c (print_long_format, print_file_name_and_frills): Cast inode
number to unsigned long and print it with %lu to avoid warnings from
gcc -Wformat because the size and type of ino_t are system dependent.
* cp.c (do_copy): Plug a memory leak with --parents.
* ln.c (main): Like mv and cp, convert `ln x y/' to ln x y/x
when a is not a directory.
[PATH_BASENAME_CONCAT]: New macro.
(do_link): Use it here, too.
* ls.c (sort_files): Add `default: abort();' clause to switch stmts.
* cp.c (do_copy): Don't remove trailing slashes from source.
Wed Aug 25 21:40:00 1993 Jim Meyering (meyering@comco.com)
* cp.c: Add --parents as synonym for --path. Change --path to
--parents in comments. --path is deprecated.
* rm.c (clear_directory): Fix incorrect test for determining when
to reallocate buffer. Thanks to Ric Anderson <ric@CS.Arizona.EDU>.
Fri Aug 13 17:19:52 1993 Jim Meyering (meyering@comco.com)
* fsusage (adjust_blocks): Round away from zero -- this matters
when computing the negative free-block count for disks that are
more than 100% full.
* mv.c (movefile): Use nested calls to stpcpy instead of sprintf.
(is_real_dir): New function.
(movefile): In addition to when dest is a directory, if dest has
a trailing `/' and source is not a directory, presume the target
is dest/`basename source`. This converts `mv x y/' to `mv x y/x'
when x is not a directory. This change means that the command
`mv any file/' will now fail rather than performing the move.
* cp.c (do_copy): Similarly, convert `cp x y/' to cp x y/x when
x is not a directory.
Wed Aug 4 17:43:18 1993 Jim Meyering (meyering@comco.com)
* ls.c (get_link_name): Don't ever use the stat field st_size as a
buffer size. Too many systems don't set it properly for mount points.
Instead, use a fixed-length buffer. From Michael Joosten
<joost@ori.CAdlab.DE>.
* cp.c (copy): Ditto.
Mon Jul 19 17:39:01 1993 Jim Meyering (meyering@comco.com)
* backupfile.c (concat): Temporary STR1_LENGTH should have type `int'
instead of `char.'
Fri Jul 16 22:00:16 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
* dd.c (print_stats): Change message from "truncated blocks"
to "truncated records" for final POSIX.2 spec.
Fri Jun 25 17:18:15 1993 Jim Meyering (meyering@comco.com)
* mkdir.c, rmdir.c: Change --path long option to --parents to avoid
confusion with search-path semantics of --path as an option to other
programs. --path will still work, but is no longer documented.
Tue Jun 8 00:46:26 1993 Jim Meyering (meyering@comco.com)
* dd.c (parse_integer): Also accept `c' multiplier for consistency
with find's -size option.
Thu May 27 00:03:51 1993 Jim Meyering (meyering@comco.com)
* Version 3.8.
* configure.in (STAT_OSF1): Reference the statfs f_fsize member
so that configure defines STAT_OSF1 only if there is such a member.
Without such a reference, a Pyramid MIServer running OSx 5.1
improperly defined STAT_OSF1 instead of the one it needed:
STAT_STATFS2_BSIZE.
Wed May 26 00:57:46 1993 Jim Meyering (meyering@comco.com)
* ls.h, ls-ls.c ls-dir.c, ls-vdir.c: New files that define or
simply set the new global variable ls_mode. ls_mode defines whether
the executable built from ls.o should act like ls, dir, or vdir.
* ls.c (decode_switches): Use the variable instead of #ifdefs.
This is modelled after the approach used in GNU binutils 2.x for
ar and ranlib. Here we avoid two redundant compilations.
* install.c (change_attributes, copy_file, install_file_in_file):
Don't call chown if we can efficiently determine that doing so is
unnecessary. On some systems, calls to chown (even with your own
uid and gid) fail unless made by root. On such systems install
got spurious failures.
Sat May 22 02:13:12 1993 Jim Meyering (meyering@comco.com)
* Version 3.6.
Fri May 21 18:42:27 1993 Jim Meyering (meyering@comco.com)
* rename.c (rename): Be careful not to unlink `from' if it happens
to be equal to `to' or (on filesystems that silently truncate
filenames after 14 characters) if `from' and `to' share the
significant characters. From Bruno Haible
<haible@ma2s2.mathematik.uni-karlsruhe.de>.
* mountlist.c, fsusage.c: Make these work under m88k DolphinOS.
From Kjetil Wiekhorst J|rgensen <jorgens@pvv.unit.no>.
Tue May 18 23:49:26 1993 Jim Meyering (meyering@comco.com)
* mkinstalldirs: New file.
* Makefile.in (installdirs): Use it.
Sat May 15 01:20:26 1993 Jim Meyering (meyering@comco.com)
* ln.c (do_link): Make `ln -s dir_pathname .' work when the
pathname has a trailing slash.
Fri May 14 23:45:52 1993 Jim Meyering (meyering@comco.com)
* all source: With --version, print version and exit immediately.
Wed May 12 20:48:55 1993 Jim Meyering (meyering@comco.com)
* configure.in: Add check for the -ldgc library that is required
for getmntent on m88k DGUX-5.4 systems.
* Makefile.in (installdirs): New rules for creating installation
directories. (install): Depend on it.
Sat May 8 11:31:14 1993 Jim Meyering (meyering@comco.com)
* lib/Makefile.in (dist): Use `cp -p' instead of just `cp'
if linking fails.
Thu May 6 22:45:25 1993 Jim Meyering (meyering@comco.com)
* makepath.c: Use explicit dcl of errno only if !STDC_HEADERS.
Some systems have <errno.h> but don't declare errno.
From Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
* getdate.y: Test TIME_WITH_SYS_TIME, not TIME_AND_SYS_TIME.
Wed May 5 00:21:12 1993 Jim Meyering (meyering@comco.com)
* configure.in: Add AC_TIME_WITH_SYS_TIME.
* getdate.y: Use it (this is a version local to fileutils).
Tue May 4 20:25:41 1993 Jim Meyering (meyering@comco.com)
* du.c (count_entry): Give an error and exit if chdir ("..") fails.
From Bruce Evans <bde@runx.oz.AU>.
* eaccess (eaccess_stat): Cast NGROUPS_MAX to appropriate types.
From Bruce Evans <bde@runx.oz.AU>.
Mon May 3 22:09:24 1993 Jim Meyering (meyering@comco.com)
* configure.in: Add AC_GETGROUPS_T.
* eaccess.c: Don't define GETGROUPS_T. Now configure does it.
Sun May 2 09:18:53 1993 Jim Meyering (meyering@comco.com)
* configure.in: Check for libypsec.a on Dolphin M88K machines.
This can result in significant speedup for programs that access
YP information. From Kjetil Wiekhorst J{\o}rgensen
<jorgens@pvv.unit.no>.
Fri Apr 30 02:21:48 1993 Jim Meyering (meyering@comco.com)
* ls.c (main): Make `-f' work like on standard Unix ls, instead
of as a short equivalent of --full-time.
* ls.1: Document it.
Thu Apr 29 00:46:46 1993 Jim Meyering (meyering@comco.com)
* src/Makefile.in [dir.o, vdir.o]: Make ordering of CFLAGS etc
in compilation rules consistent with that in .c.o rule.
* Makefile.in (dist): Depend on Makefile so that changes to
Makefile.in (like adding new files to DISTRIB) are reflected
in the new distribution.
Tue Apr 27 21:35:11 1993 Jim Meyering (meyering@comco.com)
* configure.in: Remove unnecessary AC_PROG_INSTALL.
Fri Apr 23 23:39:16 1993 Jim Meyering (meyering@comco.com)
* {lib,src}/Makefile.in [.c.o]: Make CPPFLAGS and CFLAGS follow
other options so users can use them to override DEFS.
* lib/mktime.c: Use new version from glibc instead of one from
libc-subst. `touch' built with the latter didn't set proper
time unless given a specific --date option.
Thu Apr 22 00:22:25 1993 Jim Meyering (meyering@comco.com)
* makepath.c: Decouple inclusion of errno.h from definition of
STDC_HEADERS; many systems have errno.h, yet shouldn't define
STDC_HEADERS.
* makepath.c (make_path): Add EPERM clause only if both AFS and
EPERM are defined.
* configure.in: Test for errno.h header file.
Mon Apr 19 11:21:14 1993 Jim Meyering (meyering@comco.com)
* Version 3.5.
* ls.c, touch.c: Don't include time.h explicitly -- it's included
by system.h. From Franc,ois Pinard.
* posixtm.y: Use TM_IN_SYS_TIME.
* backupfile.c [index, rindex]: Don't redefine them.
* system.h [alloca]: Don't redefine it.
* configure.in: Check for sys/time.h; getdate.y needs it for
structs timeval and timezone on some systems.
Sun Apr 18 22:40:19 1993 David J. MacKenzie (djm@kropotkin.gnu.ai.mit.edu)
* ls.c: Include fnmatch.h after system.h, so we get our
definitions of FNM_*, not those from unistd.h.
* mountlist.c [MOUNTED_GETMNTINFO]: Add #ifdef around MOUNT_PC.
* configure.in: Fix test for 4.4BSD statfs to not grep for a
macro in cpp output.
Sun Apr 18 02:35:36 1993 Jim Meyering (meyering@comco.com)
* configure.in: Check for gettimeofday.
Check for `struct tm'.
Change MVDIR definition so it works with new AC_DEFINE.
* system.h: Remove last vestiges of USG; instead, use specific
test for TM_IN_SYS_TIME to determine whether to include time.h
or sys/time.h.
* src/Makefile.in (install): Rewrite the test for whether to install
mvdir so that it doesn't cause gratuitous failures with broken shells.
Split long rule so the pieces fit in 80-column lines.
Thu Apr 15 23:44:01 1993 Jim Meyering (meyering@comco.com)
* lib/Makefile.in (posixtm.c): Add dependency on getdate.c to enforce
sequential invocations of YACC.
* (posixtm.c, getdate.c): Remove use of `bison -o' and associated
conditional rename commands -- not needed since the parser generators
won't be run in parallel; now bison (when used) is always invoked
with -y.
Tue Apr 13 09:18:18 1993 Jim Meyering (meyering@comco.com)
* configure.in: Find a parser generator.
* Makefile.in [MDEFINES]: Add YACC to the list of variables passed to
sub-makes.
* lib/Makefile.in (posixtm.c, getdate.c): Try first to build with
`bison -o' -- for parallel makes. If that fails, use $(YACC).
* posixtm.y [HAVE_MEMCPY && !HAVE_BCOPY]: Define bcopy in terms
of memcpy for old versions of bison that generate parsers that
use bcopy.
* configure.in: Add tests for memcpy and bcopy.
Mon Apr 12 23:02:14 1993 Jim Meyering (meyering@comco.com)
* configure.in (mounted, space): Add filesystem checks for DEC Alpha
running OSF/1 to complement new code in mountlist.c and fsusage.c.
* lib/mountlist.c (read_filesystem_list) [MOUNTED_GETFSSTAT]: Add code
to do it the OSF/1 way on a DEC alpha.
From Brian Fox (bfox@tinker.crseo.ucsb.edu).
* lib/fsusage.c (get_fs_usage) [STATFS_OSF1]: Add code to call OSF/1's
variant of statfs. From Brian Fox (bfox@tinker.crseo.ucsb.edu).
Sun Apr 11 20:29:31 1993 Jim Meyering (meyering@comco.com)
* df.c (main, show_dev): Don't list dummy (automounter) filesystems
unless they're explicitly listed on the command line or if the -a
option is given.
Fri Apr 9 11:40:48 1993 Jim Meyering (meyering@comco.com)
* src/Makefile.in [.c.o]: Put CFLAGS after include directives.
Wed Apr 7 23:54:48 1993 Jim Meyering (meyering@comco.com)
* eaccess.c: Undefine NGROUPS_MAX before redefining it.
From ghazi@caip.rutgers.edu (Kaveh R. Ghazi).
Mon Apr 5 20:14:17 1993 Jim Meyering (meyering@comco.com)
* chgrp.c, chmod.c, chown.c, install.c, ls.c, mkfifo.c, mknod.c,
touch.c: Add `case 0: break;' for long-only options help and version.
Sun Apr 4 09:38:00 1993 Jim Meyering (meyering@comco.com)
* src/*.c (usage): Mention --help and --version.
(main): Handle flag_help and flag_version before checking for
invocation errors.
* cp.c (copy): Declare to be static.
* cp.c (copy, make_path, re_protect): Explicitly cast alloca return
value to (char *).
* ln.c (do_link): Ditto
* mv.c (do_move): Ditto
* makepath.c (make_path): Ditto
* lib/eaccess.c (eaccess_stat): Cast to unsigned the value to
be right-shifted to avoid ANSI vs K&R semantic ambiguity.
* src/Makefile.in (incl): New variable.
* chown.c (main): Explicitly cast -1 to [ug]id_t to avoid compiler
warnings.
* cp.h: Remove unneeded extern dcl of exit_status.
* basename.c [rindex]: Don't redefine it.
* system.h [rindex, incl, bcopy, bzero]: Ditto.
* userspec.c [index]: Ditto.
* Makefile.in [CFLAGS, LDFLAGS]: Don't hard-code these; get their
definitions from configure.
* configure.in [CFLAGS, LDFLAGS]: Assign reasonable defaults.
Sat Apr 3 18:17:23 1993 Jim Meyering (meyering@comco.com)
* Makefile.in [Makefile]: Add dependencies and a rule to remake it.
[targets that cd then run make in subdirectories]: Don't depend
on `cd ..'; use a subshell instead.
[info, install-info, dvi, check, installcheck]: New targets but no
rules; comply with standards.
* src/Makefile.in [.c.o, dir.o, vdir.o]: Put CFLAGS after DEFS and
CPPFLAGS per standards.texi.
Use automatically generated dependencies.
* mvdir.c (main): Remove dcl of unused variable.
Thu Apr 1 18:05:48 1993 Jim Meyering (meyering@comco.com)
* install.c, chgrp.c, dd.c [isascii]: Undefine before redefining.
* ls.c: Move some dcls so they appear before first function.
* all programs: Add --help and --version options.
* version.c: Remove `Version: ' and newlines from version string.
* dd.c: Convert usage to take no arguments.
* lib/Makefile.in [DISTFILES]: Add version.h.
Wed Mar 31 22:03:28 1993 Jim Meyering (meyering@comco.com)
* configure.in [MVDIR]: Don't quote right hand side.
* backupfile.c, chgrp.c, install.c: Define isascii macro to be 1
also if STDC_HEADERS.
Tue Mar 30 17:42:11 1993 david d `zoo' zuhn (zoo at cirdan.cygnus.com)
* ls.c: Add -G,--no-group option to inhibit display of group
infomation.
* ls.1: Document it.
Mon Mar 29 22:22:40 1993 Jim Meyering (meyering@comco.com)
* system.h [ST_NBLOCKS]: Check also for __hpux. From Henrik B}kman
<Henrik.Bakman@csd.uu.se>.
Sun Mar 28 21:22:30 1993 Jim Meyering (meyering@comco.com)
* Makefile.in (dist): Use cp when hard link fails.
Use tar-1.11.2's -z option instead of -Z.
* makepath.c [index]: Don't redefine.
Fri Mar 26 00:32:39 1993 Jim Meyering (meyering@comco.com)
* df.c (add_excluded_fs_type, excluded_fs_type): New functions adding
support for --exclude-type option. Derived from Kaveh R. Ghazi
<ghazi@caip.rutgers.edu>.
* ls.c (decode_switches, print_long_format): New option: --full-time.
From K. Richard Pixley (rich@rtl.cygnus.com)
Thu Mar 25 21:02:36 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
* dirname.c [rindex]: Don't redefine.
Tue Mar 23 23:13:33 1993 Jim Meyering (meyering@comco.com)
* ls.c (gobble_file): Don't stat symlinks unless we need to.
From Mike Rendell <michael@mercury.cs.mun.ca>.
* dd.c (copy, copy_with_block, copy_with_block): Decrement
pending_spaces only if it's > 0. The following command didn't
terminate:
perl -e 'print "a a\n";'| dd of=/dev/null ibs=1 cbs=3 conv=unblock
With suggestions from Chris Weber <weber@bucknell.edu>,
Marlys.A.Nelson@uwrf.edu, and Albert-Lunde@nwu.edu.
Fri Mar 05 00:02:53 1993 Jim Meyering (meyering@comco.com)
* chmod.c: Add long-named options.
Mon Feb 15 23:34:55 1993 Jim Meyering (meyering@comco.com)
* rm.c (remove_file): Don't ask about overriding a mode if the
target is a symbolic link -- some systems (like SGI's Irix 4.0)
zero the permissions fields of symbolic links.
From Arne Henrik Juul (arnej@imf.unit.no).
Fri Dec 11 16:46:50 1992 David J. MacKenzie (djm@kropotkin.gnu.ai.mit.edu)
* rm.c (main): If -f is given, don't complain if no file args
are given.
Tue Dec 8 21:09:16 1992 David J. MacKenzie (djm@kropotkin.gnu.ai.mit.edu)
* posixtm.y: Include alloca.h if HAVE_ALLOCA_H, not if sparc.
Mon Dec 7 20:09:59 1992 Jim Meyering (meyering@idefix.comco.com)
* install.c (isnumber), chgrp.c (change_file_group): Define ISDIGIT
@@ -12,6 +496,35 @@ Wed Dec 2 12:28:10 1992 Jim Meyering (meyering@idefix.comco.com)
struct option to use new macros from getopt.h: no_argument,
required_argument, and optional_argument.
Tue Nov 24 07:54:45 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
* system.h: Use HAVE_FCNTL_H instead of USG.
* xgetcwd.c: Use HAVE_GETCWD instead of USG.
* backupfile.c, basename.c, dirname.c, idcache.c, makepath.c,
mountlist.c, stripslash.c, userspec.c, xstrdup.c, system.h:
Use HAVE_STRING_H instead of USG.
* system.h: Use SYSDIR and NDIR instead of USG.
Define direct as dirent, not vice-versa.
* ls.c, rm.c, backupfile.c, savedir.c: Use `struct dirent',
not `struct direct'.
Thu Nov 12 23:10:56 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
* system.h: If dirent is #defined, don't define direct as dirent;
for Sinix. Derived from Heinfried Korn (korn@med-in.uni-sb.de).
Mon Nov 9 14:13:57 1992 Jim Meyering (meyering@idefix.comco.com)
* fsusage.c (adjust_blocks): Reverse Oct 31 change --
the function is more readable than the macro.
* 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.'
Sat Oct 31 16:32:17 1992 Jim Meyering (meyering@idefix.comco.com)
* fsusage.c (adjust_blocks): Convert to a macro. The static
@@ -23,6 +536,11 @@ Sat Oct 31 16:32:17 1992 Jim Meyering (meyering@idefix.comco.com)
* dd.c (swab_buffer): Fix typo that incremented pointer instead
of counter. Add braces around static struct initializers.
Fri Oct 30 11:40:58 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
* ln.c, cp.c (main): Make -s on systems without symlinks an
error, not a warning.
Thu Oct 29 14:57:21 1992 David J. MacKenzie (djm@kropotkin.gnu.ai.mit.edu)
* Version 3.4.
@@ -369,7 +887,7 @@ Thu Oct 24 23:50:46 1991 David J. MacKenzie (djm at wookumz.gnu.ai.mit.edu)
* chown.c (change_file_owner), chgrp.c (change_file_group):
don't skip symlinks, since the chown system call works on them.
Fri 18 Oct 1991 23:29:24 Jim Meyering (meyering at wombat)
Fri 18 Oct 1991 23:29:24 Jim Meyering (meyering at wombat)
* configure: fixed test to detect sequent's strange interpretation
of utime(file, NULL).
@@ -442,12 +960,12 @@ Wed Aug 21 13:03:14 1991 David J. MacKenzie (djm at wookumz.gnu.ai.mit.edu)
like Sequents.
* configure: Check sys/dir.h for 'void closedir'.
Tue Aug 20 22:22:47 1991 Jim Meyering (meyering at nutrimat)
Tue Aug 20 22:22:47 1991 Jim Meyering (meyering at nutrimat)
* mvdir.c (main): Clean up loop to stat component
directories -- as in makepath and pathchk.
Tue Aug 20 22:10:47 1991 Jim Meyering (meyering at nutrimat)
Tue Aug 20 22:10:47 1991 Jim Meyering (meyering at nutrimat)
* dirname.c (dirname): Allocate exact amount of space
needed for result.
@@ -1584,9 +2102,9 @@ Thu Mar 15 12:33:23 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
* ls.c (print_type_indicator): Don't print a '*' next to
executable block or character special files.
* chmod.c (error): New function, replacing nonfatal_perror,
memory_out, and invalid_mode.
Global: Call error instead of the above functions.
* chmod.c (error): New function, replacing nonfatal_perror,
memory_out, and invalid_mode.
Global: Call error instead of the above functions.
(change_dir_mode): Make the new size of the path twice the
size of the name that was too long, rather than twice its old
size.

View File

@@ -1,3 +1,40 @@
Major changes in release 3.9:
* configure uses config.h, so DEFS won't exceed preprocessor limits of
some compilers on the number of symbols defined via -D.
* ls and cp can handle mount points on more systems
* cp, mkdir, and rmdir long option --path renamed to --parents; --path
will still work for a while
* cp, ln, and mv convert `cp A B/' to cp A B/A when A is not a directory.
This change affects only the two-argument form of the commands. It makes
such commands fail when the target has a trailing slash but is not a
directory or symlink to a directory and the source is not a directory.
They used to succeed, ignoring the implicitly contradictory trailing slash.
Major changes in release 3.8:
* install isn't as likely to produce spurious errors
* avoid redundant compilations for `dir' and `vdir';
* configure properly defines STAT_STATFS2_BSIZE on a Pyramid MIServer
running OSx 5.1
Major changes in release 3.7:
* none
Major changes in release 3.6:
* `ln -s dir_pathname .' works when the pathname has a trailing slash
* with the --version option programs print the version and exit immediately
* GNU ls -f works like Unix ls -f
* mktime replacement works
Major changes in release 3.5:
* adds support for DEC Alpha under OSF/1
* configuring with gcc uses CFLAGS='-g -O' by default
* all programs accept --help and --version options
* long-named options must be introduced with `--'; `+' is no longer
accepted since it is incompatible with the POSIX.2 standard
* chmod accepts long-named options
* dd conv=unblock doesn't hang
* new df option --exclude=fstype
* new ls option --full-time
Major changes in release 3.4:
* cp -p and mv preserve setuid and setgid bits
* chown works on systems where sizeof(uid_t) != sizeof(int)

View File

@@ -1,8 +1,107 @@
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
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
* system.h: Don't define r?index, bcopy... if they're already defined.
Thu Mar 25 22:41:01 1993 Jim Meyering (meyering@comco.com)
* configure.in: Add AC_IRIX_SUN to get -lsun because
Irix-4.0.5's libc.a doesn't have yp/NIS entrypoints.
From Kjetil Wiekhorst J|rgensen <jorgens@pvv.unit.no>.
Fri Mar 05 00:02:53 1993 Jim Meyering (meyering@comco.com)
* date.c: Add long-named options.
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)
@@ -12,12 +111,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.

View File

@@ -1,3 +1,6 @@
Major changes in release 1.9:
* fix bug in stty
Major changes in release 1.8:
* add echo command
* fix some incorrect warnings in pathchk

View File

@@ -1,3 +1,208 @@
Thu Sep 9 21:52:10 1993 Jim Meyering (meyering@comco.com)
* src/*.c: Print version on standard output, not stderr.
* configure.in: Add AC_LONG_64_BITS.
* memchr.c: Use #ifdef LONG_64_BITS instead of
`if (sizeof(longword) > 4)'.
Tue Jul 27 22:19:39 1993 Jim Meyering (meyering@comco.com)
* cat.c (cat): Don't fail just because ioctl (d, FIONREAD,... can't
always handle devices. Ignore errno == EINVAL and errno == ENODEV.
`cat -v /dev/null' was failing on many systems.
* cut.c (cut_fields): Don't strip off trailing delimiter e.g.
`echo 'a:b:c:' | cut -d: -f3-' should print `c:', not just `c'.
From William Dowling <will@franklin.com>.
Thu May 27 01:37:51 1993 Jim Meyering (meyering@comco.com)
* Version 1.8.
* memchr.c: De-ansify the fixed version from glibc.
It is supposed to work on systems with 64-bit long ints.
Mon May 24 00:32:43 1993 Jim Meyering (meyering@comco.com)
* Version 1.7.
Sat May 22 02:13:12 1993 Jim Meyering (meyering@comco.com)
* Version 1.6.
Fri May 21 22:57:53 1993 Jim Meyering (meyering@comco.com)
* pr.c (cols_ready_to_print): New function. It replaces a global
variable by the same name and computes on the fly the value that
was supposed to be maintained through that variable. This should
put to rest the `pr -2a' bug.
(main): Don't let getopt_long reorder arguments so we can
distinguish between `pr -1 -2' and `pr -12'. Rework handling of
-n and +n options.
* fold.c: Declare xmalloc.
Wed May 19 19:12:18 1993 Karl Berry (karl@owl.hq.ileaf.com)
* sort.c (main): fflush before exit, so a closed stdout doesn't lose.
Tue May 18 23:49:26 1993 Jim Meyering (meyering@comco.com)
* mkinstalldirs: New file.
* Makefile.in (installdirs): Use it to create installation directories.
Fri May 14 23:45:52 1993 Jim Meyering (meyering@comco.com)
* all source: With --version, print version and exit immediately.
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.
* tail.c (main): Remove --compatible since `+1f' may be used
to get the BSD `-0f' behavior portably.
* fold.c (main): Turn -N arguments, where N is a digit, into -wN.
From Ian Lance Taylor (ian@cygnus.com).
Mon May 10 22:33:44 1993 Jim Meyering (meyering@comco.com)
* tail.c (main): New option -C, --compatible to make `tail -0f'
work like `tail +1f' for compatibility with BSD tail.
Thu May 6 23:28:56 1993 Jim Meyering (meyering@comco.com)
* pr.c (print_page): Decrement cols_ready_to_print even when
lines_to_print == 0. The command `echo |pr -2ta' *still* didn't
terminate. Add parentheses for clarity.
Mon May 3 23:57:47 1993 Jim Meyering (meyering@comco.com)
* Version 1.5.
* od.c (main): Remove set-but-not-used variable, `usage_error'.
* split.c (main): Call usage with an argument.
Sun May 2 16:05:04 1993 Jim Meyering (meyering@comco.com)
* configure.in: Reverse if-else branches in AC_TEST_PROGRAM test
for 8-bit clean memcmp.
* cat.c (usage, main): Remove unused argument.
* csplit.c (remove_line): Remove set-but-not-used variable, `line_got.'
(check_for_offset): Remove unused argument `argnum.'
* configure.in: Add AC_SIZE_T.
Sat May 1 09:03:19 1993 Jim Meyering (meyering@comco.com)
* uniq.c (main): Interpret non-option arguments with a leading `+'
only if we haven't seen `--'.
* tr.c (main): Change variable name to avoid shadowed dcl.
* wc.c (write_counts): Ditto.
* sum.1: Make documentation agree with the code.
* od.c: Depend only on HAVE_LONG_DOUBLE for long double support.
Fri Apr 30 20:16:03 1993 Jim Meyering (meyering@comco.com)
* configure.in [AC_HAVE_HEADERS]: Add limits.h.
* configure.in [CFLAGS, LDFLAGS]: Assign reasonable defaults.
* od.c (parse_old_offset): Don't use prototype in function
definition. Remove unnecessary conjunct from test for hexadecimal
prefix.
* od.c: Depend on __GNUC__ || HAVE_LONG_DOUBLE rather than __STDC__
for long double support; there are compilers (Stardent Vistra svr4)
without long double but still define __STDC__.
Thu Apr 29 02:01:27 1993 Jim Meyering (meyering@comco.com)
* src/*.c and man/*.c except for sort: Add --help and --version
options.
* pr.c: Convert to use getopt_long.
* lib/memcmp.c: Use version from glibc.
[WORDS_BIGENDIAN]: Test this instead of the using glibc's
__BYTE_ORDER macro.
* configure.in: Use AC_WORDS_BIGENDIAN to set it.
* od.c (parse_old_offset): Allow `0X' as well as `0x' prefix to
indicate hex.
* Makefile.in (dist): Depend on Makefile so that changes to
Makefile.in (like adding new files to DISTRIB) are reflected
in the new distribution.
Fri Apr 23 21:53:47 1993 Jim Meyering (meyering@comco.com)
* {lib,src}/Makefile.in [.c.o]: Make CPPFLAGS and CFLAGS follow
other options so users can use them to override DEFS.
* src/Makefile.in [.c.o]: Add -I$(srcdir) for version.h.
* Makefile.in [CFLAGS, LDFLAGS]: Don't set to -g explicitely;
configure's AC_SUBST will set these.
* Makefile.in [Makefile]: Add dependencies and a rule to remake it.
[targets that cd then run make in subdirectories]: Don't depend
on `cd ..'; use a subshell instead.
* Makefile.in [info, install-info, dvi, check, installcheck]:
New targets but no rules; comply with standards.
* configure.in [CFLAGS]: Default to -g -O if CC is gcc and the user
hasn't specified CFLAGS.
[LDFLAGS]: Substitute into Makefile.
Tue Mar 30 21:36:11 1993 Jim Meyering (meyering@comco.com)
* od.c: New option --compatible, -C.
(parse_old_offset): New function.
* od.1: Document new option.
Mon Mar 29 21:27:56 1993 Jim Meyering (meyering@comco.com)
* cut.c, expand.c, join.c, nl.c: Always call error with errno
(not zero) after failed fclose or non-zero ferror.
Sun Mar 28 16:59:31 1993 Mike Haertel (mike@cs.uoregon.edu)
* configure.in: Add check for working memcmp; use GNU's if
the system's doesn't grok the 8th bit.
* memcmp.c: Fix it so it groks the 8th bit.
TODO: We really need to provide a fast memcmp, since most
machines will have a broken memcmp. Probably should get
the one from glibc.
* sort.c (mergefps): Maintain keybeg and keylim when copying
the current line to `saved'.
(numcompare): Skip white space here since -n no longer implies -b.
(getmonth): Skip white space here since -M no longer implies -b.
(compare): Completely overhauled to make the 8th bit work right,
also to properly handle the global reverse option.
(set_ordering): -n no longer implies -b, according to Posix.
For consistency, -M also no longer implies -b.
(main): Correct treatment of -r and global keys.
(findlines): Clear keybeg and keylim if no keys are used.
(sort): Avoid overwriting tempfiles[] array bounds.
Sun Mar 21 22:29:29 1993 Jim Meyering (meyering@comco.com)
* pr.c (close_file): Reverse May 13, '92 change, but add the condition
that cols_ready_to_print not be decremented when printing across.
The command `echo |pr -2ta' didn't terminate.
(print_page): Rewrite conditional (that had side effects in second
conjunct) using nested if statements to make it clear that we do
indeed want those semantics.
Tue Jan 19 13:35:24 1993 David J. MacKenzie (djm@kropotkin.gnu.ai.mit.edu)
* Version 1.4.

View File

@@ -1,10 +1,32 @@
Major changes in release 1.9:
* cat -v /dev/null works on more systems
Major changes in release 1.8:
* added non-ANSIfied version of memchr.c from GNU libc.
Major changes in release 1.7:
* none
Major changes in release 1.6:
* with the --version option programs print the version and exit immediately
* pr -2a really terminates
* pr -n produces multi-column output
Major changes in release 1.5:
* sort is 8-bit clean
* sort's -n and -M options no longer imply -b
* several bugs in sort have been fixed
* all programs accept --help and --version options
* od --compatible accepts pre-POSIX arguments
* pr -2a terminates
Major changes in release 1.4:
* add od and cksum programs
* move cmp to GNU diff distribution
* tail -f works for multiple files
* pr prints the file name in error messages
* fix some off by 1 errors in pr and fold
* optimize wc -c on regular files
* sort handles `-' argument correctly
* sort supports -T option
* tr ranges like a-a work
* tr x '' fails gracefully
* default sum output format is BSD compatible

View File

@@ -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;
if (argc == 1 || argc > 3)
program_name = argv[0];
while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
{
fprintf (stderr, "Usage: %s name [suffix]\n", argv[0]);
exit (1);
switch (c)
{
case 0:
break;
default:
usage ();
}
}
strip_trailing_slashes (argv[1]);
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
name = basename (argv[1]);
if (show_help)
usage ();
if (argc - optind == 0 || argc - optind > 2)
usage ();
strip_trailing_slashes (argv[optind]);
name = basename (argv[optind]);
if (argc == 3)
remove_suffix (name, argv[2]);
remove_suffix (name, argv[optind + 1]);
puts (name);

View File

@@ -29,6 +29,7 @@
#include <sys/ioctl.h>
#endif
#include "system.h"
#include "version.h"
#define max(h,i) ((h) > (i) ? (h) : (i))
@@ -73,16 +74,12 @@ static int newlines2 = 0;
static int exit_stat = 0;
static void
usage (reason)
char *reason;
usage ()
{
if (reason != NULL)
fprintf (stderr, "%s: %s\n", program_name, reason);
fprintf (stderr, "\
Usage: %s [-benstuvAET] [--number] [--number-nonblank] [--squeeze-blank]\n\
[--show-nonprinting] [--show-ends] [--show-tabs] [--show-all]\n\
[file...]\n",
[--help] [--version] [file...]\n",
program_name);
exit (2);
@@ -132,8 +129,16 @@ main (argc, argv)
int mark_line_ends = 0;
int quote = 0;
int output_tabs = 1;
/* If non-zero, call cat, otherwise call simple_cat to do the actual work. */
int options = 0;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const long_options[] =
{
{"number-nonblank", no_argument, NULL, 'b'},
@@ -143,6 +148,8 @@ main (argc, argv)
{"show-ends", no_argument, NULL, 'E'},
{"show-tabs", no_argument, NULL, 'T'},
{"show-all", no_argument, NULL, 'A'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -153,60 +160,79 @@ main (argc, argv)
while ((c = getopt_long (argc, argv, "benstuvAET", long_options, (int *) 0))
!= EOF)
{
options++;
switch (c)
{
case 0:
break;
case 'b':
++options;
numbers = 1;
numbers_at_empty_lines = 0;
break;
case 'e':
++options;
mark_line_ends = 1;
quote = 1;
break;
case 'n':
++options;
numbers = 1;
break;
case 's':
++options;
squeeze_empty_lines = 1;
break;
case 't':
++options;
output_tabs = 0;
quote = 1;
break;
case 'u':
/* We provide the -u feature unconditionally. */
options--;
break;
case 'v':
++options;
quote = 1;
break;
case 'A':
++options;
quote = 1;
mark_line_ends = 1;
output_tabs = 0;
break;
case 'E':
++options;
mark_line_ends = 1;
break;
case 'T':
++options;
output_tabs = 0;
break;
default:
usage ((char *) 0);
usage ();
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
output_desc = 1;
/* Get device, i-node number, and optimal blocksize of output. */
@@ -278,8 +304,9 @@ main (argc, argv)
goto contin;
}
/* Select which version of `cat' to use. If any options (more than -u)
were specified, use `cat', otherwise use `simple_cat'. */
/* Select which version of `cat' to use. If any options (more than -u,
--version, or --help) were specified, use `cat', otherwise use
`simple_cat'. */
if (options == 0)
{
@@ -302,7 +329,7 @@ main (argc, argv)
may grow by a factor of 4 (by the prepending of M-^). If all
characters do, and no newlines appear in this block of input, we
will have at most (OUTSIZE - 1 + INSIZE) bytes in the buffer. If
the last character in the preceeding block of input was a
the last character in the preceding block of input was a
newline, a line number may be written (according to the given
options) as the first thing in the output buffer. (Done after the
new input is read, but before processing of the input begins.) A
@@ -424,7 +451,7 @@ cat (inbuf, insize, outbuf, outsize, quote,
/* Number of characters read by the last read call. */
int n_read;
/* Determines how many consequtive newlines there have been in the
/* Determines how many consecutive newlines there have been in the
input. 0 newlines makes NEWLINES -1, 1 newline makes NEWLINES 1,
etc. Initially 0 to indicate that we are at the beginning of a
new line. The "state" of the procedure is determined by
@@ -484,8 +511,12 @@ cat (inbuf, insize, outbuf, outsize, quote,
&& ioctl (input_desc, FIONREAD, &n_to_read) < 0)
{
/* Ultrix returns EOPNOTSUPP on NFS;
HP-UX returns ENOTTY on pipes. */
if (errno == EOPNOTSUPP || errno == ENOTTY)
HP-UX returns ENOTTY on pipes.
SunOS returns EINVAL and
More/BSD returns ENODEV on special files
like /dev/null. */
if (errno == EOPNOTSUPP || errno == ENOTTY
|| errno == EINVAL || errno == ENODEV)
use_fionread = 0;
else
{

View File

@@ -17,14 +17,27 @@
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <grp.h>
#include <getopt.h>
#include "system.h"
#include "version.h"
#ifndef isascii
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
#define isascii(c) 1
#endif
@@ -70,6 +83,12 @@ static int changes_only;
/* The name of the group to which ownership of the files is being given. */
static char *groupname;
/* 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[] =
{
{"recursive", no_argument, 0, 'R'},
@@ -77,6 +96,8 @@ static struct option const long_options[] =
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -97,6 +118,8 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'R':
recurse = 1;
break;
@@ -115,6 +138,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind >= argc - 1)
usage ();
@@ -276,7 +308,7 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-Rcfv] [--recursive] [--changes] [--silent] [--quiet]\n\
[--verbose] group file...\n",
[--verbose] [--help] [--version] group file...\n",
program_name);
exit (1);
}

View File

@@ -23,11 +23,23 @@
David MacKenzie <djm@gnu.ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "modechange.h"
#include "system.h"
#include "version.h"
int lstat ();
@@ -57,6 +69,24 @@ static int verbose;
/* If nonzero, describe only modes that change. */
static int changes_only;
/* 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[] =
{
{"recursive", no_argument, 0, 'R'},
{"changes", no_argument, 0, 'c'},
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
/* Parse the ASCII mode given on the command line into a linked list
of `struct mode_change' and apply that to each file argument. */
@@ -78,12 +108,15 @@ main (argc, argv)
{
thisind = optind ? optind : 1;
c = getopt (argc, argv, "RcfvrwxXstugoa,+-=");
c = getopt_long (argc, argv, "RcfvrwxXstugoa,+-=", long_options,
(int *) 0);
if (c == EOF)
break;
switch (c)
{
case 0:
break;
case 'r':
case 'w':
case 'x':
@@ -120,8 +153,18 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (modeind == 0)
modeind = optind++;
if (optind >= argc)
usage ();
@@ -262,7 +305,8 @@ static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-Rcfv] mode file...\n\
Usage: %s [-Rcfv] [--recursive] [--changes] [--silent] [--quiet]\n\
[--verbose] [--help] [--version] mode file...\n\
mode is [ugoa...][[+-=][rwxXstugo...]...][,...] or octal number\n",
program_name);
exit (1);

View File

@@ -28,6 +28,17 @@
Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
@@ -35,6 +46,7 @@
#include <grp.h>
#include <getopt.h>
#include "system.h"
#include "version.h"
#ifndef _POSIX_VERSION
struct passwd *getpwnam ();
@@ -81,6 +93,12 @@ static char *username;
/* The name of the group to which ownership of the files is being given. */
static char *groupname;
/* 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[] =
{
{"recursive", no_argument, 0, 'R'},
@@ -88,6 +106,8 @@ static struct option const long_options[] =
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -96,8 +116,8 @@ main (argc, argv)
int argc;
char **argv;
{
uid_t user = -1; /* New uid; -1 if not to be changed. */
gid_t group = -1; /* New gid; -1 if not to be changed. */
uid_t user = (uid_t) -1; /* New uid; -1 if not to be changed. */
gid_t group = (uid_t) -1; /* New gid; -1 if not to be changed. */
int errors = 0;
int optc;
char *e;
@@ -110,6 +130,8 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'R':
recurse = 1;
break;
@@ -128,6 +150,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind >= argc - 1)
usage ();
@@ -265,7 +296,7 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-Rcfv] [--recursive] [--changes] [--silent] [--quiet]\n\
[--verbose] [user][:.][group] file...\n",
[--verbose] [--help] [--version] [user][:.][group] file...\n",
program_name);
exit (1);
}

View File

@@ -103,14 +103,32 @@ main ()
#else /* !CRCTAB */
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
/* Number of bytes to read at once. */
#define BUFLEN (1 << 16)
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 then 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 unsigned long const crctab[256] =
{
0x0,
@@ -167,9 +185,6 @@ static unsigned long const crctab[256] =
0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
};
/* The name this program was run with. */
char *program_name;
/* Nonzero if any of the files read were the standard input. */
static int have_read_stdin;
@@ -244,27 +259,55 @@ cksum (file, print_name)
return 0;
}
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [--help] [--version] [file...]\n", program_name);
exit (1);
}
void
main (argc, argv)
int argc;
char **argv;
{
int i, c;
int errors = 0;
program_name = argv[0];
have_read_stdin = 0;
if (argc == 1)
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 (optind >= argc)
{
if (cksum ("-", 0) < 0)
errors = 1;
}
else
{
int optind;
for (optind = 1; optind < argc; ++optind)
if (cksum (argv[optind], 1) < 0)
for (i = optind; i < argc; i++)
if (cksum (argv[i], 1) < 0)
errors = 1;
}

View File

@@ -22,9 +22,13 @@
#include <sys/types.h>
#include "system.h"
#include "linebuffer.h"
#include "version.h"
#define min(x, y) ((x) < (y) ? (x) : (y))
/* The name this program was run with. */
char *program_name;
/* If nonzero, print lines that are found only in file 1. */
static int only_file_1;
@@ -34,8 +38,18 @@ static int only_file_2;
/* If nonzero, print lines that are found in both files. */
static int both;
/* 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 then 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}
};
void error ();
static int compare_files ();
@@ -55,9 +69,12 @@ main (argc, argv)
only_file_2 = 1;
both = 1;
while ((c = getopt (argc, argv, "123")) != EOF)
while ((c = getopt_long (argc, argv, "123", long_options, (int *) 0)) != EOF)
switch (c)
{
case 0:
break;
case '1':
only_file_1 = 0;
break;
@@ -74,6 +91,15 @@ main (argc, argv)
usage ();
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind + 2 != argc)
usage ();
@@ -216,6 +242,7 @@ writeline (line, stream, class)
static void
usage ()
{
fprintf (stderr, "Usage: %s [-123] file1 file2\n", program_name);
fprintf (stderr, "Usage: %s [-123] [--help] [--version] file1 file2\n",
program_name);
exit (1);
}

108
src/cp.c
View File

@@ -20,10 +20,23 @@
#ifdef _AIX
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include "cp.h"
#include "backupfile.h"
#include "version.h"
#ifndef _POSIX_VERSION
uid_t geteuid ();
@@ -40,6 +53,7 @@ struct dir_attr
};
char *dirname ();
char *xstrdup ();
enum backup_type get_version ();
int eaccess_stat ();
@@ -56,13 +70,13 @@ static int re_protect ();
/* Initial number of entries in the inode hash table. */
#define INITIAL_ENTRY_TAB_SIZE 70
/* The invocation name of this program. */
char *program_name;
/* A pointer to either lstat or stat, depending on
whether dereferencing of symlinks is done. */
static int (*xstat) ();
/* The invocation name of this program. */
char *program_name;
/* If nonzero, copy all files except directories and, if not dereferencing
them, symbolic links, as if they were regular files. */
static int flag_copy_as_regular = 1;
@@ -117,6 +131,12 @@ static int umask_kill;
/* This process's effective user ID. */
static uid_t myeuid;
/* 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_opts[] =
{
{"archive", no_argument, NULL, 'a'},
@@ -126,6 +146,7 @@ static struct option const long_opts[] =
{"link", no_argument, NULL, 'l'},
{"no-dereference", no_argument, &flag_dereference, 0},
{"one-file-system", no_argument, &flag_one_file_system, 1},
{"parents", no_argument, &flag_path, 1},
{"path", no_argument, &flag_path, 1},
{"preserve", no_argument, &flag_preserve, 1},
{"recursive", no_argument, NULL, 'R'},
@@ -134,6 +155,8 @@ static struct option const long_opts[] =
{"update", no_argument, &flag_update, 1},
{"verbose", no_argument, &flag_verbose, 1},
{"version-control", required_argument, NULL, 'V'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -220,8 +243,7 @@ main (argc, argv)
#ifdef S_ISLNK
flag_symbolic_link = 1;
#else
error (0, 0, "symbolic links not supported; making hard links");
flag_hard_link = 1;
error (1, 0, "symbolic links are not supported on this system");
#endif
break;
@@ -250,6 +272,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage (NULL);
if (flag_hard_link && flag_symbolic_link)
usage ("cannot make both hard and symbolic links");
@@ -341,7 +372,7 @@ do_copy (argc, argv)
dst_path = xmalloc (strlen (dest) + strlen (arg) + 2);
stpcpy (stpcpy (stpcpy (dst_path, dest), "/"), arg);
/* For --path, we have to make sure that the directory
/* For --parents, we have to make sure that the directory
dirname (dst_path) exists. We may have to create a few
leading directories. */
parent_exists = !make_path (dst_path,
@@ -357,7 +388,7 @@ do_copy (argc, argv)
ap = basename (arg);
/* For `cp -R source/.. dest', don't copy into `dest/..'. */
if (!strcmp (ap, ".."))
dst_path = dest;
dst_path = xstrdup (dest);
else
{
dst_path = xmalloc (strlen (dest) + strlen (ap) + 2);
@@ -382,6 +413,7 @@ do_copy (argc, argv)
}
}
free (dst_path);
++optind;
if (optind == argc - 1)
break;
@@ -390,9 +422,41 @@ do_copy (argc, argv)
}
else if (argc - optind == 2)
{
char *new_dest;
char *source;
struct stat source_stats;
if (flag_path)
usage ("when preserving paths, last argument must be a directory");
return copy (argv[optind], dest, new_dst, 0, (struct dir_list *) 0);
source = argv[optind];
/* When the destination is specified with a trailing slash and the
source exists but is not a directory, convert the user's command
`cp source dest/' to `cp source dest/basename(source)'. */
if (dest[strlen (dest) - 1] == '/'
&& lstat (source, &source_stats) == 0
&& !S_ISDIR (source_stats.st_mode))
{
char *source_base;
char *tmp_source;
tmp_source = (char *) alloca (strlen (source) + 1);
strcpy (tmp_source, source);
strip_trailing_slashes (tmp_source);
source_base = basename (tmp_source);
new_dest = (char *) alloca (strlen (dest) + 1 +
strlen (source_base) + 1);
stpcpy (stpcpy (stpcpy (new_dest, dest), "/"), source_base);
}
else
{
new_dest = dest;
}
return copy (source, new_dest, new_dst, 0, (struct dir_list *) 0);
}
else
usage ("when copying multiple files, last argument must be a directory");
@@ -407,7 +471,7 @@ do_copy (argc, argv)
devices and inodes of parent directories of SRC_PATH.
Return 0 if successful, 1 if an error occurs. */
int
static int
copy (src_path, dst_path, new_dst, device, ancestors)
char *src_path;
char *dst_path;
@@ -514,7 +578,7 @@ copy (src_path, dst_path, new_dst, device, ancestors)
char *tmp_backup = find_backup_file_name (dst_path);
if (tmp_backup == NULL)
error (1, 0, "virtual memory exhausted");
dst_backup = alloca (strlen (tmp_backup) + 1);
dst_backup = (char *) alloca (strlen (tmp_backup) + 1);
strcpy (dst_backup, tmp_backup);
free (tmp_backup);
if (rename (dst_path, dst_backup))
@@ -694,17 +758,13 @@ copy (src_path, dst_path, new_dst, device, ancestors)
}
else
#ifdef S_ISLNK
#ifdef _AIX
#define LINK_BUF PATH_MAX
#else
#define LINK_BUF src_sb.st_size
#endif
if (S_ISLNK (src_type))
{
char *link_val = (char *) alloca (LINK_BUF + 1);
char *link_val;
int link_size;
link_size = readlink (src_path, link_val, LINK_BUF);
link_val = (char *) alloca (PATH_MAX + 2);
link_size = readlink (src_path, link_val, sizeof (link_val) - 1);
if (link_size < 0)
{
error (0, errno, "cannot read symbolic link `%s'", src_path);
@@ -784,7 +844,7 @@ un_backup:
}
/* Ensure that the parent directory of CONST_DIRPATH exists, for
the --path option.
the --parents option.
SRC_OFFSET is the index in CONST_DIRPATH (which is a destination
path) of the beginning of the source directory name.
@@ -817,13 +877,13 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
char *tmp_dst_dirname; /* Leading path of `dirpath', malloc. */
char *dst_dirname; /* Leading path of `dirpath', alloca. */
dirpath = alloca (strlen (const_dirpath) + 1);
dirpath = (char *) alloca (strlen (const_dirpath) + 1);
strcpy (dirpath, const_dirpath);
src = dirpath + src_offset;
tmp_dst_dirname = dirname (dirpath);
dst_dirname = alloca (strlen (tmp_dst_dirname) + 1);
dst_dirname = (char *) alloca (strlen (tmp_dst_dirname) + 1);
strcpy (dst_dirname, tmp_dst_dirname);
free (tmp_dst_dirname);
@@ -853,7 +913,7 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
{
/* This element of the path does not exist. We must set
*new_dst and new->is_new_dir inside this loop because,
for example, in the command `cp --path ../a/../b/c e_dir',
for example, in the command `cp --parents ../a/../b/c e_dir',
make_path creates only e_dir/../a if ./b already exists. */
*new_dst = 1;
new->is_new_dir = 1;
@@ -907,7 +967,7 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
}
/* Ensure that the parent directories of CONST_DST_PATH have the
correct protections, for the --path option. This is done
correct protections, for the --parents option. This is done
after all copying has been completed, to allow permissions
that don't include user write/execute.
@@ -917,7 +977,7 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
ATTR_LIST is a null-terminated linked list of structures that
indicates the end of the filename of each intermediate directory
in CONST_DST_PATH that may need to have its attributes changed.
The command `cp --path --preserve a/b/c d/e_dir' changes the
The command `cp --parents --preserve a/b/c d/e_dir' changes the
attributes of the directories d/e_dir/a and d/e_dir/a/b to match
the corresponding source directories regardless of whether they
existed before the `cp' command was given.
@@ -936,7 +996,7 @@ re_protect (const_dst_path, src_offset, attr_list)
char *dst_path; /* A copy of CONST_DST_PATH we can change. */
char *src_path; /* The source name in `dst_path'. */
dst_path = alloca (strlen (const_dst_path) + 1);
dst_path = (char *) alloca (strlen (const_dst_path) + 1);
strcpy (dst_path, const_dst_path);
src_path = dst_path + src_offset;

View File

@@ -24,6 +24,7 @@
#include <signal.h>
#include "regex.h"
#include "system.h"
#include "version.h"
#ifdef STDC_HEADERS
#include <stdlib.h>
@@ -118,6 +119,9 @@ struct buffer_record
struct buffer_record *next;
};
/* The name this program was run with. */
char *program_name;
/* Input file descriptor. */
static int input_desc = 0;
@@ -179,8 +183,23 @@ static struct control *controls;
/* Number of elements in `controls'. */
static unsigned control_used;
/* 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 then exit. */
static int show_version;
static struct option const longopts[] =
{
{"digits", required_argument, NULL, 'n'},
{"quiet", no_argument, NULL, 's'},
{"silent", no_argument, NULL, 's'},
{"keep-files", no_argument, NULL, 'k'},
{"prefix", required_argument, NULL, 'f'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
/* Allocate N bytes of memory dynamically, with error checking. */
@@ -580,7 +599,6 @@ static struct cstring *
remove_line ()
{
struct cstring *line; /* Return value. */
unsigned line_got; /* Number of the line retrieved. */
struct line *l; /* For convenience. */
if (head == NULL && !load_buffer ())
@@ -589,7 +607,7 @@ remove_line ()
if (current_line < head->first_available)
current_line = head->first_available;
line_got = head->first_available++;
++(head->first_available);
l = head->curr_line;
@@ -1057,13 +1075,11 @@ string_to_number (result, num)
/* Check if there is a numeric offset after a regular expression.
STR is the entire command line argument.
ARGNUM is the index in ARGV of STR.
P is the control record for this regular expression.
NUM is the numeric part of STR. */
static void
check_for_offset (argnum, p, str, num)
int argnum;
check_for_offset (p, str, num)
struct control *p;
char *str;
char *num;
@@ -1144,7 +1160,7 @@ extract_regexp (argnum, ignore, str)
}
if (closing_delim[1])
check_for_offset (argnum, p, str, closing_delim + 1);
check_for_offset (p, str, closing_delim + 1);
return p;
}
@@ -1191,16 +1207,6 @@ interrupt_handler ()
cleanup ();
}
static struct option const longopts[] =
{
{"digits", required_argument, NULL, 'n'},
{"quiet", no_argument, NULL, 's'},
{"silent", no_argument, NULL, 's'},
{"keep-files", no_argument, NULL, 'k'},
{"prefix", required_argument, NULL, 'f'},
{NULL, 0, NULL, 0}
};
void
main (argc, argv)
int argc;
@@ -1254,6 +1260,9 @@ main (argc, argv)
!= EOF)
switch (optc)
{
case 0:
break;
case 'f':
prefix = optarg;
break;
@@ -1275,6 +1284,15 @@ main (argc, argv)
usage ();
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind >= argc - 1)
usage ();
@@ -1300,7 +1318,8 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-sk] [-f prefix] [-n digits] [--prefix=prefix]\n\
[--digits=digits] [--quiet] [--silent] [--keep-files] file pattern...\n",
[--digits=digits] [--quiet] [--silent] [--keep-files]\n\
[--help] [--version] file pattern...\n",
program_name);
exit (1);
}

View File

@@ -64,6 +64,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
char *xmalloc ();
char *xrealloc ();
@@ -119,6 +120,9 @@ enum operating_mode
field_mode
};
/* The name this program was run with. */
char *program_name;
static enum operating_mode operating_mode;
/* If nonzero,
@@ -131,8 +135,11 @@ static unsigned char delim;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
/* 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 then exit. */
static int show_version;
static struct option const longopts[] =
{
@@ -141,6 +148,8 @@ static struct option const longopts[] =
{"fields", required_argument, 0, 'f'},
{"delimiter", required_argument, 0, 'd'},
{"only-delimited", no_argument, 0, 's'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -172,6 +181,9 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'b':
case 'c':
/* Build the byte list. */
@@ -212,6 +224,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (operating_mode == undefined_mode)
usage ();
@@ -233,7 +254,7 @@ main (argc, argv)
exit_status = 1;
}
if (ferror (stdout) || fclose (stdout) == EOF)
error (1, 0, "write error");
error (1, errno, "write error");
exit (exit_status);
}
@@ -519,9 +540,6 @@ cut_fields (stream)
if (fieldfound)
{
/* Something was found. Print it. */
if ((unsigned char) outbufptr[-1] == delim)
--outbufptr; /* Suppress trailing delimiter. */
fwrite (outbuf, sizeof (char), outbufptr - outbuf, stdout);
if (c == '\n')
putc (c, stdout);
@@ -570,10 +588,11 @@ static void
usage ()
{
fprintf (stderr, "\
Usage: %s {-b byte-list,--bytes=byte-list} [-n] [file...]\n\
%s {-c character-list,--characters=character-list} [file...]\n\
%s {-f field-list,--fields=field-list} [-d delim] [-s]\n\
[--delimiter=delim] [--only-delimited] [file...]\n",
Usage: %s {-b byte-list,--bytes=byte-list} [-n] [file...] <options> \n\
%s {-c character-list,--characters=character-list} <options> [file...]\n\
%s {-f field-list,--fields=field-list} [-d delim] [-s] \n\
[--delimiter=delim] [--only-delimited] <options> [file...]\n\
Options: [--help] [--version]\n",
program_name, program_name, program_name);
exit (2);
}

View File

@@ -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,6 +82,23 @@ 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'},
{"uct", no_argument, NULL, 'u'},
{"universal", no_argument, NULL, 'u'},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
void
main (argc, argv)
int argc;
@@ -93,9 +112,12 @@ main (argc, argv)
program_name = argv[0];
while ((optc = getopt (argc, argv, "d:s:u")) != EOF)
while ((optc = getopt_long (argc, argv, "d:s:u", long_options, (int *) 0))
!= EOF)
switch (optc)
{
case 0:
break;
case 'd':
datestr = optarg;
break;
@@ -110,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 ();
@@ -182,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);
}

108
src/dd.c
View File

@@ -20,7 +20,7 @@
/* Options:
Numbers can be followed by a multiplier:
b=512, k=1024, w=2, xm=number m
b=512, c=1, k=1024, w=2, xm=number m
if=FILE Read from FILE instead of stdin.
of=FILE Write to FILE instead of stdout; don't
@@ -53,10 +53,22 @@
sync Pad every input block to size of ibs with
trailing NULs. */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#ifndef isascii
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
#define isascii(c) 1
#endif
@@ -66,7 +78,9 @@
#include <sys/types.h>
#include <signal.h>
#include <getopt.h>
#include "system.h"
#include "version.h"
#define equal(p, q) (strcmp ((p),(q)) == 0)
#define max(a, b) ((a) > (b) ? (a) : (b))
@@ -305,6 +319,19 @@ static unsigned char const ebcdic_to_ascii[] =
070, 071, 0372, 0373, 0374, 0375, 0376, 0377
};
/* 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}
};
void
main (argc, argv)
int argc;
@@ -323,6 +350,16 @@ main (argc, argv)
/* Decode arguments. */
scanargs (argc, argv);
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
apply_translations ();
if (input_file != NULL)
@@ -618,8 +655,11 @@ copy ()
/* If the final input line didn't end with a '\n', pad
the output block to `conversion_blocksize' chars. */
int pending_spaces = max (0, conversion_blocksize - col);
while (pending_spaces--)
output_char (space_character);
while (pending_spaces)
{
output_char (space_character);
--pending_spaces;
}
}
if ((conversions_mask & C_UNBLOCK) && col == conversion_blocksize)
@@ -690,8 +730,11 @@ copy_with_block (buf, nread)
if (*buf == newline_character)
{
int pending_spaces = max (0, conversion_blocksize - col);
while (pending_spaces--)
output_char (space_character);
while (pending_spaces)
{
output_char (space_character);
--pending_spaces;
}
col = 0;
}
else
@@ -732,12 +775,12 @@ copy_with_unblock (buf, nread)
pending_spaces++;
else
{
if (pending_spaces)
/* `c' is the character after a run of spaces that were not
at the end of the conversion buffer. Output them. */
while (pending_spaces)
{
/* `c' is the character after a run of spaces that were not
at the end of the conversion buffer. Output them. */
while (pending_spaces--)
output_char (space_character);
output_char (space_character);
--pending_spaces;
}
output_char (c);
}
@@ -768,15 +811,31 @@ scanargs (argc, argv)
char **argv;
{
int i, n;
int c;
for (i = 1; i < argc; i++)
while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
{
switch (c)
{
case 0:
break;
default:
usage ();
}
}
for (i = optind; i < argc; i++)
{
char *name, *val;
name = argv[i];
val = index (name, '=');
if (val == NULL)
usage ("unrecognized option `%s'", name);
{
error (0, 0, "unrecognized option `%s'", name);
usage ();
}
*val++ = '\0';
if (equal (name, "if"))
@@ -812,7 +871,10 @@ scanargs (argc, argv)
else if (equal (name, "count"))
max_records = n;
else
usage ("unrecognized option `%s=%s'", name, val);
{
error (0, 0, "unrecognized option `%s=%s'", name, val);
usage ();
}
}
}
@@ -854,6 +916,8 @@ loop:
case 'b':
n *= 512;
goto loop;
case 'c':
goto loop;
case 'k':
n *= 1024;
goto loop;
@@ -894,8 +958,8 @@ parse_conversion (str)
}
if (conversions[i].convname == NULL)
{
usage ("%s: invalid conversion", str);
exit (1);
error (0, 0, "%s: invalid conversion", str);
usage ();
}
str = new;
} while (new != NULL);
@@ -981,7 +1045,7 @@ print_stats ()
fprintf (stderr, "%u+%u records in\n", r_full, r_partial);
fprintf (stderr, "%u+%u records out\n", w_full, w_partial);
if (r_truncate > 0)
fprintf (stderr, "%u truncated block%s\n", r_truncate,
fprintf (stderr, "%u truncated record%s\n", r_truncate,
r_truncate == 1 ? "" : "s");
}
@@ -1005,19 +1069,15 @@ interrupt_handler ()
}
static void
usage (string, arg0, arg1)
char *string, *arg0, *arg1;
usage ()
{
fprintf (stderr, "%s: ", program_name);
fprintf (stderr, string, arg0, arg1);
fprintf (stderr, "\n");
fprintf (stderr, "\
Usage: %s [if=file] [of=file] [ibs=bytes] [obs=bytes] [bs=bytes] [cbs=bytes]\n\
[skip=blocks] [seek=blocks] [count=blocks]\n\
[conv={ascii,ebcdic,ibm,block,unblock,lcase,ucase,swab,noerror,notrunc,\n\
sync}]\n\
sync}] [--help] [--version]\n\
Numbers can be followed by a multiplier:\n\
b=512, k=1024, w=2, xm=number m\n",
b=512, c=1, k=1024, w=2, xm=number m\n",
program_name);
exit (1);
}

153
src/df.c
View File

@@ -15,8 +15,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Usage: df [-aikP] [-t fstype] [--all] [--inodes] [--type fstype]
[--kilobytes] [--portability] [path...]
/* Usage: df [-aikP] [-t fstype] [-x fstype] [--all] [--inodes]
[--type fstype] [--exclude-type fstype] [--kilobytes] [--portability]
[path...]
Options:
-a, --all List all filesystems, even zero-size ones.
@@ -24,24 +25,40 @@
-k, --kilobytes Print sizes in 1K blocks instead of 512-byte blocks.
-P, --portability Use the POSIX output format (one line per filesystem).
-t, --type fstype Limit the listing to filesystems of type `fstype'.
Multiple -t options can be given.
-x, --exclude-type=fstype
Limit the listing to filesystems not of type `fstype'.
Multiple -t and/or -x options can be given.
By default, all filesystem types are listed.
Written by David MacKenzie <djm@gnu.ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <sys/types.h>
#include <getopt.h>
#include "mountlist.h"
#include "fsusage.h"
#include "system.h"
#include "version.h"
char *strstr ();
char *xmalloc ();
char *xstrdup ();
void error ();
static int fs_to_list ();
static int selected_fstype ();
static int excluded_fstype ();
static void add_excluded_fs_type ();
static void add_fs_type ();
static void print_header ();
static void show_entry ();
@@ -51,6 +68,9 @@ static void show_disk ();
static void show_point ();
static void usage ();
/* Name this program was run with. */
char *program_name;
/* If nonzero, show inode information. */
static int inode_format;
@@ -58,6 +78,10 @@ static int inode_format;
uninteresting types. */
static int show_all_fs;
/* If nonzero, output data for each filesystem corresponding to a
command line argument -- even if it's a dummy (automounter) entry. */
static int show_listed_fs;
/* If nonzero, use 1K blocks instead of 512-byte blocks. */
static int kilobyte_blocks;
@@ -67,19 +91,16 @@ static int posix_format;
/* Nonzero if errors have occurred. */
static int exit_status;
/* Name this program was run with. */
char *program_name;
/* A filesystem type to display. */
struct fs_select
struct fs_type_list
{
char *fs_name;
struct fs_select *fs_next;
struct fs_type_list *fs_next;
};
/* Linked list of filesystem types to display.
If `fs_list' is NULL, list all types.
If `fs_select_list' is NULL, list all types.
This table is generated dynamically from command-line options,
rather than hardcoding into the program what it thinks are the
valid filesystem types; let the user specify any filesystem type
@@ -87,13 +108,24 @@ struct fs_select
will be shown.
Some filesystem types:
4.2 4.3 ufs nfs swap ignore io vm */
4.2 4.3 ufs nfs swap ignore io vm efs dbg */
static struct fs_select *fs_list;
static struct fs_type_list *fs_select_list;
/* Linked list of filesystem types to omit.
If the list is empty, don't exclude any types. */
static struct fs_type_list *fs_exclude_list;
/* Linked list of mounted filesystems. */
static struct mount_entry *mount_list;
/* 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[] =
{
{"all", no_argument, &show_all_fs, 1},
@@ -101,6 +133,9 @@ static struct option const long_options[] =
{"kilobytes", no_argument, &kilobyte_blocks, 1},
{"portability", no_argument, &posix_format, 1},
{"type", required_argument, 0, 't'},
{"exclude-type", required_argument, 0, 'x'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -113,14 +148,16 @@ main (argc, argv)
struct stat *stats;
program_name = argv[0];
fs_list = NULL;
fs_select_list = NULL;
fs_exclude_list = NULL;
inode_format = 0;
show_all_fs = 0;
show_listed_fs = 0;
kilobyte_blocks = getenv ("POSIXLY_CORRECT") == 0;
posix_format = 0;
exit_status = 0;
while ((i = getopt_long (argc, argv, "aikPt:v", long_options, (int *) 0))
while ((i = getopt_long (argc, argv, "aikPt:vx:", long_options, (int *) 0))
!= EOF)
{
switch (i)
@@ -144,16 +181,25 @@ main (argc, argv)
break;
case 'v': /* For SysV compatibility. */
break;
case 'x':
add_excluded_fs_type (optarg);
break;
default:
usage ();
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind != argc)
{
/* Display explicitly requested empty filesystems. */
show_all_fs = 1;
/* stat all the given entries to make sure they get automounted,
if necessary, before reading the filesystem table. */
stats = (struct stat *)
@@ -167,7 +213,10 @@ main (argc, argv)
}
}
mount_list = read_filesystem_list (fs_list != NULL, show_all_fs);
mount_list =
read_filesystem_list ((fs_select_list != NULL || fs_exclude_list != NULL),
show_all_fs);
if (mount_list == NULL)
error (1, errno, "cannot read table of mounted filesystems");
@@ -177,9 +226,14 @@ main (argc, argv)
if (optind == argc)
show_all_entries ();
else
for (i = optind; i < argc; ++i)
if (argv[i])
show_entry (argv[i], &stats[i - optind]);
{
/* Display explicitly requested empty filesystems. */
show_listed_fs = 1;
for (i = optind; i < argc; ++i)
if (argv[i])
show_entry (argv[i], &stats[i - optind]);
}
exit (exit_status);
}
@@ -294,7 +348,7 @@ show_dev (disk, mount_point, fstype)
long inodes_percent_used;
char *stat_file;
if (!fs_to_list (fstype))
if (!selected_fstype (fstype) || excluded_fstype (fstype))
return;
/* If MOUNT_POINT is NULL, then the filesystem is not mounted, and this
@@ -319,7 +373,7 @@ show_dev (disk, mount_point, fstype)
if (fsu.fsu_blocks == 0)
{
if (show_all_fs == 0)
if (!show_all_fs && !show_listed_fs)
return;
blocks_used = fsu.fsu_bavail = blocks_percent_used = 0;
}
@@ -363,37 +417,70 @@ static void
add_fs_type (fstype)
char *fstype;
{
struct fs_select *fsp;
struct fs_type_list *fsp;
fsp = (struct fs_select *) xmalloc (sizeof (struct fs_select));
fsp = (struct fs_type_list *) xmalloc (sizeof (struct fs_type_list));
fsp->fs_name = fstype;
fsp->fs_next = fs_list;
fs_list = fsp;
fsp->fs_next = fs_select_list;
fs_select_list = fsp;
}
/* Add FSTYPE to the list of filesystem types to be omitted. */
static void
add_excluded_fs_type (fstype)
char *fstype;
{
struct fs_type_list *fsp;
fsp = (struct fs_type_list *) xmalloc (sizeof (struct fs_type_list));
fsp->fs_name = fstype;
fsp->fs_next = fs_exclude_list;
fs_exclude_list = fsp;
}
/* If FSTYPE is a type of filesystem that should be listed,
return nonzero, else zero. */
static int
fs_to_list (fstype)
selected_fstype (fstype)
char *fstype;
{
struct fs_select *fsp;
struct fs_type_list *fsp;
if (fs_list == NULL || fstype == NULL)
if (fs_select_list == NULL || fstype == NULL)
return 1;
for (fsp = fs_list; fsp; fsp = fsp->fs_next)
for (fsp = fs_select_list; fsp; fsp = fsp->fs_next)
if (!strcmp (fstype, fsp->fs_name))
return 1;
return 0;
}
/* If FSTYPE is a type of filesystem that should be omitted,
return nonzero, else zero. */
static int
excluded_fstype (fstype)
char *fstype;
{
struct fs_type_list *fsp;
if (fs_exclude_list == NULL || fstype == NULL)
return 0;
for (fsp = fs_exclude_list; fsp; fsp = fsp->fs_next)
if (!strcmp (fstype, fsp->fs_name))
return 1;
return 0;
}
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-aikPv] [-t fstype] [--all] [--inodes] [--type fstype]\n\
[--kilobytes] [--portability] [path...]\n",
Usage: %s [-aikPv] [-t fstype] [-x fstype] [--all] [--inodes]\n\
\t[--type=fstype] [--exclude-type=fstype] [--kilobytes] [--portability]\n\
\t[--help] [--version] [path...]\n",
program_name);
exit (1);
}

View File

@@ -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)
{
fprintf (stderr, "Usage: %s path\n", argv[0]);
exit (1);
switch (c)
{
case 0:
break;
default:
usage ();
}
}
path = argv[1];
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
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);
}

View File

@@ -39,10 +39,23 @@
#ifdef _AIX
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
int lstat ();
int stat ();
@@ -152,9 +165,14 @@ static struct stat stat_buf;
static int (*xstat) ();
/* The exit status to use if we don't get any fatal errors. */
static int exit_status;
/* 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[] =
{
{"all", no_argument, &opt_all, 1},
@@ -167,6 +185,8 @@ static struct option const long_options[] =
{"separate-dirs", no_argument, &opt_separate_dirs, 1},
{"summarize", no_argument, &opt_summarize_only, 1},
{"total", no_argument, &opt_combined_arguments, 1},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -180,7 +200,7 @@ usage (reason)
fprintf (stderr, "\
Usage: %s [-abcklsxDLS] [--all] [--total] [--count-links] [--summarize]\n\
[--bytes] [--kilobytes] [--one-file-system] [--separate-dirs]\n\
[--dereference] [--dereference-args] [path...]\n",
[--dereference] [--dereference-args] [--help] [--version] [path...]\n",
program_name);
exit (2);
@@ -250,6 +270,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage (NULL);
if (opt_all && opt_summarize_only)
usage ("cannot both summarize and show all entries");
@@ -401,7 +430,9 @@ count_entry (ent, top, last_dev)
if (errno)
{
error (0, errno, "%s", path->text);
chdir (".."); /* Try to return to previous directory. */
if (chdir ("..") < 0) /* Try to return to previous dir. */
error (1, errno, "cannot change to `..' from directory %s",
path->text);
exit_status = 1;
return 0;
}
@@ -425,7 +456,8 @@ count_entry (ent, top, last_dev)
namep += strlen (namep) + 1;
}
free (name_space);
chdir ("..");
if (chdir ("..") < 0)
error (1, errno, "cannot change to `..' from directory %s", path->text);
str_trunc (path, pathlen - 1); /* Remove the "/" we added. */
if (!opt_summarize_only || top)

View File

@@ -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;
@@ -174,6 +179,6 @@ just_echo:
}
}
if (display_return)
printf ("\n");
putchar ('\n');
exit (0);
}

View File

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

View File

@@ -40,6 +40,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
/* The number of bytes added at a time to the amount of memory
allocated for the output line. */
@@ -60,6 +61,9 @@ static void parse_tabstops ();
static void usage ();
static void validate_tabstops ();
/* The name this program was run with. */
char *program_name;
/* If nonzero, convert blanks even after nonblank characters have been
read on the line. */
static int convert_entire_line;
@@ -91,13 +95,18 @@ static int have_read_stdin;
/* Status to return to the system. */
static int exit_status;
/* 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 then exit. */
static int show_version;
static struct option const longopts[] =
{
{"tabs", required_argument, NULL, 't'},
{"initial", no_argument, NULL, 'i'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -121,6 +130,9 @@ main (argc, argv)
{
switch (c)
{
case 0:
break;
case '?':
usage ();
case 'i':
@@ -141,6 +153,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
add_tabstop (tabval);
validate_tabstops (tab_list, first_free_tab);
@@ -162,7 +183,7 @@ main (argc, argv)
if (have_read_stdin && fclose (stdin) == EOF)
error (1, errno, "-");
if (ferror (stdout) || fclose (stdout) == EOF)
error (1, 0, "write error");
error (1, errno, "write error");
exit (exit_status);
}
@@ -363,7 +384,7 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-tab1[,tab2[,...]]] [-t tab1[,tab2[,...]]] [-i]\n\
[--tabs=tab1[,tab2[,...]]] [--initial] [file...]\n",
[--tabs=tab1[,tab2[,...]]] [--initial] [--help] [--version] [file...]\n",
program_name);
exit (1);
}

View File

@@ -32,9 +32,13 @@
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>
#include "system.h"
#include <getopt.h>
#ifndef isascii
#include "system.h"
#include "version.h"
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
#define isascii(c) 1
#endif
@@ -95,6 +99,54 @@ 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 ()
{
fprintf (stderr, "Usage: %s [{--help,--version}] expression...\n",
program_name);
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;
@@ -104,11 +156,10 @@ main (argc, argv)
program_name = argv[0];
parse_long_options (argc, argv);
if (argc == 1)
{
fprintf (stderr, "Usage: %s expression...\n", argv[0]);
exit (1);
}
usage ();
args = argv + 1;
v = eval ();
@@ -172,6 +223,8 @@ printv (v)
case string:
printf ("%s\n", v->u.s);
break;
default:
abort ();
}
}
@@ -186,7 +239,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 +272,8 @@ tostring (v)
break;
case string:
break;
default:
abort ();
}
}
@@ -251,6 +308,8 @@ toarith (v)
v->u.i = i * (neg ? -1 : 1);
v->type = integer;
return 1;
default:
abort ();
}
}
@@ -309,13 +368,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 +544,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);

View File

@@ -24,10 +24,15 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
char *xrealloc ();
char *xmalloc ();
void error ();
/* The name this program was run with. */
char *program_name;
static int adjust_column ();
static int fold_file ();
@@ -40,17 +45,32 @@ static int count_bytes;
/* If nonzero, at least one of the files we read was standard input. */
static int have_read_stdin;
/* 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 then exit. */
static int show_version;
static struct option const longopts[] =
{
{"bytes", no_argument, NULL, 'b'},
{"spaces", no_argument, NULL, 's'},
{"width", required_argument, NULL, 'w'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-bs] [-w width] [--bytes] [--spaces] [--width=width]\n\
[--help] [--version] [file...]\n",
program_name);
exit (1);
}
void
main (argc, argv)
int argc;
@@ -64,11 +84,29 @@ main (argc, argv)
program_name = argv[0];
break_spaces = count_bytes = have_read_stdin = 0;
/* Turn any numeric options into -w options. */
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-' && ISDIGIT (argv[i][1]))
{
char *s;
s = xmalloc (strlen (argv[i]) + 2);
s[0] = '-';
s[1] = 'w';
strcpy (s + 2, argv[i] + 1);
argv[i] = s;
}
}
while ((optc = getopt_long (argc, argv, "bsw:", longopts, (int *) 0))
!= EOF)
{
switch (optc)
{
case 0:
break;
case 'b': /* Count bytes rather than columns. */
count_bytes = 1;
break;
@@ -84,13 +122,19 @@ main (argc, argv)
break;
default:
fprintf (stderr, "\
Usage: %s [-bs] [-w width] [--bytes] [--spaces] [--width=width] [file...]\n",
argv[0]);
exit (1);
usage ();
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (argc == optind)
errs |= fold_file ("-", width);
else

View File

@@ -37,6 +37,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
/* Number of lines/chars/blocks to head. */
#define DEFAULT_NUMBER 10
@@ -75,6 +76,12 @@ char *program_name;
/* Have we ever read standard input? */
static int have_read_stdin;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const long_options[] =
{
{"bytes", required_argument, NULL, 'c'},
@@ -82,6 +89,8 @@ static struct option const long_options[] =
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -156,6 +165,9 @@ main (argc, argv)
{
switch (c)
{
case 0:
break;
case 'c':
unit_size = 1;
parse_unit (optarg);
@@ -181,6 +193,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (number == -1)
number = DEFAULT_NUMBER;
@@ -368,7 +389,8 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-c N[bkm]] [-n N] [-qv] [--bytes=N[bkm]] [--lines=N]\n\
[--quiet] [--silent] [--verbose] [file...]\n\
%s [-Nbcklmqv] [file...]\n", program_name, program_name);
[--quiet] [--silent] [--verbose] [--help] [--version] [file...]\n\
%s [-Nbcklmqv] [--help] [--version] [file...]\n",
program_name, program_name);
exit (1);
}

View File

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

View File

@@ -52,6 +52,17 @@
David MacKenzie <djm@gnu.ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <ctype.h>
@@ -59,9 +70,11 @@
#include <pwd.h>
#include <grp.h>
#include "system.h"
#include "version.h"
#include "modechange.h"
#ifndef isascii
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
#define isascii(c) 1
#endif
@@ -89,6 +102,7 @@ int wait ();
#define READ_SIZE (32 * 1024)
char *basename ();
char *stpcpy ();
char *xmalloc ();
void error ();
int make_path ();
@@ -130,6 +144,12 @@ static int strip_files;
/* If nonzero, install a directory instead of a regular file. */
static int dir_arg;
/* 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[] =
{
{"strip", no_argument, NULL, 's'},
@@ -137,6 +157,8 @@ static struct option const long_options[] =
{"group", required_argument, NULL, 'g'},
{"mode", required_argument, NULL, 'm'},
{"owner", required_argument, NULL, 'o'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -162,6 +184,8 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'c':
break;
case 's':
@@ -184,6 +208,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
/* Check for invalid combinations of arguments. */
if ((dir_arg && strip_files)
|| (optind == argc)
@@ -242,11 +275,17 @@ install_file_in_file (from, to)
char *from;
char *to;
{
if (copy_file (from, to))
int to_created;
int no_need_to_chown;
if (copy_file (from, to, &to_created))
return 1;
if (strip_files)
strip (to);
return change_attributes (to);
no_need_to_chown = (to_created
&& owner_name == NULL
&& group_name == NULL);
return change_attributes (to, no_need_to_chown);
}
/* Copy file FROM into directory TO_DIR, keeping its same name,
@@ -264,7 +303,7 @@ install_file_in_dir (from, to_dir)
from_base = basename (from);
to = xmalloc ((unsigned) (strlen (to_dir) + strlen (from_base) + 2));
sprintf (to, "%s/%s", to_dir, from_base);
stpcpy (stpcpy (stpcpy (to, to_dir), "/"), from_base);
ret = install_file_in_file (from, to);
free (to);
return ret;
@@ -274,17 +313,22 @@ install_file_in_dir (from, to_dir)
static char buffer[READ_SIZE];
/* Copy file FROM onto file TO, creating TO if necessary.
Return 0 if the copy is successful, 1 if not. */
Return 0 if the copy is successful, 1 if not. If the copy is
successful, set *TO_CREATED to non-zero if TO was created (if it did
not exist or did, but was unlinked) and to zero otherwise. If the
copy fails, don't modify *TO_CREATED. */
static int
copy_file (from, to)
copy_file (from, to, to_created)
char *from;
char *to;
int *to_created;
{
int fromfd, tofd;
int bytes;
int ret = 0;
struct stat from_stats, to_stats;
int target_created = 1;
if (stat (from, &from_stats))
{
@@ -310,7 +354,8 @@ copy_file (from, to)
return 1;
}
/* If unlink fails, try to proceed anyway. */
unlink (to);
if (unlink (to))
target_created = 0;
}
fromfd = open (from, O_RDONLY, 0);
@@ -352,6 +397,8 @@ copy_file (from, to)
error (0, errno, "%s", to);
ret = 1;
}
if (ret == 0)
*to_created = target_created;
return ret;
copy_error:
@@ -361,11 +408,13 @@ copy_file (from, to)
}
/* Set the attributes of file or directory PATH.
If NO_NEED_TO_CHOWN is non-zero, don't call chown.
Return 0 if successful, 1 if not. */
static int
change_attributes (path)
change_attributes (path, no_need_to_chown)
char *path;
int no_need_to_chown;
{
int err = 0;
@@ -385,7 +434,7 @@ change_attributes (path)
want to know. But AFS returns EPERM when you try to change a
file's group; thus the kludge. */
if (chown (path, owner_id, group_id)
if (!no_need_to_chown && chown (path, owner_id, group_id)
#ifdef AFS
&& errno != EPERM
#endif
@@ -495,8 +544,8 @@ Usage: %s [options] [-s] [--strip] source dest\n\
%s [options] [-s] [--strip] source... directory\n\
%s [options] {-d,--directory} directory...\n\
Options:\n\
[-c] [-g group] [-m mode] [-o owner]\n\
[--group=group] [--mode=mode] [--owner=owner]\n",
[-c] [-g group] [-m mode] [-o owner] [--group=group]\n\
[--help] [--version] [--mode=mode] [--owner=owner]\n",
program_name, program_name, program_name);
exit (1);
}

View File

@@ -24,6 +24,7 @@
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
#include "version.h"
char *xmalloc ();
char *xrealloc ();
@@ -66,6 +67,9 @@ struct seq
struct line *lines;
};
/* The name this program was run with. */
char *program_name;
/* If nonzero, print unpairable lines in file 1 or 2. */
static int print_unpairables_1, print_unpairables_2;
@@ -89,8 +93,23 @@ static struct outlist *outlist_end;
tab character. */
static char tab;
/* 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 then exit. */
static int show_version;
/* When using getopt_long_only, no long option can start with
a character that is a short option. */
static struct option const longopts[] =
{
{"j", required_argument, NULL, 'j'},
{"j1", required_argument, NULL, '1'},
{"j2", required_argument, NULL, '2'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
/* Fill in the `fields' structure in LINE. */
@@ -546,16 +565,6 @@ add_field_list (str)
return added;
}
/* When using getopt_long_only, no long option can start with
a character that is a short option. */
static struct option const longopts[] =
{
{"j", required_argument, NULL, 'j'},
{"j1", required_argument, NULL, '1'},
{"j2", required_argument, NULL, '2'},
{NULL, 0, NULL, 0}
};
void
main (argc, argv)
int argc;
@@ -574,6 +583,9 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'a':
val = atoi (optarg);
if (val == 1)
@@ -647,6 +659,15 @@ main (argc, argv)
}
prev_optc = optc;
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (nfiles != 2)
usage ();
@@ -664,7 +685,7 @@ main (argc, argv)
if ((fp1 == stdin || fp2 == stdin) && fclose (stdin) == EOF)
error (1, errno, "-");
if (ferror (stdout) || fclose (stdout) == EOF)
error (1, 0, "write error");
error (1, errno, "write error");
exit (0);
}

View File

@@ -20,11 +20,24 @@
#ifdef _AIX
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
#include "backupfile.h"
#include "version.h"
int link (); /* Some systems don't declare this anywhere. */
@@ -32,15 +45,40 @@ int link (); /* Some systems don't declare this anywhere. */
int symlink ();
#endif
/* Construct a string NEW_DEST by concatenating DEST, a slash, and
basename(SOURCE) in alloca'd memory. Don't modify DEST or SOURCE. */
#define PATH_BASENAME_CONCAT(new_dest, dest, source) \
do \
{ \
char *source_base; \
char *tmp_source; \
\
tmp_source = (char *) alloca (strlen ((source)) + 1); \
strcpy (tmp_source, (source)); \
strip_trailing_slashes (tmp_source); \
source_base = basename (tmp_source); \
\
(new_dest) = (char *) alloca (strlen ((dest)) + 1 \
+ strlen (source_base) + 1); \
stpcpy (stpcpy (stpcpy ((new_dest), (dest)), "/"), source_base);\
} \
while (0)
char *basename ();
enum backup_type get_version ();
int isdir ();
int yesno ();
void error ();
void strip_trailing_slashes ();
char *stpcpy ();
static void usage ();
static int do_link ();
/* The name by which the program was run, for error messages. */
char *program_name;
/* A pointer to the function used to make links. This will point to either
`link' or `symlink'. */
static int (*linkfunc) ();
@@ -60,8 +98,11 @@ static int verbose;
/* If nonzero, allow the superuser to make hard links to directories. */
static int hard_dir_link;
/* The name by which the program was run, 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[] =
{
@@ -73,6 +114,8 @@ static struct option const long_options[] =
{"symbolic", no_argument, &symbolic_link, 1},
{"verbose", no_argument, &verbose, 1},
{"version-control", required_argument, NULL, 'V'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -122,7 +165,7 @@ main (argc, argv)
#ifdef S_ISLNK
symbolic_link = 1;
#else
error (0, 0, "symbolic links not supported; making hard links");
error (1, 0, "symbolic links are not supported on this system");
#endif
break;
case 'v':
@@ -139,6 +182,16 @@ main (argc, argv)
break;
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind == argc)
usage ();
@@ -154,7 +207,30 @@ main (argc, argv)
errors = do_link (argv[optind], ".");
else if (optind == argc - 2)
{
errors = do_link (argv[optind], argv[optind + 1]);
struct stat source_stats;
char *source;
char *dest;
char *new_dest;
source = argv[optind];
dest = argv[optind + 1];
/* When the destination is specified with a trailing slash and the
source exists but is not a directory, convert the user's command
`ln source dest/' to `ln source dest/basename(source)'. */
if (dest[strlen (dest) - 1] == '/'
&& lstat (source, &source_stats) == 0
&& !S_ISDIR (source_stats.st_mode))
{
PATH_BASENAME_CONCAT (new_dest, dest, source);
}
else
{
new_dest = dest;
}
errors = do_link (source, new_dest);
}
else
{
@@ -195,12 +271,7 @@ do_link (source, dest)
{
/* Target is a directory; build the full filename. */
char *new_dest;
char *source_base;
source_base = basename (source);
new_dest = (char *)
alloca (strlen (source_base) + 1 + strlen (dest) + 1);
sprintf (new_dest, "%s/%s", dest, source_base);
PATH_BASENAME_CONCAT (new_dest, dest, source);
dest = new_dest;
}
@@ -228,7 +299,7 @@ do_link (source, dest)
char *tmp_backup = find_backup_file_name (dest);
if (tmp_backup == NULL)
error (1, 0, "virtual memory exhausted");
dest_backup = alloca (strlen (tmp_backup) + 1);
dest_backup = (char *) alloca (strlen (tmp_backup) + 1);
strcpy (dest_backup, tmp_backup);
free (tmp_backup);
if (rename (dest, dest_backup))
@@ -288,7 +359,7 @@ Options:\n\
[-bdfisvF] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
[--version-control={numbered,existing,simple}] [--backup] [--directory]\n\
[--force] [--interactive] [--symbolic] [--verbose]\n\
[--suffix=backup-suffix]\n",
[--suffix=backup-suffix] [--help] [--version]\n",
program_name, program_name);
exit (1);
}

View File

@@ -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;
if (argc != 1)
program_name = argv[0];
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);
}

2
src/ls-dir.c Normal file
View File

@@ -0,0 +1,2 @@
#include "ls.h"
int ls_mode = LS_MULTI_COL;

2
src/ls-ls.c Normal file
View File

@@ -0,0 +1,2 @@
#include "ls.h"
int ls_mode = LS_LS;

2
src/ls-vdir.c Normal file
View File

@@ -0,0 +1,2 @@
#include "ls.h"
int ls_mode = LS_LONG_FORMAT;

335
src/ls.c
View File

@@ -35,6 +35,18 @@
#ifdef _AIX
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <sys/types.h>
#if !defined(_POSIX_SOURCE) || defined(_AIX)
#include <sys/ioctl.h>
@@ -43,8 +55,11 @@
#include <grp.h>
#include <pwd.h>
#include <getopt.h>
#include <fnmatch.h>
#include "system.h"
#include <fnmatch.h>
#include "ls.h"
#include "version.h"
#ifndef S_IEXEC
#define S_IEXEC S_IXUSR
@@ -57,9 +72,7 @@
#define longdiff(a, b) ((a) - (b))
#endif
#ifdef STDC_HEADERS
#include <time.h>
#else
#ifndef STDC_HEADERS
char *ctime ();
time_t time ();
#endif
@@ -112,6 +125,10 @@ static void queue_directory ();
static void sort_files ();
static void usage ();
/* The name the program was run with, stripped of any leading path. */
char *program_name;
enum filetype
{
symbolic_link,
@@ -178,9 +195,6 @@ static time_t current_time;
4, or more if needed for bigger numbers. */
static int block_size_size;
/* The name the program was run with, stripped of any leading path. */
char *program_name;
/* Option flags */
@@ -214,6 +228,10 @@ enum time_type
static enum time_type time_type;
/* print the full time, otherwise the standard unix heuristics. */
int full_time;
/* The file characteristic to sort by. Controlled by -t, -S, -U, -X. */
enum sort_type
@@ -235,6 +253,10 @@ static enum sort_type sort_type;
static int sort_reverse;
/* Nonzero means to NOT display group information. -G */
int inhibit_group;
/* Nonzero means print the user and group id's as numbers rather
than as names. -n */
@@ -347,6 +369,77 @@ static int format_needs_stat;
/* The exit status to use if we don't get any fatal errors. */
static int exit_status;
/* 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[] =
{
{"all", no_argument, 0, 'a'},
{"escape", no_argument, 0, 'b'},
{"directory", no_argument, 0, 'd'},
{"full-time", no_argument, &full_time, 1},
{"inode", no_argument, 0, 'i'},
{"kilobytes", no_argument, 0, 'k'},
{"numeric-uid-gid", no_argument, 0, 'n'},
{"no-group", no_argument, 0, 'G'},
{"hide-control-chars", no_argument, 0, 'q'},
{"reverse", no_argument, 0, 'r'},
{"size", no_argument, 0, 's'},
{"width", required_argument, 0, 'w'},
{"almost-all", no_argument, 0, 'A'},
{"ignore-backups", no_argument, 0, 'B'},
{"classify", no_argument, 0, 'F'},
{"file-type", no_argument, 0, 'F'},
{"ignore", required_argument, 0, 'I'},
{"dereference", no_argument, 0, 'L'},
{"literal", no_argument, 0, 'N'},
{"quote-name", no_argument, 0, 'Q'},
{"recursive", no_argument, 0, 'R'},
{"format", required_argument, 0, 12},
{"sort", required_argument, 0, 10},
{"tabsize", required_argument, 0, 'T'},
{"time", required_argument, 0, 11},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
static char const* const format_args[] =
{
"verbose", "long", "commas", "horizontal", "across",
"vertical", "single-column", 0
};
static enum format const formats[] =
{
long_format, long_format, with_commas, horizontal, horizontal,
many_per_line, one_per_line
};
static char const* const sort_args[] =
{
"none", "time", "size", "extension", 0
};
static enum sort_type const sort_types[] =
{
sort_none, sort_time, sort_size, sort_extension
};
static char const* const time_args[] =
{
"atime", "access", "use", "ctime", "status", 0
};
static enum time_type const time_types[] =
{
time_atime, time_atime, time_atime, time_ctime, time_ctime
};
void
main (argc, argv)
@@ -365,6 +458,15 @@ main (argc, argv)
program_name = argv[0];
i = decode_switches (argc, argv);
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
format_needs_stat = sort_type == sort_time || sort_type == sort_size
|| format == long_format
|| trace_links || trace_dirs || indicator_style != none
@@ -420,66 +522,6 @@ main (argc, argv)
exit (exit_status);
}
static struct option const long_options[] =
{
{"all", no_argument, 0, 'a'},
{"escape", no_argument, 0, 'b'},
{"directory", no_argument, 0, 'd'},
{"inode", no_argument, 0, 'i'},
{"kilobytes", no_argument, 0, 'k'},
{"numeric-uid-gid", no_argument, 0, 'n'},
{"hide-control-chars", no_argument, 0, 'q'},
{"reverse", no_argument, 0, 'r'},
{"size", no_argument, 0, 's'},
{"width", required_argument, 0, 'w'},
{"almost-all", no_argument, 0, 'A'},
{"ignore-backups", no_argument, 0, 'B'},
{"classify", no_argument, 0, 'F'},
{"file-type", no_argument, 0, 'F'},
{"ignore", required_argument, 0, 'I'},
{"dereference", no_argument, 0, 'L'},
{"literal", no_argument, 0, 'N'},
{"quote-name", no_argument, 0, 'Q'},
{"recursive", no_argument, 0, 'R'},
{"format", required_argument, 0, 12},
{"sort", required_argument, 0, 10},
{"tabsize", required_argument, 0, 'T'},
{"time", required_argument, 0, 11},
{0, 0, 0, 0}
};
static char const* const format_args[] =
{
"verbose", "long", "commas", "horizontal", "across",
"vertical", "single-column", 0
};
static enum format const formats[] =
{
long_format, long_format, with_commas, horizontal, horizontal,
many_per_line, one_per_line
};
static char const* const sort_args[] =
{
"none", "time", "size", "extension", 0
};
static enum sort_type const sort_types[] =
{
sort_none, sort_time, sort_size, sort_extension
};
static char const* const time_args[] =
{
"atime", "access", "use", "ctime", "status", 0
};
static enum time_type const time_types[] =
{
time_atime, time_atime, time_atime, time_ctime, time_ctime
};
/* Set all the option flags according to the switches specified.
Return the index of the first non-option argument. */
@@ -497,31 +539,40 @@ decode_switches (argc, argv)
/* initialize all switches to default settings */
#ifdef MULTI_COL
/* This is for the `dir' program. */
format = many_per_line;
quote_funny_chars = 1;
#else
#ifdef LONG_FORMAT
/* This is for the `vdir' program. */
format = long_format;
quote_funny_chars = 1;
#else
/* This is for the `ls' program. */
if (isatty (1))
switch (ls_mode)
{
case LS_MULTI_COL:
/* This is for the `dir' program. */
format = many_per_line;
qmark_funny_chars = 1;
quote_funny_chars = 1;
break;
case LS_LONG_FORMAT:
/* This is for the `vdir' program. */
format = long_format;
quote_funny_chars = 1;
break;
case LS_LS:
/* This is for the `ls' program. */
if (isatty (1))
{
format = many_per_line;
qmark_funny_chars = 1;
}
else
{
format = one_per_line;
qmark_funny_chars = 0;
}
break;
default:
abort ();
}
else
{
format = one_per_line;
qmark_funny_chars = 0;
}
#endif
#endif
time_type = time_mtime;
full_time = 0;
sort_type = sort_name;
sort_reverse = 0;
numeric_users = 0;
@@ -552,11 +603,14 @@ decode_switches (argc, argv)
p = getenv ("TABSIZE");
tabsize = p ? atoi (p) : 8;
while ((c = getopt_long (argc, argv, "abcdgiklmnpqrstuw:xABCFI:LNQRST:UX1",
while ((c = getopt_long (argc, argv, "abcdfgiklmnpqrstuw:xABCFGI:LNQRST:UX1",
long_options, (int *) 0)) != EOF)
{
switch (c)
{
case 0:
break;
case 'a':
all_files = 1;
really_all_files = 1;
@@ -574,7 +628,18 @@ decode_switches (argc, argv)
case 'd':
immediate_dirs = 1;
break;
case 'f':
/* Same as enabling -a -U and disabling -l -s. */
all_files = 1;
really_all_files = 1;
sort_type = sort_none;
/* disable -l */
if (format == long_format)
format = (isatty (1) ? many_per_line : one_per_line);
print_block_size = 0; /* disable -s */
break;
case 'g':
/* No effect. For BSD compatibility. */
break;
@@ -651,6 +716,10 @@ decode_switches (argc, argv)
indicator_style = all;
break;
case 'G': /* inhibit display of group info */
inhibit_group = 1;
break;
case 'I':
add_ignore_pattern (optarg);
break;
@@ -695,7 +764,7 @@ decode_switches (argc, argv)
case '1':
format = one_per_line;
break;
case 10: /* +sort */
i = argmatch (optarg, sort_args);
if (i < 0)
@@ -767,7 +836,7 @@ print_dir (name, realname)
char *realname;
{
register DIR *reading;
register struct direct *next;
register struct dirent *next;
register int total_blocks = 0;
errno = 0;
@@ -842,7 +911,7 @@ add_ignore_pattern (pattern)
static int
file_interesting (next)
register struct direct *next;
register struct dirent *next;
{
register struct ignore_pattern *ignore;
@@ -942,7 +1011,12 @@ gobble_file (name, explicit_arg, dirname)
get_link_name (path, &files[files_index]);
linkpath = make_link_path (path, files[files_index].linkname);
if (linkpath && stat (linkpath, &linkstats) == 0)
/* Avoid following symbolic links when possible, ie, when
they won't be traced and when no indicator is needed. */
if (linkpath
&& ((explicit_arg && format != long_format)
|| indicator_style != none)
&& stat (linkpath, &linkstats) == 0)
{
/* Symbolic links to directories that are mentioned on the
command line are automatically traced if not being
@@ -1014,31 +1088,22 @@ get_link_name (filename, f)
char *filename;
struct file *f;
{
register char *linkbuf;
#ifdef _AIX
register int bufsiz = PATH_MAX; /* st_size is wrong. */
#else
register int bufsiz = f->stat.st_size;
#endif
char *linkbuf;
register int linksize;
linkbuf = (char *) xmalloc (bufsiz + 1);
linkbuf = (char *) alloca (PATH_MAX + 2);
/* Some automounters give incorrect st_size for mount points.
I can't think of a good workaround for it, though. */
linksize = readlink (filename, linkbuf, bufsiz);
linksize = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
if (linksize < 0)
{
error (0, errno, "%s", filename);
exit_status = 1;
free (linkbuf);
}
else
{
#ifdef _AIX
linkbuf = (char *) xrealloc (linkbuf, linksize + 1);
#endif
linkbuf[linksize] = '\0';
f->linkname = linkbuf;
f->linkname = xstrdup (linkbuf);
}
}
@@ -1166,6 +1231,8 @@ sort_files ()
case time_atime:
func = sort_reverse ? rev_cmp_atime : compare_atime;
break;
default:
abort ();
}
break;
case sort_name:
@@ -1177,6 +1244,8 @@ sort_files ()
case sort_size:
func = sort_reverse ? rev_cmp_size : compare_size;
break;
default:
abort ();
}
qsort (files, files_index, sizeof (struct file), func);
@@ -1363,25 +1432,32 @@ print_long_format (f)
}
strcpy (timebuf, ctime (&when));
if (current_time > when + 6L * 30L * 24L * 60L * 60L /* Old. */
|| current_time < when - 60L * 60L) /* In the future. */
if (full_time)
timebuf[24] = '\0';
else
{
/* The file is fairly old or in the future.
POSIX says the cutoff is 6 months old;
approximate this by 6*30 days.
Allow a 1 hour slop factor for what is considered "the future",
to allow for NFS server/client clock disagreement.
Show the year instead of the time of day. */
strcpy (timebuf + 11, timebuf + 19);
if (current_time > when + 6L * 30L * 24L * 60L * 60L /* Old. */
|| current_time < when - 60L * 60L) /* In the future. */
{
/* The file is fairly old or in the future.
POSIX says the cutoff is 6 months old;
approximate this by 6*30 days.
Allow a 1 hour slop factor for what is considered "the future",
to allow for NFS server/client clock disagreement.
Show the year instead of the time of day. */
strcpy (timebuf + 11, timebuf + 19);
}
timebuf[16] = 0;
}
timebuf[16] = 0;
if (print_inode)
printf ("%6u ", f->stat.st_ino);
printf ("%6lu ", (unsigned long) f->stat.st_ino);
if (print_block_size)
printf ("%*u ", block_size_size,
convert_blocks (ST_NBLOCKS (f->stat), kilobyte_blocks));
(unsigned) convert_blocks (ST_NBLOCKS (f->stat),
kilobyte_blocks));
/* The space between the mode and the number of links is the POSIX
"optional alternate access method flag". */
@@ -1392,10 +1468,13 @@ print_long_format (f)
else
printf ("%-8.8s ", getuser (f->stat.st_uid));
if (numeric_users)
printf ("%-8u ", (unsigned int) f->stat.st_gid);
else
printf ("%-8.8s ", getgroup (f->stat.st_gid));
if (!inhibit_group)
{
if (numeric_users)
printf ("%-8u ", (unsigned int) f->stat.st_gid);
else
printf ("%-8.8s ", getgroup (f->stat.st_gid));
}
if (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode))
printf ("%3u, %3u ", major (f->stat.st_rdev),
@@ -1403,7 +1482,7 @@ print_long_format (f)
else
printf ("%8lu ", f->stat.st_size);
printf ("%s ", timebuf + 4);
printf ("%s ", full_time ? timebuf : timebuf + 4);
print_name_with_quoting (f->name);
@@ -1499,11 +1578,12 @@ print_file_name_and_frills (f)
struct file *f;
{
if (print_inode)
printf ("%6u ", f->stat.st_ino);
printf ("%6lu ", (unsigned long) f->stat.st_ino);
if (print_block_size)
printf ("%*u ", block_size_size,
convert_blocks (ST_NBLOCKS (f->stat), kilobyte_blocks));
(unsigned) convert_blocks (ST_NBLOCKS (f->stat),
kilobyte_blocks));
print_name_with_quoting (f->name);
@@ -1800,7 +1880,7 @@ static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-abcdgiklmnpqrstuxABCFLNQRSUX1] [-w cols] [-T cols] [-I pattern]\n\
Usage: %s [-abcdgiklmnpqrstuxABCFGLNQRSUX1] [-w cols] [-T cols] [-I pattern]\n\
[--all] [--escape] [--directory] [--inode] [--kilobytes] [--literal]\n\
[--numeric-uid-gid] [--hide-control-chars] [--reverse] [--size]\n\
[--width=cols] [--tabsize=cols] [--almost-all] [--ignore-backups]\n",
@@ -1809,6 +1889,7 @@ Usage: %s [-abcdgiklmnpqrstuxABCFLNQRSUX1] [-w cols] [-T cols] [-I pattern]\n\
[--classify] [--file-type] [--ignore=pattern] [--dereference]\n\
[--quote-name] [--recursive] [--sort={none,time,size,extension}]\n\
[--format={long,verbose,commas,across,vertical,single-column}]\n\
[--time={atime,access,use,ctime,status}] [path...]\n");
[--time={atime,access,use,ctime,status}] [--no-group]\n\
[--help] [--version] [path...]\n");
exit (1);
}

10
src/ls.h Normal file
View File

@@ -0,0 +1,10 @@
/* This is for the `ls' program. */
#define LS_LS 1
/* This is for the `dir' program. */
#define LS_MULTI_COL 2
/* This is for the `vdir' program. */
#define LS_LONG_FORMAT 3
extern int ls_mode;

View File

@@ -16,7 +16,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Options:
-p, --path Ensure that the given path(s) exist:
-p, --parent Ensure that the given path(s) exist:
Make any missing parent directories for each argument.
Parent dirs default to umask modified by `u+wx'.
Do not consider an argument directory that already
@@ -27,27 +27,48 @@
David MacKenzie <djm@ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "modechange.h"
#include "version.h"
int make_path ();
void error ();
static void usage ();
/* If nonzero, ensure that a path exists. */
static int path_mode;
/* The name this program was run with. */
char *program_name;
/* If nonzero, ensure that all parents of the specified directory exist. */
static int path_mode;
/* 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[] =
{
{"mode", required_argument, NULL, 'm'},
{"path", no_argument, &path_mode, 1},
{"parents", no_argument, &path_mode, 1},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -82,9 +103,18 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind == argc)
usage ();
newmode = 0777 & ~umask (0);
parent_mode = newmode | 0300; /* u+wx */
if (symbolic_mode)
@@ -115,8 +145,8 @@ static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-p] [-m mode] [--path] [--mode=mode] dir...\n",
program_name);
Usage: %s [-p] [-m mode] [--parents] [--mode=mode]\n\
[--help] [--version] dir...\n", program_name);
exit (1);
}

View File

@@ -22,11 +22,23 @@
David MacKenzie <djm@ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "modechange.h"
#include "version.h"
void error ();
@@ -35,9 +47,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 output and exit. */
static int show_version;
static struct option const longopts[] =
{
{"mode", required_argument, NULL, 'm'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -62,6 +82,8 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'm':
symbolic_mode = optarg;
break;
@@ -70,9 +92,18 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind == argc)
usage ();
newmode = 0666 & ~umask (0);
if (symbolic_mode)
{
@@ -102,7 +133,7 @@ static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-m mode] [--mode=mode] path...\n",
Usage: %s [-m mode] [--mode=mode] [--help] [--version] path...\n",
program_name);
exit (1);
}

View File

@@ -27,11 +27,23 @@
David MacKenzie <djm@ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "modechange.h"
#include "version.h"
void error ();
@@ -40,9 +52,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 output and exit. */
static int show_version;
static struct option const longopts[] =
{
{"mode", required_argument, NULL, 'm'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -63,6 +83,8 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'm':
symbolic_mode = optarg;
break;
@@ -71,6 +93,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
newmode = 0666 & ~umask (0);
if (symbolic_mode)
{
@@ -137,8 +168,10 @@ static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-m mode] [--mode=mode] path {bcu} major minor\n\
%s [-m mode] [--mode=mode] path p\n",
Usage: %s [options] path {bcu} major minor\n\
%s [options] path p\n\
Options:\n\
[-m mode] [--mode=mode] [--help] [--version]\n",
program_name, program_name);
exit (1);
}

View File

@@ -40,11 +40,24 @@
#ifdef _AIX
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "backupfile.h"
#include "version.h"
#ifndef _POSIX_VERSION
uid_t geteuid ();
@@ -57,6 +70,7 @@ int yesno ();
void error ();
void strip_trailing_slashes ();
int eaccess_stat ();
char *stpcpy ();
static int copy_reg ();
static int do_move ();
@@ -86,6 +100,12 @@ static int stdin_tty;
/* This process's effective user ID. */
static uid_t myeuid;
/* 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[] =
{
{"backup", no_argument, NULL, 'b'},
@@ -95,6 +115,8 @@ static struct option const long_options[] =
{"update", no_argument, &update, 1},
{"verbose", no_argument, &verbose, 1},
{"version-control", required_argument, NULL, 'V'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -151,6 +173,16 @@ main (argc, argv)
usage ();
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (argc < optind + 2)
usage ();
@@ -169,6 +201,17 @@ main (argc, argv)
exit (errors);
}
/* If PATH is an existing directory, return nonzero, else 0. */
static int
is_real_dir (path)
char *path;
{
struct stat stats;
return lstat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
}
/* Move file SOURCE onto DEST. Handles the case when DEST is a directory.
Return 0 if successful, 1 if an error occurred. */
@@ -179,7 +222,8 @@ movefile (source, dest)
{
strip_trailing_slashes (source);
if (isdir (dest))
if ((dest[strlen (dest) - 1] == '/' && !is_real_dir (source))
|| isdir (dest))
{
/* Target is a directory; build full target filename. */
char *base;
@@ -187,7 +231,7 @@ movefile (source, dest)
base = basename (source);
new_dest = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1);
sprintf (new_dest, "%s/%s", dest, base);
stpcpy (stpcpy (stpcpy (new_dest, dest), "/"), base);
return do_move (source, new_dest);
}
else
@@ -252,7 +296,7 @@ do_move (source, dest)
char *tmp_backup = find_backup_file_name (dest);
if (tmp_backup == NULL)
error (1, 0, "virtual memory exhausted");
dest_backup = alloca (strlen (tmp_backup) + 1);
dest_backup = (char *) alloca (strlen (tmp_backup) + 1);
strcpy (dest_backup, tmp_backup);
free (tmp_backup);
if (rename (dest, dest_backup))
@@ -432,7 +476,8 @@ Usage: %s [options] source dest\n\
Options:\n\
[-bfiuv] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
[--backup] [--force] [--interactive] [--update] [--verbose]\n\
[--suffix=backup-suffix] [--version-control={numbered,existing,simple}]\n",
[--suffix=backup-suffix] [--version-control={numbered,existing,simple}]\n\
[--help] [--version]\n",
program_name, program_name);
exit (1);
}

View File

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

View File

@@ -24,6 +24,7 @@
#include <regex.h>
#include "linebuffer.h"
#include "system.h"
#include "version.h"
#ifndef TRUE
#define TRUE 1
@@ -47,7 +48,26 @@ enum section
{
Header, Body, Footer, Text
};
char *xmalloc ();
char *xrealloc ();
void error ();
static enum section check_section ();
static int build_type_arg ();
static int nl_file ();
static void usage ();
static void process_file ();
static void proc_header ();
static void proc_body ();
static void proc_footer ();
static void proc_text ();
static void print_lineno ();
static void build_print_fmt ();
/* The name this program was run with. */
char *program_name;
/* Format of body lines (-b). */
static char *body_type = "t";
@@ -126,28 +146,15 @@ static enum number_format lineno_format = FORMAT_RIGHT_NOLZ;
/* Current print line number. */
static int line_no;
/* The name this program was run with. */
char *program_name;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
char *xmalloc ();
char *xrealloc ();
void error ();
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static enum section check_section ();
static int build_type_arg ();
static int nl_file ();
static void usage ();
static void process_file ();
static void proc_header ();
static void proc_body ();
static void proc_footer ();
static void proc_text ();
static void print_lineno ();
static void build_print_fmt ();
static struct option const longopts[] =
{
{"header-numbering", required_argument, NULL, 'h'},
@@ -161,6 +168,8 @@ static struct option const longopts[] =
{"number-width", required_argument, NULL, 'w'},
{"number-format", required_argument, NULL, 'n'},
{"section-delimiter", required_argument, NULL, 'd'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -179,6 +188,9 @@ main (argc, argv)
{
switch (c)
{
case 0:
break;
case 'h':
if (build_type_arg (&header_type, &header_regex) != TRUE)
usage ();
@@ -250,6 +262,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
/* Initialize the section delimiters. */
c = strlen (section_del);
@@ -293,7 +314,7 @@ main (argc, argv)
exit_status = 1;
}
if (ferror (stdout) || fclose (stdout) == EOF)
error (1, 0, "write error");
error (1, errno, "write error");
exit (exit_status);
}
@@ -541,7 +562,7 @@ Usage: %s [-h header-style] [-b body-style] [-f footer-style] [-p] [-d cc]\n\
[--first-page=number] [--page-increment=number] [--no-renumber]\n\
[--join-blank-lines=number] [--number-separator=string]\n\
[--number-width=number] [--number-format={ln,rn,rz}]\n\
[--section-delimiter=cc] [file...]\n",
[--section-delimiter=cc] [--help] [--version] [file...]\n",
program_name);
exit (2);
}

343
src/od.c
View File

@@ -37,12 +37,13 @@ char *alloca ();
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
#if defined(__GNUC__) || defined(STDC_HEADERS)
#include <float.h>
#endif
#ifdef __STDC__
#ifdef HAVE_LONG_DOUBLE
typedef long double LONG_DOUBLE;
#else
typedef double LONG_DOUBLE;
@@ -54,9 +55,15 @@ typedef double LONG_DOUBLE;
#ifndef SCHAR_MAX
#define SCHAR_MAX 127
#endif
#ifndef SCHAR_MIN
#define SCHAR_MIN (-128)
#endif
#ifndef SHRT_MAX
#define SHRT_MAX 32767
#endif
#ifndef SHRT_MIN
#define SHRT_MIN (-32768)
#endif
#ifndef ULONG_MAX
#define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
#endif
@@ -94,43 +101,46 @@ char *xrealloc ();
void error ();
enum size_spec
{
NO_SIZE,
CHAR,
SHORT,
INT,
LONG,
FP_SINGLE,
FP_DOUBLE,
FP_LONG_DOUBLE
};
{
NO_SIZE,
CHAR,
SHORT,
INT,
LONG,
FP_SINGLE,
FP_DOUBLE,
FP_LONG_DOUBLE
};
enum output_format
{
SIGNED_DECIMAL,
UNSIGNED_DECIMAL,
OCTAL,
HEXADECIMAL,
FLOATING_POINT,
NAMED_CHARACTER,
CHARACTER
};
{
SIGNED_DECIMAL,
UNSIGNED_DECIMAL,
OCTAL,
HEXADECIMAL,
FLOATING_POINT,
NAMED_CHARACTER,
CHARACTER
};
enum strtoul_error
{
UINT_OK, UINT_INVALID, UINT_INVALID_SUFFIX_CHAR, UINT_OVERFLOW
};
{
UINT_OK, UINT_INVALID, UINT_INVALID_SUFFIX_CHAR, UINT_OVERFLOW
};
typedef enum strtoul_error strtoul_error;
/* Each output format specification (from POSIX `-t spec' or from
old-style options) is represented by one of these structures. */
struct tspec
{
enum output_format fmt;
enum size_spec size;
void (*print_function) ();
char *fmt_string;
};
{
enum output_format fmt;
enum size_spec size;
void (*print_function) ();
char *fmt_string;
};
/* The name this program was run with. */
char *program_name;
/* Convert the number of 8-bit bytes of a binary representation to
the number of characters (digits + sign if the type is signed)
@@ -182,12 +192,31 @@ static const char *output_address_fmt_string;
/* FIXME: make this the number of octal digits in an unsigned long. */
#define MAX_ADDRESS_LENGTH 13
static char address_fmt_buffer[MAX_ADDRESS_LENGTH + 1];
/* Space for a normal address, a space, a pseudo address, parentheses
around the pseudo address, and a trailing zero byte. */
static char address_fmt_buffer[2 * MAX_ADDRESS_LENGTH + 4];
static char address_pad[MAX_ADDRESS_LENGTH + 1];
static unsigned long int string_min;
static unsigned long int flag_dump_strings;
/* Non-zero if we should recognize the pre-POSIX non-option arguments
that specified at most one file and optional arguments specifying
offset and pseudo-start address. */
static int flag_compatibility;
/* Non-zero if an old-style `pseudo-address' was specified. */
static long int flag_pseudo_start;
/* The difference between the old-style pseudo starting address and
the number of bytes to skip. */
static long int pseudo_offset;
/* Function to format an address and optionally an additional parenthesized
pseudo-address; it returns the formatted string. */
static const char *(*format_address) (/* long unsigned int */);
/* The number of input bytes to skip before formatting and writing. */
static unsigned long int n_bytes_to_skip = 0;
@@ -242,6 +271,12 @@ static enum size_spec integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1];
#define MAX_FP_TYPE_SIZE sizeof(LONG_DOUBLE)
static enum size_spec fp_type_size[MAX_FP_TYPE_SIZE + 1];
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const long_options[] =
{
/* POSIX options. */
@@ -252,14 +287,14 @@ static struct option const long_options[] =
{"output-duplicates", no_argument, NULL, 'v'},
/* non-POSIX options. */
{"compatible", no_argument, NULL, 'C'},
{"strings", optional_argument, NULL, 's'},
{"width", optional_argument, NULL, 'w'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
/* The name this program was run with. */
char *program_name;
static void
usage ()
{
@@ -267,7 +302,7 @@ usage ()
Usage: %s [-abcdfhiloxv] [-s[bytes]] [-w[bytes]] [-A radix] [-j bytes]\n\
[-N bytes] [-t type] [--skip-bytes=bytes] [--address-radix=radix]\n\
[--read-bytes=bytes] [--format=type] [--output-duplicates]\n\
[--strings[=bytes]] [--width[=bytes]] [file...]\n",
[--strings[=bytes]] [--width[=bytes]] [--help] [--version] [file...]\n",
program_name);
exit (1);
}
@@ -336,25 +371,25 @@ my_strtoul (s, base, val, allow_bkm_suffix)
case '\0':
break;
#define BKM_SCALE(x,scale_factor) \
#define BKM_SCALE(x,scale_factor,error_return) \
do \
{ \
if (x > (double) ULONG_MAX / scale_factor) \
return UINT_OVERFLOW; \
return error_return; \
x *= scale_factor; \
} \
while (0)
case 'b':
BKM_SCALE (tmp, 512);
BKM_SCALE (tmp, 512, UINT_OVERFLOW);
break;
case 'k':
BKM_SCALE (tmp, 1024);
BKM_SCALE (tmp, 1024, UINT_OVERFLOW);
break;
case 'm':
BKM_SCALE (tmp, 1024 * 1024);
BKM_SCALE (tmp, 1024 * 1024, UINT_OVERFLOW);
break;
default:
@@ -404,7 +439,7 @@ print_s_char (n_bytes, block, fmt_string)
{
int tmp = (unsigned) *(const unsigned char *) block;
if (tmp > SCHAR_MAX)
tmp = (SCHAR_MAX - tmp);
tmp -= SCHAR_MAX - SCHAR_MIN + 1;
assert (tmp <= SCHAR_MAX);
printf (fmt_string, tmp, (i == 1 ? '\n' : ' '));
block += sizeof (unsigned char);
@@ -437,13 +472,12 @@ print_s_short (n_bytes, block, fmt_string)
{
int tmp = (unsigned) *(const unsigned short *) block;
if (tmp > SHRT_MAX)
tmp = (SHRT_MAX - tmp);
tmp -= SHRT_MAX - SHRT_MIN + 1;
assert (tmp <= SHRT_MAX);
printf (fmt_string, tmp, (i == 1 ? '\n' : ' '));
block += sizeof (unsigned short);
}
}
static void
print_short (n_bytes, block, fmt_string)
long unsigned int n_bytes;
@@ -519,7 +553,7 @@ print_double (n_bytes, block, fmt_string)
}
}
#ifdef __STDC__
#ifdef HAVE_LONG_DOUBLE
static void
print_long_double (n_bytes, block, fmt_string)
long unsigned int n_bytes;
@@ -737,7 +771,7 @@ decode_one_format (s, next, tspec)
{
case 'd':
fmt = SIGNED_DECIMAL;
sprintf (fmt_string, "%%0%u%sd%%c",
sprintf (fmt_string, "%%%u%sd%%c",
bytes_to_signed_dec_digits[size],
(size_spec == LONG ? "l" : ""));
break;
@@ -751,7 +785,7 @@ decode_one_format (s, next, tspec)
case 'u':
fmt = UNSIGNED_DECIMAL;
sprintf (fmt_string, "%%0%u%su%%c",
sprintf (fmt_string, "%%%u%su%%c",
bytes_to_unsigned_dec_digits[size],
(size_spec == LONG ? "l" : ""));
break;
@@ -851,7 +885,7 @@ decode_one_format (s, next, tspec)
DBL_DIG + 8, DBL_DIG);
break;
#ifdef __STDC__
#ifdef HAVE_LONG_DOUBLE
case FP_LONG_DOUBLE:
print_function = print_long_double;
pre_fmt_string = "%%%d.%dle%%c";
@@ -999,7 +1033,7 @@ skip (n_skip)
if (n_skip >= file_stats.st_size)
{
n_skip -= file_stats.st_size;
if (in_stream != stdin && fclose (in_stream))
if (in_stream != stdin && fclose (in_stream) == EOF)
{
error (0, errno, "%s", input_filename);
err = 1;
@@ -1042,18 +1076,33 @@ skip (n_skip)
}
static const char *
format_address (address)
format_address_none (address)
long unsigned int address;
{
return "";
}
static const char *
format_address_std (address)
long unsigned int address;
{
const char *address_string;
if (output_address_fmt_string == NULL)
address_string = "";
else
{
sprintf (address_fmt_buffer, output_address_fmt_string, address);
address_string = address_fmt_buffer;
}
sprintf (address_fmt_buffer, output_address_fmt_string, address);
address_string = address_fmt_buffer;
return address_string;
}
static const char *
format_address_label (address)
long unsigned int address;
{
const char *address_string;
assert (output_address_fmt_string != NULL);
sprintf (address_fmt_buffer, output_address_fmt_string,
address, address + pseudo_offset);
address_string = address_fmt_buffer;
return address_string;
}
@@ -1295,6 +1344,64 @@ get_lcm ()
return l_c_m;
}
/* If S is a valid pre-POSIX offset specification with an optional leading '+'
return the offset it denotes. Otherwise, return -1. */
long int
parse_old_offset (s)
const char *s;
{
int radix;
char *suffix;
long offset;
if (*s == '\0')
return -1;
/* Skip over any leading '+'. */
if (s[0] == '+')
++s;
/* Determine the radix we'll use to interpret S. If there is a `.',
it's decimal, otherwise, if the string begins with `0X'or `0x',
it's hexadecimal, else octal. */
if (index (s, '.') != NULL)
radix = 10;
else
{
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
radix = 16;
else
radix = 8;
}
offset = strtoul (s, &suffix, radix);
if (suffix == s || errno != 0)
return -1;
if (*suffix == '.')
++suffix;
switch (*suffix)
{
case 'b':
BKM_SCALE (offset, 512, -1);
++suffix;
break;
case 'B':
BKM_SCALE (offset, 1024, -1);
++suffix;
break;
default:
/* empty */
break;
}
if (*suffix != '\0')
return -1;
else
return offset;
}
/* Read a chunk of size BYTES_PER_BLOCK from the input files, write the
formatted block to standard output, and repeat until the specified
maximum number of bytes has been read or until all input has been
@@ -1520,6 +1627,10 @@ main (argc, argv)
int width_specified = 0;
int err;
/* The old-style `pseudo starting address' to be printed in parentheses
after any true address. */
long int pseudo_start;
program_name = argv[0];
err = 0;
@@ -1546,10 +1657,11 @@ main (argc, argv)
spec = (struct tspec *) xmalloc (n_specs_allocated * sizeof (struct tspec));
output_address_fmt_string = "%07o";
format_address = format_address_std;
address_pad_len = 7;
flag_dump_strings = 0;
while ((c = getopt_long (argc, argv, "abcdfhilos::xw::A:j:N:t:v",
while ((c = getopt_long (argc, argv, "abcCdfhilos::xw::A:j:N:t:v",
long_options, (int *) 0))
!= EOF)
{
@@ -1557,23 +1669,30 @@ main (argc, argv)
switch (c)
{
case 0:
break;
case 'A':
switch (optarg[0])
{
case 'd':
output_address_fmt_string = "%07d";
format_address = format_address_std;
address_pad_len = 7;
break;
case 'o':
output_address_fmt_string = "%07o";
format_address = format_address_std;
address_pad_len = 7;
break;
case 'x':
output_address_fmt_string = "%06x";
format_address = format_address_std;
address_pad_len = 6;
break;
case 'n':
output_address_fmt_string = NULL;
format_address = format_address_none;
address_pad_len = 0;
break;
default:
@@ -1619,6 +1738,10 @@ main (argc, argv)
abbreviate_duplicate_blocks = 0;
break;
case 'C':
flag_compatibility = 1;
break;
/* The next several cases map the old, pre-POSIX format
specification options to the corresponding POSIX format
specs. GNU od accepts any combination of old- and
@@ -1666,9 +1789,112 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (flag_dump_strings && n_specs > 0)
error (2, 0, "no type may be specified when dumping strings");
n_files = argc - optind;
/* If the --compatible option is used, there may be from 0 to 3
remaining command line arguments; handle each case separately.
od [file] [[+]offset[.][b] [[+]label[.][b]]]
The offset and pseudo_start have the same syntax. */
if (flag_compatibility)
{
long int offset;
if (n_files == 1)
{
if ((offset = parse_old_offset (argv[optind])) >= 0)
{
n_bytes_to_skip = offset;
--n_files;
++argv;
}
}
else if (n_files == 2)
{
long int o1, o2;
if ((o1 = parse_old_offset (argv[optind])) >= 0
&& (o2 = parse_old_offset (argv[optind + 1])) >= 0)
{
n_bytes_to_skip = o1;
flag_pseudo_start = 1;
pseudo_start = o2;
argv += 2;
n_files -= 2;
}
else if ((o2 = parse_old_offset (argv[optind + 1])) >= 0)
{
n_bytes_to_skip = o2;
--n_files;
argv[optind + 1] = argv[optind];
++argv;
}
else
{
error (0, 0,
"invalid second operand in compatibility mode `%s'",
argv[optind + 1]);
usage ();
}
}
else if (n_files == 3)
{
long int o1, o2;
if ((o1 = parse_old_offset (argv[optind + 1])) >= 0
&& (o2 = parse_old_offset (argv[optind + 2])) >= 0)
{
n_bytes_to_skip = o1;
flag_pseudo_start = 1;
pseudo_start = o2;
argv[optind + 2] = argv[optind];
argv += 2;
n_files -= 2;
}
else
{
error (0, 0,
"in compatibility mode the last 2 arguments must be offsets");
usage ();
}
}
else
{
error (0, 0,
"in compatibility mode there may be no more than 3 arguments");
usage ();
}
if (flag_pseudo_start)
{
static char buf[10];
if (output_address_fmt_string == NULL)
{
output_address_fmt_string = "(%07o)";
format_address = format_address_std;
}
else
{
sprintf (buf, "%s (%s)",
output_address_fmt_string,
output_address_fmt_string);
output_address_fmt_string = buf;
format_address = format_address_label;
}
}
}
assert (address_pad_len <= MAX_ADDRESS_LENGTH);
for (i = 0; i < address_pad_len; i++)
address_pad[i] = ' ';
@@ -1682,7 +1908,6 @@ main (argc, argv)
n_specs = 1;
}
n_files = argc - optind;
if (n_files > 0)
file_list = (char const *const *) &argv[optind];
else
@@ -1697,6 +1922,8 @@ main (argc, argv)
err |= skip (n_bytes_to_skip);
pseudo_offset = (flag_pseudo_start ? pseudo_start - n_bytes_to_skip : 0);
/* Compute output block length. */
l_c_m = get_lcm ();
@@ -1727,7 +1954,7 @@ main (argc, argv)
}
#endif
err |= (flag_dump_strings ? dump_strings () : dump ());
err |= (flag_dump_strings ? dump_strings () : dump ());
if (have_read_stdin && fclose (stdin) == EOF)
error (2, errno, "standard input");

View File

@@ -42,6 +42,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
void error ();
char *xmalloc ();
@@ -77,10 +78,18 @@ static char *delims;
/* A pointer to the character after the end of `delims'. */
static char *delim_end;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const longopts[] =
{
{"serial", no_argument, 0, 's'},
{"delimiters", required_argument, 0, 'd'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -104,6 +113,9 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'd':
/* Delimiter character(s). */
if (optarg[0] == '\0')
@@ -120,6 +132,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind == argc)
argv[argc++] = "-";
@@ -453,7 +474,7 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-s] [-d delim-list] [--serial] [--delimiters=delim-list]\n\
[file...]\n",
[--help] [--version] [file...]\n",
program_name);
exit (1);
}

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;

213
src/pr.c
View File

@@ -99,6 +99,7 @@
#include <sys/types.h>
#include <time.h>
#include "system.h"
#include "version.h"
char *xmalloc ();
char *xrealloc ();
@@ -195,6 +196,9 @@ typedef struct COLUMN COLUMN;
#define NULLCOL (COLUMN *)0
/* The name under which this program was invoked. */
char *program_name;
/* All of the columns to print. */
static COLUMN *column_vector;
@@ -246,9 +250,6 @@ static int standard_header = TRUE;
/* (-f) True means use formfeeds instead of newlines to separate pages. */
static int use_form_feed = FALSE;
/* True means we haven't encountered any filenames in the argument list. */
static int input_is_stdin = TRUE;
/* True means we have read the standard input. */
static int have_read_stdin = FALSE;
@@ -342,9 +343,6 @@ static int first_page_number = 1;
/* Number of files open (not closed, not on hold). */
static int files_ready_to_read = 0;
/* Number of columns with either an open file or stored lines. */
static int cols_ready_to_print = 0;
/* Current page number. Displayed in header. */
static int page_number;
@@ -427,87 +425,106 @@ static int *clump_buff;
/* True means we truncate lines longer than chars_per_column. */
static int truncate_lines = FALSE;
/* The name under which this program was invoked. */
char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then 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}
};
/* Return the number of columns that have either an open file or
stored lines. */
static int
cols_ready_to_print ()
{
COLUMN *q;
int i;
int n;
n = 0;
for (q = column_vector, i = 0; i < columns; ++q, ++i)
if (q->status == OPEN ||
(storing_columns && q->lines_stored > 0 && q->lines_to_print > 0))
++n;
return n;
}
void
main (argc, argv)
int argc;
char **argv;
{
int c;
char *s;
int files = 0;
char **file_names, **file_name_vector;
int accum = 0;
int n_files;
char **file_names;
program_name = argv[0];
file_name_vector = (char **) xmalloc (argc * sizeof (char **));
file_names = file_name_vector;
n_files = 0;
file_names = (char **) xmalloc ((argc - 1) * sizeof (char *));
for (;;)
while (1)
{
c = getopt (argc, argv, "-0123456789abcde::fFh:i::l:mn::o:rs::tvw:");
if (c == 1) /* Non-option argument. */
c = getopt_long (argc, argv,
"-0123456789abcde::fFh:i::l:mn::o:rs::tvw:",
long_options, (int *) 0);
if (c == 1) /* Non-option argument. */
{
char *s;
s = optarg;
if (*s == '+')
{
++s;
if (!ISDIGIT (*s))
usage ("`+' requires a numeric argument");
{
error (0, 0, "`+' requires a numeric argument");
usage ();
}
/* FIXME: use strtol */
first_page_number = atoi (s);
}
else
{
*file_names++ = optarg;
++files;
file_names[n_files++] = optarg;
}
}
else if (files > 0)
{
if (parallel_files && explicit_columns)
error (1, 0,
"Cannot specify number of columns when printing in parallel.");
if (parallel_files && print_across_flag)
error (1, 0,
"Cannot specify both printing across and printing in parallel.");
if (parallel_files)
print_files (files, file_name_vector);
else
{
file_names = file_name_vector;
while (files--)
print_files (1, file_names++);
}
input_is_stdin = FALSE;
file_names = file_name_vector;
files = 0;
cleanup ();
}
if (ISDIGIT (c))
{
accum = accum * 10 + c - '0';
continue;
}
else
{
if (accum > 0)
if (ISDIGIT (c))
{
columns = accum;
explicit_columns = TRUE;
accum = accum * 10 + c - '0';
continue;
}
else
{
if (accum > 0)
{
columns = accum;
explicit_columns = TRUE;
accum = 0;
}
}
accum = 0;
}
if (c == 1)
continue;
if (c == EOF)
break;
switch (c)
{
case 0: /* getopt long option */
break;
case 'a':
print_across_flag = TRUE;
storing_columns = FALSE;
@@ -566,6 +583,7 @@ main (argc, argv)
use_column_separator = TRUE;
if (optarg)
{
char *s;
s = optarg;
column_separator = *s;
if (*++s)
@@ -573,7 +591,7 @@ main (argc, argv)
fprintf (stderr, "\
%s: extra characters in the argument to the `-s' option: `%s'\n",
program_name, s);
usage ((char *) 0);
usage ();
}
}
break;
@@ -586,17 +604,52 @@ main (argc, argv)
case 'w':
chars_per_line = atoi (optarg);
break;
case '?':
usage ((char *) 0);
default:
usage ();
break;
}
if (c == EOF)
break;
}
if (input_is_stdin)
print_files (0, (char **) 0);
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (parallel_files && explicit_columns)
error (1, 0,
"Cannot specify number of columns when printing in parallel.");
if (parallel_files && print_across_flag)
error (1, 0,
"Cannot specify both printing across and printing in parallel.");
for ( ; optind < argc; optind++)
{
file_names[n_files++] = argv[optind];
}
if (n_files == 0)
{
/* No file arguments specified; read from standard input. */
print_files (0, (char **) 0);
}
else
{
if (parallel_files)
print_files (n_files, file_names);
else
{
int i;
for (i=0; i<n_files; i++)
print_files (1, &file_names[i]);
}
}
cleanup ();
if (have_read_stdin && fclose (stdin) == EOF)
error (1, errno, "standard input");
@@ -629,7 +682,7 @@ getoptarg (arg, switch_char, character, number)
fprintf (stderr, "\
%s: extra characters in the argument to the `-%c' option: `%s'\n",
program_name, switch_char, arg);
usage ((char *) 0);
usage ();
}
}
}
@@ -919,10 +972,6 @@ close_file (p)
q->status = CLOSED;
if (q->lines_stored == 0)
{
#if 0
if (cols_ready_to_print > 0)
--cols_ready_to_print;
#endif
q->lines_to_print = 0;
}
}
@@ -1073,24 +1122,18 @@ init_page ()
int j;
COLUMN *p;
cols_ready_to_print = 0;
if (storing_columns)
{
store_columns ();
for (j = columns - 1, p = column_vector; j; --j, ++p)
{
p->lines_to_print = p->lines_stored;
if (p->lines_to_print != 0)
++cols_ready_to_print;
}
/* Last column. */
if (balance_columns)
{
p->lines_to_print = p->lines_stored;
if (p->lines_to_print != 0)
++cols_ready_to_print;
}
/* Since we're not balancing columns, we don't need to store
the rightmost column. Read it straight from the file. */
@@ -1099,7 +1142,6 @@ init_page ()
if (p->status == OPEN)
{
p->lines_to_print = lines_per_body;
++cols_ready_to_print;
}
else
p->lines_to_print = 0;
@@ -1110,7 +1152,6 @@ init_page ()
if (p->status == OPEN)
{
p->lines_to_print = lines_per_body;
++cols_ready_to_print;
}
else
p->lines_to_print = 0;
@@ -1145,7 +1186,7 @@ print_page ()
init_page ();
if (cols_ready_to_print == 0)
if (cols_ready_to_print () == 0)
return FALSE;
if (extremities)
@@ -1159,7 +1200,7 @@ print_page ()
if (double_space)
lines_left_on_page *= 2;
while (lines_left_on_page > 0 && cols_ready_to_print > 0)
while (lines_left_on_page > 0 && cols_ready_to_print () > 0)
{
output_position = 0;
spaces_not_printed = 0;
@@ -1180,8 +1221,12 @@ print_page ()
if (use_column_separator)
++separators_not_printed;
if (--p->lines_to_print <= 0 && --cols_ready_to_print <= 0)
break;
--p->lines_to_print;
if (p->lines_to_print <= 0)
{
if (cols_ready_to_print () <= 0)
break;
}
}
}
@@ -1818,17 +1863,13 @@ cleanup ()
/* Complain, print a usage message, and die. */
static void
usage (reason)
char *reason;
usage ()
{
if (reason)
fprintf (stderr, "%s: %s\n", program_name, reason);
fprintf (stderr, "\
Usage: %s [+PAGE] [-COLUMN] [-abcdfFmrtv] [-e[in-tab-char[in-tab-width]]]\n\
[-h header] [-i[out-tab-char[out-tab-width]]] [-l page-length]\n\
[-n[number-separator[digits]]] [-o left-margin]\n\
[-s[column-separator]] [-w page-width] [file...]\n",
[-s[column-separator]] [-w page-width] [--help] [--version] [file...]\n",
program_name);
exit (2);
}

View File

@@ -48,7 +48,8 @@
#include <sys/types.h>
#include "system.h"
#ifndef isascii
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
#define isascii(c) 1
#endif

View File

@@ -17,10 +17,22 @@
/* Written by Paul Rubin, David MacKenzie, and Richard Stallman. */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
#ifdef _POSIX_SOURCE
/* POSIX.1 doesn't have inodes, so fake them to avoid lots of ifdefs. */
@@ -46,6 +58,9 @@ static int remove_file ();
static int rm ();
static void usage ();
/* Name this program was run with. */
char *program_name;
/* Path of file now being processed; extended as necessary. */
static char *pathname;
@@ -53,9 +68,6 @@ static char *pathname;
made larger when necessary, but never smaller. */
static int pnsize;
/* Name this program was run with. */
char *program_name;
/* If nonzero, display the name of each file removed. */
static int verbose;
@@ -76,6 +88,12 @@ static int unlink_dirs;
/* If nonzero, stdin is a tty. */
static int stdin_tty;
/* 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_opts[] =
{
{"directory", no_argument, &unlink_dirs, 1},
@@ -83,6 +101,8 @@ static struct option const long_opts[] =
{"interactive", no_argument, NULL, 'i'},
{"recursive", no_argument, &recursive, 1},
{"verbose", no_argument, &verbose, 1},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -129,9 +149,23 @@ main (argc, argv)
}
}
if (optind == argc)
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind == argc)
{
if (ignore_missing_files)
exit (0);
else
usage ();
}
stdin_tty = isatty (0);
for (; optind < argc; optind++)
@@ -194,7 +228,11 @@ remove_file (statp)
struct stat *statp;
{
if (!ignore_missing_files && (interactive || stdin_tty)
&& eaccess_stat (statp, W_OK))
&& eaccess_stat (statp, W_OK)
#ifdef S_ISLNK
&& !S_ISLNK (statp->st_mode)
#endif
)
{
fprintf (stderr, "%s: remove %s`%s', overriding mode %04o? ",
program_name,
@@ -311,7 +349,7 @@ clear_directory (statp)
struct stat *statp;
{
DIR *dirp;
struct direct *dp;
struct dirent *dp;
char *name_space; /* Copy of directory's filenames. */
char *namep; /* Current entry in `name_space'. */
unsigned name_size; /* Bytes allocated for `name_space'. */
@@ -319,7 +357,8 @@ clear_directory (statp)
int pathname_length; /* Length of `pathname'. */
ino_t *inode_space; /* Copy of directory's inodes. */
ino_t *inodep; /* Current entry in `inode_space'. */
unsigned inode_size; /* Bytes allocated for `inode_space'. */
unsigned n_inodes_allocated; /* There is space for this many inodes
in `inode_space'. */
int err = 0; /* Return status. */
struct pathstack pathframe; /* New top of stack. */
struct pathstack *pp; /* Temporary. */
@@ -327,8 +366,8 @@ clear_directory (statp)
name_size = statp->st_size;
name_space = (char *) xmalloc (name_size);
inode_size = statp->st_size;
inode_space = (ino_t *) xmalloc (inode_size);
n_inodes_allocated = (statp->st_size + sizeof (ino_t) - 1) / sizeof (ino_t);
inode_space = (ino_t *) xmalloc (n_inodes_allocated * sizeof (ino_t));
do
{
@@ -371,12 +410,13 @@ clear_directory (statp)
}
namep = stpcpy (namep, dp->d_name) + 1;
if (inodep == inode_space + inode_size)
if (inodep == inode_space + n_inodes_allocated)
{
ino_t *new_inode_space;
inode_size += 1024;
new_inode_space = (ino_t *) xrealloc (inode_space, inode_size);
n_inodes_allocated += 1024;
new_inode_space = (ino_t *) xrealloc (inode_space,
n_inodes_allocated * sizeof (ino_t));
inodep += new_inode_space - inode_space;
inode_space = new_inode_space;
}
@@ -490,7 +530,7 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-dfirvR] [--directory] [--force] [--interactive] [--recursive]\n\
[--verbose] path...\n",
[--verbose] [--help] [--version] path...\n",
program_name);
exit (1);
}

View File

@@ -16,16 +16,28 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Options:
-p, --path Remove any parent dirs that are explicitly mentioned
-p, --parent Remove any parent dirs that are explicitly mentioned
in an argument, if they become empty after the
argument file is removed.
David MacKenzie <djm@ai.mit.edu> */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
void error ();
void strip_trailing_slashes ();
@@ -33,15 +45,24 @@ void strip_trailing_slashes ();
static void remove_parents ();
static void usage ();
/* The name this program was run with. */
char *program_name;
/* If nonzero, remove empty parent directories. */
static int empty_paths;
/* 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[] =
{
{"path", no_argument, &empty_paths, 1},
{"parents", no_argument, &empty_paths, 1},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -70,9 +91,18 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind == argc)
usage ();
for (; optind < argc; ++optind)
{
/* Stripping slashes is harmless for rmdir;
@@ -116,7 +146,7 @@ remove_parents (path)
static void
usage ()
{
fprintf (stderr, "Usage: %s [-p] [--path] dir...\n",
fprintf (stderr, "Usage: %s [-p] [--parents] [--help] [--version] dir...\n",
program_name);
exit (1);
}

View File

@@ -554,6 +554,11 @@ findlines (buf, lines)
lines->lines[lines->used].keybeg = beg;
}
}
else
{
lines->lines[lines->used].keybeg = 0;
lines->lines[lines->used].keylim = 0;
}
++lines->used;
beg = ptr + 1;
@@ -630,6 +635,11 @@ numcompare (a, b)
tmpa = UCHAR (*a), tmpb = UCHAR (*b);
while (blanks[tmpa])
tmpa = UCHAR (*++a);
while (blanks[tmpb])
tmpb = UCHAR (*++b);
if (tmpa == '-')
{
tmpa = UCHAR (*++a);
@@ -724,6 +734,9 @@ getmonth (s, len)
char month[4];
register int i, lo = 0, hi = 12;
while (len > 0 && blanks[UCHAR(*s)])
++s, --len;
if (len < 3)
return 0;
@@ -877,36 +890,34 @@ compare (a, b)
{
int diff, tmpa, tmpb, mini;
/* First try to compare on the specified keys (if any).
The only two cases with no key at all are unadorned sort,
and unadorned sort -r. */
if (keyhead.next)
{
diff = keycompare (a, b);
if (diff)
if (diff != 0)
return diff;
if (!unique && !stable)
{
tmpa = a->length, tmpb = b->length;
diff = memcmp (a->text, b->text, min (tmpa, tmpb));
if (!diff)
diff = tmpa - tmpb;
}
if (unique || stable)
return 0;
}
/* If the keys all compare equal (or no keys were specified)
fall through to the default byte-by-byte comparison. */
tmpa = a->length, tmpb = b->length;
mini = min (tmpa, tmpb);
if (mini == 0)
diff = tmpa - tmpb;
else
{
tmpa = a->length, tmpb = b->length;
mini = min (tmpa, tmpb);
if (mini == 0)
diff = tmpa - tmpb;
else
{
char *ap = a->text, *bp = b->text;
char *ap = a->text, *bp = b->text;
diff = *ap - *bp;
diff = UCHAR (*ap) - UCHAR (*bp);
if (diff == 0)
{
diff = memcmp (ap, bp, mini);
if (diff == 0)
{
diff = memcmp (ap, bp, mini);
if (diff == 0)
diff = tmpa - tmpb;
}
diff = tmpa - tmpb;
}
}
@@ -1069,6 +1080,18 @@ mergefps (fps, nfps, ofp)
saved.length = lines[ord[0]].lines[cur[ord[0]]].length;
bcopy (lines[ord[0]].lines[cur[ord[0]]].text, saved.text,
saved.length + 1);
if (lines[ord[0]].lines[cur[ord[0]]].keybeg != NULL)
{
saved.keybeg = saved.text +
(lines[ord[0]].lines[cur[ord[0]]].keybeg
- lines[ord[0]].lines[cur[ord[0]]].text);
}
if (lines[ord[0]].lines[cur[ord[0]]].keylim != NULL)
{
saved.keylim = saved.text +
(lines[ord[0]].lines[cur[ord[0]]].keylim
- lines[ord[0]].lines[cur[ord[0]]].text);
}
savedflag = 1;
}
}
@@ -1308,7 +1331,7 @@ sort (files, nfiles, ofp)
{
tempfiles = (char **) xmalloc (ntemp * sizeof (char *));
i = ntemp;
for (node = temphead.next; node; node = node->next)
for (node = temphead.next; i > 0; node = node->next)
tempfiles[--i] = node->name;
merge (tempfiles, ntemp, ofp);
free ((char *) tempfiles);
@@ -1392,10 +1415,10 @@ set_ordering (s, key, blanktype)
key->ignore = nonprinting;
break;
case 'M':
key->skipsblanks = key->skipeblanks = key->month = 1;
key->month = 1;
break;
case 'n':
key->skipsblanks = key->skipeblanks = key->numeric = 1;
key->numeric = 1;
break;
case 'r':
key->reverse = 1;
@@ -1673,9 +1696,9 @@ main (argc, argv)
}
if (!keyhead.next && (gkey.ignore || gkey.translate || gkey.skipsblanks
|| gkey.reverse || gkey.skipeblanks
|| gkey.month || gkey.numeric))
|| gkey.skipeblanks || gkey.month || gkey.numeric))
insertkey (&gkey);
reverse = gkey.reverse;
if (nfiles == 0)
{
@@ -1724,10 +1747,18 @@ main (argc, argv)
sort (files, nfiles, ofp);
cleanup ();
/* If we wait for the implicit flush on exit, and the parent process
has closed stdout (e.g., exec >&- in a shell), then the output file
winds up empty. I don't understand why. This is under SunOS,
Solaris, Ultrix, and Irix. This premature fflush makes the output
reappear. --karl@cs.umb.edu */
if (fflush (ofp) < 0)
error (1, errno, "fflush", outfile);
if (have_read_stdin && fclose (stdin) == EOF)
error (1, errno, "-");
if (ferror (stdout) || fclose (stdout) == EOF)
error (1, 0, "write error");
error (1, errno, "write error");
exit (0);
}

View File

@@ -25,6 +25,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
char *xmalloc ();
void error ();
@@ -38,7 +39,7 @@ static void cwrite ();
static void lines_split ();
static void next_file_name ();
/* Name under which this program was invoked. */
/* The name this program was run with. */
char *program_name;
/* Base name of output files. */
@@ -64,7 +65,23 @@ static int input_desc;
/* Descriptor on which output file is open. */
static int output_desc;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const longopts[] =
{
{"bytes", required_argument, NULL, 'b'},
{"lines", required_argument, NULL, 'l'},
{"line-bytes", required_argument, NULL, 'C'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
static void
usage (reason)
char *reason;
@@ -74,18 +91,10 @@ usage (reason)
fprintf (stderr, "\
Usage: %s [-lines] [-l lines] [-b bytes[bkm]] [-C bytes[bkm]]\n\
[--lines=lines] [--bytes=bytes[bkm]] [--line-bytes=bytes[bkm]]\n\
[infile [outfile-prefix]]\n",
[--help] [--version] [infile [outfile-prefix]]\n",
program_name);
exit (2);
}
static struct option const longopts[] =
{
{"bytes", required_argument, NULL, 'b'},
{"lines", required_argument, NULL, 'l'},
{"line-bytes", required_argument, NULL, 'C'},
{NULL, 0, NULL, 0}
};
void
main (argc, argv)
@@ -123,6 +132,9 @@ main (argc, argv)
switch (c)
{
case 0:
break;
case 'b':
if (split_type != type_undef)
usage ("cannot split in more than one way");
@@ -172,6 +184,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ((char *)0);
/* Handle default case. */
if (split_type == type_undef)
{

View File

@@ -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>
@@ -105,6 +105,9 @@
#if defined(VLNEXT) && !defined(CLNEXT)
#define CLNEXT Control ('v')
#endif
#if defined(VFLUSHO) && !defined(CFLUSHO)
#define CFLUSHO Control ('o')
#endif
char *visible ();
unsigned long baud_to_value ();
@@ -346,6 +349,9 @@ static struct control_info control_info[] =
#ifdef VLNEXT
{"lnext", CLNEXT, VLNEXT},
#endif
#ifdef VFLUSHO
{"flush", CFLUSHO, VFLUSHO},
#endif
/* These must be last because of the display routines. */
{"min", 1, VMIN},

View File

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

View File

@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
#include "version.h"
static int bsd_sum_file ();
static int sysv_sum_file ();
@@ -38,12 +39,28 @@ static int have_read_stdin;
/* Right-rotate 32-bit integer variable C. */
#define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x8000; else (c) >>= 1;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const longopts[] =
{
{"sysv", no_argument, NULL, 's'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-rs] [--help] [--version] [--sysv] [file...]\n", program_name);
exit (1);
}
void
main (argc, argv)
int argc;
@@ -61,6 +78,9 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case 'r': /* For SysV compatibility. */
sum_func = bsd_sum_file;
break;
@@ -69,13 +89,20 @@ main (argc, argv)
sum_func = sysv_sum_file;
break;
case '?':
fprintf (stderr, "\
Usage: %s [-rs] [--sysv] [file...]\n", argv[0]);
exit (1);
default:
usage ();
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
files_given = argc - optind;
if (files_given == 0)
{

View File

@@ -41,6 +41,7 @@ tac -r -s '.\|
#include <signal.h>
#include <regex.h>
#include "system.h"
#include "version.h"
#ifndef STDC_HEADERS
char *malloc ();
@@ -101,14 +102,32 @@ static unsigned buffer_size;
/* The compiled regular expression representing `separator'. */
static struct re_pattern_buffer compiled_separator;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const longopts[] =
{
{"before", no_argument, &separator_ends_record, 0},
{"regex", no_argument, &sentinel_length, 0},
{"separator", required_argument, NULL, 's'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-br] [-s separator] [--before] [--regex] [--separator=separator]\n\
[--help] [--version] [file...]\n",
program_name);
exit (1);
}
void
main (argc, argv)
int argc;
@@ -143,14 +162,19 @@ main (argc, argv)
error (1, 0, "separator cannot be empty");
break;
default:
fprintf (stderr, "\
Usage: %s [-br] [-s separator] [--before] [--regex] [--separator=separator]\n\
[file...]\n",
program_name);
exit (1);
usage ();
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (sentinel_length == 0)
{
compiled_separator.allocated = 100;

View File

@@ -50,6 +50,7 @@
#include <sys/types.h>
#include <signal.h>
#include "system.h"
#include "version.h"
/* Number of items to tail. */
#define DEFAULT_NUMBER 10
@@ -111,6 +112,12 @@ char *program_name;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const long_options[] =
{
{"bytes", required_argument, NULL, 'c'},
@@ -119,6 +126,8 @@ static struct option const long_options[] =
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -208,6 +217,9 @@ main (argc, argv)
{
switch (c)
{
case 0:
break;
case 'c':
unit_size = 1;
parse_unit (optarg);
@@ -244,6 +256,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (number == -1)
number = DEFAULT_NUMBER;
@@ -987,7 +1008,8 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-c [+]N[bkm]] [-n [+]N] [-fqv] [--bytes=[+]N[bkm]] [--lines=[+]N]\n\
[--follow] [--quiet] [--silent] [--verbose] [file...]\n\
[--follow] [--quiet] [--silent] [--verbose] [--help] [--version]\n\
[file...]\n\
%s [{-,+}Nbcfklmqv] [file...]\n", program_name, program_name);
exit (1);
}

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

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

View File

@@ -32,15 +32,25 @@
Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie,
and Randy Smith. */
#ifdef HAVE_CONFIG_H
#if 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 it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
#ifdef STDC_HEADERS
#include <time.h>
#else
#ifndef STDC_HEADERS
time_t mktime ();
time_t time ();
#endif
@@ -61,6 +71,9 @@ static int utime_now ();
#define CH_ATIME 1
#define CH_MTIME 2
/* The name by which this program was run. */
char *program_name;
/* Which timestamps to change. */
static int change_times;
@@ -90,8 +103,11 @@ static char *ref_file;
/* Info about the reference file. */
static struct stat ref_stats;
/* 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 longopts[] =
{
@@ -99,6 +115,8 @@ static struct option const longopts[] =
{"no-create", no_argument, 0, 'c'},
{"date", required_argument, 0, 'd'},
{"file", required_argument, 0, 'r'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -132,6 +150,9 @@ main (argc, argv)
{
switch (c)
{
case 0:
break;
case 'a':
change_times |= CH_ATIME;
break;
@@ -183,6 +204,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (change_times == 0)
change_times = CH_ATIME | CH_MTIME;
@@ -351,7 +381,7 @@ usage ()
fprintf (stderr, "\
Usage: %s [-acfm] [-r reference-file] [-t MMDDhhmm[[CC]YY][.ss]]\n\
[-d time] [--time={atime,access,use,mtime,modify}] [--date=time]\n\
[--file=reference-file] [--no-create] file...\n",
[--file=reference-file] [--no-create] [--help] [--version] file...\n",
program_name);
exit (1);
}

186
src/tr.c
View File

@@ -26,6 +26,7 @@
#include <sys/types.h>
#include "getopt.h"
#include "system.h"
#include "version.h"
#ifndef LONG_MAX
#define LONG_MAX 0x7FFFFFFF
@@ -68,12 +69,12 @@ typedef int (*PFI) ();
/* The following (but not CC_NO_CLASS) are indices into the array of
valid character class strings. */
enum Char_class
{
CC_ALNUM = 0, CC_ALPHA = 1, CC_BLANK = 2, CC_CNTRL = 3,
CC_DIGIT = 4, CC_GRAPH = 5, CC_LOWER = 6, CC_PRINT = 7,
CC_PUNCT = 8, CC_SPACE = 9, CC_UPPER = 10, CC_XDIGIT = 11,
CC_NO_CLASS = 9999
};
{
CC_ALNUM = 0, CC_ALPHA = 1, CC_BLANK = 2, CC_CNTRL = 3,
CC_DIGIT = 4, CC_GRAPH = 5, CC_LOWER = 6, CC_PRINT = 7,
CC_PUNCT = 8, CC_SPACE = 9, CC_UPPER = 10, CC_XDIGIT = 11,
CC_NO_CLASS = 9999
};
/* Character class to which a character (returned by get_next) belonged;
but it is set only if the construct from which the character was obtained
@@ -82,18 +83,18 @@ enum Char_class
and lower class constructs have the same relative positions in string1
and string2. */
enum Upper_Lower_class
{
UL_LOWER = 0,
UL_UPPER = 1,
UL_NONE = 2
};
{
UL_LOWER = 0,
UL_UPPER = 1,
UL_NONE = 2
};
/* A shortcut to ensure that when constructing the translation array,
one of the values returned by paired calls to get_next (from s1 and s2) is
from [:upper:] and the other is from [:lower:], or neither is
from upper or lower. In fact, no other character classes are allowed
when translating, but that condition is tested elsewhere. This array
is indexed by values of type enum Upper_Lower_class. */
one of the values returned by paired calls to get_next (from s1 and s2)
is from [:upper:] and the other is from [:lower:], or neither is from
upper or lower. In fact, no other character classes are allowed when
translating, but that condition is tested elsewhere. This array is
indexed by values of type enum Upper_Lower_class. */
static int const class_ok[3][3] =
{
{0, 1, 0},
@@ -103,42 +104,44 @@ static int const class_ok[3][3] =
/* The type of a List_element. See build_spec_list for more details. */
enum Range_element_type
{
RE_NO_TYPE = 0,
RE_NORMAL_CHAR,
RE_RANGE,
RE_CHAR_CLASS,
RE_EQUIV_CLASS,
RE_REPEATED_CHAR
};
{
RE_NO_TYPE = 0,
RE_NORMAL_CHAR,
RE_RANGE,
RE_CHAR_CLASS,
RE_EQUIV_CLASS,
RE_REPEATED_CHAR
};
/* One construct in one of tr's argument strings.
For example, consider the POSIX version of the
classic tr command:
For example, consider the POSIX version of the classic tr command:
tr -cs 'a-zA-Z_' '[\n*]'
String1 has 3 constructs, two of which are ranges (a-z and A-Z),
and a single normal character, `_'. String2 has one construct. */
struct List_element
{
enum Range_element_type type;
struct List_element *next;
union
{
int normal_char;
struct /* unnamed */
{
unsigned int first_char;
unsigned int last_char;
} range;
enum Char_class char_class;
int equiv_code;
struct /* unnamed */
{
unsigned int the_repeated_char;
long repeat_count;
} repeated_char;
} u;
};
enum Range_element_type type;
struct List_element *next;
union
{
int normal_char;
struct /* unnamed */
{
unsigned int first_char;
unsigned int last_char;
}
range;
enum Char_class char_class;
int equiv_code;
struct /* unnamed */
{
unsigned int the_repeated_char;
long repeat_count;
}
repeated_char;
}
u;
};
/* Each of tr's argument strings is parsed into a form that is easier
to work with: a linked list of constructs (struct List_element).
@@ -150,39 +153,39 @@ struct List_element
it is used by get_next to save its state when traversing the list.
The member `state' serves a similar function. */
struct Spec_list
{
/* Points to the head of the list of range elements.
The first struct is a dummy; its members are never used. */
struct List_element *head;
{
/* Points to the head of the list of range elements.
The first struct is a dummy; its members are never used. */
struct List_element *head;
/* When appending, points to the last element. When traversing via
get_next(), points to the element to process next. Setting
Spec_list.state to the value BEGIN_STATE before calling get_next
signals get_next to initialize tail to point to head->next. */
struct List_element *tail;
/* When appending, points to the last element. When traversing via
get_next(), points to the element to process next. Setting
Spec_list.state to the value BEGIN_STATE before calling get_next
signals get_next to initialize tail to point to head->next. */
struct List_element *tail;
/* Used to save state between calls to get_next(). */
unsigned int state;
/* Used to save state between calls to get_next(). */
unsigned int state;
/* Length, in the sense that length('a-z[:digit:]123abc')
is 42 ( = 26 + 10 + 6). */
int length;
/* Length, in the sense that length('a-z[:digit:]123abc')
is 42 ( = 26 + 10 + 6). */
int length;
/* The number of [c*] and [c*0] constructs that appear in this spec. */
int n_indefinite_repeats;
/* The number of [c*] and [c*0] constructs that appear in this spec. */
int n_indefinite_repeats;
/* Non-zero if this spec contains at least one equivalence
class construct e.g. [=c=]. */
int has_equiv_class;
/* Non-zero if this spec contains at least one equivalence
class construct e.g. [=c=]. */
int has_equiv_class;
/* Non-zero if this spec contains at least one of [:upper:] or
[:lower:] class constructs. */
int has_upper_or_lower;
/* Non-zero if this spec contains at least one of [:upper:] or
[:lower:] class constructs. */
int has_upper_or_lower;
/* Non-zero if this spec contains at least one of the character class
constructs (all but upper and lower) that aren't allowed in s2. */
int has_restricted_char_class;
};
/* Non-zero if this spec contains at least one of the character class
constructs (all but upper and lower) that aren't allowed in s2. */
int has_restricted_char_class;
};
char *xmalloc ();
char *stpcpy ();
@@ -258,7 +261,7 @@ static int translating;
#define IO_BUF_SIZE BUFSIZ
static unsigned char io_buf[IO_BUF_SIZE];
static char const* const char_class_name[] =
static char const *const char_class_name[] =
{
"alnum", "alpha", "blank", "cntrl", "digit", "graph",
"lower", "print", "punct", "space", "upper", "xdigit"
@@ -284,22 +287,29 @@ static SET_TYPE in_delete_set[N_CHARS];
two specification strings and the delete switch is not given. */
static char xlate[N_CHARS];
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const long_options[] =
{
{"complement", no_argument, NULL, 'c'},
{"delete", no_argument, NULL, 'd'},
{"squeeze-repeats", no_argument, NULL, 's'},
{"truncate-set1", no_argument, NULL, 't'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-cdst] [--complement] [--delete] [--squeeze-repeats]\n\
[--truncate-set1] string1 [string2]\n",
[--truncate-set1] [--help] [--version] string1 [string2]\n",
program_name);
exit (2);
}
@@ -361,7 +371,7 @@ is_char_class_member (char_class, c)
case CC_XDIGIT:
return ISXDIGIT (c);
break;
case CC_NO_CLASS:
default:
abort ();
break;
}
@@ -618,7 +628,7 @@ append_range (list, first, last)
char *tmp2 = make_printable_char (last);
error (0, 0,
"range-endpoints of `%s-%s' are in reverse collating sequence order",
"range-endpoints of `%s-%s' are in reverse collating sequence order",
tmp1, tmp2);
free (tmp1);
free (tmp2);
@@ -976,7 +986,6 @@ build_spec_list (unescaped_string, len, result)
return 0;
}
/* Given a Spec_list S (with its saved state implicit in the values
of its members `tail' and `state'), return the next single character
in the expansion of S's constructs. If the last character of S was
@@ -1381,7 +1390,7 @@ validate (s1, s2)
if (s2->length == 0)
error (1, 0,
"when not truncating set1, string2 must be non-empty");
"when not truncating set1, string2 must be non-empty");
string2_extend (s1, s2);
}
}
@@ -1656,7 +1665,16 @@ main (argc, argv)
}
}
posix_pedantic = (getenv ("POSIXLY_CORRECT") != 0);
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
posix_pedantic = (getenv ("POSIXLY_CORRECT") != NULL);
non_option_args = argc - optind;
translating = (non_option_args == 2 && !delete);
@@ -1744,15 +1762,15 @@ deleting and squeezing repeats");
{
if (!in_s1[i])
{
int c = get_next (s2, NULL);
assert (c != -1 || truncate_set1);
if (c == -1)
int ch = get_next (s2, NULL);
assert (ch != -1 || truncate_set1);
if (ch == -1)
{
/* This will happen when tr is invoked like e.g.
tr -cs A-Za-z0-9 '\012'. */
break;
}
xlate[i] = c;
xlate[i] = ch;
}
}
assert (get_next (s2, NULL) == -1 || truncate_set1);
@@ -1774,7 +1792,7 @@ deleting and squeezing repeats");
c2 = get_next (s2, &class_s2);
if (!class_ok[(int) class_s1][(int) class_s2])
error (1, 0,
"misaligned or mismatched upper and/or lower classes");
"misaligned or mismatched upper and/or lower classes");
/* The following should have been checked by validate... */
if (c2 == -1)
break;

View File

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

View File

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

View File

@@ -42,6 +42,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
/* The number of bytes added at a time to the amount of memory
allocated for the output line. */
@@ -62,6 +63,9 @@ static void unexpand ();
static void usage ();
static void validate_tabstops ();
/* The name this program was run with. */
char *program_name;
/* If nonzero, convert blanks even after nonblank characters have been
read on the line. */
static int convert_entire_line;
@@ -93,13 +97,18 @@ static int have_read_stdin;
/* Status to return to the system. */
static int exit_status;
/* 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 then exit. */
static int show_version;
static struct option const longopts[] =
{
{"tabs", required_argument, NULL, 't'},
{"all", no_argument, NULL, 'a'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -123,6 +132,9 @@ main (argc, argv)
{
switch (c)
{
case 0:
break;
case '?':
usage ();
case 'a':
@@ -144,6 +156,15 @@ main (argc, argv)
}
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
add_tabstop (tabval);
validate_tabstops (tab_list, first_free_tab);
@@ -418,7 +439,7 @@ usage ()
{
fprintf (stderr, "\
Usage: %s [-tab1[,tab2[,...]]] [-t tab1[,tab2[,...]]] [-a]\n\
[--tabs=tab1[,tab2[,...]]] [--all] [file...]\n",
[--tabs=tab1[,tab2[,...]]] [--all] [--help] [--version] [file...]\n",
program_name);
exit (1);
}

View File

@@ -25,6 +25,7 @@
#include <sys/types.h>
#include "system.h"
#include "linebuffer.h"
#include "version.h"
#define min(x, y) ((x) < (y) ? (x) : (y))
@@ -36,6 +37,9 @@ static void check_file ();
static void usage ();
static void writeline ();
/* The name this program was run with. */
char *program_name;
/* Number of fields to skip on each line when doing comparisons. */
static int skip_fields;
@@ -65,8 +69,11 @@ enum output_mode
/* Which lines to output. */
static enum output_mode mode;
/* 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 then exit. */
static int show_version;
static struct option const longopts[] =
{
@@ -76,6 +83,8 @@ static struct option const longopts[] =
{"skip-fields", required_argument, NULL, 'f'},
{"skip-chars", required_argument, NULL, 's'},
{"check-chars", required_argument, NULL, 'w'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -99,6 +108,9 @@ main (argc, argv)
{
switch (optc)
{
case 0:
break;
case '0':
case '1':
case '2':
@@ -141,8 +153,22 @@ main (argc, argv)
}
}
while (optind < argc && argv[optind][0] == '+')
skip_chars = atoi (argv[optind++]);
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (optind >= 2 && strcmp (argv[optind - 1], "--") != 0)
{
/* Interpret non-option arguments with leading `+' only
if we haven't seen `--'. */
while (optind < argc && argv[optind][0] == '+')
skip_chars = atoi (argv[optind++]);
}
if (optind < argc)
infile = argv[optind++];
@@ -314,7 +340,7 @@ usage ()
Usage: %s [-cdu] [-f skip-fields] [-s skip-chars] [-w check-chars]\n\
[-#skip-fields] [+#skip-chars] [--count] [--repeated] [--unique]\n\
[--skip-fields=skip-fields] [--skip-chars=skip-chars]\n\
[--check-chars=check-chars] [infile] [outfile]\n",
[--check-chars=check-chars] [--help] [--version] [infile] [outfile]\n",
program_name);
exit (1);
}

View File

@@ -22,6 +22,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "version.h"
/* Size of atomic reads. */
#define BUFFER_SIZE (16 * 1024)
@@ -32,6 +33,9 @@ static void wc ();
static void wc_file ();
static void write_counts ();
/* The name this program was run with. */
char *program_name;
/* Cumulative number of lines, words, and chars in all files so far. */
static unsigned long total_lines, total_words, total_chars;
@@ -41,21 +45,36 @@ static int print_lines, print_words, print_chars;
/* Nonzero if we have ever read the standard input. */
static int have_read_stdin;
/* The name this program was run with. */
char *program_name;
/* The error code to return to the system. */
static int exit_status;
/* If non-zero, display usage information and exit. */
static int show_help;
/* If non-zero, print the version on standard output then exits. */
static int show_version;
static struct option const longopts[] =
{
{"bytes", no_argument, NULL, 'c'},
{"chars", no_argument, NULL, 'c'},
{"lines", no_argument, NULL, 'l'},
{"words", no_argument, NULL, 'w'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
static void
usage ()
{
fprintf (stderr, "\
Usage: %s [-clw] [--bytes] [--chars] [--lines] [--words]\n\
[--help] [--version] [file...]\n",
program_name);
exit (1);
}
void
main (argc, argv)
int argc;
@@ -72,6 +91,9 @@ main (argc, argv)
while ((optc = getopt_long (argc, argv, "clw", longopts, (int *) 0)) != EOF)
switch (optc)
{
case 0:
break;
case 'c':
print_chars = 1;
break;
@@ -85,11 +107,18 @@ main (argc, argv)
break;
default:
fprintf (stderr, "\
Usage: %s [-clw] [--bytes] [--chars] [--lines] [--words] [file...]\n", argv[0]);
exit (1);
usage ();
}
if (show_version)
{
printf ("%s\n", version_string);
exit (0);
}
if (show_help)
usage ();
if (print_lines + print_words + print_chars == 0)
print_lines = print_words = print_chars = 1;
@@ -208,23 +237,23 @@ wc (fd, file)
}
static void
write_counts (lc, wc, cc, file)
unsigned long lc, wc, cc;
write_counts (lines, words, chars, file)
unsigned long lines, words, chars;
char *file;
{
if (print_lines)
printf ("%7lu", lc);
printf ("%7lu", lines);
if (print_words)
{
if (print_lines)
putchar (' ');
printf ("%7lu", wc);
printf ("%7lu", words);
}
if (print_chars)
{
if (print_lines || print_words)
putchar (' ');
printf ("%7lu", cc);
printf ("%7lu", chars);
}
if (*file)
printf (" %s", file);

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

19
tests/tr/Makefile Normal file
View File

@@ -0,0 +1,19 @@
.PHONY: all
all: tr-tests
./tr-tests
tr-tests: main build-script test.data.pl
./main test.data.pl > $@.n
mv $@.n $@
chmod 755 $@
.PHONY: distclean
distclean:
rm -f t[0-9]*.out
.PHONY: clean
clean: distclean
.PHONY: realclean
realclean: clean
rm -f tr-tests t[0-9]*.in t[0-9]*.expected

1
tests/tr/TODO Normal file
View File

@@ -0,0 +1 @@
Integrate tests from the files `range-tests' and `failures'.

55
tests/tr/build-script Executable file
View File

@@ -0,0 +1,55 @@
#!/p/bin/perl
$tr = '../tr +io 5';
$tr = 'tr';
$test = 0;
$failures = 0;
$| = 1;
print ":\nerrors=0\n";
while (<>)
{
next if (/^\s*#/);
$test++;
chop;
$prog = '($input,$flags,$s1,$s2,$expected,$e_ret_code) = ' . $_ . ';';
eval $prog;
$in = "t$test.in";
$exp_name = 't' . $test . '.expected';
$out = "t$test.out";
open(IN, ">$in") || die "Couldn't open $in for writing.\n";
print IN $input;
close(IN);
open(EXP, ">$exp_name")
|| die "Couldn't open $exp_name for writing.\n";
print EXP $expected;
close(EXP);
$arg2 = ($s2 ? "'$s2'" : '');
$cmd = "$tr $flags \'$s1\' $arg2 < $in > $out";
print <<EOF ;
$cmd 2> /dev/null
code=\$?
if test \$code != $e_ret_code ; then
echo Test $test failed: tr return code \$code differs from expected value $e_ret_code 1>&2
errors=`expr \$errors + 1`
else
cmp $out $exp_name
case \$? in
0) if test "\$verbose" ; then echo passed $test; fi ;; # equal files
1) echo Test $test failed: files $out and $exp_name differ 1>&2;
errors=`expr \$errors + 1` ;;
2) echo Test $test may have failed. 1>&2;
echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
errors=`expr \$errors + 1` ;;
esac
fi
EOF
}
print <<EOF2 ;
if test \$errors -gt 0 ; then
echo Failed \$errors tests. 1>&2
fi
EOF2

18
tests/tr/failures Normal file
View File

@@ -0,0 +1,18 @@
# ./tr a '[c*]b'
# ./tr -s abc zy
# ./tr abc zy
tr a '[:not-a-class:]' < /dev/null
tr a '[:digit:]' < /dev/null
tr '[c*]' k < /dev/null
tr a '[=c=]' < /dev/null
tr a '[c*][c*]' < /dev/null
tr -ds abd '[c*]' < /dev/null
tr -c '[:lower:]' '[:upper:]' < /dev/null
tr '[:lower:]' '[:lower:]' < /dev/null
tr '0-9[:lower:]' '[:upper:]' < /dev/null
tr a '' < /dev/null
tr -s '\432' < /dev/null
tr a 'abc\' < /dev/null
tr a '\x' < /dev/null
# And make sure tr does the right thing when POSIXLY_... is set.

3
tests/tr/main Executable file
View File

@@ -0,0 +1,3 @@
:
perl -pe 's/\\\n$//' "$@" \
| ./build-script

18
tests/tr/range-tests Normal file
View File

@@ -0,0 +1,18 @@
[]*] # What about this?! valid
[:*096] # invalid: 096 isn't a valid octal number
a [:*0] # as many colons as string1 was long (not to be confused
# with a character class)
[:*] # ditto
[:*016] # 14 colons
[=]=] # valid: equivalence class containing ']'
[-a # valid, assuming `[' is before 'a' in collating sequence
-] # valid, assuming ` ' is before ']' in collating sequence
--] # valid, assuming `-' is before ']' in collating sequence
\0-\377 # valid
[\0-\377]# valid, (but brackets will be mapped to corresponding chars
# in other string)
abcde[:* # valid, but none of the characters is considered special
abc xyzdef # Should this (str2 longer than str1) evoke a warning?
# Probably so if we're only translating, but if also deleting or
# squeezing this makes sense.
abcdef : # Map abcdef all to `:', as if str2 had been [:*]

61
tests/tr/test.data.pl Executable file
View File

@@ -0,0 +1,61 @@
# input flags 1 or 2 strings expected output expected return code
#
("abcd", '', 'abcd','[]*]', "]]]]", 0);
("abc", '', 'abc','[%*]xyz', "xyz", 0);
("abc", '', '','[.*]', "abc", 0);
# Test --truncate-set1 behavior when string1 is longer than string2
("abcde", '-t', 'abcd','xy', "xycde", 0);
# Test bsd behavior (the default) when string1 is longer than string2
("abcde", '', 'abcd','xy', "xyyye", 0);
# Do it the posix way
("abcde", '', 'abcd','x[y*]', "xyyye", 0);
#
("abcdefghijklmnop", '-s', 'a-p','%[.*]$', "%.$", 0);
("abcdefghijklmnop", '-s', 'a-p','[.*]$', ".$", 0);
("abcdefghijklmnop", '-s', 'a-p','%[.*]', "%.", 0);
("aabbcc", '-s', '[a-z]','', "abc", 0);
("aabbcc", '-s', '[a-c]','', "abc", 0);
("aabbcc", '-s', '[a-b]','', "abcc", 0);
("aabbcc", '-s', '[b-c]','', "aabc", 0);
("\0\0a\1\1b\2\2\2c\3\3\3d\4\4\4\4e\5\5", \
'-s', '[\0-\5]','', "\0a\1b\2c\3d\4e\5", 0);
# tests of delete
("[[[[[[[]]]]]]]]", '-d', '[=[=]','', "]]]]]]]]", 0);
("[[[[[[[]]]]]]]]", '-d', '[=]=]','', "[[[[[[[", 0);
("0123456789acbdefABCDEF", '-d', '[:xdigit:]','', "", 0);
("w0x1y2z3456789acbdefABCDEFz", '-d', '[:xdigit:]','', "wxyzz", 0);
("0123456789", '-d', '[:digit:]','', "", 0);
("a0b1c2d3e4f5g6h7i8j9k", '-d', '[:digit:]','', "abcdefghijk", 0);
("abcdefghijklmnopqrstuvwxyz", '-d', '[:lower:]','', "", 0);
("ABCDEFGHIJKLMNOPQRSTUVWXYZ", '-d', '[:upper:]','', "", 0);
("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", \
'-d', '[:lower:][:upper:]','', "", 0);
("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", \
'-d', '[:alpha:]','', "", 0);
("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", \
'-d', '[:alnum:]','', "", 0);
(".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.", \
'-d', '[:alnum:]','', "..", 0);
(".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.", \
'-ds', '[:alnum:]','.', ".", 0);
# The classic example, with string2 BSD-style
("The big black fox jumped over the fence.", \
'-cs', '[:alnum:]','\n', \
"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n", 0);
# The classic example, POSIX-style
("The big black fox jumped over the fence.", \
'-cs', '[:alnum:]','[\n*]', \
"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n", 0);
("aabbaa", '-ds', 'b','a', "a", 0);
("ZZ0123456789acbdefABCDEFZZ", \
'-ds', '[:xdigit:]','Z', "Z", 0);
# Try some data with 8th bit set in case something is mistakenly sign-extended.
("\300\301\377\345\345\350\345", \
'-ds', '\350','\345', "\300\301\377\345", 0);
("abcdefghijklmnop", '-s', 'abcdefghijklmn','[:*016]', ":op", 0);
("abc \$code", '-d', 'a-z','', " \$", 0);
("a.b.c \$\$\$\$code\\", '-ds', 'a-z','$.', ". \$\\", 0);
# Make sure that a-a is accepted, even though POSIX 1001.2 says it is illegal.
("abc", '', 'a-a','z', "zbc", 0);
#
("", '', 'a',"''", "", 1);