-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathansi.c
More file actions
183 lines (164 loc) · 3.34 KB
/
ansi.c
File metadata and controls
183 lines (164 loc) · 3.34 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
/*_ ansi.c Fri Feb 7 1986 Modified by: Bjorn Benson */
/*
* 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.
*/
#include <stdio.h>
#include "ed.h"
#if ANSI || ANSISYS
#define NROW 23 /* Screen size. */
#define NCOL 77 /* Edit if you want to. */
#define BEL 0x07 /* BEL character. */
#define ESC 0x1B /* ESC character. */
extern int ttopen(); /* Forward references. */
extern int ttgetc();
extern int ttputc();
extern int ttflush();
extern int ttclose();
extern int ansimove();
extern int ansieeol();
extern int ansieeop();
extern int ansibeep();
extern int ansiopen();
extern int ansinull();
extern int ansistartstand();
extern int ansiendstand();
extern int ansiscrup();
extern int ansiscrdn();
/*
* Standard terminal interface dispatch table. Most of the fields point into
* "termio" code.
*/
TERM term = {
NROW-1,
NCOL,
ansiopen,
ttclose,
ttgetc,
ttputc,
ttflush,
ansimove,
ansieeol,
ansieeop,
ansibeep,
ansistartstand,
ansiendstand,
#if ANSISYS
NULL,NULL /* scrolling regions don't work right */
#else
ansiscrup,
ansiscrdn
#endif
};
ansinull()
{
/* null function - do nothing */
}
ansimove(row, col)
{
ttputc(ESC);
ttputc('[');
ansiparm(row+1);
ttputc(';');
ansiparm(col+1);
ttputc('H');
}
ansieeol()
{
ttputc(ESC);
ttputc('[');
ttputc('K');
}
ansieeop()
{
ttputc(ESC);
ttputc('[');
ttputc('J');
}
ansibeep()
{
ttputc(BEL);
ttflush();
}
ansistartstand()
{
ttputc(ESC); ttputc('['); ttputc('7'); ttputc('m');
}
ansiendstand()
{
ttputc(ESC); ttputc('['); ttputc('0'); ttputc('m');
}
ansiscrup( first, last )
int first,last;
{
ttputc(ESC);
ttputc('[');
ansiparm(first+1);
ttputc(';');
ansiparm(last+1);
ttputc('r');
ttputc(ESC);
ttputc('[');
ansiparm(last+1);
ttputc(';');
ttputc('1');
ttputc('f');
ttputc('\n');
ttputc(ESC);
ttputc('[');
ttputc('1');
ttputc(';');
ansiparm( NROW+1 );
ttputc('r');
}
ansiscrdn( first, last )
int first,last;
{
ttputc(ESC);
ttputc('[');
ansiparm(first+1);
ttputc(';');
ansiparm(last+1);
ttputc('r');
ttputc(ESC);
ttputc('[');
ansiparm(first+1);
ttputc(';');
ttputc('1');
ttputc('f');
ttputc(ESC);
ttputc('M');
ttputc(ESC);
ttputc('[');
ttputc('1');
ttputc(';');
ansiparm( NROW+1 );
ttputc('r');
}
ansiparm(n)
register int n;
{
register int q;
q = n/10;
if (q != 0)
ansiparm(q);
ttputc((n%10) + '0');
}
ansiopen()
{
#if BSDUNIX || LINUX
register char *cp;
char *getenv();
if ((cp = getenv("TERM")) == NULL) {
puts("Shell variable TERM not defined!");
exit(1);
}
if (strcmp(cp, "vt100") != 0) {
puts("Terminal type not 'vt100'!");
exit(1);
}
#endif
ttopen();
}
#endif