forked from hughbarney/pEmacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcap.c
131 lines (113 loc) · 2.36 KB
/
tcap.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
/* termios video driver */
#define termdef 1 /* don't define "term" external */
#include <stdlib.h> /* exit */
#include <stdio.h> /* puts(3), snprintf(3) */
#include "estruct.h"
#include "edef.h"
#undef CTRL
#include <sys/ioctl.h>
extern int tgetent();
extern char *tgetstr();
extern char *tgoto();
extern void tputs();
extern char *getenv();
extern void ttopen();
extern int ttgetc();
extern void ttputc();
extern void ttflush();
extern void ttclose();
void getwinsize();
void tcapopen();
void tcapmove(int row, int col);
void tcapeeol();
void tcapeeop();
void tcaprev();
void tcapbeep();
#define MARGIN 8
#define SCRSIZ 64
#define BEL 0x07
#define TCAPSLEN 64
char tcapbuf[TCAPSLEN]; /* capabilities actually used */
char *CM, *CE, *CL, *SO, *SE;
TERM term = {
0, 0, MARGIN, SCRSIZ, tcapopen, ttclose, ttgetc, ttputc,
ttflush, tcapmove, tcapeeol, tcapeeop, tcapbeep, tcaprev
};
void getwinsize ()
{
int cols, rows;
#ifndef FORCE_COLS
struct winsize ws;
ioctl (0, TIOCGWINSZ, &ws);
cols = ws.ws_col;
rows = ws.ws_row;
#else
cols = FORCE_COLS;
rows = FORCE_ROWS;
#endif
if ((cols < 10) || (rows < 3))
{
puts ("Unbelievable screen size\n");
exit (1);
}
term.t_ncol = cols;
term.t_nrow = rows-1;
}
void tcapopen ()
{
char tcbuf[1024], err_str[72];
char *p, *tv_stype;
if ((tv_stype = getenv ("TERM")) == NULL)
{
puts ("Environment variable TERM not defined\n");
exit (1);
}
if ((tgetent (tcbuf, tv_stype)) != 1)
{
snprintf (err_str, 72, "Unknown terminal type %s\n", tv_stype);
puts (err_str);
exit (1);
}
p = tcapbuf;
CL = tgetstr ("cl", &p);
CM = tgetstr ("cm", &p);
CE = tgetstr ("ce", &p);
SE = tgetstr ("se", &p);
SO = tgetstr ("so", &p);
if (CE == NULL)
eolexist = FALSE;
if (SO != NULL && SE != NULL)
revexist = TRUE;
if (CL == NULL || CM == NULL)
{
puts ("Insufficient termcap! (needs cl & cm abilities)\n");
exit (1);
}
if (p >= &tcapbuf[TCAPSLEN]) /* XXX */
{
puts ("Terminal description too big!\n");
exit (1);
}
ttopen ();
}
void tcaprev (int state)
{
if (revexist)
tputs ((state ? SO : SE), 1, ttputc);
}
void tcapmove (int row, int col)
{
tputs (tgoto (CM, col, row), 1, ttputc);
}
void tcapeeol ()
{
tputs (CE, 1, ttputc);
}
void tcapeeop ()
{
tputs (CL, 1, ttputc);
}
void tcapbeep ()
{
ttputc (BEL);
}