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