Repost - sc 5.1 patch file #1

Robert Bond rgb at nscpdc.NSC.COM
Wed Mar 9 10:59:29 AEST 1988


I posted this once before - but when I mentioned it in a recent posting
I was bombarded with "We didn't get it here".  SO, once more:

-------------------------------

This stuff is a collection of patches and a couple of small enhancements
for SC 5.1.  You will have version 5.2 when complete.

In the best tradition of Larry Wall, point this file at your sc
source directory with:

			"| patch -d scdir" 

The patches are as follows:

1) Update revision level to 5.2 in sc.c

2) Add a constant prescale toggle.  Lets you put in dollars without
   having to hit the "." key each time.  This is in sc.c and interp.c

3) Fixed a bug in the "do you want to save this" sequence.  Thanks to
   Lawrence Cipriani.  Sc.c.

4) Added some code in lex.c to change escape sequences from the keypad
   back to numbers.  This works on 5.3 with a wyse 75.  Your mileage
   may vary.  Curses to curses.

5) Two null pointer dereferences showed up.  Soren Lundsgaard found one -
   I found the other.  This is in interp.c

6) Xmalloc.c aligned everything to an int boundary.  For some machines
   it works better aligned to a double boundary.  Thanks to Andy Valencia.

Index: sc.c
Prereq: 5.1
*** /tmp/,RCSt1018847	Fri Feb 12 10:37:38 1988
--- sc.c	Fri Feb 12 10:19:48 1988
***************
*** 66,72
  int  lastmx, lastmy;	/* Screen address of the cursor */
  int  lastcol;		/* Spreadsheet Column the cursor was in last */
  char *under_cursor = " "; /* Data under the < cursor */
! char *rev = "$Revision: 5.1 $";
  
  int seenerr;
  

--- 66,72 -----
  int  lastmx, lastmy;	/* Screen address of the cursor */
  int  lastcol;		/* Spreadsheet Column the cursor was in last */
  char *under_cursor = " "; /* Data under the < cursor */
! char *rev = "$Revision: 5.2 $";
  
  int seenerr;
  
***************
*** 647,653
  		case ctl (s):
  		    break;	/* ignore flow control */
  		case ctl (t):
! 		    error("Toggle - n:numeric  t:top row  x:encryption");
  		    (void) refresh();
  		    switch (nmgetch()) {
  			case 't': case 'T':

--- 647,653 -----
  		case ctl (s):
  		    break;	/* ignore flow control */
  		case ctl (t):
! 		    error("Toggle - n:numeric  t:top row  x:encryption $:prescale");
  		    (void) refresh();
  		    switch (nmgetch()) {
  			case 't': case 'T':
***************
*** 662,667
  			    Crypt ^= 1;
  			    error("Encryption %sabled.",Crypt? "en":"dis");
  			    break;
  			default:
  			    error("Bad toggle switch");
  		    }

--- 662,676 -----
  			    Crypt ^= 1;
  			    error("Encryption %sabled.",Crypt? "en":"dis");
  			    break;
+ 			case '$':
+ 			    if (prescale == 1.0) {
+ 				error("Prescale set.");
+ 				prescale = 0.01;
+ 			    } else {
+ 				prescale = 1.0;
+ 				error("Prescale resest.");
+ 			    }
+ 			    break;
  			default:
  			    error("Bad toggle switch");
  		    }
***************
*** 1267,1273
  	(void) addstr (lin);
  	(void) refresh();
  	ch = nmgetch();
