| 1 |
greg |
1.1 |
/* Copyright (c) 1987 Regents of the University of California */ |
| 2 |
|
|
|
| 3 |
|
|
#ifndef lint |
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
|
#endif |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* editline.c - routine for editing raw input for rview. |
| 9 |
|
|
* |
| 10 |
|
|
* 10/5/88 |
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
greg |
1.2 |
#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 |
greg |
1.1 |
|
| 19 |
|
|
|
| 20 |
greg |
1.2 |
editline(buf, c_get, s_put) /* edit input line */ |
| 21 |
greg |
1.1 |
char *buf; |
| 22 |
|
|
int (*c_get)(), (*s_put)(); |
| 23 |
|
|
{ |
| 24 |
|
|
static char erases[] = "\b \b"; |
| 25 |
|
|
static char obuf[4]; |
| 26 |
|
|
register int i; |
| 27 |
|
|
register int c; |
| 28 |
|
|
|
| 29 |
|
|
i = 0; |
| 30 |
|
|
while ((c = (*c_get)()&0177) != '\n' && c != '\r') |
| 31 |
greg |
1.2 |
if (iserase(c)) { /* single char erase */ |
| 32 |
greg |
1.1 |
if (i > 0) { |
| 33 |
|
|
(*s_put)(erases); |
| 34 |
|
|
--i; |
| 35 |
|
|
} |
| 36 |
greg |
1.2 |
} 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 |
greg |
1.1 |
while (i > 0) { |
| 47 |
|
|
(*s_put)(erases); |
| 48 |
|
|
--i; |
| 49 |
|
|
} |
| 50 |
|
|
} else if (iscntrl(c)) { /* control char */ |
| 51 |
|
|
i = 0; |
| 52 |
|
|
buf[i++] = c; |
| 53 |
|
|
obuf[0] = '^'; obuf[1] = c|0100; obuf[2] = '\0'; |
| 54 |
|
|
(*s_put)(obuf); |
| 55 |
|
|
break; |
| 56 |
|
|
} else { /* regular char */ |
| 57 |
|
|
buf[i++] = c; |
| 58 |
|
|
obuf[0] = c; obuf[1] = '\0'; |
| 59 |
|
|
(*s_put)(obuf); |
| 60 |
|
|
} |
| 61 |
|
|
buf[i] = '\0'; |
| 62 |
|
|
(*s_put)("\n"); |
| 63 |
|
|
} |
| 64 |
greg |
1.3 |
|
| 65 |
|
|
|
| 66 |
|
|
#include "driver.h" |
| 67 |
|
|
|
| 68 |
|
|
static char mybuf[512]; |
| 69 |
|
|
|
| 70 |
|
|
|
| 71 |
|
|
char * |
| 72 |
|
|
getcombuf(d) /* return buffer for my command */ |
| 73 |
|
|
struct driver *d; |
| 74 |
|
|
{ |
| 75 |
|
|
d->inpready++; |
| 76 |
|
|
return(mybuf+strlen(mybuf)); |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
|
| 80 |
|
|
fromcombuf(b, d) /* get command from my buffer */ |
| 81 |
|
|
char *b; |
| 82 |
|
|
struct driver *d; |
| 83 |
|
|
{ |
| 84 |
|
|
register char *cp; |
| 85 |
|
|
/* get next command */ |
| 86 |
|
|
for (cp = mybuf; *cp != '\n'; cp++) |
| 87 |
|
|
if (!*cp) |
| 88 |
|
|
return(0); |
| 89 |
|
|
*cp++ = '\0'; |
| 90 |
greg |
1.4 |
#ifdef DEBUG |
| 91 |
greg |
1.3 |
(*d->comout)(mybuf); /* echo my command */ |
| 92 |
|
|
(*d->comout)("\n"); |
| 93 |
greg |
1.4 |
#endif |
| 94 |
greg |
1.3 |
/* send it as reply */ |
| 95 |
|
|
strcpy(b, mybuf); |
| 96 |
|
|
d->inpready--; |
| 97 |
|
|
/* get next command */ |
| 98 |
|
|
strcpy(mybuf, cp); |
| 99 |
|
|
return(1); |
| 100 |
|
|
} |