[comp.sources.bugs] Patches to screen

damon@upba.UUCP (Damon Scaggs) (12/21/87)

Enclosed are two patches for the program screen in the comp.sources.unix
archives.  The first is a VERY minor fix to make screens pay attention if
you disable SIGHUP in your .profile file.  The second fixes a more serious
bug that occurs when you have programs updating two seperate screens
simultaneously.  Escape code arguments were kept globally rather than local
to a specific screen and could collide with each other if you received them
from more than one screen at a time.

The following is a shar file containing the two patches, so you can't just
send this through patch directly.

Damon Scaggs
ihnp4!upba!damon

----------------------------------------------------------------------------
: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
echo 'Extracting PATCH1'
sed 's/^X//' > PATCH1 << '+ END-OF-FILE PATCH1'
X*** screen.c.old	Fri Dec 11 13:18:54 1987
X--- screen.c	Fri Dec 11 13:18:52 1987
X***************
X*** 241,247
X  #ifdef LOADAV
X      InitKmem ();
X  #endif
X!     signal (SIGHUP, Finit);
X      signal (SIGINT, Finit);
X      signal (SIGQUIT, Finit);
X      signal (SIGTERM, Finit);
X
X--- 241,248 -----
X  #ifdef LOADAV
X      InitKmem ();
X  #endif
X!     if (signal (SIGHUP, Finit) == SIG_IGN)
X! 	signal (SIGHUP, SIG_IGN);
X      signal (SIGINT, Finit);
X      signal (SIGQUIT, Finit);
X      signal (SIGTERM, Finit);
+ END-OF-FILE PATCH1
chmod 'u=rw,g=rw,o=' 'PATCH1'
echo '	-rw-rw----  1 damon         503 Dec 11 13:22 PATCH1        (as sent)'
echo -n '	'
/bin/ls -l PATCH1
echo 'Extracting PATCH2'
sed 's/^X//' > PATCH2 << '+ END-OF-FILE PATCH2'
X*** ansi.c.old	Fri Dec 11 13:46:42 1987
X--- ansi.c	Fri Dec 11 13:52:55 1987
X***************
X*** 33,39
X      M_CR,
X  };
X  
X- #define MAXARGS      64
X  #define EXPENSIVE    1000
X  
X  extern char *getenv(), *tgetstr(), *tgoto(), *malloc();
X
X--- 33,38 -----
X      M_CR,
X  };
X  
X  #define EXPENSIVE    1000
X  
X  extern char *getenv(), *tgetstr(), *tgoto(), *malloc();
X***************
X*** 54,62
X  static char *CS, *DL, *DC, *IC, *IM, *EI, *UP, *ND, *KS, *KE;
X  static char *MB, *MD, *MH, *MR, *ME;
X  static AM;
X- static args[MAXARGS];
X- static char GotArg[MAXARGS];
X- static NumArgs;
X  static char GlobalAttr, TmpAttr;
X  static char *OldImage, *OldAttr;
X  static last_x, last_y;
X
X--- 53,58 -----
X  static char *CS, *DL, *DC, *IC, *IM, *EI, *UP, *ND, *KS, *KE;
X  static char *MB, *MD, *MH, *MR, *ME;
X  static AM;
X  static char GlobalAttr, TmpAttr;
X  static char *OldImage, *OldAttr;
X  static last_x, last_y;
X***************
X*** 374,380
X  	case ESC:
X  	    switch (c) {
X  	    case '[':
X! 		NumArgs = 0;
X  		intermediate = 0;
X  		bzero ((char *)args, MAXARGS * sizeof (int));
X  		bzero (GotArg, MAXARGS);
X
X--- 370,376 -----
X  	case ESC:
X  	    switch (c) {
X  	    case '[':
X! 		curr->NumArgs = 0;
X  		intermediate = 0;
X  		bzero ((char *)curr->args, MAXARGS * sizeof (int));
X  		bzero (curr->GotArg, MAXARGS);
X***************
X*** 376,383
X  	    case '[':
X  		NumArgs = 0;
X  		intermediate = 0;
X! 		bzero ((char *)args, MAXARGS * sizeof (int));
X! 		bzero (GotArg, MAXARGS);
X  		curr->state = CSI;
X  		break;
X  	    case ']':
X
X--- 372,379 -----
X  	    case '[':
X  		curr->NumArgs = 0;
X  		intermediate = 0;
X! 		bzero ((char *)curr->args, MAXARGS * sizeof (int));
X! 		bzero (curr->GotArg, MAXARGS);
X  		curr->state = CSI;
X  		break;
X  	    case ']':
X***************
X*** 406,414
X  	    switch (c) {
X  	    case '0': case '1': case '2': case '3': case '4':
X  	    case '5': case '6': case '7': case '8': case '9':
X! 		if (NumArgs < MAXARGS) {
X! 		    args[NumArgs] = 10 * args[NumArgs] + c - '0';
X! 		    GotArg[NumArgs] = 1;
X  		}
X  		break;
X  	    case ';': case ':':
X
X--- 402,411 -----
X  	    switch (c) {
X  	    case '0': case '1': case '2': case '3': case '4':
X  	    case '5': case '6': case '7': case '8': case '9':
X! 		if (curr->NumArgs < MAXARGS) {
X! 		    curr->args[curr->NumArgs] =
X!                         10 * curr->args[curr->NumArgs] + c - '0';
X! 		    curr->GotArg[curr->NumArgs] = 1;
X  		}
X  		break;
X  	    case ';': case ':':
X***************
X*** 412,418
X  		}
X  		break;
X  	    case ';': case ':':
X! 		NumArgs++; break;
X  	    default:
X  		if (Special (c))
X  		    break;
X
X--- 409,415 -----
X  		}
X  		break;
X  	    case ';': case ':':
X! 		curr->NumArgs++; break;
X  	    default:
X  		if (Special (c))
X  		    break;
X***************
X*** 417,423
X  		if (Special (c))
X  		    break;
X  		if (c >= '@' && c <= '~') {
X! 		    NumArgs++;
X  		    DoCSI (c, intermediate);
X  		    curr->state = LIT;
X  		} else if ((c >= ' ' && c <= '/') || (c >= '<' && c <= '?')) {
X
X--- 414,420 -----
X  		if (Special (c))
X  		    break;
X  		if (c >= '@' && c <= '~') {
X! 		    curr->NumArgs++;
X  		    DoCSI (c, intermediate);
X  		    curr->state = LIT;
X  		} else if ((c >= ' ' && c <= '/') || (c >= '<' && c <= '?')) {
X***************
X*** 548,554
X  }
X  
X  static DoCSI (c, intermediate) {
X!     register i, a1 = args[0], a2 = args[1];
X  
X      if (NumArgs >= MAXARGS)
X  	NumArgs = MAXARGS;
X
X--- 545,551 -----
X  }
X  
X  static DoCSI (c, intermediate) {
X!     register i, a1 = curr->args[0], a2 = curr->args[1];
X  
X      if (curr->NumArgs >= MAXARGS)
X  	curr->NumArgs = MAXARGS;
X***************
X*** 550,560
X  static DoCSI (c, intermediate) {
X      register i, a1 = args[0], a2 = args[1];
X  
X!     if (NumArgs >= MAXARGS)
X! 	NumArgs = MAXARGS;
X!     for (i = 0; i < NumArgs; ++i)
X! 	if (args[i] == 0)
X! 	    GotArg[i] = 0;
X      switch (intermediate) {
X      case 0:
X  	switch (c) {
X
X--- 547,557 -----
X  static DoCSI (c, intermediate) {
X      register i, a1 = curr->args[0], a2 = curr->args[1];
X  
X!     if (curr->NumArgs >= MAXARGS)
X! 	curr->NumArgs = MAXARGS;
X!     for (i = 0; i < curr->NumArgs; ++i)
X! 	if (curr->args[i] == 0)
X! 	    curr->GotArg[i] = 0;
X      switch (intermediate) {
X      case 0:
X  	switch (c) {
X***************
X*** 559,566
X      case 0:
X  	switch (c) {
X  	case 'H': case 'f':
X! 	    if (!GotArg[0]) a1 = 1;
X! 	    if (!GotArg[1]) a2 = 1;
X  	    if (curr->origin)
X  		a1 += curr->top;
X  	    if (a1 < 1)
X
X--- 556,563 -----
X      case 0:
X  	switch (c) {
X  	case 'H': case 'f':
X! 	    if (!curr->GotArg[0]) a1 = 1;
X! 	    if (!curr->GotArg[1]) a2 = 1;
X  	    if (curr->origin)
X  		a1 += curr->top;
X  	    if (a1 < 1)
X***************
X*** 577,583
X  	    curr->x = a2;
X  	    break;
X  	case 'J':
X! 	    if (!GotArg[0] || a1 < 0 || a1 > 2)
X  		a1 = 0;
X  	    switch (a1) {
X  	    case 0:
X
X--- 574,580 -----
X  	    curr->x = a2;
X  	    break;
X  	case 'J':
X! 	    if (!curr->GotArg[0] || a1 < 0 || a1 > 2)
X  		a1 = 0;
X  	    switch (a1) {
X  	    case 0:
X***************
X*** 591,597
X  	    }
X  	    break;
X  	case 'K':
X! 	    if (!GotArg[0] || a1 < 0 || a2 > 2)
X  		a1 = 0;
X  	    switch (a1) {
X  	    case 0:
X
X--- 588,594 -----
X  	    }
X  	    break;
X  	case 'K':
X! 	    if (!curr->GotArg[0] || a1 < 0 || a2 > 2)
X  		a1 = 0;
X  	    switch (a1) {
X  	    case 0:
X***************
X*** 603,609
X  	    }
X  	    break;
X  	case 'A':
X! 	    CursorUp (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'B':
X  	    CursorDown (GotArg[0] ? a1 : 1);
X
X--- 600,606 -----
X  	    }
X  	    break;
X  	case 'A':
X! 	    CursorUp (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'B':
X  	    CursorDown (curr->GotArg[0] ? a1 : 1);
X***************
X*** 606,612
X  	    CursorUp (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'B':
X! 	    CursorDown (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'C':
X  	    CursorRight (GotArg[0] ? a1 : 1);
X
X--- 603,609 -----
X  	    CursorUp (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'B':
X! 	    CursorDown (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'C':
X  	    CursorRight (curr->GotArg[0] ? a1 : 1);
X***************
X*** 609,615
X  	    CursorDown (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'C':
X! 	    CursorRight (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'D':
X  	    CursorLeft (GotArg[0] ? a1 : 1);
X
X--- 606,612 -----
X  	    CursorDown (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'C':
X! 	    CursorRight (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'D':
X  	    CursorLeft (curr->GotArg[0] ? a1 : 1);
X***************
X*** 612,618
X  	    CursorRight (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'D':
X! 	    CursorLeft (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'm':
X  	    SelectRendition ();
X
X--- 609,615 -----
X  	    CursorRight (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'D':
X! 	    CursorLeft (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'm':
X  	    SelectRendition ();
X***************
X*** 618,624
X  	    SelectRendition ();
X  	    break;
X  	case 'g':
X! 	    if (!GotArg[0] || a1 == 0)
X  		curr->tabs[curr->x] = 0;
X  	    else if (a1 == 3)
X  		bzero (curr->tabs, cols);
X
X--- 615,621 -----
X  	    SelectRendition ();
X  	    break;
X  	case 'g':
X! 	    if (!curr->GotArg[0] || a1 == 0)
X  		curr->tabs[curr->x] = 0;
X  	    else if (a1 == 3)
X  		bzero (curr->tabs, cols);
X***************
X*** 626,633
X  	case 'r':
X  	    if (!CS)
X  		break;
X! 	    if (!GotArg[0]) a1 = 1;
X! 	    if (!GotArg[1]) a2 = rows;
X  	    if (a1 < 1 || a2 > rows || a1 >= a2)
X  		break;
X  	    curr->top = a1-1;
X
X--- 623,630 -----
X  	case 'r':
X  	    if (!CS)
X  		break;
X! 	    if (!curr->GotArg[0]) a1 = 1;
X! 	    if (!curr->GotArg[1]) a2 = rows;
X  	    if (a1 < 1 || a2 > rows || a1 >= a2)
X  		break;
X  	    curr->top = a1-1;
X***************
X*** 643,649
X  	    }
X  	    break;
X  	case 'I':
X! 	    if (!GotArg[0]) a1 = 1;
X  	    while (a1--)
X  		ForwardTab ();
X  	    break;
X
X--- 640,646 -----
X  	    }
X  	    break;
X  	case 'I':
X! 	    if (!curr->GotArg[0]) a1 = 1;
X  	    while (a1--)
X  		ForwardTab ();
X  	    break;
X***************
X*** 648,654
X  		ForwardTab ();
X  	    break;
X  	case 'Z':
X! 	    if (!GotArg[0]) a1 = 1;
X  	    while (a1--)
X  		BackwardTab ();
X  	    break;
X
X--- 645,651 -----
X  		ForwardTab ();
X  	    break;
X  	case 'Z':
X! 	    if (!curr->GotArg[0]) a1 = 1;
X  	    while (a1--)
X  		BackwardTab ();
X  	    break;
X***************
X*** 653,659
X  		BackwardTab ();
X  	    break;
X  	case 'L':
X! 	    InsertLine (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'M':
X  	    DeleteLine (GotArg[0] ? a1 : 1);
X
X--- 650,656 -----
X  		BackwardTab ();
X  	    break;
X  	case 'L':
X! 	    InsertLine (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'M':
X  	    DeleteLine (curr->GotArg[0] ? a1 : 1);
X***************
X*** 656,662
X  	    InsertLine (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'M':
X! 	    DeleteLine (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'P':
X  	    DeleteChar (GotArg[0] ? a1 : 1);
X
X--- 653,659 -----
X  	    InsertLine (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'M':
X! 	    DeleteLine (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'P':
X  	    DeleteChar (curr->GotArg[0] ? a1 : 1);
X***************
X*** 659,665
X  	    DeleteLine (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'P':
X! 	    DeleteChar (GotArg[0] ? a1 : 1);
X  	    break;
X  	case '@':
X  	    InsertChar (GotArg[0] ? a1 : 1);
X
X--- 656,662 -----
X  	    DeleteLine (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'P':
X! 	    DeleteChar (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case '@':
X  	    InsertChar (curr->GotArg[0] ? a1 : 1);
X***************
X*** 662,668
X  	    DeleteChar (GotArg[0] ? a1 : 1);
X  	    break;
X  	case '@':
X! 	    InsertChar (GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'h':
X  	    SetMode (1);
X
X--- 659,665 -----
X  	    DeleteChar (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case '@':
X! 	    InsertChar (curr->GotArg[0] ? a1 : 1);
X  	    break;
X  	case 'h':
X  	    SetMode (1);
X***************
X*** 675,681
X      case '?':
X  	if (c != 'h' && c != 'l')
X  	    break;
X! 	if (!GotArg[0])
X  	    break;
X  	i = (c == 'h');
X  	if (a1 == 5) {
X
X--- 672,678 -----
X      case '?':
X  	if (c != 'h' && c != 'l')
X  	    break;
X! 	if (!curr->GotArg[0])
X  	    break;
X  	i = (c == 'h');
X  	if (a1 == 5) {
X***************
X*** 1228,1235
X  static SetMode (on) {
X      register i;
X  
X!     for (i = 0; i < NumArgs; ++i) {
X! 	switch (args[i]) {
X  	case 4:
X  	    curr->insert = on;
X  	    InsertMode (on);
X
X--- 1225,1232 -----
X  static SetMode (on) {
X      register i;
X  
X!     for (i = 0; i < curr->NumArgs; ++i) {
X! 	switch (curr->args[i]) {
X  	case 4:
X  	    curr->insert = on;
X  	    InsertMode (on);
X***************
X*** 1241,1247
X  static SelectRendition () {
X      register i, old = GlobalAttr;
X  
X!     if (NumArgs == 0)
X  	SetRendition (0);
X      else for (i = 0; i < NumArgs; ++i)
X  	SetRendition (args[i]);
X
X--- 1238,1244 -----
X  static SelectRendition () {
X      register i, old = GlobalAttr;
X  
X!     if (curr->NumArgs == 0)
X  	SetRendition (0);
X      else for (i = 0; i < curr->NumArgs; ++i)
X  	SetRendition (curr->args[i]);
X***************
X*** 1243,1250
X  
X      if (NumArgs == 0)
X  	SetRendition (0);
X!     else for (i = 0; i < NumArgs; ++i)
X! 	SetRendition (args[i]);
X      NewRendition (old, GlobalAttr);
X  }
X  
X
X--- 1240,1247 -----
X  
X      if (curr->NumArgs == 0)
X  	SetRendition (0);
X!     else for (i = 0; i < curr->NumArgs; ++i)
X! 	SetRendition (curr->args[i]);
X      NewRendition (old, GlobalAttr);
X  }
X  
X*** screen.h.old	Fri Dec 11 13:46:48 1987
X--- screen.h	Fri Dec 11 13:48:21 1987
X***************
X*** 25,30
X  };
X  
X  #define MAXSTR       128
X  
X  #define IOSIZE       80
X  
X
X--- 25,31 -----
X  };
X  
X  #define MAXSTR       128
X+ #define	MAXARGS      64
X  
X  #define IOSIZE       80
X  
X***************
X*** 36,41
X      int outlen;
X      char cmd[MAXSTR];
X      char tty[MAXSTR];
X      int slot;
X      char **image;
X      char **attr;
X
X--- 37,45 -----
X      int outlen;
X      char cmd[MAXSTR];
X      char tty[MAXSTR];
X+     int args[MAXARGS];
X+     char GotArg[MAXARGS];
X+     int NumArgs;
X      int slot;
X      char **image;
X      char **attr;
X*** screen.c.old	Fri Dec 11 13:46:54 1987
X--- screen.c	Fri Dec 11 14:01:52 1987
X***************
X*** 38,44
X  #endif
X  
X  #define MAXWIN     10
X- #define MAXARGS    64
X  #define MAXLINE  1024
X  #define MSGWAIT     5
X  
X
X--- 38,43 -----
X  #endif
X  
X  #define MAXWIN     10
X  #define MAXLINE  1024
X  #define MSGWAIT     5
X  
+ END-OF-FILE PATCH2
chmod 'u=rw,g=rw,o=' 'PATCH2'
echo '	-rw-rw----  1 damon       12292 Dec 11 15:28 PATCH2        (as sent)'
echo -n '	'
/bin/ls -l PATCH2
exit 0

-- 
Damon Scaggs
ihnp4!upba!damon