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

📄 ecutty.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef USE_COLOR#   ifdef M_SYSV			/* SCO family */#	   define USE_COLOR#   endif#   ifdef ISC				/* not yet */#   endif#   ifdef sun				/* not yet */#   endif#   ifdef ISCSVR4			/* last I heard from lothar, this worked */#	   define USE_COLOR#   endif#   ifdef ESIXSVR4			/* I heard this does not work */#   endif#endif /* USE_COLOR *//*+-------------------------------------------------------------------------	ecutty.c - local tty (console) functions	wht@n4hgf.Mt-Park.GA.US  Defined functions:	B_to_timeout_msec(c_cflag,st_rdev)	_setcolor(clrs)	color_name_to_num(cname)	get_initial_colors()	get_ttymode()	get_ttyname()	kbd_test()	read_colors_file()	restore_initial_colors()	ring_bell()	setcolor(new_colors)	setcolor_internal(ntokens,tokens)	termio_to_kbd_chars()	ttyflush(flush_type)	ttygetc(xkey_ok)	ttygets(str,maxsize,flags,delim,pstrpos)	ttygets(str,maxsize,flags,delim,pstrpos)	ttygets_esd(tesd,flags,append_flag)	ttyinit(param)	ttymode(arg)	ttyrdchk()    In SCO versions, ECU keeps the the state of the normal and    reverse video foreground and background colors in a 32-bit value:     00000000001111111111222222222233     01234567890123456789012345678901     0000|--|0000|--|0000|--|0000|--|          fg      bk      fg      bk           reverse      normal    The color values are per the SCO extended color definitons:    black    0     gray         8    blue     1     lt_blue      9    green    2     lt_green    10    cyan     3     lt_cyan     11    red      4     lt_red      12    magenta  5     lt_magenta  13    brown    6     yellow      14    white    7     hi_white    15    With Lothar's ISC SVR4, the format is     00000000001111111111222222222233     01234567890123456789012345678901     00000000000000000011????0100????       0   0   0   0   3   f   4  o b    where f is the foreground color    and   b is the background color    (I dont have one, so I'm guessing these colors are chosen from    the ISO colors):     BLACK       0     RED         1     GREEN       2     YELLOW      3     BLUE        4     MAGENTA     5     CYAN        6     WHITE       7--------------------------------------------------------------------------*//*+:EDITS:*//*:10-18-1992-14:26-wht@n4hgf-add console xon/xoff control *//*:10-08-1992-01:12-wht@n4hgf-no more obsolete Metro Link PTS *//*:10-08-1992-01:06-wht@n4hgf-SVR4 color work + !use_color normal fix *//*:09-15-1992-18:52-wht@n4hgf-left some debug code in patch01 dammit *//*:09-13-1992-12:52-wht@n4hgf-add tty_is_scoterm *//*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 *//*:08-30-1992-07:42-wht@n4hgf-implement USE_COLOR+turn off ESIX color for now *//*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA *//*:08-16-1992-03:43-wht@n4hgf-add -F funckeytype *//*:06-20-1992-21:13-wht@n4hgf-eculibdir was overwritten if no home dir colors *//*:06-16-1992-11:20-wht@n4hgf-ECUFUNCKEY *//*:05-05-1992-17:42-wht@n4hgf-repair underscore always on on sun *//*:04-24-1992-16:55-wht@n4hgf-dont flunk on >43 lines but use only 43 *//*:04-20-1992-20:31-wht@n4hgf-ttymode now no-op until ttyinit called *//*:04-20-1992-19:42-wht@n4hgf-kbdtest code in ttygetc messed up-str too short *//*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 *//*:04-19-1992-02:00-wht@n4hgf-if TERM=ansi with WINDOWID, assume scoterm *//*:08-31-1991-13:29-wht@n4hgf2-look for colors in ECULIBDIR too *//*:08-30-1991-04:12-wht@n4hgf2-restore colors wrong to do now if not SCO *//*:08-30-1991-02:49-aega84!lh-use at_ansi.h/kd.h/CONS_GET under ISC SVR4 *//*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh *//*:08-17-1991-18:29-wht@n4hgf-add kbdtest command *//*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 *//*:07-14-1991-18:18-wht@n4hgf-new ttygets functions *//*:07-10-1991-16:19-wht@n4hgf-improve multi-char func key read timeout *//*:03-20-1991-03:07-root@n4hgf-pts driver returns -1 on rdchk success! *//*:03-19-1991-21:24-root@n4hgf-METROLINK_X11R4_PTS mods *//*:01-29-1991-14:03-wht@n4hgf-more time for ESC vs fkey discrimination *//*:01-29-1991-13:44-wht@n4hgf-load colors_normal w/ioctl GIO_ATTR if M_UNIX *//*:12-01-1990-14:33-wht@n4hgf-more non-ansi - fkey mapping with nonansi.c *//*:11-28-1990-15:56-wht@n4hgf-add non-ansi terminal support *//*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */#include "ecu.h"#include "esd.h"#include "ecufkey.h"#include "ecukey.h"#include "ecuxkey.h"#include "ecuerror.h"#include "termecu.h"/* * This is how we determine whether we are on a color terminal or not. * We handle SCO XENIX, SCO UNIX, ISC 2.2 and ISC SVR4. * If you have trouble with this add some kind of thing instead of MYSYS * and mail me the full details.  Search for MYSYS throughout here. */#if defined(M_SYSV)#   include <sys/machdep.h>/* * Thanks for the G2, er GIO_ATTR, to staceyc@sco.COM (Stacey Campbell) * GIO_ATTR was not defined in header files as of this writing */#if !defined(GIO_ATTR)#define GIO_ATTR  ('a' << 8) | 0	/* Ioctl call for current attribute */#endif#else#if defined(ISC) || defined(ISCSVR4) || defined(ESIXSVR4) /*&&!defined(MYSYS)*/#  include <sys/at_ansi.h>#  include <sys/kd.h>#endif /* ISC || ISCSVR4 || ESIXSVR4 */#endif /* M_SYSV */#define DEFINE_TTY_DATA#include "ecutty.h"extern uint tcap_LINES;extern uint tcap_COLS;extern int LINES;extern int COLS;extern char screen_dump_file_name[];extern char *dash_f_funckeytype;char *kde_text();uint LINESxCOLS;int current_ttymode = 0;int ttymode_termecu_on_sigint = 0;int tty_is_pty;int tty_is_multiscreen;int tty_is_scoterm;int tty_not_char_special;int tty_use_kbd_sw_flow_control = 1;int use_colors = 0;		/* set by ttyinit, but default no */char *ttype;			/* getenv("TERM") */static int kbd_test_active = 0;static int ttyinit_has_been_called = 0;static int got_original_colors = 0;struct termio tty_termio_at_entry;struct termio tty_termio_current;struct stat tty_stat;struct stat dn;struct stat tty01;struct stat ttyp0;struct stat console;uchar kbdeof;			/* current input EOF */uchar kbdeol2;			/* current secondary input EOL */uchar kbdeol;			/* current input EOL */uchar kbderase;			/* current input ERASE */uchar kbdintr;			/* current input INTR */uchar kbdkill;			/* current input KILL */uchar kbdquit;			/* current input QUIT */int echo_erase_char;	/* save users ECHOE bit */int echo_kill_char;		/* save users ECHOK bit */char kbd_is_7bit;		/* keyboard has parity */long tty_escape_timeout = 40L;		/* timeout on waiting for char after ESC */uchar *dole_out_tgc_accum = (uchar *)0;int dole_out_tgc_accum_count = 0;/* * color definitions per format described at top of source * we handle SCO XENIX and UNIX and ISC SVR4 but not "MYSYS" * (search for MYSYS near top of source for clue what MYSYS means) * * As of this writing, I don't know about colors on ISC 2.2. * but they might be the same as for SVR4. * */#ifdef M_SYSV /* SCO */ulong colors_initial = 0x04070A00L;	/* default initial colors */ulong colors_current = 0x04070A00L; /* colors set during execution */ulong colors_normal  = 0x04070A00L;	/* default lt_green/black red/white */ulong colors_success = 0x07000A00L;	/* lt_green/black red/white */ulong colors_alert   = 0x0E000E00L;	/* yellow */ulong colors_error   = 0x04000400L;	/* red */ulong colors_notify  = 0x08000800L;	/* gray */#define COLORS_DEFINED#endif /* M_SYSV */#if defined(ISCSVR4)ulong colors_initial = 0x00003740L;ulong colors_current = 0x00003740L;ulong colors_normal  = 0x00003740L;	/* white */ulong colors_success = 0x00003240L;	/* green */ulong colors_alert   = 0x00003340L;	/* yellow */ulong colors_error   = 0x00003140L;	/* red  */ulong colors_notify  = 0x00003640L;	/* cyan */#define COLORS_DEFINED#endif /* ISCSVR4 */#if defined(ESIXSVR4)ulong colors_initial = 0x00003740L;ulong colors_current = 0x00003740L;ulong colors_normal  = 0x00003740L;	/* ? */ulong colors_success = 0x00003240L;	/* ? */ulong colors_alert   = 0x00003340L;	/* ? */ulong colors_error   = 0x00003140L;	/* ? */ulong colors_notify  = 0x00003640L;	/* ? */#define COLORS_DEFINEDstatic struct color_remapping {  char *name;  char ecu_val;  char svr4_val;} color_remapping[] =  {	{ "black",		0,		0x00 },	{ "blue",		1,		0x04 },	{ "brown",		6,		0x03 },	{ "cyan",		3,		0x06 },	{ "gray",		8,		0x10 },	{ "green",		2,		0x02 },	{ "hi_white",	15,		0x17 },	{ "lt_blue",	9,		0x14 },	{ "lt_cyan",	11,		0x16 },	{ "lt_green",	10,		0x12 },	{ "lt_magenta",	13,		0x15 },	{ "lt_red",		12,		0x11 },	{ "magenta",	5,		0x05 },	{ "red",		4,		0x01 },	{ "white",		7,		0x07 },	{ "yellow",		14,		0x13 },	0, 0, 0,};#endif /* ESIXSVR4 */#if !defined(COLORS_DEFINED)ulong colors_current = 1; /* dummy */ulong colors_normal = 2; /* dummy */ulong colors_initial = 3; /* dummy */ulong colors_success = 4; /* dummy */ulong colors_alert = 5; /* dummy */ulong colors_error = 6; /* dummy */ulong colors_notify = 7; /* dummy */#define COLORS_DEFINED#endif /* !COLORS_DEFINED *//*+-------------------------------------------------------------------------	B_to_timeout_msec(c_cflag,st_rdev) - CBAUD code to ESC timeout msec--------------------------------------------------------------------------*//*ARGSUSED*/ulongB_to_timeout_msec(c_cflag,st_rdev)ushort c_cflag;ushort st_rdev;{	long ms = 300L;	/* make network/xterm/pty sweat, but don't make as many mistakes */	if(tty_is_pty)		return(ms);	/* if multiscreen, 3 ticks is pu-lenty */	if(tty_is_multiscreen)		return((long)(1000/hz * 3));	/* baud rate fiddling */	switch(c_cflag & CBAUD)	{		/*       char times * time/char */		case B110:	ms = 10 * 100;		case B300:	ms = 10 * 33;		case B600:	ms = 10 * 16;		case B1200:	ms = 10 * 8;		case B2400:	ms = 10 * 4;		default:		/* many character times for packetized ... */			ms = 400L;	/* ... modems used for console */	}	return(ms);}	/* end of B_to_timeout_msec *//*+-------------------------------------------------------------------------	color_name_to_num(cname)--------------------------------------------------------------------------*/intcolor_name_to_num(cname)char *cname;{	register COLOR *color = colors;	register itmp;	while(color->name)	{		if((itmp = strcmp(color->name,cname)) > 0)			return(-1);		if(!itmp)			return(color->num);		color++;	}	return(-1);}	/* end of color_name_to_num *//*+-------------------------------------------------------------------------	_setcolor(clrs)--------------------------------------------------------------------------*/void_setcolor(clrs)ulong clrs;{#if defined(SVR4)#if defined(ESIXSVR4)	struct color_remapping *cr;	char fgcolor;	char bgcolor;#else	char fg[4], bg[4];#endif#endif	if(!use_colors || tty_not_char_special)		return;#if defined(SVR4)#if defined(ESIXSVR4)	/* set foreground color */	fgcolor = (clrs >> 8) & 0xff;	for (cr=color_remapping; cr->name; ++cr) {	  if (fgcolor == cr->ecu_val) {		fgcolor = cr->svr4_val;		break;	  }	}	if (!cr->name) {	  fgcolor = 0x07; /* white */	}	if (fgcolor & 0x10) {	  fgcolor &= ~0x10;	  ff(se, "\033[1;3%d;m", fgcolor);	} else {	  ff(se, "\033[0;3%d;m", fgcolor);	}	/* set background color */	bgcolor = clrs & 0xff;	for (cr=color_remapping; cr->name; ++cr) {	  if (bgcolor == cr->ecu_val) {		bgcolor = cr->svr4_val;		break;	  }	}	if (!cr->name) {	  bgcolor = 0x00; /* black */	}	if (bgcolor & 0x10) {	  bgcolor &= ~0x10;	  ff(se, "\033[5;3%d;m", bgcolor);	} else {	  ff(se, "\033[0;3%d;m", bgcolor);	}#else	/* ISC SVR4 */	/* normal */	sprintf(fg,"%d", (clrs >> 8) & 0xFF);	sprintf(bg,"%d", clrs & 0xFF);	ff(se,"\033[%sm", fg);	ff(se,"\033[%sm", bg);#endif	/* ESIXSVR4 */#else	/* not any SVR4 */#ifdef M_SYSV /* SCO */	/* normal */	ff(se,"\033[=%ldF\033[=%ldG",(clrs >> 8) & 0xFF,clrs & 0xFF);	/* reverse */	ff(se,"\033[=%ldH\033[=%ldI",(clrs >> 24) & 0xFF,(clrs >> 16) & 0xFF);#endif /* M_SYSV */#endif /* SVR4 */	colors_current = clrs;}	/* end of _setcolor *//*+-------------------------------------------------------------------------	setcolor(new_colors)requires termcap init to have been done--------------------------------------------------------------------------*/voidsetcolor(new_colors)ulong new_colors;{	if(tty_not_char_special)		return;	if(!use_colors)	{		if(new_colors == colors_notify)			tcap_underscore_on();		else if(new_colors == colors_alert)			tcap_bold_on();		else if(new_colors == colors_error)			tcap_stand_out();		else		{			tcap_underscore_off();			tcap_bold_off();			tcap_stand_end();		}		return;	}	_setcolor(new_colors);	tcap_stand_end();}	/* end of setcolor *//*+-------------------------------------------------------------------------	setcolor_internal(ntokens,tokens)returns 0 on success, else token number in error + 1--------------------------------------------------------------------------*/intsetcolor_internal(ntokens,tokens)int ntokens;char **tokens;{	ulong fgnd;	ulong bgnd;	if(tty_not_char_special || !use_colors)		return(0);	if(ntokens < 2)		return(1);	else if(ntokens == 2)		tokens[2] = "black";	if((fgnd = (ulong)color_name_to_num(tokens[1])) > 15)		return(2);	if((bgnd = (ulong)color_name_to_num(tokens[2])) > 15) 		return(3);	if(!strcmp(tokens[0],"normal"))	{		colors_normal &= 0xFFFF0000L;		colors_normal |= (fgnd << 8) | bgnd;		setcolor(colors_normal);	}	else if(!strcmp(tokens[0],"reverse"))	{		colors_normal &= 0x0000FFFFL;		colors_normal |= (fgnd << 24) | (bgnd << 16);		setcolor(colors_normal);	}	else if(!strcmp(tokens[0],"notify"))		colors_notify = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;	else if(!strcmp(tokens[0],"success"))		colors_success = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;	else if(!strcmp(tokens[0],"alert"))		colors_alert = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;	else if(!strcmp(tokens[0],"error"))		colors_error = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;	else		return(1);	return(0);}	/* end of setcolor_internal */

⌨️ 快捷键说明

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