[comp.sources.misc] v05i005:

george@rebel.UUCP (George M. Sipe) (10/28/88)

Posting-number: Volume 5, Issue 5
Submitted-by: "George M. Sipe" <george@rebel.UUCP>
Archive-name: vis.Patch1

This update adds two useful new features to vis, the program recently
posted which makes any command "screen oriented":

	1.  Steve Alter (alter@ttidca.tti.com) added the capability
	    to fully suppress the status line via a new -h option.
	    This permits the full screen to be used to display the
	    output of the command.

	2.  Anton Chernoff (abc@lpi.uucp) added the capability to
	    highlight characters changed since the last pass by the
	    use of standout mode, specified with a new -s option.

George M. Sipe,		Phone: (404) 662-1533
Tolerant Systems, 6961 Peachtree Industrial, Norcross, GA  30071
UUCP: ...!{decvax,hplabs,linus,rutgers,seismo}!gatech!rebel!george


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README.diff
#	vis.c.diff
#	vis.man.diff
# This archive created: Sun Oct 23 16:08:40 1988
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'README.diff'
then
	echo shar: "will not over-write existing file 'README.diff'"
else
cat << \X > 'README.diff'
*** README_orig	Sun Oct 23 15:10:24 1988
--- README	Sun Oct 23 15:48:18 1988
***************
*** 45,47
  	George M.  Sipe (rebel!george) to the point where Dan
  	would no longer recoginze it.  No copyright notices
  	were embodied in the original net distribution.

--- 45,51 -----
  	George M.  Sipe (rebel!george) to the point where Dan
  	would no longer recoginze it.  No copyright notices
  	were embodied in the original net distribution.
+ 
+ 	Steve Alter (alter@ttidca.tti.com) added the -h option.
+ 
+ 	Anton Chernoff (abc@lpi.uucp) added the -s option.
X
fi
if test -f 'vis.c.diff'
then
	echo shar: "will not over-write existing file 'vis.c.diff'"
else
cat << \X > 'vis.c.diff'
*** vis.c_orig	Sun Oct 23 15:10:30 1988
--- vis.c	Sun Oct 23 15:47:01 1988
***************
*** 27,32
  	Sipe (rebel!george) to the point where Dan would no longer
  	recoginze it.  No copyright notices were embodied in the
  	original net distribution.
  */
  
  #include <stdio.h>

--- 27,36 -----
  	Sipe (rebel!george) to the point where Dan would no longer
  	recoginze it.  No copyright notices were embodied in the
  	original net distribution.
+ 
+ 	Steve Alter (alter@ttidca.tti.com) added the -h option.
+ 
+ 	Anton Chernoff (abc@lpi.uucp) added the -s option.
  */
  
  #include <stdio.h>
***************
*** 120,125
  	int sw;
  	int badsw = 0;
  	int baseline = BASELINE;
  	long nextcycle;
  	long curtime;
  	long delta;

--- 124,134 -----
  	int sw;
  	int badsw = 0;
  	int baseline = BASELINE;
+ 	int doheader = 1;
+ 	int flagchanges = 0;
+ 	int flagch = 0;
+ 	int y, x;
+ 	int somode;
  	long nextcycle;
  	long curtime;
  	long delta;
***************
*** 134,140
  	(void) signal(SIGINT, terminate);	/* exit when requested */
  	(void) signal(SIGPIPE, SIG_IGN);	/* when output > screen size */
  
