Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/sort general cleanup of file list passing:



details:   https://anonhg.NetBSD.org/src/rev/72b945389dcf
branches:  trunk
changeset: 502085:72b945389dcf
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Thu Jan 11 14:05:24 2001 +0000

description:
general cleanup of file list passing:
* get rid of union f_handle, replace by passing explicit int parameter
  and (new) struct filelist
* add new typedefs gen_func_t and put_func_t and use where appropriate

diffstat:

 usr.bin/sort/append.c |  16 +++++----
 usr.bin/sort/extern.h |  34 ++++++++-------------
 usr.bin/sort/files.c  |  56 +++++++++++++++++++----------------
 usr.bin/sort/fsort.c  |  80 ++++++++++++++++++++++++++++----------------------
 usr.bin/sort/msort.c  |  58 +++++++++++++++++++-----------------
 usr.bin/sort/sort.c   |  23 ++++++++------
 usr.bin/sort/sort.h   |  10 ++++-
 7 files changed, 146 insertions(+), 131 deletions(-)

diffs (truncated from 669 to 300 lines):

diff -r 382aafbd1a78 -r 72b945389dcf usr.bin/sort/append.c
--- a/usr.bin/sort/append.c     Thu Jan 11 14:00:11 2001 +0000
+++ b/usr.bin/sort/append.c     Thu Jan 11 14:05:24 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: append.c,v 1.7 2001/01/08 18:00:31 jdolecek Exp $      */
+/*     $NetBSD: append.c,v 1.8 2001/01/11 14:05:24 jdolecek Exp $      */
 
 /*-
  * Copyright (c) 1993
@@ -39,7 +39,7 @@
 #include "sort.h"
 
 #ifndef lint
-__RCSID("$NetBSD: append.c,v 1.7 2001/01/08 18:00:31 jdolecek Exp $");
+__RCSID("$NetBSD: append.c,v 1.8 2001/01/11 14:05:24 jdolecek Exp $");
 __SCCSID("@(#)append.c 8.1 (Berkeley) 6/6/93");
 #endif /* not lint */
 
@@ -71,7 +71,7 @@
        int nelem;
        int depth;
        FILE *fp;
