adding feature to LESS V5

Alexander Dupuy dupuy at douglass.columbia.edu
Sun Sep 25 14:35:17 AEST 1988


Before people go and add incompatible flags to their versions of less, there is
a better way....

Here are my local patches to less.  I had planned to finish reapplying all my
local patches to the last version, and post them all at once.  But since the
fifth patch does what Patrick Wolfe wants, without causing problems for users
of terminals with a special termcap mode (like xterm, cmdtool, or multi-page
terminals) and since there is a problem with the HP display fixes that Julian
Perry posted which causes terminals which have clear-eol but not clear-eos to
exhibit the symptoms the HP used to have, I'm posting them now.  When I finish
the rest, I'll post them as well, and send the whole shebang to Mark Nudelman.

If you have a recent version of patch, and a virgin copy of less, you can just
feed patch the entire article.  Otherwise, unshar it, and feed patch the pieces
which are relevant.  There's a brief description at the beginning of each one.

: This is a shar archive.  Extract with sh, not csh.
: The rest of this file will extract: 
:
:	PATCH.1
:	PATCH.2
:	PATCH.3
:	PATCH.3a
:	PATCH.4
:	PATCH.5
:	PATCH.6
:
echo x - PATCH.1
sed 's/^X//' > PATCH.1 << '//go.sysin dd *'
X
XSince it isn't always possible to get people to install the latest and greatest
Xversion of less, it's sometimes nice to allow less to work with some old flags.
XI use LESS=pc to get my preferred behavior on both old and new versions.
X
X*** /tmp/,RCSt1a10424	Mon Sep 19 18:02:21 1988
X--- option.c	Mon Sep 19 16:59:44 1988
X***************
X*** 477,482 ****
X--- 477,484 ----
X  		s--;
X  		c = 'z';
X  		break;
X+ 	case 'p':
X+ 		c = 'C';		/* compatibility with old less */
X  	}
X  
X  	for (o = option;  o->oletter != '\0';  o++)
//go.sysin dd *
echo x - PATCH.2
sed 's/^X//' > PATCH.2 << '//go.sysin dd *'
X
XAnother compatibility issue is the -t flag, which is now -a.  Since the new use
Xof -t requires a string argument, we can be compatible when it's the last char
Xin an option cluster.  This allows LESS=emct and similar uses.
X
X*** /tmp/,RCSt1a10951	Mon Sep 19 19:10:30 1988
X--- option.c	Mon Sep 19 19:08:32 1988
X***************
X*** 458,463 ****
X--- 458,468 ----
X  	case 't':
X  	{
X  		char *p;
X+ 		if (*s == ' ' || *s == '\t' || *s == '\0')
X+ 		{
X+ 			c = 'a';	/* some compatibility with old less */
X+ 			break;
X+ 		}
X  		tagoption = 1;
X  		p = s;
X  		s = optstring(s, c);
X***************
X*** 464,469 ****
X--- 469,478 ----
X  		findtag(p);
X  		goto next;
X  	}
X+ #else
X+ 	case 't':
X+ 		c = 'a';		/* compatibility with old less */
X+ 		break;
X  #endif
X  	case 'P':
X  		s = opt_P(s);
//go.sysin dd *
echo x - PATCH.3
sed 's/^X//' > PATCH.3 << '//go.sysin dd *'
X
XIt is sometimes useful to be able to look at a character special file (like a
Xtape).  There's also no reason why you shouldn't be able to look at a fifo.
X
X*** /tmp/,RCSt1a11210	Mon Sep 19 19:25:20 1988
X--- os.c	Mon Sep 19 19:25:04 1988
X***************
X*** 245,250 ****
X--- 245,252 ----
X  #include <sys/types.h>
X  #include <sys/stat.h>
X  
X+ extern int	ispipe;
X+ 
X  	public char *
X  bad_file(filename, message, len)
X  	char *filename;
X***************
X*** 253,258 ****
X--- 255,262 ----
X  {
X  	struct stat statbuf;
X  
X+ 	ispipe = 0;
X+ 
X  	if (stat(filename, &statbuf) < 0)
X  		return (errno_message(filename, message, len));
X  
X***************
X*** 263,268 ****
X--- 267,284 ----
X  		strcat(message, is_dir);
X  		return (message);
X  	}
X+ 	if ((statbuf.st_mode & S_IFMT) == S_IFCHR)
X+ 	{
X+ 		ispipe = 1;
X+ 		return (NULL);
X+ 	}
X+ #ifdef S_IFIFO
X+ 	if ((statbuf.st_mode & S_IFMT) == S_IFIFO)
X+ 	{
X+ 		ispipe = 1;
X+ 		return (NULL);
X+ 	}
X+ #endif
X  	if ((statbuf.st_mode & S_IFMT) != S_IFREG)
X  	{
X  		static char not_reg[] = " is not a regular file";
X*** /tmp/,RCSt1a11228	Mon Sep 19 19:31:49 1988
X--- main.c	Mon Sep 19 19:31:36 1988
X***************
X*** 133,140 ****
X  	previous_file = current_file;
X  	current_file = filename;
X  	prev_pos = position(TOP);
X! 	ispipe = (f == 0);
X! 	if (ispipe)
X  		didpipe = 1;
X  	file = f;
X  	ch_init(cbufs, 0);
X--- 133,140 ----
X  	previous_file = current_file;
X  	current_file = filename;
X  	prev_pos = position(TOP);
X! 	ispipe |= (f == 0);
X! 	if (f == 0)
X  		didpipe = 1;
X  	file = f;
X  	ch_init(cbufs, 0);
//go.sysin dd *
echo x - PATCH.3a
sed 's/^X//' > PATCH.3a << '//go.sysin dd *'
X*** /tmp/,RCSt1a03252	Sun Sep 25 00:04:19 1988
X--- /tmp/,RCSt2a03252	Sun Sep 25 00:04:20 1988
X***************
X*** 201,207 ****
X  		/*
X  		 * Read the output of <$SHELL -c "echo filename">.
X  		 */
X! 		cmd = calloc(strlen(p)+12);
X  		if (cmd == NULL)
X  			return (filename);
X  		sprintf(cmd, "%s -c \"echo %s\"", p, filename);
X--- 201,207 ----
X  		/*
X  		 * Read the output of <$SHELL -c "echo filename">.
X  		 */
X! 		cmd = calloc(strlen(p)+strlen(filename)+12, sizeof(char));
X  		if (cmd == NULL)
X  			return (filename);
X  		sprintf(cmd, "%s -c \"echo %s\"", p, filename);
//go.sysin dd *
echo x - PATCH.4
sed 's/^X//' > PATCH.4 << '//go.sysin dd *'
XBugfix for underlining from David MacKenzie (edf at rocky2.rockefeller.edu).
X
X*** /tmp/,RCSt1a08977	Wed Sep 21 13:31:15 1988
X--- less.h	Wed Sep 21 12:33:00 1988
X***************
X*** 59,68 ****
X  #define	BS_CONTROL	2	/* \b treated as control char; prints as ^H */
X  
X  /* Special chars used to tell put_line() to do something special */
X! #define	UL_CHAR		'\201'	/* Enter underline mode */
X! #define	UE_CHAR		'\202'	/* Exit underline mode */
X! #define	BO_CHAR		'\203'	/* Enter boldface mode */
X! #define	BE_CHAR		'\204'	/* Exit boldface mode */
X  
X  #define	CONTROL(c)		((c)&037)
X  #define	SIGNAL(sig,func)	signal(sig,func)
X--- 59,68 ----
X  #define	BS_CONTROL	2	/* \b treated as control char; prints as ^H */
X  
X  /* Special chars used to tell put_line() to do something special */
X! #define	UL_CHAR		(unsigned) 0201	/* Enter underline mode */
X! #define	UE_CHAR		(unsigned) 0202	/* Exit underline mode */
X! #define	BO_CHAR		(unsigned) 0203	/* Enter boldface mode */
X! #define	BE_CHAR		(unsigned) 0204	/* Exit boldface mode */
X  
X  #define	CONTROL(c)		((c)&037)
X  #define	SIGNAL(sig,func)	signal(sig,func)
X*** /tmp/,RCSt1a08977	Wed Sep 21 13:31:16 1988
X--- output.c	Wed Sep 21 12:33:02 1988
X***************
X*** 44,50 ****
X  	column = 0;
X  	for (p = line;  *p != '\0';  p++)
X  	{
X! 		switch (c = *p)
X  		{
X  		case UL_CHAR:
X  			ul_enter();
X--- 44,50 ----
X  	column = 0;
X  	for (p = line;  *p != '\0';  p++)
X  	{
X! 		switch (c = *p & 0377)
X  		{
X  		case UL_CHAR:
X  			ul_enter();
X*** /tmp/,RCSt1a08977	Wed Sep 21 13:31:17 1988
X--- os.c	Wed Sep 21 12:42:09 1988
X***************
X*** 201,207 ****
X  		/*
X  		 * Read the output of <$SHELL -c "echo filename">.
X  		 */
X! 		cmd = calloc(strlen(p)+12);
X  		if (cmd == NULL)
X  			return (filename);
X  		sprintf(cmd, "%s -c \"echo %s\"", p, filename);
X--- 201,207 ----
X  		/*
X  		 * Read the output of <$SHELL -c "echo filename">.
X  		 */
X! 		cmd = calloc(strlen(p)+strlen(filename)+12, sizeof(char));
X  		if (cmd == NULL)
X  			return (filename);
X  		sprintf(cmd, "%s -c \"echo %s\"", p, filename);
//go.sysin dd *
echo x - PATCH.5
sed 's/^X//' > PATCH.5 << '//go.sysin dd *'
XPatrick J. Wolfe (pwolfe at kai.com) posted a patch which reimplemented a feature
Xof less I sent to Casey Leedom and which might have been found in one of his
X"unofficial" distributions of less.  
X
XSpecifically, it caused less to automatically exit at the end of the first and
Xonly file, if it was less than one page (the idea being that you can see the
Xwhole thing without a pager).
X
XIt was pointed out that this causes some problems for people on workstations,
Xor more generally anyone whose terminal goes into a special mode for termcap
Xusing terminals.
X
XThe right way to fix this problem is to automatically disable the feature when
Xless is running on a terminal with a special termcap mode.
X
X*** /tmp/,RCSt1a02865	Sat Sep 24 23:10:58 1988
X--- screen.c	Sat Sep 24 23:10:13 1988
X***************
X*** 55,60 ****
X--- 55,61 ----
X  
X  public int auto_wrap;		/* Terminal does \r\n when write past margin */
X  public int ignaw;		/* Terminal ignores \n immediately after wrap */
X+ public int te_init;		/* Terminal uses ti and/or te for screen mode */
X  public int erase_char, kill_char; /* The user's erase and line-kill chars */
X  public int sc_width, sc_height;	/* Height & width of screen */
X  public int sc_window = -1;	/* window size for forward and backward */
X***************
X*** 267,276 ****
X--- 268,281 ----
X  	sc_init = tgetstr("ti", &sp);
X  	if (sc_init == NULL)
X  		sc_init = "";
X+ 	else
X+ 		te_init = 1;
X  
X  	sc_deinit= tgetstr("te", &sp);
X  	if (sc_deinit == NULL)
X  		sc_deinit = "";
X+ 	else
X+ 		te_init = 1;
X  
X  	sc_eol_clear = tgetstr("ce", &sp);
X  	if (hard || sc_eol_clear == NULL || *sc_eol_clear == '\0')
X*** /tmp/,RCSt1a02865	Sat Sep 24 23:10:59 1988
X--- prim.c	Sat Sep 24 23:10:11 1988
X***************
X*** 16,22 ****
X--- 16,24 ----
X  extern int top_scroll;
X  extern int back_scroll;
X  extern int sc_width, sc_height;
X+ extern int te_init;
X  extern int quit_at_eof;
X+ extern int ac;
X  extern int caseless;
X  extern int linenums;
X  extern int plusoption;
X***************
X*** 198,203 ****
X--- 200,208 ----
X  		eof_bell();
X  	else if (do_repaint)
X  		repaint();
X+ 	if (first_time && hit_eof && quit_at_eof && ac <= 1 &&
X+ 		(!te_init || quit_at_eof > 1))
X+   		quit();
X  	first_time = 0;
X  	(void) currline(BOTTOM);
X  }
//go.sysin dd *
echo x - PATCH.6
sed 's/^X//' > PATCH.6 << '//go.sysin dd *'
XJulian Perry's (jules at zen.co.uk) fixes for HP terminals, with one change.  His
Xversion would complain about not being able to clear to end of screen, when for
Xeverything except HP terminals, clear to end of line suffices.
X
X*** /tmp/,RCSt1a03276	Sun Sep 25 00:08:41 1988
X--- command.c	Sat Sep 24 23:42:38 1988
X***************
X*** 699,705 ****
X  			 * Help.
X  			 */
X  			lower_left();
X! 			clear_eol();
X  			putstr("help");
X  			cmd_exec();
X  			help();
X--- 699,705 ----
X  			 * Help.
X  			 */
X  			lower_left();
X! 			clear_eos();
X  			putstr("help");
X  			cmd_exec();
X  			help();
X*** /tmp/,RCSt1a03276	Sun Sep 25 00:08:42 1988
X--- main.c	Sat Sep 24 23:42:41 1988
X***************
X*** 446,452 ****
X  	end_logfile();
X  #endif
X  	lower_left();
X! 	clear_eol();
X  	deinit();
X  	flush();
X  	raw_mode(0);
X--- 446,452 ----
X  	end_logfile();
X  #endif
X  	lower_left();
X! 	clear_eos();
X  	deinit();
X  	flush();
X  	raw_mode(0);
X*** /tmp/,RCSt1a03276	Sun Sep 25 00:08:43 1988
X--- os.c	Sat Sep 24 23:42:43 1988
X***************
X*** 44,50 ****
X  	else
X  	{
X  		lower_left();
X! 		clear_eol();
X  		putstr("!");
X  		putstr(cmd);
X  		putstr("\n");
X--- 44,50 ----
X  	else
X  	{
X  		lower_left();
X! 		clear_eos();
X  		putstr("!");
X  		putstr(cmd);
X  		putstr("\n");
X*** /tmp/,RCSt1a03276	Sun Sep 25 00:08:44 1988
X--- prim.c	Sat Sep 24 23:42:46 1988
X***************
X*** 118,124 ****
X  		} else
X  		{
X  			lower_left();
X! 			clear_eol();
X  		}
X  
X  		if (pos != position(BOTTOM_PLUS_ONE))
X--- 118,124 ----
X  		} else
X  		{
X  			lower_left();
X! 			clear_eos();
X  		}
X  
X  		if (pos != position(BOTTOM_PLUS_ONE))
X*** /tmp/,RCSt1a03276	Sun Sep 25 00:08:45 1988
X--- screen.c	Sat Sep 24 23:42:49 1988
X***************
X*** 42,47 ****
X--- 42,48 ----
X  	*sc_move,		/* General cursor positioning */
X  	*sc_clear,		/* Clear screen */
X  	*sc_eol_clear,		/* Clear to end of line */
X+ 	*sc_eos_clear,		/* Clear to end of screen */
X  	*sc_s_in,		/* Enter standout (highlighted) mode */
X  	*sc_s_out,		/* Exit standout mode */
X  	*sc_u_in,		/* Enter underline mode */
X***************
X*** 284,289 ****
X--- 285,294 ----
X  		sc_eol_clear = "";
X  	}
X  
X+ 	sc_eos_clear = tgetstr("cd", &sp);
X+ 	if (sc_eos_clear == NULL || *sc_eos_clear == '\0')
X+ 		sc_eos_clear = sc_eol_clear;
X+ 
X  	sc_clear = tgetstr("cl", &sp);
X  	if (hard || sc_clear == NULL || *sc_clear == '\0')
X  	{
X***************
X*** 498,503 ****
X--- 503,518 ----
X  clear_eol()
X  {
X  	tputs(sc_eol_clear, 1, putchr);
X+ }
X+ 
X+ /*
X+  * Clear from the cursor to the end of the screen (memory).
X+  * {{ This must not move the cursor. }}
X+  */
X+ 	public void
X+ clear_eos()
X+ {
X+ 	tputs(sc_eos_clear, 1, putchr);
X  }
X  
X  /*
X*** /tmp/,RCSt1a03276	Sun Sep 25 00:08:46 1988
X--- signal.c	Sat Sep 24 23:42:52 1988
X***************
X*** 166,172 ****
X  		SIGNAL(SIGTTOU, SIG_IGN);
X  #endif
X  		lower_left();
X! 		clear_eol();
X  		deinit();
X  		flush();
X  		raw_mode(0);
X--- 166,172 ----
X  		SIGNAL(SIGTTOU, SIG_IGN);
X  #endif
X  		lower_left();
X! 		clear_eos();
X  		deinit();
X  		flush();
X  		raw_mode(0);
//go.sysin dd *
exit
-- 
inet: dupuy at columbia.edu
uucp: ...!rutgers!columbia!dupuy



More information about the Comp.sources.bugs mailing list