[comp.sources.misc] v16i030: ECU async comm package rev 3.0, Part06/35

wht@n4hgf.uucp (Warren Tucker) (01/06/91)

Submitted-by: wht@n4hgf.uucp (Warren Tucker)
Posting-number: Volume 16, Issue 30
Archive-name: ecu3/part06

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is part 06 of ecu3
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= ecuphrase.c ==============
echo 'x - extracting ecuphrase.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuphrase.c' &&
X/*+-----------------------------------------------------------------
X	ecuphrases.c - %# phrase management
X	wht@n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	phrase_help()
X	phrases(nargc,nargv)
X	read_phrases()
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X
X#define P_N_QUAN	23
Xchar *phrases_string[P_N_QUAN];
Xchar *phrases_label[P_N_QUAN];
Xint phrases_count = 0;
Xint phrases_resident = 0;
X
X/*+-----------------------------------------------------------------------
X	read_phrases()
X------------------------------------------------------------------------*/
Xvoid
Xread_phrases()
X{
Xregister char *phrases_str;
Xchar phrases_buf[256];
Xchar phrases_buf_copy[256];
Xchar *phrases_lbl;
XFILE *fd_phrase;
X
X	if(phrases_resident)
X	{
X		while(phrases_count)
X			free(phrases_string[--phrases_count]);
X		phrases_resident = 0;
X	}
X
X	get_home_dir(phrases_buf);
X	strcat(phrases_buf,"/.ecu/phrases");
X
X	if( (fd_phrase = fopen(phrases_buf,"r")) == NULL)
X	{
X		ff(se,"\r\n");
X		perror(phrases_buf);
X		ff(se,"\r\n");
X		ff(se,"... no phrases resident\r\n");
X		return;
X	}
X
X/* we have an open .ecu/phrase file */
X	phrases_count = 0;
X	while(fgets(phrases_buf,sizeof(phrases_buf),fd_phrase) != NULL)
X	{
X		phrases_buf[strlen(phrases_buf) - 1] = 0;
X		if(strlen(phrases_buf) == 0)
X			continue;
X
X		if(phrases_count == P_N_QUAN)
X		{
X			ff(se,"\r\nMaximum number of phrases %d exceeded\r\n",P_N_QUAN);
X			ff(se,"rest of file ignored, starting with the following:\r\n");
X			ff(se,"--> %s\r\n\r\n",phrases_buf);
X			phrases_resident = 1;
X			fclose(fd_phrase);
X			return;
X		}
X		strcpy(phrases_buf_copy,phrases_buf);
X		phrases_lbl = phrases_buf_copy;
X		for(phrases_str = phrases_buf_copy; *phrases_str; phrases_str++)
X		{
X			if(*phrases_str == ':')
X			{
X				*phrases_str++ = 0;
X				break;
X			}
X			if(*phrases_str == 0)
X			{
X				ff(se,"invalid entry `%s'\n",phrases_buf);
X				continue;
X			}
X		}
X
X		if(!(phrases_string[phrases_count] = malloc(strlen(phrases_str)+2)) ||
X		   !(phrases_label[phrases_count] = malloc(strlen(phrases_lbl)+2)))
X		{
X			ff(se,"\r\nNo more memory for phrases\r\n");
X			ff(se,"rest of file ignored, starting with the following:\r\n");
X			ff(se,"--> %s\r\n\r\n",phrases_buf);
X			phrases_resident = 1;
X			fclose(fd_phrase);
X			if(phrases_string[phrases_count])
X				free(phrases_string[phrases_count]);
X			return;
X		}
X		strcpy(phrases_string[phrases_count],phrases_str);
X		strcpy(phrases_label[phrases_count],phrases_lbl);
X		phrases_count++;
X	}			/* while records left to read */
X
X	fclose(fd_phrase);
X	phrases_resident = 1;
X}	/* end of read_phrases */
X
X/*+-------------------------------------------------------------------------
X	phrases(nargc,nargv)
X--------------------------------------------------------------------------*/
Xphrases(nargc,nargv)
Xint nargc;
Xchar **nargv;
X{
Xregister itmp;
Xregister ichar;
Xregister char *cptr;
Xint old_ttymode = get_ttymode();
Xextern char *phrases_string[]; 
Xextern int phrases_count;
Xextern int phrases_resident;
Xextern int interrupt;
Xextern int icmd_prompt_len;
X
X	for(itmp = icmd_prompt_len + strlen(nargv[0]); itmp; itmp--)
X		fputs("\b \b",se);
X
X	itmp = atoi(nargv[0]);
X
X	if(itmp == 0)
X	{
X		ff(se,"\r\n");
X		read_phrases();
X		if(!phrases_count)
X			return(0);
X		tcap_stand_out();
X		ff(se,
X" # |  mnemonic    |     phrase                                              ");
X		tcap_stand_end();
X		ff(se,"\r\n");
X		for(itmp = 0; itmp < phrases_count; itmp++)
X			ff(se,"%2d | %12s |  %s\r\n",itmp + 1,phrases_label[itmp],
X						phrases_string[itmp]);
X		return(0);
X	}
X	else
X		if(phrases_resident == 0)
X			read_phrases();
X
X	if(itmp > phrases_count)
X	{
X		ff(se,"  unknown: %d\r\n",itmp);
X		return(-1);
X	}
X	else
X	{
X		cptr = phrases_string[itmp - 1];
X		ttymode(2);
X		while(*cptr)
X		{
X			if(interrupt)
X				break;
X
X			switch(ichar = *cptr++)
X			{
X				case '^':
X					ichar = *cptr++;
X					if((ichar >= '@') && (ichar <= '_'))
X						lputc_paced(0,ichar & 0x1F);
X					else if(ichar == '?')
X						lputc_paced(0,0x7F);
X					else
X					{
X						switch(ichar)
X						{
X							case 0:
X								goto NULL_FOUND;
X							case 'r':
X								lputc_paced(0,'\r');
X								break;
X							case 'n':
X								lputc_paced(0,'\n');
X								break;
X							case 't':
X								lputc_paced(0,'\t');
X								break;
X							case '^':
X								lputc_paced(0,'^'); 
X								break;
X							case 'p': 
X								itmp = atoi(cptr);
X								while((*cptr >= '0') && (*cptr <= '9'))
X									cptr++;
X								if(*cptr == '.')
X									cptr++;
X								if(!itmp)
X									itmp = 1;
X								nap((long)itmp * 100L);
X								break;
X							case 'a':
X								itmp = atoi(cptr);
X								while((*cptr >= '0') && (*cptr <= '9'))
X									cptr++;
X								if(*cptr == '.')
X									cptr++;
X								if(itmp < nargc)
X								{
X									lputs_paced(0,nargv[itmp]);
X									itmp = strlen(nargv[itmp]);
X								}
X								break;
X						}
X					}
X					break;
X				default:
X					lputc_paced(0,ichar);
X			}
X		}
X
XNULL_FOUND:
X		if(interrupt)
X		{
X			interrupt = 0;
X			ff(se,"\r\n--> interrupted\r\n");
X		}
X
X	}
X
X	ttymode(old_ttymode);
X	return(0);
X
X}	/* end of phrases */
X
X
X/*+-------------------------------------------------------------------------
X	phrase_help()
X--------------------------------------------------------------------------*/
Xvoid
Xphrase_help()
X{
X	ff(se,"^r == \\r    ^n == \\n   ^t == \\t  ^^ == '^'\r\n");
X	ff(se,"^p#.  pause # secs\r\n");
X	ff(se,"^a#.  arg number # of %%# invocation\r\n");
X}	/* end of phrase_help */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1224223290 'ecuphrase.c' &&
chmod 0644 ecuphrase.c ||
echo 'restore of ecuphrase.c failed'
Wc_c="`wc -c < 'ecuphrase.c'`"
test 5521 -eq "$Wc_c" ||
	echo 'ecuphrase.c: original size 5521, current size' "$Wc_c"