-       void (*put)(const RECHEADER *, FILE *);
+       put_func_t put;
        struct field *ftbl;
 {
        u_char *wts, *wts1;
@@ -169,16 +169,18 @@
  */
 void
 rd_append(binno, infl0, nfiles, outfp, buffer, bufend)
-       u_char *buffer, *bufend;
+       u_char *buffer;
+       int infl0;
        int binno, nfiles;
-       union f_handle infl0;
        FILE *outfp;
+       u_char *bufend;
 {
        struct recheader *rec;
        rec = (RECHEADER *) buffer;
-       if (!getnext(binno, infl0, nfiles, (RECHEADER *) buffer, bufend, 0)) {
+       if (!getnext(binno, infl0, NULL, nfiles,
+                       (RECHEADER *) buffer, bufend, 0)) {
                putline(rec, outfp);
-               while (getnext(binno, infl0, nfiles, (RECHEADER *) buffer,
+               while (getnext(binno, infl0, NULL, nfiles, (RECHEADER *) buffer,
                        bufend, 0) == 0) {
                        if (!UNIQUE)
                                putline(rec, outfp);
diff -r 382aafbd1a78 -r 72b945389dcf usr.bin/sort/extern.h
--- a/usr.bin/sort/extern.h     Thu Jan 11 14:00:11 2001 +0000
+++ b/usr.bin/sort/extern.h     Thu Jan 11 14:05:24 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.3 2000/10/16 21:38:44 jdolecek Exp $      */
+/*     $NetBSD: extern.h,v 1.4 2001/01/11 14:05:24 jdolecek Exp $      */
 
 /*-
  * Copyright (c) 1993
@@ -46,33 +46,25 @@
 void    fixit __P((int *, char **));
 void    fldreset __P((struct field *));
 FILE   *ftmp __P((void));
-void    fmerge __P((int, union f_handle, int,
-           int (*)(int, union f_handle, int, struct recheader *, u_char *,
-               struct field *), FILE *,
-               void (*)(const 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 *));
-int     getnext __P((int, union f_handle,
+void    fmerge __P((int, int, struct filelist *, int,
+               get_func_t, FILE *, put_func_t, struct field *));
+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     makekey __P((int, union f_handle,
+int     getnext __P((int, int, struct filelist *,
            int, struct recheader *, u_char *, struct field *));
-int     makeline __P((int, union f_handle,
+int     makekey __P((int, int, struct filelist *,
            int, struct recheader *, u_char *, struct field *));
-void    merge __P((int, int,
-           int (*)(int, union f_handle, int, struct recheader *, u_char *,
-               struct field *), FILE *,
-               void (*)(const struct recheader *, FILE *),
-           struct field *));
+int     makeline __P((int, int, struct filelist *,
+           int, struct 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((union f_handle,
-           int (*)(int, union f_handle, int, struct recheader *, u_char *,
-               struct field *), struct field *));
+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    rd_append __P((int, union f_handle, int, FILE *, u_char *, u_char *));
+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 -r 382aafbd1a78 -r 72b945389dcf usr.bin/sort/files.c
--- a/usr.bin/sort/files.c      Thu Jan 11 14:00:11 2001 +0000
+++ b/usr.bin/sort/files.c      Thu Jan 11 14:05:24 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.7 2001/01/08 19:16:50 jdolecek Exp $       */
+/*     $NetBSD: files.c,v 1.8 2001/01/11 14:05:24 jdolecek Exp $       */
 
 /*-
  * Copyright (c) 1993
@@ -40,7 +40,7 @@
 #include "fsort.h"
 
 #ifndef lint
-__RCSID("$NetBSD: files.c,v 1.7 2001/01/08 19:16:50 jdolecek Exp $");
+__RCSID("$NetBSD: files.c,v 1.8 2001/01/11 14:05:24 jdolecek Exp $");
 __SCCSID("@(#)files.c  8.1 (Berkeley) 6/6/93");
 #endif /* not lint */
 
@@ -53,9 +53,10 @@
  * It keeps the buffers for all temporary files.
  */
 int
-getnext(binno, infl0, nfiles, pos, end, dummy)
-       int binno, nfiles;
-       union f_handle infl0;
+getnext(binno, infl0, filelist, nfiles, pos, end, dummy)
+       int binno, infl0;
+       struct filelist *filelist;
+       int nfiles;
        struct recheader *pos;
        u_char *end;
        struct field *dummy;
@@ -70,27 +71,27 @@
        if (nleft == 0) {
                if (binno < 0)  /* reset files. */ {
                        for (i = 0; i < nfiles; i++) {
-                               rewind(fstack[infl0.top + i].fp);
-                               fstack[infl0.top + i].max_o = 0;
+                               rewind(fstack[infl0 + i].fp);
+                               fstack[infl0 + i].max_o = 0;
                        }
                        flag = -1;
                        nleft = cnt = 0;
                        return(-1);
                }
-               maxb = fstack[infl0.top].maxb;
+               maxb = fstack[infl0].maxb;
                for (; nleft == 0; cnt++) {
                        if (cnt >= nfiles) {
                                cnt = 0;
                                return (EOF);
                        }
-                       fp = fstack[infl0.top + cnt].fp;
+                       fp = fstack[infl0 + cnt].fp;
                        fread(&nleft, sizeof(nleft), 1, fp);
                        if (binno < maxb)
-                               fstack[infl0.top+cnt].max_o
+                               fstack[infl0+cnt].max_o
                                        += sizeof(nleft) + nleft;
                        else if (binno == maxb) {
-                               if (binno != fstack[infl0.top].lastb) {
-                                       fseek(fp, fstack[infl0.top+
+                               if (binno != fstack[infl0].lastb) {
+                                       fseek(fp, fstack[infl0+
                                                cnt].max_o, SEEK_SET);
                                        fread(&nleft, sizeof(nleft), 1, fp);
                                }
@@ -114,7 +115,7 @@
        }
        fread(pos->data, pos->length, 1, fp);
        nleft -= pos->length + sizeof(TRECHEADER);
-       if (nleft == 0 && binno == fstack[infl0.top].maxb)
+       if (nleft == 0 && binno == fstack[infl0].maxb)
                fclose(fp);
        return (0);
 }
@@ -124,9 +125,10 @@
  * in the first fsort pass.
  */
 int
-makeline(flno, filelist, nfiles, buffer, bufend, dummy2)
-       int flno, nfiles;
-       union f_handle filelist;
+makeline(flno, top, filelist, nfiles, buffer, bufend, dummy2)
+       int flno, top;
+       struct filelist *filelist;
+       int nfiles;
        struct recheader *buffer;
        u_char *bufend;
        struct field *dummy2;
@@ -148,8 +150,8 @@
                                return (EOF);
                } else if (!fp) {
                        if (fileno  >= nfiles) return(EOF);
-                       if (!(fp = fopen(filelist.names[fileno], "r")))
-                               err(2, "%s", filelist.names[fileno]);
+                       if (!(fp = fopen(filelist->names[fileno], "r")))
+                               err(2, "%s", filelist->names[fileno]);
                        ++fileno;
                }
                while ((pos < (char *)bufend) && ((c = getc(fp)) != EOF)) {
@@ -195,9 +197,10 @@
  * This generates keys. It's only called in the first fsort pass
  */
 int
-makekey(flno, filelist, nfiles, buffer, bufend, ftbl)
-       int flno, nfiles;
-       union f_handle filelist;
+makekey(flno, top, filelist, nfiles, buffer, bufend, ftbl)
+       int flno, top;
+       struct filelist *filelist;
+       int nfiles;
        struct recheader *buffer;
        u_char *bufend;
        struct field *ftbl;
@@ -222,9 +225,9 @@
                } else if (!dbdesc) {
                        if (fileno  >= nfiles)
                                return (EOF);
-                       dbdesc = fopen(filelist.names[fileno], "r");
+                       dbdesc = fopen(filelist->names[fileno], "r");
                        if (!dbdesc)
-                               err(2, "%s", filelist.names[fileno]);
+                               err(2, "%s", filelist->names[fileno]);
                        ++fileno;
                }
                if (!(c = seq(dbdesc, line, dbkey))) {
@@ -331,9 +334,10 @@
  * get a record from a temporary file. (Used by merge sort.)
  */
 int
-geteasy(flno, filelist, nfiles, rec, end, dummy2)
-       int flno, nfiles;
-       union f_handle filelist;
+geteasy(flno, top, filelist, nfiles, rec, end, dummy2)
+       int flno, top;
+       struct filelist *filelist;
+       int nfiles;
        struct recheader *rec;
        u_char *end;
        struct field *dummy2;
diff -r 382aafbd1a78 -r 72b945389dcf usr.bin/sort/fsort.c
--- a/usr.bin/sort/fsort.c      Thu Jan 11 14:00:11 2001 +0000
+++ b/usr.bin/sort/fsort.c      Thu Jan 11 14:05:24 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fsort.c,v 1.7 2001/01/08 18:00:31 jdolecek Exp $       */
+/*     $NetBSD: fsort.c,v 1.8 2001/01/11 14:05:24 jdolecek Exp $       */
 
 /*-
  * Copyright (c) 1993
@@ -47,7 +47,7 @@
 #include "fsort.h"
 
 #ifndef lint
-__RCSID("$NetBSD: fsort.c,v 1.7 2001/01/08 18:00:31 jdolecek Exp $");
+__RCSID("$NetBSD: fsort.c,v 1.8 2001/01/11 14:05:24 jdolecek Exp $");
 __SCCSID("@(#)fsort.c  8.1 (Berkeley) 6/6/93");
 #endif /* not lint */
 
@@ -62,10 +62,13 @@
 #define FSORTMAX 4
 int PANIC = FSORTMAX;
 
+#define MSTART         (MAXFCT - 16)
+
 void
-fsort(binno, depth, infiles, nfiles, outfp, ftbl)
-       int binno, depth, nfiles;
-       union f_handle infiles;
+fsort(binno, depth, top, filelist, nfiles, outfp, ftbl)
+       int binno, depth, top;
+       struct filelist *filelist;
+       int nfiles;
        FILE *outfp;
        struct field *ftbl;
 {
@@ -73,11 +76,9 @@
        u_char *bufend, *tmpbuf;
        u_char *weights;
        int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0;
-       int c, nelem;
+       int c, nelem, base;
        long sizes [NBINS+1];
-       union f_handle tfiles, mstart = {MAXFCT-16};
-       int (*get)(int, union f_handle, int, RECHEADER *,
-               u_char *, struct field *);
+       get_func_t get;
        struct recheader *crec;
        struct field tfield[2];
        FILE *prevfp, *tailfp[FSORTMAX+1];
@@ -102,10 +103,10 @@
        }
        bufend = buffer + bufsize;
        if (binno >= 0) {
-               tfiles.top = infiles.top + nfiles;



Home | Main Index | Thread Index | Old Index