17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
524da5b34Srie * Common Development and Distribution License (the "License").
624da5b34Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
2224da5b34Srie * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include "errno.h"
307c478bd9Sstevel@tonic-gate #include "string.h"
317c478bd9Sstevel@tonic-gate #include "sys/types.h"
327c478bd9Sstevel@tonic-gate #include "sys/stat.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #if defined(__STDC__)
357c478bd9Sstevel@tonic-gate #include "stdarg.h"
367c478bd9Sstevel@tonic-gate #else
377c478bd9Sstevel@tonic-gate #include "varargs.h"
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include "lp.h"
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate extern char *boolnames[],
437c478bd9Sstevel@tonic-gate *numnames[],
4424da5b34Srie *strnames[];
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate extern char *getenv();
477c478bd9Sstevel@tonic-gate
4824da5b34Srie ushort_t tidbit_boolean = 0;
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate short tidbit_number = 0;
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate char *tidbit_string = 0;
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #if defined(__STDC__)
557c478bd9Sstevel@tonic-gate static int open_terminfo_file(char *, char *);
567c478bd9Sstevel@tonic-gate #else
577c478bd9Sstevel@tonic-gate static int open_terminfo_file();
587c478bd9Sstevel@tonic-gate #endif
597c478bd9Sstevel@tonic-gate
6024da5b34Srie /*
6124da5b34Srie * _Getsh() - GET TWO-BYTE SHORT FROM "char *" POINTER PORTABLY
6224da5b34Srie */
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate * "function" to get a short from a pointer. The short is in a standard
667c478bd9Sstevel@tonic-gate * format: two bytes, the first is the low order byte, the second is
677c478bd9Sstevel@tonic-gate * the high order byte (base 256). The only negative number allowed is
687c478bd9Sstevel@tonic-gate * -1, which is represented as 255, 255. This format happens to be the
697c478bd9Sstevel@tonic-gate * same as the hardware on the pdp-11 and vax, making it fast and
707c478bd9Sstevel@tonic-gate * convenient and small to do this on a pdp-11.
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate #if vax || pdp11 || i386
747c478bd9Sstevel@tonic-gate #define _Getsh(ip) (*((short *)((char *)(ip))))
757c478bd9Sstevel@tonic-gate #endif /* vax || pdp11 || i386 */
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * The following macro is partly due to Mike Laman, laman@sdcsvax
797c478bd9Sstevel@tonic-gate * NCR @ Torrey Pines. - Tony Hansen
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate #if u3b || u3b15 || u3b2 || m68000 || sparc
827c478bd9Sstevel@tonic-gate #define _Getsh(ip) ((short)(*((unsigned char *) ip) | (*(ip+1) << 8)))
837c478bd9Sstevel@tonic-gate #endif /* u3b || u3b15 || u3b2 || m68000 || sparc */
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate #ifndef _Getsh
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate * Here is a more portable version, which does not assume byte ordering
887c478bd9Sstevel@tonic-gate * in shorts, sign extension, etc. It does assume that the C preprocessor
897c478bd9Sstevel@tonic-gate * does sign-extension the same as on the machine being compiled for.
907c478bd9Sstevel@tonic-gate * When ANSI C comes along, this should be changed to check <limits.h>
917c478bd9Sstevel@tonic-gate * to see if the low character value is negative.
927c478bd9Sstevel@tonic-gate */
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate static int
957c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_Getsh(register char * p)967c478bd9Sstevel@tonic-gate _Getsh(
977c478bd9Sstevel@tonic-gate register char *p
987c478bd9Sstevel@tonic-gate )
997c478bd9Sstevel@tonic-gate #else
1007c478bd9Sstevel@tonic-gate _Getsh(p)
1017c478bd9Sstevel@tonic-gate register char *p;
1027c478bd9Sstevel@tonic-gate #endif
1037c478bd9Sstevel@tonic-gate {
1047c478bd9Sstevel@tonic-gate register int rv,
1057c478bd9Sstevel@tonic-gate rv2;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate #if -1 == '\377' /* sign extension occurs */
1087c478bd9Sstevel@tonic-gate rv = (*p++) & 0377;
1097c478bd9Sstevel@tonic-gate rv2 = (*p) & 0377;
1107c478bd9Sstevel@tonic-gate #else /* -1 == '\377' */ /* no sign extension */
1117c478bd9Sstevel@tonic-gate rv = *p++;
1127c478bd9Sstevel@tonic-gate rv2 = *p;
1137c478bd9Sstevel@tonic-gate #endif /* -1 == '\377' */
1147c478bd9Sstevel@tonic-gate if ((rv2 == 0377) && ((rv == 0377) || (rv == 0376)))
1157c478bd9Sstevel@tonic-gate return (-1);
1167c478bd9Sstevel@tonic-gate return (rv + (rv2 * 256));
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate #endif /* _Getsh */
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate #define MAX_TIDBS 32
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate static struct tidb {
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate int snames,
1257c478bd9Sstevel@tonic-gate nbools,
1267c478bd9Sstevel@tonic-gate nints,
1277c478bd9Sstevel@tonic-gate nstrs;
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate char *term,
1307c478bd9Sstevel@tonic-gate *tiebuf,
1317c478bd9Sstevel@tonic-gate *boolean_offset,
1327c478bd9Sstevel@tonic-gate *number_offset,
1337c478bd9Sstevel@tonic-gate *string_offset,
1347c478bd9Sstevel@tonic-gate *string_table;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate } tidbs[MAX_TIDBS + 1]; /* one for last ditch */
1377c478bd9Sstevel@tonic-gate
13824da5b34Srie /*
13924da5b34Srie * tidbit() - TERMINFO DATABASE LOOKUP
14024da5b34Srie */
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate * Four forms of calling:
1447c478bd9Sstevel@tonic-gate *
1457c478bd9Sstevel@tonic-gate * tidbit ("term-type", "boolean-cap-name", &ushort)
1467c478bd9Sstevel@tonic-gate * tidbit ("term-type", "numeric-cap-name", &short)
1477c478bd9Sstevel@tonic-gate * tidbit ("term-type", "string-cap-name", &charstar)
1487c478bd9Sstevel@tonic-gate * tidbit ("term-type", "any-cap-name", (char *)0)
1497c478bd9Sstevel@tonic-gate *
1507c478bd9Sstevel@tonic-gate * The last one is chancy, because of the pointer alignment
1517c478bd9Sstevel@tonic-gate * problem, but hey--what the heck. Anyway, the last one
1527c478bd9Sstevel@tonic-gate * causes the value to be stored in one of
1537c478bd9Sstevel@tonic-gate *
1547c478bd9Sstevel@tonic-gate * ushort tidbit_boolean;
1557c478bd9Sstevel@tonic-gate * short tidbit_number;
1567c478bd9Sstevel@tonic-gate * char *tidbit_string;
1577c478bd9Sstevel@tonic-gate *
1587c478bd9Sstevel@tonic-gate * as appropriate, and returns one of 1, 2, or 3 as the type
1597c478bd9Sstevel@tonic-gate * of the capability is boolean, numeric, or string.
1607c478bd9Sstevel@tonic-gate *
1617c478bd9Sstevel@tonic-gate * For example, to extract the size of the screen for a 5410:
1627c478bd9Sstevel@tonic-gate *
1637c478bd9Sstevel@tonic-gate * short cols, lines;
1647c478bd9Sstevel@tonic-gate *
1657c478bd9Sstevel@tonic-gate * tidbit ("5410", "cols", &cols);
1667c478bd9Sstevel@tonic-gate * tidbit ("5410", "lines", &lines);
1677c478bd9Sstevel@tonic-gate *
1687c478bd9Sstevel@tonic-gate * Note that for the lines and columns, this does NOT check
1697c478bd9Sstevel@tonic-gate * the LINES and COLUMNS environment variables nor the window
1707c478bd9Sstevel@tonic-gate * size, if running on a windowing terminal. That can be done
1717c478bd9Sstevel@tonic-gate * by the caller.
1727c478bd9Sstevel@tonic-gate *
1737c478bd9Sstevel@tonic-gate * If first argument is (char *)0, "tidbit()" uses the same TERM
1747c478bd9Sstevel@tonic-gate * used in the last call, or the TERM environment variable if this
1757c478bd9Sstevel@tonic-gate * is the first call.
1767c478bd9Sstevel@tonic-gate * If second argument is (char *)0, no lookup just verification
1777c478bd9Sstevel@tonic-gate * of terminal type.
1787c478bd9Sstevel@tonic-gate *
1797c478bd9Sstevel@tonic-gate * Return is 0 (or 1, 2, 3 as above) if successful, otherwise -1
1807c478bd9Sstevel@tonic-gate * with "errno" set:
1817c478bd9Sstevel@tonic-gate *
1827c478bd9Sstevel@tonic-gate * ENOENT can't open Terminfo file for terminal type
1837c478bd9Sstevel@tonic-gate * EBADF Terminfo file is corrupted
1847c478bd9Sstevel@tonic-gate * ENOMEM malloc failed
1857c478bd9Sstevel@tonic-gate */
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*VARARGS2*/
1887c478bd9Sstevel@tonic-gate int
1897c478bd9Sstevel@tonic-gate #if defined(__STDC__)
tidbit(char * term,char * cap,...)1907c478bd9Sstevel@tonic-gate tidbit(
1917c478bd9Sstevel@tonic-gate char *term,
1927c478bd9Sstevel@tonic-gate char *cap,
1937c478bd9Sstevel@tonic-gate ...
1947c478bd9Sstevel@tonic-gate )
1957c478bd9Sstevel@tonic-gate #else
1967c478bd9Sstevel@tonic-gate tidbit(term, cap, va_alist)
1977c478bd9Sstevel@tonic-gate char *term,
1987c478bd9Sstevel@tonic-gate *cap;
1997c478bd9Sstevel@tonic-gate va_dcl
2007c478bd9Sstevel@tonic-gate #endif
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate va_list ap;
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate int rc;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate register int i;
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate register char **pp;
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate register struct tidb *pt;
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate static char *last_term;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate if (!term)
2167c478bd9Sstevel@tonic-gate if (last_term)
2177c478bd9Sstevel@tonic-gate term = last_term;
2187c478bd9Sstevel@tonic-gate else {
2197c478bd9Sstevel@tonic-gate term = getenv("TERM");
2207c478bd9Sstevel@tonic-gate if (!term || !*term)
2217c478bd9Sstevel@tonic-gate term = NAME_UNKNOWN;
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate if (term != last_term) {
2247c478bd9Sstevel@tonic-gate if (last_term)
2257c478bd9Sstevel@tonic-gate Free(last_term);
2267c478bd9Sstevel@tonic-gate last_term = Strdup(term);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_TIDBS; i++)
2307c478bd9Sstevel@tonic-gate if (tidbs[i].term && STREQU(tidbs[i].term, term)) {
2317c478bd9Sstevel@tonic-gate pt = &tidbs[i];
2327c478bd9Sstevel@tonic-gate break;
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate * Not cached, so read the file and cache it.
2377c478bd9Sstevel@tonic-gate */
2387c478bd9Sstevel@tonic-gate if (i >= MAX_TIDBS) {
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate register int n,
2417c478bd9Sstevel@tonic-gate tfd;
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate register char *terminfo;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate struct stat statbuf;
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate * If no empty spot can be found, "i" will index the
2507c478bd9Sstevel@tonic-gate * last spot, a spare reserved to avoid problems with
2517c478bd9Sstevel@tonic-gate * a full cache.
2527c478bd9Sstevel@tonic-gate */
2537c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_TIDBS; i++)
2547c478bd9Sstevel@tonic-gate if (!tidbs[i].term)
2557c478bd9Sstevel@tonic-gate break;
2567c478bd9Sstevel@tonic-gate pt = &tidbs[i];
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate tfd = -1;
2597c478bd9Sstevel@tonic-gate if ((terminfo = getenv("TERMINFO")) && *terminfo)
2607c478bd9Sstevel@tonic-gate tfd = open_terminfo_file(terminfo, term);
2617c478bd9Sstevel@tonic-gate #if defined(TERMINFO)
2627c478bd9Sstevel@tonic-gate if (tfd < 0)
2637c478bd9Sstevel@tonic-gate tfd = open_terminfo_file(TERMINFO, term);
2647c478bd9Sstevel@tonic-gate #endif
2657c478bd9Sstevel@tonic-gate if (tfd >= 0)
2667c478bd9Sstevel@tonic-gate (void) Fstat(tfd, &statbuf);
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate if (tfd < 0 || !statbuf.st_size) {
2697c478bd9Sstevel@tonic-gate errno = ENOENT;
2707c478bd9Sstevel@tonic-gate return (-1);
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate if (pt->tiebuf)
2747c478bd9Sstevel@tonic-gate Free(pt->tiebuf);
2757c478bd9Sstevel@tonic-gate if (!(pt->tiebuf = Malloc(statbuf.st_size))) {
2767c478bd9Sstevel@tonic-gate errno = ENOMEM;
2777c478bd9Sstevel@tonic-gate return (-1);
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate n = Read(tfd, pt->tiebuf, statbuf.st_size);
2817c478bd9Sstevel@tonic-gate (void) Close(tfd);
2827c478bd9Sstevel@tonic-gate if (n <= 0 || n >= 4096 || _Getsh(pt->tiebuf) != 0432) {
2837c478bd9Sstevel@tonic-gate Free(pt->tiebuf);
2847c478bd9Sstevel@tonic-gate pt->tiebuf = 0;
2857c478bd9Sstevel@tonic-gate errno = EBADF;
2867c478bd9Sstevel@tonic-gate return (-1);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate if (pt->term)
2907c478bd9Sstevel@tonic-gate Free(pt->term);
2917c478bd9Sstevel@tonic-gate if (!(pt->term = Strdup(term))) {
2927c478bd9Sstevel@tonic-gate Free(pt->tiebuf);
2937c478bd9Sstevel@tonic-gate pt->tiebuf = 0;
2947c478bd9Sstevel@tonic-gate errno = ENOMEM;
2957c478bd9Sstevel@tonic-gate return (-1);
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate pt->snames = _Getsh(pt->tiebuf + 2);
2997c478bd9Sstevel@tonic-gate pt->nbools = _Getsh(pt->tiebuf + 4);
3007c478bd9Sstevel@tonic-gate pt->nints = _Getsh(pt->tiebuf + 6);
3017c478bd9Sstevel@tonic-gate pt->nstrs = _Getsh(pt->tiebuf + 8);
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate pt->boolean_offset = pt->tiebuf + 6 * 2 + pt->snames;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate pt->number_offset = pt->boolean_offset + pt->nbools;
3067c478bd9Sstevel@tonic-gate if ((unsigned int)pt->number_offset & 1)
3077c478bd9Sstevel@tonic-gate pt->number_offset++;
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate pt->string_offset = pt->number_offset + pt->nints * 2;
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate pt->string_table = pt->string_offset + pt->nstrs * 2;
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate rc = 0;
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate #if defined(__STDC__)
3187c478bd9Sstevel@tonic-gate va_start(ap, cap);
3197c478bd9Sstevel@tonic-gate #else
3207c478bd9Sstevel@tonic-gate va_start(ap);
3217c478bd9Sstevel@tonic-gate #endif
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate if (!cap || !*cap)
3247c478bd9Sstevel@tonic-gate ;
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate else if ((pp = wherelist(cap, boolnames))) {
32724da5b34Srie register ushort_t *ushort_p;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate register char *ip;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate register int index = pp - boolnames;
3327c478bd9Sstevel@tonic-gate
33324da5b34Srie if (!(ushort_p = va_arg(ap, ushort_t *))) {
3347c478bd9Sstevel@tonic-gate ushort_p = &tidbit_boolean;
3357c478bd9Sstevel@tonic-gate rc = 1;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate if (index >= pt->nbools)
3397c478bd9Sstevel@tonic-gate *ushort_p = 0;
3407c478bd9Sstevel@tonic-gate else {
3417c478bd9Sstevel@tonic-gate ip = pt->boolean_offset + index;
3427c478bd9Sstevel@tonic-gate *ushort_p = (*ip & 01);
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate } else if ((pp = wherelist(cap, numnames))) {
3467c478bd9Sstevel@tonic-gate register short *short_p;
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate register char *ip;
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate register int index = pp - numnames;
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate if (!(short_p = va_arg(ap, short *))) {
3537c478bd9Sstevel@tonic-gate short_p = &tidbit_number;
3547c478bd9Sstevel@tonic-gate rc = 2;
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate if (index >= pt->nints)
3587c478bd9Sstevel@tonic-gate *short_p = -1;
3597c478bd9Sstevel@tonic-gate else {
3607c478bd9Sstevel@tonic-gate ip = pt->number_offset + index * 2;
3617c478bd9Sstevel@tonic-gate *short_p = _Getsh(ip);
3627c478bd9Sstevel@tonic-gate if (*short_p == -2)
3637c478bd9Sstevel@tonic-gate *short_p = -1;
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
36624da5b34Srie } else if ((pp = wherelist(cap, strnames))) {
3677c478bd9Sstevel@tonic-gate register char **charstar_p;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate register char *ip;
3707c478bd9Sstevel@tonic-gate
37124da5b34Srie register int index = pp - strnames;
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate register short sindex;
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate if (!(charstar_p = va_arg(ap, char **))) {
3777c478bd9Sstevel@tonic-gate charstar_p = &tidbit_string;
3787c478bd9Sstevel@tonic-gate rc = 3;
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate if (index >= pt->nstrs)
3827c478bd9Sstevel@tonic-gate *charstar_p = 0;
3837c478bd9Sstevel@tonic-gate else {
3847c478bd9Sstevel@tonic-gate ip = pt->string_offset + index * 2;
3857c478bd9Sstevel@tonic-gate if ((sindex = _Getsh(ip)) >= 0)
3867c478bd9Sstevel@tonic-gate *charstar_p = pt->string_table + sindex;
3877c478bd9Sstevel@tonic-gate else
3887c478bd9Sstevel@tonic-gate *charstar_p = 0;
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate va_end(ap);
3937c478bd9Sstevel@tonic-gate return (rc);
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate
39624da5b34Srie /*
39724da5b34Srie * untidbit() - FREE SPACE ASSOCIATED WITH A TERMINFO ENTRY
39824da5b34Srie */
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate void
4017c478bd9Sstevel@tonic-gate #if defined(__STDC__)
untidbit(char * term)4027c478bd9Sstevel@tonic-gate untidbit(
4037c478bd9Sstevel@tonic-gate char *term
4047c478bd9Sstevel@tonic-gate )
4057c478bd9Sstevel@tonic-gate #else
4067c478bd9Sstevel@tonic-gate untidbit(term)
4077c478bd9Sstevel@tonic-gate char *term;
4087c478bd9Sstevel@tonic-gate #endif
4097c478bd9Sstevel@tonic-gate {
4107c478bd9Sstevel@tonic-gate register int i;
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_TIDBS; i++)
4147c478bd9Sstevel@tonic-gate if (tidbs[i].term && STREQU(tidbs[i].term, term)) {
4157c478bd9Sstevel@tonic-gate if (tidbs[i].tiebuf) {
4167c478bd9Sstevel@tonic-gate Free(tidbs[i].tiebuf);
4177c478bd9Sstevel@tonic-gate tidbs[i].tiebuf = 0;
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate Free(tidbs[i].term);
4207c478bd9Sstevel@tonic-gate tidbs[i].term = 0;
4217c478bd9Sstevel@tonic-gate break;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate
42524da5b34Srie /*
42624da5b34Srie * open_terminfo_file() - OPEN FILE FOR TERM ENTRY
42724da5b34Srie */
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate static int
4307c478bd9Sstevel@tonic-gate #if defined(__STDC__)
open_terminfo_file(char * terminfo,char * term)4317c478bd9Sstevel@tonic-gate open_terminfo_file(
4327c478bd9Sstevel@tonic-gate char *terminfo,
4337c478bd9Sstevel@tonic-gate char *term
4347c478bd9Sstevel@tonic-gate )
4357c478bd9Sstevel@tonic-gate #else
4367c478bd9Sstevel@tonic-gate open_terminfo_file(terminfo, term)
4377c478bd9Sstevel@tonic-gate char *terminfo,
4387c478bd9Sstevel@tonic-gate *term;
4397c478bd9Sstevel@tonic-gate #endif
4407c478bd9Sstevel@tonic-gate {
441*268ffd3aSRichard Lowe char first_letter[] = "X",
4427c478bd9Sstevel@tonic-gate *path;
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate int fd;
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate first_letter[0] = term[0];
4477c478bd9Sstevel@tonic-gate path = makepath(terminfo, first_letter, term, (char *)0);
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate /* start fix for bugid 1109709 */
4507c478bd9Sstevel@tonic-gate if (path == NULL) {
45124da5b34Srie return (-1);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate /* end fix for bugid 1109709 */
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate fd = Open(path, 0);
4567c478bd9Sstevel@tonic-gate Free(path);
4577c478bd9Sstevel@tonic-gate return (fd);
4587c478bd9Sstevel@tonic-gate }
459