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

📄 ecutty.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	errno = 0;	if(read(TTYIN,(char *)&ctmp,1) < 0)	{		if(errno == EINTR)			goto GET_KEY;		perror_errmsg("keyboard");		termecu(TERMECU_TTYIN_READ_ERROR);	}	if(	((ctmp >= 0x01) && (ctmp <= 0x1F) ||		 (ctmp >= 0x81) && (ctmp <= 0x9F)) &&		(ctmp != kbderase) && (ctmp != kbdkill) &&		(ctmp != kbdeol) && (ctmp != kbdeol2) &&		(ctmp != kbdintr) && (ctmp != kbdeof) )	{		tgc_accum[0] = ctmp;		tgc_accum[itmp = 1] = 0;		timeout_remaining = tty_escape_timeout;#if defined(NAP_DEBUG)		ff(se,"timeout_remaining = %ld hzmsec=%ld\r\n",			timeout_remaining,hzmsec);#endif		while(((ctmp = funckeymap(tgc_accum,itmp)) >= XF_no_way) &&			(timeout_remaining > 0))		{			timeout_remaining -= Nap(hzmsec);#if defined(NAP_DEBUG)			ff(se,"timeout_remaining = %ld\r\n",timeout_remaining);#endif			if(!rdchk(TTYIN))				continue;			read(TTYIN,(char *)&ctmp,1);			if(itmp == (sizeof(tgc_accum) - 1))	/* do not allow overflow */			{				ctmp = XF_no_way;				break;			}			timeout_remaining = tty_escape_timeout;			tgc_accum[itmp++] = ctmp;		}		tgc_accum[itmp] = 0;		if((ctmp == XF_not_yet) && (itmp == 1))		{			if(kbd_is_7bit)				tgc_accum[0] &= 0x7F;			return((uint)tgc_accum[0]);		}		else if(ctmp < XF_no_way)	/* if we got a map */		{			if(kbd_test_active)			{				char title[128];				sprintf(title,"--> func key '%s' (%d key codes received)",					kde_text(ctmp),itmp);				hex_dump(tgc_accum,-itmp,title,1);			}			if(!xkey_ok)			{				ring_bell();				goto GET_KEY;			}			switch(ctmp)			{				case IKDE_CU5:					screen_dump(screen_dump_file_name);					goto GET_KEY;				default:					return((uint)ikde_to_xf(ctmp));			}			/*NOTREACHED*/		}		/* not func key -- must be typamatic control key */		if(kbd_test_active)		{			char title[128];			if(itmp > 1)			{				sprintf(title,					"--> no func key recognized (%d key codes received)",itmp);				hex_dump(tgc_accum,-itmp,title,1);			}		}		dole_out_tgc_accum_count = itmp - 1;		dole_out_tgc_accum = tgc_accum + 1;		if(kbd_is_7bit)			tgc_accum[0] &= 0x7F;		return((uint)tgc_accum[0]);	}	/*	 * simple key, not special	 */	if(kbd_is_7bit)		ctmp &= 0x7F;	return((uint)ctmp);}	/* end if ttygetc *//*+-----------------------------------------------------------------------	ttygets(str,maxsize,flags,delim,pstrpos)flags & TG_CRLF   - echo cr/lf terminatorflags & TG_XDELIM - extended delimiter set                    (Home, End, PgUp, PgDn, CurUp, CurDn)flags & TG_EDIT   - redisplay/edit current stringflags & TG_IPOS   - if edit, use initial string pos------------------------------------------------------------------------*/voidttygets(str,maxsize,flags,delim,pstrpos)register char *str;int maxsize;int flags;uchar *delim;int *pstrpos;{	register inch;	char ch;	register strcount = 0;	register strpos = 0;	int insert_mode = 0;	char *bs_str = "\010 \010";	extern int rcvrdisp_actual2_xmtr_buffer;	rcvrdisp_actual2_xmtr_buffer = 1; /* let tcap_ rtns buffer */	--maxsize;		/* decrement for safety */	if(flags & TG_EDIT)	{		strpos = strcount = strlen(str);		write(TTYOUT,str,strcount);		if(pstrpos && (*pstrpos > 0) && (*pstrpos <= strcount))			strpos = *pstrpos;		tcap_curleft(strcount - strpos);	}	while(1)	{		rcvrdisp_actual2_xmtr_buffer = 0; /* disallow tcap_ rtns buffer */		rcvrdisp_actual2_xmtr_buffer = 1; /* let tcap_ rtns buffer */		inch = ttygetc(1);		*delim = (uchar)inch;	/* last char will always be the delimiter */		if((inch == kbdintr) || (inch == ESC))		{			tcap_curright(strcount - strpos);			while(strcount)			{				write(TTYOUT,bs_str,strlen(bs_str));				strcount--;			}			str[strcount] = 0;			*delim = ESC;			goto RETURN;		}		else if(inch == kbdkill)		{			tcap_curright(strcount - strpos);			while(strcount)			{				write(TTYOUT,bs_str,strlen(bs_str));				strcount--;			}			strpos = 0;			*str = 0;			continue;		}		else if(inch == kbderase)		{			if(strcount)			{				if(strcount == strpos)				{					write(TTYOUT,bs_str,strlen(bs_str));					strcount--,strpos--;				}				else				{					if(!strpos)						continue;					mem_cpy(str + strpos - 1,str + strpos,strcount - strpos);					write(TTYOUT,"\010",1);					str[--strcount] = 0;					strpos--;					write(TTYOUT,str + strpos,strlen(str + strpos));					write(TTYOUT," ",1);					tcap_curleft(strcount - strpos + 1);				}			}			str[strcount] = 0;			continue;		}		else if(inch == XFins)		{			insert_mode = !insert_mode;			continue;		}		else if(inch == XFcurlf)		{			if(strpos)			{				strpos--;				tcap_curleft(1);			}			continue;		}		else if(inch == XFcurrt)		{			if(strpos < strcount)			{				strpos++;				tcap_curright(1);			}			continue;		}		if(flags & TG_XDELIM)	/* extended delimiter */		{			switch(inch)			{				case XFhome:				case XFend:				case XFpgup:				case XFpgdn:				case XFcurup:				case XFcurdn:#ifdef notdef					tcap_curright(strcount - strpos);					while(strcount)					{						write(TTYOUT,bs_str,strlen(bs_str));						strcount--;					}#endif					str[strcount] = 0;					goto RETURN;			}		}		switch(inch)		{			case CRET:				*delim = NL;			case NL:				str[strcount] = 0;				tcap_curright(strcount - strpos);				if((flags & TG_CRLF))					ff(se,"\r\n");				goto RETURN;			case CTL_L:			case CTL_R:				tcap_curright(strcount - strpos);				ff(se,"%s (insert mode %s)\r\n",make_char_graphic(inch,0),					(insert_mode) ? "ON" : "OFF");				tcap_eeol();				write(TTYOUT,str,strcount);				tcap_curleft(strcount - strpos);				break;			default:				if((inch < SPACE) || (inch >= 0x7F))				{					ring_bell();					break;				}				if(strpos == strcount)				{					if(strcount == maxsize)					{						ring_bell();						continue;					}					str[strcount++] = inch;					strpos++;					ch = (char)inch;					write(TTYOUT,&ch,1);				}				else				{					if(insert_mode)					{						if(strcount == maxsize)						{							ring_bell();							continue;						}						mem_cpy(str+strpos+1,str+strpos,strcount-strpos);						str[strpos] = inch;						strcount++;						str[strcount] = 0;						write(TTYOUT,str + strpos,strcount - strpos);						strpos++;						tcap_curleft(strcount - strpos);					}					else					{						str[strpos++] = inch;						ch = (char)inch;						write(TTYOUT,&ch,1);					}				}				str[strcount] = 0;				continue;		}	}RETURN:	rcvrdisp_actual2_xmtr_buffer = 0; /* disallow tcap_ rtns buffer */	if(pstrpos)		*pstrpos = strpos;}	/* end of ttygets() *//*+-------------------------------------------------------------------------	ttygets_esd(tesd,flags,append_flag)--------------------------------------------------------------------------*/ttygets_esd(tesd,flags,append_flag)ESD *tesd;int flags;int append_flag;{	char *pb = tesd->pb;	int maxcb = tesd->maxcb;	uchar delim;	if(append_flag)	{		pb += tesd->cb;		maxcb -= tesd->cb;	}	else	{		pb = tesd->pb;		maxcb = tesd->maxcb;		tesd->cb = 0;	}	ttygets(pb,maxcb,flags,&delim,(int *)0);	if(delim == ESC)	{		if(!append_flag)			esdzero(tesd);		return(eProcAttn_ESCAPE);	}	tesd->cb = strlen(tesd->pb);	plogs(pb);	if(flags & 1)		plogc(NL);	return(0);}	/* end of ttygets_esd *//*+-------------------------------------------------------------------------	kbd_test() - test keyboard handler--------------------------------------------------------------------------*/voidkbd_test(){	uint ctmp = 0;	pputs("Press keys to test (ESCape to exit)\n");	kbd_test_active = 1;	while(ctmp != ESC)	{		ctmp = ttygetc(1);				if((ctmp < 0x80) && dole_out_tgc_accum_count)		{			pprintf("    got %d key sequence %s ",				dole_out_tgc_accum_count + 1,hex_to_ascii_name(ctmp));			while(dole_out_tgc_accum_count)			{				pprintf("%s ",hex_to_ascii_name(*dole_out_tgc_accum++));				dole_out_tgc_accum_count--;			}			pputs("\n");			ctmp = 0;			continue;		}		pputs("    got ");		if(ctmp >= 0x80)			pprintf("fkey '%s'\n",xf_text(ctmp));		else			pprintf("key  '%s'\n",hex_to_ascii_name(ctmp));	}	kbd_test_active = 0;	ttyflush(0);	pputs("keyboard test complete\n\n");	dole_out_tgc_accum = (uchar *)0;	dole_out_tgc_accum_count = 0;	}	/* end of kbd_test *//*+-------------------------------------------------------------------------	char *get_ttyname() - return pointer to static stringThis routine is largely a crock and is likely to explode at any rev or twist--------------------------------------------------------------------------*/char *get_ttyname(){#ifndef OLD_WAY	char *ttyname();	return(ttyname(TTYIN));#else	static char ttname[64];	register unsigned int rdev;	register char *cptr;	if(tty_not_char_special)		return("stdin");	else if(!tty_is_multiscreen)		return("non-multiscreen");	rdev = (unsigned)tty_stat.st_rdev;	if(rdev == 0x0301)		strcpy(ttname,"/dev/console");#if defined(M_UNIX)	else if(rdev == 0x0000)		strcpy(ttname,"/dev/syscon");#endif	else	{		strcpy(ttname,"/dev/tty");		cptr = ttname + 8;		if(rdev < 0x000C)		{			*cptr++ = '0' + ((rdev + 1) / 10);			*cptr++ = '0' + ((rdev + 1) % 10);		}		else if(!(rdev & ~0x58F))		{			*cptr++ = (rdev & 0x0008) ? '2' : '1';			*cptr++ = ((rdev & 0x0080) ? 'A' : 'a') + (rdev & 0x0007);		}		else		{			*cptr++ = '?';			*cptr++ = '?';		}		*cptr = 0;	}	return(ttname);#endif}	/* end of get_ttyname *//*+-------------------------------------------------------------------------	set_console_xon_xoff_by_arg(arg)--------------------------------------------------------------------------*/intset_console_xon_xoff_by_arg(arg)char *arg;{	int new_xon_xoff = 0;	if(ulcmpb(arg,"on") < 0)	{		new_xon_xoff = IXON | IXOFF;		tty_use_kbd_sw_flow_control = 1;	}	else if(ulcmpb(arg,"off") < 0)	{		new_xon_xoff = 0;		tty_use_kbd_sw_flow_control = 0;	}	else		return(-1);	tty_termio_current.c_iflag &= ~(IXON|IXOFF);	tty_termio_current.c_iflag |= new_xon_xoff;	ioctl(TTYIN,TCSETA,(char *)&tty_termio_current);	return(0);}	/* end of set_console_xon_xoff_by_arg *//*+-------------------------------------------------------------------------	console_xon_status()--------------------------------------------------------------------------*/char *console_xon_status(){	if(tty_use_kbd_sw_flow_control)		return("HONOR ^S/^Q locally");	else		return("PASS ^S/^Q to remote");}	/* end of console_xon_status *//* end of ecutty.c *//* vi: set tabstop=4 shiftwidth=4: */

⌨️ 快捷键说明

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