summaryrefslogtreecommitdiff
path: root/usr/src/lib/libcurses/screen/termcap.ed
blob: 6375be8dfb1350ec6be1463ef1babcf031fa7f37 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
H
!rm -f termcap.c
0a
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * University Copyright- Copyright (c) 1982, 1986, 1988
 * The Regents of the University of California
 * All Rights Reserved
 *
 * University Acknowledgment- Portions of this document are derived from
 * software developed by the University of California, Berkeley, and its
 * contributors.
 */

/*
 * Simulation of termcap using terminfo.
 * This file is created from termcap.ed. DO NOT EDIT ME!
 */

/*
 * These are declared so people won't get undefineds if they use
 * old documentation.  We don't do anything with them.
 */

#include	<sys/types.h>
#include	<string.h>
#include	"curses_inc.h"

char	*UP;
char	*BC;
char	PC;
short	ospeed;

/* ARGSUSED */
int
tgetent(char *bp, char *name)
{
	int	rv;

	if (setupterm(name, 1, &rv) >= 0)
	/* Leave things as they were (for compatibility) */
		(void) reset_shell_mode();
	return (rv);
}

/* Make a 2 letter code into an integer we can switch on easily */
#define	_TWO(s1, s2)	(s1 + 256*s2)
#define	_TWOSTR(str)	_TWO(*str, str[1])

static	char	*
_stripdelays(char *inbuf, char *outbuf, int size)
{
	char	*saveoutbuf = outbuf;

	if (inbuf == NULL)
		return (0);

	while (size && *inbuf) {
		if (*inbuf == '$' && *(inbuf+1) == '<') {
			/* LINTED */
			while (*inbuf && *inbuf++ != '>');
		} else {
			size--;
			*outbuf++ = *inbuf++;
			*outbuf = 0;
		}
	}
	return (saveoutbuf);
}

/* generated by sort on caps */
static	short	booloffsets[] =
		{		/* generated by sort on caps */
.
!sed -e '1,/^--- begin bool/d' -e '/^--- end bool/,$d' -e '/^#/d' < caps | awk '{printf "\t/* \%s */\t\%d,\n", $3, i++}' | sort > ./tmp/termcap.tmp
.r !cat ./tmp/termcap.tmp
.a
		};

/* generated by sort on caps */
static	short	numoffsets[] =
		{
.
!sed -e '1,/^--- begin num/d' -e '/^--- end num/,$d' -e '/^#/d' < caps | awk '{printf "\t/* \%s */\t\%d,\n", $3, i++}' | sort > ./tmp/termcap.tmp
.r !cat ./tmp/termcap.tmp
.a
		};

/* generated by sort on caps */
static	short	stroffsets[] =
		{
.
!sed -e '1,/^--- begin str/d' -e '/^--- end str/,$d' -e '/^#/d' < caps | awk '{printf "\t/* \%s */\t\%d,\n", $3, i++}' | sort > ./tmp/termcap.tmp
.r !cat ./tmp/termcap.tmp
!rm ./tmp/termcap.tmp
.a
		};

/*
 * Return the value of the boolean capability tcstr.
 * Return 0 if the capability is not found.
 */

int
tgetflag(char *tcstr)
{
	char	*p;
	char	stripped[16];

	switch (_TWOSTR(tcstr)) {
	/* Special cases that do not have exact terminfo equivalents */
		case _TWO('b','s'):
			/* bs: true if ^H moves the cursor left */
			p = _stripdelays(cursor_left, stripped, 16);
			return (p && *p == 8 && p[1] == 0);
		case _TWO('p','t'):
			/* pt: true if terminal has ^I tabs every 8 spaces */
			p = _stripdelays(tab, stripped, 16);
			return (p && *p == 9 && p[1] == 0);
		case _TWO('n','c'):
			/* cr: true if ^M does not return the cursor */
			p = _stripdelays(carriage_return, stripped, 16);
			return (! (p && *p == 13 && p[1] == 0));
		case _TWO('n','s'):
			/* ns: true if no way to scroll the terminal */
			return (scroll_forward == NULL);
	}
	{
		int	n = _NUMELEMENTS(booloffsets);
		int	offset = _tcsearch(tcstr, booloffsets, boolcodes, n, 2);
		char	*bool_array = (char *) cur_bools;

		if (offset == -1)
			return (0);
		else
			return (bool_array[offset]);
	}
}

/*
 * Return the value of the numeric capability tcstr.
 * Return -1 if the capability is not found.
 */

int
tgetnum(char *tcstr)
{
	int	n = _NUMELEMENTS(numoffsets);
	int	offset = _tcsearch(tcstr, numoffsets, numcodes, n, 2);
	short	*num_array = (short *) cur_nums;

	if (offset == -1)
		return (-1);
	else
		return (num_array[offset]);
}

/*
 * Return the string capability for capability "id".  We also copy
 * it into *area for upward compatibility with a few programs that
 * actually expect it to be copied, at a slight cost in speed.
 */

char	*
tgetstr(char *tcstr, char **area)
{
	int	n = _NUMELEMENTS(stroffsets);
	int	offset = _tcsearch(tcstr, stroffsets, strcodes, n, 2);
	char	**str_array = (char **) cur_strs;
	char	*rv;

	if (offset == -1)
		return (0);
	rv = str_array[offset];
	if (area && *area && rv) {
		(void) strcpy(*area, rv);
		*area += strlen(rv) + 1;
	}
	return (rv);
}
.
w termcap.c
q