asthetic mods
[unix-history] / usr / src / old / more / more.c
index 8fd0d0f..d4eb516 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)more.c      4.4 (Berkeley) 81/04/23";
+static char *sccsid = "@(#)more.c      4.11 (Berkeley) 83/03/17";
 
 /*
 ** more.c - General purpose tty output filter and file perusal program
 
 /*
 ** more.c - General purpose tty output filter and file perusal program
@@ -9,10 +9,6 @@ static char *sccsid = "@(#)more.c      4.4 (Berkeley) 81/04/23";
 **     modified by John Foderaro, UCB to add -c and MORE environment variable
 */
 
 **     modified by John Foderaro, UCB to add -c and MORE environment variable
 */
 
-#include <whoami.h>
-#ifdef V6
-#include <retrofit.h>
-#endif
 #include <stdio.h>
 #include <ctype.h>
 #include <signal.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <signal.h>
@@ -20,23 +16,13 @@ static      char *sccsid = "@(#)more.c      4.4 (Berkeley) 81/04/23";
 #include <sgtty.h>
 #include <setjmp.h>
 #include <sys/types.h>
 #include <sgtty.h>
 #include <setjmp.h>
 #include <sys/types.h>
-#include <sys/dir.h>
 #include <sys/stat.h>
 #include <local/uparm.h>
 
 /* Help file will eventually go in libpath(more.help) on all systems */
 
 #include <sys/stat.h>
 #include <local/uparm.h>
 
 /* Help file will eventually go in libpath(more.help) on all systems */
 
-#ifdef INGRES
-#define VI             "/usr/bin/vi"
-#define HELPFILE       "/mntp/doucette/more/more.help"
-#endif
-
-#ifndef INGRES
-#ifndef HELPFILE
 #define HELPFILE       libpath(more.help)
 #define HELPFILE       libpath(more.help)
-#endif
 #define VI             binpath(vi)
 #define VI             binpath(vi)
-#endif
 
 #define Fopen(s,m)     (Currline = 0,file_pos=0,fopen(s,m))
 #define Ftell(f)       file_pos
 
 #define Fopen(s,m)     (Currline = 0,file_pos=0,fopen(s,m))
 #define Ftell(f)       file_pos
@@ -44,13 +30,8 @@ static       char *sccsid = "@(#)more.c      4.4 (Berkeley) 81/04/23";
 #define Getc(f)                (++file_pos, getc(f))
 #define Ungetc(c,f)    (--file_pos, ungetc(c,f))
 
 #define Getc(f)                (++file_pos, getc(f))
 #define Ungetc(c,f)    (--file_pos, ungetc(c,f))
 
-#ifdef V6
-#define MBIT   RAW
-#define CBREAK ~RAW
-#else
 #define MBIT   CBREAK
 #define stty(fd,argp)  ioctl(fd,TIOCSETN,argp)
 #define MBIT   CBREAK
 #define stty(fd,argp)  ioctl(fd,TIOCSETN,argp)
-#endif
 
 #define TBUFSIZ        1024
 #define LINSIZ 256
 
 #define TBUFSIZ        1024
 #define LINSIZ 256
@@ -63,9 +44,7 @@ struct sgttyb         otty;
 long           file_pos, file_size;
 int            fnum, no_intty, no_tty, slow_tty;
 int            dum_opt, dlines, onquit(), end_it();
 long           file_pos, file_size;
 int            fnum, no_intty, no_tty, slow_tty;
 int            dum_opt, dlines, onquit(), end_it();
-#ifdef SIGTSTP
 int            onsusp();
 int            onsusp();
-#endif
 int            nscroll = 11;   /* Number of lines scrolled by 'd' */
 int            fold_opt = 1;   /* Fold long lines */
 int            stop_opt = 1;   /* Stop after form feeds */
 int            nscroll = 11;   /* Number of lines scrolled by 'd' */
 int            fold_opt = 1;   /* Fold long lines */
 int            stop_opt = 1;   /* Stop after form feeds */
