sc 6.1 - Allow ANSI pre-processor and read-only strings

Rob McMahon cudcv at warwick.ac.uk
Sun Apr 2 05:40:38 AEST 1989


There are two problems with compiling sc with an ANSI compiler such as gcc.
The first is the ctl macro relies on a non-ANSI pre-processor which will do
replacement of macro arguments within strings, this will stop it compiling at
all.  The second is that it tries to write to strings constants, which may be
in read-only memory, so that it dumps core as soon as you try to run it.
These patches fix both of these problems, most of the patches are for the ctl
macro, the first two of the patches to sc.c are for read-only strings.

RCS file: cmds.c,v
retrieving revision 1.1
diff -c -r1.1 cmds.c
*** /tmp/,RCSt1a12449	Sat Apr  1 20:34:58 1989
--- cmds.c	Sat Apr  1 18:04:10 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);
      }
===================================================================
RCS file: lex.c,v
retrieving revision 1.1
diff -c -r1.1 lex.c
*** /tmp/,RCSt1a12449	Sat Apr  1 20:35:05 1989
--- lex.c	Sat Apr  1 18:04:15 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,329 ----
  #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);
--- 343,352 ----
      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
--- 376,384 ----
  #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. */
--- 503,512 ----
  
      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; 
--- 521,527 ----
      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; 
===================================================================
RCS file: sc.c,v
retrieving revision 1.1
diff -c -r1.1 sc.c
*** /tmp/,RCSt1a12449	Sat Apr  1 20:35:11 1989
--- sc.c	Sat Apr  1 20:26:43 1989
***************
*** 82,88 ****
  
  int  lastmx, lastmy;	/* Screen address of the cursor */
  int  lastcol;		/* Spreadsheet Column the cursor was in last */
! char *under_cursor = " "; /* Data under the < cursor */
  
  #ifdef VMS
  int VMS_read_raw = 0;
--- 82,88 ----
  
  int  lastmx, lastmy;	/* Screen address of the cursor */
  int  lastcol;		/* Spreadsheet Column the cursor was in last */
! char under_cursor[] = " "; /* Data under the < cursor */
  
  #ifdef VMS
  int VMS_read_raw = 0;
***************
*** 514,522 ****
  repaint(x, y, len)
  int x, y, len;
  {
!     char *buf;
  
!     buf = " ";
  
      while(len-- > 0) {
  	(void) move(y,x);
--- 514,522 ----
  repaint(x, y, len)
  int x, y, len;
  {
!     char buf[2];
  
!     buf[1] = '\0';
  
      while(len-- > 0) {
  	(void) move(y,x);
***************
*** 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,721 ****
  
  		    break;
  
! 		case ctl (f):
  		    forwcol(arg);
  		    break;
! 		case ctl (g):
! 		case ESC:	/* ctl ([) */
  		    showrange = 0;
  		    linelim = -1;
  		    (void) move (1, 0);
--- 711,721 ----
  
  		    break;
  
! 		case ctl('f'):
  		    forwcol(arg);
  		    break;
! 		case ctl('g'):
! 		case ESC:	/* ctl('[') */
  		    showrange = 0;
  		    linelim = -1;
  		    (void) move (1, 0);
***************
*** 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];
  
===================================================================
RCS file: sc.h,v
retrieving revision 1.1
diff -c -r1.1 sc.h
*** /tmp/,RCSt1a12449	Sat Apr  1 20:35:19 1989
--- sc.h	Sat Apr  1 18:04:28 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
  

Rob
-- 
UUCP:   ...!mcvax!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv at uk.ac.warwick             ARPA:   cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England



More information about the Comp.sources.bugs mailing list