⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeterm.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International *	This software is quasi-public; it may be used freely with *	like software, but may NOT be sold or made part of licensed *	products without permission of the author. *//* *  EETERM	ELLE Terminal Driver. *	Directly supports DM2500, H-19, Omron 8025AG, Coherent/IBM-PC, TVI925. *	Others also supported if using TX_TERMCAP. */#include "elle.h"/* Define terminal indices (there may be holes but C preprocessor is too * stupid to let us close them).  Should be one TN_ definition for every * hardwired terminal type, even though whether or not it is actually * compiled depends on which TX_ switches are defined. */#define TN_TERMCAP 0#define TN_DM2500 1#define TN_H19	  2#define TN_OM8025 3#define TN_COHIBM 4	/* Coherent IBM-PC console */#define TN_TVI925 5#if TX_COHIBM && !(TX_H19)	/* Ensure H19 defined if COHIBM is. */#define TX_H19 1#endif#ifndef TXS_DEFAULT		/* If no default is explicitly specified */#define TXS_DEFAULT "H19"	/* Then settle for H-19 */#endif /*TXS_DEFAULT*/extern char *tv_stype;	/* If set, specifies terminal type */extern int tibfmsk;	/* Crock to mask off parity (meta) bit */static int tv_padc;	/* Pad character to use */static int tv_cspeed;	/* # msec per char (set from trm_ospeed) */static int tv_type;	/* Index of selected terminal type *//* Internal functions */static void tpadn(), tpad();/* Character speed table, indexed by system output speed value (0-017). * Value in table is 100 * <# msec used per character>. */static int cspdtab[] ={	/* Val    Idx Baud CPS  Time/char in msec */	0,	/*  0 Hangup -	----		*/	13333,	/*  1   50 7.5 133.33  (Baudot)	*/	10000,	/*  2   75  10 100.0   (Baudot)	*/	10000,	/*  3  110  10 100.0		*/	 8200,	/*  4 134.5 12.2 82.0 (IBM2741)	*/	 6666,	/*  5  150  15 	66.6666 	*/	 5000,	/*  6  200  20	50.0		*/	 3333,	/*  7  300  30	33.3333 	*/	 1666,	/*  8  600  60  16.6666 	*/	  833,	/*  9 1200 120   8.3333 	*/	  555,	/* 10 1800 180   5.5555 	*/	  416,	/* 11 2400 240   4.1666 	*/	  208,	/* 12 4800 480   2.0833		*/	  104,	/* 13 9600 960   1.04166	*/	0,	/* 14 Ext A  ?	 ?		*/	0	/* 15 Ext B  ?	 ?		*/};#if TX_TERMCAP/* Declarations for TERMCAP stuff.  Only EETERM knows about them. *//* Termcap routines */extern int tgetent(), tgetnum(), tgetflag(), tputs();extern char *tgetstr(), *tgoto();static int getcap();		/* Internal routines */static void putpad(), putnpad(), putpar();/* Gross disgusting externals that must be defined for TERMCAP rtns */char	PC;		/* Pad char */char	*BC;		/* Backspace to use, if not ^H */char	*UP;		/* Cursor up */short	ospeed;		/* Terminal output speed *//* Termcap numerical values/flags */static int	tc_am,		/* TRUE if has auto-wrap */	tc_km;		/* TRUE if meta key exists *//* Termcap capability strings we want to know about */struct tcap { char tcicod1, tcicod2, *tccap; };static struct tcap tcap[] = {#define TC_al	tcap[0].tccap	/* Add (insert) line */	{'a','l', 0},#define TC_AL	tcap[1].tccap	/* Add N lines */	{'A','L', 0},#define TC_bc	tcap[2].tccap	/* Backspace Char (for BC) */	{'b','c', 0},#define TC_ce	tcap[3].tccap	/* Erase to end of line (CLEOL) */	{'c','e', 0},#define TC_cl	tcap[4].tccap	/* Clear screen */	{'c','l', 0},#define TC_cm	tcap[5].tccap	/* Cursor motion */	{'c','m', 0},#define TC_dc	tcap[6].tccap	/* Delete char */	{'d','c', 0},#define TC_DC	tcap[7].tccap	/* Delete N chars */	{'D','C', 0},#define TC_dl	tcap[8].tccap	/* Delete line */	{'d','l', 0},#define TC_DL	tcap[9].tccap	/* Delete N lines */	{'D','L', 0},#define TC_dm	tcap[10].tccap	/* Delete mode on */	{'d','m', 0},#define TC_ed	tcap[11].tccap	/* Delete mode off */	{'e','d', 0},#define TC_ei	tcap[12].tccap	/* Insert mode off */	{'e','i', 0},#define TC_ia	tcap[13].tccap	/* Add line while in insert mode (see note) */	{'i','a', 0},#define TC_ic	tcap[14].tccap	/* Insert blank char */	{'i','c', 0},#define TC_IC	tcap[15].tccap	/* Insert N blank chars */	{'I','C', 0},#define TC_id	tcap[16].tccap	/* Delete line while in del mode (see note) */	{'i','d', 0},#define TC_im	tcap[17].tccap	/* Insert mode on */	{'i','m', 0},#define TC_ip	tcap[18].tccap	/* Padding to send after char insertion */	{'i','p', 0},#define TC_mm	tcap[19].tccap	/* String to set (turn on) meta-key mode */	{'m','m', 0},#define TC_mo	tcap[20].tccap	/* String to reset (turn off) meta-key mode */	{'m','o', 0},#define TC_pc	tcap[21].tccap	/* Pad Char (for PC) */	{'p','c', 0},#define TC_se	tcap[22].tccap	/* End standout mode */	{'s','e', 0},#define TC_so	tcap[23].tccap	/* Enter standout mode */	{'s','o', 0},#define TC_te	tcap[24].tccap	/* String to end programs that use termcap */	{'t','e', 0},#define TC_ti	tcap[25].tccap	/* String to beg programs that use termcap */	{'t','i', 0},#define TC_up	tcap[26].tccap	/* Move cursor up (for UP) */	{'u','p', 0},#define TC_vb	tcap[27].tccap	/* Visible bell */	{'v','b', 0},};#define NTCAPS ((sizeof(tcap))/(sizeof(struct tcap)))	/* # entries *//* * There are many other things that must be taken into account. * The termcap code here will probably not work for many termcap entries, * but the only sure way to find out which ones they are is to try them. *//* Note that the "ia" and "id" strings are not defined by the TERMCAP doc; * their usage here is derived from examining other TERMCAP-using programs. * Sigh!!!! */#endif /*TX_TERMCAP*//* T_INIT is called once only at program startup, to identify the *	terminal type and set up any one-time things. * T_FATAL is only called if some routine detects an error related to the *	terminal specification, before any initialization is done. *	It prints a short error message and exits the program. * T_ENTER is called after TS_ENTER to set the terminal parameters for *	editing (as opposed to normal typeout).  It may be called *	several times. * T_EXIT is called before TS_EXIT to restore normal typeout modes. *	It is called on exit from the program, and perhaps other times. */t_init(){	char *getenv();	/* Set some default parameters */	scr_ht = 24;	scr_wid = 79;	trm_flags = 0;	tvc_cin = 1;		/* Assume 1 char per char I/D pos */	tvc_cdn = 1;	tvc_pos = 4;		/* Default abs-move cost is 4 chars */	tvc_bs = 1;		/* Default backspace cost is 1 char */	tv_cspeed = cspdtab[trm_ospeed];	/* Find # msec per char */	/* First must determine terminal type, and check for terminals	 * that are hardwired into ELLE. */	if(!tv_stype		/* String set in command line args? */#if !(V6)	 && !(tv_stype = getenv("TERM"))	/* or given by TERM var? */#endif /*-V6*/		) tv_stype = TXS_DEFAULT;	/* No, try using default */	if(0) ;			/* Sigh, stupid construct */#if TX_H19	else if(ustrcmp(tv_stype,"H19")) tv_type = TN_H19;#endif /*TX_H19*/#if TX_OM8025	else if(ustrcmp(tv_stype,"OM8025")) tv_type = TN_OM8025;#endif /*TX_OM8025*/#if TX_DM2500	else if(ustrcmp(tv_stype,"DM2500")) tv_type = TN_DM2500;	else if(ustrcmp(tv_stype,"DM3025")) tv_type = TN_DM2500;#endif /*TX_DM2500*/#if TX_COHIBM	else if(ustrcmp(tv_stype,"COHIBM")) tv_type = TN_COHIBM;#endif /*TX_COHIBM*/#if TX_TVI925	else if(ustrcmp(tv_stype,"TVI925")) tv_type = TN_TVI925;#endif /*TX_TVI925*/#if TX_TERMCAP	/* This should be last thing */	else if(getcap(tv_stype)) tv_type = TN_TERMCAP;#endif /*TX_TERMCAP*/	else t_fatal("type unknown");	/* Ugh, barf and exit */	/* Terminal selected, now initialize parameters for it. */	switch(tv_type)	  {#if TX_DM2500		case TN_DM2500:			tv_padc = 0177;		/* Use rubout for pad */			tvc_pos = 3;		/* Only 3 chars for abs mov */			tvc_ci = 2;		/*	tvc_cin = 1; */		/* Default is OK */			tvc_cd = 2;		/*	tvc_cdn = 1; */		/* Default is OK */			tvc_ld = 2;			tvc_ldn = 1;			tvc_li = 2;			tvc_lin = 1;			if(trm_ospeed == 13)	/* If 9600, */			  {	tvc_cin = 5;		/* Sigh, high cost */				tvc_cdn = 2;				tvc_lin = 18;				tvc_ldn = 2;			  }			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL|TF_METAKEY;			break;#endif /*TX_DM2500*/#if TX_H19		case TN_H19:						trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL;			tvc_ci = 8;		/*	tvc_cin = 1; */	/* default is ok */			tvc_cd = 0;			tvc_cdn = 2;		/*	tvc_ld = 0; */	/* Default is OK */			tvc_ldn = 1 << (trm_ospeed - 7);		/*	tvc_li = 0; */	/* Default is OK */			tvc_lin = tvc_ldn;			break;#endif /*TX_H19*/#if TX_COHIBM		case TN_COHIBM:			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL|TF_METAKEY|TF_DIRVID;			/* Always use lowest possible costs */		/*	tvc_ci = 0; */	/* Default */			tvc_cin = 2;		/*	tvc_cd = 0; */	/* Default */			tvc_cdn = 2;		/*	tvc_ld = 0; */	/* Default */			tvc_ldn = 2;		/*	tvc_li = 0; */	/* Default */			tvc_lin = 2;			break;#endif /*TX_COHIBM*/#if TX_OM8025		case TN_OM8025:			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL;			tvc_pos = 6;		/*	tvc_ci = tvc_cd = 0; */	/* Default */			tvc_cin = 4;			tvc_cdn = 2;		/*	tvc_ld = tvc_li = 0; */	/* Default */			tvc_ldn = 10;		/* Crude approx */			tvc_lin = 10;			if(trm_ospeed > 7)	/* If faster than 300 baud */				trm_flags &= ~TF_IDLIN;	/* Turn off LID */			break;#endif /*TX_OM8025*/#if TX_TVI925		case TN_TVI925:			trm_flags |= TF_IDLIN|TF_IDCHR|TF_CLEOL;			tvc_ci = tvc_cd = tvc_cin = tvc_cdn				= tvc_ldn = tvc_lin = 2;			break;#endif /*TX_TVI925*/	  }	if(tibfmsk < 0)		/* If mask is still default -1, set it. */		tibfmsk = ((trm_flags&TF_METAKEY) ? 0377 : 0177);}/* T_FATAL(str) - prints error message and exits.*/t_fatal(str)char *str;{	writerr("ELLE: \"");	writerr(tv_stype);	writerr("\" terminal ");	writerr(str);	writerr("\n");	exit(1);		/* Terminate with prejudice */}/* T_ENTER is called after TS_ENTER to set the terminal parameters for *	editing (as opposed to normal typeout). *	Standout mode must initially be off. */t_enter(){	switch(tv_type)	  {#if TX_TERMCAP		case TN_TERMCAP:                        putpad(TC_ti);			if(tc_km) putpad(TC_mm);	/* Use meta if poss */#if FX_SOWIND			t_standout(0);		/* Ensure standout mode off */#endif			break;#endif /*TX_TERMCAP*/#if TX_DM2500		case TN_DM2500:			tput(030);	/* Just in case, flush stray modes */			break;#endif /*TX_DM2500*/#if TX_COHIBM		case TN_COHIBM:		/* Note TN_H19 will exist too */#endif /*TX_COHIBM*/#if TX_H19		case TN_H19:			/* Enter ZDS (Heath) mode, then			 * Exit graphics mode (G) Exit ins-char mode (O)			 * exit rev video mode (q) exit hold-screen mode (\)			 * set cursor on (y5)			 */			tputz("\033[?2h\033G\033O\033q\033\\\033y5");			/* Set Discard-at-EOL (w)			 * Set no auto-CR (y9)			 * Enable 25th line (x1)			 */			tputz("\033w\033y9\033x1");			break;#endif /*TX_H19*/	  }}/* T_EXIT - Leave editing modes.  This function should restore**	the terminal's modes to what they were before ELLE was started.**	Standout mode is turned off.*/t_exit(){	switch(tv_type)	  {#if TX_TERMCAP		case TN_TERMCAP:			if(tc_km) putpad(TC_mo);	/* Turn off meta */			putpad(TC_te);			break;#endif /*TX_TERMCAP*/#if TX_DM2500		case TN_DM2500:			tput(035);	/* Turn on roll mode */			break;#endif /*TX_DM2500*/#if TX_COHIBM		case TN_COHIBM:		/* If this exists, TN_H19 will too */#endif /*TX_COHIBM*/#if TX_H19		case TN_H19:			tputz("\033v");		/* Turn EOL-wrap back on */#if DNTTY			tputz("\033<");		/* Return to ANSI mode */#endif /*DNTTY*/			break;#endif /*TX_H19*/	  }}/* T_CLEAR() - Clears the screen and homes the cursor. *	Always valid - ELLE refuses to support terminals without this. */t_clear (){	switch(tv_type)	  {#if TX_TERMCAP		case TN_TERMCAP:			putnpad(TC_cl,scr_ht);			break;#endif /*TX_TERMCAP*/#if TX_DM2500		case TN_DM2500:			tputz("\036\036");	/* Double Master Clear */			break;#endif /*TX_DM2500*/#if TX_COHIBM		case TN_COHIBM:		/* Note TN_H19 will exist too */#endif /*TX_COHIBM*/#if TX_H19		case TN_H19:			tputz("\033E");		/*	tputn(zpadstr,9);	*/			break;#endif /*TX_H19*/#if TX_OM8025		case TN_OM8025:			tputz("\033H\033J");	/* Home then CLEOS */			tpad(1000);		/* One second!!!! */			break;#endif /*TX_OM8025*/#if TX_TVI925		case TN_TVI925:			tput(032);	/* ^Z */			break;#endif /*TX_TVI925*/	  }	curs_lin = curs_col = 0;}/* T_CURPOS(y, x) - Absolute move.  Place cursor in given position *	regardless of where it currently is. *	Updates curs_lin, curs_col. *	Always valid -- ELLE refuses to support terminals without this. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -