[comp.sources.d] SC6 Patches For 'Funky' cpps

scs@lokkur.UUCP (Steve Simmons) (03/27/89)

In the recent posting of sc6, a macro "ctl(c)" was used to create
control characters.  On some preprocessors, it caused major league
barfing.  The macro was defined
 #define ctl(x) ('x'&037)
and used
  ctl(a)
This caused severe problems with C preprocessors that don't like to
substitute inside of quotes.  The following patches change the macro
definition to
 #define ctl(x) (x&037)
and change the usage to match.  I believe the changed code is a more
generally accepted (portable) form.

Many thanks for the new sc6, by the way -- the help facility alone
is worth the hassle of upgrading.

Steve Simmons
  

*** original/cmds.c	Thu Mar 23 20:48:34 1989
--- cmds.c	Thu Mar 23 21:12:50 1989
***************
*** 319,337 ****
  	case 'r':
  	case 'l':
  	case 'h':
! 	case ctl(f):
! 	case ctl(b):	return ('r');
  
  	case 'c':
  	case 'j':
  	case 'k':
! 	case ctl(p):
! 	case ctl(n):	return ('c');
  
  	case 'm':	return ((ch == 'p') ? 'm' : 0);
  
  	case ESC:
! 	case ctl (g):	return (ESC);
  
  	default:	return (0);
      }
--- 319,337 ----
  	case 'r':
  	case 'l':
  	case 'h':
! 	case ctl('f'):
! 	case ctl('b'):	return ('r');
  
  	case 'c':
  	case 'j':
  	case 'k':
! 	case ctl('p'):
! 	case ctl('n'):	return ('c');
  
  	case 'm':	return ((ch == 'p') ? 'm' : 0);
  
  	case ESC:
! 	case ctl ('g'):	return (ESC);
  
  	default:	return (0);
      }
*** original/lex.c	Thu Mar 23 20:48:07 1989
--- lex.c	Thu Mar 23 21:15:31 1989
***************
*** 65,71 ****
  #include "statres.h"
      0, 0};
  
! #define ctl(x) ('x'&037)
  
  yylex ()
  {
--- 65,71 ----
  #include "statres.h"
      0, 0};
  
