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