summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-10-23 15:37:19 +0000
committerJim Meyering <jim@meyering.net>1993-10-23 15:37:19 +0000
commitb869639f4661488eba0bb2d08020c6e71bb72627 (patch)
treee325845ec7ca06b4d59fcc07e87020897c7c4d9b
parentd1df8c198d8878b77d1d1583bc7b3c491534616a (diff)
downloadcoreutils-b869639f4661488eba0bb2d08020c6e71bb72627.tar.xz
merge with 1.8d+
-rw-r--r--old/textutils/ChangeLog28
-rw-r--r--src/cat.c42
-rw-r--r--src/cksum.c26
-rw-r--r--src/comm.c31
-rw-r--r--src/csplit.c48
-rw-r--r--src/cut.c55
-rw-r--r--src/expand.c34
-rw-r--r--src/fold.c29
-rw-r--r--src/head.c40
-rw-r--r--src/join.c47
-rw-r--r--src/nl.c74
-rw-r--r--src/od.c86
-rw-r--r--src/paste.c32
-rw-r--r--src/pr.c58
-rw-r--r--src/sort.c51
-rw-r--r--src/split.c88
-rw-r--r--src/sum.c30
-rw-r--r--src/tac.c33
-rw-r--r--src/tail.c43
-rw-r--r--src/tr.c260
-rw-r--r--src/unexpand.c34
-rw-r--r--src/uniq.c44
-rw-r--r--src/wc.c34
23 files changed, 919 insertions, 328 deletions
diff --git a/old/textutils/ChangeLog b/old/textutils/ChangeLog
index 52071e648..9a4c80006 100644
--- a/old/textutils/ChangeLog
+++ b/old/textutils/ChangeLog
@@ -1,3 +1,31 @@
+Sat Oct 23 01:00:12 1993 Jim Meyering (meyering@comco.com)
+
+ * cat.c, cksum.c, comm.c, csplit.c, cut.c, expand.c, fold.c, head.c,
+ join.c, nl.c, od.c, paste.c, pr.c, split.c, sum.c, tac.c, tail.c,
+ tr.c, unexpand.c, uniq.c, wc.c (usage): Add long --help.
+ Exit successfully for --help, non-zero for usage error.
+ From Francois Pinard.
+
+ * configure.in: Add AC_STAT_MACROS_BROKEN.
+ * system.h [AC_STAT_MACROS_BROKEN]: Test it.
+
+Fri Oct 22 23:26:17 1993 Jim Meyering (meyering@comco.com)
+
+ * linebuffer.c, memchr.c [HAVE_CONFIG_H, CONFIG_BROKETS]: Include
+ <config.h> or "config.h".
+ * cat.c, cksum.c, comm.c, csplit.c, cut.c, expand.c, fold.c, head.c,
+ join.c, nl.c, od.c, paste.c, pr.c, sort.c, split.c, sum.c, tac.c,
+ tail.c, tr.c, unexpand.c, uniq.c, version.c, wc.c: Ditto.
+
+ * configure.in: Use AC_CONIG_HEADER.
+ * Makefile.in [DIST]: Add config.h.in.
+
+ * Makefile.in: Convert so make may be run from subdirectories.
+ Add dependencies on config.h.
+ * src/Makefile.in: Ditto.
+ * lib/Makefile.in: Ditto.
+ * man/Makefile.in: Ditto.
+
Wed Oct 20 20:05:48 1993 Jim Meyering (meyering@comco.com)
* memchr.c (memchr): Do the 32-bit assignment only if !LONG_64_BITS.
diff --git a/src/cat.c b/src/cat.c
index 8cbc61f7d..702d5c984 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -85,15 +85,37 @@ static int newlines2 = 0;
static int exit_stat = 0;
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-benstuvAET] [--number] [--number-nonblank] [--squeeze-blank]\n\
- [--show-nonprinting] [--show-ends] [--show-tabs] [--show-all]\n\
- [--help] [--version] [file...]\n",
- program_name);
-
- exit (2);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION] [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -b, --number-nonblank number nonblank output lines\n\
+ -e equivalent to -vE\n\
+ -n, --number number all output lines\n\
+ -s, --squeeze-blank never more than one single blank line\n\
+ -t equivalent to -vT\n\
+ -u (ignored)\n\
+ -v, --show-nonprinting use ^ and M- notation, save for LFD and TAB\n\
+ -A, --show-all equivalent to -vET\n\
+ -E, --show-ends display $ at end of each line\n\
+ -T, --show-tabs display TAB characters as ^I\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
@@ -231,7 +253,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (2);
}
}
@@ -242,7 +264,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
output_desc = 1;
diff --git a/src/cksum.c b/src/cksum.c
index f6f7d26a3..135864151 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -271,11 +271,25 @@ cksum (file, print_name)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [--help] [--version] [file...]\n", program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+");
+ }
+ exit (status);
}
void
@@ -297,7 +311,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -308,7 +322,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (optind >= argc)
{
diff --git a/src/comm.c b/src/comm.c
index 1900661cd..2fc538526 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -99,7 +99,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
if (show_version)
@@ -109,10 +109,10 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (optind + 2 != argc)
- usage ();
+ usage (1);
exit (compare_files (argv + optind));
}
@@ -251,9 +251,26 @@ writeline (line, stream, class)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "Usage: %s [-123] [--help] [--version] file1 file2\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... LEFT_FILE RIGHT_FILE\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -1 suppress lines unique to left file\n\
+ -2 suppress lines unique to right file\n\
+ -3 suppress lines unique to both files\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+");
+ }
+ exit (status);
}
diff --git a/src/csplit.c b/src/csplit.c
index 4fb9f2ca5..592e2b8d6 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -1517,7 +1517,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
if (show_version)
@@ -1527,10 +1527,10 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (optind >= argc - 1)
- usage ();
+ usage (1);
if (suffix)
filename_space = (char *) xmalloc (strlen (prefix) + max_out (suffix) + 2);
@@ -1553,13 +1553,39 @@ main (argc, argv)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-sqkz] [-f prefix] [-b suffix] [-n digits] [--prefix=prefix]\n\
- [--suffix=suffix] [--digits=digits] [--quiet] [--silent]\n\
- [--keep-files] [--abandon-null-files] [--help] [--version]\n\
- file pattern...\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... FILE PATTERN...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -b, --suffix=FORMAT use sprintf FORMAT instead of %%d\n\
+ -f, --prefix=PREFIX use PREFIX instead of xx\n\
+ -k, --keep-files do not remove output files on errors\n\
+ -n, --digits=DIGITS use specified number of digits instead of 2\n\
+ -s, --quiet, --silent do not print counts of output file sizes\n\
+ -z, --abandon-null-files remove empty output files\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+Read standard input if FILE is -. Each PATTERN may be:\n\
+\n\
+ INTEGER copy up to but not including specified line number\n\
+ /REGEXP/[OFFSET] copy up to but not including a matching line\n\
+ %%REGEXP%%[OFFSET] skip to, but not including a matching line\n\
+ {INTEGER} repeat the previous pattern specified number of times\n\
+ {*} repeat the previous pattern as many times as possible\n\
+\n\
+A line OFFSET is a `+' or `-' (required) followed by a positive integer.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/cut.c b/src/cut.c
index 4953afc04..c53402f63 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -199,7 +199,7 @@ main (argc, argv)
case 'c':
/* Build the byte list. */
if (operating_mode != undefined_mode)
- usage ();
+ usage (2);
operating_mode = byte_mode;
if (set_fields (optarg) == 0)
error (2, 0, "no fields given");
@@ -208,7 +208,7 @@ main (argc, argv)
case 'f':
/* Build the field list. */
if (operating_mode != undefined_mode)
- usage ();
+ usage (2);
operating_mode = field_mode;
if (set_fields (optarg) == 0)
error (2, 0, "no fields given");
@@ -231,7 +231,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (2);
}
}
@@ -242,13 +242,13 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (operating_mode == undefined_mode)
- usage ();
+ usage (2);
if ((delimited_lines_only || delim != '\0') && operating_mode != field_mode)
- usage ();
+ usage (2);
if (delim == '\0')
delim = '\t';
@@ -596,14 +596,39 @@ invalid_list ()
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-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);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -b, --bytes LIST output only these bytes\n\
+ -c, --characters LIST output only these characters\n\
+ -d, --delimiter DELIM use DELIM instead of TAB for field delimiter\n\
+ -f, --fields LIST output only these fields\n\
+ -n (ignored)\n\
+ -s, --only-delimited do not print lines not containing delimiters\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+Use one, and only one of -b, -c or -f. Each LIST is made up of one\n\
+range, or many ranges separated by commas. Each range is one of:\n\
+\n\
+ N N'th byte, character or field, counted from 1\n\
+ N- from N'th byte, character or field, to end of line\n\
+ N-M from N'th to M'th (included) byte, character or field\n\
+ -M from first to M'th (included) byte, character or field\n\
+\n\
+With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/expand.c b/src/expand.c
index 92e8c61b7..e46e4150b 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -145,7 +145,7 @@ main (argc, argv)
break;
case '?':
- usage ();
+ usage (1);
case 'i':
convert_entire_line = 0;
break;
@@ -171,7 +171,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
add_tabstop (tabval);
@@ -391,11 +391,29 @@ next_file (fp)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-tab1[,tab2[,...]]] [-t tab1[,tab2[,...]]] [-i]\n\
- [--tabs=tab1[,tab2[,...]]] [--initial] [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -i, --initial do not convert TABs after non whitespace\n\
+ -t, --tabs NUMBER have tabs NUMBER characters apart, not 8\n\
+ -t, --tabs LIST use comma separated list of explicit tab positions\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+Instead of -t NUMBER or -t LIST, -NUMBER or -LIST may be used. With\n\
+no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/fold.c b/src/fold.c
index 39097c724..ff151739d 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -73,13 +73,26 @@ static struct option const longopts[] =
};
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-bs] [-w width] [--bytes] [--spaces] [--width=width]\n\
- [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -b, --bytes count bytes rather than columns\n\
+ -s, --spaces break at word boundaries\n\
+ -w, --width WIDTH use WIDTH columns instead of 80\n\
+");
+ }
+ exit (status);
}
void
@@ -133,7 +146,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -144,7 +157,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (argc == optind)
errs |= fold_file ("-", width);
diff --git a/src/head.c b/src/head.c
index 82ad29141..2ab70af05 100644
--- a/src/head.c
+++ b/src/head.c
@@ -161,7 +161,7 @@ main (argc, argv)
default:
error (0, 0, "unrecognized option `-%c'", *argv[1]);
- usage ();
+ usage (1);
}
++argv[1];
}
@@ -200,7 +200,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -211,7 +211,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (number == -1)
number = DEFAULT_NUMBER;
@@ -396,12 +396,32 @@ atou (str)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-c N[bkm]] [-n N] [-qv] [--bytes=N[bkm]] [--lines=N]\n\
- [--quiet] [--silent] [--verbose] [--help] [--version] [file...]\n\
- %s [-Nbcklmqv] [--help] [--version] [file...]\n",
- program_name, program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -c, --bytes SIZE print first SIZE bytes\n\
+ -l, -n, --lines NUMBER print first NUMBER lines instead of first 10\n\
+ -q, --quiet, --silent never print headers giving file names\n\
+ -v, --verbose always print headers giving file names\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.\n\
+If -VALUE is used as first OPTION, read -c VALUE when one of\n\
+multipliers bkm follows concatenated, else read -n VALUE. With no\n\
+FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/join.c b/src/join.c
index 0113f86c4..c8c649332 100644
--- a/src/join.c
+++ b/src/join.c
@@ -661,12 +661,12 @@ main (argc, argv)
}
if (nfiles > 1)
- usage ();
+ usage (1);
names[nfiles++] = optarg;
break;
case '?':
- usage ();
+ usage (1);
}
prev_optc = optc;
}
@@ -678,10 +678,10 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (nfiles != 2)
- usage ();
+ usage (1);
fp1 = strcmp (names[0], "-") ? fopen (names[0], "r") : stdin;
if (!fp1)
@@ -702,11 +702,38 @@ main (argc, argv)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-a 1|2] [-v 1|2] [-e empty-string] [-o field-list...] [-t char]\n\
- [-j[1|2] field] [-1 field] [-2 field] file1 file2\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... FILE1 FILE2\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -a SIDE print unpairable lines coming from file SIDE\n\
+ -e EMPTY replace missing input fields with EMPTY\n\
+ -j FIELD join on this FIELD for both files\n\
+ -[j]SIDE FIELD join on this FIELD for file SIDE\n\
+ -o FORMAT obey FORMAT while constructing output line\n\
+ -t CHAR use CHAR as input and output field separator\n\
+ -v SIDE like -a SIDE, but suppress joined output lines\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+When FILE1 or FILE2 is -, not both, read standard input. SIDE is 1\n\
+for FILE1 or 2 for FILE2. Unless -t CHAR is given, leading blanks\n\
+separate fields and are ignored, else fields are separated by CHAR.\n\
+Any FIELD is a field number counted from 1. FORMAT is one or more\n\
+comma or blank separated specifications, each being `SIDE.FIELD'.\n\
+Default FORMAT outputs the join field, the remaining fields from\n\
+FILE1, the remaining fields from FILE2, all separated by CHAR.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/nl.c b/src/nl.c
index 8fb0cd809..f281d5564 100644
--- a/src/nl.c
+++ b/src/nl.c
@@ -204,15 +204,15 @@ main (argc, argv)
case 'h':
if (build_type_arg (&header_type, &header_regex) != TRUE)
- usage ();
+ usage (2);
break;
case 'b':
if (build_type_arg (&body_type, &body_regex) != TRUE)
- usage ();
+ usage (2);
break;
case 'f':
if (build_type_arg (&footer_type, &footer_regex) != TRUE)
- usage ();
+ usage (2);
break;
case 'v':
page_start = atoi (optarg);
@@ -243,7 +243,7 @@ main (argc, argv)
if (optarg[1] == 'n')
lineno_format = FORMAT_LEFT;
else
- usage ();
+ usage (2);
break;
case 'r':
switch (optarg[1])
@@ -255,12 +255,12 @@ main (argc, argv)
lineno_format = FORMAT_RIGHT_LZ;
break;
default:
- usage ();
+ usage (2);
break;
}
break;
default:
- usage ();
+ usage (2);
break;
}
break;
@@ -268,7 +268,7 @@ main (argc, argv)
section_del = optarg;
break;
default:
- usage ();
+ usage (2);
break;
}
}
@@ -280,7 +280,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
/* Initialize the section delimiters. */
c = strlen (section_del);
@@ -563,17 +563,51 @@ build_type_arg (typep, regexp)
/* Print a usage message and quit. */
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-h header-style] [-b body-style] [-f footer-style] [-p] [-d cc]\n\
- [-v start-number] [-i increment] [-l lines] [-s line-separator]\n\
- [-w line-no-width] [-n {ln,rn,rz}] [--header-numbering=style]\n\
- [--body-numbering=style] [--footer-numbering=style]\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] [--help] [--version] [file...]\n",
- program_name);
- exit (2);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -b, --body-numbering STYLE use STYLE for numbering body lines\n\
+ -d, --section-delimiter CC use CC for separating logical pages\n\
+ -f, --footer-numbering STYLE use STYLE for numbering footer lines\n\
+ -h, --header-numbering STYLE use STYLE for numbering header lines\n\
+ -i, --page-increment NUMBER line number increment at each line\n\
+ -l, --join-blank-lines NUMBER group of NUMBER empty lines counted as one\n\
+ -n, --number-format FORMAT insert line numbers according to FORMAT\n\
+ -p, --no-renumber do not reset line numbers at logical pages\n\
+ -s, --number-separator STRING add STRING after (possible) line number\n\
+ -v, --first-page NUMBER first line number on each logical page\n\
+ -w, --number-width NUMBER use NUMBER columns for line numbers\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+By default, selects -v1 -i1 -l1 -sTAB -w6 -nrn -hn -bt -fn. CC are\n\
+two delimiter characters for separating logical pages, a missing\n\
+second character implies :. Type \\\\ for \\. STYLE is one of:\n\
+\n\
+ a number all lines\n\
+ t number only nonempty lines\n\
+ n number no lines\n\
+ pREGEXP number only lines that contain a match for REGEXP\n\
+\n\
+FORMAT is one of:\n\
+\n\
+ ln left justified, no leading zeros\n\
+ rn right justified, no leading zeros\n\
+ rz right justified, leading zeros\n\
+\n\
+With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/od.c b/src/od.c
index c5c853bc8..e47df0081 100644
--- a/src/od.c
+++ b/src/od.c
@@ -307,15 +307,75 @@ static struct option const long_options[] =
};
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-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]] [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+ or: %s -C [FILE] [[+]OFFSET [[+]LABEL]]\n\
+",
+ program_name, program_name);
+ printf ("\
+\n\
+ -A, --address-radix RADIX decide how file offsets are printed\n\
+ -C, --compatible trigger older syntax\n\
+ -N, --read-bytes BYTES limit dump to BYTES input bytes per file\n\
+ -j, --skip-bytes BYTES skip BYTES input bytes first on each file\n\
+ -s, --strings [BYTES] output strings of at least BYTES graphic chars\n\
+ -t, --format TYPE select output format or formats\n\
+ -v, --output-duplicates do not use * to mark line suppression\n\
+ -w, --width [BYTES] output BYTES bytes per output line\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+Pre-POSIX format specifications may be intermixed, they accumulate:\n\
+ -a same as -t a, select named characters\n\
+ -b same as -t oC, select octal bytes\n\
+ -c same as -t c, select ASCII characters or backslash escapes\n\
+ -d same as -t u2, select unsigned decimal shorts\n\
+ -f same as -t fF, select floats\n\
+ -h same as -t x2, select hexadecimal shorts\n\
+ -i same as -t d2, select decimal shorts\n\
+ -l same as -t d4, select decimal longs\n\
+ -o same as -t o2, select octal shorts\n\
+ -x same as -t x2, select hexadecimal shorts\n\
+");
+ printf ("\
+\n\
+For older syntax (second call format), OFFSET means -j OFFSET. LABEL\n\
+is the pseudo-address at first byte printed, incremented when dump is\n\
+progressing. For OFFSET and LABEL, a 0x or 0X prefix indicates\n\
+hexadecimal, suffixes maybe . for octal and b multiply by 512.\n\
+\n\
+TYPE is made up of one or more of these specifications:\n\
+\n\
+ a named character\n\
+ c ASCII character or backslash escape\n\
+ d[SIZE] signed decimal, SIZE bytes per integer\n\
+ f[SIZE] floating point, SIZE bytes per integer\n\
+ o[SIZE] octal, SIZE bytes per integer\n\
+ u[SIZE] unsigned decimal, SIZE bytes per integer\n\
+ x[SIZE] hexadecimal, SIZE bytes per integer\n\
+\n\
+SIZE is a number. For TYPE in doux, SIZE may also be C for\n\
+sizeof(char), S for sizeof(short), I for sizeof(int) or L for\n\
+sizeof(long). If TYPE is f, SIZE may also be F for sizeof(float), D\n\
+for sizeof(double) or L for sizeof(long double).\n\
+\n\
+RADIX is d for decimal, o for octal, x for hexadecimal or n for none.\n\
+BYTES is hexadecimal with 0x or 0X prefix, it is multiplied by 512\n\
+with b suffix, by 1024 with k and by 1048576 with m. -s without a\n\
+number implies 3. -w without a number implies 32. By default, od\n\
+uses -A o -t d2 -w 16. With no FILE, or when FILE is -, read standard\n\
+input.\n\
+");
+ }
+ exit (status);
}
/* Compute the greatest common denominator of U and V
@@ -1795,7 +1855,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
break;
}
}
@@ -1807,7 +1867,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (flag_dump_strings && n_specs > 0)
error (2, 0, "no type may be specified when dumping strings");
@@ -1856,7 +1916,7 @@ main (argc, argv)
error (0, 0,
"invalid second operand in compatibility mode `%s'",
argv[optind + 1]);
- usage ();
+ usage (1);
}
}
else if (n_files == 3)
@@ -1876,14 +1936,14 @@ main (argc, argv)
{
error (0, 0,
"in compatibility mode the last 2 arguments must be offsets");
- usage ();
+ usage (1);
}
}
else
{
error (0, 0,
"in compatibility mode there may be no more than 3 arguments");
- usage ();
+ usage (1);
}
if (flag_pseudo_start)
diff --git a/src/paste.c b/src/paste.c
index d4a0f9295..76f2d9c45 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -139,7 +139,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -150,7 +150,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (optind == argc)
argv[argc++] = "-";
@@ -481,11 +481,27 @@ paste_serial (nfiles, fnamptr)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-s] [-d delim-list] [--serial] [--delimiters=delim-list]\n\
- [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -d, --delimiters LIST reuse characters from LIST instead of TABs\n\
+ -s, --serial paste one file at a time instead of in parallel\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+With no INPUT, or when INPUT is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/pr.c b/src/pr.c
index 9ac5a99d2..8ecc2c6f0 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -499,7 +499,7 @@ main (argc, argv)
if (!ISDIGIT (*s))
{
error (0, 0, "`+' requires a numeric argument");
- usage ();
+ usage (2);
}
/* FIXME: use strtol */
first_page_number = atoi (s);
@@ -604,7 +604,7 @@ main (argc, argv)
fprintf (stderr, "\
%s: extra characters in the argument to the `-s' option: `%s'\n",
program_name, s);
- usage ();
+ usage (2);
}
}
break;
@@ -618,7 +618,7 @@ main (argc, argv)
chars_per_line = atoi (optarg);
break;
default:
- usage ();
+ usage (2);
break;
}
}
@@ -630,7 +630,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (parallel_files && explicit_columns)
error (1, 0,
@@ -695,7 +695,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 ();
+ usage (2);
}
}
}
@@ -1876,13 +1876,45 @@ cleanup ()
/* Complain, print a usage message, and die. */
static void
-usage ()
+usage (status)
+ int status;
{
- 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] [--help] [--version] [file...]\n",
- program_name);
- exit (2);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ +PAGE begin printing with page PAGE\n\
+ -COLUMN produce COLUMN-column output and print columns down\n\
+ -F, -f simulate formfeed with newlines on output\n\
+ -a print columns across rather than down\n\
+ -b balance columns on the last page\n\
+ -c use hat notation (^G) and octal backslash notation\n\
+ -d double space the output\n\
+ -e[CHAR[WIDTH]] expand input CHARs (TABs) to tab WIDTH (8)\n\
+ -h HEADER use HEADER instead of filename in page headers\n\
+ -i[CHAR[WIDTH]] replace spaces with CHARs (TABs) to tab WIDTH (8)\n\
+ -l PAGE_LENGTH set the page length to PAGE_LENGTH (66) lines\n\
+ -m print all files in parallel, one in each column\n\
+ -n[SEP[DIGITS]] number lines, use DIGITS (5) digits, then SEP (TAB)\n\
+ -o MARGIN offset each line with MARGIN spaces (do not affect -w)\n\
+ -r inhibit warning when a file cannot be opened\n\
+ -s[SEP] separate columns by character SEP (TAB)\n\
+ -t inhibit 5-line page headers and trailers\n\
+ -v use octal backslash notation\n\
+ -w PAGE_WIDTH set page width to PAGE_WIDTH (72) columns\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+-t implied by -l N when N < 10. Without -s, columns are separated by\n\
+spaces. With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/sort.c b/src/sort.c
index 5253f5f89..ce3d271c1 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1539,7 +1539,7 @@ main (argc, argv)
if (digits[UCHAR (*s)])
{
if (!key)
- usage ();
+ usage (2);
for (t = 0; digits[UCHAR (*s)]; ++s)
t = t * 10 + *s - '0';
t2 = 0;
@@ -1676,7 +1676,7 @@ main (argc, argv)
default:
fprintf (stderr, "%s: unrecognized option `-%c'\n",
argv[0], *s);
- usage ();
+ usage (2);
}
if (*s)
++s;
@@ -1775,11 +1775,46 @@ main (argc, argv)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-cmus] [-t separator] [-o output-file] [-T tempdir] [-bdfiMnr]\n\
- [+POS1 [-POS2]] [-k POS1[,POS2]] [file...]\n",
- program_name);
- exit (2);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ +POS1 [-POS2] start a key at POS1, end it before POS2\n\
+ -M compare (unknown) < `JAN' < ... < `DEC', imply -b\n\
+ -T DIRECT use DIRECTfor temporary files, not $TEMPDIR nor /tmp\n\
+ -b ignore leading blanks in sort fields or keys\n\
+ -c check if given files already sorted, do not sort\n\
+ -d consider only [a-zA-Z0-9 ] characters in keys\n\
+ -f fold lower case to upper case characters in keys\n\
+ -i consider only [\\040-\\0176] characters in keys\n\
+ -k POS1[,POS2] same as +POS1 [-POS2], but all positions counted from 1\n\
+ -m merge already sorted files, do not sort\n\
+ -n compare according to string numerical value, imply -b\n\
+ -o FILE write result on FILE instead of standard output\n\
+ -r reverse the result of comparisons\n\
+ -s stabilize sort by disabling last resort comparison\n\
+ -t SEP use SEParator instead of non- to whitespace transition\n\
+ -u with -c, check for strict ordering\n\
+ -u with -m, only output the first of an equal sequence\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+POS is F[.C][OPTS], where F is the field number and C the character\n\
+position in the field, both counted from zero. OPTS is made up of one\n\
+or more of Mbdfinr, this effectively disable global -Mbdfinr settings\n\
+for that key. If no key given, use the entire line as key. With no\n\
+FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/split.c b/src/split.c
index 8dee177dd..9a1d419b0 100644
--- a/src/split.c
+++ b/src/split.c
@@ -94,23 +94,43 @@ static struct option const longopts[] =
};
static void
-usage (reason)
- char *reason;
+usage (status, reason)
+ int status;
+ char *reason;
{
if (reason != NULL)
fprintf (stderr, "%s: %s\n", program_name, 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\
- [--help] [--version] [infile [outfile-prefix]]\n",
- program_name);
- exit (2);
+
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION] [INPUT [PREFIX]]\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -C, --line-bytes SIZE put at most SIZE bytes of lines per output file\n\
+ -b, --bytes SIZE put SIZE bytes per output file\n\
+ -l, --lines NUMBER put NUMBER lines per output file\n\
+ -NUMBER same as -l NUMBER\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.\n\
+With no PREFIX, use x. With no INPUT, or when INPUT is -, read\n\
+standard input.\n\
+");
+ }
+ exit (status);
}
void
main (argc, argv)
- int argc;
- char *argv[];
+ int argc;
+ char *argv[];
{
struct stat stat_buf;
int num; /* numeric argument from command line */
@@ -148,27 +168,27 @@ main (argc, argv)
case 'b':
if (split_type != type_undef)
- usage ("cannot split in more than one way");
+ usage (2, "cannot split in more than one way");
split_type = type_bytes;
if (convint (optarg, &accum) == -1)
- usage ("invalid number of bytes");
+ usage (2, "invalid number of bytes");
break;
case 'l':
if (split_type != type_undef)
- usage ("cannot split in more than one way");
+ usage (2, "cannot split in more than one way");
split_type = type_lines;
if (!isdigits (optarg))
- usage ("invalid number of lines");
+ usage (2, "invalid number of lines");
accum = atoi (optarg);
break;
case 'C':
if (split_type != type_undef)
- usage ("cannot split in more than one way");
+ usage (2, "cannot split in more than one way");
split_type = type_byteslines;
if (convint (optarg, &accum) == -1)
- usage ("invalid number of bytes");
+ usage (2, "invalid number of bytes");
break;
case '0':
@@ -182,7 +202,7 @@ main (argc, argv)
case '8':
case '9':
if (split_type != type_undef && split_type != type_digits)
- usage ("cannot split in more than one way");
+ usage (2, "cannot split in more than one way");
if (digits_optind != 0 && digits_optind != this_optind)
accum = 0; /* More than one number given; ignore other. */
digits_optind = this_optind;
@@ -191,7 +211,7 @@ main (argc, argv)
break;
default:
- usage ((char *)0);
+ usage (2, (char *)0);
}
}
@@ -202,7 +222,7 @@ main (argc, argv)
}
if (show_help)
- usage ((char *)0);
+ usage (0, (char *)0);
/* Handle default case. */
if (split_type == type_undef)
@@ -212,7 +232,7 @@ main (argc, argv)
}
if (accum < 1)
- usage ("invalid number");
+ usage (2, "invalid number");
num = accum;
/* Get out the filename arguments. */
@@ -224,7 +244,7 @@ main (argc, argv)
outbase = argv[optind++];
if (optind < argc)
- usage ("too many arguments");
+ usage (2, "too many arguments");
/* Open the input file. */
if (!strcmp (infile, "-"))
@@ -289,7 +309,7 @@ main (argc, argv)
static int
isdigits (str)
- char *str;
+ char *str;
{
do
{
@@ -343,9 +363,9 @@ convint (str, val)
static void
bytes_split (nchars, buf, bufsize)
- int nchars;
- char *buf;
- int bufsize;
+ int nchars;
+ char *buf;
+ int bufsize;
{
int n_read;
int new_file_flag = 1;
@@ -390,9 +410,9 @@ bytes_split (nchars, buf, bufsize)
static void
lines_split (nlines, buf, bufsize)
- int nlines;
- char *buf;
- int bufsize;
+ int nlines;
+ char *buf;
+ int bufsize;
{
int n_read;
char *bp, *bp_out, *eob;
@@ -439,7 +459,7 @@ lines_split (nlines, buf, bufsize)
static void
line_bytes_split (nchars)
- int nchars;
+ int nchars;
{
int n_read;
char *bp;
@@ -490,9 +510,9 @@ line_bytes_split (nchars)
static void
cwrite (new_file_flag, bp, bytes)
- int new_file_flag;
- char *bp;
- int bytes;
+ int new_file_flag;
+ char *bp;
+ int bytes;
{
if (new_file_flag)
{
@@ -514,8 +534,8 @@ cwrite (new_file_flag, bp, bytes)
static int
stdread (buf, nchars)
- char *buf;
- int nchars;
+ char *buf;
+ int nchars;
{
int n_read;
int to_be_read = nchars;
diff --git a/src/sum.c b/src/sum.c
index 3cf17662c..67527e142 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -65,11 +65,29 @@ static struct option const longopts[] =
};
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-rs] [--help] [--version] [--sysv] [file...]\n", program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -r defeat -s, use BSD sum algorithm, use 1K blocks\n\
+ -s, --sysv use System V sum algorithm, use 512 bytes blocks\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
void
@@ -101,7 +119,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -112,7 +130,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
files_given = argc - optind;
if (files_given == 0)
diff --git a/src/tac.c b/src/tac.c
index 34aa7e051..fcff73749 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -130,13 +130,30 @@ static struct option const longopts[] =
};
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-br] [-s separator] [--before] [--regex] [--separator=separator]\n\
- [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -b, --before attach the separator before instead of after\n\
+ -r, --regex intepret the separator as a regular expression\n\
+ -s, --separator STRING use STRING as the separator instead of newline\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
void
@@ -173,7 +190,7 @@ main (argc, argv)
error (1, 0, "separator cannot be empty");
break;
default:
- usage ();
+ usage (1);
}
}
@@ -184,7 +201,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (sentinel_length == 0)
{
diff --git a/src/tail.c b/src/tail.c
index e5308a15c..91c470b41 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -212,7 +212,7 @@ main (argc, argv)
default:
error (0, 0, "unrecognized option `-%c'", *argv[1]);
- usage ();
+ usage (1);
}
++argv[1];
}
@@ -263,7 +263,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -274,7 +274,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (number == -1)
number = DEFAULT_NUMBER;
@@ -1015,12 +1015,35 @@ atou (str)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-c [+]N[bkm]] [-n [+]N] [-fqv] [--bytes=[+]N[bkm]] [--lines=[+]N]\n\
- [--follow] [--quiet] [--silent] [--verbose] [--help] [--version]\n\
- [file...]\n\
- %s [{-,+}Nbcfklmqv] [file...]\n", program_name, program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -c, --bytes SIZE print last SIZE bytes\n\
+ -f, --follow print files as they grow\n\
+ -l, -n, --lines NUMBER print last NUMBER lines, instead of last 10\n\
+ -q, --quiet, --silent never print headers giving file names\n\
+ -v, --verbose always print headers giving file names\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.\n\
+If SIZE is prefixed by +, prints all except the first SIZE bytes. If\n\
+NUMBER is prefixed by +, prints all except the first NUMBER lines. If\n\
+-VALUE or +VALUE is used as first OPTION, read -c VALUE or -c +VALUE\n\
+when one of multipliers bkm follows concatenated, else read -n VALUE\n\
+or -n +VALUE. With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/tr.c b/src/tr.c
index aadab06cb..19f747fe8 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* Written by Jim Meyering, meyering@cs.utexas.edu. */
+/* Written by Jim Meyering, meyering@cs.utexas.edu. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
@@ -49,36 +49,36 @@
#define N_CHARS (UCHAR_MAX + 1)
-/* A pointer to a function that returns an int. */
+/* A pointer to a function that returns an int. */
typedef int (*PFI) ();
/* Convert from character C to its index in the collating
sequence array. Just cast to an unsigned int to avoid
- problems with sign-extension. */
+ problems with sign-extension. */
#define ORD(c) (unsigned int)(c)
-/* The inverse of ORD. */
+/* The inverse of ORD. */
#define CHR(i) (unsigned char)(i)
/* The value for Spec_list->state that indicates to
get_next that it should initialize the tail pointer.
Its value doesn't matter as long as it can't be
- confused with a valid character code. */
+ confused with a valid character code. */
#define BEGIN_STATE (2 * N_CHARS)
/* The value for Spec_list->state that indicates to
get_next that the element pointed to by Spec_list->tail is
being considered for the first time on this pass through the
list -- it indicates that get_next should make any necessary
- initializations. */
+ initializations. */
#define NEW_ELEMENT (BEGIN_STATE + 1)
/* A value distinct from any character that may have been stored in a
- buffer as the result of a block-read in the function squeeze_filter. */
+ buffer as the result of a block-read in the function squeeze_filter. */
#define NOT_A_CHAR (unsigned int)(-1)
/* The following (but not CC_NO_CLASS) are indices into the array of
- valid character class strings. */
+ valid character class strings. */
enum Char_class
{
CC_ALNUM = 0, CC_ALPHA = 1, CC_BLANK = 2, CC_CNTRL = 3,
@@ -92,7 +92,7 @@ enum Char_class
was one of the character classes [:upper:] or [:lower:]. The value
is used only when translating and then, only to make sure that upper
and lower class constructs have the same relative positions in string1
- and string2. */
+ and string2. */
enum Upper_Lower_class
{
UL_LOWER = 0,
@@ -105,7 +105,7 @@ enum Upper_Lower_class
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. */
+ indexed by values of type enum Upper_Lower_class. */
static int const class_ok[3][3] =
{
{0, 1, 0},
@@ -113,7 +113,7 @@ static int const class_ok[3][3] =
{0, 0, 1}
};
-/* The type of a List_element. See build_spec_list for more details. */
+/* The type of a List_element. See build_spec_list for more details. */
enum Range_element_type
{
RE_NO_TYPE = 0,
@@ -128,7 +128,7 @@ enum Range_element_type
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. */
+ and a single normal character, `_'. String2 has one construct. */
struct List_element
{
enum Range_element_type type;
@@ -162,39 +162,39 @@ struct List_element
specified (like -s, -d, or -c). The main exception is the member
`tail', which is first used to construct the list. After construction,
it is used by get_next to save its state when traversing the list.
- The member `state' serves a similar function. */
+ 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. */
+ 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. */
+ signals get_next to initialize tail to point to head->next. */
struct List_element *tail;
- /* Used to save state between calls to get_next(). */
+ /* 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). */
+ is 42 ( = 26 + 10 + 6). */
int length;
- /* The number of [c*] and [c*0] constructs that appear in this spec. */
+ /* 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=]. */
+ class construct e.g. [=c=]. */
int has_equiv_class;
/* Non-zero if this spec contains at least one of [:upper:] or
- [:lower:] class constructs. */
+ [: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. */
+ constructs (all but upper and lower) that aren't allowed in s2. */
int has_restricted_char_class;
};
@@ -202,18 +202,18 @@ char *xmalloc ();
char *stpcpy ();
void error ();
-/* The name by which this program was run. */
+/* The name by which this program was run. */
char *program_name;
/* When non-zero, each sequence in the input of a repeated character
(call it c) is replaced (in the output) by a single occurrence of c
- for every c in the squeeze set. */
+ for every c in the squeeze set. */
static int squeeze_repeats = 0;
-/* When non-zero, removes characters in the delete set from input. */
+/* When non-zero, removes characters in the delete set from input. */
static int delete = 0;
-/* Use the complement of set1 in place of set1. */
+/* Use the complement of set1 in place of set1. */
static int complement = 0;
/* When non-zero, this flag causes GNU tr to provide strict
@@ -228,7 +228,7 @@ static int complement = 0;
being POSIX conformant means we can't issue such messages.
Warnings on the following topics are suppressed when this
variable is non-zero:
- 1. Ambiguous octal escapes. */
+ 1. Ambiguous octal escapes. */
static int posix_pedantic;
/* When tr is performing translation and string1 is longer than string2,
@@ -258,11 +258,11 @@ static int posix_pedantic;
compatibility. For example, it doesn't disable the interpretation
of the POSIX constructs [:alpha:], [=c=], and [c*10], so if by
some unfortunate coincidence you use such constructs in scripts
- expecting to use some other version of tr, the scripts will break. */
+ expecting to use some other version of tr, the scripts will break. */
static int truncate_set1 = 0;
/* An alias for (!delete && non_option_args == 2).
- It is set in main and used there and in validate(). */
+ It is set in main and used there and in validate(). */
static int translating;
#ifndef BUFSIZ
@@ -295,7 +295,7 @@ static SET_TYPE in_delete_set[N_CHARS];
/* Array of character values defining the translation (if any) that
tr is to perform. Translation is performed only when there are
- two specification strings and the delete switch is not given. */
+ two specification strings and the delete switch is not given. */
static char xlate[N_CHARS];
/* If non-zero, display usage information and exit. */
@@ -316,17 +316,76 @@ static struct option const long_options[] =
};
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-cdst] [--complement] [--delete] [--squeeze-repeats]\n\
- [--truncate-set1] [--help] [--version] string1 [string2]\n",
- program_name);
- exit (2);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... SET1 [SET2]\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -c, --complement first complement SET1\n\
+ -d, --delete delete characters in SET1, do not translate\n\
+ -s, --squeeze-repeats replace sequence of characters with one\n\
+ -t, --truncate-set1 first truncate SET1 to length of SET2\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+");
+ printf ("\
+\n\
+SETs are specified as strings of characters. Most represent\n\
+themselves. Here are the special writings:\n\
+\n\
+ \\NNN character with octal value NNN (1 to 3 digits)\n\
+ \\\\ backslash\n\
+ \\a audible BEL\n\
+ \\b backspace\n\
+ \\f form feed\n\
+ \\n new line\n\
+ \\r return\n\
+ \\t horizontal tab\n\
+ \\v vertical tab\n\
+ CHAR1-CHAR2 all characters from CHAR1 to CHAR2 in ascending order\n\
+ [CHAR1-CHAR2] same as CHAR1-CHAR2, if both SET1 and SET2 use this\n\
+ [CHAR*] in SET2, copies of CHAR until length of SET1\n\
+ [CHAR*REPEAT] REPEAT copies of CHAR, REPEAT octal if starting with 0\n\
+ [:alnum:] all letters and digits\n\
+ [:alpha:] all letters\n\
+ [:blank:] all horizontal whitespace\n\
+ [:cntrl:] all control characters\n\
+ [:digit:] all digits\n\
+ [:graph:] all printable characters, not including space\n\
+ [:lower:] all lowercase letters\n\
+ [:print:] all printable characters, including space\n\
+ [:punct:] all punctuation characters\n\
+ [:space:] all horizontal or vertical whitespace\n\
+ [:upper:] all uppercase letters\n\
+ [:xdigit:] all hexadecimal digits\n\
+ [=CHAR=] all characters which are equivalent to CHAR\n\
+");
+ printf ("\
+\n\
+Translation occurs if -d is not given and both SET1 and SET2 appear.\n\
+-t may be used only when translating. SET2 is extended to length of\n\
+SET1 by repeating its last character as necessary. Excess characters\n\
+of SET2 are ignored. Only [:lower:] and [:upper:] are guaranteed to\n\
+expand in ascending order; used in SET2 while translating, they may\n\
+only be used in pairs to specify case conversion. -s uses SET1 if not\n\
+translating nor deleting; else squeezing uses SET2 and occurs after\n\
+translation or deletion.\n\
+");
+ }
+ exit (status);
}
/* Return non-zero if the character C is a member of the
- equivalence class containing the character EQUIV_CLASS. */
+ equivalence class containing the character EQUIV_CLASS. */
static int
is_equiv_class_member (equiv_class, c)
@@ -337,7 +396,7 @@ is_equiv_class_member (equiv_class, c)
}
/* Return non-zero if the character C is a member of the
- character class CHAR_CLASS. */
+ character class CHAR_CLASS. */
static int
is_char_class_member (char_class, c)
@@ -396,7 +455,7 @@ is_char_class_member (char_class, c)
the resulting string is returned through LEN and the function returns 0.
The resulting array of characters may contain zero-bytes; however,
on input, S is assumed to be null-terminated, and hence
- cannot contain actual (non-escaped) zero bytes. */
+ cannot contain actual (non-escaped) zero bytes. */
static int
unquote (s, len)
@@ -469,7 +528,7 @@ unquote (s, len)
give a warning about the ambiguity. POSIX
isn't clear on this, but one person has said
that in his interpretation, POSIX says tr
- can't even give a warning. */
+ can't even give a warning. */
error (0, 0, "warning: the ambiguous octal escape \
\\%c%c%c is being\n\tinterpreted as the 2-byte sequence \\0%c%c, `%c'",
s[i], s[i + 1], s[i + 2],
@@ -500,7 +559,7 @@ unquote (s, len)
}
/* If CLASS_STR is a valid character class string, return its index
- in the global char_class_name array. Otherwise, return CC_NO_CLASS. */
+ in the global char_class_name array. Otherwise, return CC_NO_CLASS. */
static enum Char_class
look_up_char_class (class_str)
@@ -515,7 +574,7 @@ look_up_char_class (class_str)
}
/* Return a newly allocated string with a printable version of C.
- This function is used solely for formatting error messages. */
+ This function is used solely for formatting error messages. */
static char *
make_printable_char (c)
@@ -541,7 +600,7 @@ make_printable_char (c)
(isprint) characters are represented by a backslash followed by
3 octal digits. However, the characters represented by \c escapes
where c is one of [abfnrtv] are represented by their 2-character \c
- sequences. This function is used solely for printing error messages. */
+ sequences. This function is used solely for printing error messages. */
static char *
make_printable_str (s, len)
@@ -549,7 +608,7 @@ make_printable_str (s, len)
int len;
{
/* Worst case is that every character expands to a backslash
- followed by a 3-character octal escape sequence. */
+ followed by a 3-character octal escape sequence. */
char *printable_buf = xmalloc (4 * len + 1);
char *p = printable_buf;
int i;
@@ -602,7 +661,7 @@ make_printable_str (s, len)
}
/* Append a newly allocated structure representing a
- character C to the specification list LIST. */
+ character C to the specification list LIST. */
static void
append_normal_char (list, c)
@@ -659,7 +718,7 @@ append_range (list, first, last)
/* If CHAR_CLASS_STR is a valid character class string, append a
newly allocated structure representing that character class to the end
of the specification list LIST and return 0. If CHAR_CLASS_STR is not
- a valid string, give an error message and return non-zero. */
+ a valid string, give an error message and return non-zero. */
static int
append_char_class (list, char_class_str, len)
@@ -692,7 +751,7 @@ append_char_class (list, char_class_str, len)
/* Append a newly allocated structure representing a [c*n]
repeated character construct, to the specification list LIST.
THE_CHAR is the single character to be repeated, and REPEAT_COUNT
- is non-negative repeat count. */
+ is non-negative repeat count. */
static void
append_repeated_char (list, the_char, repeat_count)
@@ -716,7 +775,7 @@ append_repeated_char (list, the_char, repeat_count)
the length of that string, LEN, if LEN is exactly one, append
a newly allocated structure representing the specified
equivalence class to the specification list, LIST and return zero.
- If LEN is not 1, issue an error message and return non-zero. */
+ If LEN is not 1, issue an error message and return non-zero. */
static int
append_equiv_class (list, equiv_class_str, len)
@@ -745,7 +804,7 @@ append_equiv_class (list, equiv_class_str, len)
return 0;
}
-/* Return a newly allocated copy of P[FIRST_IDX..LAST_IDX]. */
+/* Return a newly allocated copy of P[FIRST_IDX..LAST_IDX]. */
static unsigned char *
substr (p, first_idx, last_idx)
@@ -757,8 +816,8 @@ substr (p, first_idx, last_idx)
unsigned char *tmp = (unsigned char *) xmalloc (len);
assert (first_idx <= last_idx);
- /* We must use bcopy or memcopy rather than strncpy
- because `p' may contain zero-bytes. */
+ /* We must use bcopy or memcpy rather than strncpy
+ because `p' may contain zero-bytes. */
bcopy (p + first_idx, tmp, len);
tmp[len] = '\0';
return tmp;
@@ -767,7 +826,7 @@ substr (p, first_idx, last_idx)
/* Search forward starting at START_IDX for the 2-char sequence
(PRE_BRACKET_CHAR,']') in the string P of length P_LEN. If such
a sequence is found, return the index of the first character,
- otherwise return -1. P may contain zero bytes. */
+ otherwise return -1. P may contain zero bytes. */
static int
find_closing_delim (p, start_idx, p_len, pre_bracket_char)
@@ -789,7 +848,7 @@ find_closing_delim (p, start_idx, p_len, pre_bracket_char)
If the string represents a negative value, a value larger
than LONG_MAX, or if all LEN characters do not represent a
valid integer, return non-zero and do not modify *VAL.
- Otherwise, return zero and set *VAL to the converted value. */
+ Otherwise, return zero and set *VAL to the converted value. */
static int
non_neg_strtol (s, len, val)
@@ -833,7 +892,7 @@ non_neg_strtol (s, len, val)
found, return -1. If a closing bracket is found and the
second char is `*', but the string between the `*' and `]' isn't
empty, an octal number, or a decimal number, print an error message
- and return -2. */
+ and return -2. */
static int
find_bracketed_repeat (p, start_idx, p_len, char_to_repeat, n)
@@ -859,13 +918,13 @@ find_bracketed_repeat (p, start_idx, p_len, char_to_repeat, n)
*char_to_repeat = p[start_idx];
if (digit_str_len == 0)
{
- /* We've matched [c*] -- no explicit repeat count. */
+ /* We've matched [c*] -- no explicit repeat count. */
*n = 0;
return i;
}
/* Here, we have found [c*s] where s should be a string
- of octal or decimal digits. */
+ of octal or decimal digits. */
digit_str = &p[start_idx + 2];
if (non_neg_strtol (digit_str, digit_str_len, n))
{
@@ -877,7 +936,7 @@ find_bracketed_repeat (p, start_idx, p_len, char_to_repeat, n)
return i;
}
}
- return -1; /* No bracket found. */
+ return -1; /* No bracket found. */
}
/* Convert string UNESACPED_STRING (which has been preprocessed to
@@ -890,7 +949,7 @@ find_bracketed_repeat (p, start_idx, p_len, char_to_repeat, n)
decimal integer.
- r-s Range of characters from `r' to `s'. The second endpoint must
not precede the first in the current collating sequence.
- - c Any other character is interpreted as itself. */
+ - c Any other character is interpreted as itself. */
static int
build_spec_list (unescaped_string, len, result)
@@ -908,7 +967,7 @@ build_spec_list (unescaped_string, len, result)
constructs is classified as `normal'. Since all multi-character
constructs have at least 3 characters, any strings of length 2 or
less are composed solely of normal characters. Hence, the index of
- the outer for-loop runs only as far as LEN-2. */
+ the outer for-loop runs only as far as LEN-2. */
for (i = 0; i < len - 2;)
{
@@ -938,17 +997,17 @@ build_spec_list (unescaped_string, len, result)
(closing_delim_idx - 1) - (i + 2) + 1);
free (opnd_str);
- /* Return non-zero if append_*_class reports a problem. */
+ /* Return non-zero if append_*_class reports a problem. */
if (parse_failed)
return 1;
else
i = closing_delim_idx + 2;
break;
}
- /* Else fall through. This could be [:*] or [=*]. */
+ /* Else fall through. This could be [:*] or [=*]. */
default:
/* Determine whether this is a bracketed repeat range
- matching the RE \[.\*(dec_or_oct_number)?\]. */
+ matching the RE \[.\*(dec_or_oct_number)?\]. */
closing_bracket_idx = find_bracketed_repeat (p, i + 1,
len, &char_to_repeat, &repeat_count);
if (closing_bracket_idx >= 0)
@@ -963,7 +1022,7 @@ build_spec_list (unescaped_string, len, result)
}
else
/* Found a string that looked like [c*n] but the
- numeric part was invalid. */
+ numeric part was invalid. */
return 1;
break;
}
@@ -972,9 +1031,9 @@ build_spec_list (unescaped_string, len, result)
/* Here if we've tried to match [c*n], [:str:], and [=c=]
and none of them fit. So we still have to consider the
- range `[-c' (from `[' to `c'). */
+ range `[-c' (from `[' to `c'). */
default:
- /* Look ahead one char for ranges like a-z. */
+ /* Look ahead one char for ranges like a-z. */
if (p[i + 1] == '-')
{
if (append_range (result, p[i], p[i + 2]))
@@ -990,7 +1049,7 @@ build_spec_list (unescaped_string, len, result)
}
}
- /* Now handle the (2 or fewer) remaining characters p[i]..p[len - 1]. */
+ /* Now handle the (2 or fewer) remaining characters p[i]..p[len - 1]. */
for (; i < len; i++)
append_normal_char (result, p[i]);
@@ -1009,7 +1068,7 @@ build_spec_list (unescaped_string, len, result)
CLASS is set to UL_NONE. This value is used only when constructing
the translation table to verify that any occurrences of upper and
lower class constructs in the spec-strings appear in the same relative
- positions. */
+ positions. */
static int
get_next (s, class)
@@ -1096,7 +1155,7 @@ get_next (s, class)
/* FIXME: this assumes that each character is alone in its own
equivalence class (which appears to be correct for my
LC_COLLATE. But I don't know of any function that allows
- one to determine a character's equivalence class. */
+ one to determine a character's equivalence class. */
return_val = p->u.equiv_code;
s->state = NEW_ELEMENT;
@@ -1104,7 +1163,7 @@ get_next (s, class)
break;
case RE_REPEATED_CHAR:
- /* Here, a repeat count of n == 0 means don't repeat at all. */
+ /* Here, a repeat count of n == 0 means don't repeat at all. */
assert (p->u.repeated_char.repeat_count >= 0);
if (p->u.repeated_char.repeat_count == 0)
{
@@ -1132,14 +1191,18 @@ get_next (s, class)
case RE_NO_TYPE:
abort ();
break;
+
+ default:
+ abort ();
+ break;
}
return return_val;
}
/* This is a minor kludge. This function is called from
get_spec_stats to determine the cardinality of a set derived
- from a complemented string. It's a kludge in that some of
- the same operations are (duplicated) performed in set_initialize. */
+ from a complemented string. It's a kludge in that some of the
+ same operations are (duplicated) performed in set_initialize. */
static int
card_of_complement (s)
@@ -1168,7 +1231,7 @@ card_of_complement (s)
construct in string2 to [c*n] where n is large enough (or 0) to give
string2 the same length as string1. For example, with the command
tr a-z 'A[\n*]Z' on the second call to get_spec_stats, LEN_S1 would
- be 26 and S (representing string2) would be converted to 'A[\n*24]Z'. */
+ be 26 and S (representing string2) would be converted to 'A[\n*24]Z'. */
static void
get_spec_stats (s, len_s1)
@@ -1261,7 +1324,7 @@ spec_init (spec_list)
one converts all \c and \ddd escapes to their one-byte representations.
The second constructs a linked specification list, SPEC_LIST, of the
characters and constructs that comprise the argument string. If either
- of these passes detects an error, this function returns non-zero. */
+ of these passes detects an error, this function returns non-zero. */
static int
parse_str (s, spec_list)
@@ -1328,14 +1391,19 @@ string2_extend (s1, s2)
case RE_EQUIV_CLASS:
/* This shouldn't happen, because validate exits with an error
- if it finds an equiv class in string2 when translating. */
+ if it finds an equiv class in string2 when translating. */
abort ();
break;
case RE_NO_TYPE:
abort ();
break;
+
+ default:
+ abort ();
+ break;
}
+
append_repeated_char (s2, char_to_repeat, s1->length - s2->length);
s2->length = s1->length;
return;
@@ -1347,7 +1415,7 @@ string2_extend (s1, s2)
[c*0] construct appears in string2, it is converted to [c*n]
with a value for n that makes s2->length == s1->length. By
the same token, if the --truncate-set1 option is not
- given, S2 may be extended. */
+ given, S2 may be extended. */
static void
validate (s1, s2)
@@ -1362,7 +1430,7 @@ validate (s1, s2)
/* FIXME: it isn't clear from the POSIX spec that this is illegal,
but in the spirit of the other restrictions put on translation
- with character classes, this seems a logical interpretation. */
+ with character classes, this seems a logical interpretation. */
if (complement && s1->has_upper_or_lower)
{
error (1, 0,
@@ -1397,7 +1465,7 @@ validate (s1, s2)
if (!truncate_set1)
{
/* string2 must be non-empty unless --truncate-set1 is
- given or string1 is empty. */
+ given or string1 is empty. */
if (s2->length == 0)
error (1, 0,
@@ -1411,7 +1479,7 @@ validate (s1, s2)
"character classes may not be used when translating and complementing");
}
else
- /* Not translating. */
+ /* Not translating. */
{
if (s2->n_indefinite_repeats > 0)
error (1, 0,
@@ -1426,7 +1494,7 @@ validate (s1, s2)
processed and written to stdout. The buffers are processed so that
multiple consecutive occurrences of the same character in the input
stream are replaced by a single occurrence of that character if the
- character is in the squeeze set. */
+ character is in the squeeze set. */
static void
squeeze_filter (buf, size, reader)
@@ -1471,13 +1539,13 @@ squeeze_filter (buf, size, reader)
perhaps twice as much work in the worst cases where most
of the input is removed by squeezing repeats. But most
uses of this functionality seem to remove less than 20-30%
- of the input. */
+ of the input. */
for (; i < nr && !in_squeeze_set[buf[i]]; i += 2)
; /* empty */
/* There is a special case when i == nr and we've just
skipped a character (the last one in buf) that is in
- the squeeze set. */
+ the squeeze set. */
if (i == nr && in_squeeze_set[buf[i - 1]])
--i;
@@ -1486,17 +1554,17 @@ squeeze_filter (buf, size, reader)
else
{
char_to_squeeze = buf[i];
- /* We're about to output buf[begin..i]. */
+ /* We're about to output buf[begin..i]. */
out_len = i - begin + 1;
/* But since we stepped by 2 in the loop above,
- out_len may be one too large. */
+ out_len may be one too large. */
if (i > 0 && buf[i - 1] == char_to_squeeze)
--out_len;
/* Advance i to the index of first character to be
considered when looking for a char different from
- char_to_squeeze. */
+ char_to_squeeze. */
++i;
}
if (out_len > 0
@@ -1508,14 +1576,14 @@ squeeze_filter (buf, size, reader)
{
/* Advance i to index of first char != char_to_squeeze
(or to nr if all the rest of the characters in this
- buffer are the same as char_to_squeeze). */
+ buffer are the same as char_to_squeeze). */
for (; i < nr && buf[i] == char_to_squeeze; i++)
; /* empty */
if (i < nr)
char_to_squeeze = NOT_A_CHAR;
/* If (i >= nr) we've squeezed the last character in this buffer.
So now we have to read a new buffer and continue comparing
- characters against char_to_squeeze. */
+ characters against char_to_squeeze. */
}
}
}
@@ -1524,7 +1592,7 @@ squeeze_filter (buf, size, reader)
contains at least one character not in the delete set. Store
in the array BUF, all characters from that buffer that are not
in the delete set, and return the number of characters saved
- or 0 upon EOF. */
+ or 0 upon EOF. */
static long
read_and_delete (buf, size, not_used)
@@ -1543,7 +1611,7 @@ read_and_delete (buf, size, not_used)
/* This enclosing do-while loop is to make sure that
we don't return zero (indicating EOF) when we've
- just deleted all the characters in a buffer. */
+ just deleted all the characters in a buffer. */
do
{
int i;
@@ -1560,7 +1628,7 @@ read_and_delete (buf, size, not_used)
/* This first loop may be a waste of code, but gives much
better performance when no characters are deleted in
the beginning of a buffer. It just avoids the copying
- of buf[i] into buf[n_saved] when it would be a NOP. */
+ of buf[i] into buf[n_saved] when it would be a NOP. */
for (i = 0; i < nr && !in_delete_set[buf[i]]; i++)
/* empty */ ;
@@ -1577,7 +1645,7 @@ read_and_delete (buf, size, not_used)
/* Read at most SIZE bytes from stdin into the array BUF. Then
perform the in-place and one-to-one mapping specified by the global
- array `xlate'. Return the number of characters read, or 0 upon EOF. */
+ array `xlate'. Return the number of characters read, or 0 upon EOF. */
static long
read_and_xlate (buf, size, not_used)
@@ -1613,7 +1681,7 @@ read_and_xlate (buf, size, not_used)
/* Initialize a boolean membership set IN_SET with the character
values obtained by traversing the linked list of constructs S
using the function `get_next'. If COMPLEMENT_THIS_SET is
- non-zero the resulting set is complemented. */
+ non-zero the resulting set is complemented. */
static void
set_initialize (s, complement_this_set, in_set)
@@ -1671,7 +1739,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (2);
break;
}
}
@@ -1683,7 +1751,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
posix_pedantic = (getenv ("POSIXLY_CORRECT") != NULL);
@@ -1694,9 +1762,9 @@ main (argc, argv)
no args at all. POSIX doesn't specifically say anything
either way, but it looks like they implied it's illegal
by omission. If you want to make tr do a slow imitation
- of `cat' use `tr a a'. */
+ of `cat' use `tr a a'. */
if (non_option_args > 2)
- usage ();
+ usage (2);
if (!delete && !squeeze_repeats && non_option_args != 2)
error (1, 0, "two strings must be given when translating");
@@ -1709,7 +1777,7 @@ deleting and squeezing repeats");
only one string argument may be specified. But POSIX
says to ignore any string2 in this case, so if POSIXLY_CORRECT
is set, pretend we never saw string2. But I think
- this deserves a fatal error, so that's the default. */
+ this deserves a fatal error, so that's the default. */
if ((delete && !squeeze_repeats) && non_option_args != 1)
{
if (posix_pedantic && non_option_args == 2)
@@ -1804,7 +1872,7 @@ deleting and squeezing repeats");
if (!class_ok[(int) class_s1][(int) class_s2])
error (1, 0,
"misaligned or mismatched upper and/or lower classes");
- /* The following should have been checked by validate... */
+ /* The following should have been checked by validate... */
if (c2 == -1)
break;
xlate[c1] = c2;
diff --git a/src/unexpand.c b/src/unexpand.c
index 5ab1e6bbb..70078d14c 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -147,7 +147,7 @@ main (argc, argv)
break;
case '?':
- usage ();
+ usage (1);
case 'a':
convert_entire_line = 1;
break;
@@ -174,7 +174,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
add_tabstop (tabval);
@@ -446,11 +446,29 @@ next_file (fp)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-tab1[,tab2[,...]]] [-t tab1[,tab2[,...]]] [-a]\n\
- [--tabs=tab1[,tab2[,...]]] [--all] [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -a, --all convert all whitespace, instead of initial whitespace\n\
+ -t, --tabs NUMBER have tabs NUMBER characters apart, not 8\n\
+ -t, --tabs LIST use comma separated list of explicit tab positions\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+Instead of -t NUMBER or -t LIST, -NUMBER or -LIST may be used. With\n\
+no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/uniq.c b/src/uniq.c
index 6ba6b6869..5cbd4df60 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -160,7 +160,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
}
@@ -171,7 +171,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (optind >= 2 && strcmp (argv[optind - 1], "--") != 0)
{
@@ -188,7 +188,7 @@ main (argc, argv)
outfile = argv[optind++];
if (optind < argc)
- usage (); /* Extra arguments. */
+ usage (1); /* Extra arguments. */
check_file (infile, outfile);
@@ -345,13 +345,35 @@ writeline (line, stream, linecount)
}
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-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] [--help] [--version] [infile] [outfile]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [INPUT [OUTPUT]]\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -c, --count prefix lines by the number of occurrences\n\
+ -d, --repeated only print duplicate lines\n\
+ -f, --skip-fields N avoid comparing the N first fields\n\
+ -s, --skip-chars N avoid comparing the N first characters\n\
+ -u, --unique only print unique lines\n\
+ -w, --check-chars N compare no more then N characters in lines\n\
+ -N same as -f N\n\
+ +N same as -s N\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+A field is a run of whitespace, than non whitespace characters.\n\
+Fields are skipped before chars. If OUTPUT not specified, writes to\n\
+standard output. If INPUT not specified, reads from standard input.\n\
+");
+ }
+ exit (status);
}
diff --git a/src/wc.c b/src/wc.c
index 6dce78241..6625b59f0 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -77,13 +77,31 @@ static struct option const longopts[] =
};
static void
-usage ()
+usage (status)
+ int status;
{
- fprintf (stderr, "\
-Usage: %s [-clw] [--bytes] [--chars] [--lines] [--words]\n\
- [--help] [--version] [file...]\n",
- program_name);
- exit (1);
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION]... [FILE]...\n\
+",
+ program_name);
+ printf ("\
+\n\
+ -c, --bytes, --chars print the byte counts\n\
+ -l, --lines print the newline counts\n\
+ -w, --words print the word counts\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+\n\
+Print lines, words and bytes in that order. If none of -clw, select\n\
+them all. With no FILE, or when FILE is -, read standard input.\n\
+");
+ }
+ exit (status);
}
void
@@ -118,7 +136,7 @@ main (argc, argv)
break;
default:
- usage ();
+ usage (1);
}
if (show_version)
@@ -128,7 +146,7 @@ main (argc, argv)
}
if (show_help)
- usage ();
+ usage (0);
if (print_lines + print_words + print_chars == 0)
print_lines = print_words = print_chars = 1;