Module Name: src Committed By: dsl Date: Sat Aug 15 09:48:46 UTC 2009
Modified Files: src/usr.bin/sort: append.c fields.c files.c fsort.c init.c msort.c sort.c tmp.c Log Message: Ansify. I'm looking at fixing the 'sort -n' fubars, but this code is an inpeneterable mess - which needs some fixing first! To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/sort/append.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/sort/fields.c cvs rdiff -u -r1.27 -r1.28 src/usr.bin/sort/files.c cvs rdiff -u -r1.32 -r1.33 src/usr.bin/sort/fsort.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/sort/init.c src/usr.bin/sort/msort.c cvs rdiff -u -r1.48 -r1.49 src/usr.bin/sort/sort.c cvs rdiff -u -r1.13 -r1.14 src/usr.bin/sort/tmp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/sort/append.c diff -u src/usr.bin/sort/append.c:1.14 src/usr.bin/sort/append.c:1.15 --- src/usr.bin/sort/append.c:1.14 Mon Apr 28 20:24:15 2008 +++ src/usr.bin/sort/append.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: append.c,v 1.14 2008/04/28 20:24:15 martin Exp $ */ +/* $NetBSD: append.c,v 1.15 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: append.c,v 1.14 2008/04/28 20:24:15 martin Exp $"); +__RCSID("$NetBSD: append.c,v 1.15 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)append.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -91,13 +91,8 @@ * copy sorted lines to output; check for uniqueness */ void -append(keylist, nelem, depth, fp, put, ftbl) - const u_char **keylist; - int nelem; - int depth; - FILE *fp; - put_func_t put; - struct field *ftbl; +append(const u_char **keylist, int nelem, int depth, FILE *fp, put_func_t put, + struct field *ftbl) { u_char *wts, *wts1; int n, odepth = depth; @@ -192,12 +187,8 @@ * output the already sorted eol bin. */ void -rd_append(binno, infl0, nfiles, outfp, buffer, bufend) - u_char *buffer; - int infl0; - int binno, nfiles; - FILE *outfp; - u_char *bufend; +rd_append(int binno, int infl0, int nfiles, FILE *outfp, u_char *buffer, + u_char *bufend) { RECHEADER *rec; @@ -217,8 +208,7 @@ * append plain text--used after sorting the biggest bin. */ void -concat(a, b) - FILE *a, *b; +concat(FILE *a, FILE *b) { int nread; char buffer[4096]; Index: src/usr.bin/sort/fields.c diff -u src/usr.bin/sort/fields.c:1.20 src/usr.bin/sort/fields.c:1.21 --- src/usr.bin/sort/fields.c:1.20 Mon Apr 13 11:07:59 2009 +++ src/usr.bin/sort/fields.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fields.c,v 1.20 2009/04/13 11:07:59 lukem Exp $ */ +/* $NetBSD: fields.c,v 1.21 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: fields.c,v 1.20 2009/04/13 11:07:59 lukem Exp $"); +__RCSID("$NetBSD: fields.c,v 1.21 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -81,8 +81,8 @@ while ((*(pos+1) != '\0') && !((FLD_D | REC_D_F) & l_d_mask[*++pos]));\ } -static u_char *enterfield __P((u_char *, u_char *, struct field *, int)); -static u_char *number __P((u_char *, u_char *, u_char *, u_char *, int)); +static u_char *enterfield(u_char *, u_char *, struct field *, int); +static u_char *number(u_char *, u_char *, u_char *, u_char *, int); #define DECIMAL '.' #define OFFSET 128 @@ -97,11 +97,8 @@ * followed by the original line. */ length_t -enterkey(keybuf, line, size, fieldtable) - RECHEADER *keybuf; /* pointer to start of key */ - DBT *line; - int size; - struct field fieldtable[]; +enterkey(RECHEADER *keybuf, DBT *line, int size, struct field fieldtable[]) + /* keybuf: pointer to start of key */ { int i; u_char *l_d_mask; @@ -168,10 +165,7 @@ * constructs a field (as defined by -k) within a key */ static u_char * -enterfield(tablepos, endkey, cur_fld, gflags) - struct field *cur_fld; - u_char *tablepos, *endkey; - int gflags; +enterfield(u_char *tablepos, u_char *endkey, struct field *cur_fld, int gflags) { u_char *start, *end, *lineend, *mask, *lweight; struct column icol, tcol; @@ -239,9 +233,7 @@ */ static u_char * -number(pos, bufend, line, lineend, Rflag) - u_char *line, *pos, *bufend, *lineend; - int Rflag; +number(u_char *pos, u_char *bufend, u_char *line, u_char *lineend, int Rflag) { int or_sign, parity = 0; int expincr = 1, exponent = -1; @@ -342,7 +334,7 @@ * rnum over (0,254) -> (255,REC_D+1),(REC_D-1,0)) */ void -num_init() +num_init(void) { int i; TENS[0] = REC_D <=128 ? 130 - '0' : 2 - '0'; Index: src/usr.bin/sort/files.c diff -u src/usr.bin/sort/files.c:1.27 src/usr.bin/sort/files.c:1.28 --- src/usr.bin/sort/files.c:1.27 Mon Apr 13 11:07:59 2009 +++ src/usr.bin/sort/files.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: files.c,v 1.27 2009/04/13 11:07:59 lukem Exp $ */ +/* $NetBSD: files.c,v 1.28 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -65,26 +65,21 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: files.c,v 1.27 2009/04/13 11:07:59 lukem Exp $"); +__RCSID("$NetBSD: files.c,v 1.28 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)files.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ #include <string.h> -static int seq __P((FILE *, DBT *, DBT *)); +static int seq(FILE *, DBT *, DBT *); /* * this is the subroutine for file management for fsort(). * It keeps the buffers for all temporary files. */ int -getnext(binno, infl0, filelist, nfiles, pos, end, dummy) - int binno, infl0; - struct filelist *filelist; - int nfiles; - RECHEADER *pos; - u_char *end; - struct field *dummy; +getnext(int binno, int infl0, struct filelist *filelist, int nfiles, + RECHEADER *pos, u_char *end, struct field *dummy) { int i; u_char *hp; @@ -150,13 +145,8 @@ * in the first fsort pass. */ int -makeline(flno, top, filelist, nfiles, recbuf, bufend, dummy2) - int flno, top; - struct filelist *filelist; - int nfiles; - RECHEADER *recbuf; - u_char *bufend; - struct field *dummy2; +makeline(int flno, int top, struct filelist *filelist, int nfiles, + RECHEADER *recbuf, u_char *bufend, struct field *dummy2) { static u_char *obufend; static size_t osz; @@ -239,13 +229,8 @@ * This generates keys. It's only called in the first fsort pass */ int -makekey(flno, top, filelist, nfiles, recbuf, bufend, ftbl) - int flno, top; - struct filelist *filelist; - int nfiles; - RECHEADER *recbuf; - u_char *bufend; - struct field *ftbl; +makekey(int flno, int top, struct filelist *filelist, int nfiles, + RECHEADER *recbuf, u_char *bufend, struct field *ftbl) { static int filenum = 0; static FILE *dbdesc = 0; @@ -303,9 +288,7 @@ * get a key/line pair from fp */ static int -seq(fp, line, key) - FILE *fp; - DBT *key, *line; +seq(FILE *fp, DBT *line, DBT *key) { static u_char *buf, flag = 1; u_char *end, *pos; @@ -351,9 +334,7 @@ * write a key/line pair to a temporary file */ void -putrec(rec, fp) - const RECHEADER *rec; - FILE *fp; +putrec(const RECHEADER *rec, FILE *fp) { EWRITE(rec, 1, rec->length + sizeof(TRECHEADER), fp); } @@ -362,9 +343,7 @@ * write a line to output */ void -putline(rec, fp) - const RECHEADER *rec; - FILE *fp; +putline(const RECHEADER *rec, FILE *fp) { EWRITE(rec->data+rec->offset, 1, rec->length - rec->offset, fp); } @@ -373,13 +352,8 @@ * get a record from a temporary file. (Used by merge sort.) */ int -geteasy(flno, top, filelist, nfiles, rec, end, dummy2) - int flno, top; - struct filelist *filelist; - int nfiles; - RECHEADER *rec; - u_char *end; - struct field *dummy2; +geteasy(int flno, int top, struct filelist *filelist, int nfiles, + RECHEADER *rec, u_char *end, struct field *dummy2) { int i; FILE *fp; Index: src/usr.bin/sort/fsort.c diff -u src/usr.bin/sort/fsort.c:1.32 src/usr.bin/sort/fsort.c:1.33 --- src/usr.bin/sort/fsort.c:1.32 Mon Apr 28 20:24:15 2008 +++ src/usr.bin/sort/fsort.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fsort.c,v 1.32 2008/04/28 20:24:15 martin Exp $ */ +/* $NetBSD: fsort.c,v 1.33 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -72,7 +72,7 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: fsort.c,v 1.32 2008/04/28 20:24:15 martin Exp $"); +__RCSID("$NetBSD: fsort.c,v 1.33 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -95,12 +95,8 @@ #define SALIGN(n) ((n+sizeof(length_t)-1) & ~(sizeof(length_t)-1)) void -fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) - int binno, depth, top; - struct filelist *filelist; - int nfiles; - FILE *outfp; - struct field *ftbl; +fsort(int binno, int depth, int top, struct filelist *filelist, int nfiles, + FILE *outfp, struct field *ftbl) { const u_char **keypos; u_char *bufend; @@ -344,12 +340,7 @@ */ #define swap(a, b, t) t = a, a = b, b = t void -onepass(a, depth, n, sizes, tr, fp) - const u_char **a; - int depth; - long n, sizes[]; - u_char *tr; - FILE *fp; +onepass(const u_char **a, int depth, long n, long sizes[], u_char *tr, FILE *fp) { size_t tsizes[NBINS + 1]; const u_char **bin[257], ***bp, ***bpmax, **top[256], ***tp; Index: src/usr.bin/sort/init.c diff -u src/usr.bin/sort/init.c:1.18 src/usr.bin/sort/init.c:1.19 --- src/usr.bin/sort/init.c:1.18 Mon Apr 28 20:24:15 2008 +++ src/usr.bin/sort/init.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.18 2008/04/28 20:24:15 martin Exp $ */ +/* $NetBSD: init.c,v 1.19 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -64,15 +64,15 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: init.c,v 1.18 2008/04/28 20:24:15 martin Exp $"); +__RCSID("$NetBSD: init.c,v 1.19 2009/08/15 09:48:46 dsl 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 *)); -static const char *setcolumn __P((const char *, struct field *, int)); +static void insertcol(struct field *); +static const char *setcolumn(const char *, struct field *, int); u_char gweights[NBINS]; @@ -97,8 +97,7 @@ * keep clist in order--inserts a column in a sorted array */ static void -insertcol(field) - struct field *field; +insertcol(struct field *field) { int i; struct coldesc *p; @@ -134,8 +133,7 @@ * matches fields with the appropriate columns--n^2 but who cares? */ void -fldreset(fldtab) - struct field *fldtab; +fldreset(struct field *fldtab) { int i; @@ -156,10 +154,7 @@ * interprets a column in a -k field */ static const char * -setcolumn(pos, cur_fld, gflag) - const char *pos; - struct field *cur_fld; - int gflag; +setcolumn(const char *pos, struct field *cur_fld, int gflag) { struct column *col; char *npos; @@ -188,10 +183,7 @@ } int -setfield(pos, cur_fld, gflag) - const char *pos; - struct field *cur_fld; - int gflag; +setfield(const char *pos, struct field *cur_fld, int gflag) { int tmp; @@ -241,8 +233,7 @@ } int -optval(desc, tcolflag) - int desc, tcolflag; +optval(int desc, int tcolflag) { switch(desc) { case 'b': @@ -263,9 +254,7 @@ * Replace historic +SPEC arguments with appropriate -kSPEC. */ void -fixit(argc, argv) - int *argc; - char **argv; +fixit(int *argc, char **argv) { int i, j, fplus=0; char *vpos, *tpos, spec[20]; @@ -345,8 +334,7 @@ * all bets are off. See also num_init in number.c */ void -settables(gflags) - int gflags; +settables(int gflags) { u_char *wts; int i, incr; Index: src/usr.bin/sort/msort.c diff -u src/usr.bin/sort/msort.c:1.18 src/usr.bin/sort/msort.c:1.19 --- src/usr.bin/sort/msort.c:1.18 Mon Apr 28 20:24:15 2008 +++ src/usr.bin/sort/msort.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: msort.c,v 1.18 2008/04/28 20:24:15 martin Exp $ */ +/* $NetBSD: msort.c,v 1.19 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: msort.c,v 1.18 2008/04/28 20:24:15 martin Exp $"); +__RCSID("$NetBSD: msort.c,v 1.19 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)msort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -84,19 +84,13 @@ static u_char *wts, *wts1 = NULL; -static int cmp __P((RECHEADER *, RECHEADER *)); -static int insert __P((struct mfile **, struct mfile **, int, int)); +static int cmp(RECHEADER *, RECHEADER *); +static int insert(struct mfile **, struct mfile **, int, int); static void merge(int, int, get_func_t, FILE *, put_func_t, struct field *); void -fmerge(binno, top, filelist, nfiles, get, outfp, fput, ftbl) - int binno, top; - struct filelist *filelist; - int nfiles; - get_func_t get; - FILE *outfp; - put_func_t fput; - struct field *ftbl; +fmerge(int binno, int top, struct filelist *filelist, int nfiles, + get_func_t get, FILE *outfp, put_func_t fput, struct field *ftbl) { FILE *tout; int i, j, last; @@ -162,12 +156,8 @@ } static void -merge(infl0, nfiles, get, outfp, put, ftbl) - int infl0, nfiles; - get_func_t get; - put_func_t put; - FILE *outfp; - struct field *ftbl; +merge(int infl0, int nfiles, get_func_t get, FILE *outfp, put_func_t put, + struct field *ftbl) { int c, i, j, nf = nfiles; struct mfile *flistb[MERGE_FNUM], **flist = flistb, *cfile; @@ -275,9 +265,8 @@ * otherwise just inserts *rec in flist. */ static int -insert(flist, rec, ttop, delete) - struct mfile **flist, **rec; - int delete, ttop; /* delete = 0 or 1 */ +insert(struct mfile **flist, struct mfile **rec, int ttop, int delete) + /* delete, ttop: delete = 0 or 1 */ { struct mfile *tmprec = *rec; int mid, top = ttop, bot = 0, cmpv = 1; @@ -348,10 +337,7 @@ * check order on one file */ void -order(filelist, get, ftbl) - struct filelist *filelist; - get_func_t get; - struct field *ftbl; +order(struct filelist *filelist, get_func_t get, struct field *ftbl) { u_char *crec_end, *prec_end, *trec_end; int c; @@ -396,8 +382,7 @@ } static int -cmp(rec1, rec2) - RECHEADER *rec1, *rec2; +cmp(RECHEADER *rec1, RECHEADER *rec2) { int r; u_char *pos1, *pos2, *end; Index: src/usr.bin/sort/sort.c diff -u src/usr.bin/sort/sort.c:1.48 src/usr.bin/sort/sort.c:1.49 --- src/usr.bin/sort/sort.c:1.48 Mon Apr 13 11:07:59 2009 +++ src/usr.bin/sort/sort.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sort.c,v 1.48 2009/04/13 11:07:59 lukem Exp $ */ +/* $NetBSD: sort.c,v 1.49 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -76,7 +76,7 @@ #endif /* not lint */ #ifndef lint -__RCSID("$NetBSD: sort.c,v 1.48 2009/04/13 11:07:59 lukem Exp $"); +__RCSID("$NetBSD: sort.c,v 1.49 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)sort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -110,16 +110,14 @@ const char *tmpdir; /* where temporary files should be put */ -static void cleanup __P((void)); -static void onsignal __P((int)); -static void usage __P((const char *)); +static void cleanup(void); +static void onsignal(int); +static void usage(const char *); -int main __P((int argc, char **argv)); +int main(int argc, char **argv); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { get_func_t get; int ch, i, stdinflag = 0, tmp = 0; @@ -357,22 +355,20 @@ } static void -onsignal(sig) - int sig; +onsignal(int sig) { cleanup(); } static void -cleanup() +cleanup(void) { if (toutpath[0]) (void)unlink(toutpath); } static void -usage(msg) - const char *msg; +usage(const char *msg) { if (msg != NULL) (void)fprintf(stderr, "%s: %s\n", getprogname(), msg); Index: src/usr.bin/sort/tmp.c diff -u src/usr.bin/sort/tmp.c:1.13 src/usr.bin/sort/tmp.c:1.14 --- src/usr.bin/sort/tmp.c:1.13 Mon Apr 28 20:24:15 2008 +++ src/usr.bin/sort/tmp.c Sat Aug 15 09:48:46 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: tmp.c,v 1.13 2008/04/28 20:24:15 martin Exp $ */ +/* $NetBSD: tmp.c,v 1.14 2009/08/15 09:48:46 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: tmp.c,v 1.13 2008/04/28 20:24:15 martin Exp $"); +__RCSID("$NetBSD: tmp.c,v 1.14 2009/08/15 09:48:46 dsl Exp $"); __SCCSID("@(#)tmp.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -85,7 +85,7 @@ #define _NAME_TMP "sort.XXXXXXXX" FILE * -ftmp() +ftmp(void) { sigset_t set, oset; FILE *fp;