1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* editline.c - routine for editing raw input for rview. |
6 |
|
* |
7 |
< |
* 10/5/88 |
7 |
> |
* External symbols declared in driver.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include <ctype.h> |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
+ |
#include <stdio.h> |
13 |
|
|
14 |
< |
editline(buf, c_get, s_put, c_erase, c_kill) /* edit input line */ |
14 |
> |
#include "color.h" |
15 |
> |
|
16 |
> |
#include "driver.h" |
17 |
> |
|
18 |
> |
#define iscntrl(c) ((c) < ' ') |
19 |
> |
#define isblank(c) ((c) == ' ') |
20 |
> |
#define iserase(c) ((c) == '\b' || (c) == 127) |
21 |
> |
#define iswerase(c) ((c) == 'W'-'@') |
22 |
> |
#define iskill(c) ((c) == 'U'-'@' || (c) == 'X'-'@') |
23 |
> |
|
24 |
> |
|
25 |
> |
void |
26 |
> |
editline(buf, c_get, s_put) /* edit input line */ |
27 |
|
char *buf; |
28 |
< |
int (*c_get)(), (*s_put)(); |
29 |
< |
int c_erase, c_kill; |
28 |
> |
int (*c_get)(); |
29 |
> |
void (*s_put)(); |
30 |
|
{ |
31 |
|
static char erases[] = "\b \b"; |
32 |
|
static char obuf[4]; |
35 |
|
|
36 |
|
i = 0; |
37 |
|
while ((c = (*c_get)()&0177) != '\n' && c != '\r') |
38 |
< |
if (c == c_erase) { /* single char erase */ |
38 |
> |
if (iserase(c)) { /* single char erase */ |
39 |
|
if (i > 0) { |
40 |
|
(*s_put)(erases); |
41 |
|
--i; |
42 |
|
} |
43 |
< |
} else if (c == c_kill) { /* kill line */ |
43 |
> |
} else if (iswerase(c)) { /* word erase */ |
44 |
> |
while (i > 0 && isblank(buf[i-1])) { |
45 |
> |
(*s_put)(erases); |
46 |
> |
--i; |
47 |
> |
} |
48 |
> |
while (i > 0 && !isblank(buf[i-1])) { |
49 |
> |
(*s_put)(erases); |
50 |
> |
--i; |
51 |
> |
} |
52 |
> |
} else if (iskill(c)) { /* kill line */ |
53 |
|
while (i > 0) { |
54 |
|
(*s_put)(erases); |
55 |
|
--i; |
67 |
|
} |
68 |
|
buf[i] = '\0'; |
69 |
|
(*s_put)("\n"); |
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
|
73 |
+ |
static char mybuf[512]; |
74 |
+ |
|
75 |
+ |
|
76 |
+ |
void |
77 |
+ |
tocombuf(b, d) /* add command(s) to my buffer */ |
78 |
+ |
register char *b; |
79 |
+ |
register struct driver *d; |
80 |
+ |
{ |
81 |
+ |
register char *cp; |
82 |
+ |
char *comstart; |
83 |
+ |
|
84 |
+ |
for (cp = mybuf; *cp; cp++) |
85 |
+ |
; |
86 |
+ |
comstart = cp; |
87 |
+ |
while (*cp++ = *b) |
88 |
+ |
if (cp >= mybuf+sizeof(mybuf)) { |
89 |
+ |
*comstart = '\0'; |
90 |
+ |
return; /* what should I do about this? */ |
91 |
+ |
} else if (*b++ == '\n') { |
92 |
+ |
d->inpready++; |
93 |
+ |
comstart = cp; |
94 |
+ |
} |
95 |
+ |
} |
96 |
+ |
|
97 |
+ |
|
98 |
+ |
int |
99 |
+ |
fromcombuf(b, d) /* get command from my buffer */ |
100 |
+ |
char *b; |
101 |
+ |
struct driver *d; |
102 |
+ |
{ |
103 |
+ |
register char *cp; |
104 |
+ |
/* get next command */ |
105 |
+ |
for (cp = mybuf; *cp != '\n'; cp++) |
106 |
+ |
if (!*cp) |
107 |
+ |
return(0); |
108 |
+ |
*cp++ = '\0'; |
109 |
+ |
#ifdef DEBUG |
110 |
+ |
(*d->comout)(mybuf); /* echo my command */ |
111 |
+ |
(*d->comout)("\n"); |
112 |
+ |
#endif |
113 |
+ |
/* send it as reply */ |
114 |
+ |
strcpy(b, mybuf); |
115 |
+ |
d->inpready--; |
116 |
+ |
/* advance commands */ |
117 |
+ |
strcpy(mybuf, cp); |
118 |
+ |
return(1); |
119 |
|
} |