! #define ctl(x) (x&037)
  
  yylex ()
  {
***************
*** 255,264 ****
         c = getchar();
  
      switch (c) {
!     case SMG$K_TRM_LEFT:  c = ctl(b); break;
!     case SMG$K_TRM_RIGHT: c = ctl(f); break;
!     case SMG$K_TRM_UP:    c = ctl(p); break;
!     case SMG$K_TRM_DOWN:  c = ctl(n); break;
      default:   c = c & 0x7f;
      }
      return (c);
--- 255,264 ----
         c = getchar();
  
      switch (c) {
!     case SMG$K_TRM_LEFT:  c = ctl('b'); break;
!     case SMG$K_TRM_RIGHT: c = ctl('f'); break;
!     case SMG$K_TRM_UP:    c = ctl('p'); break;
!     case SMG$K_TRM_DOWN:  c = ctl('n'); break;
      default:   c = c & 0x7f;
      }
      return (c);
***************
*** 320,328 ****
  #endif
  
  char dont_use[] = {
!     ctl(z), ctl(r), ctl(l), ctl(b), ctl(c), ctl(f), ctl(g), ctl([),
!     ctl(h), ctl(m), ctl(j), ctl(n), ctl(p), ctl(q), ctl(s), ctl(t),
!     ctl(u), ctl(v), ctl(e), ctl(a), ctl(i), ctl(w), 0,
  };
  
  charout(c)
--- 320,328 ----
  #endif
  
  char dont_use[] = {
!     ctl('z'), ctl('r'), ctl('l'), ctl('b'), ctl('c'), ctl('f'), ctl('g'), ctl('['),
!     ctl('h'), ctl('m'), ctl('j'), ctl('n'), ctl('p'), ctl('q'), ctl('s'), ctl('t'),
!     ctl('u'), ctl('v'), ctl('e'), ctl('a'), ctl('i'), ctl('w'), 0,
  };
  
  charout(c)
***************
*** 342,351 ****
      if (tgetent(buf, getenv("TERM")) <= 0)
  	return;
  
!     km[0].k_str = tgetstr("kl", &p); km[0].k_val = ctl(b);
!     km[1].k_str = tgetstr("kr", &p); km[1].k_val = ctl(f);
!     km[2].k_str = tgetstr("ku", &p); km[2].k_val = ctl(p);
!     km[3].k_str = tgetstr("kd", &p); km[3].k_val = ctl(n);
      ktmp = tgetstr("ks",&p);
      if (ktmp)  {
  	(void) strcpy(ks_buf, ktmp);
--- 342,351 ----
      if (tgetent(buf, getenv("TERM")) <= 0)
  	return;
  
!     km[0].k_str = tgetstr("kl", &p); km[0].k_val = ctl('b');
!     km[1].k_str = tgetstr("kr", &p); km[1].k_val = ctl('f');
!     km[2].k_str = tgetstr("ku", &p); km[2].k_val = ctl('p');
!     km[3].k_str = tgetstr("kd", &p); km[3].k_val = ctl('n');
      ktmp = tgetstr("ks",&p);
      if (ktmp)  {
  	(void) strcpy(ks_buf, ktmp);
***************
*** 375,383 ****
  #ifdef TIOCSLTC
      (void)ioctl(fileno(stdin), TIOCGLTC, (char *)&old_chars);
      new_chars = old_chars;
!     if (old_chars.t_lnextc == ctl(v))
  	new_chars.t_lnextc = -1;
!     if (old_chars.t_rprntc == ctl(r))
  	new_chars.t_rprntc = -1;
      (void)ioctl(fileno(stdin), TIOCSLTC, (char *)&new_chars);
  #endif
--- 375,383 ----
  #ifdef TIOCSLTC
      (void)ioctl(fileno(stdin), TIOCGLTC, (char *)&old_chars);
      new_chars = old_chars;
!     if (old_chars.t_lnextc == ctl('v'))
  	new_chars.t_lnextc = -1;
!     if (old_chars.t_rprntc == ctl('r'))
  	new_chars.t_rprntc = -1;
      (void)ioctl(fileno(stdin), TIOCSLTC, (char *)&new_chars);
  #endif
***************
*** 502,511 ****
  
      c = getch();
      switch (c) {
!     case KEY_LEFT:  c = ctl(b); break;
!     case KEY_RIGHT: c = ctl(f); break;
!     case KEY_UP:    c = ctl(p); break;
!     case KEY_DOWN:  c = ctl(n); break;
  #ifdef KEY_C1
  /* This stuff works for a wyse wy75 in ANSI mode under 5.3.  Good luck. */
  /* It is supposed to map the curses keypad back to the numeric equiv. */
--- 502,511 ----
  
      c = getch();
      switch (c) {
!     case KEY_LEFT:  c = ctl('b'); break;
!     case KEY_RIGHT: c = ctl('f'); break;
!     case KEY_UP:    c = ctl('p'); break;
!     case KEY_DOWN:  c = ctl('n'); break;
  #ifdef KEY_C1
  /* This stuff works for a wyse wy75 in ANSI mode under 5.3.  Good luck. */
  /* It is supposed to map the curses keypad back to the numeric equiv. */
***************
*** 520,526 ****
      case KEY_F(10): c = '8'; break;
      case KEY_F0:    c = '9'; break;
      case KEY_C3:    c = '.'; break;
!     case KEY_ENTER: c = ctl(m); break;
  #endif
  #ifndef INTERNATIONAL
      default:   c = c & 0x7f; 
--- 520,526 ----
      case KEY_F(10): c = '8'; break;
      case KEY_F0:    c = '9'; break;
      case KEY_C3:    c = '.'; break;
!     case KEY_ENTER: c = ctl('m'); break;
  #endif
  #ifndef INTERNATIONAL
      default:   c = c & 0x7f; 
*** original/sc.c	Thu Mar 23 20:47:59 1989
--- sc.c	Thu Mar 23 21:17:12 1989
***************
*** 659,665 ****
  	if ((c < ' ') || ( c == DEL ))
  	    switch (c) {
  #ifdef SIGTSTP
! 		case ctl (z):
  		    deraw();
  		    (void) kill(getpid(),SIGTSTP);
  
--- 659,665 ----
  	if ((c < ' ') || ( c == DEL ))
  	    switch (c) {
  #ifdef SIGTSTP
! 		case ctl ('z'):
  		    deraw();
  		    (void) kill(getpid(),SIGTSTP);
  
***************
*** 668,681 ****
  		    goraw();
  		    break;
  #endif
! 		case ctl (r):
! 		case ctl (l):
  		    FullUpdate++;
! 		    if (c == ctl (r))
  			showneed = 1;
  		    (void) clearok(stdscr,1);
  		    break;
! 		case ctl (x):
  		    FullUpdate++;
  		    showexpr = 1;
  		    (void) clearok(stdscr,1);
--- 668,681 ----
  		    goraw();
  		    break;
  #endif
! 		case ctl ('r'):
! 		case ctl ('l'):
  		    FullUpdate++;
! 		    if (c == ctl ('r'))
  			showneed = 1;
  		    (void) clearok(stdscr,1);
  		    break;
! 		case ctl ('x'):
  		    FullUpdate++;
  		    showexpr = 1;
  		    (void) clearok(stdscr,1);
***************
*** 683,707 ****
  		default:
  		    error ("No such command (^%c)", c + 0100);
  		    break;
! 		case ctl (b):
  		    backcol(arg);
  		    break;
! 		case ctl (c):
  		    running = 0;
  		    break;
  
! 		case ctl (e):
  
  		    switch (nmgetch()) {
! 		    case ctl (p): case 'k':	doend (-1, 0);	break;
! 		    case ctl (n): case 'j':	doend ( 1, 0);	break;
! 		    case ctl (b): case 'h':
! 		    case ctl (h):		doend ( 0,-1);	break;
! 		    case ctl (f): case 'l':
! 		    case ctl (i): case ' ':	doend ( 0, 1);	break;
  
  		    case ESC:
! 		    case ctl (g):
  			break;
  
  		    default:
--- 683,707 ----
  		default:
  		    error ("No such command (^%c)", c + 0100);
  		    break;
! 		case ctl ('b'):
  		    backcol(arg);
  		    break;
! 		case ctl ('c'):
  		    running = 0;
  		    break;
  
! 		case ctl ('e'):
  
  		    switch (nmgetch()) {
! 		    case ctl ('p'): case 'k':	doend (-1, 0);	break;
! 		    case ctl ('n'): case 'j':	doend ( 1, 0);	break;
! 		    case ctl ('b'): case 'h':
! 		    case ctl ('h'):		doend ( 0,-1);	break;
! 		    case ctl ('f'): case 'l':
! 		    case ctl ('i'): case ' ':	doend ( 0, 1);	break;
  
  		    case ESC:
! 		    case ctl ('g'):
  			break;
  
  		    default:
***************
*** 711,720 ****
  
  		    break;
  
! 		case ctl (f):
  		    forwcol(arg);
  		    break;
! 		case ctl (g):
  		case ESC:	/* ctl ([) */
  		    showrange = 0;
  		    linelim = -1;
--- 711,720 ----
  
  		    break;
  
! 		case ctl ('f'):
  		    forwcol(arg);
  		    break;
! 		case ctl ('g'):
  		case ESC:	/* ctl ([) */
  		    showrange = 0;
  		    linelim = -1;
***************
*** 722,728 ****
  		    (void) clrtoeol ();
  		    break;
  		case DEL:
! 		case ctl (h):
  		    if (linelim <= 0) {	/* not editing line */
  			backcol(arg);	/* treat like ^B    */
  			break;
--- 722,728 ----
  		    (void) clrtoeol ();
  		    break;
  		case DEL:
! 		case ctl ('h'):
  		    if (linelim <= 0) {	/* not editing line */
  			backcol(arg);	/* treat like ^B    */
  			break;
***************
*** 730,736 ****
  		    while (--arg>=0) if (linelim > 0)
  			line[--linelim] = 0;
  		    break;
! 		case ctl (i): 		/* tab */
  		    if (linelim <= 0) {	/* not editing line */
  			forwcol(arg);
  			break;
--- 730,736 ----
  		    while (--arg>=0) if (linelim > 0)
  			line[--linelim] = 0;
  		    break;
! 		case ctl ('i'): 		/* tab */
  		    if (linelim <= 0) {	/* not editing line */
  			forwcol(arg);
  			break;
***************
*** 747,754 ****
  		    }
  		    linelim = strlen (line);
  		    break;
! 		case ctl (m):
! 		case ctl (j):
  		    showrange = 0;
  		    if (linelim < 0)
  			line[linelim = 0] = 0;
--- 747,754 ----
  		    }
  		    linelim = strlen (line);
  		    break;
! 		case ctl ('m'):
! 		case ctl ('j'):
  		    showrange = 0;
  		    if (linelim < 0)
  			line[linelim = 0] = 0;
***************
*** 758,774 ****
  			linelim = -1;
  		    }
  		    break;
! 		case ctl (n):
  		    forwrow(arg);
  		    break;
! 		case ctl (p):
  		    backrow(arg);
  		    break;
! 		case ctl (q):
  		    break;	/* ignore flow control */
! 		case ctl (s):
  		    break;	/* ignore flow control */
! 		case ctl (t):
  		    error(
  "Toggle:  a:auto  c:cell  e:ext funcs  n:numeric  t:top  x:encrypt  $:pre-scale");
  		    (void) refresh();
--- 758,774 ----
  			linelim = -1;
  		    }
  		    break;
! 		case ctl ('n'):
  		    forwrow(arg);
  		    break;
! 		case ctl ('p'):
  		    backrow(arg);
  		    break;
! 		case ctl ('q'):
  		    break;	/* ignore flow control */
! 		case ctl ('s'):
  		    break;	/* ignore flow control */
! 		case ctl ('t'):
  		    error(
  "Toggle:  a:auto  c:cell  e:ext funcs  n:numeric  t:top  x:encrypt  $:pre-scale");
  		    (void) refresh();
***************
*** 815,821 ****
  				    extfunc? "en" : "dis");
  			    break;
  			case ESC:
! 			case ctl (g):
  			    break;
  			default:
  			    error ("Invalid toggle command");
--- 815,821 ----
  				    extfunc? "en" : "dis");
  			    break;
  			case ESC:
! 			case ctl ('g'):
  			    break;
  			default:
  			    error ("Invalid toggle command");
***************
*** 823,842 ****
  		    FullUpdate++;
  		    modflg++;
  		    break;
! 		case ctl (u):
  		    narg = arg * 4;
  		    nedistate = 1;
  		    break;
! 		case ctl (v):	/* insert variable name */
  		    if (linelim > 0) {
  		    (void) sprintf (line+linelim,"%s", v_name(currow, curcol));
  			linelim = strlen (line);
  		    }
  		    break;
! 		case ctl (w):	/* insert variable expression */
  		    if (linelim > 0) editexp(currow,curcol);
  		    break;
! 		case ctl (a):	/* insert variable value */
  		    if (linelim > 0) {
  			struct ent *p = tbl[currow][curcol];
  
--- 823,842 ----
  		    FullUpdate++;
  		    modflg++;
  		    break;
! 		case ctl ('u'):
  		    narg = arg * 4;
  		    nedistate = 1;
  		    break;
! 		case ctl ('v'):	/* insert variable name */
  		    if (linelim > 0) {
  		    (void) sprintf (line+linelim,"%s", v_name(currow, curcol));
  			linelim = strlen (line);
  		    }
  		    break;
! 		case ctl ('w'):	/* insert variable expression */
  		    if (linelim > 0) editexp(currow,curcol);
  		    break;
! 		case ctl ('a'):	/* insert variable value */
  		    if (linelim > 0) {
  			struct ent *p = tbl[currow][curcol];
  
***************
*** 1033,1039 ****
  				break;
  				
  			    case ESC:
! 			    case ctl (g):
  				break;
  			   default:
  				error("Invalid region command");
--- 1033,1039 ----
  				break;
  				
  			    case ESC:
! 			    case ctl ('g'):
  				break;
  			   default:
  				error("Invalid region command");
***************
*** 1062,1068 ****
  
  				error ("");	/* clear line */
  
! 				if ( rcqual == ESC || rcqual == ctl(g))
  				    break;
  
  				switch (c) {
--- 1062,1068 ----
  
  				error ("");	/* clear line */
  
! 				if ( rcqual == ESC || rcqual == ctl('g'))
  				    break;
  
  				switch (c) {
***************
*** 1474,1480 ****
   	if (ch != 'n' && ch != 'N') {
   	    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
   		return (1);
! 	} else if (ch == ctl (g) || ch == ESC) return(1);
      } else if (modflg) {
  	char ch, lin[100];
  
--- 1474,1480 ----
   	if (ch != 'n' && ch != 'N') {
   	    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
   		return (1);
! 	} else if (ch == ctl ('g') || ch == ESC) return(1);
      } else if (modflg) {
  	char ch, lin[100];
  
*** original/sc.h	Thu Mar 23 21:10:03 1989
--- sc.h	Thu Mar 23 21:12:10 1989
***************
*** 138,144 ****
  #define is_leftflush 0010
  #define is_deleted   0020
  
! #define ctl(c) ('c'&037)
  #define ESC 033
  #define DEL 0177
  
--- 138,144 ----
  #define is_leftflush 0010
  #define is_deleted   0020
  
! #define ctl(c) (c&037)
  #define ESC 033
  #define DEL 0177
  
-- 
+ Steve Simmons, Inland Sea Software, Ltd.         scs@lokkur.dexter.mi.us +
|    9353 Hidden Lake, Dexter, MI. 48130                   313-426-8981    |
+          "When Dexter's on the Internet can Hell be far behind?"         +