tidbit.c revision 268ffd3a6be10ad5e25b948f7662de75e1316495
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include "errno.h"
#include "string.h"
#if defined(__STDC__)
#include "stdarg.h"
#else
#include "varargs.h"
#endif
#include "lp.h"
extern char *boolnames[],
*numnames[],
*strnames[];
extern char *getenv();
ushort_t tidbit_boolean = 0;
short tidbit_number = 0;
char *tidbit_string = 0;
#if defined(__STDC__)
static int open_terminfo_file(char *, char *);
#else
static int open_terminfo_file();
#endif
/*
* _Getsh() - GET TWO-BYTE SHORT FROM "char *" POINTER PORTABLY
*/
/*
* "function" to get a short from a pointer. The short is in a standard
* format: two bytes, the first is the low order byte, the second is
* the high order byte (base 256). The only negative number allowed is
* -1, which is represented as 255, 255. This format happens to be the
* same as the hardware on the pdp-11 and vax, making it fast and
* convenient and small to do this on a pdp-11.
*/
#endif /* vax || pdp11 || i386 */
/*
* The following macro is partly due to Mike Laman, laman@sdcsvax
* NCR @ Torrey Pines. - Tony Hansen
*/
#endif /* u3b || u3b15 || u3b2 || m68000 || sparc */
#ifndef _Getsh
/*
* Here is a more portable version, which does not assume byte ordering
* in shorts, sign extension, etc. It does assume that the C preprocessor
* does sign-extension the same as on the machine being compiled for.
* When ANSI C comes along, this should be changed to check <limits.h>
* to see if the low character value is negative.
*/
static int
#if defined(__STDC__)
register char *p
)
#else
_Getsh(p)
register char *p;
#endif
{
register int rv,
rv2;
#if -1 == '\377' /* sign extension occurs */
rv = (*p++) & 0377;
rv2 = (*p) & 0377;
#else /* -1 == '\377' */ /* no sign extension */
rv = *p++;
rv2 = *p;
#endif /* -1 == '\377' */
return (-1);
}
#endif /* _Getsh */
#define MAX_TIDBS 32
static struct tidb {
int snames,
char *term,
*tiebuf,
/*
* tidbit() - TERMINFO DATABASE LOOKUP
*/
/*
* Four forms of calling:
*
* tidbit ("term-type", "boolean-cap-name", &ushort)
* tidbit ("term-type", "numeric-cap-name", &short)
* tidbit ("term-type", "string-cap-name", &charstar)
* tidbit ("term-type", "any-cap-name", (char *)0)
*
* The last one is chancy, because of the pointer alignment
* problem, but hey--what the heck. Anyway, the last one
* causes the value to be stored in one of
*
* ushort tidbit_boolean;
* short tidbit_number;
* char *tidbit_string;
*
* as appropriate, and returns one of 1, 2, or 3 as the type
* of the capability is boolean, numeric, or string.
*
* For example, to extract the size of the screen for a 5410:
*
* short cols, lines;
*
* tidbit ("5410", "cols", &cols);
* tidbit ("5410", "lines", &lines);
*
* Note that for the lines and columns, this does NOT check
* the LINES and COLUMNS environment variables nor the window
* size, if running on a windowing terminal. That can be done
* by the caller.
*
* If first argument is (char *)0, "tidbit()" uses the same TERM
* used in the last call, or the TERM environment variable if this
* is the first call.
* If second argument is (char *)0, no lookup just verification
* of terminal type.
*
* Return is 0 (or 1, 2, 3 as above) if successful, otherwise -1
* with "errno" set:
*
* ENOENT can't open Terminfo file for terminal type
* EBADF Terminfo file is corrupted
* ENOMEM malloc failed
*/
/*VARARGS2*/
int
#if defined(__STDC__)
char *term,
char *cap,
...
)
#else
char *term,
*cap;
#endif
{
int rc;
register int i;
register char **pp;
static char *last_term;
if (!term)
if (last_term)
else {
term = NAME_UNKNOWN;
}
if (last_term)
}
for (i = 0; i < MAX_TIDBS; i++)
break;
}
/*
* Not cached, so read the file and cache it.
*/
if (i >= MAX_TIDBS) {
register int n,
tfd;
register char *terminfo;
/*
* If no empty spot can be found, "i" will index the
* last spot, a spare reserved to avoid problems with
* a full cache.
*/
for (i = 0; i < MAX_TIDBS; i++)
break;
tfd = -1;
#if defined(TERMINFO)
if (tfd < 0)
#endif
if (tfd >= 0)
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
pt->number_offset++;
}
rc = 0;
#if defined(__STDC__)
#else
#endif
;
register char *ip;
rc = 1;
}
*ushort_p = 0;
else {
}
register short *short_p;
register char *ip;
short_p = &tidbit_number;
rc = 2;
}
*short_p = -1;
else {
if (*short_p == -2)
*short_p = -1;
}
register char **charstar_p;
register char *ip;
register short sindex;
rc = 3;
}
*charstar_p = 0;
else {
else
*charstar_p = 0;
}
}
return (rc);
}
/*
* untidbit() - FREE SPACE ASSOCIATED WITH A TERMINFO ENTRY
*/
void
#if defined(__STDC__)
char *term
)
#else
char *term;
#endif
{
register int i;
for (i = 0; i < MAX_TIDBS; i++)
}
break;
}
}
/*
* open_terminfo_file() - OPEN FILE FOR TERM ENTRY
*/
static int
#if defined(__STDC__)
char *terminfo,
char *term
)
#else
char *terminfo,
*term;
#endif
{
char first_letter[] = "X",
*path;
int fd;
first_letter[0] = term[0];
/* start fix for bugid 1109709 */
return (-1);
}
/* end fix for bugid 1109709 */
return (fd);
}