# ============= ecurcvr.c ==============
echo 'x - extracting ecurcvr.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecurcvr.c' &&
X#define DEFENSIVE		/* lots of changes this rev: defining this
X						 * will make for screwed up screen image
X						 * but no core dump if nassssty bugs show up
X						 */
X/* #define ANSI_DEBUG */		/* debug ansi */
X/* #define ANSI_DEBUG_2 */		/* debug ansi intensive output */
X/* #define ANSI_DEBUG_3 */		/* debug ansi selected output */
X/* #define ANSI_DEBUG_NOBUF */	/* unbufferred logging */
X/* #define ANSI_DEBUG_LOGFILE	"/dev/tty2h" */
X/* #define DEBUG_CURSOR */
X#ifdef TEMP_HACK
X#define ANSI_DEBUG
X#define ANSI_DEBUG_2
X#define ANSI_DEBUG_3
X#define ANSI_DEBUG_LOGFILE	"/t/ansi.log"
X#endif
X
X/*+-------------------------------------------------------------------------
X	ecurcvr.c - rcvr process + ANSI filter + non-ANSI<->ANSI hoop jumping
X	wht@n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	accumulate_ansi_sequence(rchar)
X	ansi_CNL()
X	ansi_CPL()
X	ansi_CUB()
X	ansi_CUD()
X	ansi_CUF()
X	ansi_CUP()
X	ansi_CUU()
X	ansi_DCH()
X	ansi_DL()
X	ansi_DSR()
X	ansi_ECH()
X	ansi_ED()
X	ansi_EL()
X	ansi_HPA()
X	ansi_ICH()
X	ansi_IL()
X	ansi_SD()
X	ansi_SGR()
X	ansi_SU()
X	ansi_VPA()
X	is_ansi_terminator(rchar)
X	lgetc_rcvr()
X	process_ansi_sequence()
X	process_rcvd_char(rchar)
X	rcvd_ESC()
X	rcvr()
X	rcvr_log_open()
X	redisplay_rcvr_screen()
X	saved_cursor_restore_cursor()
X	saved_cursor_save_cursor()
X	spaces(buf,buflen)
X	spaces_trap(code,buf,buflen)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:12-21-1990-21:06-wht@n4hgf-CUF and CUB set non-ansi cursor incorrectly */
X/*:12-20-1990-16:27-wht@n4hgf-had SU and SD swapped */
X/*:11-30-1990-18:39-wht@n4hgf-non-ansi console rcvr appears to be working */
X/*:11-28-1990-14:13-wht@n4hgf-start non-ansi console support */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecukey.h"
X
Xextern int errno;
Xextern char rcvr_log_file[];	/* if rcvr_log!= 0,log filename */
Xextern int rcvr_log;			/* rcvr log active if != 0 */
Xextern FILE *rcvr_log_fp;		/* rcvr log file */
Xextern int rcvr_log_raw;		/* if true, log all, else filter ctl chrs */
Xextern int rcvr_log_append;		/* if true, append, else scratch */
Xextern int rcvr_log_flusheach;	/* if true, flush log on each char */
Xextern int rcvr_log_gen_title;
X
Xextern int want_bell_notify;
Xextern uint tcap_LINES;	/* terminal line quantity - see ecutcap.c */
Xextern uint tcap_COLS;	/* terminal column quantity - see ecutcap.c */
Xextern uint LINESxCOLS;
Xextern int tty_is_ansi;		/* true if TERM contains "ansi" */
X
Xstatic char esc = ESC;
X#define MAX_ANSI_LEN	30	/* generous */
Xchar ansibuf[MAX_ANSI_LEN];
Xchar *ansi;
Xint ansilen = 0;
Xint in_ansi_accumulation = 0;
X
Xint saved_cursor_y;
Xint saved_cursor_x;
X
X#define RCVR_RDQUAN		250
Xchar lgetc_buf[RCVR_RDQUAN];
Xchar *lgetc_ptr;
Xint lgetc_count = 0;
Xint vmin;				/* quick copy of current vmin value */
X
X#ifdef ANSI_DEBUG
XFILE *wfp = (FILE *)0;
X#endif
X
X/*+-------------------------------------------------------------------------
X	redisplay_rcvr_screen() - redisplay logical receiver screen
XAs of writing, this function is called only by the XMTR process
X--------------------------------------------------------------------------*/
Xvoid
Xredisplay_rcvr_screen()
X{
Xregister uint y;
X
X	setcolor(colors_current);
X	tcap_stand_end();
X	for(y = 0; y < tcap_LINES; y++)
X	{
X		tcap_cursor(y,0);
X		fwrite(&shm->screen[y][0],
X			((y != tcap_LINES - 1) ? tcap_COLS : tcap_COLS - 1),
X			1,se);
X	}
X	tcap_eeol();
X	tcap_cursor(shm->cursor_y,shm->cursor_x);
X
X}	/* end of redisplay_rcvr_screen */
X
X#ifdef DEBUG_CURSOR
Xvoid
Xspaces_trap(code,buf,buflen)
Xint code;
Xregister uchar *buf;
Xregister uint buflen;
X{
Xchar *xyz = (char *)0x90000000;
X	ff(se,"rcvr 'spaces trap' code %d: cursor x,y=%d,%d\r\n",
X		code,
X		shm->cursor_y,shm->cursor_x);
X	ff(se,"buf=%08lx len=%08lx offs=%08lx\r\n",buf,buflen,
X		(ulong)buf - (ulong)shm->screen);
X	*xyz = 0;
X	abort();
X}
X#endif
X
X/*+-------------------------------------------------------------------------
X	spaces(buf,buflen) - fill with spaces
X--------------------------------------------------------------------------*/
Xvoid
Xspaces(buf,buflen)
Xregister uchar *buf;
Xregister uint buflen;
X{
X#ifdef DEBUG_CURSOR
X	if((ulong)buf > (((ulong)shm->screen) + LINESxCOLS))
X		spaces_trap(1,buf,buflen);
X	if((ulong)buf < (ulong)shm->screen)
X		spaces_trap(2,buf,buflen);
X	if((ulong)(buf + buflen) > (((ulong)shm->screen) + LINESxCOLS))
X		spaces_trap(3,buf,buflen);
X	if((ulong)(buf + buflen) < (ulong)shm->screen)
X		spaces_trap(4,buf,buflen);
X#endif
X
X	if(!buflen)
X		return;
X
X#ifdef DEFENSIVE
X	if((ulong)buf < (ulong)shm->screen)
X		return;
X	if((ulong)(buf + buflen) > (((ulong)shm->screen) + LINESxCOLS))
X		return;
X#endif
X
X	while(buflen--)
X		*buf++ = ' ';
X}	/* end of spaces */
X
X/*+-------------------------------------------------------------------------
X	lgetc_rcvr() - rcvr version of get char from line
X--------------------------------------------------------------------------*/
Xint
Xlgetc_rcvr()
X{
Xextern int errno;
Xchar char_rtnd;
X
X	if(!lgetc_count)
X	{
X		if(vmin == 1)
X		{
X			char_rtnd = lgetc_xmtr();
X			return(char_rtnd);
X		}
X		lgetc_ptr = lgetc_buf;
XREAD_AGAIN:
X		errno = 0;
X		if((lgetc_count =
X			read(shm->Liofd,lgetc_buf,RCVR_RDQUAN)) < 0)
X		{
X			if(errno == EINTR)			/* if signal interrupted, ... */
X				goto READ_AGAIN;
X			hangup(HANGUP_LINE_READ_ERROR);
X		}
X		shm->rcvd_chars += lgetc_count;
X		shm->rcvd_chars_this_connect += lgetc_count;
X
X	}
X	if(!lgetc_count)
X		goto READ_AGAIN;
X
X	lgetc_count--;
X	return(*lgetc_ptr++);
X}	/* end of lgetc_rcvr */
X
X/*+-------------------------------------------------------------------------
X	ansi_SGR() - Set Graphics Rendition
X
XThe DOS ANSI world expects to be able to be able to chain 0,1 and
X3x,4x params together with semicolons.
X
X  Supported modifiers for non-ansi terminals
X  0       normal
X  1       bold
X  4       underscore
X  5       blink
X  7       reverse video
X--------------------------------------------------------------------------*/
Xvoid
Xansi_SGR()
X{
Xregister itmp;
Xregister char *cptr;
Xchar SGRstr[MAX_ANSI_LEN];
Xchar *token;
Xchar *str_token();
X
X	if(!tty_is_ansi)
X	{
X		cptr = ansibuf;
X		while(token = str_token(cptr,";"))
X		{
X			cptr = (char *)0;	/* further calls to str_token need NULL */
X			switch(atoi(token))
X			{
X				case 0:		/* normal */
X					tcap_stand_end();
X					tcap_blink_off();
X					tcap_underscore_off();
X					tcap_bold_off();
X					break;
X				case 1:		/* bold */
X					tcap_bold_on();
X					break;
X				case 4:		/* underscore */
X					tcap_underscore_on();
X					break;
X				case 5:		/* blink */
X					tcap_blink_on();
X					break;
X				case 7:		/* reverse video */
X					tcap_stand_out();
X					break;
X				default:
X					break;
X			}
X		}
X		return;
X	}
X
X	if(ansilen <= 3)	/* 'ESC[<0-9>m' and 'ESC[m' - quickly handled */
X	{
X		write(TTYERR,&esc,1);
X		write(TTYERR,ansibuf,ansilen);
X		return;
X	}
X
X/* check XENIX 'ESC[<2,3,7>m' extensions */
X	switch(itmp = atoi(ansibuf + 1))
X	{
X		case 7: /* XENIX 'ESC[7;<0-15>;<0-15>m' set fore/background color */
X			itmp = atoi(ansibuf + 3);	/* second parameter */
X			if(itmp > 15)				/* not XENIX extension */
X				break;
X			/* fall through */
X		case 2:	/* XENIX 'ESC[2;<0-15>;<0-15>m' set fore/background color */
X		case 3:	/* XENIX 'ESC[3;<0-1>m' color only set/clear blink */
X			write(TTYERR,&esc,1);
X			write(TTYERR,ansibuf,ansilen);
X			return;
X		default:
X			break;
X	}
X
X/* not XENIX extension */
X	ansibuf[ansilen - 1] = 0;	/* get rid of 'm' */
X	cptr = ansibuf + 1;			/* get rid of '[' */
X
X	while(token = str_token(cptr,";"))
X	{
X		cptr = (char *)0;	/* further calls to str_token need NULL */
X		sprintf(SGRstr,"\033[%sm",token);
X		write(TTYERR,SGRstr,strlen(SGRstr));
X	}
X
X}	/* end of ansi_SGR */
X
X/*+-------------------------------------------------------------------------
X	ansi_CUP() - cursor position (also HVP horiz/vertical position)
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CUP()
X{
Xregister uint param_count = 0;
Xchar ansicopy[MAX_ANSI_LEN];
Xregister char *cptr = ansicopy;
Xregister char *token;
Xchar *str_token();
X
X	strcpy(cptr,ansibuf + 1);
X	*(cptr + ansilen - 2) = 0;
X
X	while(token = str_token(cptr,";"))
X	{
X		cptr = (char *)0;	/* further calls to str_token need NULL */
X		switch(++param_count)
X		{
X			case 1:	shm->cursor_y = atoi(token) - 1; break;
X			case 2:	shm->cursor_x = atoi(token) - 1; break;
X		}
X	}
X	switch(param_count)
X	{
X		case 0:
X			shm->cursor_y = 0;
X		case 1:
X			shm->cursor_x = 0;
X	}
X	if(shm->cursor_x > (tcap_COLS - 1))
X		shm->cursor_x = 0;
X	if(shm->cursor_y > (tcap_LINES - 1))
X		shm->cursor_y = 0;
X
X	if(!tty_is_ansi)
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X
X}	/* end of ansi_CUP */
X
X/*+-------------------------------------------------------------------------
X	ansi_CUU() - cursor up
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CUU()
X{
Xregister uint count;
Xregister uint y;
X
X	if(ansilen == 2)		/* no param */
X		count = 1;
X	else
X		count = atoi(ansibuf + 1);
X
X	y = shm->cursor_y - count;
X	if(y > (tcap_LINES - 1))	/* unsigned comparison */
X		y = 0;
X
X	if(y != shm->cursor_y)
X	{
X		shm->cursor_y = y;
X		if(!tty_is_ansi)
X			tcap_cursor(shm->cursor_y,shm->cursor_x);
X	}
X
X}	/* end of ansi_CUU */
X
X/*+-------------------------------------------------------------------------
X	ansi_CUD() - cursor down (also VPR vertical position relative)
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CUD()
X{
Xregister uint count;
Xregister uint y;
X
X	if(ansilen == 2)		/* no param */
X		count = 1;
X	else
X		count = atoi(ansibuf + 1);
X
X	y = shm->cursor_y + count;
X	if(y > (tcap_LINES - 1))
X		y = tcap_LINES - 1;
X
X	if(y != shm->cursor_y)
X	{
X		shm->cursor_y = y;
X		if(!tty_is_ansi)
X			tcap_cursor(shm->cursor_y,shm->cursor_x);
X	}
X
X}	/* end of ansi_CUD */
X
X/*+-------------------------------------------------------------------------
X	ansi_CUF() - cursor forward (also HPR horizontal position relative)
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CUF()
X{
Xregister uint count;
Xregister uint x;
X
X	if(ansilen == 2)		/* no param */
X		count = 1;
X	else
X		count = atoi(ansibuf + 1);
X
X	x = shm->cursor_x + count;
X	if(x > tcap_COLS - 1)
X		x = tcap_COLS - 1;
X
X	if(x != shm->cursor_x)
X	{
X		shm->cursor_x = x;
X		if(!tty_is_ansi)
X			tcap_cursor(shm->cursor_y,shm->cursor_x);
X	}
X
X}	/* end of ansi_CUF */
X
X/*+-------------------------------------------------------------------------
X	ansi_CUB() - cursor forward
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CUB()
X{
Xregister uint count;
Xregister uint x;
X
X	if(ansilen == 2)		/* no param */
X		count = 1;
X	else
X		count = atoi(ansibuf + 1);
X
X	x = shm->cursor_x - count;
X	if(x > (tcap_COLS - 1))	/* unsigned comparison */
X		x = 0;
X
X	if(x != shm->cursor_x)
X	{
X		shm->cursor_x = x;
X		if(!tty_is_ansi)
X			tcap_cursor(shm->cursor_y,shm->cursor_x);
X	}
X
X}	/* end of ansi_CUB */
X
X/*+-------------------------------------------------------------------------
X	ansi_DSR() - device status report
X--------------------------------------------------------------------------*/
Xvoid
Xansi_DSR()
X{
Xchar response[MAX_ANSI_LEN];
X
X	sprintf(response,"\033[%d;%dR",shm->cursor_y + 1,shm->cursor_x + 1);
X	write(shm->Liofd,response,strlen(response));
X
X}	/* end of ansi_DSR */
X
X/*+-------------------------------------------------------------------------
X	ansi_ED() - erase in display
X--------------------------------------------------------------------------*/
Xvoid
Xansi_ED()
X{
Xregister uint param;
Xint y;
X
X	if(ansilen == 2)		/* no param */
X		param = 0;
X	else
X		param = atoi(ansibuf + 1);
X
X	switch(param)
X	{
X		case 0:	/* erase to end of display */
X			spaces(&shm->screen[shm->cursor_y][shm->cursor_x],
X				LINESxCOLS - ((shm->cursor_y * tcap_COLS) + shm->cursor_x));
X			if(!tty_is_ansi)
X				tcap_eeod();
X			break;
X		case 1:	/* erase from beginning of display */
X			spaces((char *)shm->screen,(shm->cursor_y * tcap_COLS) +
X				shm->cursor_x);
X			if(!tty_is_ansi)
X			{
X				for(y = 0; y < shm->cursor_y - 1; y++)
X				{
X					tcap_cursor(y,0);
X					tcap_eeol();
X				}
X				if(shm->cursor_x)
X				{
X					tcap_cursor(shm->cursor_y,0);
X					tcap_clear_area_char(shm->cursor_x,' ');
X				}
X				else
X					tcap_cursor(shm->cursor_y,shm->cursor_x);
X			}
X			break;
X		case 2:	/* clear display */
X			shm->cursor_y = 0;
X			shm->cursor_x = 0;
X			spaces((char *)shm->screen,LINESxCOLS);
X			if(!tty_is_ansi)
X			{
X				tcap_clear_screen();
X				tcap_cursor(shm->cursor_y,shm->cursor_x);
X			}
X			break;
X	}
X
X}	/* end of ansi_ED */
X
X/*+-------------------------------------------------------------------------
X	ansi_EL() - erase in line
X--------------------------------------------------------------------------*/
Xvoid
Xansi_EL()
X{
Xregister uint param;
Xchar cr = CR;
X
X	if(ansilen == 2)		/* no param */
X		param = 0;
X	else
X		param = atoi(ansibuf + 1);
X
X	switch(param)
X	{
X		case 2:	/* clear line */
X			shm->cursor_x = 0;
X			if(!tty_is_ansi)
X				write(TTYERR,&cr,1);
X			/* fall thru */
X		case 0:	/* erase to end of line */
X			spaces(&shm->screen[shm->cursor_y][shm->cursor_x],
X				tcap_COLS - shm->cursor_x);
X			if(!tty_is_ansi)
X				tcap_eeol();
X			break;
X		case 1:	/* erase from beginning of line */
X			spaces(&shm->screen[shm->cursor_y][0],shm->cursor_x);
X			if(!tty_is_ansi && shm->cursor_x)
X			{
X				write(TTYERR,&cr,1);
X				tcap_clear_area_char(shm->cursor_x,' ');
X			}
X			break;
X	}
X
X}	/* end of ansi_EL */
X
X/*+-------------------------------------------------------------------------
X	ansi_ECH() - erase characters
X--------------------------------------------------------------------------*/
Xvoid
Xansi_ECH()
X{
Xregister uint param;
Xregister uint screen_pos;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if((shm->cursor_x + param) > (tcap_COLS - 1))
X		return;
X
X	screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
X	mem_cpy((char *)shm->screen + screen_pos,
X	       (char *)shm->screen + screen_pos + param,param);
X	spaces((char *)shm->screen + ((shm->cursor_y + 1) * tcap_COLS) -
X				param, param);
X
X	if(!tty_is_ansi)
X		tcap_delete_chars(param);
X
X}	/* end of ansi_ECH */
X
X/*+-------------------------------------------------------------------------
X	ansi_SU() - scroll up (new blank lines at the bottom)
X--------------------------------------------------------------------------*/
Xvoid
Xansi_SU()
X{
Xregister uint param;
Xregister uint count;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > tcap_LINES)
X		param = tcap_LINES;
X	if(!param)
X		return;
X
X#ifdef ANSI_DEBUG_3
X	if(wfp)
X		fprintf(wfp,"SU: param=%u y,x=%d,%d\n",param,
X			shm->cursor_y,shm->cursor_x);
X#endif
X
X	count = tcap_COLS * param;
X	mem_cpy((char *)shm->screen,
X		(char *)shm->screen + (tcap_COLS * param),
X		LINESxCOLS - count);
X	spaces(&shm->screen[shm->cursor_y][0],count);
X
X	if(!tty_is_ansi)
X	{
X		tcap_cursor(tcap_LINES - 1,0);
X		while(param--)
X			ff(se,"\r\n");
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X	}
X
X}	/* end of ansi_SU */
X
X/*+-------------------------------------------------------------------------
X	ansi_SD() - scroll down (new blank lines at the top)
X--------------------------------------------------------------------------*/
Xvoid
Xansi_SD()
X{
Xregister uint param;
Xregister uint count;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > tcap_LINES)
X		param = tcap_LINES;
X	if(!param)
X		return;
X
X#ifdef ANSI_DEBUG_3
X	if(wfp)
X		fprintf(wfp,"SD: param=%u y,x=%d,%d\n",param,
X			shm->cursor_y,shm->cursor_x);
X#endif
X
X	count = tcap_COLS * param;
X	mem_cpy((char *)shm->screen,(char *)shm->screen + count,
X		LINESxCOLS - count);
X	spaces((char *)shm->screen + LINESxCOLS - count,count);
X
X	if(!tty_is_ansi)
X	{
X		tcap_cursor(tcap_LINES - 1,0);
X		while(param--)
X			ff(se,"\r\n");
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X	}
X
X}	/* end of ansi_SD */
X
X/*+-------------------------------------------------------------------------
X	ansi_HPA() - horizontal position absolute
X--------------------------------------------------------------------------*/
Xvoid
Xansi_HPA()
X{
Xregister uint param;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > (tcap_LINES - 1))
X		return;
X
X	if((unsigned)(shm->cursor_x = param) > (unsigned)(tcap_COLS - 1))
X		shm->cursor_x = tcap_COLS - 1;
X
X	if(!tty_is_ansi)
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X
X}	/* end of ansi_HPA */
X
X/*+-------------------------------------------------------------------------
X	ansi_VPA() - vertical position absolute
X--------------------------------------------------------------------------*/
Xvoid
Xansi_VPA()
X{
Xregister uint param;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > (tcap_COLS - 1))
X		return;
X
X	if((unsigned)(shm->cursor_y = param) > (unsigned)(tcap_LINES - 1))
X		shm->cursor_y = tcap_LINES - 1;
X
X	if(!tty_is_ansi)
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X
X}	/* end of ansi_VPA */
X
X/*+-------------------------------------------------------------------------
X	ansi_IL() - insert lines
X--------------------------------------------------------------------------*/
Xvoid
Xansi_IL()
X{
Xregister uint param;
Xregister uint count;
Xregister uint screen_pos;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if((shm->cursor_y + param) > (tcap_LINES - 1))
X		return;
X
X	count = tcap_COLS * param;
X	screen_pos = shm->cursor_y * tcap_COLS;
X	mem_cpy((char *)shm->screen + screen_pos + count,
X	       (char *)shm->screen + screen_pos,
X		   LINESxCOLS - screen_pos - count);
X	spaces((char *)shm->screen + screen_pos,count);
X
X	if(!tty_is_ansi)
X		tcap_insert_lines(param);
X
X}	/* end of ansi_IL */
X
X/*+-------------------------------------------------------------------------
X	ansi_ICH() - insert characters
X--------------------------------------------------------------------------*/
Xvoid
Xansi_ICH()
X{
Xregister uint param;
Xregister uint count;
Xregister uint screen_pos;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > tcap_COLS - shm->cursor_x)
X		param = tcap_COLS - shm->cursor_x;
X
X	if(!param)
X		return;
X
X	screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
X	count = tcap_COLS - shm->cursor_x - param;
X	mem_cpy((char *)shm->screen + screen_pos + param,
X	       (char *)shm->screen + screen_pos,count);
X	spaces((char *)shm->screen + screen_pos,param);
X
X	if(!tty_is_ansi)
X		tcap_insert_chars(param);
X
X}	/* end of ansi_ICH */
X
X/*+-------------------------------------------------------------------------
X	ansi_DL() - delete lines
X--------------------------------------------------------------------------*/
Xvoid
Xansi_DL()
X{
Xregister uint param;
Xregister uint count;
Xregister uint screen_pos;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > (tcap_LINES - shm->cursor_y))
X		param = tcap_LINES - shm->cursor_y;
X
X	if(!param)
X		return;
X
X	count = tcap_COLS * param;
X	screen_pos = shm->cursor_y * tcap_COLS;
X	mem_cpy((char *)shm->screen + screen_pos,
X		   (char *)shm->screen + screen_pos + count,
X			LINESxCOLS - screen_pos - count);
X	spaces((char *)shm->screen + LINESxCOLS - count,count);
X
X	if(!tty_is_ansi)
X		tcap_delete_lines(param);
X
X}	/* end of ansi_DL */
X
X/*+-------------------------------------------------------------------------
X	ansi_DCH() - delete characters
X--------------------------------------------------------------------------*/
Xvoid
Xansi_DCH()
X{
Xregister uint param;
Xregister uint count;
Xregister uint screen_pos;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if(param > tcap_COLS - shm->cursor_x)
X		param = tcap_COLS - shm->cursor_x;
X
X	if(!param)
X		return;
X
X	screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
X	count = tcap_COLS - shm->cursor_x - param;
X	mem_cpy((char *)shm->screen + screen_pos,
X	        (char *)shm->screen + screen_pos + param,count);
X	screen_pos = ((shm->cursor_y + 1) * tcap_COLS) - param;
X	spaces((char *)shm->screen + screen_pos,param);
X
X	if(!tty_is_ansi)
X		tcap_delete_chars(param);
X
X}	/* end of ansi_DCH */
X
X/*+-------------------------------------------------------------------------
X	ansi_CPL() - cursor to previous line
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CPL()
X{
Xregister uint param;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if((shm->cursor_y -= param) > (tcap_LINES - 1))	/* unsigned comparison */
X		shm->cursor_y = 0;
X	shm->cursor_x = 0;
X
X	if(!tty_is_ansi)
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X
X}	/* end of ansi_CPL */
X
X/*+-------------------------------------------------------------------------
X	ansi_CNL() - cursor to next line
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CNL()
X{
Xregister uint param;
X
X	if(ansilen == 2)		/* no param */
X		param = 1;
X	else
X		param = atoi(ansibuf + 1);
X
X	if((shm->cursor_y += param) > (tcap_LINES - 1))
X		shm->cursor_y = tcap_LINES - 1;
X	shm->cursor_x = 0;
X
X	if(!tty_is_ansi)
X		tcap_cursor(shm->cursor_y,shm->cursor_x);
X
X}	/* end of ansi_CNL */
X
X/*+-------------------------------------------------------------------------
X	saved_cursor_save_cursor()
X--------------------------------------------------------------------------*/
Xvoid
Xsaved_cursor_save_cursor()
X{
X	saved_cursor_y = shm->cursor_y;
X	saved_cursor_x = shm->cursor_x;
X}	/* end of saved_cursor_save_cursor */
X
X/*+-------------------------------------------------------------------------
X	saved_cursor_restore_cursor()
X--------------------------------------------------------------------------*/
Xvoid
Xsaved_cursor_restore_cursor()
X{
X	shm->cursor_y = saved_cursor_y;
X	shm->cursor_x = saved_cursor_x;
X	tcap_cursor(shm->cursor_y,shm->cursor_x);
X}	/* end of saved_cursor_restore_cursor */
X
X/*+-------------------------------------------------------------------------
X	rcvd_ESC() - ESC seen-prepare to accumulate ansi sequence
X--------------------------------------------------------------------------*/
Xvoid
Xrcvd_ESC()
X{
X#ifdef ANSI_DEBUG
X	if(wfp)
X		fprintf(wfp,"ESC ");
X#endif
X
X	ansi = ansibuf;
X	ansilen = 0;
X	in_ansi_accumulation = 1;
X
X}	/* end of rcvd_ESC */
X
X/*+-------------------------------------------------------------------------
X	is_ansi_terminator(rchar) - is character terminator for ansi sequence?
X--------------------------------------------------------------------------*/
Xint
Xis_ansi_terminator(rchar)
Xregister uint rchar;
X{
X	return(isalpha(rchar) || (rchar == '@'));
X}	/* end of is_ansi_terminator */
X
X/*+-------------------------------------------------------------------------
X	accumulate_ansi_sequence(rchar)
X--------------------------------------------------------------------------*/
Xvoid
Xaccumulate_ansi_sequence(rchar)
Xuint rchar;
X{
X	if(ansilen == (MAX_ANSI_LEN - 2))
X	{
X		in_ansi_accumulation = 0;
X		return;
X	}
X
X#ifdef ANSI_DEBUG_2
X	if(wfp)
X		fprintf(wfp,"\naas: %02x %c ansilen=%d",
X			rchar,(rchar & 0x7F < SPACE) ? '.' : (rchar & 0x7F),ansilen);
X#endif
X
X	*ansi++ = (uchar)rchar;
X	*ansi   = 0;
X	ansilen++;
X
X}	/* end of accumulate_ansi_sequence */
X
X/*+-------------------------------------------------------------------------
X	process_ansi_sequence() - a full ansi sequence is to be decoded
X--------------------------------------------------------------------------*/
Xvoid
Xprocess_ansi_sequence()
X{
Xregister itmp;
X
X#ifdef ANSI_DEBUG
X	if(wfp)
X		fprintf(wfp,"\npas: len=%d '%s' y,x=%d,%d\n",ansilen,ansibuf,
X			shm->cursor_y,shm->cursor_x);
X#endif
X
X	if(!in_ansi_accumulation)
X		return;
X	in_ansi_accumulation = 0;
X
X	itmp = 1;		/* assume write needed */
X	if((ansilen > 1) && (ansibuf[1] == '='))
X		;
X	else switch(ansibuf[ansilen - 1])
X	{
X		case '@': ansi_ICH(); break;
X		case 'A': ansi_CUU(); break;
X		case 'B': ansi_CUD(); break;
X		case 'C': ansi_CUF(); break;
X		case 'D': ansi_CUB(); break;
X		case 'E': ansi_CNL(); break;
X		case 'F': ansi_CPL(); break;
X		case 'H': ansi_CUP(); break;
X		case 'J': ansi_ED(); break;
X		case 'K': ansi_EL(); break;
X		case 'L': ansi_IL(); break;
X		case 'M': ansi_DL(); break;
X		case 'P': ansi_DCH(); break;
X		case 'S': ansi_SU(); break;
X		case 'T': ansi_SD(); break;
X		case 'X': ansi_ECH(); break;
X		case '`': ansi_HPA(); break;
X		case 'a': ansi_CUF(); break; /* HPR */
X		case 'd': ansi_VPA(); break;
X		case 'e': ansi_CUD(); break; /* VPR */
X		case 'f': ansi_CUP(); break; /* HVP */
X		case 'm': ansi_SGR(); itmp = 0; break;
X		case 'n': ansi_DSR(); itmp = 0; break;
X		case 's': saved_cursor_save_cursor(); itmp = 0; break;
X		case 'u': saved_cursor_restore_cursor(); itmp = 0; break;
X#ifdef FUTURES
X		case 'h': ansi_SM(); break;	/* Set Mode: SCO: lock keyboard
X									 *           MSDOS: host of shit */
X		case 'i': ansi_MC(); break;	/* Media Copy: send screen to line */
X		case 'l': ansi_RM(); break;	/* Reset Mode: SCO: unlock keyboard
X									 *             MSDOS: host of shit */
X#endif /* FUTURES */
X		default:
X			break;
X	}
X
X/* if proper ansi console and indicated, write the buffer to the screen */
X	if(tty_is_ansi && itmp)
X	{
X		write(TTYERR,&esc,1);
X		write(TTYERR,ansibuf,ansilen);
X	}
X
X#ifdef ANSI_DEBUG
X	if(wfp)
X		fprintf(wfp,"pas: new cursor y,x=%d,%d\n",shm->cursor_y,shm->cursor_x);
X#endif
X}	/* end of process_ansi_sequence */
X
X/*+-------------------------------------------------------------------------
X	rcvr_log_open()
X--------------------------------------------------------------------------*/
Xvoid
Xrcvr_log_open()
X{
X
X	if(rcvr_log)		/* if xmtr set us up for logging */
X	{
X		rcvr_log_fp = fopen(rcvr_log_file,rcvr_log_append ? "a" : "w");
X		rcvr_log_append = 1;	/* until next %log -s */
X		if(!rcvr_log_fp)
X		{
X			ff(se,"ecu RCVR: Could not open log file: %s\r\n",rcvr_log_file);
X			ff(se,"recording aborted.\r\n");
X		}
X		else if(!rcvr_log_raw && rcvr_log_gen_title)
X		{
X		char tstr[80];
X			get_tod(2,tstr);
X			fprintf(rcvr_log_fp,"\n====> %s (%s, %s, %s) %s\n\n",
X				shm->Lrname,shm->Llogical,
X				shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE",tstr);
X		}
X		rcvr_log_gen_title = 0;
X	}
X}	/* end of rcvr_log_open */
X
X/*+-------------------------------------------------------------------------
X	process_rcvd_char(rchar)
X--------------------------------------------------------------------------*/
Xprocess_rcvd_char(rchar)
Xregister uint rchar;
X{
Xregister itmp;
X
X	if(shm->Lparity)
X		rchar &= 0x7F;
X
X	if(want_bell_notify == 2)
X	{
X		shmr_set_xmtr_bn_1();
X		want_bell_notify = 1;
X		bell_notify(XBELL_3T);
X	}
X	else if(rchar == 7)
X	{
X		bell_notify(XBELL_ATTENTION);
X		return(0);
X	}
X
X	if(rchar == ESC)
X	{
X		rcvd_ESC();
X		return(1);
X	}
X	else if(in_ansi_accumulation)
X	{
X		accumulate_ansi_sequence(rchar);
X		if(is_ansi_terminator(rchar))
X			process_ansi_sequence();
X		return(1);
X	}
X
X#ifdef TANDEM_ENQ_ACK	/* for my friend John Dashner at Tandem */
X	if(rchar == ENQ)
X	{
X		lputc(ACK);
X		return(0);
X	}
X#endif
X
X	if(rchar < SPACE)
X	{
X		switch(rchar)
X		{
X			case CTL_L:
X				spaces((char *)shm->screen,LINESxCOLS);
X				shm->cursor_y = 0;
X				shm->cursor_x = 0;
X				break;
X
X			case BS:
X				if(shm->cursor_x)
X					shm->cursor_x--;
X				break;
X
X			case NL:
X				if(shm->cursor_y != tcap_LINES - 1)
X					shm->cursor_y++;
X				else
X				{
X					mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS,
X						LINESxCOLS - tcap_COLS);
X					spaces(&shm->screen[shm->cursor_y][0],tcap_COLS);
X				}
X				break;
X
X			case CR:
X				shm->cursor_x = 0;
X				break;
X
X			case TAB:
X				itmp = 8 - (shm->cursor_x % 8);
X				shm->cursor_x += itmp;
X				if(shm->cursor_x >= tcap_COLS)
X				{
X					shm->cursor_x = 0;
X					if(++shm->cursor_y > tcap_LINES - 1)
X						shm->cursor_y = tcap_LINES - 1;
X				}
X#ifdef old
X				else
X#endif
X					spaces(&shm->screen[shm->cursor_y][shm->cursor_x],itmp);
X				break;
X		}
X	}
X	else
X	{
X		shm->screen[shm->cursor_y][shm->cursor_x++] = (uchar)rchar;
X		if(shm->cursor_x > tcap_COLS - 1)
X		{
X			shm->cursor_x = 0;
X			if(shm->cursor_y != tcap_LINES - 1)
X				shm->cursor_y++;
X			else
X			{
X				mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS,
X					LINESxCOLS - tcap_COLS);
X				spaces(&shm->screen[shm->cursor_y][shm->cursor_x],tcap_COLS);
X			}
X		}
X	}
X
X#ifdef ANSI_DEBUG_2
X	if(wfp)
X	{
X		if((rchar & 0x7F) == NL)
X			fputs("\n",wfp);
X		else
X			fputc(((rchar & 0x7F) < SPACE) ? '.' : (rchar & 0x7F),wfp);
X	}
X#endif
X
X	if(rcvr_log && rcvr_log_fp)
X	{
X		/* if raw mode or character not excluded from "cooked" logging */
X		if(rcvr_log_raw ||
X			((rchar >= SPACE) && (rchar <= '~')) ||
X			 (rchar == NL) || (rchar == TAB))
X		{
X			putc(rchar,rcvr_log_fp);
X		}
X		/* back if log file if not raw and char is backspace */
X		else if(!rcvr_log_raw && (rchar == BS))
X		{
X		long logpos = 0;
X			if(logpos = ftell(rcvr_log_fp))
X				fseek(rcvr_log_fp,logpos - 1,0);
X		}
X
X		if(rcvr_log_flusheach)
X			fflush(rcvr_log_fp);
X	}
X	return(0);
X
X}	/* end of process_rcvd_char */
X
X/*+-----------------------------------------------------------------------
X	rcvr() - copy characters from remote line to so (fd == 1)
X------------------------------------------------------------------------*/
Xvoid
Xrcvr()
X{
Xregister itmp;
Xuchar rchar;
Xuchar nlchar = NL;
Xchar *cptr;
X
X#ifdef ANSI_DEBUG
Xchar s80[80];
X	wfp = fopen(ANSI_DEBUG_LOGFILE,"a");
X	if(ulindex(ANSI_DEBUG_LOGFILE,"/dev/tty") != -1)
X	{
X		sprintf(s80,"stty opost ocrnl < %s",ANSI_DEBUG_LOGFILE);
X		system(s80);
X	}
X	fprintf(wfp,"***************\n");
X#ifdef ANSI_DEBUG_NOBUF
X	setbuf(wfp,NULL);
X#endif /* ANSI_DEBUG_NOBUF */
X#endif /* ANSI_DEBUG */
X
X	lgetc_count = 0;
X	in_ansi_accumulation = 0;
X	ansi = ansibuf;
X	ansilen = 0;
X
X/* yetch - magic number gretching for lines and columns */
X	if(!tcap_LINES || !tcap_COLS)
X	{
X		tcap_LINES = 25;
X		tcap_COLS = 80;
X	}
X	if(tcap_LINES > 43)
X		tcap_LINES = 43;
X	if(tcap_COLS > 80)
X		tcap_COLS = 80;
X	LINESxCOLS = tcap_LINES * tcap_COLS;
X
X	rcvr_signals();
X	rcvr_log_open();
X
X	saved_cursor_y = shm->cursor_y;
X	saved_cursor_x = shm->cursor_x;
X
X	while(1)		/* receive loop - keep tight as possible! */
X	{
X		rchar = lgetc_rcvr();
X
X		if(process_rcvd_char(rchar))
X			continue;
X
X		write(TTYERR,&rchar,1);
X
X		if(shm->Ladd_nl_incoming && (rchar == CR))
X			write(TTYERR,&nlchar,1);
X
X	}
X}	/* end of rcvr */
X
X/* end of ecurcvr.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1226051590 'ecurcvr.c' &&
chmod 0644 ecurcvr.c ||
echo 'restore of ecurcvr.c failed'
Wc_c="`wc -c < 'ecurcvr.c'`"
test 30050 -eq "$Wc_c" ||
	echo 'ecurcvr.c: original size 30050, current size' "$Wc_c"
# ============= ecuscrdump.c ==============
echo 'x - extracting ecuscrdump.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuscrdump.c' &&
X#define MULTISCREEN_DUMP_BUG
X/*+-------------------------------------------------------------------------
X	ecuscrdump.c - screen dump
X	wht@n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	screen_dump(scrfile)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:12-21-1990-17:27-wht@n4hgf-non-ansi considerations */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecukey.h"
X#include "pc_scr.h"
X
Xextern char curr_dir[];		/* current working directory */
Xextern int rcvr_pid;
Xextern uint tcap_LINES;
Xextern uint tcap_COLS;
Xextern struct termio tty_termio_at_entry;
Xextern int tty_not_char_special;
Xextern int tty_is_multiscreen;
X
Xchar screen_dump_file_name[256];
X
X/*+-------------------------------------------------------------------------
X	screen_dump(scrfile) - dump physical display contents
Xunless stdin is non-multiscreen and/or /dev/null, in which case,
Xdump rcvr virtual screen
Xif scrfile == NULL, default to ~/.ecu/screen.dump
X--------------------------------------------------------------------------*/
Xvoid
Xscreen_dump(scrfile)
Xchar *scrfile;
X{
Xuchar s133[133];
Xuchar schar;
Xregister uchar *cptr = s133;
Xuchar *sptr;
Xint srow;
Xint scol;
XFILE *fp;
Xstruct termio dump_tty_termio_at_entry;
Xstruct termio dump_tty_termio_current;
Xint rcvr_alive = (rcvr_pid > 0);
Xint use_ansi_MC = !(!tty_is_multiscreen || tty_not_char_special);
Xuint lines_left = tcap_LINES;
Xchar *vbuf = (char *)0;
X
X	if(rcvr_alive)
X		kill_rcvr_process(SIGUSR1);
X
X	if(use_ansi_MC)
X	{
X		/* save keyboard termio at entry */
X		ioctl(TTYIN,TCGETA,(char *)&dump_tty_termio_at_entry);
X
X		/* set keyboard to termio status at staart of execution of program 
X		 * plus a few mods
X		 */
X
X		dump_tty_termio_current = tty_termio_at_entry;
X		dump_tty_termio_current.c_cflag &= ~(PARENB | PARODD);
X		dump_tty_termio_current.c_cflag |= CS8;
X		dump_tty_termio_current.c_iflag &= ~(ISTRIP);
X		dump_tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
X		ioctl(TTYIN,TCSETAW,(char *) &dump_tty_termio_current);
X		ttyflush(2);
X	}
X
X	if(scrfile)
X		fp = fopen(scrfile,"a");
X	else
X	{
X		get_home_dir(s133);
X		strcat(s133,"/.ecu/screen.dump");
X		fp = fopen(s133,"a");
X	}
X	if(!fp)
X	{
X#if defined(MORSE)
X		xbell(XBELL_3T,1);
X#else
X		ring_bell();
X		nap(20L);
X		ring_bell();
X#endif
X		return;
X	}
X
X	if(vbuf = (char *)malloc(5120))	/* big buffer; size used elsewhere too */
X#if defined(M_XENIX)	/* bassackwards */
X		setvbuf(fp,_IOFBF,vbuf,5120);
X#else
X		setvbuf(fp,vbuf,_IOFBF,5120);
X#endif
X
X	get_tod(2,s133);
X	fprintf(fp,"====> %s (phone %s) %s\n",
X		shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE",s133);
X
X	if(use_ansi_MC)
X		write(1,"\033[2i",4);	/* spill your guts, screen */
X	else
X	{
X		sptr = (uchar *)shm->screen;
X		srow = 0;
X		scol = 0;
X	}
X
X	while(1)
X	{
X		if(use_ansi_MC)
X		{
X			if(!rdchk(0))
X			{
X				nap(20L);
X				if(!rdchk(0))
X					break;
X			}
X			read(0,&schar,1);
X			if(!lines_left)
X				continue;
X		}
X		else
X		{
X			if(srow == tcap_LINES)
X				break;
X			if(scol == tcap_COLS)
X			{
X				scol = 0;
X				srow++;
X				schar = NL;
X			}
X			else
X			{
X				schar = *sptr++;
X				scol++;
X			}
X		}
X
X		if((schar > 0x7E) || (schar < 0x20))
X		{
X			switch(schar)
X			{
X			case NL:
X				while((cptr > s133) && (*(cptr - 1) == ' '))
X					cptr--;
X				*cptr++ = 0x0A;
X				*cptr = 0;
X				fputs(s133,fp);
X				cptr = s133;
X				*cptr = 0;
X				--lines_left;
X				continue;
X
X			case at_TL:		
X				schar = vanilla_TL;
X				break;
X			case at_TR:
X				schar = vanilla_TR;
X				break;
X			case at_BL:		
X				schar = vanilla_BL;
X				break;
X			case at_BR:		
X				schar = vanilla_BR;
X				break;
X			case at_LT:			/* left hand T */
X				schar = vanilla_LT;
X				break;
X			case at_RT:			/* right hand T */
X				schar = vanilla_RT;
X				break;
X			case at_VR:			/* vertical rule */
X				schar = vanilla_VR;
X				break;
X			case at_HR:			/* horizontal rule */
X				schar = vanilla_HR;
X				break;
X			default:
X				schar = ' ';
X			}
X		}
X		*cptr++ = schar;
X	}
X
X	if(use_ansi_MC)
X	{
X		/* restore keyboard termio at entry */
X		ioctl(TTYIN,TCSETAW,(char *)&dump_tty_termio_at_entry);
X		ttyflush(2);
X#if defined(MULTISCREEN_DUMP_BUG)
X		/*
X		 * bug in 2.3.1 sco video driver leaves "ESC[2" active;
X		 * use "l" (unlock tty) a noop
X		 */
X		fputs("l",stdout);
X#endif /* MULTISCREEN_DUMP_BUG */
X	}
X
X	fclose(fp);
X
X	if(vbuf)
X		free(vbuf);
X
X#if defined(MORSE)
X	xbell(XBELL_DONE,1);
X#else
X	ring_bell();
X#endif
X
X	if(rcvr_alive)
X		start_rcvr_process(0);
X
X}	/* end of screen_dump */
SHAR_EOF
$TOUCH -am 1224223390 'ecuscrdump.c' &&
chmod 0644 ecuscrdump.c ||
echo 'restore of ecuscrdump.c failed'
Wc_c="`wc -c < 'ecuscrdump.c'`"
test 4434 -eq "$Wc_c" ||
	echo 'ecuscrdump.c: original size 4434, current size' "$Wc_c"
true || echo 'restore of ecusetup.c failed'
echo End of part 6, continue with part 7
exit 0
--------------------------------------------------------------------
Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.