make ^D scroll 1/2 screenful by default.
[unix-history] / usr / src / old / more / more.c
index 783a752..984677b 100644 (file)
@@ -1,4 +1,6 @@
-static char *sccsid = "@(#)more.c      4.5 (Berkeley) 82/03/15";
+#ifndef lint
+static char *sccsid = "@(#)more.c      4.17 (Berkeley) 84/01/06";
+#endif
 
 /*
 ** more.c - General purpose tty output filter and file perusal program
 
 /*
 ** more.c - General purpose tty output filter and file perusal program
@@ -16,14 +18,10 @@ static      char *sccsid = "@(#)more.c      4.5 (Berkeley) 82/03/15";
 #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 <sys/stat.h>
-#include <local/uparm.h>
 
 
-/* Help file will eventually go in libpath(more.help) on all systems */
-
-#define HELPFILE       libpath(more.help)
-#define VI             binpath(vi)
+#define HELPFILE       "/usr/lib/more.help"
+#define VI             "/usr/ucb/vi"
 
 #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
@@ -41,7 +39,7 @@ static        char *sccsid = "@(#)more.c      4.5 (Berkeley) 82/03/15";
 #define ESC    '\033'
 #define QUIT   '\034'
 
 #define ESC    '\033'
 #define QUIT   '\034'
 
-struct sgttyb  otty;
+struct sgttyb  otty, savetty;
 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();
@@ -113,6 +111,9 @@ char *argv[];
     nfiles = argc;
     fnames = argv;
     initterm ();
     nfiles = argc;
     fnames = argv;
     initterm ();
+    nscroll = Lpp/2 - 1;
+    if (nscroll <= 0)
+       nscroll = 1;
     if(s = getenv("MORE")) argscan(s);
     while (--nfiles > 0) {
        if ((ch = (*++fnames)[0]) == '-') {
     if(s = getenv("MORE")) argscan(s);
     while (--nfiles > 0) {
        if ((ch = (*++fnames)[0]) == '-') {
@@ -264,23 +265,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;
+               }
+       }
 }
 
 
 }
 
 
@@ -416,7 +433,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();
@@ -551,16 +568,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';
 }
 
@@ -683,7 +700,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;
@@ -1307,10 +1324,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")) == 0 || tgetent(buf, term) <= 0) {
            dumb++; ul_opt = 0;
        }
        else {
            dumb++; ul_opt = 0;
        }
        else {
@@ -1352,7 +1370,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));
@@ -1366,6 +1384,7 @@ initterm ()
     }
     no_intty = gtty(0, &otty);
     gtty(2, &otty);
     }
     no_intty = gtty(0, &otty);
     gtty(2, &otty);
+    savetty = otty;
     ospeed = otty.sg_ospeed;
     slow_tty = ospeed < B1200;
     hardtabs =  !(otty.sg_flags & XTABS);
     ospeed = otty.sg_ospeed;
     slow_tty = ospeed < B1200;
     hardtabs =  !(otty.sg_flags & XTABS);
@@ -1560,7 +1579,7 @@ reset_tty ()
 {
     otty.sg_flags |= ECHO;
     otty.sg_flags &= ~MBIT;
 {
     otty.sg_flags |= ECHO;
     otty.sg_flags &= ~MBIT;
-    stty(2, &otty);
+    stty(2, &savetty);
 }
 
 rdline (f)
 }
 
 rdline (f)
@@ -1581,9 +1600,14 @@ register FILE *f;
 
 onsusp ()
 {
 
 onsusp ()
 {
+    /* ignore SIGTTOU so we don't get stopped if csh grabs the tty */
+    signal(SIGTTOU, SIG_IGN);
     reset_tty ();
     fflush (stdout);
     reset_tty ();
     fflush (stdout);
+    signal(SIGTTOU, SIG_DFL);
     /* Send the TSTP signal to suspend our process group */
     /* Send the TSTP signal to suspend our process group */
+    signal(SIGTSTP, SIG_DFL);
+    sigsetmask(0);
     kill (0, SIGTSTP);
     /* Pause for station break */
 
     kill (0, SIGTSTP);
     /* Pause for station break */