Hit sort(1) with a hammer till it compiles.

Also add RCSIDs.
This commit is contained in:
bjh21 2000-10-07 18:37:09 +00:00
parent 0b6e7eef69
commit 6029888a3a
14 changed files with 136 additions and 78 deletions

View File

@ -1,4 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $NetBSD: Makefile,v 1.2 2000/10/07 18:37:09 bjh21 Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= sort
SRCS= append.c fields.c files.c fsort.c init.c msort.c sort.c tmp.c

View File

@ -1,3 +1,5 @@
/* $NetBSD: append.c,v 1.2 2000/10/07 18:37:09 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,12 +36,13 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)append.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "sort.h"
#ifndef lint
__RCSID("$NetBSD: append.c,v 1.2 2000/10/07 18:37:09 bjh21 Exp $");
__SCCSID("@(#)append.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <stdlib.h>
#include <string.h>
@ -61,7 +64,7 @@ static char sccsid[] = "@(#)append.c 8.1 (Berkeley) 6/6/93";
*/
void
append(keylist, nelem, depth, fd, put, ftbl)
u_char **keylist;
const u_char **keylist;
int nelem;
register int depth;
FILE *fd;
@ -69,9 +72,9 @@ append(keylist, nelem, depth, fd, put, ftbl)
struct field *ftbl;
{
register u_char *wts, *wts1;
register n, odepth;
register u_char **cpos, **ppos, **lastkey;
register u_char *cend, *pend, *start;
register int n, odepth;
register const u_char **cpos, **ppos, **lastkey;
register const u_char *cend, *pend, *start;
register struct recheader *crec, *prec;
if (*keylist == '\0' && UNIQUE)

View File

@ -1,3 +1,5 @@
/* $NetBSD: extern.h,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -36,15 +38,18 @@
* @(#)extern.h 8.1 (Berkeley) 6/6/93
*/
void append __P((u_char **, int, int, FILE *, void (*)(), struct field *));
void append __P((const u_char **, int, int, FILE *,
void (*)(RECHEADER *, FILE *), struct field *));
void concat __P((FILE *, FILE *));
length_t enterkey __P((struct recheader *,
DBT *, int, struct field *));
void fixit __P((int *, char **));
void fldreset __P((struct field *));
FILE *ftmp __P((void));
void fmerge __P((int, union f_handle,
int, int (*)(), FILE *, void (*)(), struct field *));
void fmerge __P((int, union f_handle, int,
int (*)(int, union f_handle, int, struct recheader *, u_char *,
struct field *), FILE *, void (*)(struct recheader *, FILE *),
struct field *));
void fsort __P((int, int, union f_handle, int, FILE *, struct field *));
int geteasy __P((int, union f_handle,
int, struct recheader *, u_char *, struct field *));
@ -54,11 +59,16 @@ int makekey __P((int, union f_handle,
int, struct recheader *, u_char *, struct field *));
int makeline __P((int, union f_handle,
int, struct recheader *, u_char *, struct field *));
void merge __P((int, int, int (*)(), FILE *, void (*)(), struct field *));
void merge __P((int, int,
int (*)(int, union f_handle, int, struct recheader *, u_char *,
struct field *), FILE *, void (*)(struct recheader *, FILE *),
struct field *));
void num_init __P((void));
void onepass __P((u_char **, int, long, long *, u_char *, FILE *));
void onepass __P((const u_char **, int, long, long *, u_char *, FILE *));
int optval __P((int, int));
void order __P((union f_handle, int (*)(), struct field *));
void order __P((union f_handle,
int (*)(int, union f_handle, int, struct recheader *, u_char *,
struct field *), struct field *));
void putline __P((struct recheader *, FILE *));
void putrec __P((struct recheader *, FILE *));
void rd_append __P((int, union f_handle, int, FILE *, u_char *, u_char *));

View File

@ -1,3 +1,5 @@
/* $NetBSD: fields.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,14 +36,15 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)fields.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
/* Subroutines to generate sort keys. */
#include "sort.h"
#ifndef lint
__RCSID("$NetBSD: fields.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#define blancmange(ptr) { \
if (BLANK & d_mask[*(ptr)]) \
while (BLANK & d_mask[*(++(ptr))]); \

View File

@ -1,3 +1,5 @@
/* $NetBSD: files.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,13 +36,14 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)files.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "sort.h"
#include "fsort.h"
#ifndef lint
__RCSID("$NetBSD: files.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)files.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <string.h>
/*
@ -194,7 +197,7 @@ makekey(flno, filelist, nfiles, buffer, bufend, ftbl)
u_char *bufend;
struct field *ftbl;
{
static int (*get)();
static int (*get) __P((FILE *, DBT *, DBT *));
static int fileno = 0;
static FILE *dbdesc = 0;
static DBT dbkey[1], line[1];

View File

@ -1,3 +1,5 @@
/* $NetBSD: fsort.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,10 +36,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)fsort.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
/*
* Read in the next bin. If it fits in one segment sort it;
* otherwise refine it by segment deeper by one character,
@ -48,10 +46,16 @@ static char sccsid[] = "@(#)fsort.c 8.1 (Berkeley) 6/6/93";
#include "sort.h"
#include "fsort.h"
#ifndef lint
__RCSID("$NetBSD: fsort.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <stdlib.h>
#include <string.h>
u_char **keylist = 0, *buffer = 0, *linebuf = 0;
const u_char **keylist = 0;
u_char *buffer = 0, *linebuf = 0;
struct tempfile fstack[MAXFCT];
extern char *toutpath;
#define FSORTMAX 4
@ -64,7 +68,8 @@ fsort(binno, depth, infiles, nfiles, outfd, ftbl)
FILE *outfd;
register struct field *ftbl;
{
register u_char *bufend, **keypos, *tmpbuf;
register const u_char **keypos;
register u_char *bufend, *tmpbuf;
u_char *weights;
int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0;
register int c, nelem;
@ -238,19 +243,19 @@ fsort(binno, depth, infiles, nfiles, outfd, ftbl)
#define swap(a, b, t) t = a, a = b, b = t
void
onepass(a, depth, n, sizes, tr, fd)
u_char **a;
const u_char **a;
int depth;
long n, sizes[];
u_char *tr;
FILE *fd;
{
long tsizes[NBINS+1];
u_char **bin[257], **top[256], ***bp, ***bpmax, ***tp;
static histo[256];
const u_char **bin[257], ***bp, ***bpmax, **top[256], ***tp;
static int histo[256];
int *hp;
register int c;
u_char **an, *t, **aj;
register u_char **ak, *r;
const u_char **an, *t, **aj;
register const u_char **ak, *r;
memset(tsizes, 0, sizeof(tsizes));
depth += sizeof(TRECHEADER);

View File

@ -1,3 +1,5 @@
/* $NetBSD: fsort.h,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -43,7 +45,8 @@
#define MAXFCT 1000
#define MAXLLEN ((1 << min(POW-4, 16)) - 14)
extern u_char **keylist, **l2buf, *buffer, *linebuf;
extern const u_char **keylist, **l2buf;
extern u_char *buffer, *linebuf;
/* temp files in the stack have a file descriptor, a largest bin (maxb)
* which becomes the last non-empty bin (lastb) when the actual largest

View File

@ -1,3 +1,5 @@
/* $NetBSD: init.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,15 +36,20 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "sort.h"
#ifndef lint
__RCSID("$NetBSD: init.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)init.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <ctype.h>
#include <string.h>
static void insertcol __P((struct field *));
char *setcolumn __P((char *, struct field *, int));
int setfield __P((char *, struct field *, int));
extern struct coldesc clist[(ND+1)*2];
extern int ncols;
u_char gweights[NBINS];
@ -129,7 +136,7 @@ setcolumn(pos, cur_fld, gflag)
errx(2, "illegal offset");
}
if (optval(*pos, cur_fld->tcol.num))
while (tmp = optval(*pos, cur_fld->tcol.num)) {
while ((tmp = optval(*pos, cur_fld->tcol.num))) {
cur_fld->flags |= tmp;
pos++;
}
@ -146,7 +153,7 @@ setfield(pos, cur_fld, gflag)
{
static int nfields = 0;
int tmp;
char *setcolumn();
char *setcolumn __P((char *, struct field *, int));
if (++nfields == ND)
errx(2, "too many sort keys. (Limit is %d)", ND-1);
cur_fld->weights = ascii;
@ -243,7 +250,7 @@ fixit(argc, argv)
if (*tpos == '.') {
tpos += sscanf(++tpos, "%d", &x);
while (isdigit(*tpos))
*tpos++;
tpos++;
}
if (x) {
vpos += sprintf(vpos, "%d", w+1);

View File

@ -1,3 +1,5 @@
/* $NetBSD: msort.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,13 +36,14 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)msort.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "sort.h"
#include "fsort.h"
#ifndef lint
__RCSID("$NetBSD: msort.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)msort.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -69,15 +72,15 @@ void
fmerge(binno, files, nfiles, get, outfd, fput, ftbl)
union f_handle files;
int binno, nfiles;
int (*get)();
int (*get) __P((int, union f_handle, int, struct recheader *, u_char *,
struct field *));
FILE *outfd;
void (*fput)();
void (*fput) __P((struct recheader *, FILE *));
struct field *ftbl;
{
FILE *tout;
int i, j, last;
void (*put)(struct recheader *, FILE *);
extern int geteasy();
struct tempfile *l_fstack;
wts = ftbl->weights;
@ -137,7 +140,8 @@ fmerge(binno, files, nfiles, get, outfd, fput, ftbl)
void
merge(infl0, nfiles, get, outfd, put, ftbl)
int infl0, nfiles;
int (*get)();
int (*get) __P((int, union f_handle, int, struct recheader *, u_char *,
struct field *));
void (*put)(struct recheader *, FILE *);
FILE *outfd;
struct field *ftbl;
@ -245,7 +249,8 @@ insert(flist, rec, ttop, delete)
void
order(infile, get, ftbl)
union f_handle infile;
int (*get)();
int (*get) __P((int, union f_handle, int, struct recheader *, u_char *,
struct field *));
struct field *ftbl;
{
u_char *end;
@ -285,7 +290,7 @@ static int
cmp(rec1, rec2)
struct recheader *rec1, *rec2;
{
register r;
register int r;
register u_char *pos1, *pos2, *end;
register u_char *cwts;
for (cwts = wts; cwts; cwts = (cwts == wts1 ? 0 : wts1)) {
@ -296,7 +301,7 @@ cmp(rec1, rec2)
else
end = pos1 + min(rec1->length, rec2->length);
for (; pos1 < end; ) {
if (r = cwts[*pos1++] - cwts[*pos2++])
if ((r = cwts[*pos1++] - cwts[*pos2++]))
return (r);
}
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: pathnames.h,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.

View File

@ -1,3 +1,5 @@
.\" $NetBSD: sort.1,v 1.2 2000/10/07 18:37:10 bjh21 Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@ -198,13 +200,14 @@ and
.Pp
The following operands are available:
.Bl -tag -width indent
.Ar file
.It Ar file
The pathname of a file to be sorted, merged, or checked.
If no file
operands are specified, or if
a file operand is
.Fl ,
the standard input is used.
.El
.Pp
A field is
defined as a minimal sequence of characters followed by a
@ -329,6 +332,7 @@ on disorder (or non-uniqueness) with the
option
.It Pa 2:
an error occurred.
.El
.Sh BUGS
Lines longer than 65522 characters are discarded and processing continues.
To sort files larger than 60Mb, use

View File

@ -1,3 +1,5 @@
/* $NetBSD: sort.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,16 +36,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)sort.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
/* Sort sorts a file using an optional user-defined key.
* Sort uses radix sort for internal sorting, and allows
* a choice of merge sort and radix sort for external sorting.
@ -53,6 +45,16 @@ static char sccsid[] = "@(#)sort.c 8.1 (Berkeley) 6/6/93";
#include "fsort.h"
#include "pathnames.h"
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
__RCSID("$NetBSD: sort.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)sort.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <paths.h>
#include <signal.h>
#include <stdlib.h>
@ -81,9 +83,11 @@ char devstdin[] = _PATH_STDIN;
char toutpath[_POSIX_PATH_MAX];
static void cleanup __P((void));
static void onsig __P((int));
static void onsignal __P((int));
static void usage __P((char *));
int main __P((int argc, char **argv));
int
main(argc, argv)
int argc;
@ -91,7 +95,8 @@ main(argc, argv)
{
extern int optind;
extern char *optarg;
int (*get)();
int (*get) __P((int, union f_handle, int, struct recheader *, u_char *,
struct field *));
int ch, i, stdinflag = 0, tmp = 0;
char cflag = 0, mflag = 0, nflag = 0;
char *outfile, *outpath = 0;
@ -137,8 +142,8 @@ main(argc, argv)
SEP_FLAG = 1;
d_mask[' '] &= ~FLD_D;
d_mask['\t'] &= ~FLD_D;
d_mask[*optarg] |= FLD_D;
if (d_mask[*optarg] & REC_D_F)
d_mask[(u_char)*optarg] |= FLD_D;
if (d_mask[(u_char)*optarg] & REC_D_F)
err(2, "record/field delimiter clash");
break;
case 'T':
@ -183,7 +188,7 @@ main(argc, argv)
stdinflag = 1;
argv[i] = devstdin;
}
} else if (ch = access(argv[i], R_OK))
} else if ((ch = access(argv[i], R_OK)))
err(2, "%s", argv[i]);
}
if (!(fldtab->flags & (I|D) || fldtab[1].icol.num)) {
@ -219,13 +224,14 @@ main(argc, argv)
outfile = outpath = toutpath;
} else if (!(ch = access(outpath, 0)) &&
strncmp(_PATH_DEV, outpath, 5)) {
struct sigaction act = {0, SIG_BLOCK, 6};
struct sigaction act = {0};
int sigtable[] = {SIGHUP, SIGINT, SIGPIPE, SIGXCPU, SIGXFSZ,
SIGVTALRM, SIGPROF, 0};
errno = 0;
if (access(outpath, W_OK))
err(2, "%s", outpath);
act.sa_handler = cleanup;
act.sa_handler = onsignal;
act.sa_flags = SA_RESTART | SA_RESETHAND;
(void)snprintf(toutpath, sizeof(toutpath), "%sXXXX", outpath);
outfile = mktemp(toutpath);
if (!outfile)
@ -253,11 +259,10 @@ main(argc, argv)
}
static void
onsig(s)
int s;
onsignal(sig)
int sig;
{
cleanup();
exit(2); /* return 2 on error/interrupt */
}
static void

View File

@ -1,3 +1,5 @@
/* $NetBSD: sort.h,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -70,7 +72,7 @@
#define FCLOSE(file) { \
if (EOF == fclose(file)) \
err(2, "%s", file); \
err(2, "%p", file); \
}
#define EWRITE(ptr, size, n, f) { \

View File

@ -1,3 +1,5 @@
/* $NetBSD: tmp.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@ -34,8 +36,11 @@
* SUCH DAMAGE.
*/
#include "sort.h"
#ifndef lint
static char sccsid[] = "@(#)tmp.c 8.1 (Berkeley) 6/6/93";
__RCSID("$NetBSD: tmp.c,v 1.2 2000/10/07 18:37:10 bjh21 Exp $");
__SCCSID("@(#)tmp.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
#include <sys/param.h>
@ -77,7 +82,7 @@ ftmp()
(void)sigprocmask(SIG_BLOCK, &set, &oset);
path = mktemp(path);
if (!path)
err(2, "%s");
err(2, NULL);
if (!(fd = fopen(path, "w+")))
err(2, "%s", path);
(void)unlink(path);