#include <sys/ioctl.h>
#endif
#include "system.h"
+#include "version.h"
#define max(h,i) ((h) > (i) ? (h) : (i))
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);
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 flag_help;
+
+ /* If non-zero, print the version on standard error. */
+ static int flag_version;
+
static struct option const long_options[] =
{
{"number-nonblank", no_argument, NULL, 'b'},
{"show-ends", no_argument, NULL, 'E'},
{"show-tabs", no_argument, NULL, 'T'},
{"show-all", no_argument, NULL, 'A'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
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;
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
output_desc = 1;
/* Get device, i-node number, and optimal blocksize of output. */
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)
{
#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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
+static struct option const long_options[] =
+{
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {0, 0, 0, 0}
+};
+
static unsigned long const crctab[256] =
{
0x0,
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;
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 (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_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;
}
#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;
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
+static struct option const long_options[] =
+{
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {0, 0, 0, 0}
+};
void error ();
static int compare_files ();
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;
usage ();
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (optind + 2 != argc)
usage ();
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);
}
#include <signal.h>
#include "regex.h"
#include "system.h"
+#include "version.h"
#ifdef STDC_HEADERS
#include <stdlib.h>
struct buffer_record *next;
};
+/* The name this program was run with. */
+char *program_name;
+
/* Input file descriptor. */
static int input_desc = 0;
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {NULL, 0, NULL, 0}
+};
/* Allocate N bytes of memory dynamically, with error checking. */
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;
!= EOF)
switch (optc)
{
+ case 0:
+ break;
+
case 'f':
prefix = optarg;
break;
usage ();
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (optind >= argc - 1)
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);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
char *xmalloc ();
char *xrealloc ();
field_mode
};
+/* The name this program was run with. */
+char *program_name;
+
static enum operating_mode operating_mode;
/* If nonzero,
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
static struct option const longopts[] =
{
{"fields", required_argument, 0, 'f'},
{"delimiter", required_argument, 0, 'd'},
{"only-delimited", no_argument, 0, 's'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
{
switch (optc)
{
+ case 0:
+ break;
+
case 'b':
case 'c':
/* Build the byte list. */
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (operating_mode == undefined_mode)
usage ();
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);
}
#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. */
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;
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
static struct option const longopts[] =
{
{"tabs", required_argument, NULL, 't'},
{"initial", no_argument, NULL, 'i'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (c)
{
+ case 0:
+ break;
+
case '?':
usage ();
case 'i':
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
add_tabstop (tabval);
validate_tabstops (tab_list, first_free_tab);
{
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);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
char *xrealloc ();
void error ();
+/* The name this program was run with. */
+char *program_name;
+
static int adjust_column ();
static int fold_file ();
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
static struct option const longopts[] =
{
{"bytes", no_argument, NULL, 'b'},
{"spaces", no_argument, NULL, 's'},
{"width", required_argument, NULL, 'w'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
\f
+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;
{
switch (optc)
{
+ case 0:
+ break;
+
case 'b': /* Count bytes rather than columns. */
count_bytes = 1;
break;
break;
default:
- fprintf (stderr, "\
-Usage: %s [-bs] [-w width] [--bytes] [--spaces] [--width=width] [file...]\n",
- argv[0]);
- exit (1);
+ usage ();
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (argc == optind)
errs |= fold_file ("-", width);
else
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
/* Number of lines/chars/blocks to head. */
#define DEFAULT_NUMBER 10
/* Have we ever read standard input? */
static int have_read_stdin;
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
static struct option const long_options[] =
{
{"bytes", required_argument, NULL, 'c'},
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (c)
{
+ case 0:
+ break;
+
case 'c':
unit_size = 1;
parse_unit (optarg);
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (number == -1)
number = DEFAULT_NUMBER;
{
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);
}
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
+#include "version.h"
char *xmalloc ();
char *xrealloc ();
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;
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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {NULL, 0, NULL, 0}
+};
/* Fill in the `fields' structure in LINE. */
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;
{
switch (optc)
{
+ case 0:
+ break;
+
case 'a':
val = atoi (optarg);
if (val == 1)
}
prev_optc = optc;
}
+
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
if (nfiles != 2)
usage ();
#include <regex.h>
#include "linebuffer.h"
#include "system.h"
+#include "version.h"
#ifndef TRUE
#define TRUE 1
{
Header, Body, Footer, Text
};
-\f
+
+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";
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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 ();
-\f
static struct option const longopts[] =
{
{"header-numbering", required_argument, NULL, 'h'},
{"number-width", required_argument, NULL, 'w'},
{"number-format", required_argument, NULL, 'n'},
{"section-delimiter", required_argument, NULL, 'd'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (c)
{
+ case 0:
+ break;
+
case 'h':
if (build_type_arg (&header_type, &header_regex) != TRUE)
usage ();
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
/* Initialize the section delimiters. */
c = strlen (section_del);
[--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);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
#if defined(__GNUC__) || defined(STDC_HEADERS)
#include <float.h>
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)
required to represent the same quantity in the specified base/type.
#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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
static struct option const long_options[] =
{
/* POSIX options. */
{"compatible", no_argument, NULL, 'C'},
{"strings", optional_argument, NULL, 's'},
{"width", optional_argument, NULL, 'w'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
-/* The name this program was run with. */
-char *program_name;
-
static void
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);
}
switch (c)
{
+ case 0:
+ break;
+
case 'A':
switch (optarg[0])
{
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (flag_dump_strings && n_specs > 0)
error (2, 0, "no type may be specified when dumping strings");
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
void error ();
char *xmalloc ();
/* A pointer to the character after the end of `delims'. */
static char *delim_end;
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
static struct option const longopts[] =
{
{"serial", no_argument, 0, 's'},
{"delimiters", required_argument, 0, 'd'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
{
switch (optc)
{
+ case 0:
+ break;
+
case 'd':
/* Delimiter character(s). */
if (optarg[0] == '\0')
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (optind == argc)
argv[argc++] = "-";
{
fprintf (stderr, "\
Usage: %s [-s] [-d delim-list] [--serial] [--delimiters=delim-list]\n\
- [file...]\n",
+ [--help] [--version] [file...]\n",
program_name);
exit (1);
}
#include <sys/types.h>
#include <time.h>
#include "system.h"
+#include "version.h"
char *xmalloc ();
char *xrealloc ();
#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;
/* (-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;
/* 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;
-\f
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
+static struct option const long_options[] =
+{
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {0, 0, 0, 0}
+};
+
void
main (argc, argv)
int argc;
char **argv;
{
int c;
- char *s;
- int files = 0;
- char **file_names, **file_name_vector;
int accum = 0;
program_name = argv[0];
- file_name_vector = (char **) xmalloc (argc * sizeof (char **));
- file_names = file_name_vector;
-
- for (;;)
+ while ((c = getopt_long (argc, argv,
+ "0123456789abcde::fFh:i::l:mn::o:rs::tvw:",
+ long_options, (int *) 0)) != EOF)
{
- c = getopt (argc, argv, "-0123456789abcde::fFh:i::l:mn::o:rs::tvw:");
-
- if (c == 1) /* Non-option argument. */
- {
- s = optarg;
- if (*s == '+')
- {
- ++s;
- if (!ISDIGIT (*s))
- usage ("`+' requires a numeric argument");
- first_page_number = atoi (s);
- }
- else
- {
- *file_names++ = optarg;
- ++files;
- }
- }
- 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';
switch (c)
{
+ case 0: /* getopt long option */
+ break;
+
case 'a':
print_across_flag = TRUE;
storing_columns = FALSE;
use_column_separator = TRUE;
if (optarg)
{
+ char *s;
s = optarg;
column_separator = *s;
if (*++s)
fprintf (stderr, "\
%s: extra characters in the argument to the `-s' option: `%s'\n",
program_name, s);
- usage ((char *) 0);
+ usage ();
}
}
break;
case 'w':
chars_per_line = atoi (optarg);
break;
- case '?':
- usage ((char *) 0);
+ default:
+ usage ();
break;
}
+ }
+
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_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.");
+
+ if (optind >= 2 && strcmp (argv[optind - 1], "--") == 0)
+ {
+ /* We've seen `--', so interpret all remaining arguments as
+ filenames. */
+ }
+ else
+ {
+ for ( ; optind < argc && argv[optind][0] == '+'; optind++)
+ {
+ first_page_number = atoi (&argv[optind][1]);
+ }
+ }
- if (c == EOF)
- break;
+ if (optind >= argc)
+ {
+ /* No file arguments specified; read from standard input. */
+ print_files (0, (char **) 0);
+ }
+ else
+ {
+ if (parallel_files)
+ print_files (argc - optind, &argv[optind]);
+ else
+ {
+ for ( ; optind < argc; optind++)
+ print_files (1, &argv[optind]);
+ }
}
- if (input_is_stdin)
- print_files (0, (char **) 0);
+ cleanup ();
if (have_read_stdin && fclose (stdin) == EOF)
error (1, errno, "standard input");
fprintf (stderr, "\
%s: extra characters in the argument to the `-%c' option: `%s'\n",
program_name, switch_char, arg);
- usage ((char *) 0);
+ usage ();
}
}
}
/* 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);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
char *xmalloc ();
void error ();
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. */
/* Descriptor on which output file is open. */
static int output_desc;
-\f
+
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {NULL, 0, NULL, 0}
+};
+
static void
usage (reason)
char *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);
}
-\f
-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)
switch (c)
{
+ case 0:
+ break;
+
case 'b':
if (split_type != type_undef)
usage ("cannot split in more than one way");
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
/* Handle default case. */
if (split_type == type_undef)
{
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
+#include "version.h"
static int bsd_sum_file ();
static int sysv_sum_file ();
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
static struct option const longopts[] =
{
{"sysv", no_argument, NULL, 's'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_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;
{
switch (optc)
{
+ case 0:
+ break;
+
case 'r': /* For SysV compatibility. */
sum_func = bsd_sum_file;
break;
sum_func = sysv_sum_file;
break;
- case '?':
- fprintf (stderr, "\
-Usage: %s [-rs] [--sysv] [file...]\n", argv[0]);
- exit (1);
+ default:
+ usage ();
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
files_given = argc - optind;
if (files_given == 0)
{
#include <signal.h>
#include <regex.h>
#include "system.h"
+#include "version.h"
#ifndef STDC_HEADERS
char *malloc ();
/* The compiled regular expression representing `separator'. */
static struct re_pattern_buffer compiled_separator;
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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, &flag_help, 1},
+ {"version", no_argument, &flag_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;
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 (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (sentinel_length == 0)
{
compiled_separator.allocated = 100;
#include <sys/types.h>
#include <signal.h>
#include "system.h"
+#include "version.h"
/* Number of items to tail. */
#define DEFAULT_NUMBER 10
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
static struct option const long_options[] =
{
{"bytes", required_argument, NULL, 'c'},
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (c)
{
+ case 0:
+ break;
+
case 'c':
unit_size = 1;
parse_unit (optarg);
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (number == -1)
number = DEFAULT_NUMBER;
{
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);
}
#include <sys/types.h>
#include "getopt.h"
#include "system.h"
+#include "version.h"
#ifndef LONG_MAX
#define LONG_MAX 0x7FFFFFFF
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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
\f
{
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);
}
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
posix_pedantic = (getenv ("POSIXLY_CORRECT") != NULL);
non_option_args = argc - optind;
#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. */
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;
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
static struct option const longopts[] =
{
{"tabs", required_argument, NULL, 't'},
{"all", no_argument, NULL, 'a'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
{
switch (c)
{
+ case 0:
+ break;
+
case '?':
usage ();
case 'a':
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
add_tabstop (tabval);
validate_tabstops (tab_list, first_free_tab);
{
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);
}
#include <sys/types.h>
#include "system.h"
#include "linebuffer.h"
+#include "version.h"
#define min(x, y) ((x) < (y) ? (x) : (y))
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;
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
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, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
\f
{
switch (optc)
{
+ case 0:
+ break;
+
case '0':
case '1':
case '2':
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
while (optind < argc && argv[optind][0] == '+')
skip_chars = atoi (argv[optind++]);
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);
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
/* Size of atomic reads. */
#define BUFFER_SIZE (16 * 1024)
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;
/* 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 flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_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, &flag_help, 1},
+ {"version", no_argument, &flag_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;
while ((optc = getopt_long (argc, argv, "clw", longopts, (int *) 0)) != EOF)
switch (optc)
{
+ case 0:
+ break;
+
case 'c':
print_chars = 1;
break;
break;
default:
- fprintf (stderr, "\
-Usage: %s [-clw] [--bytes] [--chars] [--lines] [--words] [file...]\n", argv[0]);
- exit (1);
+ usage ();
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (print_lines + print_words + print_chars == 0)
print_lines = print_words = print_chars = 1;