!  	if (ch != 'n' && ch != 'N')
   	    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
   		return (1);
  	else if (ch == ctl (g) || ch == ctl([)) return(1);

--- 1276,1282 -----
  	(void) addstr (lin);
  	(void) refresh();
  	ch = nmgetch();
!  	if (ch != 'n' && ch != 'N') {
   	    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
   		return (1);
  	} else if (ch == ctl (g) || ch == ctl([)) return(1);
***************
*** 1270,1276
   	if (ch != 'n' && ch != 'N')
   	    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
   		return (1);
! 	else if (ch == ctl (g) || ch == ctl([)) return(1);
      } else if (modflg) {
  	char ch, lin[100];
  

--- 1279,1285 -----
   	if (ch != 'n' && ch != 'N') {
   	    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
   		return (1);
! 	} else if (ch == ctl (g) || ch == ctl([)) return(1);
      } else if (modflg) {
  	char ch, lin[100];
  
*** /tmp/,RCSt1018869	Fri Feb 12 10:38:09 1988
--- sc.h	Fri Feb 12 10:20:10 1988
***************
*** 157,162
  extern char *mdir;
  extern char *xmalloc();
  extern int xfree();
  
  #if BSD42 || SYSIII
  

--- 157,163 -----
  extern char *mdir;
  extern char *xmalloc();
  extern int xfree();
+ extern double prescale;
  
  #if BSD42 || SYSIII
  
*** /tmp/,RCSt1018874	Fri Feb 12 10:38:12 1988
--- lex.c	Fri Feb 12 10:19:15 1988
***************
*** 388,393
      case KEY_RIGHT: c = ctl(f); break;
      case KEY_UP:    c = ctl(p); break;
      case KEY_DOWN:  c = ctl(n); break;
      default:   c = c & 0x7f; 
      }
      return (c);

--- 389,410 -----
      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. */
+     case KEY_C1:    c = '0'; break;
+     case KEY_A1:    c = '1'; break;
+     case KEY_B2:    c = '2'; break;
+     case KEY_A3:    c = '3'; break;
+     case KEY_F(5):  c = '4'; break;
+     case KEY_F(6):  c = '5'; break;
+     case KEY_F(7):  c = '6'; break;
+     case KEY_F(9):  c = '7'; break;
+     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
      default:   c = c & 0x7f; 
      }
      return (c);
*** /tmp/,RCSt1018888	Fri Feb 12 10:38:31 1988
--- interp.c	Fri Feb 12 10:19:01 1988
***************
*** 30,36
  extern char curfile[];
  
  jmp_buf fpe_save;
! int	exprerr;	/* Set by eval() and seval() if expression errors */
  
  #ifdef SYSV3
  void exit();

--- 30,37 -----
  extern char curfile[];
  
  jmp_buf fpe_save;
! int	exprerr;	   /* Set by eval() and seval() if expression errors */
! double  prescale = 1.0;    /* Prescale for constants in let() */
  
  #ifdef SYSV3
  void exit();
***************
*** 482,488
  		    } else {
  		        v = seval(p->expr);
  		    }
! 		    if (strcmp(v, p->label) != 0) {
  			chgct++;
  		        p->flags |= is_changed;
  		    }

--- 483,489 -----
  		    } else {
  		        v = seval(p->expr);
  		    }
! 		    if (!p->label || (strcmp(v, p->label) != 0)) {
  			chgct++;
  		        p->flags |= is_changed;
  		    }
***************
*** 704,710
  	return;
      }
      if (constant(e)) {
! 	v->v = val;
  	if (!(v->flags & is_strexpr)) {
              efree (v->expr);
  	    v->expr = 0;

--- 705,711 -----
  	return;
      }
      if (constant(e)) {
! 	v->v = val * prescale;
  	if (!(v->flags & is_strexpr)) {
              efree (v->expr);
  	    v->expr = 0;
***************
*** 1025,1031
      linelim = strlen(line);
      if (p->flags & is_strexpr && p->expr) {
  	editexp(row, col);
!     } else {
          (void)sprintf (line+linelim, "\"%s\"", p->label);
          linelim += strlen (line+linelim);
      }

--- 1026,1032 -----
      linelim = strlen(line);
      if (p->flags & is_strexpr && p->expr) {
  	editexp(row, col);
!     } else if (p->label) {
          (void)sprintf (line+linelim, "\"%s\"", p->label);
          linelim += strlen (line+linelim);
      } else {
***************
*** 1028,1033
      } else {
          (void)sprintf (line+linelim, "\"%s\"", p->label);
          linelim += strlen (line+linelim);
      }
  }
  

--- 1029,1037 -----
      } else if (p->label) {
          (void)sprintf (line+linelim, "\"%s\"", p->label);
          linelim += strlen (line+linelim);
+     } else {
+         (void)sprintf (line+linelim, "\"");
+         linelim += 1;
      }
  }
  