! 	while ((sw = getopt (argc, argv, "d:f")) != EOF)
  		switch (sw) {
  			case 'f':
  				force = !force;

--- 143,149 -----
  	(void) signal(SIGINT, terminate);	/* exit when requested */
  	(void) signal(SIGPIPE, SIG_IGN);	/* when output > screen size */
  
! 	while ((sw = getopt (argc, argv, "d:fhs")) != EOF)
  		switch (sw) {
  			case 'd':
  				wait_delay = atoi(optarg);
***************
*** 136,144
  
  	while ((sw = getopt (argc, argv, "d:f")) != EOF)
  		switch (sw) {
- 			case 'f':
- 				force = !force;
- 				break;
  			case 'd':
  				wait_delay = atoi(optarg);
  				if (wait_delay < 1) wait_delay = 1;

--- 145,150 -----
  
  	while ((sw = getopt (argc, argv, "d:fhs")) != EOF)
  		switch (sw) {
  			case 'd':
  				wait_delay = atoi(optarg);
  				if (wait_delay < 1) wait_delay = 1;
***************
*** 143,148
  				wait_delay = atoi(optarg);
  				if (wait_delay < 1) wait_delay = 1;
  				break;
  			case '?':
  			default:
  				badsw = 1;

--- 149,164 -----
  				wait_delay = atoi(optarg);
  				if (wait_delay < 1) wait_delay = 1;
  				break;
+ 			case 'f':
+ 				force = !force;
+ 				break;
+ 			case 'h':
+ 				doheader = 0;
+ 				baseline = 0;
+ 				break;
+ 			case 's':
+ 				flagchanges = !flagchanges;
+ 				break;
  			case '?':
  			default:
  				badsw = 1;
***************
*** 152,158
  	argc -= optind;
  	if (badsw || argc < 1) {
  		(void) fprintf(stderr,
! 			"Usage: %s [-d delay] [-f] command [args]\n", cmd);
  		exit (-1);
  	}
  	initscr();

--- 168,175 -----
  	argc -= optind;
  	if (badsw || argc < 1) {
  		(void) fprintf(stderr,
! 			"Usage: %s [-d delay] [-f] [-h] [-s] command [args]\n",
! 			cmd);
  		exit (-1);
  	}
  	initscr();
***************
*** 163,176
  		shcmd[2] = cmd;
  		shcmd[3] = (char *) 0;
  	}
! 	if (wait_delay != DELAY) {
! 		if (strlen(cmd) > COLS-39)
! 			(void) sprintf(cmd, "%.*s...", COLS-42, cmd);
! 		mvprintw(0, max((COLS-11)/2, strlen(cmd)+15), "Delay:  %d",
! 			wait_delay);
! 	} else if (strlen(cmd) > COLS-21)
! 		(void) sprintf(cmd, "%.*s...", COLS-24, cmd);
! 	mvprintw(0, 0, "Command:  %s", cmd);
  	noecho();			/* don't let typing ruin our painting */
  	nextcycle = time(0) + wait_delay;
  	while (1) {

--- 180,195 -----
  		shcmd[2] = cmd;
  		shcmd[3] = (char *) 0;
  	}
! 	if (doheader) {
! 		if (wait_delay != DELAY) {
! 			if (strlen(cmd) > COLS-39)
! 				(void) sprintf(cmd, "%.*s...", COLS-42, cmd);
! 			mvprintw(0, max((COLS-11)/2, strlen(cmd)+15),
! 				"Delay:  %d", wait_delay);
! 		} else if (strlen(cmd) > COLS-21)
! 			(void) sprintf(cmd, "%.*s...", COLS-24, cmd);
! 		mvprintw(0, 0, "Command:  %s", cmd);
! 	}
  	noecho();			/* don't let typing ruin our painting */
  	nextcycle = time(0) + wait_delay;
  	while (1) {
***************
*** 174,180
  	noecho();			/* don't let typing ruin our painting */
  	nextcycle = time(0) + wait_delay;
  	while (1) {
! 		mvprintw(0, COLS - 10, "Exec:  %d", ++iteration);
  		if (iteration == 1) refresh();
  		(void) pipe(fildes);
  		/* fork and exec redirecting stdout thru pipe to curses */

--- 193,200 -----
  	noecho();			/* don't let typing ruin our painting */
  	nextcycle = time(0) + wait_delay;
  	while (1) {
! 		if (doheader)
! 			mvprintw(0, COLS - 10, "Exec:  %d", ++iteration);
  		if (iteration == 1) refresh();
  		(void) pipe(fildes);
  		/* fork and exec redirecting stdout thru pipe to curses */
***************
*** 191,196
  		if (!(fp = fdopen(pinput, "r"))) terminate(-3);
  		(void) close(poutput);
  		curline = baseline;
  		move(curline, 0);
  		/* read the command's output */
  		while ((c = getc(fp)) != EOF && !ferror(fp) && curline < LINES)

--- 211,217 -----
  		if (!(fp = fdopen(pinput, "r"))) terminate(-3);
  		(void) close(poutput);
  		curline = baseline;
+ 		somode = 0;
  		move(curline, 0);
  		getyx(stdscr, y, x);
  		/* read the command's output */
***************
*** 192,197
  		(void) close(poutput);
  		curline = baseline;
  		move(curline, 0);
  		/* read the command's output */
  		while ((c = getc(fp)) != EOF && !ferror(fp) && curline < LINES)
  				if (c == '\n') {

--- 213,219 -----
  		curline = baseline;
  		somode = 0;
  		move(curline, 0);
+ 		getyx(stdscr, y, x);
  		/* read the command's output */
  		while ((c = getc(fp)) != EOF && !ferror(fp) && curline < LINES)
  		{
***************
*** 194,204
  		move(curline, 0);
  		/* read the command's output */
  		while ((c = getc(fp)) != EOF && !ferror(fp) && curline < LINES)
! 				if (c == '\n') {
! 					clrtoeol();
! 					move(++curline, 0);
! 				}
! 				else addch(c);
  		if (ferror(fp)) terminate(-4);
  		if (baseline > 1 && curline == LINES && c != EOF)
  			--baseline;

--- 216,250 -----
  		getyx(stdscr, y, x);
  		/* read the command's output */
  		while ((c = getc(fp)) != EOF && !ferror(fp) && curline < LINES)
! 		{
! 
! 			if (c == '\n') {
! 				if (x < COLS-1) clrtoeol();
! 				move(++curline, 0);
! 				getyx(stdscr, y, x);
! 			}
! 			else {
! 				if (x >= COLS-1)
! 					continue;
! 				getyx(stdscr, y, x);
! 				if (flagch)
! 					if ((c & 0177) == (inch() & 0177)) {
! 						if (somode) {
! 							standend();
! 							somode = 0;
! 						}
! 					}
! 					else {
! 						if (!somode) {
! 							standout();
! 							somode = 1;
! 						}
! 					}
! 				addch(c);
! 			}
! 		}
! 		if (somode) standend();
! 		flagch = flagchanges;
  		if (ferror(fp)) terminate(-4);
  		if (baseline > 1 && curline == LINES && c != EOF)
  			--baseline;
***************
*** 210,216
  		(void) wait(&status);	/* wait for child to terminate */
  		/* if child didn't terminate properly, w_status will != 0 */
  		if (status.w_status) {
! 			mvprintw(0, COLS - 12, "!");
  			if (!force) terminate(status.w_status);
  		}
  		curtime = time(0);

--- 256,263 -----
  		(void) wait(&status);	/* wait for child to terminate */
  		/* if child didn't terminate properly, w_status will != 0 */
  		if (status.w_status) {
! 			if (doheader)
! 				mvprintw(0, COLS - 12, "!");
  			if (!force) terminate(status.w_status);
  		}
  		curtime = time(0);
X
fi
if test -f 'vis.man.diff'
then
	echo shar: "will not over-write existing file 'vis.man.diff'"
else
cat << \X > 'vis.man.diff'
*** vis.man_orig	Sun Oct 23 15:10:27 1988
--- vis.man	Sun Oct 23 15:47:13 1988
***************
*** 1,4
! .TH VIS l "21 July 1988"
  .SH NAME
  vis \- repeatedly run command, refreshing screen
  .SH SYNTAX

--- 1,4 -----
! .TH VIS l "24 October 1988"
  .SH NAME
  vis \- repeatedly run command, refreshing screen
  .SH SYNTAX
***************
*** 2,8
  .SH NAME
  vis \- repeatedly run command, refreshing screen
  .SH SYNTAX
! .B vis "[-d delay] [-f] command [args]"
  .SH DESCRIPTION
  .I Vis
  repeatedly executes a specified

--- 2,8 -----
  .SH NAME
  vis \- repeatedly run command, refreshing screen
  .SH SYNTAX
! .B vis "[-d delay] [-f] [-h] [-s] command [args]"
  .SH DESCRIPTION
  .I Vis
  repeatedly executes a specified
***************
*** 67,72
  status line by a ``!'' flag whenever a non-zero status has been returned
  by
  .B command .
  .SH EXAMPLES
  vis ps
  .IP "" 5

--- 67,85 -----
  status line by a ``!'' flag whenever a non-zero status has been returned
  by
  .B command .
+ .TP
+ .B -h
+ causes the entire status line and the following blank line to be
+ suppressed, which leaves the full screen available for the output of
+ .B command .
+ .TP
+ .B -s
+ causes
+ .I vis
+ to use standout mode for any bytes that have changed between the
+ previous execution of
+ .B command
+ and the current one.
  .SH EXAMPLES
  vis ps
  .IP "" 5
***************
*** 77,82
  .IP "" 5
  Display the system users and disk usage statistics every 60 seconds.
  Separate the two with a blank line.
  .SH "SEE ALSO"
  User Commands (1):  sh, csh
  .SH DIAGNOSTICS

--- 90,100 -----
  .IP "" 5
  Display the system users and disk usage statistics every 60 seconds.
  Separate the two with a blank line.
+ .PP
+ vis -s ls -l
+ .IP "" 5
+ Continually display a long directory listing, highlighting via standout
+ mode the parts that change each time.
  .SH "SEE ALSO"
  User Commands (1):  sh, csh
  .SH DIAGNOSTICS
***************
*** 94,96
  It has been substantially enhanced and generalized by George M. Sipe
  (currently - 7/88, at rebel!george) to the point where Dan would no
  longer recognize it.

--- 112,118 -----
  It has been substantially enhanced and generalized by George M. Sipe
  (currently - 7/88, at rebel!george) to the point where Dan would no
  longer recognize it.
+ .PP
+ Steve Alter (alter@ttidca.tti.com) added the -h option.
+ .PP
+ Anton Chernoff (abc@lpi.uucp) added the -s option.
X
fi
exit 0
#	End of shell archive

-- 
George M. Sipe,		Phone: (404) 662-1533
Tolerant Systems, 6961 Peachtree Industrial, Norcross, GA  30071
UUCP: ...!{decvax,hplabs,linus,rutgers,seismo}!gatech!rebel!george