summaryrefslogtreecommitdiffstats
path: root/lib/libmytinfo/termcap.c
blob: f914c0b85b49981752b1599290880539a5c6f359 (plain)
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
/*
 * termcap.c
 *
 * By Ross Ridge
 * Public Domain
 * 92/06/01 07:43:08
 *
 * termcap compatibility functions
 *
 */

#include "defs.h"
#include <term.h>
#ifdef __FreeBSD__
#include <unistd.h>
#endif

#ifdef USE_SCCS_IDS
static const char SCCSid[] = "@(#) mytinfo termcap.c 3.3 92/06/01 public domain, By Ross Ridge";
#endif

extern char _mytinfo_version[];
/* not static */
char *_force_pick1 = _mytinfo_version;

int
tgetent(buf, term)
char *term, *buf; {
	char *s;
	struct term_path *path;
	int r = -1;
	int fd;

	if (term == NULL)
		term = getenv("TERM");
	if (term == NULL)
		return 0;

	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)
		return -1;

#if 1
	{
		char buf1[MAX_BUF];
		r = _fillterm(term, path, buf1);
	}
#else
	r = _fillterm(term, path, buf);
#endif

	_delpath(path);

	switch(r) {
	case -3:
	case -2:
	case -1:
		return -1;
	case 0:
		return 0;
	case 1:
	case 2:
	case 3:
		if (isatty(1))
			fd = 1;
		else if (isatty(2))
			fd = 2;
		else if (isatty(3))	/* V10 /dev/tty ?? */
			fd = 3;
		else if (isatty(0))
			fd = 0;
		else
			fd = 1;

		cur_term->fd = fd;
		_term_buf.fd = fd;

		if (_init_tty() == ERR)
			return 0;
		if ((s = getenv("LINES")) != NULL && atoi(s) > 0)
			lines = atoi(s);
		if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
			columns = atoi(s);
		cur_term->termcap = 1;
		return 1;
	default:
		return -1;
	}
}

static char cap2[3];

int
tgetnum(cap)
char *cap; {
	int ind;

	cap2[0] = cap[0];
	cap2[1] = cap[1];
	cap2[2] = '\0';

	ind = _findnumcode(cap2);
	if (ind == -1)
		return -1;
	return cur_term->nums[ind];
}

int
tgetflag(cap)
char *cap; {
	int ind;

	cap2[0] = cap[0];
	cap2[1] = cap[1];
	cap2[2] = '\0';

	ind = _findboolcode(cap2);
	if (ind == -1)
		return 0;
	return cur_term->bools[ind];
}

char *
tgetstr(cap, area)
char *cap;
char **area; {
	register char *sp, *dp;
	int ind;

	cap2[0] = cap[0];
	cap2[1] = cap[1];
	cap2[2] = '\0';

	ind = _findstrcode(cap2);
	if (ind == -1)
		return NULL;
	sp = cur_term->strs[ind];
	if (area == NULL || sp == NULL)
		return sp;
	dp = *area;
	while (*sp != '\0')
		*dp++ = *sp++;
	*dp++ = '\0';
	sp = *area;
	*area = dp;
	return sp;
}
OpenPOWER on IntegriCloud