Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/less merge less-374



details:   https://anonhg.NetBSD.org/src/rev/07da0f8698ae
branches:  trunk
changeset: 523122:07da0f8698ae
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Mar 05 12:28:31 2002 +0000

description:
merge less-374

diffstat:

 usr.bin/less/less/Makefile       |    4 +-
 usr.bin/less/less/ch.c           |  147 +++++++---
 usr.bin/less/less/charset.c      |   51 +++-
 usr.bin/less/less/cmdbuf.c       |   70 +++-
 usr.bin/less/less/command.c      |   71 +++++-
 usr.bin/less/less/decode.c       |   27 +-
 usr.bin/less/less/defines.h      |   10 +-
 usr.bin/less/less/edit.c         |   48 ++-
 usr.bin/less/less/filename.c     |  497 +++++++++++++++++++-------------------
 usr.bin/less/less/funcs.h        |   28 +-
 usr.bin/less/less/help.c         |   12 +-
 usr.bin/less/less/less.1         |  135 +++++++---
 usr.bin/less/less/less.h         |   28 +-
 usr.bin/less/less/line.c         |  296 ++++++++++++++++++-----
 usr.bin/less/less/linenum.c      |    4 +-
 usr.bin/less/less/lsystem.c      |   16 +-
 usr.bin/less/less/main.c         |   26 +-
 usr.bin/less/less/option.c       |   52 ++-
 usr.bin/less/less/option.h       |    4 +-
 usr.bin/less/less/opttbl.c       |   51 ++-
 usr.bin/less/less/os.c           |   87 +++---
 usr.bin/less/less/output.c       |   73 +---
 usr.bin/less/less/prompt.c       |  106 +++++---
 usr.bin/less/less/screen.c       |  246 +++++++++++++++----
 usr.bin/less/less/search.c       |   20 +-
 usr.bin/less/less/version.c      |   32 ++-
 usr.bin/less/lessecho/lessecho.c |   65 ++++-
 usr.bin/less/lesskey/lesskey.1   |   69 ++--
 usr.bin/less/lesskey/lesskey.c   |    9 +-
 29 files changed, 1510 insertions(+), 774 deletions(-)

diffs (truncated from 4455 to 300 lines):

diff -r 5dfb22beab64 -r 07da0f8698ae usr.bin/less/less/Makefile
--- a/usr.bin/less/less/Makefile        Tue Mar 05 11:56:33 2002 +0000
+++ b/usr.bin/less/less/Makefile        Tue Mar 05 12:28:31 2002 +0000
@@ -1,8 +1,8 @@
-#      $NetBSD: Makefile,v 1.8 2000/10/11 14:46:09 is Exp $
+#      $NetBSD: Makefile,v 1.9 2002/03/05 12:28:31 mrg Exp $
 #      from: @(#)Makefile      5.6 (Berkeley) 3/12/91
 
 PROG=  less
-CPPFLAGS+=-I${.CURDIR} -I${.CURDIR}/../lesskey
+CPPFLAGS+=-I${.CURDIR} -I${.CURDIR}/../lesskey -DSYSDIR=\"/etc\"
 SRCS=  brac.c ch.c charset.c cmdbuf.c command.c decode.c edit.c \
        filename.c forwback.c help.c ifile.c input.c jump.c line.c \
        linenum.c lsystem.c main.c mark.c optfunc.c option.c opttbl.c \
diff -r 5dfb22beab64 -r 07da0f8698ae usr.bin/less/less/ch.c
--- a/usr.bin/less/less/ch.c    Tue Mar 05 11:56:33 2002 +0000
+++ b/usr.bin/less/less/ch.c    Tue Mar 05 12:28:31 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ch.c,v 1.4 2001/07/26 13:43:43 mrg Exp $       */
+/*     $NetBSD: ch.c,v 1.5 2002/03/05 12:28:31 mrg Exp $       */
 
 /*
  * Copyright (C) 1984-2000  Mark Nudelman
@@ -23,6 +23,8 @@
 #include <windows.h>
 #endif
 
+typedef POSITION BLOCKNUM;
+
 public int ignore_eoi;
 
 /*
@@ -31,34 +33,38 @@
  * in order from most- to least-recently used.
  * The circular list is anchored by the file state "thisfile".
  */
