/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*LINTLIBRARY*/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "curses_inc.h"
};
char _called_before = 0;
#ifdef SYSV
#endif
#ifdef DUMPTI
{
if (argc > 1)
else
setupterm((char *)0, 1, (int *)0);
return (0);
}
{
if (ch >= 0200) {
printf("M-");
ch -= 0200;
}
else
}
{
int ch;
if (n == -1) {
printf(".\n");
return;
}
printf(", string = '");
printf("'.\n");
}
{
unsigned char ch;
}
#endif /* vax || pdp11 */
#ifndef _Vr2getsh
/*
* Here is a more portable version, which does not assume byte ordering
* in shorts, sign extension, etc.
*/
_Vr2getsh(char *p)
{
int rv;
if (*p == (char)0377)
return (-1);
rv = (unsigned char) *p++;
rv += (unsigned char) *p * 256;
return (rv);
}
#endif /* _Vr2getsh */
#endif /* DUMPTI */
/*
* "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 numbers allowed are
* -1 and -2, which are represented as 255,255 and 255,254 This format
* happens to be the same as the hardware on the pdp-11, vax, and 386,
* making it fast and convenient and small to do this on a pdp-11.
*/
#endif /* vax || pdp11 */
/*
* The following macro is partly due to Mike Laman, laman@sdcsvax
* NCR @ Torrey Pines. - Tony Hansen
*/
#endif /* u3b || u3b15 || u3b2 || m68000 */
#ifndef _Getsh
/*
* Here is a more portable version, which does not assume byte ordering
* in shorts, sign extension, etc. For the sake of the porters,
* two alternative implementations, for the machines that don't have
* casting to "unsigned char", are also given, but commented out.
* Not ANSI C implementation assumes that the * C preprocessor does
* sign-extension the same as on the machine being compiled for.
*/
static int
_Getsh(char *p)
{
rv = (unsigned char) p[0];
rv2 = (unsigned char) p[1];
/* the following stuff is only for porting. See the comment above */
#ifdef FOR_PORTING
#if CHAR_MIN < 0
rv = (*p++) & 0377;
rv2 = (*p) & 0377;
#else /* CHAR_MIN < 0 */
rv = *p++;
rv2 = *p;
#endif /* CHAR_MIN < 0 */
#endif /* FOR_PORTING */
return (-1);
}
#endif /* _Getsh */
/*
* setupterm: low level routine to dig up terminfo from database
* and read it in. Parms are terminal type (0 means use getenv("TERM"),
* file descriptor all output will go to (for ioctls), and a pointer
* to an int into which the error return code goes (0 means to bomb
* out with an error message if there's an error). Thus,
* setupterm((char *)0, 1, (int *)0) is a reasonable way for a simple
* program to set up.
*/
int
/* filenum - This is a UNIX file descriptor, not a stdio ptr. */
{
char *ip;
char *cp;
int n, tfd;
char *strtab;
#ifdef DUMPTI
int Vr2val;
#endif /* DUMPTI */
(void) mbgetwidth();
tfd = -1;
errno = 0; /* ehr3 */
if (errret != 0)
*errret = -1;
/* $TERMINFO/?/$TERM */
goto out_err;
}
#ifdef DUMPTI
#endif /* DUMPTI */
goto cant_read;
}
if (tfd < 0) {
goto out_err;
}
#ifdef DUMPTI
#endif /* DUMPTI */
}
if (tfd < 0) {
} else {
else {
if (errret != 0)
*errret = 0;
}
}
/*
* if the length of the specified terminal name is longer
* than 31, it will be chopped after the 31st byte.
* This should be a rare case.
*/
goto out_err;
}
/* LINTED */
if (n <= 0) {
goto out_err;
} else
if (n == sizeof (tiebuf)) {
goto out_err;
}
/* Pick up header */
#ifdef DUMPTI
Vr2val = _Vr2getshi();
#endif /* DUMPTI */
goto corrupt;
#ifdef DUMPTI
Vr2val = _Vr2getshi();
#endif /* DUMPTI */
#ifdef DUMPTI
Vr2val = _Vr2getshi();
#endif /* DUMPTI */
#ifdef DUMPTI
Vr2val = _Vr2getshi();
#endif /* DUMPTI */
#ifdef DUMPTI
Vr2val = _Vr2getshi();
#endif /* DUMPTI */
#ifdef DUMPTI
Vr2val = _Vr2getshi();
#endif /* DUMPTI */
/* allocate all of the space */
if (_called_before) {
/* 2nd or more times through */
goto badmalloc;
if ((cur_bools = (struct _bool_struct *)
goto freeterminal;
if ((cur_nums = (struct _num_struct *)
goto freebools;
if ((cur_strs = (struct _str_struct *)
#ifdef DEBUG
#endif /* DEBUG */
if (errret == 0) {
termerr();
exit(-term_errno);
} else
return (ERR);
}
} else {
/* First time through */
cur_term = &_first_term;
cur_bools = &_frst_bools;
cur_nums = &_frst_nums;
cur_strs = &_frst_strs;
if (sstrtab < sizeof (_frst_tblstr))
}
if (cur_strs != &_frst_strs)
goto freenums;
}
}
/* no more catchable errors */
if (errret)
*errret = 1;
/* In case the name is exactly 15 characters */
/* LINTED */
#ifndef DUMPTI
(void) def_shell_mode();
/* This is a useful default for PROGTTY, too */
#ifdef SYSV
if (shell_istermios < 0) {
int i;
for (i = 0; i < NCC; i++)
prog_istermios = -1;
for (i = 0; i < NCC; i++)
} else {
prog_istermios = 0;
}
#else /* SYSV */
#endif /* SYSV */
#endif /* DUMPTI */
/* Skip names of terminals */
/*
* Pull out the booleans.
* The for loop below takes care of a new curses with an old tic
* file and visa-versa. nbools says how many bools the tic file has.
* So, we only loop for as long as there are bools to read.
* However, if this is an old curses that doesn't have all the
* bools that this new tic has dumped, then the extra if
* "if (cp < fp)" says that if we are going to read into our structure
* passed its size don't do it but we still need to keep bumping
* up the pointer of what we read in from the terminfo file.
*/
{
char s;
#ifdef DUMPTI
int tempindex = 0;
#endif /* DUMPTI */
while (nbools--) {
s = *ip++;
#ifdef DUMPTI
printf("Bool %s [%s] (%s) = %d.\n",
tempindex++;
#endif /* DUMPTI */
*cp++ = s & 01;
}
}
/* Force proper alignment */
if (((unsigned long) ip) & 1)
ip++;
/*
* Pull out the numbers.
*/
{
int s;
#ifdef DUMPTI
int tempindex = 0;
#endif /* DUMPTI */
while (nints--) {
s = _Getshi();
#ifdef DUMPTI
Vr2val = _Vr2getshi();
printf("Num %s [%s] (%s) = %d [%d].\n",
tempindex++;
#endif /* DUMPTI */
if (s < 0)
*sp++ = -1;
else
/* LINTED */
*sp++ = (short)s;
}
}
if (_use_env) {
/*
* This ioctl defines the window size and overrides what
* it says in terminfo.
*/
{
struct winsize w;
if (w.ws_row != 0)
if (w.ws_col != 0)
#ifdef DUMPTI
printf("ioctl TIOCGWINSZ override: "
"(lines, columns) = (%d, %d)\n",
#endif /* DUMPTI */
}
}
/*
* Check $LINES and $COLUMNS.
*/
{
if (lcp)
/* LINTED */
#ifdef DUMPTI
printf("$LINES override: lines = %d\n",
ilines);
#endif /* DUMPTI */
}
if (ccp)
/* LINTED */
#ifdef DUMPTI
printf("$COLUMNS override: columns = "
"%d\n", icolumns);
#endif /* DUMPTI */
}
}
}
/* Pull out the strings. */
{
#ifdef DUMPTI
int tempindex = 0;
printf("string table = '");
printf("'\n");
#endif /* DUMPTI */
while (nstrs--) {
n = _Getshi();
#ifdef DUMPTI
Vr2val = _Vr2getshi();
printf("String %s [%s] (%s) offset = %d [%d]",
tempindex++;
#endif /* DUMPTI */
#ifdef DUMPTI
#endif /* DUMPTI */
if (n < 0)
else
}
#ifdef DUMPTI
else
_Sprint(-1, (char *)0);
#endif /* DUMPTI */
}
}
#ifndef DUMPTI
/*
* If tabs are being expanded in software, turn this off
* so output won't get messed up. Also, don't use tab
* or backtab, even if the terminal has them, since the
* user might not have hardware tabs set right.
*/
#ifdef SYSV
(void) reset_prog_mode();
goto next;
}
#else /* SYSV */
(void) reset_prog_mode();
goto next;
}
#endif /* SYSV */
if (dest_tabs_magic_smso) {
next:
}
#ifdef LTILDE
#endif /* LTILDE */
#endif /* DUMPTI */
#ifdef _VR2_COMPAT_CODE
#endif /* _VR2_COMPAT_CODE */
{
static char offsets[] = {
35, /* enter_standout_mode, */
36, /* enter_underline_mode, */
25, /* enter_alt_charset_mode, */
34, /* enter_reverse_mode, */
26, /* enter_blink_mode, */
30, /* enter_dim_mode, */
27, /* enter_bold_mode, */
32, /* enter_secure_mode, */
33, /* enter_protected_mode, */
};
for (n = 0; n < NUM_ATTRIBUTES; n++) {
}
}
if (!(set_attributes)) {
offsets[] = {
43, /* exit_standout_mode, */
44, /* exit_underline_mode, */
38, /* exit_alt_charset_mode, */
};
int i;
(magic_cookie_glitch >= 0)))
max_attributes = 1;
/* Figure out what attributes need to be faked. */
/* See vidupdate.c */
for (n = 0; n < sizeof (faked_attrs); n++) {
if (on_sequences[0] != NULL) {
if ((!on_sequences[i = faked_attrs[n]]) ||
(strcmp(on_sequences[i],
on_sequences[0]) == 0)) {
bit_attributes[i];
}
} else {
if (!on_sequences[i = faked_attrs[n]]) {
bit_attributes[i];
}
}
}
for (n = 0; n < sizeof (offsets); n++) {
((n > 0) && off_sequences[0] &&
0)) || ((n == 2) && (exit_attribute_mode) &&
0))) {
}
}
}
return (OK);
}
void
{
sizeof (bool));
}
#ifndef DUMPTI
int
reset_prog_mode(void)
{
#ifdef SYSV
if (prog_istermios < 0) {
int i;
for (i = 0; i < NCC; i++)
} else
}
#else /* SYSV */
#endif /* SYSV */
#ifdef LTILDE
#endif /* LTILDE */
#ifdef DIOCSETT
#endif /* DIOCSETT */
return (OK);
}
int
def_shell_mode(void)
{
#ifdef SYSV
if ((shell_istermios =
int i;
for (i = 0; i < NCC; i++)
}
#else /* SYSV */
#endif /* SYSV */
return (OK);
}
#endif /* DUMPTI */