New files.

This commit is contained in:
mycroft 1993-08-07 05:51:11 +00:00
parent b06a09ba51
commit c710920fc5
3 changed files with 497 additions and 0 deletions

214
lib/libcurses/setterm.c Normal file
View File

@ -0,0 +1,214 @@
/*
* Copyright (c) 1981 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)setterm.c 5.9 (Berkeley) 8/23/92";*/
static char rcsid[] = "$Id: setterm.c,v 1.1 1993/08/07 05:51:11 mycroft Exp $";
#endif /* not lint */
#include <sys/ioctl.h>
#include <curses.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static void zap __P((void));
static char *sflags[] = {
&AM, &BS, &DA, &EO, &HC, &HZ, &IN, &MI, &MS,
&NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS, &XX
};
static char *_PC,
**sstrs[] = {
&AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS,
&DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2,
&K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC,
&IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU,
&LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF,
&SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US,
&VB, &VS, &VE, &AL_PARM, &DL_PARM, &UP_PARM,
&DOWN_PARM, &LEFT_PARM, &RIGHT_PARM,
};
static char *aoftspace; /* Address of _tspace for relocation */
static char tspace[2048]; /* Space for capability strings */
static int destcol, destline;
char *ttytype;
int
setterm(type)
register char *type;
{
static char genbuf[1024];
static char __ttytype[1024];
register int unknown;
struct winsize win;
char *p;
#ifdef DEBUG
__TRACE("setterm: (\"%s\")\nLINES = %d, COLS = %d\n",
type, LINES, COLS);
#endif
if (type[0] == '\0')
type = "xx";
unknown = 0;
if (tgetent(genbuf, type) != 1) {
unknown++;
strcpy(genbuf, "xx|dumb:");
}
#ifdef DEBUG
__TRACE("setterm: tty = %s\n", type);
#endif
/* Try TIOCGWINSZ, and, if it fails, the termcap entry. */
if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) != -1 &&
win.ws_row != 0 && win.ws_col != 0) {
LINES = win.ws_row;
COLS = win.ws_col;
} else {
LINES = tgetnum("li");
COLS = tgetnum("co");
}
/* POSIX 1003.2 requires that the environment override. */
if ((p = getenv("ROWS")) != NULL)
LINES = strtol(p, NULL, 10);
if ((p = getenv("COLUMNS")) != NULL)
COLS = strtol(p, NULL, 10);
/*
* XXX
* Historically, curses fails if rows <= 5, cols <= 4.
*/
if (LINES <= 5 || COLS <= 4)
return (ERR);
#ifdef DEBUG
__TRACE("setterm: LINES = %d, COLS = %d\n", LINES, COLS);
#endif
aoftspace = tspace;
zap(); /* Get terminal description. */
/* Handle funny termcap capabilities. */
if (CS && SC && RC)
AL = DL = "";
if (AL_PARM && AL == NULL)
AL = "";
if (DL_PARM && DL == NULL)
DL = "";
if (IC) {
if (IM == NULL)
IM = "";
if (EI == NULL)
EI = "";
}
if (!GT) /* If we can't tab, we can't backtab either. */
BT = NULL;
if (tgoto(CM, destcol, destline)[0] == 'O') {
CA = 0;
CM = 0;
} else
CA = 1;
PC = _PC ? _PC[0] : 0;
aoftspace = tspace;
ttytype = longname(genbuf, __ttytype);
return (unknown ? ERR : OK);
}
/*
* zap --
* Gets all the terminal flags from the termcap database.
*/
static void
zap()
{
register char *namp, ***sp;
register char **fp;
#ifdef DEBUG
register char *cp;
#endif
namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx";
fp = sflags;
do {
*(*fp++) = tgetflag(namp);
#ifdef DEBUG
__TRACE("2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
#endif
namp += 2;
} while (*namp);
namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI";
sp = sstrs;
do {
*(*sp++) = tgetstr(namp, &aoftspace);
#ifdef DEBUG
__TRACE("2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
if (*sp[-1] != NULL) {
for (cp = *sp[-1]; *cp; cp++)
__TRACE("%s", unctrl(*cp));
__TRACE("\"\n");
}
#endif
namp += 2;
} while (*namp);
if (XS)
SO = SE = NULL;
else {
if (tgetnum("sg") > 0)
SO = NULL;
if (tgetnum("ug") > 0)
US = NULL;
if (!SO && US) {
SO = US;
SE = UE;
}
}
}
/*
* getcap --
* Return a capability from termcap.
*/
char *
getcap(name)
char *name;
{
return (tgetstr(name, &aoftspace));
}

77
lib/libcurses/trace.c Normal file
View File

@ -0,0 +1,77 @@
/*-
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)trace.c 5.1 (Berkeley) 8/23/92";*/
static char rcsid[] = "$Id: trace.c,v 1.1 1993/08/07 05:51:14 mycroft Exp $";
#endif /* not lint */
#ifdef DEBUG
#include <stdio.h>
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#ifndef TFILE
#define TFILE "__curses.out"
#endif
static FILE *tracefp; /* Curses debugging file descriptor. */
void
#if __STDC__
__TRACE(const char *fmt, ...)
#else
__TRACE(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
if (tracefp == NULL)
tracefp = fopen(TFILE, "w");
if (tracefp == NULL)
return;
(void)vfprintf(tracefp, fmt, ap);
va_end(ap);
(void)fflush(tracefp);
}
#endif

206
lib/libcurses/tty.c Normal file
View File

@ -0,0 +1,206 @@
/*-
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)tty.c 5.2 (Berkeley) 8/31/92";*/
static char rcsid[] = "$Id: tty.c,v 1.1 1993/08/07 05:51:16 mycroft Exp $";
#endif /* not lint */
/*
* Terminal initialization routines.
*/
#include <sys/ioctl.h>
#include <curses.h>
#include <termios.h>
#include <unistd.h>
struct termios newtermio, origtermio;
static struct termios norawt, rawt;
static int useraw;
/*
* gettmode --
* Do terminal type initialization.
*/
int
gettmode()
{
if (tcgetattr(STDIN_FILENO, &origtermio))
return (OK);
GT = (origtermio.c_oflag & OXTABS) == 0;
NONL = (origtermio.c_oflag & ONLCR) == 0;
norawt = origtermio;
norawt.c_oflag &= ~OXTABS;
rawt = norawt;
cfmakeraw(&rawt);
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt) ? ERR : OK);
}
int
raw()
{
useraw = __pfast = __rawmode = 1;
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
}
int
noraw()
{
useraw = __pfast = __rawmode = 0;
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
cbreak()
{
rawt.c_lflag &= ~ICANON;
norawt.c_lflag &= ~ICANON;
__rawmode = 1;
if (useraw)
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
else
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
nocbreak()
{
rawt.c_lflag |= ICANON;
norawt.c_lflag |= ICANON;
__rawmode = 0;
if (useraw)
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
else
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
echo()
{
rawt.c_lflag |= ECHO;
norawt.c_lflag |= ECHO;
__echoit = 1;
if (useraw)
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
else
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
noecho()
{
rawt.c_lflag &= ~ECHO;
norawt.c_lflag &= ~ECHO;
__echoit = 0;
if (useraw)
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
else
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
nl()
{
rawt.c_iflag |= ICRNL;
rawt.c_oflag |= ONLCR;
norawt.c_iflag |= ICRNL;
norawt.c_oflag |= ONLCR;
__pfast = __rawmode;
if (useraw)
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
else
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
nonl()
{
rawt.c_iflag &= ~ICRNL;
rawt.c_oflag &= ~ONLCR;
norawt.c_iflag &= ~ICRNL;
norawt.c_oflag &= ~ONLCR;
__pfast = 1;
if (useraw)
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &rawt));
else
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &norawt));
}
int
endwin()
{
if (curscr) {
if (curscr->_flags & _STANDOUT) {
tputs(SE, 0, __cputchar);
curscr->_flags &= ~_STANDOUT;
}
__endwin = 1;
}
(void)tputs(VE, 0, __cputchar);
(void)tputs(TE, 0, __cputchar);
(void)fflush(stdout);
__echoit = origtermio.c_lflag & ECHO;
__rawmode = origtermio.c_lflag & ICANON;
__pfast = origtermio.c_iflag & ICRNL ? __rawmode : 1;
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &origtermio));
}
/*
* The following routines, savetty and resetty are completely useless and
* are left in only as stubs. If people actually use them they will almost
* certainly screw up the state of the world.
*/
static struct termios savedtty;
int
savetty()
{
return (tcgetattr(STDIN_FILENO, &savedtty));
}
int
resetty()
{
return (tcsetattr(STDIN_FILENO, TCSADRAIN, &savedtty));
}