/* SC A Spreadsheet Calculator
#if !defined(strchr) && !defined(UPORT)
#define istext(a) (isalnum(a) || ((a) == '_'))
extern char mode_ind
; /* Mode indicator */
/* values for mode below */
#define INSERT_MODE 0 /* Insert mode */
#define EDIT_MODE 1 /* Edit mode */
#define REP_MODE 2 /* Replace mode */
#define SEARCH_MODE 3 /* Get arguments for '/' command */
static int mode
= INSERT_MODE
;
static char *history
[HISTLEN
];
static char *last_search
;
case (ctl('h')): linelim
= back_line(); break;
case (ctl('m')): cr_line(); break;
case ESC
: stop_edit(); break;
case '+': for_hist(); break;
case '-': back_hist(); break;
case '$': last_col(); break;
case '.': dotcmd(); break;
case '/': search_mode(); break;
case '0': col_0(); break;
case 'D': u_save(c
);del_to_end(); break;
case 'I': u_save(c
);col_0();insert_mode();break;
case 'R': replace_mode(); break;
case 'X': u_save(c
); back_space(); break;
case 'a': u_save(c
); append_line(); break;
case 'b': linelim
= back_word(); break;
case 'c': u_save(c
); change_cmd(); break;
case 'd': u_save(c
); delete_cmd(); break;
case 'f': linelim
= find_char(); break;
case 'h': linelim
= back_line(); break;
case 'i': u_save(c
); insert_mode(); break;
case 'j': for_hist(); break;
case 'k': back_hist(); break;
case 'l': linelim
= for_line(0); break;
case 'n': search_again(); break;
case 'q': stop_edit(); break;
case 'r': u_save(c
); rep_char(); break;
case 't': linelim
= to_char(); break;
case 'u': restore_it(); break;
case 'w': linelim
= for_word(0); break;
case 'x': u_save(c
); del_in_line(); break;
} else if (mode
== INSERT_MODE
) {
case (ctl('h')): back_space(); break;
case (ctl('m')): cr_line(); break;
case ESC
: edit_mode(); break;
default: ins_in_line(c
); break;
} else if (mode
== SEARCH_MODE
) {
case (ctl('h')): back_space(); break;
case (ctl('m')): search_hist(); break;
case ESC
: edit_mode(); break;
default: ins_in_line(c
); break;
} else if (mode
== REP_MODE
) {
case (ctl('h')): back_space(); break;
case (ctl('m')): cr_line(); break;
case ESC
: edit_mode(); break;
default: replace_in_line(c
); break;
if (line
[linelim
] == '\0')
/* dot command functions. Saves info so we can redo on a '.' command */
/* saves the current line for possible use by an undo cmd */
undo_line
= strcpy(xmalloc((unsigned)(strlen(line
)+1)), line
);
/* reset dot command if not processing it. */
/* Restores the current line saved by u_save() */
tempc
= strcpy(xmalloc((unsigned)(strlen(line
)+1)), line
);
/* This command stops the editing process. */
* Motion commands. Forward motion commands take an argument
* which, when set, cause the forward motion to continue onto
* the null at the end of the line instead of stopping at the
* the last character of the line.
if (linelim
>= 0 && line
[linelim
] != 0 &&
(line
[linelim
+1] != 0 || stop_null
))
while (line
[cpos
] == ' ')
if (cpos
> 0 && line
[cpos
] == 0)
if (istext(line
[cpos
])) {
while ((c
= line
[cpos
]) && istext(c
))
while ((c
= line
[cpos
]) && !istext(c
) && c
!= ' ')
while (line
[cpos
] == ' ')
if (cpos
> 0 && line
[cpos
] == 0 && !stop_null
)
while (cpos
> 0 && line
[cpos
] == ' ')
} else if (cpos
> 0 && (line
[cpos
-1] == ' '
|| istext(line
[cpos
]) && !istext(line
[cpos
-1])
|| !istext(line
[cpos
]) && istext(line
[cpos
-1]))) {
/* Started on the first char of a word - back up to prev. word */
while (cpos
> 0 && line
[cpos
] == ' ')
/* Skip across the word - goes 1 too far */
if (istext(line
[cpos
])) {
while (cpos
> 0 && (c
= line
[cpos
]) && istext(c
))
while (cpos
> 0 && (c
= line
[cpos
]) && !istext(c
) && c
!= ' ')
/* We are done - fix up the one too far */
if (cpos
> 0 && line
[cpos
] && line
[cpos
+1])
/* Text manipulation commands */
if (linelim
== len
&& linelim
> 0)
for (i
= linelim
; i
< len
; i
++)
if (linelim
> 0 && line
[linelim
] == 0)
for (i
= len
; i
>= linelim
; --i
)
if (line
[linelim
] != 0) {
if (line
[linelim
] == 0) {
case 'b': return(back_word());
case 'f': return(find_char()+1);
case 'h': return(back_line());
case 'l': return(for_line(1));
case 't': return(to_char()+1);
case 'w': return(for_word(1));
default: return(linelim
);
del_chars(cpos
, linelim
);
register int first
, last
;
temp
= last
; last
= first
; first
= temp
;
/* free the oldest one */
if (history
[HISTLEN
-1]) {
xfree(history
[HISTLEN
-1]);
/* Move the others back */
for (i
= HISTLEN
-1; i
> 0; --i
)
history
[i
] = history
[i
-1];
history
[0] = xmalloc((unsigned) strlen(line
)+1);
strcpy(history
[0], line
);
if (histp
== -1 || histp
< HISTLEN
-1 && history
[histp
+ 1])
strcpy(line
, history
[histp
]);
last_search
= strcpy(xmalloc((unsigned)(strlen(line
+1)+1)), line
+1);
while ((look_here
= strchr(look_here
, last_search
[0])) &&
if (strncmp(look_here
, last_search
, strlen(last_search
)) == 0)
else if (look_here
< line
+ strlen(line
) - 1)
if (histp
>= 0 && history
[histp
]) {
strcpy(line
, history
[histp
]);
while(line
[i
] && line
[i
] != c
)
if (i
> 0 && i
!= linelim
)