-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansi.c
More file actions
298 lines (253 loc) · 5.6 KB
/
ansi.c
File metadata and controls
298 lines (253 loc) · 5.6 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* The routines in this file provide support for ANSI style terminals
* over a serial line. The serial I/O services are provided by routines in
* "termio.c". It compiles into nothing if not an ANSI device.
*/
#define termdef 1 /* don't define "term" external */
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
#if ANSI
#define MROW 25
#if AMIGA
#define NROW 23 /* Screen size. */
#define NCOL 77 /* Edit if you want to. */
#else
#if COLOR
#define NROW 25 /* Screen size. */
#else
#define NROW 24 /* Screen size. */
#endif
#define NCOL 80 /* Edit if you want to. */
#endif
#define NPAUSE 100 /* # times thru update to pause */
#define MARGIN 8 /* size of minimim margin and */
#define SCRSIZ 64 /* scroll size for extended lines */
#define BEL 0x07 /* BEL character. */
#define ESC 0x1B /* ESC character. */
static VOID ansimove PP((int row, int col)); /* Forward references. */
static VOID ansiel PP((void));
static VOID ansiep PP((void));
static VOID ansibeep PP((void));
static int ansiopen PP((void));
static VOID ansirev PP((int state));
static int ansiclose PP((void));
static int ansikopen PP((void));
static int ansikclose PP((void));
static int ansicres PP((CONSTA char *res));
static VOID ansiparm PP((int n));
#if COLOR
static VOID ansifcol PP((int color));
static VOID ansibcol PP((int color));
int cfcolor = -1; /* current forground color */
int cbcolor = -1; /* current background color */
#if AMIGA
/* apperently the AMIGA does not follow the ANSI standards as
regards to colors....maybe because of the default pallette
settings?
*/
int coltran[8] = {2, 3, 5, 7, 0, 4, 6, 1}; /* color translation table */
#endif
#endif
/*
* Standard terminal interface dispatch table. Most of the fields point into
* "termio" code.
*/
NOSHARE TERM term = {
MROW-1,
NROW-1,
NCOL,
NCOL,
MARGIN,
SCRSIZ,
NPAUSE,
ansiopen,
ansiclose,
ansikopen,
ansikclose,
ttgetc,
ttputc,
ttflush,
ansimove,
ansiel,
ansiep,
ansibeep,
ansirev,
ansicres
#if COLOR
, ansifcol,
ansibcol
#endif
};
#if COLOR
static VOID ansifcol(color) /* set the current output color */
int color; /* color to set */
{
if (color == cfcolor)
return;
ttputc(ESC);
ttputc('[');
#if AMIGA
ansiparm(coltran[color]+30);
#else
ansiparm(color+30);
#endif
ttputc('m');
cfcolor = color;
}
static VOID ansibcol(color) /* set the current background color */
int color; /* color to set */
{
if (color == cbcolor)
return;
ttputc(ESC);
ttputc('[');
#if AMIGA
ansiparm(coltran[color]+40);
#else
ansiparm(color+40);
#endif
ttputc('m');
cbcolor = color;
}
#endif
static VOID ansimove(row, col)
int row, col;
{
ttputc(ESC);
ttputc('[');
ansiparm(row+1);
ttputc(';');
ansiparm(col+1);
ttputc('H');
}
static VOID ansiel()
{
ttputc(ESC);
ttputc('[');
ttputc('K');
}
static VOID ansiep()
{
#if COLOR
ansifcol(gfcolor);
ansibcol(gbcolor);
#endif
ttputc(ESC);
ttputc('[');
ttputc('J');
}
static VOID ansirev(state) /* change reverse video state */
int state; /* TRUE = reverse, FALSE = normal */
{
#if COLOR
int ftmp, btmp; /* temporaries for colors */
#endif
ttputc(ESC);
ttputc('[');
ttputc(state ? '7': '0');
ttputc('m');
#if COLOR
if (state == FALSE) {
ftmp = cfcolor;
btmp = cbcolor;
cfcolor = -1;
cbcolor = -1;
ansifcol(ftmp);
ansibcol(btmp);
}
#endif
}
static int ansicres(res) /* change screen resolution */
CONSTA char *res;
{
UNUSED_ARG(res);
return(TRUE);
}
int spal(dummy) /* change pallette settings */
char *dummy;
{
/* none for now */
UNUSED_ARG(dummy);
return TRUE;
}
static VOID ansibeep()
{
ttputc(BEL);
ttflush();
}
static VOID ansiparm(n)
register int n;
{
register int q,r;
q = n/10;
if (q != 0) {
r = q/10;
if (r != 0) {
ttputc((r%10)+'0');
}
ttputc((q%10) + '0');
}
ttputc((n%10) + '0');
}
static int ansiopen()
{
register char *cp;
int n;
#if V7 | USG | BSD
if ((cp = getenv("TERM")) == NULL) {
puts("Shell variable TERM not defined!");
exit(1);
}
if (strcmp(cp, "vt100") != 0 &&
strcmp(cp, "ansi") != 0 &&
strcmp(cp, "rxvt") != 0 &&
strcmp(cp, "xterm") != 0) {
puts("Terminal type not 'vt100'!");
exit(1);
}
#endif
/* Set the terminal size using */
/* LINES and COLUMNS environment variables */
n = 0;
cp = getenv("LINES");
if (cp != NULL && *cp != '\0') n = atoi(cp);
if (n > 1) term.t_nrow = term.t_mrow = (short) (n - 1);
n = 0;
cp = getenv("COLUMNS");
if (cp != NULL && *cp != '\0') n = atoi(cp);
if (n > 1) term.t_ncol = term.t_mcol = (short) n;
strcpy(sres, "NORMAL");
revexist = TRUE;
return ttopen();
}
static int ansiclose()
{
#if COLOR
ansifcol(7);
ansibcol(0);
#endif
return ttclose();
}
static int ansikopen() /* open the keyboard (a noop here) */
{
return TRUE;
}
static int ansikclose() /* close the keyboard (a noop here) */
{
return TRUE;
}
#if FLABEL
int fnclabel(f, n) /* label a function key */
int f,n; /* default flag, numeric argument [unused] */
{
/* on machines with no function keys...don't bother */
return(TRUE);
}
#endif
#else
VOID ansihello PP((void));
VOID ansihello PP((void))
{
}
#endif