/*
* 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 (c) 1995-1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* LINTLIBRARY */
/*
*
* XCurses Library
*
* Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
*
*/
#ifdef M_RCSID
#ifndef lint
static char const rcsID[] =
"$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
"cbates Exp $";
#endif
#endif
#include <private.h>
#ifdef TIOCGWINSZ
#endif
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
* Any version number should be placed in this file, since setupterm()
* must be called in order to initialize Curses or Terminfo.
*/
/*
* True if __m_setupterm() should use either the window settings from
* ioctl(), or the environment variables LINES and COLUMNS to override
* the terminfo database entries for 'lines' and 'columns'.
*
* Call use_env(flag) before either setupterm(), newterm(), or initscr().
*/
static const char e_terminal[] =
"No memory for TERMINAL structure.\n";
static const char e_unknown[] =
"\"%s\": Unknown terminal type.\n";
static const char e_pathmax[] =
"\"%s\": terminfo database path too long.\n";
/*
* These globals are used so that macro arguments are evaluated
* exactly once
*/
/* The downside is that it is not really thread-safe. Oh well... */
/*
* Take the real command character out of the CC environment variable
* and substitute it in for the prototype given in 'command_character'.
*/
static void
do_prototype(void)
{
int i, j;
char proto;
char *CC;
for (i = 0; i < __COUNT_STR; i++)
}
#define min(a, b) ((a) < (b) ? (a) : (b))
/*
* Return a number from a terminfo file. Numbers in a terminfo
* file are stored as two bytes with low-high ordering.
*/
static short
{
return (SHRT_MIN);
}
/*
* MKS Header format for terminfo database files.
*
* byte swapping (least-significant byte first). The integers are
*
* 1) magic number (octal 0432);
* 2) the size, in bytes, of the names sections;
* 3) the number of bytes in the boolean section;
* 4) the number of short integers in the numbers section;
* 5) the number of offsets (short integers) in the strings section;
* 6) the size, in bytes, of the string table.
*
* Between the boolean and number sections, a null byte is inserted, if
* necessary, to ensure that the number section begins on an even byte
* offset. All short integers are aligned on a short word boundary.
*/
typedef struct {
short magic;
short name_size;
short bool_count;
short num_count;
short str_count;
short str_size;
/*
* Read the compiled terminfo entry in the given file into the
* structure pointed to by ptr, allocating space for the string
* table and placing its address in ptr->str_table.
*/
int
{
int fd;
short offset;
unsigned char ch;
/* Get compiled terminfo file header. */
goto error_1;
}
goto error_2;
}
/* Allocate and fetch terminal names. */
goto error_2;
goto error_3;
/* Fetch booleans. */
goto error_3;
SEEK_CUR);
} else {
}
/* Eat padding byte. */
/* Fetch numbers. */
for (i = 0; i < len; ++i)
} else {
}
/* Allocate and fetch strings. */
goto error_3;
/* Read in string offset section setting pointers to strings. */
for (i = 0; i < len; ++i) {
goto error_4;
if (offset < 0)
else
}
} else {
for (; i < __COUNT_STR; ++i)
}
goto error_4;
return (0);
return (-1);
}
void
{
}
/*
* Set up terminal.
*
* Reads in the terminfo database pointed to by $TERMINFO env. var.
* for the given terminal, but does not set up the output virtualization
* structues used by CURSES. If the terminal name pointer is NULL,
* the $TERM env. var. is used for the terminal. All output is to
* the given file descriptor which is initialized for output.
*
* On error, if errret != NULL then setupterm() returns OK
* or ERR and stores a status value in the integer pointed to by
* errret. A status of 1 is normal, 0 means the terminal could
* not be found, and -1 means the terminfo database could not be
* found. If errret == NULL then setupterm() prints an error
* message upon and exit().
*
* On success, cur_term set to a terminfo structure and OK returned.
*/
int
{
const char *err_msg;
/*
* It is possible to call setupterm() for multiple terminals,
* in which case we have to be able to restore cur_term in
* case of error.
*/
err_code = -1;
goto error;
}
(void) def_shell_mode();
(void) def_prog_mode();
#ifdef ONLCR
#else
#endif
switch (err_code) {
case -1:
break;
case 0:
break;
case 1:
break;
case 2:
err_code = -1;
break;
}
if (err_return != NULL) {
*err_return = err_code;
if (err_code == 1) {
} else {
}
} else if (err_code != 1) {
exit(1);
}
return (err_code);
}
int
{
int code;
return (code);
}
int
{
}
return (OK);
}
TERMINAL *
{
return (old);
}
int
{
int err_code;
err_code = 1;
} else {
/* Not really true... */
err_code = 2;
goto error;
}
}
tm = (char *)def_termname;
}
/* Remember the terminal name being loaded. */
err_code = 2;
goto error;
}
/* Length of path we're going to construct. */
err_code = 2;
goto error;
}
/* Construct terminfo filename. */
/* Go looking for compiled terminal definition. */
/* Length of default terminfo path. */
err_code = 2;
goto error;
}
err_code = 0;
goto error;
}
}
if (use_environment) {
char *env;
#ifdef TIOCGWINSZ
/*
* Use ioctl(TIOCGWINSZ) to get row and column values. These
* values may override the default terminfo settings.
*/
{
}
}
#endif /* TIOCGWINSZ */
/* Check to see is the user wants a particular size terminal. */
if (0 < nlines)
}
if (0 < ncolumns)
}
}
do_prototype();
/*
* If no_color_video is disabled, then assign it a value that
* permits all attributes in combination with colour.
*/
if (no_color_video == -1)
no_color_video = 0;
if (terminfo != def_terminfo)
if (err_return != NULL) {
*err_return = err_code;
if (err_code == 1) {
} else {
}
} else if (err_code != 1) {
exit(1);
}
if (old_strings != NULL)
}
return (err_code);
}
/*
* Get the termios setting for the terminal. Check the input
* file descriptor first, else the output file descriptor. If
* both input and output are both terminals, it is assumed that
* they refer to the same terminal.
*/
int
{
/*
* Input was not a terminal, possibly redirected.
* Check output instead.
*/
return (ERR);
}
return (OK);
}
int
__m_tty_set_prog_mode(void)
{
}
/*
* Restore the termios settings.
*/
int
{
int fd;
int rval;
} else {
return (OK);
}
return (OK);
return (rval);
}
int
def_shell_mode(void)
{
}
int
def_prog_mode(void)
{
}
int
reset_shell_mode(void)
{
}
int
reset_prog_mode(void)
{
return (__m_tty_set_prog_mode());
}