xref: /titanic_44/usr/src/lib/libcurses/screen/termcap.ed (revision fb3fb4f3d76d55b64440afd0af72775dfad3bd1d)
1H
2!rm -f termcap.c
30a
4/*
5 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
6 * Use is subject to license terms.
7 */
8
9/*
10 * University Copyright- Copyright (c) 1982, 1986, 1988
11 * The Regents of the University of California
12 * All Rights Reserved
13 *
14 * University Acknowledgment- Portions of this document are derived from
15 * software developed by the University of California, Berkeley, and its
16 * contributors.
17 */
18
19#pragma ident	"%Z%%M%	%I%	%E% SMI"
20
21/*
22 * Simulation of termcap using terminfo.
23 * This file is created from termcap.ed. DO NOT EDIT ME!
24 */
25
26/*
27 * These are declared so people won't get undefineds if they use
28 * old documentation.  We don't do anything with them.
29 */
30
31#include	<sys/types.h>
32#include	<string.h>
33#include	"curses_inc.h"
34
35char	*UP;
36char	*BC;
37char	PC;
38short	ospeed;
39
40/* ARGSUSED */
41int
42tgetent(char *bp, char *name)
43{
44	int	rv;
45
46	if (setupterm(name, 1, &rv) >= 0)
47	/* Leave things as they were (for compatibility) */
48		(void) reset_shell_mode();
49	return (rv);
50}
51
52/* Make a 2 letter code into an integer we can switch on easily */
53#define	_TWO(s1, s2)	(s1 + 256*s2)
54#define	_TWOSTR(str)	_TWO(*str, str[1])
55
56static	char	*
57_stripdelays(char *inbuf, char *outbuf, int size)
58{
59	char	*saveoutbuf = outbuf;
60
61	if (inbuf == NULL)
62		return (0);
63	else
64		while (size && *inbuf)
65			if (*inbuf == '$' && *(inbuf+1) == '<')
66				/* LINTED */
67				while (*inbuf && *inbuf++ != '>');
68			else {
69				size--;
70				*outbuf++ = *inbuf++;
71				*outbuf = 0;
72			}
73		return (saveoutbuf);
74}
75
76/* generated by sort on caps */
77static	short	booloffsets[] =
78		{		/* generated by sort on caps */
79.
80!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
81.r !cat ./tmp/termcap.tmp
82.a
83		};
84
85/* generated by sort on caps */
86static	short	numoffsets[] =
87		{
88.
89!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
90.r !cat ./tmp/termcap.tmp
91.a
92		};
93
94/* generated by sort on caps */
95static	short	stroffsets[] =
96		{
97.
98!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
99.r !cat ./tmp/termcap.tmp
100!rm ./tmp/termcap.tmp
101.a
102		};
103
104/*
105 * Return the value of the boolean capability tcstr.
106 * Return 0 if the capability is not found.
107 */
108
109int
110tgetflag(char *tcstr)
111{
112	char	*p;
113	char	stripped[16];
114
115	switch (_TWOSTR(tcstr)) {
116	/* Special cases that do not have exact terminfo equivalents */
117		case _TWO('b','s'):
118			/* bs: true if ^H moves the cursor left */
119			p = _stripdelays(cursor_left, stripped, 16);
120			return (p && *p == 8 && p[1] == 0);
121		case _TWO('p','t'):
122			/* pt: true if terminal has ^I tabs every 8 spaces */
123			p = _stripdelays(tab, stripped, 16);
124			return (p && *p == 9 && p[1] == 0);
125		case _TWO('n','c'):
126			/* cr: true if ^M does not return the cursor */
127			p = _stripdelays(carriage_return, stripped, 16);
128			return (! (p && *p == 13 && p[1] == 0));
129		case _TWO('n','s'):
130			/* ns: true if no way to scroll the terminal */
131			return (scroll_forward == NULL);
132	}
133	{
134		int	n = _NUMELEMENTS(booloffsets);
135		int	offset = _tcsearch(tcstr, booloffsets, boolcodes, n, 2);
136		char	*bool_array = (char *) cur_bools;
137
138		if (offset == -1)
139			return (0);
140		else
141			return (bool_array[offset]);
142	}
143}
144
145/*
146 * Return the value of the numeric capability tcstr.
147 * Return -1 if the capability is not found.
148 */
149
150int
151tgetnum(char *tcstr)
152{
153	int	n = _NUMELEMENTS(numoffsets);
154	int	offset = _tcsearch(tcstr, numoffsets, numcodes, n, 2);
155	short	*num_array = (short *) cur_nums;
156
157	if (offset == -1)
158		return (-1);
159	else
160		return (num_array[offset]);
161}
162
163/*
164 * Return the string capability for capability "id".  We also copy
165 * it into *area for upward compatibility with a few programs that
166 * actually expect it to be copied, at a slight cost in speed.
167 */
168
169char	*
170tgetstr(char *tcstr, char **area)
171{
172	int	n = _NUMELEMENTS(stroffsets);
173	int	offset = _tcsearch(tcstr, stroffsets, strcodes, n, 2);
174	char	**str_array = (char **) cur_strs;
175	char	*rv;
176
177	if (offset == -1)
178		return (0);
179	rv = str_array[offset];
180	if (area && *area && rv) {
181		(void) strcpy(*area, rv);
182		*area += strlen(rv) + 1;
183	}
184	return (rv);
185}
186.
187w termcap.c
188q
189