*** /tmp/,RCSt1018925	Fri Feb 12 10:39:19 1988
--- xmalloc.c	Fri Feb 12 10:20:22 1988
***************
*** 17,23
  {
  register char *ptr;
  
! if ((ptr = malloc(n + sizeof(int))) == NULL)
      fatal("xmalloc: no memory");
  *((int *) ptr) = 12345;		/* magic number */
  return(ptr + sizeof(int));

--- 17,23 -----
  {
  register char *ptr;
  
! if ((ptr = malloc(n + sizeof(double))) == NULL)
      fatal("xmalloc: no memory");
  *((int *) ptr) = 12345;		/* magic number */
  return(ptr + sizeof(double));
***************
*** 20,26
  if ((ptr = malloc(n + sizeof(int))) == NULL)
      fatal("xmalloc: no memory");
  *((int *) ptr) = 12345;		/* magic number */
! return(ptr + sizeof(int));
  }
  
  xfree(p)

--- 20,26 -----
  if ((ptr = malloc(n + sizeof(double))) == NULL)
      fatal("xmalloc: no memory");
  *((int *) ptr) = 12345;		/* magic number */
! return(ptr + sizeof(double));
  }
  
  xfree(p)
***************
*** 28,34
  {
  if (p == NULL)
      fatal("xfree: NULL");
! p -= sizeof(int);
  if (*((int *) p) != 12345)
      fatal("xfree: storage not malloc'ed");
  free(p);

--- 28,34 -----
  {
  if (p == NULL)
      fatal("xfree: NULL");
! p -= sizeof(double);
  if (*((int *) p) != 12345)
      fatal("xfree: storage not malloc'ed");
  free(p);
*** /tmp/,RCSt1018966	Fri Feb 12 10:39:41 1988
--- sc.doc	Fri Feb 12 10:20:04 1988
***************
*** 185,192
  
  .IP \fB^T\fP
  Toggle options.  This command allows the user to switch the state
! of the encryption, quick numeric entry and top line display options.
! The user should follow the ^T character with one of "x", "n", or
  "t" to pick the intended option.  A small menu lists the choices
  when ^T is typed.
  

--- 185,193 -----
  
  .IP \fB^T\fP
  Toggle options.  This command allows the user to switch the state
! of the encryption, quick numeric entry, dollar prescale, and top line
! display options.
! The user should follow the ^T character with one of "x", "n", "$" or
  "t" to pick the intended option.  A small menu lists the choices
  when ^T is typed.  The dollar prescale option multiplies all numeric
  CONSTANTS by 0.01 so that you don't have to keep typing the decimal
***************
*** 188,194
  of the encryption, quick numeric entry and top line display options.
  The user should follow the ^T character with one of "x", "n", or
  "t" to pick the intended option.  A small menu lists the choices
! when ^T is typed.
  
  .PP
  Cells can contain both a number and a string.  To enter and edit the

--- 189,197 -----
  display options.
  The user should follow the ^T character with one of "x", "n", "$" or
  "t" to pick the intended option.  A small menu lists the choices
! when ^T is typed.  The dollar prescale option multiplies all numeric
! CONSTANTS by 0.01 so that you don't have to keep typing the decimal
! point if you are entering lots of dollar figures.
  
  .PP
  Cells can contain both a number and a string.  To enter and edit the
-- 
    Robert Bond 			ihnp4!nsc!nscpdc!rgb
    National Semiconductor		tektronix!nscpdc!rgb



More information about the Comp.sources.bugs mailing list