5 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
10 * University Copyright- Copyright (c) 1982, 1986, 1988
11 * The Regents of the University of California
14 * University Acknowledgment- Portions of this document are derived from
15 * software developed by the University of California, Berkeley, and its
19 #pragma ident "%Z%%M% %I% %E% SMI"
22 * Simulation of termcap using terminfo.
23 * This file is created from termcap.ed. DO NOT EDIT ME!
27 * These are declared so people won't get undefineds if they use
28 * old documentation. We don't do anything with them.
31 #include <sys/types.h>
33 #include "curses_inc.h"
42 tgetent(char *bp, char *name)
46 if (setupterm(name, 1, &rv) >= 0)
47 /* Leave things as they were (for compatibility) */
48 (void) reset_shell_mode();
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])
57 _stripdelays(char *inbuf, char *outbuf, int size)
59 char *saveoutbuf = outbuf;
64 while (size && *inbuf)
65 if (*inbuf == '$' && *(inbuf+1) == '<')
67 while (*inbuf && *inbuf++ != '>');
76 /* generated by sort on caps */
77 static short booloffsets[] =
78 { /* generated by sort on caps */
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
85 /* generated by sort on caps */
86 static short numoffsets[] =
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
94 /* generated by sort on caps */
95 static short stroffsets[] =
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
105 * Return the value of the boolean capability tcstr.
106 * Return 0 if the capability is not found.
110 tgetflag(char *tcstr)
115 switch (_TWOSTR(tcstr)) {
116 /* Special cases that do not have exact terminfo equivalents */
118 /* bs: true if ^H moves the cursor left */
119 p = _stripdelays(cursor_left, stripped, 16);
120 return (p && *p == 8 && p[1] == 0);
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);
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));
130 /* ns: true if no way to scroll the terminal */
131 return (scroll_forward == NULL);
134 int n = _NUMELEMENTS(booloffsets);
135 int offset = _tcsearch(tcstr, booloffsets, boolcodes, n, 2);
136 char *bool_array = (char *) cur_bools;
141 return (bool_array[offset]);
146 * Return the value of the numeric capability tcstr.
147 * Return -1 if the capability is not found.
153 int n = _NUMELEMENTS(numoffsets);
154 int offset = _tcsearch(tcstr, numoffsets, numcodes, n, 2);
155 short *num_array = (short *) cur_nums;
160 return (num_array[offset]);
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.
170 tgetstr(char *tcstr, char **area)
172 int n = _NUMELEMENTS(stroffsets);
173 int offset = _tcsearch(tcstr, stroffsets, strcodes, n, 2);
174 char **str_array = (char **) cur_strs;
179 rv = str_array[offset];
180 if (area && *area && rv) {
181 (void) strcpy(*area, rv);
182 *area += strlen(rv) + 1;