-#define LBUFSIZE       1024
+#define        LBUFSIZE        8192
 struct buf {
-       struct buf *next, *prev;  /* Must be first to match struct filestate */
-       long block;
+       struct buf *next, *prev;
+       struct buf *hnext, *hprev;
+       BLOCKNUM block;
        unsigned int datasize;
        unsigned char data[LBUFSIZE];
 };
 
+struct buflist {
+       /* -- Following members must match struct buf */
+       struct buf *buf_next, *buf_prev;
+       struct buf *buf_hnext, *buf_hprev;
+};
+
 /*
  * The file state is maintained in a filestate structure.
  * A pointer to the filestate is kept in the ifile structure.
  */
+#define        BUFHASH_SIZE    64
 struct filestate {
-       /* -- Following members must match struct buf */
        struct buf *buf_next, *buf_prev;
-       long buf_block;
-       /* -- End of struct buf copy */
+       struct buflist hashtbl[BUFHASH_SIZE];
        int file;
        int flags;
        POSITION fpos;
        int nbufs;
-       long block;
+       BLOCKNUM block;
        unsigned int offset;
        POSITION fsize;
 };
 
-
-#define        END_OF_CHAIN    ((struct buf *)thisfile)
 #define        ch_bufhead      thisfile->buf_next
 #define        ch_buftail      thisfile->buf_prev
 #define        ch_nbufs        thisfile->nbufs
@@ -69,12 +75,30 @@
 #define        ch_flags        thisfile->flags
 #define        ch_file         thisfile->file
 
+#define        END_OF_CHAIN    ((struct buf *)&thisfile->buf_next)
+#define        END_OF_HCHAIN(h) ((struct buf *)&thisfile->hashtbl[h])
+#define BUFHASH(blk)   ((blk) & (BUFHASH_SIZE-1))
+
+#define        FOR_BUFS_IN_CHAIN(h,bp) \
+       for (bp = thisfile->hashtbl[h].buf_hnext;  \
+            bp != END_OF_HCHAIN(h);  bp = bp->hnext)
+
+#define        HASH_RM(bp) \
+       (bp)->hnext->hprev = (bp)->hprev; \
+       (bp)->hprev->hnext = (bp)->hnext;
+
+#define        HASH_INS(bp,h) \
+       (bp)->hnext = thisfile->hashtbl[h].buf_hnext; \
+       (bp)->hprev = END_OF_HCHAIN(h); \
+       thisfile->hashtbl[h].buf_hnext->hprev = (bp); \
+       thisfile->hashtbl[h].buf_hnext = (bp);
+
 static struct filestate *thisfile;
 static int ch_ungotchar = -1;
+static int maxbufs = -1;
 
 extern int autobuf;
 extern int sigs;
-extern int cbufs;
 extern int secure;
 extern constant char helpdata[];
 extern constant int size_helpdata;
@@ -84,7 +108,7 @@
 extern char *namelogfile;
 #endif
 
-static int buffered __P((long));
+static int buffered __P((BLOCKNUM));
 static int ch_addbuf __P((void));
 static void ch_delbufs __P((void));
 
@@ -103,6 +127,7 @@
        register struct buf *bp;
        register int n;
        register int slept;
+       register int h;
        POSITION pos;
        POSITION len;
 
@@ -111,7 +136,9 @@
        /*
         * Look for a buffer holding the desired block.
         */
-       for (bp = ch_bufhead;  bp != END_OF_CHAIN;  bp = bp->next)
+       h = BUFHASH(ch_block);
+       FOR_BUFS_IN_CHAIN(h, bp)
+       {
                if (bp->block == ch_block)
                {
                        if (ch_offset >= bp->datasize)
@@ -121,6 +148,7 @@
                                goto read_more;
                        goto found;
                }
+       }
        /*
         * Block is not in a buffer.  
         * Take the least recently used buffer 
@@ -128,7 +156,7 @@
         * If the LRU buffer has data in it, 
         * then maybe allocate a new buffer.
         */
