less -> more
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 23 Nov 1988 08:51:31 +0000 (00:51 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 23 Nov 1988 08:51:31 +0000 (00:51 -0800)
SCCS-vsn: usr.bin/more/ch.c 5.6
SCCS-vsn: usr.bin/more/command.c 5.10
SCCS-vsn: usr.bin/more/decode.c 5.6
SCCS-vsn: usr.bin/more/help.c 5.5
SCCS-vsn: usr.bin/more/input.c 5.3
SCCS-vsn: usr.bin/more/less.h 5.7
SCCS-vsn: usr.bin/more/line.c 5.3
SCCS-vsn: usr.bin/more/linenum.c 5.5
SCCS-vsn: usr.bin/more/main.c 5.9

usr/src/usr.bin/more/ch.c
usr/src/usr.bin/more/command.c
usr/src/usr.bin/more/decode.c
usr/src/usr.bin/more/help.c
usr/src/usr.bin/more/input.c
usr/src/usr.bin/more/less.h
usr/src/usr.bin/more/line.c
usr/src/usr.bin/more/linenum.c
usr/src/usr.bin/more/main.c

index ee926e4..debc6bc 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ch.c       5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)ch.c       5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -27,26 +27,28 @@ static char sccsid[] = "@(#)ch.c    5.5 (Berkeley) %G%";
  * both forward and backward from the current read pointer.
  */
 
  * both forward and backward from the current read pointer.
  */
 
-#include "less.h"
+#include <sys/types.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <less.h>
 
 
-public int file = -1;          /* File descriptor of the input file */
+int file = -1;         /* File descriptor of the input file */
 
 /*
  * Pool of buffers holding the most recently used blocks of the input file.
  */
 
 /*
  * Pool of buffers holding the most recently used blocks of the input file.
  */
-#define BUFSIZ 1024
+#define        BUFSIZ  1024
 struct buf {
        struct buf *next, *prev;
        long block;
        int datasize;
        char data[BUFSIZ];
 };
 struct buf {
        struct buf *next, *prev;
        long block;
        int datasize;
        char data[BUFSIZ];
 };
-public int nbufs;
+int nbufs;
 
 /*
 
 /*
- * The buffer pool is kept as a doubly-linked circular list,
- * in order from most- to least-recently used.
- * The circular list is anchored by buf_anchor.
+ * The buffer pool is kept as a doubly-linked circular list, in order from
+ * most- to least-recently used.  The circular list is anchored by buf_anchor.
  */
 #define        END_OF_CHAIN    ((struct buf *)&buf_anchor)
 #define        buf_head        buf_anchor.next
  */
 #define        END_OF_CHAIN    ((struct buf *)&buf_anchor)
 #define        buf_head        buf_anchor.next
@@ -56,11 +58,7 @@ static struct {
        struct buf *next, *prev;
 } buf_anchor = { END_OF_CHAIN, END_OF_CHAIN };
 
        struct buf *next, *prev;
 } buf_anchor = { END_OF_CHAIN, END_OF_CHAIN };
 
-extern int clean_data;
-extern int ispipe;
-extern int autobuf;
-extern int cbufs;
-extern int sigs;
+extern int ispipe, cbufs, sigs;
 
 /*
  * Current position in file.
 
 /*
  * Current position in file.
@@ -69,39 +67,33 @@ extern int sigs;
 static long ch_block;
 static int ch_offset;
 
 static long ch_block;
 static int ch_offset;
 
-/* 
- * Length of file, needed if input is a pipe.
- */
-static POSITION ch_fsize;
+/* Length of file, needed if input is a pipe. */
+static off_t ch_fsize;
 
 
-/*
- * Number of bytes read, if input is standard input (a pipe).
- */
-static POSITION last_piped_pos;
+/* Number of bytes read, if input is standard input (a pipe). */
+static off_t last_piped_pos;
 
 /*
 
 /*
- * Get the character pointed to by the read pointer.
- * ch_get() is a macro which is more efficient to call
- * than fch_get (the function), in the usual case 
- * that the block desired is at the head of the chain.
+ * Get the character pointed to by the read pointer.  ch_get() is a macro
+ * which is more efficient to call than fch_get (the function), in the usual
+ * case that the block desired is at the head of the chain.
  */
  */
