[net.sources] more hacks

stan@tikal.UUCP (Stan Tazuma) (08/28/85)

Contained is a small change to the Berkeley "more" command to allow
paging backwards.  Using 'b' or ^B will page back the same way the space
bar pages forward, scroll or noscroll modes are maintained.

The method used (skip to the beginning and then skip lines) is admittedly
inefficient, but no more so than the current methods for going back
(either start up vi or go back to the beginning and page down til
you find what you wanted).  I evaluated other methods but this seems
the most portable and elegant (e.g., a scheme which used malloc'd
memory might not work too well on a limited text+data machine).

Yes, I know about some of the posted programs which can do backward
paging.  The advantage of this mod. is that you can continue to
use the more (or page) program with only one new thing to learn.
And the man program uses more, so man doesn't need to be modified
to allow different pagers.  More is also fast and handles
the reverse video stuff very well.

BTW, more has an undocumented -p flag, which results in "more -p"
being equivalent to "page".

The changes for "going back" are below.  If anyone is interested,
my more can also do the visual bell, and I've added a new feature
called 'cat' mode.  This mode, toggled with 'C', can cause more
to switch to a non-prompting mode which will just spit out lines.
Another 'C' command will switch back to the prompting, paging mode.
This is useful when trying to skip past a large part of a file,
or when more is started on a hard-copy terminal but you decide
you don't want the paging anymore.

(If you don't have source, see if a neighbor will install the
changes for you and give you the binary.)


at the beginning of more.c, put the line:
----------------------

#define GO_BACK		/* adds 'b' and '^B' commands, for going back */

----------------------
in function command(), somewhere at the top of the switch () statement,
put in the following case.
----------------------

#ifdef GO_BACK
	case 'b':
	case '\02':	/* CTRL-B */
	    {
		register int initline;

		if (no_intty) {
		    write(2, &bell, 1);
		    return (-1);
		}
		/* go back the 'k' number of pages, unless k is 0,
		 * when should go back one screen */
		initline = Currline - dlines * (nlines ? (nlines + 1) : 2);
		if (! noscroll)
		    --initline;
		if (initline < 0) initline = 0;
		Fseek(f, 0L);
		Currline = 0;	/* skiplns() will make Currline correct */
		skiplns(initline, f);
		if (! noscroll) {
		    ret(dlines + 1);
		}
		else {
		    ret(dlines);
		}
	    }
#endif GO_BACK
---------------end of changes----------------------------

Stan Tazuma
Teltone Corp.
	...uw-beaver!tikal!stan