📄 sys_term.c
字号:
/* * Copyright (c) 1989 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. *//* * From: @(#)sys_term.c 5.16 (Berkeley) 3/22/91 */char st_rcsid[] = "$Id: sys_term.c,v 1.17 1999/12/17 14:28:47 dholland Exp $";#include <utmp.h>#include "telnetd.h"#include "pathnames.h"#include "logout.h"#include "logwtmp.h"#if defined(__GLIBC__) && (__GLIBC__ >= 2)/* mmm, nonstandard */#include <pty.h>#elseint openpty(int *, int *, char *, struct termios *, struct winsize *);#endif#define ARCH64 ((sizeof(void *)) == 8)#define ARCH32 ((sizeof(void *)) == 4)#if defined(AUTHENTICATE)#include <libtelnet/auth.h>#endifstatic struct termios termbuf, termbuf2; /* pty control structure *//*static int cleanopen(char *line);*//* * init_termbuf() * copy_termbuf(cp) * set_termbuf() * * These three routines are used to get and set the "termbuf" structure * to and from the kernel. init_termbuf() gets the current settings. * copy_termbuf() hands in a new "termbuf" to write to the kernel, and * set_termbuf() writes the structure into the kernel. */void init_termbuf(void) { tcgetattr(pty, &termbuf); termbuf2 = termbuf;}#if defined(LINEMODE) && defined(TIOCPKT_IOCTL)/* * ? */void copy_termbuf(char *cp, int len) { if (len > sizeof(termbuf)) len = sizeof(termbuf); bcopy(cp, (char *)&termbuf, len); termbuf2 = termbuf;}#endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */void set_termbuf(void) { if (memcmp(&termbuf, &termbuf2, sizeof(termbuf))) { tcsetattr(pty, TCSANOW, &termbuf); }}/* * spcset(func, valp, valpp) * * This function takes various special characters (func), and * sets *valp to the current value of that character, and * *valpp to point to where in the "termbuf" structure that * value is kept. * * It returns the SLC_ level of support for this function. */int spcset(int func, cc_t *valp, cc_t **valpp) {#define setval(a, b) *valp = termbuf.c_cc[a]; \ *valpp = &termbuf.c_cc[a]; \ return(b);#define defval(a) *valp = ((cc_t)a); *valpp = (cc_t *)0; return(SLC_DEFAULT); switch(func) { case SLC_EOF: setval(VEOF, SLC_VARIABLE); case SLC_EC: setval(VERASE, SLC_VARIABLE); case SLC_EL: setval(VKILL, SLC_VARIABLE); case SLC_IP: setval(VINTR, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT); case SLC_ABORT: setval(VQUIT, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT); case SLC_XON:#ifdef VSTART setval(VSTART, SLC_VARIABLE);#else defval(0x13);#endif case SLC_XOFF:#ifdef VSTOP setval(VSTOP, SLC_VARIABLE);#else defval(0x11);#endif case SLC_EW:#ifdef VWERASE setval(VWERASE, SLC_VARIABLE);#else defval(0);#endif case SLC_RP:#ifdef VREPRINT setval(VREPRINT, SLC_VARIABLE);#else defval(0);#endif case SLC_LNEXT:#ifdef VLNEXT setval(VLNEXT, SLC_VARIABLE);#else defval(0);#endif case SLC_AO:#if !defined(VDISCARD) && defined(VFLUSHO)# define VDISCARD VFLUSHO#endif#ifdef VDISCARD setval(VDISCARD, SLC_VARIABLE|SLC_FLUSHOUT);#else defval(0);#endif case SLC_SUSP:#ifdef VSUSP setval(VSUSP, SLC_VARIABLE|SLC_FLUSHIN);#else defval(0);#endif#ifdef VEOL case SLC_FORW1: setval(VEOL, SLC_VARIABLE);#endif#ifdef VEOL2 case SLC_FORW2: setval(VEOL2, SLC_VARIABLE);#endif case SLC_AYT:#ifdef VSTATUS setval(VSTATUS, SLC_VARIABLE);#else defval(0);#endif case SLC_BRK: case SLC_SYNCH: case SLC_EOR: defval(0); default: *valp = 0; *valpp = 0; return(SLC_NOSUPPORT); }}/* * getpty() * * Allocate a pty. As a side effect, the external character * array "line" contains the name of the slave side. * * Returns the file descriptor of the opened pty. */static char linedata[PATH_MAX];char *line = linedata;static int ptyslavefd=-1;int getpty(void) { int masterfd; if (openpty(&masterfd, &ptyslavefd, line, NULL, NULL)) { return -1; } return masterfd;}#ifdef LINEMODE/* * tty_flowmode() Find out if flow control is enabled or disabled. * tty_linemode() Find out if linemode (external processing) is enabled. * tty_setlinemod(on) Turn on/off linemode. * tty_isecho() Find out if echoing is turned on. * tty_setecho(on) Enable/disable character echoing. * tty_israw() Find out if terminal is in RAW mode. * tty_binaryin(on) Turn on/off BINARY on input. * tty_binaryout(on) Turn on/off BINARY on output. * tty_isediting() Find out if line editing is enabled. * tty_istrapsig() Find out if signal trapping is enabled. * tty_setedit(on) Turn on/off line editing. * tty_setsig(on) Turn on/off signal trapping. * tty_issofttab() Find out if tab expansion is enabled. * tty_setsofttab(on) Turn on/off soft tab expansion. * tty_islitecho() Find out if typed control chars are echoed literally * tty_setlitecho() Turn on/off literal echo of control chars * tty_tspeed(val) Set transmit speed to val. * tty_rspeed(val) Set receive speed to val. */int tty_flowmode(void) { return (termbuf.c_iflag & IXON ? 1 : 0);}int tty_linemode(void) { return (termbuf.c_lflag & EXTPROC);}void tty_setlinemode(int on) {#ifdef TIOCEXT set_termbuf(); ioctl(pty, TIOCEXT, (char *)&on); init_termbuf();#else /* !TIOCEXT */# ifdef EXTPROC if (on) termbuf.c_lflag |= EXTPROC; else termbuf.c_lflag &= ~EXTPROC;# endif#endif /* TIOCEXT */}int tty_isecho(void) { return (termbuf.c_lflag & ECHO);}#endif /* LINEMODE */void tty_setecho(int on) { if (on) termbuf.c_lflag |= ECHO; else termbuf.c_lflag &= ~ECHO;}#if defined(LINEMODE) && defined(KLUDGELINEMODE)int tty_israw(void) { return(!(termbuf.c_lflag & ICANON));}#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */void tty_binaryin(int on) { if (on) { termbuf.c_iflag &= ~ISTRIP; } else { termbuf.c_iflag |= ISTRIP; }}void tty_binaryout(int on) { if (on) { termbuf.c_cflag &= ~(CSIZE|PARENB); termbuf.c_cflag |= CS8; termbuf.c_oflag &= ~OPOST; } else { termbuf.c_cflag &= ~CSIZE; termbuf.c_cflag |= CS7|PARENB; termbuf.c_oflag |= OPOST; }}int tty_isbinaryin(void) { return (!(termbuf.c_iflag & ISTRIP));}int tty_isbinaryout(void) { return (!(termbuf.c_oflag&OPOST));}#ifdef LINEMODEint tty_isediting(void) { return(termbuf.c_lflag & ICANON);}int tty_istrapsig(void) { return(termbuf.c_lflag & ISIG);}void tty_setedit(int on) { if (on) termbuf.c_lflag |= ICANON; else termbuf.c_lflag &= ~ICANON;}void tty_setsig(int on) { if (on) termbuf.c_lflag |= ISIG; else termbuf.c_lflag &= ~ISIG;}#endif /* LINEMODE */int tty_issofttab(void) {#ifdef OXTABS return (termbuf.c_oflag & OXTABS);#endif#ifdef TABDLY return ((termbuf.c_oflag & TABDLY) == TAB3);#endif}void tty_setsofttab(int on) { if (on) {#ifdef OXTABS termbuf.c_oflag |= OXTABS;#endif#ifdef TABDLY termbuf.c_oflag &= ~TABDLY; termbuf.c_oflag |= TAB3;#endif } else {#ifdef OXTABS termbuf.c_oflag &= ~OXTABS;#endif#ifdef TABDLY termbuf.c_oflag &= ~TABDLY; termbuf.c_oflag |= TAB0;#endif }}int tty_islitecho(void) { return (!(termbuf.c_lflag & ECHOCTL));}void tty_setlitecho(int on) { if (on) termbuf.c_lflag &= ~ECHOCTL; else termbuf.c_lflag |= ECHOCTL;}int tty_iscrnl(void) { return (termbuf.c_iflag & ICRNL);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -