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
|
/*
* terminfo.c
*
* By Ross Ridge
* Public Domain
* 92/02/01 07:30:30
*
* terminfo compatible libary functions
*
*/
#include "defs.h"
#include <term.h>
#ifdef USE_SCCS_IDS
static const char SCCSid[] = "@(#) mytinfo terminfo.c 3.2 92/02/01 public domain, By Ross Ridge";
#endif
extern char _mytinfo_version[];
/* not static */
char *_force_pick2 = _mytinfo_version;
#ifdef USE_FAKE_STDIO
#ifdef __GNUC__
__inline__
#endif
static int
printerr(msg)
char *msg; {
return write(2, msg, strlen(msg));
}
#define RETERR(e, msg) { (err == NULL ? (printerr(msg), exit(1)) \
: (*err = e)); return ERR; }
#else
#define RETERR(e, msg) { (err == NULL ? (fprintf(stderr, "setupterm(\"%s\",%d,NULL): %s", term, fd, msg), exit(1)) \
: (*err = e)); return ERR; }
#endif
int
setupterm(term, fd, err)
char *term;
int fd;
int *err; {
struct term_path *path;
char *s;
int r = -1;
char buf[MAX_BUF];
if (term == NULL)
term = getenv("TERM");
if (term == NULL)
RETERR(0, "TERM not set\n")
path = _buildpath(
#ifdef USE_TERMINFO
"$MYTERMINFO", 2,
"$TERMINFO", 2,
#ifdef TERMINFODIR
TERMINFODIR, 0,
#endif
#ifdef TERMINFOSRC
TERMINFOSRC, 0,
#endif
#endif
#ifdef USE_TERMCAP
"$TERMCAP", 1,
#ifdef TERMCAPFILE
TERMCAPFILE, 0,
#endif
#endif
NULL, -1);
if (path == NULL)
RETERR(0, "malloc error\n");
r = _fillterm(term, path, buf);
_delpath(path);
switch(r) {
case -3:
RETERR(0, "malloc error\n");
case -2:
RETERR(-1, "bad format\n");
case -1:
RETERR(-1, "database not found\n");
case 0:
RETERR(0, "terminal not found\n");
case 1:
case 2:
case 3:
cur_term->fd = fd;
_term_buf.fd = fd;
if (_init_tty() == ERR)
RETERR(0, "problem initializing tty\n");
if ((s = getenv("LINES")) != NULL && atoi(s) > 0)
lines = atoi(s);
if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
columns = atoi(s);
if (err != NULL)
*err = 1;
return OK;
default:
RETERR(0, "oops...\n");
}
}
int
set_curterm(p)
TERMINAL *p; {
cur_term = p;
if (_init_tty() == ERR)
return ERR;
if (_check_tty() == ERR)
return ERR;
return OK;
}
int
del_curterm(p)
TERMINAL *p; {
_del_strs(p);
free((anyptr) p);
return OK;
}
|