-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeSupp.c
201 lines (160 loc) · 3.33 KB
/
SeSupp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
* Saggaf. All rights reserved.
*
* See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
* statement of rights and permissions for this program.
*/
/*
Revisions:
2.2 lg Now uses /dev/tty instead of stdin/stdout
2.2 lg Added command parser
*/
#include <signal.h>
#include <X11/Intrinsic.h>
#include "SeDecl.h"
#include "seyon.h"
extern FILE *tfp; /* Local terminal */
extern int tfd; /* Local terminal */
char line[WBSIZE]; /* Input line */
char word[WBSIZE]; /* Parsed word */
char *wptr, *lptr; /* Word and line pointers */
int eof_flag = 0; /* Indicates EOF during seyon_getline() processing */
void sendstr(p) /* send a string to the port */
register char *p;
{
while (*p)
sendbyte(*p++);
}
/* Convert uppercase characters to lowercase, (without
* mangling non-uppercase characters), in a portable manner.
*/
int mklow(c) int c;
{
if (isupper(c))
return tolower(c);
return c;
}
/*
* parse the "line" array for a word
*/
void getword() {
char *ptr, quote;
int bflag = 0, qflag = 0;
int nflag = 0;
ptr = word;
*ptr = '\0';
if (eof_flag || *lptr == '\0')
return;
while (isspace(*lptr))
lptr++;
wptr = lptr;
if (*lptr == '\0')
return;
if (*lptr == '\'' || *lptr == '\"')
quote = *lptr++;
else
quote = '\0';
for (; *lptr != '\0'; lptr++) {
if (quote) {
if (*lptr == '\0') {
word[0] = '\0';
fprintf(tfp, "Unmatched quote: %s\r\n", line);
eof_flag = 1;
return;
}
if (*lptr == quote)
break;
} else if (!qflag && isspace(*lptr))
break;
if (bflag)
*ptr++ = *lptr & 0x1f;
else if (qflag)
*ptr++ = *lptr;
else if (*lptr == '^')
bflag = 1;
else if (*lptr == '\\')
qflag = 1;
else
*ptr++ = *lptr;
if (nflag == 1) {
nflag = 0;
bflag = 0;
qflag = 0;
}
if (bflag == 1 || qflag == 1)
nflag = 1;
}
if (*lptr)
lptr++;
*ptr = '\0';
}
void GetWord(lin, wrd) char *lin, *wrd;
{
char *ptr;
int cc = 0xff;
int quote = 0;
ptr = wrd;
lptr = lin;
*ptr = '\0';
if (*lptr == '\0')
return;
while (isspace(*lptr))
lptr++;
wptr = lptr;
if (*lptr == '\0')
return;
if (*lptr == '\"') {
lptr++;
quote = 1;
}
while (*lptr && (quote || !isspace(*lptr)) && (!quote || *lptr != '\"')) {
if (*lptr == '^' && *(lptr + 1) && (!quote || *(lptr + 1) != '\"')) {
lptr++;
if (*lptr != '^')
cc = 0x1f;
}
*ptr++ = *lptr & cc;
lptr++;
cc = 0xff;
}
if (*lptr)
lptr++;
;
*ptr = '\0';
}
char *NextWord(newLinePtr) char *newLinePtr;
{
static char nextWord[LRG_BUF], *linePtr;
if (newLinePtr)
linePtr = newLinePtr;
GetWord(linePtr, nextWord);
linePtr = lptr;
return nextWord;
}
/*
* make the specified word all lower case
*/
void lc_word(ptr) char *ptr;
{
while (*ptr) {
*ptr = mklow(*ptr);
ptr++;
}
}
/*
* input a line from the specified file
*/
void seyon_getline(fp) FILE *fp;
{
int l;
memset(line, 0, WBSIZE);
if ((fgets((lptr = line), WBSIZE, fp)) == NULL) {
eof_flag = 1;
line[0] = '\0';
}
l = strlen(line); /* Purge newline if found */
if (l--)
if (line[l] == '\n')
line[l] = '\0';
}