-       if (ch_buftail == END_OF_CHAIN || ch_buftail->block != (long)(-1))
+       if (ch_buftail == END_OF_CHAIN || ch_buftail->block != -1)
        {
                /*
                 * There is no empty buffer to use.
@@ -137,7 +165,7 @@
                 * 2. We haven't allocated the max buffers for this file yet.
                 */
                if ((autobuf && !(ch_flags & CH_CANSEEK)) ||
-                   (cbufs == -1 || ch_nbufs < cbufs))
+                   (maxbufs < 0 || ch_nbufs < maxbufs))
                        if (ch_addbuf())
                                /*
                                 * Allocation failed: turn off autobuf.
@@ -145,8 +173,10 @@
                                autobuf = OPT_OFF;
        }
        bp = ch_buftail;
+       HASH_RM(bp); /* Remove from old hash chain. */
        bp->block = ch_block;
        bp->datasize = 0;
+       HASH_INS(bp, h); /* Insert into new hash chain. */
 
     read_more:
        pos = (ch_block * LBUFSIZE) + bp->datasize;
@@ -233,7 +263,11 @@
                         * Wait a while, then try again.
                         */
                        if (!slept)
-                               ierror("Waiting for data", NULL_PARG);
+                       {
+                               PARG parg;
+                               parg.p_string = wait_message();
+                               ierror("%s", &parg);
+                       }
 #if !MSDOS_COMPILER
                        sleep(1);
 #else
@@ -256,11 +290,16 @@
                 */
                bp->next->prev = bp->prev;
                bp->prev->next = bp->next;
-
                bp->next = ch_bufhead;
                bp->prev = END_OF_CHAIN;
                ch_bufhead->prev = bp;
                ch_bufhead = bp;
+
+               /*
+                * Move to head of hash chain too.
+                */
+               HASH_RM(bp);
+               HASH_INS(bp, h);
        }
 
        if (ch_offset >= bp->datasize)
@@ -321,8 +360,8 @@
 {
        register struct buf *bp;
        int warned = FALSE;
-       long block;
-       long nblocks;
+       BLOCKNUM block;
+       BLOCKNUM nblocks;
 
        nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE;
        for (block = 0;  block < nblocks;  block++)
@@ -355,13 +394,17 @@
  */
        static int
 buffered(block)
-       long block;
+       BLOCKNUM block;
 {
        register struct buf *bp;
+       register int h;
 
-       for (bp = ch_bufhead;  bp != END_OF_CHAIN;  bp = bp->next)
+       h = BUFHASH(block);
+       FOR_BUFS_IN_CHAIN(h, bp)
+       {
                if (bp->block == block)
                        return (TRUE);
+       }
        return (FALSE);
 }
 
@@ -373,7 +416,7 @@
 ch_seek(pos)
        register POSITION pos;
 {
-       long new_block;
+       BLOCKNUM new_block;
        POSITION len;
 
        len = ch_length();
@@ -473,12 +516,10 @@
 /*
  * Return the current position in the file.
  */
-#define        tellpos(blk,off)   ((POSITION)((((long)(blk)) * LBUFSIZE) + (off)))
-
        public POSITION
 ch_tell()
 {
-       return (tellpos(ch_block, ch_offset));
+       return (ch_block * LBUFSIZE) + ch_offset;
 }
 
 /*
@@ -523,32 +564,21 @@
 }
 
 /*
- * Allocate buffers.
- * Caller wants us to have a total of at least want_nbufs buffers.
+ * Set max amount of buffer space.
+ * bufspace is in units of 1024 bytes.  -1 mean no limit.
  */
-       public int
-ch_nbuf(want_nbufs)
-       int want_nbufs;
+       public void
+ch_setbufspace(bufspace)
+       int bufspace;
 {
-       PARG parg;
-
-       while (ch_nbufs < want_nbufs)
+       if (bufspace < 0)
+               maxbufs = -1;
+       else
        {
-               if (ch_addbuf())
-               {
-                       /*
-                        * Cannot allocate enough buffers.
-                        * If we don't have ANY, then quit.
-                        * Otherwise, just report the error and return.
-                        */
-                       parg.p_int = want_nbufs - ch_nbufs;
-                       error("Cannot allocate %d buffers", &parg);
-                       if (ch_nbufs == 0)
-                               quit(QUIT_ERROR);
-                       break;
-               }
+               maxbufs = ((bufspace * 1024) + LBUFSIZE-1) / LBUFSIZE;
+               if (maxbufs < 1)



Home | Main Index | Thread Index | Old Index