/* SC A Spreadsheet Calculator
* original by James Gosling, September 1982
* modifications by Mark Weiser and Bruce Israel,
* More mods Robert Bond, 12/86
* More mods by Alan Silverstein, 3/88, see list of changes.
#if defined(BSD42) || defined(BSD43)
extern int VMS_read_raw
; /*sigh*/
struct key experres
[] = {
register char *p
= line
+linelim
;
if (*p
== '\0') ret
= -1;
register struct key
*tblp
;
* This picks up either 1 or 2 alpha characters (a column) or
* tokens with at least three leading alphas and '_' or digits
* (a function or token or command or a range name)
while (isalpha(*p
) || ((*p
== '_') || isdigit(*p
)) && (tokenl
> 2)) {
if (tokenl
<= 2) { /* a COL is 1 or 2 char alpha
(but not pi, ln, fv, pv, if -- this should be fixed!) */
if (tokenl
== 2 && tokenst
[0] == 'p' && tokenst
[1] == 'i') {
} else if (tokenl
== 2 && tokenst
[0] == 'l' && tokenst
[1] == 'n') {
} else if (tokenl
== 2 && tokenst
[0] == 'f' && tokenst
[1] == 'v') {
} else if (tokenl
== 2 && tokenst
[0] == 'p' && tokenst
[1] == 'v') {
} else if (tokenl
== 2 && tokenst
[0] == 'i' && tokenst
[1] == 'f') {
yylval
.ival
= atocol (tokenst
, tokenl
);
for (tblp
= linelim
? experres
: statres
; tblp
->key
; tblp
++)
if (((tblp
->key
[0]^tokenst
[0])&0137)==0
&& tblp
->key
[tokenl
]==0) {
while (i
<tokenl
&& ((tokenst
[i
]^tblp
->key
[i
])&0137)==0)
if (r
= find_range(tokenst
, tokenl
,
(struct ent
*)0, (struct ent
*)0)) {
yylval
.rval
.left
= r
->r_left
;
yylval
.rval
.right
= r
->r_right
;
yyerror ("Unintelligible word");
} else if ((*p
== '.') || isdigit(*p
)) {
do v
= v
*10 + (double)(*p
-'0');
if (*p
=='.' || *p
== 'e' || *p
== 'E') {
p
= strtof(nstart
, &yylval
.fval
);
/* A NUMBER must hold at least MAXROW and MAXCOL */
/* This is consistent with a short row and col in struct ent */
if (v
> (double)32767 || v
< (double)-32768) {
while(*ptr
&& *ptr
++ != '"');
ptr
= xmalloc((unsigned)(ptr
-p
));
while (*p
&& *p
!='"') *ptr
++ = *p
++;
while (*p
&& *p
!=']') p
++;
* Given a token string starting with a symbolic column name and its valid
* length, convert column name ("A"-"Z" or "AA"-"ZZ") to a column number (0-N).
* Never mind if the column number is illegal (too high). The procedure's name
* and function are the inverse of coltoa().
* Case-insensitivity is done crudely, by ignoring the 040 bit.
col
= (string
[0] & 0137) - 'A';
if (len
== 2) /* has second char */
col
= ((col
+ 1) * 26) + ((string
[1] & 0137) - 'A');
return (toascii(getchar()));
This is not perfect, it doesn't move the cursor when goraw changes
over to deraw, but it works well enough since the whole sc package
is incredibly stable (loop constantly positions cursor).
Question, why didn't the VMS people just implement cbreak?
NOTE: During testing it was discovered that the DEBUGGER and curses
and this method of reading would collide (the screen was not updated
when continuing from screen mode in the debugger).
#define VMScheck(a) {if (~(status = (a)) & 1) VMS_MSG (status);}
VMScheck(smg$
read_keystroke (&stdkb
->_id
, &c
, 0, 0, 0));
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;
Routine to put out the VMS operating system error (if one occurs).
char errstr
[81], buf
[120];
$
DESCRIPTOR(errdesc
, errstr
);
#define err_out(msg) fprintf (stderr,msg)
/* Check for no error or standard error */
status
= status
& 0x8000 ? status
& 0xFFFFFFF : status
& 0xFFFF;
if (SYS$
GETMSG(status
, &length
, &errdesc
, 1, 0) == SS$_NORMAL
) {
sprintf (buf
, "<0x%x> %s", status
, errdesc
.dsc$a_pointer
);
err_out ("System error");
#if defined(BSD42) || defined (SYSIII) || defined(BSD43)
struct key_map km
[N_KEY
];
struct ltchars old_chars
, new_chars
;
ctl('['), ctl('a'), ctl('b'), ctl('c'), ctl('e'), ctl('f'), ctl('g'), ctl('h'),
ctl('i'), ctl('j'), ctl('l'), ctl('m'), ctl('n'), ctl('p'), ctl('q'),
ctl('r'), ctl('s'), ctl('t'), ctl('u'), ctl('v'), ctl('w'), ctl('x'),
register struct key_map
*kp
;
static char buf
[1024]; /* Why do I have to do this again? */
if (tgetent(buf
, getenv("TERM")) <= 0)
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');
(void) strcpy(ks_buf
, ktmp
);
(void) strcpy(ke_buf
, ktmp
);
/* Unmap arrow keys which conflict with our ctl keys */
/* Ignore unset, longer than length 1, and 1-1 mapped keys */
for (i
= 0; i
< N_KEY
; i
++) {
if (kp
->k_str
&& (kp
->k_str
[1] == 0) && (kp
->k_str
[0] != kp
->k_val
))
for (j
= 0; dont_use
[j
] != 0; j
++)
if (kp
->k_str
[0] == dont_use
[j
]) {
(void)ioctl(fileno(stdin
), TIOCGLTC
, (char *)&old_chars
);
if (old_chars
.t_lnextc
== ctl('v'))
if (old_chars
.t_rprntc
== ctl('r'))
(void)ioctl(fileno(stdin
), TIOCSLTC
, (char *)&new_chars
);
(void)ioctl(fileno(stdin
), TIOCSLTC
, (char *)&new_chars
);
(void)ioctl(fileno(stdin
), TIOCSLTC
, (char *)&old_chars
);
register struct key_map
*kp
;
register struct key_map
*biggest
;
if (dumpindex
&& *dumpindex
)
for (kp
= &km
[0]; kp
< &km
[N_KEY
]; kp
++) {
if (c
== kp
->k_str
[kp
->k_index
]) {
if (kp
->k_str
[kp
->k_index
] == 0) {
for (kp
= &km
[0]; kp
< &km
[N_KEY
]; kp
++)
if (!biggest
&& kp
->k_index
)
else if (kp
->k_index
&& biggest
->k_index
< kp
->k_index
)
(void) signal(SIGALRM
, time_out
);
if (setjmp(wakeup
) == 0) {
for (i
= 0; i
<biggest
->k_index
; i
++)
dumpbuf
[i
] = biggest
->k_str
[i
];
for (kp
= &km
[0]; kp
< &km
[N_KEY
]; kp
++)
#if defined(SYSV2) || defined(SYSV3)
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;
/* 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 /* SYSV2 || SYSV3 */
(void)fpsetsticky((fp_except
)0); /* Clear exception */
* This converts a floating point number of the form
* [s]ddd[.d*][esd*] where s can be a + or - and e is E or e.
sig_save
= signal(SIGFPE
, fpe_trap
);
error("Floating point exception\n");
(void) signal(SIGFPE
, sig_save
);
acc
= acc
* 10.0 + (double)(*p
- '0');
if (*p
== 'e' || *p
== 'E') {
exp
= exp
* 10 + (*p
- '0');
acc
+= (*p
- '0') * fpos
;
if (*p
== 'e' || *p
== 'E') {
exp
= exp
* 10 + (*p
- '0');
(void) signal(SIGFPE
, sig_save
);