-#define        ch_get()   ((buf_head->block == ch_block && \
-                    ch_offset < buf_head->datasize) ? \
-                       buf_head->data[ch_offset] : fch_get())
-       static int
+#define        ch_get() \
+       ((buf_head->block == ch_block && \
+           ch_offset < buf_head->datasize) ? \
+           buf_head->data[ch_offset] : fch_get())
+
+static
 fch_get()
 {
        register struct buf *bp;
        register int n;
        register char *p;
 fch_get()
 {
        register struct buf *bp;
        register int n;
        register char *p;
-       POSITION pos;
+       off_t pos, lseek();
 
 
-       /*
-        * Look for a buffer holding the desired block.
-        */
+       /* look for a buffer holding the desired block. */
        for (bp = buf_head;  bp != END_OF_CHAIN;  bp = bp->next)
        for (bp = buf_head;  bp != END_OF_CHAIN;  bp = bp->next)
-               if (bp->block == ch_block)
-               {
+               if (bp->block == ch_block) {
                        if (ch_offset >= bp->datasize)
                                /*
                                 * Need more data in this buffer.
                        if (ch_offset >= bp->datasize)
                                /*
                                 * Need more data in this buffer.
@@ -122,33 +114,28 @@ fch_get()
                         * find it already buffered.
                         */
                        if (ispipe)
                         * find it already buffered.
                         */
                        if (ispipe)
-                               return (bp->data[ch_offset]);
+                               return(bp->data[ch_offset]);
                        goto found;
                }
        /*
                        goto found;
                }
        /*
-        * Block is not in a buffer.  
-        * Take the least recently used buffer 
-        * and read the desired block into it.
-        * If the LRU buffer has data in it, 
-        * and autobuf is true, and input is a pipe, 
-        * then try to allocate a new buffer first.
+        * Block is not in a buffer.  Take the least recently used buffer
+        * and read the desired block into it.  If the LRU buffer has data
+        * in it, and input is a pipe, then try to allocate a new buffer first.
         */
         */
-       if (autobuf && ispipe && buf_tail->block != (long)(-1))
-               (void) ch_addbuf(1);
+       if (ispipe && buf_tail->block != (long)(-1))
+               (void)ch_addbuf(1);
        bp = buf_tail;
        bp->block = ch_block;
        bp->datasize = 0;
 
        bp = buf_tail;
        bp->block = ch_block;
        bp->datasize = 0;
 
-    read_more:
+read_more:
        pos = (ch_block * BUFSIZ) + bp->datasize;
        pos = (ch_block * BUFSIZ) + bp->datasize;
-       if (ispipe)
-       {
+       if (ispipe) {
                /*
                 * The data requested should be immediately after
                 * the last data read from the pipe.
                 */
                /*
                 * The data requested should be immediately after
                 * the last data read from the pipe.
                 */
-               if (pos != last_piped_pos)
-               {
+               if (pos != last_piped_pos) {
                        error("pipe error");
                        quit();
                }
                        error("pipe error");
                        quit();
                }
@@ -163,8 +150,7 @@ fch_get()
        n = iread(file, &bp->data[bp->datasize], BUFSIZ - bp->datasize);
        if (n == READ_INTR)
                return (EOI);
        n = iread(file, &bp->data[bp->datasize], BUFSIZ - bp->datasize);
        if (n == READ_INTR)
                return (EOI);
-       if (n < 0)
-       {
+       if (n < 0) {
                error("read error");
                quit();
        }
                error("read error");
                quit();
        }
@@ -174,31 +160,23 @@ fch_get()
        bp->datasize += n;
 
        /*
        bp->datasize += n;
 
        /*
-        * Set an EOI marker in the buffered data itself.
-        * Then ensure the data is "clean": there are no 
-        * extra EOI chars in the data and that the "meta"
-        * bit (the 0200 bit) is reset in each char.
+        * Set an EOI marker in the buffered data itself.  Then ensure the
+        * data is "clean": there are no extra EOI chars in the data and
+        * that the "meta" bit (the 0200 bit) is reset in each char.
         */
         */
-       if (n == 0)
-       {
+       if (n == 0) {
                ch_fsize = pos;
                bp->data[bp->datasize++] = EOI;
        }
 
                ch_fsize = pos;
                bp->data[bp->datasize++] = EOI;
        }
 
-       if (!clean_data)
-       {
-               p = &bp->data[bp->datasize];
-               while (--n >= 0)
-               {
-                       *--p &= 0177;
-                       if (*p == EOI)
-                               *p = '@';
-               }
+       for (p = &bp->data[bp->datasize]; --n >= 0;) {
+               *--p &= 0177;
+               if (*p == EOI)
+                       *p = 0200;
        }
 
        }
 
-    found:
-       if (buf_head != bp)
-       {
+found:
+       if (buf_head != bp) {
                /*
                 * Move the buffer to the head of the buffer chain.
                 * This orders the buffer chain, most- to least-recently used.
                /*
                 * Move the buffer to the head of the buffer chain.
                 * This orders the buffer chain, most- to least-recently used.
@@ -219,63 +197,62 @@ fch_get()
                 */
                goto read_more;
 
                 */
                goto read_more;
 
-       return (bp->data[ch_offset]);
+       return(bp->data[ch_offset]);
 }
 
 /*
  * Determine if a specific block is currently in one of the buffers.
  */
 }
 
 /*
  * Determine if a specific block is currently in one of the buffers.
  */
-       static int
+static
 buffered(block)
        long block;
 {
        register struct buf *bp;
 
 buffered(block)
        long block;
 {
        register struct buf *bp;
 
-       for (bp = buf_head;  bp != END_OF_CHAIN;  bp = bp->next)
+       for (bp = buf_head; bp != END_OF_CHAIN; bp = bp->next)
                if (bp->block == block)
                if (bp->block == block)
-                       return (1);
-       return (0);
+                       return(1);
+       return(0);
 }
 
 /*
  * Seek to a specified position in the file.
  * Return 0 if successful, non-zero if can't seek there.
  */
 }
 
 /*
  * Seek to a specified position in the file.
  * Return 0 if successful, non-zero if can't seek there.
  */
-       public int
 ch_seek(pos)
 ch_seek(pos)
-       register POSITION pos;
+       register off_t pos;
 {
        long new_block;
 
        new_block = pos / BUFSIZ;
 {
        long new_block;
 
        new_block = pos / BUFSIZ;
-       if (!ispipe || pos == last_piped_pos || buffered(new_block))
-       {
+       if (!ispipe || pos == last_piped_pos || buffered(new_block)) {
                /*
                 * Set read pointer.
                 */
                ch_block = new_block;
                ch_offset = pos % BUFSIZ;
                /*
                 * Set read pointer.
                 */
                ch_block = new_block;
                ch_offset = pos % BUFSIZ;
-               return (0);
+               return(0);
        }
        }
-       return (1);
+       return(1);
 }
 
 /*
  * Seek to the end of the file.
  */
 }
 
 /*
  * Seek to the end of the file.
  */
-       public int
 ch_end_seek()
 {
 ch_end_seek()
 {
+       off_t ch_length();
+
        if (!ispipe)
        if (!ispipe)
-               return (ch_seek(ch_length()));
+               return(ch_seek(ch_length()));
 
        /*
         * Do it the slow way: read till end of data.
         */
        while (ch_forw_get() != EOI)
                if (sigs)
 
        /*
         * Do it the slow way: read till end of data.
         */
        while (ch_forw_get() != EOI)
                if (sigs)
-                       return (1);
-       return (0);
+                       return(1);
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -283,7 +260,6 @@ ch_end_seek()
  * We may not be able to seek there if input is a pipe and the
  * beginning of the pipe is no longer buffered.
  */
  * We may not be able to seek there if input is a pipe and the
  * beginning of the pipe is no longer buffered.
  */
-       public int
 ch_beg_seek()
 {
        register struct buf *bp, *firstbp;
 ch_beg_seek()
 {
        register struct buf *bp, *firstbp;
@@ -291,8 +267,8 @@ ch_beg_seek()
        /*
         * Try a plain ch_seek first.
         */
        /*
         * Try a plain ch_seek first.
         */
-       if (ch_seek((POSITION)0) == 0)
-               return (0);
+       if (ch_seek((off_t)0) == 0)
+               return(0);
 
        /*
         * Can't get to position 0.
 
        /*
         * Can't get to position 0.
@@ -300,69 +276,66 @@ ch_beg_seek()
         */
        firstbp = bp = buf_head;
        if (bp == END_OF_CHAIN)
         */
        firstbp = bp = buf_head;
        if (bp == END_OF_CHAIN)
-               return (1);
+               return(1);
        while ((bp = bp->next) != END_OF_CHAIN)
                if (bp->block < firstbp->block)
                        firstbp = bp;
        ch_block = firstbp->block;
        ch_offset = 0;
        while ((bp = bp->next) != END_OF_CHAIN)
                if (bp->block < firstbp->block)
                        firstbp = bp;
        ch_block = firstbp->block;
        ch_offset = 0;
-       return (0);
+       return(0);
 }
 
 /*
  * Return the length of the file, if known.
  */
 }
 
 /*
  * Return the length of the file, if known.
  */
-       public POSITION
+off_t
 ch_length()
 {
 ch_length()
 {
+       off_t lseek();
+
        if (ispipe)
        if (ispipe)
-               return (ch_fsize);
-       return ((POSITION)(lseek(file, (off_t)0, L_XTND)));
+               return(ch_fsize);
+       return((off_t)(lseek(file, (off_t)0, L_XTND)));
 }
 
 /*
  * Return the current position in the file.
  */
 }
 
 /*
  * Return the current position in the file.
  */
-       public POSITION
+off_t
 ch_tell()
 {
 ch_tell()
 {
-       return (ch_block * BUFSIZ + ch_offset);
+       return(ch_block * BUFSIZ + ch_offset);
 }
 
 /*
  * Get the current char and post-increment the read pointer.
  */
 }
 
 /*
  * Get the current char and post-increment the read pointer.
  */
-       public int
 ch_forw_get()
 {
        register int c;
 
        c = ch_get();
 ch_forw_get()
 {
        register int c;
 
        c = ch_get();
-       if (c != EOI && ++ch_offset >= BUFSIZ)
-       {
+       if (c != EOI && ++ch_offset >= BUFSIZ) {
                ch_offset = 0;
                ch_offset = 0;
-               ch_block ++;
+               ++ch_block;
        }
        }
-       return (c);
+       return(c);
 }
 
 /*
  * Pre-decrement the read pointer and get the new current char.
  */
 }
 
 /*
  * Pre-decrement the read pointer and get the new current char.
  */
-       public int
 ch_back_get()
 {
 ch_back_get()
 {
-       if (--ch_offset < 0)
-       {
-               if (ch_block <= 0 || (ispipe && !buffered(ch_block-1)))
-               {
+       if (--ch_offset < 0) {
+               if (ch_block <= 0 || (ispipe && !buffered(ch_block-1))) {
                        ch_offset = 0;
                        ch_offset = 0;
-                       return (EOI);
+                       return(EOI);
                }
                ch_offset = BUFSIZ - 1;
                ch_block--;
        }
                }
                ch_offset = BUFSIZ - 1;
                ch_block--;
        }
-       return (ch_get());
+       return(ch_get());
 }
 
 /*
 }
 
 /*
@@ -371,7 +344,6 @@ ch_back_get()
  * keep==1 means keep the data in the current buffers;
  * otherwise discard the old data.
  */
  * keep==1 means keep the data in the current buffers;
  * otherwise discard the old data.
  */
-       public void
 ch_init(want_nbufs, keep)
        int want_nbufs;
        int keep;
 ch_init(want_nbufs, keep)
        int want_nbufs;
        int keep;
@@ -380,15 +352,14 @@ ch_init(want_nbufs, keep)
        char message[80];
 
        cbufs = nbufs;
        char message[80];
 
        cbufs = nbufs;
-       if (nbufs < want_nbufs && ch_addbuf(want_nbufs - nbufs))
-       {
+       if (nbufs < want_nbufs && ch_addbuf(want_nbufs - nbufs)) {
                /*
                 * Cannot allocate enough buffers.
                 * If we don't have ANY, then quit.
                 * Otherwise, just report the error and return.
                 */
                (void)sprintf(message, "cannot allocate %d buffers",
                /*
                 * Cannot allocate enough buffers.
                 * If we don't have ANY, then quit.
                 * Otherwise, just report the error and return.
                 */
                (void)sprintf(message, "cannot allocate %d buffers",
-                       want_nbufs - nbufs);
+                   want_nbufs - nbufs);
                error(message);
                if (nbufs == 0)
                        quit();
                error(message);
                if (nbufs == 0)
                        quit();
@@ -404,29 +375,30 @@ ch_init(want_nbufs, keep)
         */
        for (bp = buf_head;  bp != END_OF_CHAIN;  bp = bp->next)
                bp->block = (long)(-1);
         */
        for (bp = buf_head;  bp != END_OF_CHAIN;  bp = bp->next)
                bp->block = (long)(-1);
-       last_piped_pos = (POSITION)0;
+       last_piped_pos = (off_t)0;
        ch_fsize = NULL_POSITION;
        ch_fsize = NULL_POSITION;
-       (void) ch_seek((POSITION)0);
+       (void)ch_seek((off_t)0);
 }
 
 /*
  * Allocate some new buffers.
  * The buffers are added to the tail of the buffer chain.
  */
 }
 
 /*
  * Allocate some new buffers.
  * The buffers are added to the tail of the buffer chain.
  */
-       static int
+static
 ch_addbuf(nnew)
        int nnew;
 {
        register struct buf *bp;
        register struct buf *newbufs;
 ch_addbuf(nnew)
        int nnew;
 {
        register struct buf *bp;
        register struct buf *newbufs;
+       char *calloc();
 
        /*
         * We don't have enough buffers.  
         * Allocate some new ones.
         */
 
        /*
         * We don't have enough buffers.  
         * Allocate some new ones.
         */
-       newbufs = (struct buf *) calloc((u_int)nnew, sizeof(struct buf));
+       newbufs = (struct buf *)calloc((u_int)nnew, sizeof(struct buf));
        if (newbufs == NULL)
        if (newbufs == NULL)
-               return (1);
+               return(1);
 
        /*
         * Initialize the new buffers and link them together.
 
        /*
         * Initialize the new buffers and link them together.
@@ -434,8 +406,7 @@ ch_addbuf(nnew)
         */
        nbufs += nnew;
        cbufs = nbufs;
         */
        nbufs += nnew;
        cbufs = nbufs;
-       for (bp = &newbufs[0];  bp < &newbufs[nnew];  bp++)
-       {
+       for (bp = &newbufs[0];  bp < &newbufs[nnew];  bp++) {
                bp->next = bp + 1;
                bp->prev = bp - 1;
                bp->block = (long)(-1);
                bp->next = bp + 1;
                bp->prev = bp - 1;
                bp->block = (long)(-1);
@@ -444,5 +415,5 @@ ch_addbuf(nnew)
        newbufs[0].prev = buf_tail;
        buf_tail->next = &newbufs[0];
        buf_tail = &newbufs[nnew-1];
        newbufs[0].prev = buf_tail;
        buf_tail->next = &newbufs[0];
        buf_tail = &newbufs[nnew-1];
-       return (0);
+       return(0);
 }
 }
index 0463329..6454dba 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)command.c  5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)command.c  5.10 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * User-level command processor.
  */
 
 #endif /* not lint */
 
 /*
  * User-level command processor.
  */
 
-#include "less.h"
-#include "position.h"
-#include "cmd.h"
+#include <sys/param.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <less.h>
 
 #define        NO_MCA          0
 #define        MCA_DONE        1
 #define        MCA_MORE        2
 
 
 #define        NO_MCA          0
 #define        MCA_DONE        1
 #define        MCA_MORE        2
 
-extern int erase_char, kill_char;
+extern int erase_char, kill_char, werase_char;
 extern int ispipe;
 extern int sigs;
 extern int quit_at_eof;
 extern int ispipe;
 extern int sigs;
 extern int quit_at_eof;
@@ -45,14 +46,12 @@ extern int curr_ac;
 extern int ac;
 extern int quitting;
 extern int scroll;
 extern int ac;
 extern int quitting;
 extern int scroll;
-extern char *first_cmd;
-extern char *every_first_cmd;
-extern char *current_file;
 extern int screen_trashed;     /* The screen has been overwritten */
 
 static char cmdbuf[120];       /* Buffer for holding a multi-char command */
 static char *cp;               /* Pointer into cmdbuf */
 static int cmd_col;            /* Current column of the multi-char command */
 extern int screen_trashed;     /* The screen has been overwritten */
 
 static char cmdbuf[120];       /* Buffer for holding a multi-char command */
 static char *cp;               /* Pointer into cmdbuf */
 static int cmd_col;            /* Current column of the multi-char command */
+static int longprompt;         /* if stat command instead of prompt */
 static int mca;                        /* The multicharacter command (action) */
 static int last_mca;           /* The previous mca */
 static int number;             /* The number typed by the user */
 static int mca;                        /* The multicharacter command (action) */
 static int last_mca;           /* The previous mca */
 static int number;             /* The number typed by the user */
@@ -69,7 +68,7 @@ cmd_reset()
 /*
  * Backspace in command buffer.
  */
 /*
  * Backspace in command buffer.
  */
-       static int
+static
 cmd_erase()
 {
        if (cp == cmdbuf)
 cmd_erase()
 {
        if (cp == cmdbuf)
@@ -77,19 +76,18 @@ cmd_erase()
                 * Backspace past beginning of the string:
                 * this usually means abort the command.
                 */
                 * Backspace past beginning of the string:
                 * this usually means abort the command.
                 */
-               return (1);
+               return(1);
 
 
-       if (control_char(*--cp))
-       {
+       if (CONTROL_CHAR(*--cp)) {
                /*
                 * Erase an extra character, for the carat.
                 */
                backspace();
                /*
                 * Erase an extra character, for the carat.
                 */
                backspace();
-               cmd_col--;
+               --cmd_col;
        }
        backspace();
        }
        backspace();
-       cmd_col--;
-       return (0);
+       --cmd_col;
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -110,49 +108,43 @@ start_mca(action, prompt)
  * Process a single character of a multi-character command, such as
  * a number, or the pattern of a search command.
  */
  * Process a single character of a multi-character command, such as
  * a number, or the pattern of a search command.
  */
-       static int
+static
 cmd_char(c)
        int c;
 {
        if (c == erase_char)
 cmd_char(c)
        int c;
 {
        if (c == erase_char)
-       {
-               if (cmd_erase())
-                       return (1);
-       } else if (c == kill_char)
-       {
-               /* {{ Could do this faster, but who cares? }} */
-               while (cmd_erase() == 0)
-                       ;
-       } else if (cp >= &cmdbuf[sizeof(cmdbuf)-1])
-       {
-               /*
-                * No room in the command buffer.
-                */
-               bell();
-       } else if (cmd_col >= sc_width-3)
-       {
-               /*
-                * No room on the screen.
-                * {{ Could get fancy here; maybe shift the displayed
-                *    line and make room for more chars, like ksh. }}
-                */
+               return(cmd_erase());
+       /* in this order, in case werase == erase_char */
+       if (c == werase_char) {
+               if (cp > cmdbuf) {
+                       while (isspace(cp[-1]) && !cmd_erase());
+                       while (!isspace(cp[-1]) && !cmd_erase());
+                       while (isspace(cp[-1]) && !cmd_erase());
+               }
+               return(cp == cmdbuf);
+       }
+       if (c == kill_char) {
+               while (!cmd_erase());
+               return(1);
+       }
+       /*
+        * No room in the command buffer, or no room on the screen;
+        * {{ Could get fancy here; maybe shift the displayed line
+        * and make room for more chars, like ksh. }}
+        */
+       if (cp >= &cmdbuf[sizeof(cmdbuf)-1] || cmd_col >= sc_width-3)
                bell();
                bell();
-       } else
-       {
-               /*
-                * Append the character to the string.
-                */
+       else {
                *cp++ = c;
                *cp++ = c;
-               if (control_char(c))
-               {
+               if (CONTROL_CHAR(c)) {
                        putchr('^');
                        cmd_col++;
                        putchr('^');
                        cmd_col++;
-                       c = carat_char(c);
+                       c = CARAT_CHAR(c);
                }
                putchr(c);
                cmd_col++;
        }
                }
                putchr(c);
                cmd_col++;
        }
-       return (0);
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -171,139 +163,135 @@ cmd_int()
  * This looks nicer if the command takes a long time before
  * updating the screen.
  */
  * This looks nicer if the command takes a long time before
  * updating the screen.
  */
-       static void
+static
 cmd_exec()
 {
        lower_left();
        flush();
 }
 
 cmd_exec()
 {
        lower_left();
        flush();
 }
 
-/*
- * Display the appropriate prompt.
- */
-       static void
 prompt()
 {
 prompt()
 {
-       register char *p;
-
-       if (first_cmd != NULL && *first_cmd != '\0')
-       {
-               /*
-                * No prompt necessary if commands are from first_cmd
-                * rather than from the user.
-                */
-               return;
-       }
+       extern int terseprompt, linenums;
+       extern char *current_name, *firstsearch;
+       off_t len, pos, ch_length(), position(), forw_line();
+       char pbuf[40];
 
        /*
 
        /*
-        * If nothing is displayed yet, display starting from line 1.
+        * if nothing is displayed yet, display starting from line 1;
+        * if search string provided, go there instead.
         */
         */
-       if (position(TOP) == NULL_POSITION)
-               jump_back(1);
+       if (position(TOP) == NULL_POSITION) {
+               if (forw_line((off_t)0) == NULL_POSITION)
+                       return(0);
+               if (!firstsearch || !search(1, firstsearch, 1, 1))
+                       jump_back(1);
+       }
        else if (screen_trashed)
                repaint();
 
        else if (screen_trashed)
                repaint();
 
-       /*
-        * If the -E flag is set and we've hit EOF on the last file, quit.
-        */
-       if (quit_at_eof == 2 && hit_eof && curr_ac + 1 >= ac)
+       /* if no -e flag and we've hit EOF on the last file, quit. */
+       if (!quit_at_eof && hit_eof && curr_ac + 1 >= ac)
                quit();
 
                quit();
 
-       /*
-        * Select the proper prompt and display it.
-        */
+       /* select the proper prompt and display it. */
        lower_left();
        clear_eol();
        lower_left();
        clear_eol();
-       p = pr_string();
-       if (p == NULL)
+       if (longprompt) {
+               so_enter();
+               putstr(current_name);
+               putstr(":");
+               if (!ispipe) {
+                       (void)sprintf(pbuf, " file %d/%d", curr_ac + 1, ac);
+                       putstr(pbuf);
+               }
+               if (linenums) {
+                       (void)sprintf(pbuf, " line %d", currline(TOP));
+                       putstr(pbuf);
+               }
+               if ((pos = position(TOP)) != NULL_POSITION) {
+                       (void)sprintf(pbuf, " byte %ld", pos);
+                       putstr(pbuf);
+                       if (!ispipe && (len = ch_length())) {
+                               (void)sprintf(pbuf, " pct %ld%%",
+                                   ((100 * pos) / len));
+                               putstr(pbuf);
+                       }
+               }
+               so_exit();
+               longprompt = 0;
+       }
+       else if (terseprompt)
                putchr(':');
                putchr(':');
-       else
-       {
+       else {
                so_enter();
                so_enter();
-               putstr(p);
+               putstr(current_name);
+               if (hit_eof)
+                       putstr(": END");
+               else if (linenums) {
+                       (void)sprintf(pbuf, ": %d", currline(TOP));
+                       putstr(pbuf);
+               }
                so_exit();
        }
                so_exit();
        }
+       return(1);
 }
 
 /*
  * Get command character.
 }
 
 /*
  * Get command character.
- * The character normally comes from the keyboard,
- * but may come from the "first_cmd" string.
  */
  */
-       static int
+static
 getcc()
 {
 getcc()
 {
-       if (first_cmd == NULL)
-               return (getchr());
-
-       if (*first_cmd == '\0')
-       {
+       if (cp > cmdbuf && position(TOP) == NULL_POSITION) {
                /*
                /*
-                * Reached end of first_cmd input.
+                * Command is incomplete, so try to complete it.
+                * There are only two cases:
+                * 1. We have "/string" but no newline.  Add the \n.
+                * 2. We have a number but no command.  Treat as #g.
+                * (This is all pretty hokey.)
                 */
                 */
-               first_cmd = NULL;
-               if (cp > cmdbuf && position(TOP) == NULL_POSITION)
-               {
-                       /*
-                        * Command is incomplete, so try to complete it.
-                        * There are only two cases:
-                        * 1. We have "/string" but no newline.  Add the \n.
-                        * 2. We have a number but no command.  Treat as #g.
-                        * (This is all pretty hokey.)
-                        */
-                       if (mca != A_DIGIT)
-                               /* Not a number; must be search string */
-                               return ('\n'); 
-                       else
-                               /* A number; append a 'g' */
-                               return ('g');
-               }
-               return (getchr());
+               if (mca != A_DIGIT)
+                       /* Not a number; must be search string */
+                       return('\n');
+               else
+                       /* A number; append a 'g' */
+                       return('g');
        }
        }
-       return (*first_cmd++);
+       return(getchr());
 }
 
 /*
  * Execute a multicharacter command.
  */
 }
 
 /*
  * Execute a multicharacter command.
  */
-       static void
+static
 exec_mca()
 {
 exec_mca()
 {
+       extern int file;
+       extern char *tagfile;
        register char *p;
        register char *p;
+       char *glob();
 
        *cp = '\0';
        cmd_exec();
 
        *cp = '\0';
        cmd_exec();
-       switch (mca)
-       {
+       switch (mca) {
        case A_F_SEARCH:
        case A_F_SEARCH:
-               search(1, cmdbuf, number, wsearch);
+               (void)search(1, cmdbuf, number, wsearch);
                break;
        case A_B_SEARCH:
                break;
        case A_B_SEARCH:
-               search(0, cmdbuf, number, wsearch);
-               break;
-       case A_FIRSTCMD:
-               /*
-                * Skip leading spaces or + signs in the string.
-                */
-               for (p = cmdbuf;  *p == '+' || *p == ' ';  p++)
-                       ;
-               if (every_first_cmd != NULL)
-                       free(every_first_cmd);
-               if (*p == '\0')
-                       every_first_cmd = NULL;
-               else
-                       every_first_cmd = save(p);
-               break;
-       case A_TOGGLE_OPTION:
-               toggle_option(cmdbuf, 1);
+               (void)search(0, cmdbuf, number, wsearch);
                break;
        case A_EXAMINE:
                break;
        case A_EXAMINE:
-               /*
-                * Ignore leading spaces in the filename.
-                */
-               for (p = cmdbuf;  *p == ' ';  p++)
-                       ;
-               edit(glob(p));
+               for (p = cmdbuf; isspace(*p); ++p);
+               (void)edit(glob(p));
+               break;
+       case A_TAGFILE:
+               for (p = cmdbuf; isspace(*p); ++p);
+               findtag(p);
+               if (tagfile == NULL)
+                       break;
+               if (edit(tagfile))
+                       (void)tagsearch();
                break;
        }
 }
                break;
        }
 }
@@ -311,56 +299,28 @@ exec_mca()
 /*
  * Add a character to a multi-character command.
  */
 /*
  * Add a character to a multi-character command.
  */
-       static int
+static
 mca_char(c)
        int c;
 {
 mca_char(c)
        int c;
 {
-       switch (mca)
-       {
-       case 0:
-               /*
-                * Not in a multicharacter command.
-                */
-               return (NO_MCA);
-
-       case A_PREFIX:
-               /*
-                * In the prefix of a command.
-                */
-               return (NO_MCA);
-
+       switch (mca) {
+       case 0:                 /* not in a multicharacter command. */
+       case A_PREFIX:          /* in the prefix of a command. */
+               return(NO_MCA);
        case A_DIGIT:
                /*
                 * Entering digits of a number.
                 * Terminated by a non-digit.
                 */
        case A_DIGIT:
                /*
                 * Entering digits of a number.
                 * Terminated by a non-digit.
                 */
-               if ((c < '0' || c > '9') &&
-                       c != erase_char && c != kill_char)
-               {
+               if (!isascii(c) || !isdigit(c) &&
+                   c != erase_char && c != kill_char && c != werase_char) {
                        /*
                         * Not part of the number.
                         * Treat as a normal command character.
                         */
                        number = cmd_int();
                        mca = 0;
                        /*
                         * Not part of the number.
                         * Treat as a normal command character.
                         */
                        number = cmd_int();
                        mca = 0;
-                       return (NO_MCA);
-               }
-               break;
-
-       case A_TOGGLE_OPTION:
-               /*
-                * Special case for the TOGGLE_OPTION command.
-                * if the option letter which was entered is a
-                * single-char option, execute the command immediately,
-                * so he doesn't have to hit RETURN.
-                */
-               if (cp == cmdbuf && c != erase_char && c != kill_char &&
-                   single_char_option(c))
-               {
-                       cmdbuf[0] = c;
-                       cmdbuf[1] = '\0';
-                       toggle_option(cmdbuf, 1);
-                       return (MCA_DONE);
+                       return(NO_MCA);
                }
                break;
        }
                }
                break;
        }
@@ -369,13 +329,12 @@ mca_char(c)
         * Any other multicharacter command
         * is terminated by a newline.
         */
         * Any other multicharacter command
         * is terminated by a newline.
         */
-       if (c == '\n' || c == '\r')
-       {
+       if (c == '\n' || c == '\r') {
                /*
                 * Execute the command.
                 */
                exec_mca();
                /*
                 * Execute the command.
                 */
                exec_mca();
-               return (MCA_DONE);
+               return(MCA_DONE);
        }
        /*
         * Append the char to the command buffer.
        }
        /*
         * Append the char to the command buffer.
@@ -384,18 +343,17 @@ mca_char(c)
                /*
                 * Abort the multi-char command.
                 */
                /*
                 * Abort the multi-char command.
                 */
-               return (MCA_DONE);
+               return(MCA_DONE);
        /*
         * Need another character.
         */
        /*
         * Need another character.
         */
-       return (MCA_MORE);
+       return(MCA_MORE);
 }
 
 /*
  * Main command processor.
  * Accept and execute commands until a quit command, then return.
  */
 }
 
 /*
  * Main command processor.
  * Accept and execute commands until a quit command, then return.
  */
-       public void
 commands()
 {
        register int c;
 commands()
 {
        register int c;
@@ -404,16 +362,14 @@ commands()
        last_mca = 0;
        scroll = (sc_height + 1) / 2;
 
        last_mca = 0;
        scroll = (sc_height + 1) / 2;
 
-       for (;;)
-       {
+       for (;;) {
                mca = 0;
                number = 0;
 
                /*
                 * See if any signals need processing.
                 */
                mca = 0;
                number = 0;
 
                /*
                 * See if any signals need processing.
                 */
-               if (sigs)
-               {
+               if (sigs) {
                        psignals();
                        if (quitting)
                                quit();
                        psignals();
                        if (quitting)
                                quit();
@@ -422,7 +378,10 @@ commands()
                 * Display prompt and accept a character.
                 */
                cmd_reset();
                 * Display prompt and accept a character.
                 */
                cmd_reset();
-               prompt();
+               if (!prompt()) {
+                       next_file(1);
+                       continue;
+               }
                noprefix();
                c = getcc();
 
                noprefix();
                c = getcc();
 
@@ -435,8 +394,7 @@ again:              if (sigs)
                 * action to be performed.
                 */
                if (mca)
                 * action to be performed.
                 */
                if (mca)
-                       switch (mca_char(c))
-                       {
+                       switch (mca_char(c)) {
                        case MCA_MORE:
                                /*
                                 * Need another character.
                        case MCA_MORE:
                                /*
                                 * Need another character.
@@ -587,21 +545,11 @@ again:            if (sigs)
                                jump_back(number);
                        break;
 
                                jump_back(number);
                        break;
 
-               case A_STAT:
-                       /*
-                        * Print file name, etc.
-                        */
-                       cmd_exec();
-                       lower_left();
-                       clear_eol();
-                       putstr(eq_message());
-                       lower_left();
-                       c = getcc();
-                       goto again;
-               case A_QUIT:
-                       /*
-                        * Exit.
-                        */
+               case A_STAT:            /* print file name, etc. */
+                       longprompt = 1;
+                       continue;
+
+               case A_QUIT:            /* exit */
                        quit();
 
                case A_F_SEARCH:
                        quit();
 
                case A_F_SEARCH:
@@ -616,8 +564,7 @@ again:              if (sigs)
                        last_mca = mca;
                        wsearch = 1;
                        c = getcc();
                        last_mca = mca;
                        wsearch = 1;
                        c = getcc();
-                       if (c == '!')
-                       {
+                       if (c == '!') {
                                /*
                                 * Invert the sense of the search.
                                 * Set wsearch to 0 and get a new
                                /*
                                 * Invert the sense of the search.
                                 * Set wsearch to 0 and get a new
@@ -643,7 +590,8 @@ again:              if (sigs)
                                start_mca(last_mca, 
                                        (last_mca==A_F_SEARCH) ? "!/" : "!?");
                        cmd_exec();
                                start_mca(last_mca, 
                                        (last_mca==A_F_SEARCH) ? "!/" : "!?");
                        cmd_exec();
-                       search(mca==A_F_SEARCH, (char *)NULL, number, wsearch);
+                       (void)search(mca == A_F_SEARCH, (char *)NULL,
+                           number, wsearch);
                        break;
 
                case A_HELP:
                        break;
 
                case A_HELP:
@@ -657,15 +605,18 @@ again:            if (sigs)
                        help();
                        break;
 
                        help();
                        break;
 
-               case A_EXAMINE:
-                       /*
-                        * Edit a new file.  Get the filename.
-                        */
+               case A_TAGFILE:         /* tag a new file; get the file name */
+                       cmd_reset();
+                       start_mca(A_TAGFILE, "Tag: ");
+                       c = getcc();
+                       goto again;
+
+               case A_EXAMINE:         /* edit a new file; get the file name */
                        cmd_reset();
                        start_mca(A_EXAMINE, "Examine: ");
                        c = getcc();
                        goto again;
                        cmd_reset();
                        start_mca(A_EXAMINE, "Examine: ");
                        c = getcc();
                        goto again;
-                       
+
                case A_VISUAL:
                        /*
                         * Invoke an editor on the input file.
                case A_VISUAL:
                        /*
                         * Invoke an editor on the input file.
@@ -699,38 +650,6 @@ again:             if (sigs)
                        prev_file(number);
                        break;
 
                        prev_file(number);
                        break;
 
-               case A_TOGGLE_OPTION:
-                       /*
-                        * Toggle a flag setting.
-                        */
-                       cmd_reset();
-                       start_mca(A_TOGGLE_OPTION, "-");
-                       c = getcc();
-                       goto again;
-
-               case A_DISP_OPTION:
-                       /*
-                        * Report a flag setting.
-                        */
-                       cmd_reset();
-                       start_mca(A_DISP_OPTION, "_");
-                       c = getcc();
-                       if (c == erase_char || c == kill_char)
-                               break;
-                       cmdbuf[0] = c;
-                       cmdbuf[1] = '\0';
-                       toggle_option(cmdbuf, 0);
-                       break;
-
-               case A_FIRSTCMD:
-                       /*
-                        * Set an initial command for new files.
-                        */
-                       cmd_reset();
-                       start_mca(A_FIRSTCMD, "+");
-                       c = getcc();
-                       goto again;
-
                case A_SETMARK:
                        /*
                         * Set a mark.
                case A_SETMARK:
                        /*
                         * Set a mark.
@@ -765,10 +684,10 @@ again:            if (sigs)
                         */
                        if (mca != A_PREFIX)
                                start_mca(A_PREFIX, "& ");
                         */
                        if (mca != A_PREFIX)
                                start_mca(A_PREFIX, "& ");
-                       if (control_char(c))
+                       if (CONTROL_CHAR(c))
                        {
                                putchr('^');
                        {
                                putchr('^');
-                               c = carat_char(c);
+                               c = CARAT_CHAR(c);
                        }
                        putchr(c);
                        c = getcc();
                        }
                        putchr(c);
                        c = getcc();
@@ -784,16 +703,18 @@ again:            if (sigs)
 static
 editfile()
 {
 static
 editfile()
 {
+       extern char *current_file;
        static int dolinenumber;
        static char *editor;
        int c;
        static int dolinenumber;
        static char *editor;
        int c;
-       char buf[MAXPATHLEN], *getenv();
+       char buf[MAXPATHLEN * 2 + 20], *getenv();
 
        if (editor == NULL) {
                editor = getenv("EDITOR");
                /* pass the line number to vi */
                if (editor == NULL || *editor == '\0') {
 
        if (editor == NULL) {
                editor = getenv("EDITOR");
                /* pass the line number to vi */
                if (editor == NULL || *editor == '\0') {
-                       editor = "/usr/ucb/vi";
+#define        EDIT_PGM        "/usr/ucb/vi"
+                       editor = EDIT_PGM;
                        dolinenumber = 1;
                }
                else
                        dolinenumber = 1;
                }
                else
index 4f7f98f..5272ac9 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)decode.c   5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)decode.c   5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -35,29 +35,24 @@ static char sccsid[] = "@(#)decode.c        5.5 (Berkeley) %G%";
  * with the command string.
  *
  * The default commands are described by cmdtable.
  * with the command string.
  *
  * The default commands are described by cmdtable.
- * User-defined commands are read into usertable.
  */
 
  */
 
-#include "less.h"
-#include "cmd.h"
+#include <sys/param.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <less.h>
 
 /*
  * Command table is ordered roughly according to expected
  * frequency of use, so the common commands are near the beginning.
  */
 
 /*
  * Command table is ordered roughly according to expected
  * frequency of use, so the common commands are near the beginning.
  */
-static char cmdtable[] =
-{
+#define        CONTROL(c)              ((c)&037)
+
+static char cmdtable[] = {
        '\r',0,                         A_F_LINE,
        '\n',0,                         A_F_LINE,
        '\r',0,                         A_F_LINE,
        '\n',0,                         A_F_LINE,
-       'e',0,                          A_F_LINE,
        'j',0,                          A_F_LINE,
        'j',0,                          A_F_LINE,
-       CONTROL('E'),0,                 A_F_LINE,
-       CONTROL('N'),0,                 A_F_LINE,
        'k',0,                          A_B_LINE,
        'k',0,                          A_B_LINE,
-       'y',0,                          A_B_LINE,
-       CONTROL('Y'),0,                 A_B_LINE,
-       CONTROL('K'),0,                 A_B_LINE,
-       CONTROL('P'),0,                 A_B_LINE,
        'd',0,                          A_F_SCROLL,
        CONTROL('D'),0,                 A_F_SCROLL,
        'u',0,                          A_B_SCROLL,
        'd',0,                          A_F_SCROLL,
        CONTROL('D'),0,                 A_F_SCROLL,
        'u',0,                          A_B_SCROLL,
@@ -65,23 +60,15 @@ static char cmdtable[] =
        ' ',0,                          A_F_SCREEN,
        'f',0,                          A_F_SCREEN,
        CONTROL('F'),0,                 A_F_SCREEN,
        ' ',0,                          A_F_SCREEN,
        'f',0,                          A_F_SCREEN,
        CONTROL('F'),0,                 A_F_SCREEN,
-       CONTROL('V'),0,                 A_F_SCREEN,
        'b',0,                          A_B_SCREEN,
        CONTROL('B'),0,                 A_B_SCREEN,
        'b',0,                          A_B_SCREEN,
        CONTROL('B'),0,                 A_B_SCREEN,
-       CONTROL('['),'v',0,             A_B_SCREEN,
        'R',0,                          A_FREPAINT,
        'r',0,                          A_REPAINT,
        'R',0,                          A_FREPAINT,
        'r',0,                          A_REPAINT,
-       CONTROL('R'),0,                 A_REPAINT,
        CONTROL('L'),0,                 A_REPAINT,
        'g',0,                          A_GOLINE,
        CONTROL('L'),0,                 A_REPAINT,
        'g',0,                          A_GOLINE,
-       '<',0,                          A_GOLINE,
-       CONTROL('['),'<',0,             A_GOLINE,
        'p',0,                          A_PERCENT,
        '%',0,                          A_PERCENT,
        'G',0,                          A_GOEND,
        'p',0,                          A_PERCENT,
        '%',0,                          A_PERCENT,
        'G',0,                          A_GOEND,
-       CONTROL('['),'>',0,             A_GOEND,
-       '>',0,                          A_GOEND,
-
        '0',0,                          A_DIGIT,
        '1',0,                          A_DIGIT,
        '2',0,                          A_DIGIT,
        '0',0,                          A_DIGIT,
        '1',0,                          A_DIGIT,
        '2',0,                          A_DIGIT,
@@ -100,39 +87,39 @@ static char cmdtable[] =
        'n',0,                          A_AGAIN_SEARCH,
        'm',0,                          A_SETMARK,
        '\'',0,                         A_GOMARK,
        'n',0,                          A_AGAIN_SEARCH,
        'm',0,                          A_SETMARK,
        '\'',0,                         A_GOMARK,
-       CONTROL('X'),CONTROL('X'),0,    A_GOMARK,
        'E',0,                          A_EXAMINE,
        'E',0,                          A_EXAMINE,
-       ':','e',0,                      A_EXAMINE,
-       CONTROL('X'),CONTROL('V'),0,    A_EXAMINE,
        'N',0,                          A_NEXT_FILE,
        'N',0,                          A_NEXT_FILE,
-       'P',0,                          A_PREV_FILE,
        ':','n',0,                      A_NEXT_FILE,
        ':','n',0,                      A_NEXT_FILE,
+       'P',0,                          A_PREV_FILE,
        ':','p',0,                      A_PREV_FILE,
        ':','p',0,                      A_PREV_FILE,
-       '-',0,                          A_TOGGLE_OPTION,
-       '_',0,                          A_DISP_OPTION,
        'v',0,                          A_VISUAL,
        'v',0,                          A_VISUAL,
-       '!',0,                          A_SHELL,
-       '+',0,                          A_FIRSTCMD,
 
 
-       'H',0,                          A_HELP,
        'h',0,                          A_HELP,
        'q',0,                          A_QUIT,
        ':','q',0,                      A_QUIT,
        'h',0,                          A_HELP,
        'q',0,                          A_QUIT,
        ':','q',0,                      A_QUIT,
-       'Z','Z',0,                      A_QUIT
+       ':','t',0,                      A_TAGFILE,
+       'Z','Z',0,                      A_QUIT,
 };
 
 char *cmdendtable = cmdtable + sizeof(cmdtable);
 
 };
 
 char *cmdendtable = cmdtable + sizeof(cmdtable);
 
-static char usertable[MAX_USERCMD];
-char *userendtable = usertable;
+#define        MAX_CMDLEN      16
 
 static char kbuf[MAX_CMDLEN+1];
 static char *kp = kbuf;
 
 
 static char kbuf[MAX_CMDLEN+1];
 static char *kp = kbuf;
 
+/*
+ * Indicate that we're not in a prefix command
+ * by resetting the command buffer pointer.
+ */
+noprefix()
+{
+       kp = kbuf;
+}
+
 /*
  * Decode a command character and return the associated action.
  */
 /*
  * Decode a command character and return the associated action.
  */
-       public int
 cmd_decode(c)
        int c;
 {
 cmd_decode(c)
        int c;
 {
@@ -144,51 +131,26 @@ cmd_decode(c)
        *kp++ = c;
        *kp = '\0';
 
        *kp++ = c;
        *kp = '\0';
 
-       /*
-        * Look first for any user-defined commands.
-        */
-       action = cmd_search(usertable, userendtable);
-       /*
-        * If didn't find user-defined command,
-        * try the normal default commands.
-        */
-       if (action == A_INVALID)
-               action = cmd_search(cmdtable, cmdendtable);
+       action = cmd_search(cmdtable, cmdendtable);
 
 
+       /* This is not a prefix character. */
        if (action != A_PREFIX)
        if (action != A_PREFIX)
-               /*
-                * This is not a prefix character.
-                */
                noprefix();
                noprefix();
-
-       return (action);
-}
-
-/*
- * Indicate that we're not in a prefix command
- * by resetting the command buffer pointer.
- */
-       public void
-noprefix()
-{
-       kp = kbuf;
+       return(action);
 }
 
 /*
  * Search a command table for the current command string (in kbuf).
  */
 }
 
 /*
  * Search a command table for the current command string (in kbuf).
  */
-       static int
+static
 cmd_search(table, endtable)
        char *table;
        char *endtable;
 {
 cmd_search(table, endtable)
        char *table;
        char *endtable;
 {
-       register char *p;
-       register char *q;
+       register char *p, *q;
 
 
-       for (p = table, q = kbuf;  p < endtable;  p++, q++)
-       {
-               if (*p == *q)
-               {
+       for (p = table, q = kbuf;  p < endtable;  p++, q++) {
+               if (*p == *q) {
                        /*
                         * Current characters match.
                         * If we're at the end of the string, we've found it.
                        /*
                         * Current characters match.
                         * If we're at the end of the string, we've found it.
@@ -197,82 +159,28 @@ cmd_search(table, endtable)
                         * in the command table.
                         */
                        if (*p == '\0')
                         * in the command table.
                         */
                        if (*p == '\0')
-                               return (p[1]);
-               } else if (*q == '\0')
-               {
+                               return(p[1]);
+               }
+               else if (*q == '\0') {
                        /*
                         * Hit the end of the user's command,
                         * but not the end of the string in the command table.
                         * The user's command is incomplete.
                         */
                        /*
                         * Hit the end of the user's command,
                         * but not the end of the string in the command table.
                         * The user's command is incomplete.
                         */
-                       return (A_PREFIX);
-               } else
-               {
+                       return(A_PREFIX);
+               } else {
                        /*
                         * Not a match.
                         * Skip ahead to the next command in the
                         * command table, and reset the pointer
                         * to the user's command.
                         */
                        /*
                         * Not a match.
                         * Skip ahead to the next command in the
                         * command table, and reset the pointer
                         * to the user's command.
                         */
-                       while (*p++ != '\0') ;
+                       while (*p++ != '\0');
                        q = kbuf-1;
                }
        }
        /*
         * No match found in the entire command table.
         */
                        q = kbuf-1;
                }
        }
        /*
         * No match found in the entire command table.
         */
-       return (A_INVALID);
-}
-
-/*
- * Initialize the user command table.
- */
-       public void
-init_cmd()
-{
-       char *homedir;
-       int f;
-       int n;
-       char filename[MAXPATHLEN];
-       extern char *getenv();
-
-       /*
-        * Try to open "$HOME/.less"
-        * If we can't, return without doing anything.
-        */
-       homedir = getenv("HOME");
-       if (homedir == NULL)
-               return;
-       (void)sprintf(filename, "%s/%s", homedir, ".less");
-       f = open(filename, O_RDONLY);
-       if (f < 0)
-               return;
-
-       /*
-        * Read the file into the user table.
-        * {{ Minimal error checking is done here.
-        *    A garbage .less file will produce strange results.
-        *    To avoid a large amount of error checking code here, we
-        *    rely on the lesskey program to generate a good .less file. }}
-        */
-       n = read(f, (char *)usertable, MAX_USERCMD);
-       if (n < 3 || usertable[n-2] != '\0')
-       {
-               /*
-                * Several error cases are lumped together here:
-                * - Cannot read user file (n < 0).
-                * - User file is too short (a valid file must
-                *   have at least 3 chars: one char command string,
-                *   the terminating null byte, and the action byte).
-                * - The final entry in the user file is bad (it
-                *   doesn't have a null byte in the proper place).
-                * Many other error cases are not caught, such as
-                * invalid format in any except the last entry,
-                * invalid action codes, command strings too long, etc.
-                */
-               error("invalid user key file");
-               n = 0;
-       }
-       userendtable = usertable + n;
-       close(f);
+       return(A_INVALID);
 }
 }
index 7e35119..b0f2d91 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)help.c     5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)help.c     5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include  "less.h"
+#include <sys/param.h>
+#include <less.h>
 
 
-/*
- * Display some help.
- * Just invoke another "less" to display the help file.
- *
- * {{ This makes this function very simple, and makes changing the
- *    help file very easy, but it may present difficulties on
- *    (non-Unix) systems which do not supply the "system()" function. }}
- */
-
-       public void
+#define        HELPFILE        "/usr/lib/more.help"
 help()
 {
 help()
 {
-       char cmd[MAXPATHLEN+100];
+       char cmd[MAXPATHLEN + 20];
 
 
-       (void)sprintf(cmd,
-        "-less -m '-PmHELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done ' %s",
-        HELPFILE);
+       (void)sprintf(cmd, "-more %s", HELPFILE);
        lsystem(cmd);
 }
        lsystem(cmd);
 }
index 064c004..a49b8e5 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)input.c    5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)input.c    5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -31,12 +31,15 @@ static char sccsid[] = "@(#)input.c 5.2 (Berkeley) %G%";
  * delimited by newlines; not processed with respect to screen width.
  */
 
  * delimited by newlines; not processed with respect to screen width.
  */
 
-#include "less.h"
+#include <sys/types.h>
+#include <less.h>
 
 extern int squeeze;
 extern int sigs;
 extern char *line;
 
 
 extern int squeeze;
 extern int sigs;
 extern char *line;
 
+off_t ch_tell();
+
 /*
  * Get the next line.
  * A "current" position is passed and a "new" position is returned.
 /*
  * Get the next line.
  * A "current" position is passed and a "new" position is returned.
@@ -44,11 +47,11 @@ extern char *line;
  * a line.  The new position is the position of the first character
  * of the NEXT line.  The line obtained is the line starting at curr_pos.
  */
  * a line.  The new position is the position of the first character
  * of the NEXT line.  The line obtained is the line starting at curr_pos.
  */
-       public POSITION
+off_t
 forw_line(curr_pos)
 forw_line(curr_pos)
-       POSITION curr_pos;
+       off_t curr_pos;
 {
 {
-       POSITION new_pos;
+       off_t new_pos;
        register int c;
 
        if (curr_pos == NULL_POSITION || ch_seek(curr_pos))
        register int c;
 
        if (curr_pos == NULL_POSITION || ch_seek(curr_pos))
@@ -114,14 +117,14 @@ forw_line(curr_pos)
  * a line.  The new position is the position of the first character
  * of the PREVIOUS line.  The line obtained is the one starting at new_pos.
  */
  * a line.  The new position is the position of the first character
  * of the PREVIOUS line.  The line obtained is the one starting at new_pos.
  */
-       public POSITION
+off_t
 back_line(curr_pos)
 back_line(curr_pos)
-       POSITION curr_pos;
+       off_t curr_pos;
 {
 {
-       POSITION new_pos, begin_new_pos;
+       off_t new_pos, begin_new_pos;
        int c;
 
        int c;
 
-       if (curr_pos == NULL_POSITION || curr_pos <= (POSITION)0 ||
+       if (curr_pos == NULL_POSITION || curr_pos <= (off_t)0 ||
                ch_seek(curr_pos-1))
                return (NULL_POSITION);
 
                ch_seek(curr_pos-1))
                return (NULL_POSITION);
 
index 7716371..48ba237 100644 (file)
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)less.h      5.6 (Berkeley) %G%
+ *     @(#)less.h      5.7 (Berkeley) %G%
  */
 
  */
 
-/*
- * Standard include file for "less".
- */
-
-/*
- * Language details.
- */
-#define        public          /* PUBLIC FUNCTION */
-
-/*
- * Special types and constants.
- */
-typedef long           POSITION;
-/*
- * {{ Warning: if POSITION is changed to other than "long",
- *    you may have to change some of the printfs which use "%ld"
- *    to print a variable of type POSITION. }}
- */
+#define        RECOMP
 
 
-#define        NULL_POSITION   ((POSITION)(-1))
-
-/*
- * The type of signal handler functions.
- * Usually int, although it should be void.
- */
-typedef        int             HANDLER;
-
-
-#define        FILENAME        128     /* Max size of a filename */
+#define        NULL_POSITION   ((off_t)(-1))
 
 #define        EOI             (0)
 
 #define        EOI             (0)
-
 #define        READ_INTR       (-2)
 
 #define        READ_INTR       (-2)
 
-/* How quiet should we be? */
-#define        NOT_QUIET       0       /* Ring bell at eof and for errors */
-#define        LITTLE_QUIET    1       /* Ring bell only for errors */
-#define        VERY_QUIET      2       /* Never ring bell */
-
-/* How should we prompt? */
-#define        PR_SHORT        0       /* Prompt with colon */
-#define        PR_MEDIUM       1       /* Prompt with message */
-#define        PR_LONG         2       /* Prompt with longer message */
-
-/* How should we handle backspaces? */
-#define        BS_SPECIAL      0       /* Do special things for underlining and bold */
-#define        BS_NORMAL       1       /* \b treated as normal char; actually output */
-#define        BS_CONTROL      2       /* \b treated as control char; prints as ^H */
-
 /* Special chars used to tell put_line() to do something special */
 /* Special chars used to tell put_line() to do something special */
-#define        UL_CHAR         '\201'  /* Enter underline mode */
-#define        UE_CHAR         '\202'  /* Exit underline mode */
-#define        BO_CHAR         '\203'  /* Enter boldface mode */
-#define        BE_CHAR         '\204'  /* Exit boldface mode */
-
-#define        CONTROL(c)              ((c)&037)
-
-#include <sys/param.h>
-#include <sys/file.h>
-
-/* Library function declarations */
-off_t lseek();
-char *calloc();
-
-#include "funcs.h"
+#define        UL_CHAR         '\201'          /* Enter underline mode */
+#define        UE_CHAR         '\202'          /* Exit underline mode */
+#define        BO_CHAR         '\203'          /* Enter boldface mode */
+#define        BE_CHAR         '\204'          /* Exit boldface mode */
+
+#define        CONTROL_CHAR(c)         (iscntrl(c))
+#define        CARAT_CHAR(c)           ((c == '\177') ? '?' : (c | 0100))
+
+#define        TOP             (0)
+#define        TOP_PLUS_ONE    (1)
+#define        BOTTOM          (-1)
+#define        BOTTOM_PLUS_ONE (-2)
+#define        MIDDLE          (-3)
+
+#define        A_INVALID               -1
+
+#define        A_AGAIN_SEARCH          1
+#define        A_B_LINE                2
+#define        A_B_SCREEN              3
+#define        A_B_SCROLL              4
+#define        A_B_SEARCH              5
+#define        A_DIGIT                 6
+#define        A_EXAMINE               7
+#define        A_FREPAINT              8
+#define        A_F_LINE                9
+#define        A_F_SCREEN              10
+#define        A_F_SCROLL              11
+#define        A_F_SEARCH              12
+#define        A_GOEND                 13
+#define        A_GOLINE                14
+#define        A_GOMARK                15
+#define        A_HELP                  16
+#define        A_NEXT_FILE             17
+#define        A_PERCENT               18
+#define        A_PREFIX                19
+#define        A_PREV_FILE             20
+#define        A_QUIT                  21
+#define        A_REPAINT               22
+#define        A_SETMARK               23
+#define        A_STAT                  24
+#define        A_VISUAL                25
+#define        A_TAGFILE               26
index 04e2427..87775af 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)line.c     5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)line.c     5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -28,17 +28,19 @@ static char sccsid[] = "@(#)line.c  5.2 (Berkeley) %G%";
  * We keep track of the PRINTABLE length of the line as it is being built.
  */
 
  * We keep track of the PRINTABLE length of the line as it is being built.
  */
 
-#include "less.h"
+#include <sys/types.h>
+#include <ctype.h>
+#include <less.h>
 
 static char linebuf[1024];     /* Buffer which holds the current output line */
 static char *curr;             /* Pointer into linebuf */
 static int column;             /* Printable length, accounting for
                                   backspaces, etc. */
 /*
 
 static char linebuf[1024];     /* Buffer which holds the current output line */
 static char *curr;             /* Pointer into linebuf */
 static int column;             /* Printable length, accounting for
                                   backspaces, etc. */
 /*
- * A ridiculously complex state machine takes care of backspaces 
- * when in BS_SPECIAL mode.  The complexity arises from the attempt
- * to deal with all cases, especially involving long lines with underlining,
- * boldfacing or whatever.  There are still some cases which will break it.
+ * A ridiculously complex state machine takes care of backspaces.  The
+ * complexity arises from the attempt to deal with all cases, especially
+ * involving long lines with underlining, boldfacing or whatever.  There
+ * are still some cases which will break it.
  *
  * There are four states:
  *     LN_NORMAL is the normal state (not in underline mode).
  *
  * There are four states:
  *     LN_NORMAL is the normal state (not in underline mode).
@@ -70,7 +72,7 @@ static int ln_state;          /* Currently in normal/underline/bold/etc mode? */
 #define        LN_BO_X         5       /* In boldface, got char, need \b */
 #define        LN_BO_XB        6       /* In boldface, got char & \b, need same char */
 
 #define        LN_BO_X         5       /* In boldface, got char, need \b */
 #define        LN_BO_XB        6       /* In boldface, got char & \b, need same char */
 
-public char *line;             /* Pointer to the current line.
+char *line;                    /* Pointer to the current line.
                                   Usually points to linebuf. */
 
 extern int bs_mode;
                                   Usually points to linebuf. */
 
 extern int bs_mode;
@@ -82,7 +84,6 @@ extern int sc_width, sc_height;
 /*
  * Rewind the line buffer.
  */
 /*
  * Rewind the line buffer.
  */
-       public void
 prewind()
 {
        line = curr = linebuf;
 prewind()
 {
        line = curr = linebuf;
@@ -95,22 +96,21 @@ prewind()
  * Expand tabs into spaces, handle underlining, boldfacing, etc.
  * Returns 0 if ok, 1 if couldn't fit in buffer.
  */
  * Expand tabs into spaces, handle underlining, boldfacing, etc.
  * Returns 0 if ok, 1 if couldn't fit in buffer.
  */
+#define        NEW_COLUMN(addon) \
+       if (column + addon + (ln_state ? ue_width : 0) > sc_width) \
+               return(1); \
+       else \
+               column += addon
 
 
-#define        NEW_COLUMN(newcol)      if ((newcol) + ((ln_state)?ue_width:0) > sc_width) \
-                                       return (1); else column = (newcol)
-
-       public int
 pappend(c)
        int c;
 {
 pappend(c)
        int c;
 {
-       if (c == '\0')
-       {
+       if (c == '\0') {
                /*
                 * Terminate any special modes, if necessary.
                 * Append a '\0' to the end of the line.
                 */
                /*
                 * Terminate any special modes, if necessary.
                 * Append a '\0' to the end of the line.
                 */
-               switch (ln_state)
-               {
+               switch (ln_state) {
                case LN_UL_X:
                        curr[0] = curr[-1];
                        curr[-1] = UE_CHAR;
                case LN_UL_X:
                        curr[0] = curr[-1];
                        curr[-1] = UE_CHAR;
@@ -132,7 +132,7 @@ pappend(c)
                }
                ln_state = LN_NORMAL;
                *curr = '\0';
                }
                ln_state = LN_NORMAL;
                *curr = '\0';
-               return (0);
+               return(0);
        }
 
        if (curr > linebuf + sizeof(linebuf) - 12)
        }
 
        if (curr > linebuf + sizeof(linebuf) - 12)
@@ -143,19 +143,18 @@ pappend(c)
                 *    will never happen, but may need to be made 
                 *    bigger for wide screens or lots of backspaces. }}
                 */
                 *    will never happen, but may need to be made 
                 *    bigger for wide screens or lots of backspaces. }}
                 */
-               return (1);
+               return(1);
 
 
-       if (bs_mode == BS_SPECIAL)
-       {
+       if (!bs_mode) {
                /*
                 * Advance the state machine.
                 */
                /*
                 * Advance the state machine.
                 */
-               switch (ln_state)
-               {
+               switch (ln_state) {
                case LN_NORMAL:
                case LN_NORMAL:
-                       if (curr <= linebuf + 1 || curr[-1] != '\b')
+                       if (curr <= linebuf + 1
+                           || curr[-1] != (char)('H' | 0200))
                                break;
                                break;
-
+                       column -= 2;
                        if (c == curr[-2])
                                goto enter_boldface;
                        if (c == '_' || curr[-2] == '_')
                        if (c == curr[-2])
                                goto enter_boldface;
                        if (c == '_' || curr[-2] == '_')
@@ -175,9 +174,8 @@ enter_boldface:
                                 */
                                return (1);
 
                                 */
                                return (1);
 
-                       if (bo_width > 0 && 
-                           curr > linebuf + 2 && curr[-3] == ' ')
-                       {
+                       if (bo_width > 0 && curr > linebuf + 2
+                           && curr[-3] == ' ') {
                                /*
                                 * Special case for magic cookie terminals:
                                 * if the previous char was a space, replace 
                                /*
                                 * Special case for magic cookie terminals:
                                 * if the previous char was a space, replace 
@@ -185,8 +183,7 @@ enter_boldface:
                                 */
                                curr[-3] = BO_CHAR;
                                column += bo_width-1;
                                 */
                                curr[-3] = BO_CHAR;
                                column += bo_width-1;
-                       } else
-                       {
+                       } else {
                                curr[-1] = curr[-2];
                                curr[-2] = BO_CHAR;
                                column += bo_width;
                                curr[-1] = curr[-2];
                                curr[-2] = BO_CHAR;
                                column += bo_width;
@@ -350,61 +347,44 @@ ln_bo_xb_case:
                        break;
                }
        }
                        break;
                }
        }
-       
-       if (c == '\t') 
-       {
+
+       if (c == '\t') {
                /*
                 * Expand a tab into spaces.
                 */
                /*
                 * Expand a tab into spaces.
                 */
-               do
-               {
-                       NEW_COLUMN(column+1);
+               do {
+                       NEW_COLUMN(1);
                } while ((column % tabstop) != 0);
                *curr++ = '\t';
                return (0);
        }
 
                } while ((column % tabstop) != 0);
                *curr++ = '\t';
                return (0);
        }
 
-       if (c == '\b')
-       {
-               if (bs_mode == BS_CONTROL)
-               {
-                       /*
-                        * Treat backspace as a control char: output "^H".
-                        */
-                       NEW_COLUMN(column+2);
-                       *curr++ = ('H' | 0200);
-               } else
-               {
-                       /*
-                        * Output a real backspace.
-                        */
+       if (c == '\b') {
+               if (ln_state == LN_NORMAL)
+                       NEW_COLUMN(2);
+               else
                        column--;
                        column--;
-                       *curr++ = '\b';
-               }
-               return (0);
+               *curr++ = ('H' | 0200);
+               return(0);
        } 
 
        } 
 
-       if (control_char(c))
-       {
+       if (CONTROL_CHAR(c)) {
                /*
                /*
-                * Put a "^X" into the buffer.
-                * The 0200 bit is used to tell put_line() to prefix
-                * the char with a ^.  We don't actually put the ^
-                * in the buffer because we sometimes need to move
-                * chars around, and such movement might separate 
-                * the ^ from its following character.
-                * {{ This should be redone so that we can use an
-                *    8 bit (e.g. international) character set. }}
+                * Put a "^X" into the buffer.  The 0200 bit is used to tell
+                * put_line() to prefix the char with a ^.  We don't actually
+                * put the ^ in the buffer because we sometimes need to move
+                * chars around, and such movement might separate the ^ from
+                * its following character.
                 */
                 */
-               NEW_COLUMN(column+2);
-               *curr++ = (carat_char(c) | 0200);
-               return (0);
+               NEW_COLUMN(2);
+               *curr++ = (CARAT_CHAR(c) | 0200);
+               return(0);
        }
 
        /*
         * Ordinary character.  Just put it in the buffer.
         */
        }
 
        /*
         * Ordinary character.  Just put it in the buffer.
         */
-       NEW_COLUMN(column+1);
+       NEW_COLUMN(1);
        *curr++ = c;
        return (0);
 }
        *curr++ = c;
        return (0);
 }
@@ -414,13 +394,13 @@ ln_bo_xb_case:
  * lines which are not split for screen width.
  * {{ This is supposed to be more efficient than forw_line(). }}
  */
  * lines which are not split for screen width.
  * {{ This is supposed to be more efficient than forw_line(). }}
  */
-       public POSITION
+off_t
 forw_raw_line(curr_pos)
 forw_raw_line(curr_pos)
-       POSITION curr_pos;
+       off_t curr_pos;
 {
        register char *p;
        register int c;
 {
        register char *p;
        register int c;
-       POSITION new_pos;
+       off_t new_pos, ch_tell();
 
        if (curr_pos == NULL_POSITION || ch_seek(curr_pos) ||
                (c = ch_forw_get()) == EOI)
 
        if (curr_pos == NULL_POSITION || ch_seek(curr_pos) ||
                (c = ch_forw_get()) == EOI)
@@ -458,15 +438,15 @@ forw_raw_line(curr_pos)
  * Analogous to back_line(), but deals with "raw lines".
  * {{ This is supposed to be more efficient than back_line(). }}
  */
  * Analogous to back_line(), but deals with "raw lines".
  * {{ This is supposed to be more efficient than back_line(). }}
  */
-       public POSITION
+off_t
 back_raw_line(curr_pos)
 back_raw_line(curr_pos)
-       POSITION curr_pos;
+       off_t curr_pos;
 {
        register char *p;
        register int c;
 {
        register char *p;
        register int c;
-       POSITION new_pos;
+       off_t new_pos, ch_tell();
 
 
-       if (curr_pos == NULL_POSITION || curr_pos <= (POSITION)0 ||
+       if (curr_pos == NULL_POSITION || curr_pos <= (off_t)0 ||
                ch_seek(curr_pos-1))
                return (NULL_POSITION);
 
                ch_seek(curr_pos-1))
                return (NULL_POSITION);
 
@@ -492,7 +472,7 @@ back_raw_line(curr_pos)
                         * This must be the first line in the file.
                         * This must, of course, be the beginning of the line.
                         */
                         * This must be the first line in the file.
                         * This must, of course, be the beginning of the line.
                         */
-                       new_pos = (POSITION)0;
+                       new_pos = (off_t)0;
                        break;
                }
                if (p <= linebuf)
                        break;
                }
                if (p <= linebuf)
index 1a5a5ec..5dc1f92 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)linenum.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)linenum.c  5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -45,8 +45,9 @@ static char sccsid[] = "@(#)linenum.c 5.4 (Berkeley) %G%";
  * called to make sure we cache line numbers often enough.
  */
 
  * called to make sure we cache line numbers often enough.
  */
 
-#include "less.h"
-#include "position.h"
+#include <sys/types.h>
+#include <stdio.h>
+#include <less.h>
 
 /*
  * Structure to keep track of a line number and the associated file position.
 
 /*
  * Structure to keep track of a line number and the associated file position.
@@ -56,8 +57,8 @@ struct linenum
 {
        struct linenum *next;           /* Link to next in the list */
        struct linenum *prev;           /* Line to previous in the list */
 {
        struct linenum *next;           /* Link to next in the list */
        struct linenum *prev;           /* Line to previous in the list */
-       POSITION pos;                   /* File position */
-       POSITION gap;                   /* Gap between prev and next */
+       off_t pos;                      /* File position */
+       off_t gap;                      /* Gap between prev and next */
        int line;                       /* Line number */
 };
 /*
        int line;                       /* Line number */
 };
 /*
@@ -73,7 +74,7 @@ struct linenum
 
 #define        LONGTIME        (2)             /* In seconds */
 
 
 #define        LONGTIME        (2)             /* In seconds */
 
-public int lnloop = 0;                 /* Are we in the line num loop? */
+int lnloop = 0;                                /* Are we in the line num loop? */
 
 static struct linenum anchor;          /* Anchor of the list */
 static struct linenum *freelist;       /* Anchor of the unused entries */
 
 static struct linenum anchor;          /* Anchor of the list */
 static struct linenum *freelist;       /* Anchor of the unused entries */
@@ -86,7 +87,6 @@ extern int sigs;
 /*
  * Initialize the line number structures.
  */
 /*
  * Initialize the line number structures.
  */
-       public void
 clr_linenum()
 {
        register struct linenum *p;
 clr_linenum()
 {
        register struct linenum *p;
@@ -107,14 +107,14 @@ clr_linenum()
         */
        anchor.next = anchor.prev = &anchor;
        anchor.gap = 0;
         */
        anchor.next = anchor.prev = &anchor;
        anchor.gap = 0;
-       anchor.pos = (POSITION)0;
+       anchor.pos = (off_t)0;
        anchor.line = 1;
 }
 
 /*
  * Calculate the gap for an entry.
  */
        anchor.line = 1;
 }
 
 /*
  * Calculate the gap for an entry.
  */
-       static void
+static
 calcgap(p)
        register struct linenum *p;
 {
 calcgap(p)
        register struct linenum *p;
 {
@@ -134,16 +134,15 @@ calcgap(p)
  * The specified position (pos) should be the file position of the
  * FIRST character in the specified line.
  */
  * The specified position (pos) should be the file position of the
  * FIRST character in the specified line.
  */
-       public void
 add_lnum(line, pos)
        int line;
 add_lnum(line, pos)
        int line;
-       POSITION pos;
+       off_t pos;
 {
        register struct linenum *p;
        register struct linenum *new;
        register struct linenum *nextp;
        register struct linenum *prevp;
 {
        register struct linenum *p;
        register struct linenum *new;
        register struct linenum *nextp;
        register struct linenum *prevp;
-       register POSITION mingap;
+       register off_t mingap;
 
        /*
         * Find the proper place in the list for the new one.
 
        /*
         * Find the proper place in the list for the new one.
@@ -222,7 +221,7 @@ add_lnum(line, pos)
  * If we get stuck in a long loop trying to figure out the
  * line number, print a message to tell the user what we're doing.
  */
  * If we get stuck in a long loop trying to figure out the
  * line number, print a message to tell the user what we're doing.
  */
-       static void
+static
 longloopmessage()
 {
        ierror("Calculating line numbers");
 longloopmessage()
 {
        ierror("Calculating line numbers");
@@ -238,15 +237,14 @@ longloopmessage()
  * Find the line number associated with a given position.
  * Return 0 if we can't figure it out.
  */
  * Find the line number associated with a given position.
  * Return 0 if we can't figure it out.
  */
-       public int
 find_linenum(pos)
 find_linenum(pos)
-       POSITION pos;
+       off_t pos;
 {
        register struct linenum *p;
        register int lno;
        register int loopcount;
 {
        register struct linenum *p;
        register int lno;
        register int loopcount;
-       POSITION cpos;
-       long startime;
+       off_t cpos, back_raw_line(), forw_raw_line();
+       time_t startime, time();
 
        if (!linenums)
                /*
 
        if (!linenums)
                /*
@@ -258,7 +256,7 @@ find_linenum(pos)
                 * Caller doesn't know what he's talking about.
                 */
                return (0);
                 * Caller doesn't know what he's talking about.
                 */
                return (0);
-       if (pos == (POSITION)0)
+       if (pos == (off_t)0)
                /*
                 * Beginning of file is always line number 1.
                 */
                /*
                 * Beginning of file is always line number 1.
                 */
@@ -285,7 +283,7 @@ find_linenum(pos)
         * traversing fewer bytes in the file.
         */
        flush();
         * traversing fewer bytes in the file.
         */
        flush();
-       startime = get_time();
+       (void)time(&startime);
        if (p == &anchor || pos - p->prev->pos < p->pos - pos)
        {
                /*
        if (p == &anchor || pos - p->prev->pos < p->pos - pos)
        {
                /*
@@ -303,11 +301,10 @@ find_linenum(pos)
                        cpos = forw_raw_line(cpos);
                        if (sigs || cpos == NULL_POSITION)
                                return (0);
                        cpos = forw_raw_line(cpos);
                        if (sigs || cpos == NULL_POSITION)
                                return (0);
-                       if (loopcount >= 0 && ++loopcount > 100)
-                       {
+                       if (loopcount >= 0 && ++loopcount > 100) {
                                loopcount = 0;
                                loopcount = 0;
-                               if (get_time() >= startime + LONGTIME)
-                               {
+                               if (time((time_t *)NULL)
+                                   >= startime + LONGTIME) {
                                        longloopmessage();
                                        loopcount = -1;
                                }
                                        longloopmessage();
                                        loopcount = -1;
                                }
@@ -336,11 +333,10 @@ find_linenum(pos)
                        cpos = back_raw_line(cpos);
                        if (sigs || cpos == NULL_POSITION)
                                return (0);
                        cpos = back_raw_line(cpos);
                        if (sigs || cpos == NULL_POSITION)
                                return (0);
-                       if (loopcount >= 0 && ++loopcount > 100)
-                       {
+                       if (loopcount >= 0 && ++loopcount > 100) {
                                loopcount = 0;
                                loopcount = 0;
-                               if (get_time() >= startime + LONGTIME)
-                               {
+                               if (time((time_t *)NULL)
+                                   >= startime + LONGTIME) {
                                        longloopmessage();
                                        loopcount = -1;
                                }
                                        longloopmessage();
                                        loopcount = -1;
                                }
@@ -361,32 +357,12 @@ find_linenum(pos)
  * The argument "where" tells which line is to be considered
  * the "current" line (e.g. TOP, BOTTOM, MIDDLE, etc).
  */
  * The argument "where" tells which line is to be considered
  * the "current" line (e.g. TOP, BOTTOM, MIDDLE, etc).
  */
-       public int
 currline(where)
        int where;
 {
 currline(where)
        int where;
 {
-       POSITION pos;
+       off_t pos, ch_length(), position();
 
 
-       pos = position(where);
-       if (pos == NULL_POSITION)
+       if ((pos = position(where)) == NULL_POSITION)
                pos = ch_length();
                pos = ch_length();
-       return (find_linenum(pos));
-}
-
-#if DEBUG_STUFF
-debug()
-{
-       register struct linenum *p;
-       char buf[20];
-
-       lower_left();
-       clear_eol();
-       for (p = anchor.next;  p != &anchor;  p = p->next)
-       {
-               (void)sprintf(buf, "%d-%d ", p->line, p->pos);
-               putstr(buf);
-       }
-       putstr("\n");
-       error("DEBUG");
+       return(find_linenum(pos));
 }
 }
-#endif /*DEBUG_STUFF*/
index 5b1df33..5259232 100644 (file)
@@ -25,38 +25,35 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * Entry point, initialization, miscellaneous routines.
  */
 
 #endif /* not lint */
 
 /*
  * Entry point, initialization, miscellaneous routines.
  */
 
-#include "less.h"
-#include "position.h"
+#include <sys/types.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <less.h>
 
 
-public int     ispipe;
-public char *  first_cmd;
-public char *  every_first_cmd;
-public int     new_file;
-public int     is_tty;
-public char    *current_file;
-public char    *previous_file;
-public POSITION        prev_pos;
-public int     any_display;
-public int     scroll;
-public int     ac;
-public char ** av;
-public int     curr_ac;
-public int     quitting;
+int    ispipe;
+int    new_file;
+int    is_tty;
+char   *current_file, *previous_file, *current_name;
+off_t  prev_pos;
+int    any_display;
+int    scroll;
+int    ac;
+char   **av;
+int    curr_ac;
+int    quitting;
 
 extern int     file;
 
 extern int     file;
-extern int     quit_at_eof;
 extern int     cbufs;
 extern int     errmsgs;
 
 extern int     cbufs;
 extern int     errmsgs;
 
-extern char *  tagfile;
-extern char *  tagpattern;
+extern char    *tagfile;
 extern int     tagoption;
 
 /*
 extern int     tagoption;
 
 /*
@@ -64,62 +61,56 @@ extern int  tagoption;
  * Filename "-" means standard input.
  * No filename means the "current" file, from the command line.
  */
  * Filename "-" means standard input.
  * No filename means the "current" file, from the command line.
  */
-       public void
 edit(filename)
        register char *filename;
 {
 edit(filename)
        register char *filename;
 {
+       extern int errno;
        register int f;
        register char *m;
        register int f;
        register char *m;
-       POSITION initial_pos;
-       char message[100];
+       off_t initial_pos, position();
        static int didpipe;
        static int didpipe;
+       char message[100], *p;
+       char *rindex(), *strerror(), *save(), *bad_file();
 
        initial_pos = NULL_POSITION;
 
        initial_pos = NULL_POSITION;
-       if (filename == NULL || *filename == '\0')
-       {
-               if (curr_ac >= ac)
-               {
+       if (filename == NULL || *filename == '\0') {
+               if (curr_ac >= ac) {
                        error("No current file");
                        error("No current file");
-                       return;
+                       return(0);
                }
                filename = save(av[curr_ac]);
                }
                filename = save(av[curr_ac]);
-       } else if (strcmp(filename, "#") == 0)
-       {
-               if (*previous_file == '\0')
-               {
+       }
+       else if (strcmp(filename, "#") == 0) {
+               if (*previous_file == '\0') {
                        error("no previous file");
                        error("no previous file");
-                       return;
+                       return(0);
                }
                filename = save(previous_file);
                initial_pos = prev_pos;
        } else
                filename = save(filename);
 
                }
                filename = save(previous_file);
                initial_pos = prev_pos;
        } else
                filename = save(filename);
 
-       if (strcmp(filename, "-") == 0)
-       {
-               /* 
-                * Use standard input.
-                */
-               if (didpipe)
-               {
+       /* use standard input. */
+       if (!strcmp(filename, "-")) {
+               if (didpipe) {
                        error("Can view standard input only once");
                        error("Can view standard input only once");
-                       return;
+                       return(0);
                }
                f = 0;
                }
                f = 0;
-       } else if ((m = bad_file(filename, message, sizeof(message))) != NULL)
-       {
+       }
+       else if ((m = bad_file(filename, message, sizeof(message))) != NULL) {
                error(m);
                free(filename);
                error(m);
                free(filename);
-               return;
-       } else if ((f = open(filename, 0)) < 0)
-       {
-               error(errno_message(filename, message, sizeof(message)));
+               return(0);
+       }
+       else if ((f = open(filename, O_RDONLY, 0)) < 0) {
+               (void)sprintf(message, "%s: %s", filename, strerror(errno));
+               error(message);
                free(filename);
                free(filename);
-               return;
+               return(0);
        }
 
        }
 
-       if (isatty(f))
-       {
+       if (isatty(f)) {
                /*
                 * Not really necessary to call this an error,
                 * but if the control terminal (for commands)
                /*
                 * Not really necessary to call this an error,
                 * but if the control terminal (for commands)
@@ -128,9 +119,9 @@ edit(filename)
                 */
                error("Can't take input from a terminal");
                if (f > 0)
                 */
                error("Can't take input from a terminal");
                if (f > 0)
-                       close(f);
-               free(filename);
-               return;
+                       (void)close(f);
+               (void)free(filename);
+               return(0);
        }
 
        /*
        }
 
        /*
@@ -138,7 +129,7 @@ edit(filename)
         * Close the current input file and set up to use the new one.
         */
        if (file > 0)
         * Close the current input file and set up to use the new one.
         */
        if (file > 0)
-               close(file);
+               (void)close(file);
        new_file = 1;
        if (previous_file != NULL)
                free(previous_file);
        new_file = 1;
        if (previous_file != NULL)
                free(previous_file);
@@ -146,21 +137,19 @@ edit(filename)
        current_file = filename;
        prev_pos = position(TOP);
        ispipe = (f == 0);
        current_file = filename;
        prev_pos = position(TOP);
        ispipe = (f == 0);
-       if (ispipe)
+       if (ispipe) {
                didpipe = 1;
                didpipe = 1;
+               current_name = "stdin";
+       } else
+               current_name = (p = rindex(filename, '/')) ? p + 1 : filename;
        file = f;
        ch_init(cbufs, 0);
        init_mark();
 
        file = f;
        ch_init(cbufs, 0);
        init_mark();
 
-       if (every_first_cmd != NULL)
-               first_cmd = every_first_cmd;
-
-       if (is_tty)
-       {
+       if (is_tty) {
                int no_display = !any_display;
                any_display = 1;
                int no_display = !any_display;
                any_display = 1;
-               if (no_display && errmsgs > 0)
-               {
+               if (no_display && errmsgs > 0) {
                        /*
                         * We displayed some messages on error output
                         * (file descriptor 2; see error() function).
                        /*
                         * We displayed some messages on error output
                         * (file descriptor 2; see error() function).
@@ -177,42 +166,44 @@ edit(filename)
                        jump_loc(initial_pos);
                clr_linenum();
        }
                        jump_loc(initial_pos);
                clr_linenum();
        }
+       return(1);
 }
 
 /*
  * Edit the next file in the command line list.
  */
 }
 
 /*
  * Edit the next file in the command line list.
  */
-       public void
 next_file(n)
        int n;
 {
 next_file(n)
        int n;
 {
-       if (curr_ac + n >= ac)
-       {
-               if (quit_at_eof)
+       extern int quit_at_eof;
+       off_t position();
+
+       if (curr_ac + n >= ac) {
+               if (quit_at_eof || position(TOP) == NULL_POSITION)
                        quit();
                error("No (N-th) next file");
                        quit();
                error("No (N-th) next file");
-       } else
-               edit(av[curr_ac += n]);
+       }
+       else
+               (void)edit(av[curr_ac += n]);
 }
 
 /*
  * Edit the previous file in the command line list.
  */
 }
 
 /*
  * Edit the previous file in the command line list.
  */
-       public void
 prev_file(n)
        int n;
 {
        if (curr_ac - n < 0)
                error("No (N-th) previous file");
        else
 prev_file(n)
        int n;
 {
        if (curr_ac - n < 0)
                error("No (N-th) previous file");
        else
-               edit(av[curr_ac -= n]);
+               (void)edit(av[curr_ac -= n]);
 }
 
 /*
  * Copy a file directly to standard output.
  * Used if standard output is not a tty.
  */
 }
 
 /*
  * Copy a file directly to standard output.
  * Used if standard output is not a tty.
  */
-       static void
+static
 cat_file()
 {
        register int c;
 cat_file()
 {
        register int c;
@@ -222,28 +213,26 @@ cat_file()
        flush();
 }
 
        flush();
 }
 
-/*
- * Entry point.
- */
 main(argc, argv)
        int argc;
 main(argc, argv)
        int argc;
-       char *argv[];
+       char **argv;
 {
 {
-       char *getenv();
-
+       int envargc, argcnt;
+       char *envargv[2], *getenv();
 
        /*
 
        /*
-        * Process command line arguments and LESS environment arguments.
+        * Process command line arguments and MORE environment arguments.
         * Command line arguments override environment arguments.
         */
         * Command line arguments override environment arguments.
         */
-       init_prompt();
-       init_option();
-       scan_option(getenv("LESS"));
-       argv++;
-       while ( (--argc > 0) && 
-               (argv[0][0] == '-' || argv[0][0] == '+') && 
-               argv[0][1] != '\0')
-               scan_option(*argv++);
+       if (envargv[1] = getenv("MORE")) {
+               envargc = 2;
+               envargv[0] = "more";
+               envargv[2] = NULL;
+               (void)option(envargc, envargv);
+       }
+       argcnt = option(argc, argv);
+       argv += argcnt;
+       argc -= argcnt;
 
        /*
         * Set up list of files to be examined.
 
        /*
         * Set up list of files to be examined.
@@ -256,21 +245,17 @@ main(argc, argv)
         * Set up terminal, etc.
         */
        is_tty = isatty(1);
         * Set up terminal, etc.
         */
        is_tty = isatty(1);
-       if (!is_tty)
-       {
+       if (!is_tty) {
                /*
                 * Output is not a tty.
                 * Just copy the input file(s) to output.
                 */
                /*
                 * Output is not a tty.
                 * Just copy the input file(s) to output.
                 */
-               if (ac < 1)
-               {
-                       edit("-");
+               if (ac < 1) {
+                       (void)edit("-");
                        cat_file();
                        cat_file();
-               } else
-               {
-                       do
-                       {
-                               edit((char *)NULL);
+               } else {
+                       do {
+                               (void)edit((char *)NULL);
                                if (file >= 0)
                                        cat_file();
                        } while (++curr_ac < ac);
                                if (file >= 0)
                                        cat_file();
                        } while (++curr_ac < ac);
@@ -282,46 +267,27 @@ main(argc, argv)
        get_term();
        open_getchr();
        init();
        get_term();
        open_getchr();
        init();
-       init_cmd();
-
        init_signals(1);
 
        init_signals(1);
 
-       /*
-        * Select the first file to examine.
-        */
-       if (tagoption)
-       {
+       /* select the first file to examine. */
+       if (tagoption) {
                /*
                /*
-                * A -t option was given.
-                * Verify that no filenames were also given.
-                * Edit the file selected by the "tags" search,
-                * and search for the proper line in the file.
+                * A -t option was given; edit the file selected by the
+                * "tags" search, and search for the proper line in the file.
                 */
                 */
-               if (ac > 0)
-               {
-                       error("No filenames allowed with -t option");
-                       quit();
-               }
-               if (tagfile == NULL)
+               if (!tagfile || !edit(tagfile) || tagsearch())
                        quit();
                        quit();
-               edit(tagfile);
-               if (file < 0)
-                       quit();
-               if (tagsearch())
-                       quit();
-       } else
-       if (ac < 1)
-               edit("-");      /* Standard input */
-       else 
-       {
+       }
+       else if (ac < 1)
+               (void)edit("-");        /* Standard input */
+       else {
                /*
                 * Try all the files named as command arguments.
                 * We are simply looking for one which can be
                 * opened without error.
                 */
                /*
                 * Try all the files named as command arguments.
                 * We are simply looking for one which can be
                 * opened without error.
                 */
-               do
-               {
-                       edit((char *)NULL);
+               do {
+                       (void)edit((char *)NULL);
                } while (file < 0 && ++curr_ac < ac);
        }
 
                } while (file < 0 && ++curr_ac < ac);
        }
 
@@ -331,25 +297,11 @@ main(argc, argv)
        /*NOTREACHED*/
 }
 
        /*NOTREACHED*/
 }
 
-/*
- * Copy a string, truncating to the specified length if necessary.
- * Unlike strncpy(), the resulting string is guaranteed to be null-terminated.
- */
-       public void
-strtcpy(to, from, len)
-       char *to;
-       char *from;
-       unsigned int len;
-{
-       strncpy(to, from, len);
-       to[len-1] = '\0';
-}
-
 /*
  * Copy a string to a "safe" place
  * (that is, to a buffer allocated by malloc).
  */
 /*
  * Copy a string to a "safe" place
  * (that is, to a buffer allocated by malloc).
  */
-       public char *
+char *
 save(s)
        char *s;
 {
 save(s)
        char *s;
 {
@@ -367,7 +319,6 @@ save(s)
 /*
  * Exit the program.
  */
 /*
  * Exit the program.
  */
-       public void
 quit()
 {
        /*
 quit()
 {
        /*