1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * University Copyright- Copyright (c) 1982, 1986, 1988
8  * The Regents of the University of California
9  * All Rights Reserved
10  *
11  * University Acknowledgment- Portions of this document are derived from
12  * software developed by the University of California, Berkeley, and its
13  * contributors.
14  */
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 /*
19  * Simulation of termcap using terminfo.
20  * This file is created from termcap.ed. DO NOT EDIT ME!
21  */
22 
23 /*
24  * These are declared so people won't get undefineds if they use
25  * old documentation.  We don't do anything with them.
26  */
27 
28 #include	<sys/types.h>
29 #include	<string.h>
30 #include	"curses_inc.h"
31 
32 char	*UP;
33 char	*BC;
34 char	PC;
35 short	ospeed;
36 
37 /* ARGSUSED */
38 int
39 tgetent(char *bp, char *name)
40 {
41 	int	rv;
42 
43 	if (setupterm(name, 1, &rv) >= 0)
44 	/* Leave things as they were (for compatibility) */
45 		(void) reset_shell_mode();
46 	return (rv);
47 }
48 
49 /* Make a 2 letter code into an integer we can switch on easily */
50 #define	_TWO(s1, s2)	(s1 + 256*s2)
51 #define	_TWOSTR(str)	_TWO(*str, str[1])
52 
53 static	char	*
54 _stripdelays(char *inbuf, char *outbuf, int size)
55 {
56 	char	*saveoutbuf = outbuf;
57 
58 	if (inbuf == NULL)
59 		return (0);
60 	else
61 		while (size && *inbuf)
62 			if (*inbuf == '$' && *(inbuf+1) == '<')
63 				/* LINTED */
64 				while (*inbuf && *inbuf++ != '>');
65 			else {
66 				size--;
67 				*outbuf++ = *inbuf++;
68 				*outbuf = 0;
69 			}
70 		return (saveoutbuf);
71 }
72 
73 /* generated by sort on caps */
74 static	short	booloffsets[] =
75 		{		/* generated by sort on caps */
76 	/* "5i" */	22,
77 	/* "HC" */	23,
78 	/* "ND" */	26,
79 	/* "NP" */	25,
80 	/* "NR" */	24,
81 	/* "YA" */	30,
82 	/* "YB" */	31,
83 	/* "YC" */	32,
84 	/* "YD" */	33,
85 	/* "YE" */	34,
86 	/* "YF" */	35,
87 	/* "YG" */	36,
88 	/* "am" */	1,
89 	/* "bw" */	0,
90 	/* "cc" */	27,
91 	/* "da" */	11,
92 	/* "db" */	12,
93 	/* "eo" */	5,
94 	/* "es" */	16,
95 	/* "gn" */	6,
96 	/* "hc" */	7,
97 	/* "hl" */	29,
98 	/* "hs" */	9,
99 	/* "hz" */	18,
100 	/* "in" */	10,
101 	/* "km" */	8,
102 	/* "mi" */	13,
103 	/* "ms" */	14,
104 	/* "nx" */	21,
105 	/* "os" */	15,
106 	/* "ul" */	19,
107 	/* "ut" */	28,
108 	/* "xb" */	2,
109 	/* "xn" */	4,
110 	/* "xo" */	20,
111 	/* "xs" */	3,
112 	/* "xt" */	17,
113 		};
114 
115 /* generated by sort on caps */
116 static	short	numoffsets[] =
117 		{
118 	/* "BT" */	30,
119 	/* "Co" */	13,
120 	/* "MW" */	12,
121 	/* "NC" */	15,
122 	/* "Nl" */	8,
123 	/* "Ya" */	16,
124 	/* "Yb" */	17,
125 	/* "Yc" */	18,
126 	/* "Yd" */	19,
127 	/* "Ye" */	20,
128 	/* "Yf" */	21,
129 	/* "Yg" */	22,
130 	/* "Yh" */	23,
131 	/* "Yi" */	24,
132 	/* "Yj" */	25,
133 	/* "Yk" */	26,
134 	/* "Yl" */	27,
135 	/* "Ym" */	28,
136 	/* "Yn" */	29,
137 	/* "Yo" */	31,
138 	/* "Yp" */	32,
139 	/* "co" */	0,
140 	/* "it" */	1,
141 	/* "lh" */	9,
142 	/* "li" */	2,
143 	/* "lm" */	3,
144 	/* "lw" */	10,
145 	/* "ma" */	11,
146 	/* "pa" */	14,
147 	/* "pb" */	5,
148 	/* "sg" */	4,
149 	/* "vt" */	6,
150 	/* "ws" */	7,
151 		};
152 
153 /* generated by sort on caps */
154 static	short	stroffsets[] =
155 		{
156 	/* "!1" */	212,
157 	/* "!2" */	213,
158 	/* "!3" */	214,
159 	/* "#1" */	198,
160 	/* "#2" */	199,
161 	/* "#3" */	200,
162 	/* "#4" */	201,
163 	/* "%0" */	177,
164 	/* "%1" */	168,
165 	/* "%2" */	169,
166 	/* "%3" */	170,
167 	/* "%4" */	171,
168 	/* "%5" */	172,
169 	/* "%6" */	173,
170 	/* "%7" */	174,
171 	/* "%8" */	175,
172 	/* "%9" */	176,
173 	/* "%a" */	202,
174 	/* "%b" */	203,
175 	/* "%c" */	204,
176 	/* "%d" */	205,
177 	/* "%e" */	206,
178 	/* "%f" */	207,
179 	/* "%g" */	208,
180 	/* "%h" */	209,
181 	/* "%i" */	210,
182 	/* "%j" */	211,
183 	/* "&0" */	187,
184 	/* "&1" */	178,
185 	/* "&2" */	179,
186 	/* "&3" */	180,
187 	/* "&4" */	181,
188 	/* "&5" */	182,
189 	/* "&6" */	183,
190 	/* "&7" */	184,
191 	/* "&8" */	185,
192 	/* "&9" */	186,
193 	/* "*0" */	197,
194 	/* "*1" */	188,
195 	/* "*2" */	189,
196 	/* "*3" */	190,
197 	/* "*4" */	191,
198 	/* "*5" */	192,
199 	/* "*6" */	193,
200 	/* "*7" */	194,
201 	/* "*8" */	195,
202 	/* "*9" */	196,
203 	/* "??" */	386,
204 	/* "??" */	387,
205 	/* "??" */	388,
206 	/* "??" */	389,
207 	/* "??" */	390,
208 	/* "??" */	391,
209 	/* "??" */	392,
210 	/* "@0" */	167,
211 	/* "@1" */	158,
212 	/* "@2" */	159,
213 	/* "@3" */	160,
214 	/* "@4" */	161,
215 	/* "@5" */	162,
216 	/* "@6" */	163,
217 	/* "@7" */	164,
218 	/* "@8" */	165,
219 	/* "@9" */	166,
220 	/* "AB" */	360,
221 	/* "AF" */	359,
222 	/* "AL" */	110,
223 	/* "CC" */	9,
224 	/* "CM" */	15,
225 	/* "CW" */	277,
226 	/* "DC" */	105,
227 	/* "DI" */	280,
228 	/* "DK" */	275,
229 	/* "DL" */	106,
230 	/* "DO" */	107,
231 	/* "F1" */	216,
232 	/* "F2" */	217,
233 	/* "F3" */	218,
234 	/* "F4" */	219,
235 	/* "F5" */	220,
236 	/* "F6" */	221,
237 	/* "F7" */	222,
238 	/* "F8" */	223,
239 	/* "F9" */	224,
240 	/* "FA" */	225,
241 	/* "FB" */	226,
242 	/* "FC" */	227,
243 	/* "FD" */	228,
244 	/* "FE" */	229,
245 	/* "FF" */	230,
246 	/* "FG" */	231,
247 	/* "FH" */	232,
248 	/* "FI" */	233,
249 	/* "FJ" */	234,
250 	/* "FK" */	235,
251 	/* "FL" */	236,
252 	/* "FM" */	237,
253 	/* "FN" */	238,
254 	/* "FO" */	239,
255 	/* "FP" */	240,
256 	/* "FQ" */	241,
257 	/* "FR" */	242,
258 	/* "FS" */	243,
259 	/* "FT" */	244,
260 	/* "FU" */	245,
261 	/* "FV" */	246,
262 	/* "FW" */	247,
263 	/* "FX" */	248,
264 	/* "FY" */	249,
265 	/* "FZ" */	250,
266 	/* "Fa" */	251,
267 	/* "Fb" */	252,
268 	/* "Fc" */	253,
269 	/* "Fd" */	254,
270 	/* "Fe" */	255,
271 	/* "Ff" */	256,
272 	/* "Fg" */	257,
273 	/* "Fh" */	258,
274 	/* "Fi" */	259,
275 	/* "Fj" */	260,
276 	/* "Fk" */	261,
277 	/* "Fl" */	262,
278 	/* "Fm" */	263,
279 	/* "Fn" */	264,
280 	/* "Fo" */	265,
281 	/* "Fp" */	266,
282 	/* "Fq" */	267,
283 	/* "Fr" */	268,
284 	/* "Gm" */	358,
285 	/* "HU" */	279,
286 	/* "IC" */	108,
287 	/* "Ic" */	299,
288 	/* "Ip" */	300,
289 	/* "K1" */	139,
290 	/* "K2" */	141,
291 	/* "K3" */	140,
292 	/* "K4" */	142,
293 	/* "K5" */	143,
294 	/* "Km" */	355,
295 	/* "LE" */	111,
296 	/* "LF" */	157,
297 	/* "LO" */	156,
298 	/* "Lf" */	273,
299 	/* "MC" */	270,
300 	/* "ML" */	271,
301 	/* "ML" */	368,
302 	/* "MR" */	272,
303 	/* "MT" */	369,
304 	/* "Mi" */	356,
305 	/* "PA" */	285,
306 	/* "PU" */	283,
307 	/* "QD" */	281,
308 	/* "RA" */	152,
309 	/* "RC" */	276,
310 	/* "RF" */	215,
311 	/* "RI" */	112,
312 	/* "RQ" */	357,
313 	/* "RX" */	150,
314 	/* "S1" */	378,
315 	/* "S2" */	379,
316 	/* "S3" */	380,
317 	/* "S4" */	381,
318 	/* "S5" */	382,
319 	/* "S6" */	383,
320 	/* "S7" */	384,
321 	/* "S8" */	385,
322 	/* "SA" */	151,
323 	/* "SC" */	274,
324 	/* "SF" */	109,
325 	/* "SR" */	113,
326 	/* "SX" */	149,
327 	/* "Sb" */	303,
328 	/* "Sf" */	302,
329 	/* "TO" */	282,
330 	/* "UP" */	114,
331 	/* "WA" */	286,
332 	/* "WG" */	278,
333 	/* "XF" */	154,
334 	/* "XN" */	153,
335 	/* "Xy" */	370,
336 	/* "YI" */	393,
337 	/* "YZ" */	377,
338 	/* "Yv" */	372,
339 	/* "Yw" */	373,
340 	/* "Yx" */	374,
341 	/* "Yy" */	375,
342 	/* "Yz" */	376,
343 	/* "ZA" */	304,
344 	/* "ZB" */	305,
345 	/* "ZC" */	306,
346 	/* "ZD" */	307,
347 	/* "ZE" */	308,
348 	/* "ZF" */	309,
349 	/* "ZG" */	310,
350 	/* "ZH" */	311,
351 	/* "ZI" */	312,
352 	/* "ZJ" */	313,
353 	/* "ZK" */	314,
354 	/* "ZL" */	315,
355 	/* "ZM" */	316,
356 	/* "ZN" */	317,
357 	/* "ZO" */	318,
358 	/* "ZP" */	319,
359 	/* "ZQ" */	320,
360 	/* "ZR" */	321,
361 	/* "ZS" */	322,
362 	/* "ZT" */	323,
363 	/* "ZU" */	324,
364 	/* "ZV" */	325,
365 	/* "ZW" */	326,
366 	/* "ZX" */	327,
367 	/* "ZY" */	328,
368 	/* "ZZ" */	329,
369 	/* "Za" */	330,
370 	/* "Zb" */	331,
371 	/* "Zc" */	332,
372 	/* "Zd" */	333,
373 	/* "Ze" */	334,
374 	/* "Zf" */	335,
375 	/* "Zg" */	336,
376 	/* "Zh" */	337,
377 	/* "Zi" */	338,
378 	/* "Zj" */	339,
379 	/* "Zk" */	340,
380 	/* "Zl" */	341,
381 	/* "Zm" */	342,
382 	/* "Zn" */	343,
383 	/* "Zo" */	344,
384 	/* "Zp" */	345,
385 	/* "Zq" */	346,
386 	/* "Zr" */	347,
387 	/* "Zs" */	348,
388 	/* "Zt" */	349,
389 	/* "Zu" */	350,
390 	/* "Zv" */	351,
391 	/* "Zw" */	352,
392 	/* "Zx" */	353,
393 	/* "Zy" */	354,
394 	/* "Zz" */	371,
395 	/* "ac" */	146,
396 	/* "ae" */	38,
397 	/* "al" */	53,
398 	/* "as" */	25,
399 	/* "bl" */	1,
400 	/* "bt" */	0,
401 	/* "cb" */	269,
402 	/* "cd" */	7,
403 	/* "ce" */	6,
404 	/* "ch" */	8,
405 	/* "ci" */	363,
406 	/* "cl" */	5,
407 	/* "cm" */	10,
408 	/* "cr" */	2,
409 	/* "cs" */	3,
410 	/* "ct" */	4,
411 	/* "cv" */	127,
412 	/* "dc" */	21,
413 	/* "dl" */	22,
414 	/* "dm" */	29,
415 	/* "do" */	11,
416 	/* "ds" */	23,
417 	/* "dv" */	362,
418 	/* "eA" */	155,
419 	/* "ec" */	37,
420 	/* "ed" */	41,
421 	/* "ei" */	42,
422 	/* "ff" */	46,
423 	/* "fh" */	284,
424 	/* "fs" */	47,
425 	/* "hd" */	24,
426 	/* "ho" */	12,
427 	/* "hu" */	137,
428 	/* "i1" */	48,
429 	/* "i3" */	50,
430 	/* "iP" */	138,
431 	/* "ic" */	52,
432 	/* "if" */	51,
433 	/* "im" */	31,
434 	/* "ip" */	54,
435 	/* "is" */	49,
436 	/* "k0" */	65,
437 	/* "k1" */	66,
438 	/* "k2" */	68,
439 	/* "k3" */	69,
440 	/* "k4" */	70,
441 	/* "k5" */	71,
442 	/* "k6" */	72,
443 	/* "k7" */	73,
444 	/* "k8" */	74,
445 	/* "k9" */	75,
446 	/* "k;" */	67,
447 	/* "kA" */	78,
448 	/* "kB" */	148,
449 	/* "kC" */	57,
450 	/* "kD" */	59,
451 	/* "kE" */	63,
452 	/* "kF" */	84,
453 	/* "kH" */	80,
454 	/* "kI" */	77,
455 	/* "kL" */	60,
456 	/* "kM" */	62,
457 	/* "kN" */	81,
458 	/* "kP" */	82,
459 	/* "kR" */	85,
460 	/* "kS" */	64,
461 	/* "kT" */	86,
462 	/* "ka" */	56,
463 	/* "kb" */	55,
464 	/* "kd" */	61,
465 	/* "ke" */	88,
466 	/* "kh" */	76,
467 	/* "kl" */	79,
468 	/* "kr" */	83,
469 	/* "ks" */	89,
470 	/* "kt" */	58,
471 	/* "ku" */	87,
472 	/* "l0" */	90,
473 	/* "l1" */	91,
474 	/* "l2" */	93,
475 	/* "l3" */	94,
476 	/* "l4" */	95,
477 	/* "l5" */	96,
478 	/* "l6" */	97,
479 	/* "l7" */	98,
480 	/* "l8" */	99,
481 	/* "l9" */	100,
482 	/* "la" */	92,
483 	/* "le" */	14,
484 	/* "ll" */	18,
485 	/* "mb" */	26,
486 	/* "md" */	27,
487 	/* "me" */	39,
488 	/* "mh" */	30,
489 	/* "mk" */	32,
490 	/* "mm" */	102,
491 	/* "mo" */	101,
492 	/* "mp" */	33,
493 	/* "mr" */	34,
494 	/* "nd" */	17,
495 	/* "nw" */	103,
496 	/* "oc" */	298,
497 	/* "op" */	297,
498 	/* "pO" */	144,
499 	/* "pc" */	104,
500 	/* "pf" */	119,
501 	/* "pk" */	115,
502 	/* "pl" */	116,
503 	/* "pn" */	147,
504 	/* "po" */	120,
505 	/* "ps" */	118,
506 	/* "px" */	117,
507 	/* "r1" */	122,
508 	/* "r2" */	123,
509 	/* "r3" */	124,
510 	/* "rP" */	145,
511 	/* "rc" */	126,
512 	/* "rf" */	125,
513 	/* "rp" */	121,
514 	/* "s0" */	364,
515 	/* "s1" */	365,
516 	/* "s2" */	366,
517 	/* "s3" */	367,
518 	/* "sa" */	131,
519 	/* "sc" */	128,
520 	/* "se" */	43,
521 	/* "sf" */	129,
522 	/* "so" */	35,
523 	/* "sp" */	301,
524 	/* "sr" */	130,
525 	/* "st" */	132,
526 	/* "ta" */	134,
527 	/* "te" */	40,
528 	/* "ti" */	28,
529 	/* "ts" */	135,
530 	/* "u0" */	287,
531 	/* "u1" */	288,
532 	/* "u2" */	289,
533 	/* "u3" */	290,
534 	/* "u4" */	291,
535 	/* "u5" */	292,
536 	/* "u6" */	293,
537 	/* "u7" */	294,
538 	/* "u8" */	295,
539 	/* "u9" */	296,
540 	/* "uc" */	136,
541 	/* "ue" */	44,
542 	/* "up" */	19,
543 	/* "us" */	36,
544 	/* "vb" */	45,
545 	/* "ve" */	16,
546 	/* "vi" */	13,
547 	/* "vs" */	20,
548 	/* "wi" */	133,
549 	/* "xl" */	361,
550 		};
551 
552 /*
553  * Return the value of the boolean capability tcstr.
554  * Return 0 if the capability is not found.
555  */
556 
557 int
558 tgetflag(char *tcstr)
559 {
560 	char	*p;
561 	char	stripped[16];
562 
563 	switch (_TWOSTR(tcstr)) {
564 	/* Special cases that do not have exact terminfo equivalents */
565 		case _TWO('b','s'):
566 			/* bs: true if ^H moves the cursor left */
567 			p = _stripdelays(cursor_left, stripped, 16);
568 			return (p && *p == 8 && p[1] == 0);
569 		case _TWO('p','t'):
570 			/* pt: true if terminal has ^I tabs every 8 spaces */
571 			p = _stripdelays(tab, stripped, 16);
572 			return (p && *p == 9 && p[1] == 0);
573 		case _TWO('n','c'):
574 			/* cr: true if ^M does not return the cursor */
575 			p = _stripdelays(carriage_return, stripped, 16);
576 			return (! (p && *p == 13 && p[1] == 0));
577 		case _TWO('n','s'):
578 			/* ns: true if no way to scroll the terminal */
579 			return (scroll_forward == NULL);
580 	}
581 	{
582 		int	n = _NUMELEMENTS(booloffsets);
583 		int	offset = _tcsearch(tcstr, booloffsets, boolcodes, n, 2);
584 		char	*bool_array = (char *) cur_bools;
585 
586 		if (offset == -1)
587 			return (0);
588 		else
589 			return (bool_array[offset]);
590 	}
591 }
592 
593 /*
594  * Return the value of the numeric capability tcstr.
595  * Return -1 if the capability is not found.
596  */
597 
598 int
599 tgetnum(char *tcstr)
600 {
601 	int	n = _NUMELEMENTS(numoffsets);
602 	int	offset = _tcsearch(tcstr, numoffsets, numcodes, n, 2);
603 	short	*num_array = (short *) cur_nums;
604 
605 	if (offset == -1)
606 		return (-1);
607 	else
608 		return (num_array[offset]);
609 }
610 
611 /*
612  * Return the string capability for capability "id".  We also copy
613  * it into *area for upward compatibility with a few programs that
614  * actually expect it to be copied, at a slight cost in speed.
615  */
616 
617 char	*
618 tgetstr(char *tcstr, char **area)
619 {
620 	int	n = _NUMELEMENTS(stroffsets);
621 	int	offset = _tcsearch(tcstr, stroffsets, strcodes, n, 2);
622 	char	**str_array = (char **) cur_strs;
623 	char	*rv;
624 
625 	if (offset == -1)
626 		return (0);
627 	rv = str_array[offset];
628 	if (area && *area && rv) {
629 		(void) strcpy(*area, rv);
630 		*area += strlen(rv) + 1;
631 	}
632 	return (rv);
633 }
634