[alt.sources] ecu - SCO XENIX V/{2,3}86 Extended CU part 07/47

wht@tridom.uucp (Warren Tucker) (10/09/89)

---- Cut Here and unpack ----
#!/bin/sh
# this is part 7 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecuphone.c continued
#
CurArch=7
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file ecuphone.c"
sed 's/^X//' << 'SHAR_EOF' >> ecuphone.c
X		tpde = curr_pde;
X	}	/* end of add code */
X
X	if(edit)
X		dirw_bot_msg("ESC: exit  ^U: erase input  ^B: back  TAB: forward");
X	else
X		dirw_bot_msg("ESC: abort  ^U: erase input  ^B: back up");
X
X/* add/edit common */
X	while(!done)
X	{
X		switch(input_state)
X		{
X			case 0:
X				pde_add_or_edit_read("Enter telephone number",
X					edit,15,s50,16+1,&delim);
X				if(delim != NL)
X					break;
X				strcpy(tpde->telno,s50);
X				break;
X
X			case 1:
X				pde_add_or_edit_read("Enter tty identifier (i.e., 1a)",
X					edit,34,s50,3+1,&delim);
X				if(delim != NL)
X					break;
X				if(ulcmpb(s50,"any") < 0)
X					tpde->tty[0] = 0;
X				else
X				{
X					strncpy(tpde->tty,s50,2);
X					tpde->tty[2] = 0;
X				}
X				break;
X
X			case 2:
X				pde_add_or_edit_read(
X				"Enter baud rate (110,300,600,1200,2400,4800,9600,19200,38400)",
X					edit,39,s50,5+1,&delim);
X				if(delim != NL)
X					break;
X				if(edit && (strlen(s50) == 0))
X					break;
X				if(valid_baud_rate(baud = atoi(s50)) < 0)
X				{
X					ring_bell();
X					continue;
X				}
X				tpde->baud = baud;
X				break;
X
X			case 3:
X				pde_add_or_edit_read("Enter parity (n,o,e)",
X					edit,45,s50,1+1,&delim);
X				if(delim != NL)
X					break;
X				if(edit && (strlen(s50) == 0))
X					break;
X				switch(s50[0] = to_lower(s50[0]))
X				{
X					case 'n':
X						s50[0] = 0;
X					case 'o':
X					case 'e':
X						tpde->parity = s50[0];
X						break;
X					default:
X						ring_bell();
X						continue;
X				}
X				break;
X
X			case 4:
X				pde_add_or_edit_read("Enter description",
X					edit,49,s50,29+1,&delim);
X				if(delim != NL)
X					break;
X				if(edit && (strlen(s50) == 0))
X					break;
X				strcpy(tpde->descr,s50);
X				break;
X		}
X
X		pde_display(scrw_curr_pde_line,tpde,1);	/* regardless of delimiter */
X
X		switch(delim) /* process delimiter */
X		{
X			case CTL_L:
X			case CTL_R:
X				clear_screen();
X				touchwin(stdscr);
X				wrefresh(stdscr);
X				touchwin(dirw);
X				wrefresh(dirw);
X				touchwin(scrw);
X				wrefresh(scrw);
X				break;
X
X			case CTL_B:
X				if(input_state)
X					input_state--;
X				break;
X
X			case TAB:
X				input_state++;
X				input_state %= 5;
X				break;
X
X			case ESC:
X				if(edit)
X				{
X					dirw_bot_msg("edit finished");
X					done = 1;
X				}
X				else
X				{
X					pde_list_remove(tpde);
X					curr_pde = old_curr_pde;
X					scrw_fill_at(scrw_curr_pde_line + 1,curr_pde,
X							&scrw_curr_pde_line);
X					dirw_bot_msg("add aborted");
X					return(0);
X				}
X				break;
X
X			case NL:
X				if(edit)
X					pde_list_set_dirty(1);
X				/* fall thru */
X			default:
X				if(!edit && (input_state == 4))
X					done = 1;
X				else 
X				{
X					input_state++;
X					input_state %= 5;
X				}
X				break;
X		}
X	}
X	return(1);
X
X}	/* end of pde_add_or_edit */
X
X/*+-------------------------------------------------------------------------
X	pde_cmd_add(tpde)
Xif tpde != 0, it is an already valid pde that is to be added
Xelse if == 0, interactive add
X--------------------------------------------------------------------------*/
Xvoid
Xpde_cmd_add(tpde)
Xregister PDE *tpde;
X{
Xregister itmp;
X
X	if(tpde)
X	{
X		pde_list_add(tpde);
X	}
X	else
X	{
X		if((tpde = (PDE *)malloc(sizeof(PDE))) == (PDE *)0)
X		{
X			dirw_bot_msg("Out of memory -- cannot add new entry");
X			return;
X		}
X		if(!pde_add_or_edit(tpde,0))	/* routine will add to list ... */
X		{								/* ... if good return */
X			free((char *)tpde);
X			return;
X		}
X	}
X	pde_list_set_dirty(1);
X
X	curr_pde = tpde;
X	scrw_fill_at(SCRW_LINES / 2,curr_pde,&scrw_curr_pde_line);
X
X}	/* end of pde_cmd_add */
X
X/*+-------------------------------------------------------------------------
X	pde_cmd_remove_oops()
X--------------------------------------------------------------------------*/
Xvoid
Xpde_cmd_remove_oops()
X{
X	if(!remove_pde)
X	{
X		dirw_bot_msg("no removed entry to restore");
X		return;
X	}
X	pde_cmd_add(remove_pde);
X	pde_list_set_dirty(remove_dirty_flag);
X	remove_pde = (PDE *)0;
X}	/* end of pde_cmd_remove_oops */
X
X/*+-------------------------------------------------------------------------
X	pde_cmd_remove()
X--------------------------------------------------------------------------*/
Xvoid
Xpde_cmd_remove()
X{
Xregister itmp;
Xregister PDE *tpde;
Xchar s80[80];
X
X	if(!check_curr_pde())
X		return;
X
X	remove_pde = curr_pde;
X	remove_dirty_flag = pde_list_dirty;
X	pde_list_remove(curr_pde);
X	pde_list_set_dirty(1);
X
X	if(pde_list_quan)
X		scrw_fill_at(scrw_curr_pde_line + 1,curr_pde,&scrw_curr_pde_line);
X	else
X		scrw_fill((PDE *)0,&scrw_curr_pde_line);
X
X	ring_bell();
X	sprintf(s80,"if you did not mean to to remove '%s', press 'o' (oops) NOW!",
X			remove_pde->logical);
X	dirw_bot_msg(s80);
X
X}	/* end of pde_cmd_remove */
X
X/*+-------------------------------------------------------------------------
X	pde_cmd_find()
X--------------------------------------------------------------------------*/
Xvoid
Xpde_cmd_find()
X{
Xregister itmp;
Xregister PDE *tpde;
Xchar findname[12];
Xchar s50[50];
Xchar delim;
Xint y,x;
X
X	dirw_bot_msg("ESC: abort  ^U: erase input");
X	dirw_cmd_line_setup("Directory entry name to find: ");
X	getyx(dirw,y,x);
X	wstandout(dirw);
X	wingets(dirw,y,x,findname,10+1,&delim,0);
X	wstandend(dirw);
X	if((!strlen(findname)) || (delim == ESC))
X		return;
X
X	if(! (tpde = pde_list_search(findname,0)))
X	{
X		dirw_bot_msg(errmsg);
X		return;
X	}
X	curr_pde = tpde;
X	scrw_fill_at(SCRW_LINES / 2,tpde,&scrw_curr_pde_line);
X
X}	/* end of pde_cmd_find */
X
X/*+-------------------------------------------------------------------------
X	pde_list_manager()
X--------------------------------------------------------------------------*/
Xvoid
Xpde_list_manager()
X{
Xregister uchar cmd = 0;
Xint rcvr_active = (rcvr_pid > 0) || (rcvr_pid == -2);
Xint done;
Xchar s80[80];
XWINDOW *window_create();
Xchar *find_procedure();
Xextern int proc_level;
X
X	if(rcvr_active && (rcvr_pid != -2))
X		kill_rcvr_process(SIGUSR1);
X
X	windows_start();
X	dirw = window_create("dialing directory",3,0,0,DIRW_LINES,DIRW_COLS);
X	dirw_display_top();
X
X	scrw = subwin(dirw,SCRW_LINES,SCRW_COLS,SCRW_TLY,SCRW_TLX);
X	scrollok(scrw,0);
X	if(!pde_list_quan)
X	{
X		if(pde_list_read())
X			dirw_bot_msg(errmsg);
X		else if(!pde_list_quan)
X			dirw_bot_msg("directory empty");
X	}
X
X	if(pde_list_quan)
X	{
X		if(curr_pde)
X			scrw_fill_at(scrw_curr_pde_line,curr_pde,&scrw_curr_pde_line);
X		else
X		{
X			curr_pde = pde_list_head;
X			scrw_fill(curr_pde,&scrw_curr_pde_line);
X		}
X	}
X
X	pde_list_set_dirty(-1);
X
X	done = 0;
X	while(!done)
X	{
X		cmd = dirw_get_cmd(
X#if defined(M_XENIX)
X	"d,j:down u,k:up e:edit a:add r:remove s:save f:find END:dial ESC,q:quit");
X#else
X	"d,j:down u,k:up e:edit a:add r:remove s:save f:find ^D:dial  ESC,q:quit");
X#endif
X		if((cmd != 'o') && (remove_pde))
X		{
X			free((char *)remove_pde);
X			remove_pde = (PDE *)0;
X		}
X
X		switch(cmd)
X		{
X			case 'd':
X			case 'j': pde_cmd_down(); break;
X
X			case 'u':
X			case 'k': pde_cmd_up(); break;
X
X			case 's': pde_cmd_save(); break;
X
X			case CR:
X			case NL:
X			case DIAL:
X				cmd = DIAL;
X				if(!check_curr_pde())
X					break;
X				pde_list_save_if_dirty();
X				windows_end(dirw);
X				done = 1;
X#ifdef AUTO_DIAL_PROC
X				if(!proc_level && find_procedure(curr_pde->logical))
X				{
X				char *pargv[2];
X					pargv[0] = curr_pde->logical;
X					pargv[1] = "!MENU";
X					rcvr_pid = 0;
X					do_proc(2,pargv);
X					start_rcvr_process(1);
X				}
X				else
X				{
X					if(rcvr_active)
X						rcvr_pid = -2;	/* hayes_dial shud start rcvr */
X					hayes_dial_pde(curr_pde);
X				}
X#else
X				if(rcvr_active)
X					rcvr_pid = -2;	/* hayes_dial shud start rcvr */
X				hayes_dial_pde(curr_pde);
X#endif
X				break;
X
X			case ESC:
X			case CTL_C:
X				cmd = 'q';
X			case 'q':
X				done = 1;
X				continue;
X
X			case 'f': pde_cmd_find(); break;
X
X			case 'r': pde_cmd_remove(); break;
X			case 'o': pde_cmd_remove_oops(); break;
X
X			case 'a': pde_cmd_add((PDE *)0); break;
X
X			case 'e': pde_add_or_edit(curr_pde,1); break;
X
X#if defined(PDE_DEBUG)
X			case CTL_BSLASH:	/* undocumented ^\ */
X				pde_cmd_dump_list(); break;
X#endif
X
X			case CTL_L:
X			case CTL_R:
X				touchwin(stdscr);
X				wrefresh(stdscr);
X				touchwin(dirw);
X				wrefresh(dirw);
X				touchwin(scrw);
X				wrefresh(scrw);
X				break;
X
X			default:
X				sprintf(s80,"illegal command: %c",
X					(isprint(cmd)) ? cmd : '?');
X				dirw_bot_msg(s80);
X				break;
X		}
X	}
X	if(cmd == DIAL)
X		return;
X	pde_list_save_if_dirty();
X	windows_end(dirw);
X	if(rcvr_active)
X		start_rcvr_process(0);
X}	/* end of pde_list_manager */
X
X/*+-------------------------------------------------------------------------
X	choose_line(baud) - user is dialing a remote and will take 'Any' line
X--------------------------------------------------------------------------*/
Xvoid
Xchoose_line(baud)
Xuint baud;
X{
Xstruct dvent *dve;
Xchar s32[32];
X
X/* check out current line choice */
X	if(access(Lline,6))
X		goto GET_LINE_THAT_MATCHES_BAUD;
X	dve = getdvline(Lline + 8);
X	enddvent();
X	if(!dve)	/* if no match in Devices, let ecu fend for itself */
X		return;
X
X/* if Lline is open and baud rate ok, no further */
X	if(Liofd > 0)
X	{
X		if((dve->low_baud <= baud) && (baud <= dve->high_baud))
X			return;
X		lclose();	/* won't do ... gotta find a new one */
X		goto GET_LINE_THAT_MATCHES_BAUD;
X	}
X
X/* see if Lline in use by someone else; if not and baud rate ok, no further */
X	switch(utmp_status(Lline))
X	{
X		case US_NOTFOUND:	/* not in utmp, or getty dead */
X			if(line_locked(Lline))
X				goto GET_LINE_THAT_MATCHES_BAUD;
X		case US_LOGIN:		/* enabled for login, idle */
X			if((dve->low_baud <= baud) && (baud <= dve->high_baud))
X				return;
X	}
X
X/* we've got to pick a new line */
XGET_LINE_THAT_MATCHES_BAUD:
X
X	strcpy(s32,"/dev/tty");
X	while(1)
X	{
X		if(!(dve = getdvbaud(baud)))
X		{
X			enddvent();		/* no match ... */
X			return;			/* ... so let Lline ring bell */
X		}
X		if(!strcmp(dve->line,Lline + 5)) /* by now, we know Lline wont work */
X			continue;
X		strcpy(&s32[8],dve->line + 3);	/* yeech ... make "/dev/ttyxx" */
X		switch(utmp_status(s32))
X		{
X			case US_NOTFOUND:	/* not in utmp, or getty dead */
X			case US_LOGIN:		/* enabled for login, idle */
X				strcpy(Lline,s32);		/* @@@@@@@@@@@@@@ MATCH @@@@@@@@@ */
X				Lline[9] = to_lower(Lline[9]);
X				return;
X		}
X	}
X	/*NOTREACHED*/
X
X}	/* end of choose_line */
X
X/*+-------------------------------------------------------------------------
X	copy_pde_to_lvar(tpde)
X
Xif changing line, close old line and open new one
X--------------------------------------------------------------------------*/
Xvoid
Xcopy_pde_to_lvar(tpde)
Xregister PDE *tpde;
X{
Xint reopen = 0;
Xint lerr;
X
X	if(tpde->tty[0])
X	{
X		if(Lline[0] && Lline[8] && strcmp(tpde->tty,Lline + 8))
X		{
X			reopen = 1;
X			Lmodem_already_init = 0;
X			lclose();
X		}
X		strcpy(Lline,"/dev/tty");
X		strcat(Lline,tpde->tty);
X	}
X	else
X		choose_line(tpde->baud);
X
X	if(Liofd < 0)
X		reopen = 1;
X	strcpy(Llogical,tpde->logical);
X	strcpy(Ldescr,tpde->descr);
X	strcpy(Ltelno,tpde->telno);
X	if(!Ldescr[0])
X		strcpy(Ldescr,Llogical);
X	Lparity = tpde->parity;
X	if(Lbaud != tpde->baud)
X		Lmodem_already_init = 0;
X	Lbaud =tpde->baud;	
X	if(reopen)
X	{
X		if(lerr = lopen())
X		{
X			curbotleft();
X			pprintf("%s: %s\n",Lline,lopen_err_text(lerr));
X			hangup(HANGUP_LINE_OPEN_ERROR);
X		}
X	}
X	else
X	{
X		lset_baud_rate(1);
X		lset_parity(1);
X	}
X
X}	/* end of copy_pde_to_lvar */
X
X/*+-----------------------------------------------------------------------
X	lookup_logical_telno()
X
XA logical telephone number is either a symbolic identifer
Xor an lcb->telno telephone number.  A symbolic identifer is a string
Xwhose initial character is a letter.
XAn lcb->telno telephone number begins with a numeral.
X
XThis function converts a logical telephone number 
Xto a telephone number (suitable for dialing by a Hayes or
Xcompatible modem).  It is called by command line processing
Xwhen 'ecu logical-name' is specified or in response to
Xa %dial logical-name.  It is not used by the curses directory
Xmanager.
X
XIf the first character of 'Llogical' is a digit, the entire
Xinput string is copied to 'Ltelno'.  If 'Llogical' has a 
Xnon-numeric first character, then the user's home directory is
Xsearched for the file .ecu/phone (~/.ecu/phone). The file is a series
Xof records terminated with a newline.  Each record has two or three
Xfields separated by colons.  The first field is the logical telephone
Xnumber and the second field is the telephone number.  The third
X(optional) field contains a string to further identify the telephone
Xnumber being called.
X
XCASE IS INSIGNIFICANT in logical entry names for this procedure
X
XThe function returns one of the following:
X
X  1		if no error occurs
X  0		if not numeric phone number and logical string not found in file.
X
X------------------------------------------------------------------------*/
Xlookup_logical_telno()
X{
Xregister PDE *tpde;
X
X	if(!pde_list_quan)
X	{
X		if(pde_list_read())
X			return(0);
X	}
X
X/* if literal phone number, return it immediately */
X
X	if(isdigit(Llogical[0]))
X	{
X		strcpy(Ltelno,Llogical);
X		strcpy(Ldescr,Llogical);
X		return(1);
X	}
X
X/* if logical phone number */
X	if(tpde = pde_list_search(Llogical,0))	/* inexact search */
X	{
X		copy_pde_to_lvar(tpde);
X		return(1);
X	}
X
X	Llogical[0] = 0;
X	Ltelno[0] = 0;
X	Ldescr[0] = 0;
X	return(0);
X
X}	/* end of lookup_logical_telno */
X/* end of ecuphone.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File ecuphone.c is complete"
chmod 0644 ecuphone.c || echo "restore of ecuphone.c fails"
echo "x - extracting ecuphrase.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuphrase.c &&
X/* CHK=0x29B5 */
X/*+-----------------------------------------------------------------
X	ecuphrases.c
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	phrase_help()
X	phrases(nargc,nargv)
X	read_phrases()
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
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
Xchar *malloc();
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			== NULL) ||
X		   ((phrases_label[phrases_count] = malloc(strlen(phrases_lbl) + 2))
X			== NULL) )
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			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		stand_out();
X		ff(se,
X" # |  mnemonic    |     phrase                                              ");
X		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
chmod 0644 ecuphrase.c || echo "restore of ecuphrase.c fails"
echo "x - extracting ecurcvr.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecurcvr.c &&
X/* CHK=0x46C3 */
X#define ANSI_DEBUG
X#define ANSI_DEBUG_2
X/*+-------------------------------------------------------------------------
X	ecurcvr.c -- rcvr process + ANSI filter
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	ansi_CUB()
X	ansi_CUD()
X	ansi_CUF()
X	ansi_CUP()
X	ansi_CUU()
X	ansi_DSR()
X	ansi_ED()
X	ansi_SGR()
X	ansi_filter_control(mode)
X	ansi_log_unknown(ansi,ansilen)
X	ibm_crock_restore_cursor()
X	ibm_crock_save_cursor()
X	lget_ansi()
X	lgetc_rcvr()
X	lrdchk_rcvr()
X	rcvr()
X	rcvr_log_open()
X	rcvr_saw_escape()
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
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 */
X
Xextern int want_bell_notify;
Xextern int tcap_LINES;	/* terminal line quantity -- see ecutcap.c */
Xextern int tcap_COLS;	/* terminal column quantity -- see ecutcap.c */
X
X#define MAX_ANSI_LEN	30	/* generous */
Xstatic char esc = ESC;
X#if defined(ANSI_DEBUG)
Xstatic FILE *dbg = NULL;
X#endif
Xchar *ansi;
Xchar ansibuf[MAX_ANSI_LEN];
Xint ansilen;
Xint ansi_filter = 1;
Xint ansi_y = 1;
Xint ansi_x = 1;
Xint ibm_crock_y = 1;
Xint ibm_crock_x = 1;
X
X#define RCVR_RDQUAN		250
Xchar xenix_lgetc_buf[RCVR_RDQUAN];
Xchar *xenix_lgetc_ptr;
Xint xenix_lgetc_count = 0;
Xint xenix_vmin;				/* quick copy of current vmin value */
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(!xenix_lgetc_count)
X	{
X		if(xenix_vmin == 1)
X		{
X			char_rtnd = lgetc_xmtr();
X			return(char_rtnd);
X		}
X		xenix_lgetc_ptr = xenix_lgetc_buf;
XREAD_AGAIN:
X		errno = 0;
X		if((xenix_lgetc_count = read(Liofd,xenix_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		shmr_rcvd_chars(xenix_lgetc_count);
X	}
X	if(!xenix_lgetc_count)
X		goto READ_AGAIN;
X
X	xenix_lgetc_count--;
X	return(*xenix_lgetc_ptr++);
X}	/* end of lgetc_rcvr */
X
X/*+-------------------------------------------------------------------------
X	lrdchk_rcvr() -- rdchk(Liofd) for rcvr
X--------------------------------------------------------------------------*/
Xint
Xlrdchk_rcvr()
X{
X	return(xenix_lgetc_count + rdchk(Liofd));
X}	/* end of lrdchk_rcvr */
X
X/*+-------------------------------------------------------------------------
X	ansi_filter_control(mode)
Xcalled by ecushm.c receiver SIGUSR2 XDSX_SET_RCVR_ANSI handler
X--------------------------------------------------------------------------*/
Xvoid
Xansi_filter_control(mode)
X{
X	ansi_y = 1;
X	ansi_x = 1;
X	ibm_crock_y = 1;
X	ibm_crock_x = 1;
X
X	switch(mode)
X	{
X		case 0:
X		case 1:
X#if defined(ANSI_DEBUG)
X			if(dbg)
X			{
X				fclose(dbg);
X				dbg = NULL;
X			}
X#endif
X			break;
X		case 2:
X#if defined(ANSI_DEBUG)
X			if(!dbg)
X			{
X				dbg = fopen("/tmp/ansi.log","a");
X				setbuf(dbg,NULL);
X			}
X#endif
X			break;
X	}
X	ansi_filter = mode;
X}	/* end of ansi_filter_control */
X
X/*+-------------------------------------------------------------------------
X	ansi_log_unknown(ansi,ansilen)
X--------------------------------------------------------------------------*/
X#if defined(ANSI_DEBUG)
Xansi_log_unknown(ansi,ansilen)
Xregister char *ansi;
Xregister ansilen;
X{
X	if(dbg)
X		fprintf(dbg,"unknown: %c %2d %s\n",ansi[ansilen - 1],ansilen,ansi);
X}	/* end of ansi_log_unknown */
X#endif
X
X/*+-------------------------------------------------------------------------
X	lget_ansi()
Xreturns 0 if no chars read (escape incoming with no chars following)
Xelse positive count of ansi string
Xelse negative count of string not terminated with alpha character
X--------------------------------------------------------------------------*/
Xint
Xlget_ansi()
X{
Xregister char *cptr = ansibuf;
Xregister count = 0;
Xregister timeout_counter;
Xlong quantum;
Xint quantum_count = 0;
Xint max_count = MAX_ANSI_LEN;
Xlong nap(long);
X
X#ifdef BAUD_SENSITIVE
X	switch(Lbaud)
X	{
X		case 110:   quantum_count = 40; quantum = 80L; break;
X		case 300:
X		case 600:   quantum_count = 30; quantum = 40L; break;
X		case 1200:
X		case 2400:  quantum_count = 15; quantum = 40L; break;
X		case 4800:
X		case 9600: 
X		case 19200:	/* since these modems might be jerkey packetized */
X		case 38400: quantum_count = 40; quantum = 20L; break;
X	}
X#else
X/* since connections could go though packet switches, delay between
Xchars could be lengthy */
X	quantum_count = 250;
X	quantum = 40L;
X#endif
X
X	max_count--;				/* leave room for null */
X
X	timeout_counter = quantum_count;			/* first timeout */ 
X	*cptr = 0;									/* init result string */
X	while(timeout_counter--)
X	{
X		nap(quantum);
X		while(lrdchk_rcvr())
X		{
X			*cptr = lgetc_rcvr();
X			count++;
X			if(isalpha(*cptr) || (*cptr == '@') || (*cptr == '`'))
X			{
X				cptr++;
X				goto READ_ANSI_RTN;
X			}
X			if(!isprint(*cptr))
X				goto READ_ANSI_RTN_NEGATIVE;
X			cptr++;
X			if(--max_count == 0)
X				goto READ_ANSI_RTN_NEGATIVE;
X#ifdef BAUD_SENSITIVE
X			timeout_counter = quantum_count;
X#endif
X		}
X	}
X
X#if defined(ANSI_DEBUG)
X	if(dbg)
X		hex_dump_fp(dbg,ansibuf,count,"timeout",1);
X	count = -count;
X	goto READ_ANSI_RTN;
X#endif
X
XREAD_ANSI_RTN_NEGATIVE:
X#if defined(ANSI_DEBUG)
X	if(dbg)
X		hex_dump_fp(dbg,ansibuf,count,"logic_fail",1);
X#endif
X	count = -count;
X
XREAD_ANSI_RTN:
X	*cptr = 0;
X	if(rcvr_log && rcvr_log_raw)
X		fprintf(rcvr_log_fp,"\033%s",ansibuf);
X	return(count);
X}	/* end of lget_ansi */
X
X/*+-------------------------------------------------------------------------
X	ansi_SGR()
X
XThe PC world expects to be able to be able to chain 0,1 and 3x,4x params
Xtogether with semicolons.
X--------------------------------------------------------------------------*/
Xvoid
Xansi_SGR()
X{
Xregister itmp;
Xchar SGRstr[MAX_ANSI_LEN];
Xchar *token;
Xchar *str_token();
X
X#if defined(ANSI_DEBUG_2)
X	if(dbg)
X		hex_dump_fp(dbg,ansi,ansilen,"SGR",1);
X#endif
X
X	if(ansilen <= 3)	/* 'ESC[<0-9>m' and 'ESC[m' -- quickly handled */
X	{
X		sprintf(SGRstr,"\033%s",ansi);
X		write(TTYERR,SGRstr,ansilen + 1);
X		return;
X	}
X
X/* check XENIX 'ESC[<2,3,7>m' extensions */
X	switch(itmp = atoi(ansi + 1))
X	{
X		case 7: /* XENIX 'ESC[7;<0-15>;<0-15>m' set fore/background color */
X			itmp = atoi(ansi + 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			sprintf(SGRstr,"\033[%s",ansi);
X			write(TTYERR,SGRstr,ansilen + 1);
X			return;
X		default:
X			break;
X	}
X
X/* not XENIX extension */
X	ansi[ansilen - 1] = 0;	/* get rid of 'm' */
X	ansi++;					/* get rid of '[' */
X
X	while((token = str_token(ansi,";")) != NULL)
X	{
X		ansi = NULL;	/* 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 param_count = 0;
Xchar ansicopy[MAX_ANSI_LEN];
Xregister char *cptr = ansicopy;
Xregister char *token;
Xchar *str_token();
X
X	strcpy(cptr,ansi + 1);
X	*(cptr + ansilen - 2) = 0;
X
X#if defined(ANSI_DEBUG_2)
X	if(dbg)
X		hex_dump_fp(dbg,cptr,strlen(cptr),"CUP",1);
X#endif
X
X	while((token = str_token(cptr,";")) != NULL)
X	{
X		cptr = NULL;	/* further calls to str_token need NULL */
X		switch(++param_count)
X		{
X			case 1:	ansi_y = atoi(token); break;
X			case 2:	ansi_x = atoi(token); break;
X		}
X	}
X	switch(param_count)
X	{
X		case 0:
X			ansi_y = 1;
X		case 1:
X			ansi_x = 1;
X	}
X#if defined(ANSI_DEBUG_2)
X	if(dbg)
X		fprintf(dbg,"CUP count=%d cur %d,%d\n",param_count,ansi_y,ansi_x);
X#endif
X
X}	/* end of ansi_CUP */
X
X/*+-------------------------------------------------------------------------
X	ansi_CUU() - cursor up
X--------------------------------------------------------------------------*/
Xvoid
Xansi_CUU()
X{
Xregister count;
X	if(ansilen == 2)		/* no param */
X		count = 1;
X	else
X		count = atoi(ansi + 1);
X
X	ansi_y -= count;
X	if(ansi_y < 1)
X		ansi_y = 1;
X#if defined(ANSI_DEBUG_2)
X	if(dbg)
X		fprintf(dbg,"CUU count %d cur %d,%d\n",count,ansi_y,ansi_x);
X#endif
X}	/* end of ansi_CUU */
X
X/*+-------------------------------------------------------------------------
SHAR_EOF
echo "End of part 7"
echo "File ecurcvr.c is continued in part 8"
echo "8" > s2_seq_.tmp
exit 0
-- 
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation       ...!gatech!emory!tridom!wht 
Ker-au'-lo-phon.  An 8-foot partial flue-stop, having metal pipes
surmounted by adjustable rings, and with a hole bored near the top
of each pipe, producing a soft and "reedy" tone.