void free ();
#endif
-static void usage ();
-
/* Undefine, to avoid warning about redefinition on some systems. */
#undef min
#define min(a, b) ((a) < (b) ? (a) : (b))
struct keyfield *next; /* Next keyfield to try. */
} keyhead;
+static void
+usage (int status)
+{
+ if (status != 0)
+ fprintf (stderr, _("Try `%s --help' for more information.\n"),
+ program_name);
+ else
+ {
+ printf (_("\
+Usage: %s [OPTION]... [FILE]...\n\
+"),
+ program_name);
+ printf (_("\
+Write sorted concatenation of all FILE(s) to standard output.\n\
+\n\
+ +POS1 [-POS2] start a key at POS1, end it before POS2\n\
+ -M compare (unknown) < `JAN' < ... < `DEC', imply -b\n\
+ -T DIRECT use DIRECT for temporary files, not $TMPDIR or %s\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\
+")
+ , DEFAULT_TMPDIR);
+ }
+ exit (status);
+}
+
/* The list of temporary files. */
static struct tempnode
{
/* Clean up any remaining temporary files. */
static void
-cleanup ()
+cleanup (void)
{
struct tempnode *node;
/* Allocate N bytes of memory dynamically, with error checking. */
char *
-xmalloc (n)
- unsigned n;
+xmalloc (unsigned int n)
{
char *p;
If N is 0, run free and return NULL. */
char *
-xrealloc (p, n)
- char *p;
- unsigned n;
+xrealloc (char *p, unsigned int n)
{
if (p == 0)
return xmalloc (n);
}
static FILE *
-xfopen (file, how)
- char *file, *how;
+xfopen (char *file, char *how)
{
FILE *fp = strcmp (file, "-") ? fopen (file, how) : stdin;
}
static void
-xfclose (fp)
- FILE *fp;
+xfclose (FILE *fp)
{
if (fp == stdin)
{
}
static void
-xfwrite (buf, size, nelem, fp)
- char *buf;
- int size, nelem;
- FILE *fp;
+xfwrite (const char *buf, int size, int nelem, FILE *fp)
{
if (fwrite (buf, size, nelem, fp) != nelem)
{
/* Return a name for a temporary file. */
static char *
-tempname ()
+tempname (void)
{
static unsigned int seq;
int len = strlen (temp_file_prefix);
remove it if it is found on the list. */
static void
-zaptemp (name)
- char *name;
+zaptemp (char *name)
{
struct tempnode *node, *temp;
/* Initialize the character class tables. */
static void
-inittables ()
+inittables (void)
{
int i;
/* Initialize BUF, allocating ALLOC bytes initially. */
static void
-initbuf (buf, alloc)
- struct buffer *buf;
- int alloc;
+initbuf (struct buffer *buf, int alloc)
{
buf->alloc = alloc;
buf->buf = xmalloc (buf->alloc);
of bytes buffered. */
static int
-fillbuf (buf, fp)
- struct buffer *buf;
- FILE *fp;
+fillbuf (struct buffer *buf, FILE *fp)
{
int cc;
for, ever. */
static void
-initlines (lines, alloc, limit)
- struct lines *lines;
- int alloc;
- int limit;
+initlines (struct lines *lines, int alloc, int limit)
{
lines->alloc = alloc;
lines->lines = (struct line *) xmalloc (lines->alloc * sizeof (struct line));
by KEY in LINE. */
static char *
-begfield (line, key)
- struct line *line;
- struct keyfield *key;
+begfield (const struct line *line, const struct keyfield *key)
{
register char *ptr = line->text, *lim = ptr + line->length;
register int sword = key->sword, schar = key->schar;
in LINE specified by KEY. */
static char *
-limfield (line, key)
- struct line *line;
- struct keyfield *key;
+limfield (const struct line *line, const struct keyfield *key)
{
register char *ptr = line->text, *lim = ptr + line->length;
register int eword = key->eword, echar = key->echar;
}
/* Find the lines in BUF, storing pointers and lengths in LINES.
- Also replace newlines with NULs. */
+ Also replace newlines in BUF with NULs. */
static void
-findlines (buf, lines)
- struct buffer *buf;
- struct lines *lines;
+findlines (struct buffer *buf, struct lines *lines)
{
register char *beg = buf->buf, *lim = buf->buf + buf->used, *ptr;
struct keyfield *key = keyhead.next;
of the fraction. Strings not of this form are considered to be zero. */
static int
-fraccompare (a, b)
- register char *a, *b;
+fraccompare (register const char *a, register const char *b)
{
register tmpa = UCHAR (*a), tmpb = UCHAR (*b);
hideously fast. */
static int
-numcompare (a, b)
- register char *a, *b;
+numcompare (register const char *a, register const char *b)
{
register int tmpa, tmpb, loga, logb, tmp;
0 if the name in S is not recognized. */
static int
-getmonth (s, len)
- char *s;
- int len;
+getmonth (const char *s, int len)
{
char month[4];
register int i, lo = 0, hi = 12;
are no more keys or a difference is found. */
static int
-keycompare (a, b)
- struct line *a, *b;
+keycompare (const struct line *a, const struct line *b)
{
register char *texta, *textb, *lima, *limb, *translate;
register int *ignore;
depending on whether A compares less than, equal to, or greater than B. */
static int
-compare (a, b)
- register struct line *a, *b;
+compare (register const struct line *a, register const struct line *b)
{
int diff, tmpa, tmpb, mini;
FIXME: return number of first out-of-order line if not sorted. */
static int
-checkfp (fp)
- FILE *fp;
+checkfp (FILE *fp)
{
struct buffer buf; /* Input buffer. */
struct lines lines; /* Lines scanned from the buffer. */
Close FPS before returning. */
static void
-mergefps (fps, nfps, ofp)
- FILE *fps[], *ofp;
- register int nfps;
+mergefps (FILE **fps, register int nfps, FILE *ofp)
{
struct buffer buffer[NMERGE]; /* Input buffers for each file. */
struct lines lines[NMERGE]; /* Line tables for each buffer. */
/* Sort the array LINES with NLINES members, using TEMP for temporary space. */
static void
-sortlines (lines, nlines, temp)
- struct line *lines, *temp;
- int nlines;
+sortlines (struct line *lines, int nlines, struct line *temp)
{
register struct line *lo, *hi, *t;
register int nlo, nhi;
Return a count of disordered files. */
static int
-check (files, nfiles)
- char *files[];
- int nfiles;
+check (char **files, int nfiles)
{
int i, disorders = 0;
FILE *fp;
/* Merge NFILES FILES onto OFP. */
static void
-merge (files, nfiles, ofp)
- char *files[];
- int nfiles;
- FILE *ofp;
+merge (char **files, int nfiles, FILE *ofp)
{
int i, j, t;
char *temp;
/* Sort NFILES FILES onto OFP. */
static void
-sort (files, nfiles, ofp)
- char **files;
- int nfiles;
- FILE *ofp;
+sort (char **files, int nfiles, FILE *ofp)
{
struct buffer buf;
struct lines lines;
/* Insert key KEY at the end of the list (`keyhead'). */
static void
-insertkey (key)
- struct keyfield *key;
+insertkey (struct keyfield *key)
{
struct keyfield *k = &keyhead;
}
static void
-badfieldspec (s)
- char *s;
+badfieldspec (const char *s)
{
error (2, 0, _("invalid field specification `%s'"), s);
}
/* Handle interrupts and hangups. */
static void
-sighandler (sig)
- int sig;
+sighandler (int sig)
{
#ifdef SA_INTERRUPT
struct sigaction sigact;
BLANKTYPE is the kind of blanks that 'b' should skip. */
static char *
-set_ordering (s, key, blanktype)
- register char *s;
- struct keyfield *key;
- enum blanktype blanktype;
+set_ordering (register const char *s, struct keyfield *key,
+ enum blanktype blanktype)
{
while (*s)
{
key->reverse = 1;
break;
default:
- return s;
+ return (char *) s;
}
++s;
}
- return s;
+ return (char *) s;
}
void
-main (argc, argv)
- int argc;
- char *argv[];
+main (int argc, char **argv)
{
struct keyfield *key = NULL, gkey;
char *s;
exit (0);
}
-
-static void
-usage (status)
- int status;
-{
- if (status != 0)
- fprintf (stderr, _("Try `%s --help' for more information.\n"),
- program_name);
- else
- {
- printf (_("\
-Usage: %s [OPTION]... [FILE]...\n\
-"),
- program_name);
- printf (_("\
-Write sorted concatenation of all FILE(s) to standard output.\n\
-\n\
- +POS1 [-POS2] start a key at POS1, end it before POS2\n\
- -M compare (unknown) < `JAN' < ... < `DEC', imply -b\n\
- -T DIRECT use DIRECT for temporary files, not $TMPDIR or %s\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\
-")
- , DEFAULT_TMPDIR);
- }
- exit (status);
-}