From affba8f2e9ac72423927f027e6726f1d44fceb55 Mon Sep 17 00:00:00 2001 From: jdolecek Date: Mon, 19 Feb 2001 20:50:17 +0000 Subject: [PATCH] Pull up various cosmetic (mostly whitespace) changes from OpenBSD. This is primarily to ease syncing the two versions. --- usr.bin/sort/append.c | 13 +++++---- usr.bin/sort/extern.h | 16 +++++------ usr.bin/sort/fields.c | 42 ++++++++++++++++------------ usr.bin/sort/files.c | 64 ++++++++++++++++++++++++------------------- usr.bin/sort/fsort.c | 30 ++++++++++---------- usr.bin/sort/fsort.h | 4 +-- usr.bin/sort/init.c | 26 ++++++++++-------- usr.bin/sort/msort.c | 28 ++++++++----------- 8 files changed, 117 insertions(+), 106 deletions(-) diff --git a/usr.bin/sort/append.c b/usr.bin/sort/append.c index 671fa7ea65ea..d02a96fcc491 100644 --- a/usr.bin/sort/append.c +++ b/usr.bin/sort/append.c @@ -1,4 +1,4 @@ -/* $NetBSD: append.c,v 1.9 2001/01/18 20:59:43 jdolecek Exp $ */ +/* $NetBSD: append.c,v 1.10 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -39,7 +39,7 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: append.c,v 1.9 2001/01/18 20:59:43 jdolecek Exp $"); +__RCSID("$NetBSD: append.c,v 1.10 2001/02/19 20:50:17 jdolecek Exp $"); __SCCSID("@(#)append.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -101,7 +101,7 @@ append(keylist, nelem, depth, fp, put, ftbl) crec = (const RECHEADER *) (*cpos - depth); if (crec->length == prec->length) { /* - * Set pend & cend so that trailing '\0' and + * Set pend and cend so that trailing NUL and * record separator is ignored. */ pend = (const u_char *) &prec->data + prec->length - 2; @@ -133,11 +133,11 @@ append(keylist, nelem, depth, fp, put, ftbl) ppos = keylist; prec = (const RECHEADER *) (*ppos - depth); put(prec, fp); - for (cpos = keylist+1; cpos < lastkey; cpos++) { + for (cpos = &keylist[1]; cpos < lastkey; cpos++) { crec = (const RECHEADER *) (*cpos - depth); if (crec->offset == prec->offset) { /* - * Set pend & cend so that trailing '\0' and + * Set pend and cend so that trailing NUL and * record separator is ignored. */ pend = (const u_char *) &prec->data + prec->offset - 2; @@ -175,7 +175,8 @@ rd_append(binno, infl0, nfiles, outfp, buffer, bufend) FILE *outfp; u_char *bufend; { - struct recheader *rec; + RECHEADER *rec; + rec = (RECHEADER *) buffer; if (!getnext(binno, infl0, NULL, nfiles, (RECHEADER *) buffer, bufend, 0)) { diff --git a/usr.bin/sort/extern.h b/usr.bin/sort/extern.h index 569e74313c49..56fdb5873d52 100644 --- a/usr.bin/sort/extern.h +++ b/usr.bin/sort/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.5 2001/01/12 19:31:25 jdolecek Exp $ */ +/* $NetBSD: extern.h,v 1.6 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -41,7 +41,7 @@ void append __P((const u_char **, int, int, FILE *, void (*)(const RECHEADER *, FILE *), struct field *)); void concat __P((FILE *, FILE *)); -length_t enterkey __P((struct recheader *, DBT *, int, struct field *)); +length_t enterkey __P((RECHEADER *, DBT *, int, struct field *)); void fixit __P((int *, char **)); void fldreset __P((struct field *)); FILE *ftmp __P((void)); @@ -50,20 +50,20 @@ void fmerge __P((int, int, struct filelist *, int, void fsort __P((int, int, int, struct filelist *, int, FILE *, struct field *)); int geteasy __P((int, int, struct filelist *, - int, struct recheader *, u_char *, struct field *)); + int, RECHEADER *, u_char *, struct field *)); int getnext __P((int, int, struct filelist *, - int, struct recheader *, u_char *, struct field *)); + int, RECHEADER *, u_char *, struct field *)); int makekey __P((int, int, struct filelist *, - int, struct recheader *, u_char *, struct field *)); + int, RECHEADER *, u_char *, struct field *)); int makeline __P((int, int, struct filelist *, - int, struct recheader *, u_char *, struct field *)); + int, RECHEADER *, u_char *, struct field *)); void merge __P((int, int, get_func_t, FILE *, put_func_t, struct field *)); void num_init __P((void)); void onepass __P((const u_char **, int, long, long *, u_char *, FILE *)); int optval __P((int, int)); void order __P((struct filelist *, get_func_t, struct field *)); -void putline __P((const struct recheader *, FILE *)); -void putrec __P((const struct recheader *, FILE *)); +void putline __P((const RECHEADER *, FILE *)); +void putrec __P((const RECHEADER *, FILE *)); void rd_append __P((int, int, int, FILE *, u_char *, u_char *)); int setfield __P((const char *, struct field *, int)); void settables __P((int)); diff --git a/usr.bin/sort/fields.c b/usr.bin/sort/fields.c index d98edc08e3f7..12242f661758 100644 --- a/usr.bin/sort/fields.c +++ b/usr.bin/sort/fields.c @@ -1,4 +1,4 @@ -/* $NetBSD: fields.c,v 1.9 2001/02/19 19:52:27 jdolecek Exp $ */ +/* $NetBSD: fields.c,v 1.10 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -41,7 +41,7 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: fields.c,v 1.9 2001/02/19 19:52:27 jdolecek Exp $"); +__RCSID("$NetBSD: fields.c,v 1.10 2001/02/19 20:50:17 jdolecek Exp $"); __SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -76,10 +76,10 @@ u_char fnum[NBINS], rnum[NBINS]; */ length_t enterkey(keybuf, line, size, fieldtable) - struct recheader *keybuf; /* pointer to start of key */ + RECHEADER *keybuf; /* pointer to start of key */ DBT *line; int size; - struct field *fieldtable; + struct field fieldtable[]; { int i; u_char *l_d_mask; @@ -95,8 +95,9 @@ enterkey(keybuf, line, size, fieldtable) for (i = 0; i < ncols; i++) { clpos = clist + i; - for (; (col < clpos->num) && (pos < lineend); col++) - { NEXTCOL(pos); } + for (; (col < clpos->num) && (pos < lineend); col++) { + NEXTCOL(pos); + } if (pos >= lineend) break; clpos->start = SEP_FLAG ? pos + 1 : pos; @@ -105,14 +106,14 @@ enterkey(keybuf, line, size, fieldtable) col++; if (pos >= lineend) { clpos->end = lineend; - ++i; + i++; break; } } for (; i <= ncols; i++) clist[i].start = clist[i].end = lineend; if (clist[0].start < (u_char *) line->data) - ++clist[0].start; + clist[0].start++; keypos = keybuf->data; endkey = (u_char *) keybuf + size - line->size; @@ -154,6 +155,7 @@ enterfield(tablepos, endkey, cur_fld, gflags) struct column icol, tcol; u_int flags; u_int Rflag; + icol = cur_fld->icol; tcol = cur_fld->tcol; flags = cur_fld->flags; @@ -163,6 +165,7 @@ enterfield(tablepos, endkey, cur_fld, gflags) blancmange(start); start += icol.indent; start = min(start, lineend); + if (!tcol.num) end = lineend; else { @@ -211,7 +214,7 @@ enterfield(tablepos, endkey, cur_fld, gflags) * if the exponent is exactly 61, 61+252, etc--this is ok, since it's the * only time a field delimiter can come in that position. * Reverse order is done analagously. -*/ + */ static u_char * number(pos, bufend, line, lineend, Rflag) @@ -230,8 +233,10 @@ number(pos, bufend, line, lineend, Rflag) nweights = fnum; if (pos > bufend - 8) return (NULL); - /* or_sign sets the sort direction: - * (-r: +/-)(sign: +/-)(expsign: +/-) */ + /* + * or_sign sets the sort direction: + * (-r: +/-)(sign: +/-)(expsign: +/-) + */ or_sign = sign ^ expsign ^ Rflag; blancmange(line); if (*line == '-') { /* set the sign */ @@ -240,7 +245,8 @@ number(pos, bufend, line, lineend, Rflag) line++; } /* eat initial zeroes */ - for (; *line == '0' && line < lineend; line++); + for (; *line == '0' && line < lineend; line++) + ; /* calculate exponents < 0 */ if (*line == DECIMAL) { exponent = 1; @@ -309,7 +315,7 @@ number(pos, bufend, line, lineend, Rflag) /* This forces a gap around the record delimiter * Thus fnum has vaues over (0,254) -> ((0,REC_D-1),(REC_D+1,255)); * rnum over (0,254) -> (255,REC_D+1),(REC_D-1,0)) -*/ + */ void num_init() { @@ -319,15 +325,15 @@ num_init() OFF_TENS = TENS - '0'; OFF_NTENS = NEGTENS - '0'; for (i = 1; i < 10; i++) { - TENS[i] = TENS[i-1] + 10; - NEGTENS[i] = NEGTENS[i-1] - 10; + TENS[i] = TENS[i - 1] + 10; + NEGTENS[i] = NEGTENS[i - 1] - 10; } for (i = 0; i < REC_D; i++) { fnum[i] = i; - rnum[255-i] = i; + rnum[255 - i] = i; } for (i = REC_D; i <255; i++) { - fnum[i] = i+1; - rnum[255-i] = i-1; + fnum[i] = i + 1; + rnum[255 - i] = i - 1; } } diff --git a/usr.bin/sort/files.c b/usr.bin/sort/files.c index f838e6fe14fe..0398894a5922 100644 --- a/usr.bin/sort/files.c +++ b/usr.bin/sort/files.c @@ -1,4 +1,4 @@ -/* $NetBSD: files.c,v 1.15 2001/02/19 15:45:45 jdolecek Exp $ */ +/* $NetBSD: files.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -40,13 +40,13 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: files.c,v 1.15 2001/02/19 15:45:45 jdolecek Exp $"); +__RCSID("$NetBSD: files.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $"); __SCCSID("@(#)files.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ #include -static int seq __P((FILE *, DBT *, DBT *)); +static int seq __P((FILE *, DBT *, DBT *)); /* * this is the subroutine for file management for fsort(). @@ -57,7 +57,7 @@ getnext(binno, infl0, filelist, nfiles, pos, end, dummy) int binno, infl0; struct filelist *filelist; int nfiles; - struct recheader *pos; + RECHEADER *pos; u_char *end; struct field *dummy; { @@ -76,7 +76,7 @@ getnext(binno, infl0, filelist, nfiles, pos, end, dummy) } flag = -1; nleft = cnt = 0; - return(-1); + return (-1); } maxb = fstack[infl0].maxb; for (; nleft == 0; cnt++) { @@ -108,7 +108,7 @@ getnext(binno, infl0, filelist, nfiles, pos, end, dummy) return (BUFFEND); fread(pos, sizeof(TRECHEADER), 1, fp); if (end - pos->data < pos->length) { - hp = ((u_char *) pos) + sizeof(TRECHEADER); + hp = ((u_char *)pos) + sizeof(TRECHEADER); for (i = sizeof(TRECHEADER); i ; i--) ungetc(*--hp, fp); return (BUFFEND); @@ -129,7 +129,7 @@ makeline(flno, top, filelist, nfiles, buffer, bufend, dummy2) int flno, top; struct filelist *filelist; int nfiles; - struct recheader *buffer; + RECHEADER *buffer; u_char *bufend; struct field *dummy2; { @@ -158,14 +158,14 @@ makeline(flno, top, filelist, nfiles, buffer, bufend, dummy2) overflow = 0; } for (;;) { - if (flno >= 0) { - if (!(fp = fstack[flno].fp)) + if (flno >= 0 && (fp = fstack[flno].fp) == NULL) + return (EOF); + else if (fp == NULL) { + if (fileno >= nfiles) return (EOF); - } else if (!fp) { - if (fileno >= nfiles) return(EOF); if (!(fp = fopen(filelist->names[fileno], "r"))) err(2, "%s", filelist->names[fileno]); - ++fileno; + fileno++; } while ((pos < (char *)bufend) && ((c = getc(fp)) != EOF)) { if ((*pos++ = c) == REC_D) { @@ -186,21 +186,24 @@ makeline(flno, top, filelist, nfiles, buffer, bufend, dummy2) *pos++ = REC_D; buffer->offset = 0; buffer->length = pos - (char *) buffer->data; - return(0); + return (0); } FCLOSE(fp); fp = 0; - if(flno >= 0) fstack[flno].fp = 0; + if (flno >= 0) + fstack[flno].fp = 0; } else { warnx("makeline: line too long: ignoring '%.100s...'", buffer->data); - /* consume rest of line from input */ - while((c = getc(fp)) != REC_D && c != EOF); + /* Consume the rest of line from input */ + while((c = getc(fp)) != REC_D && c != EOF) + ; buffer->offset = 0; buffer->length = 0; - return BUFFEND; + + return (BUFFEND); } } } @@ -213,7 +216,7 @@ makekey(flno, top, filelist, nfiles, buffer, bufend, ftbl) int flno, top; struct filelist *filelist; int nfiles; - struct recheader *buffer; + RECHEADER *buffer; u_char *bufend; struct field *ftbl; { @@ -222,25 +225,27 @@ makekey(flno, top, filelist, nfiles, buffer, bufend, ftbl) static DBT dbkey[1], line[1]; static int overflow = 0; int c; + if (overflow) { - overflow = enterkey(buffer, line, bufend - (u_char *) buffer, - ftbl); + overflow = enterkey(buffer, line, bufend - (u_char *)buffer, + ftbl); if (overflow) return (BUFFEND); else return (0); } + for (;;) { if (flno >= 0) { if (!(dbdesc = fstack[flno].fp)) - return(EOF); + return (EOF); } else if (!dbdesc) { if (fileno >= nfiles) return (EOF); dbdesc = fopen(filelist->names[fileno], "r"); if (!dbdesc) err(2, "%s", filelist->names[fileno]); - ++fileno; + fileno++; } if (!(c = seq(dbdesc, line, dbkey))) { if ((signed)line->size > bufend - buffer->data) { @@ -257,13 +262,13 @@ makekey(flno, top, filelist, nfiles, buffer, bufend, ftbl) if (c == EOF) { FCLOSE(dbdesc); dbdesc = 0; - if (flno >= 0) fstack[flno].fp = 0; + if (flno >= 0) + fstack[flno].fp = 0; } else { ((char *) line->data)[60] = '\000'; warnx("makekey: line too long: ignoring %.100s...", (char *)line->data); } - } } @@ -278,6 +283,7 @@ seq(fp, line, key) static char *buf, flag = 1; char *end, *pos; int c; + if (flag) { flag = 0; buf = (char *) linebuf; @@ -294,7 +300,8 @@ seq(fp, line, key) linebuf_size *= 2; linebuf = realloc(linebuf, linebuf_size); if (!linebuf) - err(2, "realloc for linebuf to %lu bytes failed", (unsigned long) linebuf_size); + err(2, "realloc of linebuf to %lu bytes failed", + (unsigned long)linebuf_size); end = linebuf + linebuf_size; pos = linebuf + (pos - buf); @@ -315,7 +322,7 @@ seq(fp, line, key) */ void putrec(rec, fp) - const struct recheader *rec; + const RECHEADER *rec; FILE *fp; { EWRITE(rec, 1, rec->length + sizeof(TRECHEADER), fp); @@ -326,7 +333,7 @@ putrec(rec, fp) */ void putline(rec, fp) - const struct recheader *rec; + const RECHEADER *rec; FILE *fp; { EWRITE(rec->data+rec->offset, 1, rec->length - rec->offset, fp); @@ -340,12 +347,13 @@ geteasy(flno, top, filelist, nfiles, rec, end, dummy2) int flno, top; struct filelist *filelist; int nfiles; - struct recheader *rec; + RECHEADER *rec; u_char *end; struct field *dummy2; { int i; FILE *fp; + fp = fstack[flno].fp; if ((u_char *) rec > end - sizeof(TRECHEADER)) return (BUFFEND); diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c index 975c1f255219..35ed9cb33bb8 100644 --- a/usr.bin/sort/fsort.c +++ b/usr.bin/sort/fsort.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsort.c,v 1.15 2001/02/19 19:39:53 jdolecek Exp $ */ +/* $NetBSD: fsort.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -42,12 +42,12 @@ * and try again on smaller bins. Sort the final bin at this level * of recursion to keep the head of fstack at 0. * After PANIC passes, abort to merge sort. -*/ + */ #include "sort.h" #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: fsort.c,v 1.15 2001/02/19 19:39:53 jdolecek Exp $"); +__RCSID("$NetBSD: fsort.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $"); __SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -100,7 +100,8 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) memset(keylist, 0, MAXNUM * sizeof(u_char *)); if (!SINGL_FLD) { linebuf_size = DEFLLEN; - linebuf = malloc(linebuf_size); + if ((linebuf = malloc(linebuf_size)) == NULL) + errx(2, "cannot allocate memory"); } } bufend = buffer + bufsize; @@ -190,7 +191,7 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) mfct, geteasy, fstack[base].fp, putrec, ftbl); - ++ntfiles; + ntfiles++; mfct = 0; memmove(crec->data, tmpbuf, bufend - crec->data); @@ -200,17 +201,16 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) fstack[base + ntfiles].fp= ftmp(); onepass(keylist, depth, nelem, sizes, weights, fstack[base + ntfiles].fp); - ++ntfiles; + ntfiles++; } } } if (!ntfiles && !mfct) { /* everything in memory--pop */ - if (nelem > 1) { - if ((stable_sort) + if (nelem > 1 + && ((stable_sort) ? sradixsort(keylist, nelem, weights, REC_D) - : radixsort(keylist, nelem, weights, REC_D) ) + : radixsort(keylist, nelem, weights, REC_D) )) err(2, NULL); - } append(keylist, nelem, depth, outfp, putline, ftbl); break; /* pop */ } @@ -242,10 +242,9 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) for (i = 0; i < maxb; i++) { if (!sizes[i]) /* bin empty; step ahead file offset */ getnext(i, base, NULL,ntfiles, crec, bufend, 0); - else { + else fsort(i, depth+1, base, filelist, ntfiles, outfp, ftbl); - } } get = getnext; @@ -255,13 +254,12 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) tailfp[panic] = prevfp; prevfp = ftmp(); for (i = maxb+1; i <= lastb; i++) - if (!sizes[i]) { + if (!sizes[i]) getnext(i, base, NULL, ntfiles, crec, bufend,0); - } else { + else fsort(i, depth+1, base, filelist, ntfiles, prevfp, ftbl); - } } /* sort biggest (or last) bin at this level */ @@ -283,7 +281,7 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) } /* - This is one pass of radix exchange, dumping the bins to disk. + * This is one pass of radix exchange, dumping the bins to disk. */ #define swap(a, b, t) t = a, a = b, b = t void diff --git a/usr.bin/sort/fsort.h b/usr.bin/sort/fsort.h index 5475e9358206..389eb5e28266 100644 --- a/usr.bin/sort/fsort.h +++ b/usr.bin/sort/fsort.h @@ -1,4 +1,4 @@ -/* $NetBSD: fsort.h,v 1.7 2001/02/19 19:31:29 jdolecek Exp $ */ +/* $NetBSD: fsort.h,v 1.8 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -64,6 +64,6 @@ struct tempfile { FILE *fp; u_char maxb; u_char lastb; - long max_o; + int max_o; }; extern struct tempfile fstack[MAXFCT]; diff --git a/usr.bin/sort/init.c b/usr.bin/sort/init.c index ccd3a103687b..5af6619c5751 100644 --- a/usr.bin/sort/init.c +++ b/usr.bin/sort/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.4 2001/01/12 19:30:22 jdolecek Exp $ */ +/* $NetBSD: init.c,v 1.5 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -39,7 +39,7 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: init.c,v 1.4 2001/01/12 19:30:22 jdolecek Exp $"); +__RCSID("$NetBSD: init.c,v 1.5 2001/02/19 20:50:17 jdolecek Exp $"); __SCCSID("@(#)init.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -103,11 +103,13 @@ fldreset(fldtab) int i; fldtab[0].tcol.p = clist+ncols-1; for (++fldtab; fldtab->icol.num; ++fldtab) { - for (i = 0; fldtab->icol.num != clist[i].num; i++); + for (i = 0; fldtab->icol.num != clist[i].num; i++) + ; fldtab->icol.p = clist + i; if (!fldtab->tcol.num) continue; - for (i = 0; fldtab->tcol.num != clist[i].num; i++); + for (i = 0; fldtab->tcol.num != clist[i].num; i++) + ; fldtab->tcol.p = clist + i; } } @@ -213,15 +215,15 @@ optval(desc, tcolflag) switch(desc) { case 'b': if (!tcolflag) - return(BI); + return (BI); else - return(BT); - case 'd': return(D); - case 'f': return(F); - case 'i': return(I); - case 'n': return(N); - case 'r': return(R); - default: return(0); + return (BT); + case 'd': return (D); + case 'f': return (F); + case 'i': return (I); + case 'n': return (N); + case 'r': return (R); + default: return (0); } } diff --git a/usr.bin/sort/msort.c b/usr.bin/sort/msort.c index 295c07e0150b..8a2500cc35d2 100644 --- a/usr.bin/sort/msort.c +++ b/usr.bin/sort/msort.c @@ -1,4 +1,4 @@ -/* $NetBSD: msort.c,v 1.9 2001/01/19 10:50:31 jdolecek Exp $ */ +/* $NetBSD: msort.c,v 1.10 2001/02/19 20:50:17 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -40,7 +40,7 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: msort.c,v 1.9 2001/01/19 10:50:31 jdolecek Exp $"); +__RCSID("$NetBSD: msort.c,v 1.10 2001/02/19 20:50:17 jdolecek Exp $"); __SCCSID("@(#)msort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -59,7 +59,7 @@ typedef struct mfile { static u_char *wts, *wts1 = NULL; -static int cmp __P((struct recheader *, struct recheader *)); +static int cmp __P((RECHEADER *, RECHEADER *)); static int insert __P((struct mfile **, struct mfile **, int, int)); void @@ -96,6 +96,7 @@ fmerge(binno, top, filelist, nfiles, get, outfp, fput, ftbl) l_fstack = fstack + top; else l_fstack = fstack; + while (nfiles) { put = putrec; for (j = 0; j < nfiles; j += MERGE_FNUM) { @@ -107,18 +108,13 @@ fmerge(binno, top, filelist, nfiles, get, outfp, fput, ftbl) tout = ftmp(); last = min(MERGE_FNUM, nfiles - j); if (binno < 0) { - FILE *fp; - for (i = 0; i < last; i++) { - fp = fopen(filelist->names[j+i], "r"); - if (!fp) { + for (i = 0; i < last; i++) + if (!(l_fstack[i+MAXFCT-1-MERGE_FNUM].fp = + fopen(filelist->names[j+i], "r"))) err(2, "%s", filelist->names[j+i]); - } - l_fstack[i+MAXFCT-1-MERGE_FNUM].fp = fp; - } merge(MAXFCT-1-MERGE_FNUM, last, get, tout, put, ftbl); - } - else { + } else { for (i = 0; i< last; i++) rewind(l_fstack[i+j].fp); merge(top+j, last, get, tout, put, ftbl); @@ -248,7 +244,7 @@ merge(infl0, nfiles, get, outfp, put, ftbl) /* * if delete: inserts *rec in flist, deletes flist[0], and leaves it in *rec; * otherwise just inserts *rec in flist. -*/ + */ static int insert(flist, rec, ttop, delete) struct mfile **flist, **rec; @@ -294,7 +290,7 @@ insert(flist, rec, ttop, delete) if (!bot && cmpv) cmpv = cmp(tmprec->rec, flist[0]->rec); if (!cmpv) - return(1); + return (1); } tmprec = flist[0]; if (bot) @@ -330,7 +326,7 @@ order(filelist, get, ftbl) { u_char *crec_end, *prec_end, *trec_end; int c; - struct recheader *crec, *prec, *trec; + RECHEADER *crec, *prec, *trec; if (!SINGL_FLD) linebuf = malloc(DEFLLEN); @@ -372,7 +368,7 @@ order(filelist, get, ftbl) static int cmp(rec1, rec2) - struct recheader *rec1, *rec2; + RECHEADER *rec1, *rec2; { int r; u_char *pos1, *pos2, *end;