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

📄 ecutty.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*+-------------------------------------------------------------------------	restore_initial_colors() - make screen safeOn SCO, restore color choices at execution time if we successfullygot them from the driver; in other situations, use tcap to reset.--------------------------------------------------------------------------*/voidrestore_initial_colors(){#if defined(M_SYSV) || defined(SVR4)	if(use_colors && got_original_colors)		setcolor(colors_initial);	else#endif	{		tcap_blink_off();		tcap_bold_off();		tcap_underscore_off();	}}	/* end of restore_initial_colors *//*+-------------------------------------------------------------------------	get_initial_colors() - read colors at time of execution from driver     00000000001111111111222222222233     01234567890123456789012345678901     0000|--|0000|--|0000|--|0000|--|          fg      bk      fg      bk           reverse      normal--------------------------------------------------------------------------*/#if defined(M_SYSV)voidget_initial_colors(){	uint cur_attr;	ulong fgnd;	ulong bgnd;	colors_initial = colors_normal;	 /* scoterm can use color but ... */	if(ioctl(TTYIN, GIO_ATTR, 0) == -1) /* ... GIO_ATTR won't work */		return;	colors_normal = 0L;/* * first, reverse, so we can end up with normal colors selected */	write(1,"\033[7m",4);		/* select reverse */	cur_attr = (uint)ioctl(TTYIN, GIO_ATTR, 0);	fgnd = (ulong)cur_attr & 0x0F;	bgnd = (ulong) (cur_attr >> 4) & 0x0F;	colors_normal |= (fgnd << 24) | (bgnd << 16);/* * now, normal */	write(1,"\033[m",3);		/* select normal */	cur_attr = (uint)ioctl(TTYIN, GIO_ATTR, 0);	fgnd = (ulong)cur_attr & 0x0F;	bgnd = (ulong) (cur_attr >> 4) & 0x0F;	colors_normal |= (fgnd << 8) | bgnd;	colors_initial = colors_normal;		/* save for restore_initial_colors */	got_original_colors = 1;}	/* end of get_initial_colors */#endif/*+-------------------------------------------------------------------------	read_colors_file() - read color definition if present--------------------------------------------------------------------------*/voidread_colors_file(){	FILE *fp;	char s128[128];#define MAX_COLOR_TOKENS 6	char *tokens[MAX_COLOR_TOKENS];	int ntokens;	char *cptr;	int itmp;	if(tty_not_char_special)		return;#if defined(M_SYSV)	get_initial_colors();#endif	get_home_dir(s128);	strcat(s128,"/.ecu/colors");	if(access(s128,4))		return;	if(!(fp = fopen(s128,"r")))	{		strcpy(s128,eculibdir);		strcat(s128,"/colors");		if(!(fp = fopen(s128,"r")))			return;	}	while(fgets(s128,sizeof(s128),fp))	{		if(s128[0] == '#')			/* comment? */			continue;		if(itmp = strlen(s128))		/* itmp = len; if > 0 ... */		{			itmp--;			s128[itmp] = 0;			/* ... strip trailing NL */		}		cptr = s128;				/* first call to str_token, -> buff */		while((*cptr == 0x20) || (*cptr == TAB))			cptr++;				/* strip leading spaces */		if(*cptr == 0)				/* if line all blank, skip it */			continue;		build_str_array(s128,tokens,MAX_COLOR_TOKENS,&ntokens);		if(ntokens < 2)			continue;		setcolor_internal(ntokens,tokens);	}			/* while records left to ready */#if defined(M_SYSV)	if(ioctl(TTYIN, GIO_ATTR, 0) == -1)		colors_initial = colors_normal; /* hack for scoterm */#endif	fclose(fp);}	/* end of read_colors_file *//*+-------------------------------------------------------------------------	ring_bell()--------------------------------------------------------------------------*/voidring_bell(){	char b = BEL;	if(tty_not_char_special)		return;	write(TTYOUT,&b,1);}	/* end of ring_bell *//*+-------------------------------------------------------------------------	termio_to_kbd_chars()--------------------------------------------------------------------------*/voidtermio_to_kbd_chars(){	kbdintr =  (tty_termio_at_entry.c_cc[VINTR])		? (tty_termio_at_entry.c_cc[VINTR]  & 0x7F) : '\377';	kbdquit =  (tty_termio_at_entry.c_cc[VQUIT])		? (tty_termio_at_entry.c_cc[VQUIT]  & 0x7F) : '\377';	kbderase = (tty_termio_at_entry.c_cc[VERASE])		? (tty_termio_at_entry.c_cc[VERASE] & 0x7F) : '\377';	kbdkill =  (tty_termio_at_entry.c_cc[VKILL])		? (tty_termio_at_entry.c_cc[VKILL]  & 0x7F) : '\377';	kbdeof =   (tty_termio_at_entry.c_cc[VEOF])		? (tty_termio_at_entry.c_cc[VEOF]   & 0x7F) : '\04';	kbdeol2 =  (tty_termio_at_entry.c_cc[VEOL])		? (tty_termio_at_entry.c_cc[VEOL]   & 0x7F) : '\377';	kbdeol =   (tty_termio_at_entry.c_iflag & ICRNL)		? '\r' : '\n';	kbd_is_7bit = ((tty_termio_at_entry.c_cflag & PARENB) != 0);	echo_erase_char = tty_termio_at_entry.c_lflag & ECHOE;	echo_kill_char = tty_termio_at_entry.c_lflag & ECHOK;}	/* end of termio_to_kbd_chars *//*+-------------------------------------------------------------------------	ttyinit(param)--------------------------------------------------------------------------*/voidttyinit(param)uchar param;{	int fddevtty;	int itmp;	char *ftype;#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)	int monitor_type;	int cons_get_err;#endif	ttype = getenv("TERM");	/* must do this first */	/*	 * get control tty control chars in case stdin not tty	 */	if((fddevtty = open("/dev/tty",O_RDONLY,0)) >= 0)	{		ioctl(fddevtty,TCGETA,(char *)&tty_termio_at_entry);		close(fddevtty);		termio_to_kbd_chars();	}	sigint = 0;			/* see xmtr signal handlers */	memset((char *)&tty_stat,0xFF,sizeof(struct stat));	memset((char *)&ttyp0,0xFF,sizeof(struct stat));	memset((char *)&console,0xFF,sizeof(struct stat));	stat("/dev/console",&console);	stat("/dev/null",&dn);	stat("/dev/tty01",&tty01);	stat("/dev/ttyp0",&ttyp0);	/*	 * if stdin not open or is /dev/null or is non-character-device	 */	itmp = fstat(TTYIN,&tty_stat);	if(itmp || ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||		((dn.st_ino == tty_stat.st_ino) && (dn.st_rdev == tty_stat.st_rdev)))	{		tcap_LINES = LINES = 25;	/* fake necessary termcap/curses vars */		tcap_COLS = COLS = 80;		LINESxCOLS = tcap_LINES * tcap_COLS;		shm->scr_lines = tcap_LINES;		shm->scr_cols = tcap_COLS;		shm->scr_size = LINESxCOLS;		tty_not_char_special = 1;		tty_is_multiscreen = 0;		return;	}	/*	 * if pty	 */	if((tty_stat.st_rdev & 0xFF00) == (ttyp0.st_rdev & 0xFF00))		tty_is_pty = 1;	/*	 * use color if we are on a display that supports it and we know how :-|	 */	use_colors = 0;#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)	if( ((cons_get_err = ioctl(TTYIN,CONS_GET,&monitor_type)) >= 0) &&		(use_colors = (monitor_type != MONO)))	{		read_colors_file();		setcolor(colors_normal);	}#endif /* CONS_GET && MONO && USE_COLOR */	/*	 * remember whether or not we are on a multiscreen	 */#if defined(M_SYSV) /* for multiscreen and scoterm */	tty_is_multiscreen = !(cons_get_err < 0);	/*	 * a fuzzy heuristic for scoterm:	 * 1. presence of WINDOWID and	 * 2. first four characters of $TERM == "ansi"	 */	if(getenv("WINDOWID") && ttype && !strncmp(ttype,"ansi",4))	{		use_colors = 1;		tty_is_scoterm = 1;		read_colors_file();		setcolor(colors_normal);	}#endif /* M_SYSV multiscreen and scoterm */	/*	 * save initial tty state	 */	ioctl(TTYIN,TCGETA,(char *)&tty_termio_at_entry);	tty_escape_timeout =		B_to_timeout_msec(tty_termio_at_entry.c_cflag,tty_stat.st_rdev);	termio_to_kbd_chars();	tty_termio_current = tty_termio_at_entry;	current_ttymode = 0;	get_home_dir(screen_dump_file_name);	strcat(screen_dump_file_name,"/.ecu/screen.dump");	ftype = 0;	if(dash_f_funckeytype)		ftype =	dash_f_funckeytype;	else		ftype = getenv("ECUFUNCKEY");	if(ttype || ftype)		funckeymap_read((ftype) ? ftype : ttype);	/* initialize termcap */	tcap_init();			/* read termcap strings */	/* yetch - magic number gretching for lines and columns */	if(tcap_LINES < 20)	{		ff(se,"\7screen height must be >= 20 lines (found %dx%d).\r\n",			tcap_COLS,tcap_LINES);		termecu(TERMECU_GEOMETRY);	}	if(tcap_LINES > SCREEN_LINES_MAX)	{		ff(se,"\7screen height limited to %d lines (found %dx%d).\r\n",			SCREEN_LINES_MAX,tcap_COLS,tcap_LINES);		termecu(TERMECU_GEOMETRY);	}	if(tcap_COLS != SCREEN_COLS_MAX)	{		ff(se,"\7terminal width must be %d columns (found %dx%d).\r\n",			SCREEN_COLS_MAX,tcap_COLS,tcap_LINES);		termecu(TERMECU_GEOMETRY);	}	LINESxCOLS = tcap_LINES * tcap_COLS;	shm->scr_lines = tcap_LINES;	shm->scr_cols = tcap_COLS;	shm->scr_size = LINESxCOLS;	ttyinit_has_been_called = 1;}	/* end of ttyinit *//*+-----------------------------------------------------------------------	ttymode(arg) -- control user console (kbd/screen)  Where arg ==	0 restore attributes saved at start of execution	1 raw mode (send xon/xoff, but do not respond to it, no ISIG/SIGINT)	2 raw mode (same as 1 but allow keyboard interrupts)	3 same as 2 but terminate program on SIGINT    4 terminate ecu on sigint------------------------------------------------------------------------*/voidttymode(arg)int arg;{	/*	 * ignore if no keyboard involved	 */	if(tty_not_char_special)		return;	/*	 * usage()->termecu()->ttymode() is possible before ttyinit()	 */	if(!ttyinit_has_been_called)		return;	switch(arg)	{	case 0:		ioctl(TTYIN,TCSETAW,(char *)&tty_termio_at_entry);		tty_termio_current = tty_termio_at_entry;		current_ttymode = 0;		break;	case 4:		ttymode_termecu_on_sigint = 1;		/* fall thru */	case 1:	case 2:	case 3:		tty_termio_current = tty_termio_at_entry;		tty_termio_current.c_cflag &= ~(PARENB | PARODD);		tty_termio_current.c_cflag |= CS8;		/* don't want to honor tty xon/xoff, but pass to other end */		tty_termio_current.c_iflag &=			~(INLCR | ICRNL | IGNCR | IUCLC | ISTRIP);		if(tty_use_kbd_sw_flow_control)			tty_termio_current.c_iflag |= IXON | IXOFF;		else			tty_termio_current.c_iflag &= ~(IXON | IXOFF);		tty_termio_current.c_oflag |= OPOST;		tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);		tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);		if(arg > 1)			tty_termio_current.c_lflag |= ISIG;		tty_termio_current.c_cc[VMIN] = 1;		tty_termio_current.c_cc[VTIME] = 0;		ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);		current_ttymode = arg;		break;	default:		ff(se,"\r\nttymode: invalid argument %d\r\n",arg);		break;	}}	/* end of ttymode *//*+-------------------------------------------------------------------------	int	get_ttymode()--------------------------------------------------------------------------*/intget_ttymode(){	return(current_ttymode);}	/* end of get_ttymode *//*+-----------------------------------------------------------------------	ttyflush(flush_type) -- flush tty driver input &/or output buffers0 == input buffer1 == output buffer2 == both buffers------------------------------------------------------------------------*/voidttyflush(flush_type)int flush_type;{	if(tty_not_char_special)		return;	ioctl(TTYIN,TCXONC,(char *)0); /* stop tty output */#if !defined(M_I286)	ioctl(TTYIN,TCFLSH,(char *)flush_type);#else	/* avoid 286 compiler warning of cast int to far ptr */	switch(flush_type)	{		case 0:			ioctl(TTYIN,TCFLSH,(char *)0); break;		case 1:			ioctl(TTYIN,TCFLSH,(char *)1); break;		case 2:			ioctl(TTYIN,TCFLSH,(char *)2); break;	}#endif	ioctl(TTYIN,TCXONC,(char *)1);	/* restart tty output */	if(flush_type != 1)	{		dole_out_tgc_accum = (uchar *)0;		dole_out_tgc_accum_count = 0;	}}	/* end of ttyflush *//*+-------------------------------------------------------------------------	ttyrdchk() - see if key pressed and not read--------------------------------------------------------------------------*/intttyrdchk(){	return(rdchk(TTYIN) || dole_out_tgc_accum_count);}	/* end of ttyrdchk *//*+-------------------------------------------------------------------------	ttygetc(xkey_ok) -- get a key from the keyboardif UNIX or XENIX, map extended keys to sign-bit-set special valueif xkey_ok is 0, disallow extended keys--------------------------------------------------------------------------*/uintttygetc(xkey_ok)int xkey_ok;{	uchar ctmp;	extern int errno;	register uint itmp = 0;	long timeout_remaining;	static uchar tgc_accum[16];	uchar funckeymap();	if(tty_not_char_special)	/* this really is unexplored territory */	{		ctmp = 255;		read(TTYIN,(char *)&ctmp,1);		return((uint)ctmp);	}	if(dole_out_tgc_accum_count)	{		ctmp = *dole_out_tgc_accum++;		dole_out_tgc_accum_count--;		if(kbd_is_7bit)			ctmp &= 0x7F;		return((uint)ctmp);	}GET_KEY:

⌨️ 快捷键说明

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