📄 main.c
字号:
#ifndef lintstatic char *rid="$Header: main.c,v 1.202.1.2 93/03/22 12:38:11 dbrooks Exp $";#endif /* lint *//* * W A R N I N G * * If you think you know what all of this code is doing, you are * probably very mistaken. There be serious and nasty dragons here. * * This client is *not* to be taken as an example of how to write X * Toolkit applications. It is in need of a substantial rewrite, * ideally to create a generic tty widget with several different parsing * widgets so that you can plug 'em together any way you want. Don't * hold your breath, though.... *//***********************************************************Copyright 1987, 1988 by Digital Equipment Corporation, Maynard,Massachusetts, and the Massachusetts Institute of Technology,Cambridge, Massachusetts. All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the names of Digital or MIT not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* main.c */#ifdef DEBUGGING#define DBG(i) fprintf(stderr, i);#else#define DBG(i)#endif#define VERSIONINFO "UGCS color xterm ver. 6.1 beta 1\n"#include "ptyx.h"#include "data.h"#include "error.h"#include "menu.h"#include <X11/StringDefs.h>#include <X11/Shell.h>#include <X11/Xos.h>#include <X11/cursorfont.h>#include <X11/Xaw/SimpleMenu.h>#include <pwd.h>#include <ctype.h>#ifdef att#define ATT#endif#ifdef SVR4#define SYSV /* SVR4 is (approx) superset of SVR3 */#define USE_SYSV_UTMP#define ATT#define USE_TERMIOS#endif #ifdef SYSV386#define USE_SYSV_UTMP#define ATT#define USE_HANDSHAKEstatic Bool IsPts = False;#endif#if defined(ATT) || defined(sgi)#define USE_USG_PTYS#else#define USE_HANDSHAKE#endif#if defined(SYSV) && !defined(SVR4)/* older SYSV systems cannot ignore SIGHUP. Shell hangs, or you get extra shells, or something like that */#define USE_SYSV_SIGHUP#endif#if defined(sony) && defined(bsd43) && !defined(KANJI)#define KANJI#endif#include <sys/ioctl.h>#include <sys/stat.h>#ifdef USE_TERMIOS#include <termios.h>/* this hacked termios support only works on SYSV */#define USE_SYSV_TERMIO#define termio termios#undef TCGETA#ifndef BSD_TERMIOS#define TCGETA TCGETS#else#define TCGETA TIOCGETA#endif#undef TCSETA#ifndef BSD_TERMIOS#define TCSETA TCSETS#else#define TCSETA TIOCSETA#endif#else /* USE_TERMIOS */#ifdef SYSV#include <sys/termio.h>#endif /* SYSV */#endif /* USE_TERMIOS else */#if defined(SVR4) || defined(sgi)#undef TIOCSLTC /* defined, but not useable */#endif#ifdef SYSV#ifdef USE_USG_PTYS /* AT&T SYSV has no ptyio.h */#include <sys/stream.h> /* get typedef used in ptem.h */#ifndef sgi#include <sys/ptem.h> /* get struct winsize */#endif#include <sys/stropts.h> /* for I_PUSH */#include <poll.h> /* for POLLIN */#endif /* USE_USG_PTYS */#define USE_SYSV_TERMIO#define USE_SYSV_SIGNALS#define USE_SYSV_PGRP#define USE_SYSV_ENVVARS /* COLUMNS/LINES vs. TERMCAP *//* * now get system-specific includes */#ifdef CRAY#define USE_SYSV_UTMP#define HAS_UTMP_UT_HOST#define HAS_BSD_GROUPS#endif#ifdef macII#define HAS_UTMP_UT_HOST#define HAS_BSD_GROUPS#include <sys/ttychars.h>#undef USE_SYSV_ENVVARS#undef FIOCLEX#undef FIONCLEX#define setpgrp2 setpgrp#include <sgtty.h>#include <sys/resource.h>#endif#ifdef hpux#define HAS_BSD_GROUPS#define USE_SYSV_UTMP#define HAS_UTMP_UT_HOST#include <sys/ptyio.h>#endif /* hpux */#ifdef sgi#include <sys/sysmacros.h>#endif /* sgi */#endif /* SYSV */#ifdef INCLUDE_SGTTY#include <sgtty.h>#endif#ifndef SYSV /* BSD systems */#include <sys/resource.h>#define HAS_UTMP_UT_HOST#define HAS_BSD_GROUPS#endif /* !SYSV */#ifdef _POSIX_SOURCE#define USE_POSIX_WAIT#endif#ifdef SVR4#define USE_POSIX_WAIT#endif#include <stdio.h>#include <errno.h>#include <setjmp.h>#ifdef hpux#include <sys/utsname.h>#endif /* hpux */#if defined(apollo) && OSMAJORVERSION == 10 && OSMINORVERSION < 4#define ttyslot() 1#endif /* apollo */#ifdef sun#include <sys/filio.h>#endif#include <utmp.h>#ifdef LASTLOG#include <lastlog.h>#endif#include <sys/param.h> /* for NOFILE */#ifdef PUCC_PTYD#include <local/openpty.h>int Ptyfd;#endif /* PUCC_PTYD */#ifdef sequent#define USE_GET_PSEUDOTTY#endif#ifndef UTMP_FILENAME#define UTMP_FILENAME "/etc/utmp"#endif#ifndef LASTLOG_FILENAME#define LASTLOG_FILENAME "/usr/adm/lastlog" /* only on BSD systems */#endif#ifndef WTMP_FILENAME#if defined(SYSV)#define WTMP_FILENAME "/etc/wtmp"#else#define WTMP_FILENAME "/usr/adm/wtmp"#endif#endif#include <signal.h>#if defined(SCO) || defined(ISC)#undef SIGTSTP /* defined, but not the BSD way */#endif#ifdef SIGTSTP#include <sys/wait.h>#ifdef hpux#include <sys/bsdtty.h>#endif#endif#ifdef SIGNALRETURNSINT#define SIGNAL_T int#define SIGNAL_RETURN return 0#else#define SIGNAL_T void#define SIGNAL_RETURN return#endifSIGNAL_T Exit();#ifndef X_NOT_POSIX#include <unistd.h>#elseextern long lseek();#ifdef USGextern unsigned sleep();#elseextern void sleep();#endif#endif#ifndef X_NOT_STDC_ENV#include <stdlib.h>#elseextern char *malloc();extern char *calloc();extern char *realloc();extern char *getenv();extern void exit();#endif#ifdef X_NOT_POSIXextern char *ttyname();#endif#if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */char *malloc(), *realloc(), *calloc();char *ttyname(); /* and we don't get this from unistd.h */#endif /* macII */#ifdef SYSVextern char *ptsname();#endifextern char *strindex ();extern void HandlePopupMenu();int switchfb[] = {0, 2, 1, 3};static SIGNAL_T reapchild ();static Bool added_utmp_entry = False;static char **command_to_exec;#ifdef USE_SYSV_TERMIO/* The following structures are initialized in main() in order** to eliminate any assumptions about the internal order of their** contents.*/static struct termio d_tio;#ifdef TIOCSLTCstatic struct ltchars d_ltc;#endif /* TIOCSLTC */#ifdef TIOCLSETstatic unsigned int d_lmode;#endif /* TIOCLSET */#else /* not USE_SYSV_TERMIO */static struct sgttyb d_sg = { 0, 0, 0177, CKILL, EVENP|ODDP|ECHO|XTABS|CRMOD};static struct tchars d_tc = { CINTR, CQUIT, CSTART, CSTOP, CEOF, CBRK,};static struct ltchars d_ltc = { CSUSP, CDSUSP, CRPRNT, CFLUSH, CWERASE, CLNEXT};static int d_disipline = NTTYDISC;static long int d_lmode = LCRTBS|LCRTERA|LCRTKIL|LCTLECH;#ifdef sonystatic long int d_jmode = KM_SYSSJIS|KM_ASCII;static struct jtchars d_jtc = { 'J', 'B'};#endif /* sony */#endif /* USE_SYSV_TERMIO */static int parse_tty_modes ();/* * SYSV has the termio.c_cc[V] and ltchars; BSD has tchars and ltchars; * SVR4 has only termio.c_cc, but it includes everything from ltchars. */static int override_tty_modes = 0;struct _xttymodes { char *name; int len; int set; char value;} ttymodelist[] = {{ "intr", 4, 0, '\0' }, /* tchars.t_intrc ; VINTR */#define XTTYMODE_intr 0{ "quit", 4, 0, '\0' }, /* tchars.t_quitc ; VQUIT */#define XTTYMODE_quit 1{ "erase", 5, 0, '\0' }, /* sgttyb.sg_erase ; VERASE */#define XTTYMODE_erase 2{ "kill", 4, 0, '\0' }, /* sgttyb.sg_kill ; VKILL */#define XTTYMODE_kill 3{ "eof", 3, 0, '\0' }, /* tchars.t_eofc ; VEOF */#define XTTYMODE_eof 4{ "eol", 3, 0, '\0' }, /* VEOL */#define XTTYMODE_eol 5{ "swtch", 5, 0, '\0' }, /* VSWTCH */#define XTTYMODE_swtch 6{ "start", 5, 0, '\0' }, /* tchars.t_startc */#define XTTYMODE_start 7{ "stop", 4, 0, '\0' }, /* tchars.t_stopc */#define XTTYMODE_stop 8{ "brk", 3, 0, '\0' }, /* tchars.t_brkc */#define XTTYMODE_brk 9{ "susp", 4, 0, '\0' }, /* ltchars.t_suspc ; VSUSP */#define XTTYMODE_susp 10{ "dsusp", 5, 0, '\0' }, /* ltchars.t_dsuspc ; VDSUSP */#define XTTYMODE_dsusp 11{ "rprnt", 5, 0, '\0' }, /* ltchars.t_rprntc ; VREPRINT */#define XTTYMODE_rprnt 12{ "flush", 5, 0, '\0' }, /* ltchars.t_flushc ; VDISCARD */#define XTTYMODE_flush 13{ "weras", 5, 0, '\0' }, /* ltchars.t_werasc ; VWERASE */#define XTTYMODE_weras 14{ "lnext", 5, 0, '\0' }, /* ltchars.t_lnextc ; VLNEXT */#define XTTYMODE_lnext 15{ NULL, 0, 0, '\0' }, /* end of data */};#ifdef USE_SYSV_UTMP#ifndef SVR4 /* otherwise declared in utmp.h */extern struct utmp *getutent();extern struct utmp *getutid();extern struct utmp *getutline();extern void pututline();extern void setutent();extern void endutent();extern void utmpname();#endif /* !SVR4 */#ifndef SYSV386 /* could remove paragraph unconditionally? */extern struct passwd *getpwent();extern struct passwd *getpwuid();extern struct passwd *getpwnam();extern void setpwent();extern void endpwent();#endifextern struct passwd *fgetpwent();#else /* not USE_SYSV_UTMP */static char etc_utmp[] = UTMP_FILENAME;#ifdef LASTLOGstatic char etc_lastlog[] = LASTLOG_FILENAME;#endif #endif /* USE_SYSV_UTMP */#ifdef WTMPstatic char etc_wtmp[] = WTMP_FILENAME;#endif/* * Some people with 4.3bsd /bin/login seem to like to use login -p -f user * to implement xterm -ls. They can turn on USE_LOGIN_DASH_P and turn off * WTMP and LASTLOG. */#ifdef USE_LOGIN_DASH_P#ifndef LOGIN_FILENAME#define LOGIN_FILENAME "/bin/login"#endifstatic char bin_login[] = LOGIN_FILENAME;#endifstatic int inhibit;static char passedPty[2]; /* name if pty if slave */#ifdef TIOCCONSstatic int Console;#include <X11/Xmu/SysUtil.h> /* XmuGetHostname */#define MIT_CONSOLE_LEN 12#define MIT_CONSOLE "MIT_CONSOLE_"static char mit_console_name[255 + MIT_CONSOLE_LEN + 1] = MIT_CONSOLE;static Atom mit_console;#endif /* TIOCCONS */#ifdef SOLARIS#include <sys/wait.h>#include <sys/resource.h>#endif#ifndef USE_SYSV_UTMPstatic int tslot;#endif /* USE_SYSV_UTMP */static jmp_buf env;char *ProgramName;Boolean sunFunctionKeys;static struct _resource { char *xterm_name; char *icon_geometry; char *title; char *icon_name; char *term_name; char *tty_modes; Boolean utmpInhibit; Boolean sunFunctionKeys; /* %%% should be widget resource? */ Boolean wait_for_map; Boolean useInsertMode;} resource;/* used by VT (charproc.c) */#define offset(field) XtOffsetOf(struct _resource, field)static XtResource application_resources[] = { {"name", "Name", XtRString, sizeof(char *), offset(xterm_name), XtRString, "xterm"}, {"iconGeometry", "IconGeometry", XtRString, sizeof(char *), offset(icon_geometry), XtRString, (caddr_t) NULL}, {XtNtitle, XtCTitle, XtRString, sizeof(char *), offset(title), XtRString, (caddr_t) NULL}, {XtNiconName, XtCIconName, XtRString, sizeof(char *), offset(icon_name), XtRString, (caddr_t) NULL}, {"termName", "TermName", XtRString, sizeof(char *), offset(term_name), XtRString, (caddr_t) NULL},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -