[comp.sources.bugs] Bug fixes for vtem 1.1 - a termcap driven VT100 emulator for BSD Unix

gnu@hoptoad.uucp (John Gilmore) (07/01/87)

I found a few obscure bugs and cleaned up some of the environment setting
code in this great program.  Kudos to Leif Samuelsson (erisun!leif) for
writing it and putting it in the public domain.  It was most recently
posted to net.sources in article <552@erisun.UUCP> of 25 Apr 86.

*** ../vtem/out.c	Tue Jun 30 22:40:07 1987
--- out.c	Wed Jul  1 00:12:39 1987
***************
*** 1,7 ****
  /*
   * vtem - A termcap driven VT100 emulator for BSD Unix
   *
!  * Version 1.1
   *
   * Public domain software.
   * Written by Leif Samuelsson (leif@erisun) in December, 1985
--- 1,10 ----
  /*
   * vtem - A termcap driven VT100 emulator for BSD Unix
   *
!  * Version 1.1+gnu1
!  * Bug fixes by hoptoad!gnu for version 1.1+gnu1:
!  * Don't walk past the end of the 'tabs' array if we are in column 81.
!  * There may still be a few column 81 bugs in here.
   *
   * Public domain software.
   * Written by Leif Samuelsson (leif@erisun) in December, 1985
***************
*** 153,159 ****
  	    if (save_row > 0) {
  		row = save_row;
  		col = save_col;
! 		set_cursor(col-1, arow-1);
  		if (blink = save_blink)
  		    start_blink();
  		if (bold = save_bold)
--- 156,162 ----
  	    if (save_row > 0) {
  		row = save_row;
  		col = save_col;
! 		set_cursor((col == 81)? 80-1 : col-1, arow-1);
  		if (blink = save_blink)
  		    start_blink();
  		if (bold = save_bold)
***************
*** 175,181 ****
  	    do_linefeed(); break;
  
  	case 'H':
! 	    tabs[col-1] = 1; break;
  
  	case 'M':
  	    do_reverse_lf(); break;
--- 178,185 ----
  	    do_linefeed(); break;
  
  	case 'H':
! 	    if (col <= sizeof (tabs)/sizeof (*tabs))
! 		    tabs[col-1] = 1; break;
  
  	case 'M':
  	    do_reverse_lf(); break;
***************
*** 349,365 ****
      switch (argno) {
  	case 0:
  	    arg[0] = 1;
- 	    argno++;
  	    /* Fall through */
  
  	case 1:
! 	    arg[1] = 1;		/* Correct? */
! 	    argno++;
  	    /* Fall through... */
  
  	case 2:
  	    row = arg[0];
  	    col = arg[1];
  	    set_cursor(col-1, arow-1);
  	    break;
      }
--- 353,369 ----
      switch (argno) {
  	case 0:
  	    arg[0] = 1;
  	    /* Fall through */
  
  	case 1:
! 	    arg[1] = 1;
  	    /* Fall through... */
  
  	case 2:
  	    row = arg[0];
  	    col = arg[1];
+ 	    if (row > 24) row = 24;
+ 	    if (col > 80) col = 80;
  	    set_cursor(col-1, arow-1);
  	    break;
      }
***************
*** 438,444 ****
  	arg[argno++] = 0;
      switch (arg[0]) {
  	case 0:
! 	    tabs[col-1] = 0; break;
  	case 3:
  	    for (i = 0; i<80; i++)
  		tabs[i] = 0; break;
--- 442,449 ----
  	arg[argno++] = 0;
      switch (arg[0]) {
  	case 0:
! 	    if (col <= sizeof (tabs)/sizeof (*tabs))
! 		    tabs[col-1] = 0; break;
  	case 3:
  	    for (i = 0; i<80; i++)
  		tabs[i] = 0; break;
*** ../vtem/vtem.1	Tue Jun 30 22:40:05 1987
--- vtem.1	Wed Jul  1 00:12:39 1987
***************
*** 25,31 ****
  "VT100 Tool" shelltool -Ww 80 -Wh 24 -Wl " VT100 Tool" vtem
  .fi
  .SH BUGS
! Release 1.0 of vtem has the following bugs and limitations:
  
  Region scroll will only work on terminals with
  cs or al/dl.
--- 25,31 ----
  "VT100 Tool" shelltool -Ww 80 -Wh 24 -Wl " VT100 Tool" vtem
  .fi
  .SH BUGS
! Release 1.1+gnu1 of vtem has the following bugs and limitations:
  
  Region scroll will only work on terminals with
  cs or al/dl.
*** ../vtem/vtem.c	Tue Jun 30 22:40:06 1987
--- vtem.c	Wed Jul  1 00:12:39 1987
***************
*** 1,7 ****
  /*
   * vtem - A termcap driven VT100 emulator for BSD Unix
   *
!  * Version 1.1
   *
   * Public domain software.
   * Written by Leif Samuelsson (lsamuelsson@erisun) in December, 1985
--- 1,7 ----
  /*
   * vtem - A termcap driven VT100 emulator for BSD Unix
   *
!  * Version 1.1+gnu1
   *
   * Public domain software.
   * Written by Leif Samuelsson (lsamuelsson@erisun) in December, 1985
***************
*** 8,13 ****
--- 8,17 ----
   * 
   * History:
   * 
+  * 1987-07-01	Version 1.1+gnu1.  Bug fixes for setting tabs in column
+  *		81 (crashes when you run 'reset'), and for setting the
+  *		environment variables TERM and TERMCAP.
+  *
   * 1986-04-25	Version 1.1 posted to net.sources. This version contains
   *		bug fixes and some new code for simulating semi-graphics.
   *
***************
*** 67,83 ****
  int t;
  char *term, *getenv(), *shell, *tail, *rindex();
  
! 	/* First, set the new terminal type. This only works if
! 	 * the previous terminal name is at least as long as "vt100".
! 	 * I would appreciate ideas on how to improve this.
! 	 */
! 	term=getenv("TERM");
! 	if (term != (char *)0
! 	    && strlen(term) >= strlen("vt100"))
! 		strcpy(term, "vt100");
! 	else
  		fprintf(stderr, "Set terminal type to \"vt100\" manually.\r\n");
! 
  	/* Then fork the shell
  	 */
  	if ((shell = getenv("SHELL")) == (char *) 0)
--- 71,90 ----
  int t;
  char *term, *getenv(), *shell, *tail, *rindex();
  
! 	if (0 != putenv("TERM=vt100"))
  		fprintf(stderr, "Set terminal type to \"vt100\" manually.\r\n");
! 	term = getenv("TERMCAP");
! 	if (term && term[0] != '/') {
! 		/* TERMCAP contains a termcap entry for the old terminal
! 		 * type.  Kill it.  We would not have to do this if termcap
! 		 * didn't have the bug that if TERMCAP is specified and
! 		 * the TERM value is not found in it, /etc/termcap is not
! 		 * searched.
! 		 */
! 		if (0 != putenv("TERMCAP="))
! 			fprintf(stderr, "Unset TERMCAP manually.\r\n");
! 	}
! 			
  	/* Then fork the shell
  	 */
  	if ((shell = getenv("SHELL")) == (char *) 0)