| 10 |
|
* 10/5/88 |
| 11 |
|
*/ |
| 12 |
|
|
| 13 |
< |
#include <ctype.h> |
| 13 |
> |
#define iscntrl(c) ((c) < ' ') |
| 14 |
> |
#define isblank(c) ((c) == ' ') |
| 15 |
> |
#define iserase(c) ((c) == '\b' || (c) == 127) |
| 16 |
> |
#define iswerase(c) ((c) == 'W'-'@') |
| 17 |
> |
#define iskill(c) ((c) == 'U'-'@' || (c) == 'X'-'@') |
| 18 |
|
|
| 19 |
|
|
| 20 |
< |
editline(buf, c_get, s_put, c_erase, c_kill) /* edit input line */ |
| 20 |
> |
editline(buf, c_get, s_put) /* edit input line */ |
| 21 |
|
char *buf; |
| 22 |
|
int (*c_get)(), (*s_put)(); |
| 19 |
– |
int c_erase, c_kill; |
| 23 |
|
{ |
| 24 |
|
static char erases[] = "\b \b"; |
| 25 |
|
static char obuf[4]; |
| 28 |
|
|
| 29 |
|
i = 0; |
| 30 |
|
while ((c = (*c_get)()&0177) != '\n' && c != '\r') |
| 31 |
< |
if (c == c_erase) { /* single char erase */ |
| 31 |
> |
if (iserase(c)) { /* single char erase */ |
| 32 |
|
if (i > 0) { |
| 33 |
|
(*s_put)(erases); |
| 34 |
|
--i; |
| 35 |
|
} |
| 36 |
< |
} else if (c == c_kill) { /* kill line */ |
| 36 |
> |
} else if (iswerase(c)) { /* word erase */ |
| 37 |
> |
while (i > 0 && isblank(buf[i-1])) { |
| 38 |
> |
(*s_put)(erases); |
| 39 |
> |
--i; |
| 40 |
> |
} |
| 41 |
> |
while (i > 0 && !isblank(buf[i-1])) { |
| 42 |
> |
(*s_put)(erases); |
| 43 |
> |
--i; |
| 44 |
> |
} |
| 45 |
> |
} else if (iskill(c)) { /* kill line */ |
| 46 |
|
while (i > 0) { |
| 47 |
|
(*s_put)(erases); |
| 48 |
|
--i; |