@@ -182,12 +161,10 @@ char *argv[];
     if (!no_tty) {
        signal(SIGQUIT, onquit);
        signal(SIGINT, end_it);
     if (!no_tty) {
        signal(SIGQUIT, onquit);
        signal(SIGINT, end_it);
-#ifdef SIGTSTP
        if (signal (SIGTSTP, SIG_IGN) == SIG_DFL) {
            signal(SIGTSTP, onsusp);
            catch_susp++;
        }
        if (signal (SIGTSTP, SIG_IGN) == SIG_DFL) {
            signal(SIGTSTP, onsusp);
            catch_susp++;
        }
-#endif
        stty (2, &otty);
     }
     if (no_intty) {
        stty (2, &otty);
     }
     if (no_intty) {
@@ -286,23 +263,39 @@ char *argv[];
 argscan(s)
 char *s;
 {
 argscan(s)
 char *s;
 {
-           for (dlines = 0; *s != '\0'; s++)
-               if (isdigit(*s))
-                   dlines = dlines*10 + *s - '0';
-               else if (*s == 'd')
-                   dum_opt = 1;
-               else if (*s == 'l')
-                   stop_opt = 0;
-               else if (*s == 'f')
-                   fold_opt = 0;
-               else if (*s == 'p')
-                   noscroll++;
-               else if (*s == 'c')
-                   clreol++;
-               else if (*s == 's')
-                   ssp_opt = 1;
-               else if (*s == 'u')
-                   ul_opt = 0;
+       for (dlines = 0; *s != '\0'; s++)
+       {
+               switch (*s)
+               {
+                 case '0': case '1': case '2':
+                 case '3': case '4': case '5':
+                 case '6': case '7': case '8':
+                 case '9':
+                       dlines = dlines*10 + *s - '0';
+                       break;
+                 case 'd':
+                       dum_opt = 1;
+                       break;
+                 case 'l':
+                       stop_opt = 0;
+                       break;
+                 case 'f':
+                       fold_opt = 0;
+                       break;
+                 case 'p':
+                       noscroll++;
+                       break;
+                 case 'c':
+                       clreol++;
+                       break;
+                 case 's':
+                       ssp_opt = 1;
+                       break;
+                 case 'u':
+                       ul_opt = 0;
+                       break;
+               }
+       }
 }
 
 
 }
 
 
@@ -438,7 +431,7 @@ register int num_lines;
            return;
        if (hard && promptlen > 0)
                erase (0);
            return;
        if (hard && promptlen > 0)
                erase (0);
-       if (noscroll && num_lines == dlines)
+       if (noscroll && num_lines >= dlines)
        { 
            if (clreol)
                home();
        { 
            if (clreol)
                home();
@@ -573,16 +566,16 @@ int n;
 char *str;
 {
     sptr = str;
 char *str;
 {
     sptr = str;
-    sprintf (n);
+    Sprintf (n);
     *sptr = '\0';
 }
 
     *sptr = '\0';
 }
 
-sprintf (n)
+Sprintf (n)
 {
     int a;
 
     if (a = n/10)
 {
     int a;
 
     if (a = n/10)
-       sprintf (a);
+       Sprintf (a);
     *sptr++ = n % 10 + '0';
 }
 
     *sptr++ = n % 10 + '0';
 }
 
@@ -705,7 +698,7 @@ int *length;
            }
            else
                column = 1 + (column | 7);
            }
            else
                column = 1 + (column | 7);
-       else if (c == '\b')
+       else if (c == '\b' && column > 0)
            column--;
        else if (c == '\r')
            column = 0;
            column--;
        else if (c == '\r')
            column = 0;
@@ -1230,9 +1223,7 @@ register int n;
     }
     if (feof (file)) {
        if (!no_intty) {
     }
     if (feof (file)) {
        if (!no_intty) {
-#ifdef V6
            file->_flag &= ~_IOEOF; /* why doesn't fseek do this ??!!??! */
            file->_flag &= ~_IOEOF; /* why doesn't fseek do this ??!!??! */
-#endif
            Currline = saveln;
            Fseek (file, startline);
        }
            Currline = saveln;
            Fseek (file, startline);
        }
@@ -1261,17 +1252,13 @@ char *cmd, *args;
        }
        signal (SIGINT, SIG_IGN);
        signal (SIGQUIT, SIG_IGN);
        }
        signal (SIGINT, SIG_IGN);
        signal (SIGQUIT, SIG_IGN);
-#ifdef SIGTSTP
        if (catch_susp)
            signal(SIGTSTP, SIG_DFL);
        if (catch_susp)
            signal(SIGTSTP, SIG_DFL);
-#endif
        wait (0);
        signal (SIGINT, end_it);
        signal (SIGQUIT, onquit);
        wait (0);
        signal (SIGINT, end_it);
        signal (SIGQUIT, onquit);
-#ifdef SIGTSTP
        if (catch_susp)
            signal(SIGTSTP, onsusp);
        if (catch_susp)
            signal(SIGTSTP, onsusp);
-#endif
        set_tty ();
        pr ("------------------------\n");
        prompt (filename);
        set_tty ();
        pr ("------------------------\n");
        prompt (filename);
@@ -1335,10 +1322,11 @@ initterm ()
     char       clearbuf[100];
     char       *clearptr, *padstr;
     int                ldisc;
     char       clearbuf[100];
     char       *clearptr, *padstr;
     int                ldisc;
+    char       *term;
 
     setbuf(stdout, obuf);
     if (!(no_tty = gtty(1, &otty))) {
 
     setbuf(stdout, obuf);
     if (!(no_tty = gtty(1, &otty))) {
-       if (tgetent(buf, getenv("TERM")) <= 0) {
+       if ((term = getenv("TERM")) && tgetent(buf, term) <= 0) {
            dumb++; ul_opt = 0;
        }
        else {
            dumb++; ul_opt = 0;
        }
        else {
@@ -1380,7 +1368,7 @@ initterm ()
            if (padstr = tgetstr("pc", &clearptr))
                PC = *padstr;
            Home = tgetstr("ho",&clearptr);
            if (padstr = tgetstr("pc", &clearptr))
                PC = *padstr;
            Home = tgetstr("ho",&clearptr);
-           if (*Home == '\0')
+           if (Home == 0 && *Home == '\0')
            {
                if ((cursorm = tgetstr("cm", &clearptr)) != NULL) {
                    strcpy(cursorhome, tgoto(cursorm, 0, 0));
            {
                if ((cursorm = tgetstr("cm", &clearptr)) != NULL) {
                    strcpy(cursorhome, tgoto(cursorm, 0, 0));
@@ -1607,7 +1595,6 @@ register FILE *f;
 
 /* Come here when we get a suspend signal from the terminal */
 
 
 /* Come here when we get a suspend signal from the terminal */
 
-#ifdef SIGTSTP
 onsusp ()
 {
     reset_tty ();
 onsusp ()
 {
     reset_tty ();
@@ -1622,4 +1609,3 @@ onsusp ()
     if (inwait)
            longjmp (restore);
 }
     if (inwait)
            longjmp (restore);
 }
-#endif