ecu - SCO XENIX V/{2,3}86 Extended CU part 04/47

Warren Tucker wht at tridom.uucp
Mon Oct 9 07:43:07 AEST 1989


---- Cut Here and unpack ----
#!/bin/sh
# this is part 4 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecuhayes.c continued
#
CurArch=4
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 ecuhayes.c"
sed 's/^X//' << 'SHAR_EOF' >> ecuhayes.c
X	interrupt = 0;
X
X}	/* end of hayes_get_result */
X
X/*+-------------------------------------------------------------------------
X	hayes_modem_init()
X--------------------------------------------------------------------------*/
Xhayes_modem_init()
X{
Xregister itmp;
Xint retries = 0;
Xchar *cmd;
Xchar *cptr;
Xchar ctmp;
X
X	if(Lmodem_already_init)
X		return(0);
X
X	interrupt = 0;
X	hayes_read_modem_init();
X
X	lputs_paced(0,"\b\b\b\b\b\b\b\b\b\r");
X	nap(200L);
X	lflush(0);
X
X	while(!Lmodem_already_init)
X	{
XINIT_LOOP:
X		if(retries > 3)
X			return(-1);
X
X		if(interrupt)
X			return(-1);
X
X		if(retries)
X		{
X			ltoggle_dtr();
X			lputs_paced(0,"AT\r");
X			nap(400L);
X			lputs_paced(0,"ATQ0V1E1\r");
X			nap(400L);
X		}
X
X		lflush(0);
X		cmd = Lmodem_init;
X		itmp = 0;
X#ifdef NEUROTIC
X		while(*cmd)
X		{
X			lputc_paced(0,*cmd++);
X			if(++itmp < 2)
X				nap(40L);
X			if((itmp = lgetc_timeout(500L)) < 0)
X			{
X				if(interrupt)
X					return(-1);
X				retries++;
X				goto INIT_LOOP;
X			}
X			pputc(itmp);
X		}
X#else
X		lputs(cmd);
X		pputs(cmd);
X#endif
X
X		pputc(NL);
X		lputc_paced(0,CR);
X
X		itmp = 0;
X		while(itmp != CR)
X		{
X			if((itmp = lgetc_timeout(500L)) < 0)
X			{
X				if(interrupt)
X					return(-1);
X				pputs("missed reading \\r\n");
X				retries++;
X				goto INIT_LOOP;
X			}
X		}
X
X		if(strcmp(cptr = hayes_get_result(1200L),"OK"))
X		{
X			if(!strcmp(cptr,interrupted_string))
X			{
X				interrupt = 1;
X				return(-1);
X			}
X			pprintf("unexpected result: '%s'\n",cptr);
X			retries++;
X			continue;
X		}
X		Lmodem_already_init = 1;
X	}
X
X	return(0);
X
X}	/* end of hayes_modem_init */
X
X/*+-------------------------------------------------------------------------
X	hayes_send_cmd(cmd)
X--------------------------------------------------------------------------*/
Xint
Xhayes_send_cmd(cmd)
Xregister char *cmd;
X{
Xregister itmp;
Xregister char_count = 0;
Xchar s32[32];
X
X	hayes_modem_init();
X	nap(600L);
X
X	lflush(0);
X#ifdef NEUROTIC
X	while(*cmd)
X	{
X		lputc_paced(20,*cmd++);
X		if(++char_count < 2)
X			nap(40L);
X		if((itmp = lgetc_timeout(500L)) < 0)
X			return(-1);
X		pputc(itmp);
X	}
X#else
X	lputs(cmd);
X	pputs(cmd);
X#endif
X	pputc(NL);
X	lputc_paced(20,CR);
X	itmp = 0;
X	while(itmp != CR)
X	{
X		if((itmp = lgetc_timeout(500L)) < 0)
X		{
X			pputs("missed reading \\r\n");
X			return(-1);
X		}
X		if(itmp == CR)
X			break;
X	}
X	return(0);
X
X}	/* end of hayes_send_cmd */
X
X/*+-------------------------------------------------------------------------
X	hayes_report_iv_set(varnum)
X--------------------------------------------------------------------------*/
Xhayes_report_iv_set(varnum)
Xint varnum;
X{
X
X	if(proctrace)
X		pprintf("modem handler set $i%02d = %ld\n",varnum,iv[varnum]);
X}	/* end of hayes_report_iv_set */
X
X/*+-----------------------------------------------------------------------
X	hayes_dial() - dial a remote or connect
X
X  returns 0 on success (CONNECT),
X          eConnectFailed if failure
X          eCONINT on interrupt
X
X  sets I0 to 0==connect,
X             1==failed to connect,
X             2==interrupted
X             3==modem error
X  sets S0 to modem result code or uucp status code string
X
X  This function has gotten quite NASTY and needs rewriting!
X------------------------------------------------------------------------*/
Xint
Xhayes_dial()
X{
Xchar s128[128];
Xint rcvr_was_alive = (rcvr_pid > 0) || (rcvr_pid == -2);
Xextern char kbdintr;		/* current input INTR */
Xint erc;
Xint s7;
Xint lerr;
Xint hack_fd;
Xchar *result = "";
Xuint connect_baud;
Xulong colors_at_entry = current_colors;
X
X	if(rcvr_was_alive && (rcvr_pid != -2))
X	{
X		kill_rcvr_process(SIGUSR1);
X		nap(500L);
X	}
X
X	if(Ldescr[0])
X	{
X		setcolor(0x07000A00L);	/* lt_green */
X		pprintf("%s %s (%u baud) on %s\n",
X			(Ltelno[0]) ? "Dialing" : "Connecting to",Ldescr,Lbaud,Lline);
X	}
X
X	setcolor(0x07000E00L);	/* yellow */
X
X	if(!Ltelno[0])	/* if no phone number, direct connect */
X	{
X		sprintf(s128,"CONNECT %u",Lbaud);
X		result = s128;
X		iv[0] = 0;
X		erc = 0;
X		goto START_RCVR_PROCESS;
X	}
X 	else
X	{
X		switch(hdb_dial(&result))
X		{
X			case 0:		/* success */
X				goto CONNECTED;
X			case 1:		/* failure -- iv[0] set by hdb_dial */
X				hayes_report_iv_set(0);
X				erc = eConnectFailed;
X				goto START_RCVR_PROCESS;
X			case 2:		/* interrupted -- iv[0] set by hdb_dial */
X				hayes_report_iv_set(0);
X				erc = eCONINT;
X				goto START_RCVR_PROCESS;
X			case 3:		/* modem error */
X				setcolor(0x07000400L);	/* red */
X				pprintf("%s\n",result);
X				goto CANNOT_TALK_TO_MODEM;
X			case 4:		/* try local */
X				break;
X		}
X
X		hayes_modem_init();
X
X#if defined(USE_S7)
X		if((s7 = hayes_get_sreg_value(7)) < 0)
X			s7 = 30;
X#else
X		s7 = 30;
X#endif
X
X		/* build and send dial command */
X		strcpy(s128,Lmodem_dial);
X		strcat(s128,Ltelno);
X		if(hayes_send_cmd(s128))
X			goto SEND_CMD_ERROR;
X
X		/* some modems (ahem, the Hayes 2400) do not accurately honor S7
X		so our timer is twice sreg 7 */
X 		pprintf("Type %s to abort ... ",make_char_graphic(kbdintr,1));
X		lflush(0);
X		result = hayes_get_result(s7 * 2 * 1000L);
X
X		if(!strcmp(result,interrupted_string))
X		{
X			setcolor(0x07000400L);	/* red */
X			pprintf("%s\n",result);
X			lputc(0);				/* make modem go on hook */
X			nap(40L);
X			lputc(0);
X			interrupt = 0;
X			hayes_get_result(2000L);	/* wait for NO CARRIER */
X			erc = eCONINT;
X			iv[0] = 2;
X			hayes_report_iv_set(0);
X			goto START_RCVR_PROCESS;
X		}
X		if(!strncmp(result,"CONNECT",7))
X		{
X			if(strlen(result) > 7)
X			{
X				if(Lbaud != (unsigned)atoi(result + 7))
X				{
X					setcolor(0x07000400L);	/* red */
X					pprintf("%s (incorrect rate)\n",result);
X					iv[0] = 2;
X					hayes_report_iv_set(0);
X					goto START_RCVR_PROCESS;
X				}
X			}
XCONNECTED:
X			setcolor(0x07000A00L);	/* lt_green */
X			pprintf("%s\n",result);
X			sprintf(s128,"CONNECT %s (%s) %u baud",Llogical,Ltelno,Lbaud);
X			ecu_log_event(s128);
X			if(isalpha(Llogical[0]))
X				if(keyset_read(Llogical) != 0)
X					keyset_init();
X			shmx_connect();
X			xmit_chars_this_connect = 0L;
X			Loff_hook_time = time((long *)0);
X			iv[0] = 0;
X			hayes_report_iv_set(0);
X			erc = 0;
X			Lmodem_off_hook = 1;
X			goto START_RCVR_PROCESS;
X		}
X		setcolor(0x07000400L);	/* red */
X		pprintf("%s\n",result);
X		iv[0] = 1;
X			hayes_report_iv_set(0);
X		erc = eConnectFailed;
X		goto START_RCVR_PROCESS;
X	}
X
XLMODEM_OFF_HOOK:
X	Lmodem_off_hook = 1;
X
XSTART_RCVR_PROCESS:	;
X	setcolor(colors_at_entry);
X	strcpy(sv[0]->pb,result);
X	sv[0]->cb = strlen(result);
X	if(rcvr_was_alive)
X		start_rcvr_process(1);
X	return(erc);
X
XSEND_CMD_ERROR: ;
X	if(interrupt || proc_interrupt)
X	{
X		result = interrupted_string;
X		iv[0] = 2;
X		hayes_report_iv_set(0);
X		erc = eCONINT;
X	}
X	else
X	{
XCANNOT_TALK_TO_MODEM:
X		setcolor(0x07000400L);	/* red */
X		pprintf("Cannot talk to modem\n");
X		result = "!Modem Error";
X		iv[0] = 3;
X		hayes_report_iv_set(0);
X		erc = eConnectFailed;
X	}
X	goto START_RCVR_PROCESS;
X
X}	/* end of hayes_dial */
X
X/*+-------------------------------------------------------------------------
X	hayes_dial_pde(tpde)
Xcurses access dial command
X--------------------------------------------------------------------------*/
Xint
Xhayes_dial_pde(tpde)
Xregister PDE *tpde;
X{
X	copy_pde_to_lvar(tpde);
X	hayes_dial();
X	
X}	/* end of hayes_dial_pde */
X
X/*+-------------------------------------------------------------------------
X	hayes_redial(arg,argc)
X--------------------------------------------------------------------------*/
Xhayes_redial(arg,argc)
Xchar **arg;
Xint argc;
X{
Xint erc;
Xint delay = 15;
Xint retries = 10;
Xint throw_away;
Xchar *pargv[2];
X
X	if(Ltelno[0] == 0)
X	{
X		pprintf("   no previous number\n");
X		return(-1);
X	}
X
X	if((argc > 1) && ((retries = atoi(arg[1])) == 0))
X	{
X		pprintf("  invalid retry count\n");
X		return(-1);
X	}
X
X	if((argc > 2) && ((delay = atoi(arg[2])) == 0))
X	{
X		pprintf("  invalid delay\n");
X		return(-1);
X	}
X/*
X	if(delay < 15)
X		delay = 15;
X*/
X
X	pprintf("  for %d retries, pause between: %d secs\n",
X				retries,delay);
X
X	kill_rcvr_process(SIGUSR1);		/* kill rcvr process */
X
X	while(retries--)
X	{
X	register itmp;
X
X#ifdef AUTO_DIAL_PROC
X		if(!isdigit(Llogical[0]) && find_procedure(Llogical))
X		{
X			pargv[0] = Llogical;
X			pargv[1] = "!REDIAL;";
X			if(!(erc = icmd_do_proc(2,pargv)))
X				return(0);
X			nap(100L);
X			kill_rcvr_process(SIGUSR1);		/* kill rcvr process */
X		}
X		else if(!(erc = hayes_dial()))
X		{
X			start_rcvr_process(1);
X			return(0);
X		}
X#else
X		if(!(erc = hayes_dial()))
X		{
X			start_rcvr_process(1);
X			return(0);
X		}
X#endif
X
X		if((retries == 0) || (erc == eCONINT))
X			break;
X
X		pprintf("%d %s left ... ",retries,(retries == 1) ? "retry" : "retries");
X		pprintf("waiting %d seconds ... press any key to abort\n",delay);
X		for(itmp = 0; itmp < delay; itmp++)
X		{
X			sleep(1);
X			if(rdchk(TTYIN))
X			{
X				throw_away = ttygetc(1);
X				retries = 0;
X				break;
X			}
X		}
X	}
X
X	start_rcvr_process(1);
X	return(-1);
X
X}	/* end of hayes_redial */
X
X/*+-------------------------------------------------------------------------
X	hayes_modem_on_hook()
X--------------------------------------------------------------------------*/
Xvoid
Xhayes_modem_on_hook()
X{
Xchar s128[128];
Xlong connect_secs;
Xlong time();
Xchar *get_elapsed_time();
X
X	if(Lmodem_off_hook)
X	{
X		connect_secs = time((long *)0) - Loff_hook_time;
X		sprintf(s128,"DISCONNECT %s (%s) %ld %s",Llogical,Ltelno,connect_secs,
X			get_elapsed_time(connect_secs));
X		ecu_log_event(s128);
X	}
X	Lmodem_off_hook = 0;
X}	/* end of hayes_modem_on_hook */
X
X/*+-------------------------------------------------------------------------
X	hayes_ATH()
X--------------------------------------------------------------------------*/
Xvoid hayes_ATH()
X{
Xint ixon;
Xint ixoff;
Xint rcvr_was_alive = (rcvr_pid > 0);
Xchar s64[64];
X
X	if(rcvr_was_alive)
X	{
X		kill_rcvr_process(SIGUSR1);
X		nap(500L);
X	}
X
X	ltoggle_dtr();
X	hayes_modem_on_hook();
X	set_default_escape_prompt();
X	if(rcvr_was_alive)
X		start_rcvr_process(0);
X
X}	/* end of hayes_ATH */
X
X/*+-------------------------------------------------------------------------
X	hayes_get_sreg_value(regnum)
X assumes rcvr process has been killed
X--------------------------------------------------------------------------*/
Xint
Xhayes_get_sreg_value(regnum)
Xint regnum;
X{
Xchar s128[128];
XLRWT	lr;
X
X	sprintf(s128,"ATS%d?",regnum);
X	hayes_send_cmd(s128);
X	lflush(0);
X	lr.to1 = 2000L;
X	lr.to2 = 140L;
X	lr.raw_flag = 0;
X	lr.buffer = s128;
X	lr.bufsize = sizeof(s128);
X	lr.delim = (char *)0;
X	lr.echo = 0;
X	lgets_timeout(&lr);
X	if(lr.count != 3)
X		return(-1);
X	return(atoi(s128));
X
X}	/* end of hayes_get_sreg_value */
X
X/*+-------------------------------------------------------------------------
X	hayes_set_sreg(regnum,value)
X assumes rcvr process has been killed
X returns 0 if no error (reads back value set),
X else -1 and error message has been printed
X--------------------------------------------------------------------------*/
Xint
Xhayes_set_sreg(regnum,value)
Xint regnum;
Xint value;
X{
Xchar s128[128];
Xint value2;
XLRWT	lr;
X
X	sprintf(s128,"ATS%d=%d",regnum,value);
X	hayes_send_cmd(s128);
X	lflush(0);
X	lr.to1 = 2000L;
X	lr.to2 = 140L;
X	lr.raw_flag = 0;
X	lr.buffer = s128;
X	lr.bufsize = sizeof(s128);
X	lr.delim = (char *)0;
X	lr.echo = 0;
X	lgets_timeout(&lr);
X	value2 = hayes_get_sreg_value(regnum);
X	if(value2 < 0)
X		pprintf("PROBLEM setting modem S%d=%d; cannot talk to modem\n",
X				regnum,value);
X	else if(value != value2)
X		pprintf("PROBLEM setting modem S%d=%d; got %d back\n",
X				regnum,value,value2);
X	return((value != value2) ? -1 : 0);
X
X}	/* end of hayes_set_sreg */
X
X/*+-------------------------------------------------------------------------
X	hayes_autoanswer()
X--------------------------------------------------------------------------*/
Xvoid
Xhayes_autoanswer()
X{
X	if(!Lmodem_autoans[0])
X		return;
X	nap(200L);
X	lputs_paced(20,"AT\r");
X	nap(100L);
X	lputs_paced(20,Lmodem_autoans); /* quiet modem */
X	lputs_paced(20,"\r");
X	nap(200L);
X	lputs_paced(20,Lmodem_autoans); /* quiet modem */
X	lputs_paced(20,"\r");
X	nap(200L);
X	lflush(0);
X}	/* end of hayes_autoanswer */
X
X/* end of ecuhayes.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File ecuhayes.c is complete"
chmod 0644 ecuhayes.c || echo "restore of ecuhayes.c fails"
echo "x - extracting ecuicmaux.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuicmaux.c &&
X/* CHK=0xF521 */
X/*+-------------------------------------------------------------------------
X	ecuicmaux.c -- ecuicmd.c auxiliary functions
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	cmd_escape_str()
X	display_ascii_names()
X	nlin_nlout_control(token,narg,arg)
X	icmd_conversion(token,narg,arg)
X	icmd_log(token,narg,arg)
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 "ecuerror.h"
X#include "ecucmd.h"
X
X#if !defined(M_XENIX)
Xextern int cmd_escape;		/* icmd escape */
X#endif
Xextern int rcvr_pid;
X
Xchar rcvr_log_file[256];	/* if rcvr_log!= 0,log filename */
Xint rcvr_log = 0;		/* rcvr log active if != 0 */
XFILE *rcvr_log_fp;		/* rcvr log file */
Xint rcvr_log_append = 1;
Xint rcvr_log_raw = 0;
Xint rcvr_log_flusheach = 0;
X
X/*+-------------------------------------------------------------------------
X	cmd_escape_str()
X--------------------------------------------------------------------------*/
Xchar *
Xcmd_escape_str()
X{
X#if defined(M_XENIX)
X	return("HOME ");
X#else
Xchar *make_char_graphic();
X	return(make_char_graphic(cmd_escape,0));
X#endif
X}	/* end of cmd_escape_str */
X
X/*+-----------------------------------------------------------------------
X	display_ascii_names()
X------------------------------------------------------------------------*/
Xvoid display_ascii_names()
X{
Xregister intval;
X
X	for(intval = 0; intval < 8; intval++)
X	{
X		ff(se,"%s %3d %03o %02x ^%c | ",hex_to_ascii_name((intval)),
X				(intval),(intval),(intval),(intval) +0x40);
X		ff(se,"%s %3d %03o %02x ^%c | ",hex_to_ascii_name(intval+8),
X				intval+8,intval+8,intval+8,intval+8+0x40);
X		ff(se,"%s %3d %03o %02x ^%c | ",hex_to_ascii_name(intval+16),
X				intval+16,intval+16,intval+16,intval+16+0x40);
X		ff(se,"%s %3d %03o %02x ^%c\r\n",hex_to_ascii_name(intval+24),
X				intval+24,intval+24,intval+24,intval+24+0x40);
X	}
X	ff(se,"\r\n");
X	for(intval = 8; intval < 32; intval++)
X	{
X		ff(se,"    %3d %03o %02x  %c | ",
X				intval,intval,intval,intval);
X		ff(se,"    %3d %03o %02x  %c | ",
X				intval+32,intval+32,intval+32,intval+32);
X		ff(se,"    %3d %03o %02x  %c | ",
X				intval+64,intval+64,intval+64,intval+64);
X		ff(se,"    %3d %03o %02x  %c\r\n",
X				intval+96,intval+96,intval+96,intval+96);
X	}
X
X}	/* end of display_ascii_names */
X
X/*+-------------------------------------------------------------------------
X	icmd_conversion(token,narg,arg)
X--------------------------------------------------------------------------*/
Xvoid
Xicmd_conversion(token,narg,arg)
Xint token;
Xint narg;
Xchar **arg;
X{
Xregister itmp;
X
X	switch(token)
X	{
X	case CTxa:
X	case CToa:
X	case CTda:
X		if(narg > 1)
X		{
X		int result;
X		char format[4];
X			sprintf(format,"%%%c",to_lower(*arg[0]));
X			if(sscanf(arg[1],format,&result) == 0)
X			{
X				ff(se,"  invalid argument\r\n");
X				return;
X			}
X			result &= 0xFF;
X			if(result == ' ')
X				ff(se," == ' ' 0x20\r\n",make_char_graphic(result,1));
X			else
X				ff(se," == %s\r\n",make_char_graphic(result,1));
X		}
X		else
X		{
X			ff(se,"\r\n");
X			display_ascii_names();
X		}
X		break;
X	case CTax:
X		if(arg[1] == (char *)0)
X		{
X			ff(se,"\r\n");
X			display_ascii_names();
X			break;
X		}
X		switch(strlen(arg[1]))
X		{
X			case 1:
X				ff(se," == 0x%02x\r\n",*arg[1]);
X				break;
X			case 2:
X				if(*arg[1] == '^')
X				{
X					itmp = to_upper(*(arg[1] + 1));
X					if((itmp < '@') || (itmp > '_'))
X					{
X						ff(se,"  not a valid control character\r\n");
X						return;
X					}
X					itmp &= 0x1F;
X					ff(se," == 0x%02x %s\r\n",itmp,make_char_graphic(itmp,1));
X					break;
X				}	/* else fall thru */
X			case 3:
X				if((itmp = ascii_name_to_hex(arg[1])) > -1)
X				{
X					ff(se," == 0x%02x %s\r\n",itmp,make_char_graphic(itmp,1));
X					break;
X				}	/* else fall thru */
X			default:
X				ff(se,"  invalid ... examples of valid parameters:\r\n");
X				ff(se,"        ^A ETX  or  printable character\r\n");
X				break;
X		}
X		break;
X	default:
X		ff(se,"  invalid command\r\n");
X	}
X}	/* end of icmd_conversion */
X
X/*+-------------------------------------------------------------------------
X	icmd_log(token,narg,arg)
X--------------------------------------------------------------------------*/
Xicmd_log(token,narg,arg)
Xint token;
Xint narg;
Xchar **arg;
X{
Xregister itmp;
Xregister itmp2;
X
X	switch(token)
X	{
X	case CTloff:
X		icmd("log off");
X		break;
X	case CTllp:
X#if defined(M_XENIX)
X		icmd("log /dev/lp1");
X#endif
X		break;
X	case CTlog:
X		if(narg > 1)
X		{
X			if(minunique("off",arg[1],3))
X			{
X				if(rcvr_log == 0)	/* "off",but not logging */
X					goto RECORD_REPORT;
X				ff(se,"\r\nlogging concluded (file %s)\r\n",rcvr_log_file);
X				shmx_set_rcvr_log("",0,0,0);
X				rcvr_log = 0;
X				rcvr_log_file[0] = 0;
X				return(0);
X			}
X/* turning logging on */
X			itmp2 = -1;
X			rcvr_log_append = 1;
X			rcvr_log_raw = 0;
X			for(itmp = 1; itmp < narg; itmp++)
X			{
X				if(*arg[itmp] == '-')
X				{
X					switch(arg[itmp][1])
X					{
X						case 's': rcvr_log_append = 0; break;
X						case 'r': rcvr_log_raw = 1; break;
X						case 'f': rcvr_log_flusheach = 1; break;
X						default:
X							ff(se,"   unrecognized switch -%c\r\n",
X										arg[itmp][1]);
X							log_cmd_usage();
X							return(eFATAL_ALREADY);
X					}
X				}
X				else
X				{
X					if(itmp2 > 0)
X					{
X						ff(se,"   too many positional arguments\r\n");
X						log_cmd_usage();
X						return(eFATAL_ALREADY);
X					}
X					itmp2 = itmp;
X				}
X			}
X			if(itmp2 < 0)
X			{
X				ff(se,"   no log file name specified\r\n");
X				log_cmd_usage();
X				return(eFATAL_ALREADY);
X			}
X			if(arg[itmp2][0] != '/')	/* if log file not full path, ... */
X			{							/* ... supply current directory */
X				get_curr_dir(rcvr_log_file,
X					sizeof(rcvr_log_file) - strlen(arg[itmp2]) - 2);
X				strcat(rcvr_log_file,"/");
X				strcat(rcvr_log_file,arg[itmp2]);
X			}
X			else
X				strcpy(rcvr_log_file,arg[itmp2]);
X
X			/* try to open the file if we can */
X			rcvr_log_fp = fopen(rcvr_log_file,"a");
X			if(rcvr_log_fp != NULL)		/* if success */
X			{
X				fclose(rcvr_log_fp);
X				rcvr_log = 1;
X				shmx_set_rcvr_log(rcvr_log_file,rcvr_log_append,rcvr_log_raw,
X					rcvr_log_flusheach);
X			}
X			else		/* xmtr() could not open file */
X			{
X				ff(se,"   could not open ");
X				perror(rcvr_log_file);
X				ff(se,"\r\n");
X				return(eFATAL_ALREADY);
X			}
X		}	/* end of if argument to command */
X
XRECORD_REPORT:
X		if(rcvr_log)
X		{
X			ff(se,"\r\n%sing received %s text to %s\r\n",
X				(rcvr_log_append) ? "append" : "writ",
X				(rcvr_log_raw)    ? "raw"    : "filtered",
X				rcvr_log_file);
X			ff(se,"use \"%slog off\" to stop logging\r\n",
X					cmd_escape_str());
X		}
X		else
X		{
X			ff(se,"   not logging.\r\n");
X			ff(se,"use \"%slog <filename>\" to start logging\r\n",
X					cmd_escape_str());
X		}
X		break;
X	default:
X		ff(se,"  invalid command\r\n");
X		return(eFATAL_ALREADY);
X	}
X	return(0);
X}	/* end of icmd_log */
X
X/*+-------------------------------------------------------------------------
X	nlin_nlout_control(token,narg,arg)
X--------------------------------------------------------------------------*/
Xvoid
Xnlin_nlout_control(token,narg,arg)
Xint token;
Xint narg;
Xchar **arg;
X{
X	switch(token)
X	{
X	case CTnlin:
X		if(narg != 1)
X			Ladd_nl_incoming = yes_or_no(arg[1]);
X		ff(se,"  %sappending NL to incoming CR\r\n",
X			(Ladd_nl_incoming) ? "" : "not ");
X		break;
X	case CTnlout:
X		if(narg != 1)
X			Ladd_nl_outgoing = yes_or_no(arg[1]);
X		ff(se,"  %sappending NL to outgoing CR\r\n",
X			(Ladd_nl_outgoing) ? "" : "not ");
X		break;
X	default:
X	case CTnl:
X		ff(se,"  incoming: %s  outgoing: %s\r\n",
X			(Ladd_nl_incoming) ? "CR/LF" : "CR",
X			(Ladd_nl_outgoing) ? "CR/LF" : "CR");
X		break;
X	}
X
X	if(narg && (rcvr_pid > 0))
X		shmx_set_rcvr_nl_control();
X
X}	/* end of nlin_nlout_control */
X
X/* end of ecuicmaux.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 ecuicmaux.c || echo "restore of ecuicmaux.c fails"
echo "x - extracting ecuicmd.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuicmd.c &&
X/* CHK=0x00AA */
X/*+-----------------------------------------------------------------------
X	ecuicmd.c
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	icmd(icmd_cmd)
X	icmd_do_proc(narg,arg)
X	search_cmd_list(cmd_list,cmd)
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:09-26-1989-14:23-wht-add mkdir */
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 "esd.h"
X#include "ecufkey.h"
X
X#define NEED_P_CMD
X#include "ecucmd.h"
X
Xchar *cmd_escape_str();
X
Xextern KDE keyset_table[];
Xextern char *revision;
Xextern char curr_dir[];
Xextern char hello_str[];
Xextern char keyset_name[];
Xextern char rcvr_log_file[];	/* if rcvr_log!= 0,log filename */
Xextern int ansi_filter;
Xextern int cmd_escape;
Xextern int current_ttymode;
Xextern int errno;
Xextern int proc_level;
Xextern int proctrace;
Xextern int rcvr_log;			/* rcvr log active if != 0 */
Xextern int rcvr_log_append;	/* if true, append, else scratch */
Xextern int rcvr_log_raw;		/* if true, log all, else filter ctl chrs */
Xextern int rcvr_pid;
Xextern long xmit_chars;
Xextern long xmit_chars_this_connect;
Xextern ulong current_colors;
Xextern FILE *plog_fp;
Xextern ESD  *plog_name;
Xextern char screen_dump_file_name[];
X
Xint protocol_log_packets = 0;
Xint want_bell_notify = 1;	/* want xenix bell notify */
X
X/*+-------------------------------------------------------------------------
X	search_cmd_list(cmd_list,cmd)
Xreturns -1 if cmd not found or insufficient chars for match
Xelse token value for command
Xproc-only commands have 'min' values 0
X--------------------------------------------------------------------------*/
Xsearch_cmd_list(cmd_list,cmd)
Xregister P_CMD *cmd_list;
Xregister char *cmd;
X{
X	while(cmd_list->token != -1)
X	{
X		if(minunique(cmd_list->cmd,cmd,cmd_list->min))
X		{
X			if(cmd_list->min)
X				break;
X			return(-1);
X		}
X		cmd_list++;
X	}
X	return(cmd_list->token);
X
X}	/* end of search_cmd_list */
X
X/*+-------------------------------------------------------------------------
X	icmd_do_proc(narg,arg)
X--------------------------------------------------------------------------*/
Xicmd_do_proc(narg,arg)
Xint narg;
Xchar **arg;
X{
Xregister erc;
Xulong colors_at_entry = current_colors;
X
X	kill_rcvr_process(SIGUSR1);
X	ttymode(2);
X	erc = do_proc(narg,arg);
X	proc_file_reset();
X	ttymode(1);
X	setcolor(0x07000800L);	/* gray */
X	ff(se,"[procedure finished]");
X	setcolor(colors_at_entry);
X	ff(se,"\r\n");
X	start_rcvr_process(0);
X	return(erc);
X}	/* end of icmd_do_proc */
X
X/*+-----------------------------------------------------------------------
X	icmd(cmd)
X This function implements the built in commands
X It returns non-zero if program should terminate
X------------------------------------------------------------------------*/
Xint
Xicmd(icmd_cmd)
Xregister char *icmd_cmd;
X{
X
X#define ARG_MAX_QUAN 40
Xchar *arg[ARG_MAX_QUAN];
Xchar cmd[128];
Xint itmp;
Xint token;
Xint narg = 0;
XESD *tesd;
Xchar s80[80];
Xchar *epoch_secs_to_str();
Xlong atol();
Xlong rcvr_chars;
Xlong rcvr_chars_this_connect;
Xchar *find_procedure();
X
X	strcpy(cmd,icmd_cmd);			/* get local copy of cmd string */
X	switch(cmd[0]) 
X	{
X		case '.':		/* exit xmtr() (generally program too) */
X			ff(se,"  disconnecting from line %s\r\n",Lline);
X			return(1);
X		case '!':
X		case '$':
X		case '>':
X			ff(se,"\r\n"); shell(cmd); return(0);
X		case '-':
X			ff(se,"\r\n"); exec_cmd(&cmd[1]); return(0);
X		case '^':
X			ff(se,"\r\n"); phrase_help(); return(0);
X		case '?':
X			icmd_help(0,(char **)0); return(0);
X		default:
X			break;
X	}
X
X/* not single character argument */
X	build_str_array(cmd,arg,ARG_MAX_QUAN,&narg);
X
X/* handle phrases */
X	if(isdigit(*arg[0]))
X	{
X		phrases(narg,arg);
X		return(0);
X	}
X
X/* search command list */
X	if((token = search_cmd_list(icmd_cmds,arg[0])) < 0)
X	{
X		ff(se,"\r\n");
X		if(find_procedure(arg[0]))
X		{
X			icmd_do_proc(narg,arg);
X			return(0);
X		}
X		ff(se,"invalid command... %s? for help\r\n",
X			cmd_escape_str());
X		return(0);
X	}
X
X	switch(token)
X	{					/* keep alphabetized PLEASE */
X		case CTrx:
X		case CTry:
X		case CTrz:
X		case CTrk:
X		case CTrs:
X		receive_files_from_remote(narg,arg);
X		break;
X
X		case CTsx:
X		case CTsy:
X		case CTsz:
X		case CTsk:
X		case CTss:
X		send_files_to_remote(narg,arg);
X		break;
X
X#ifndef NOMEMCHECK
X		case CTmdump:
X		_dump_malloc();
X		break;
X#endif
X
X		case CTbaud:
X		if(narg == 1)
X			ff(se,"   baud rate is %u\r\n",Lbaud);
X		else
X		{
X			itmp = atoi(arg[1]);
X			if(!lnew_baud_rate(itmp))
X				ff(se,"   baud rate set to %u\r\n",Lbaud);
X			else
X			{
X				ff(se,"   invalid baud rate: %u\r\n",itmp);
X				ff(se,"valid rates: 110,300,600,1200,2400,4800,9600,19200\r\n");
X			}
X		}
X		break;
X
X		case CTbreak:
X		lbreak();
X		ff(se,"   break sent\r\n");
X		break;
X
X		case CTcd:
X		change_directory(arg[1],(narg == 1) ? 0 : 1);
X		break;
X
X		case CTclrx:
X		lclear_xmtr_xoff();
X		break;
X
X		case CTdial:
X		if(narg > 1)
X		{
X			ff(se,"\r\n");
X			strcpy(Llogical,arg[1]);
X			if(!lookup_logical_telno())
X				ff(se,"No such entry. Try 'dial' with no arguments\r\n");
X			else
X			{
X				if(isdigit(Llogical[0]) || !find_procedure(Llogical))
X					hayes_dial();
X				else
X				{
X					arg[0] = Llogical;
X					arg[1] = "!INTERACTIVE";
X					icmd_do_proc(2,arg);
X				}
X			}
X		}
X		else
X		{
X			pde_list_manager();
X		}
X		break;
X
X		case CTdo:
X		ff(se,"\r\n");
X		icmd_do_proc(narg - 1,&arg[1]);
X		break;
X
X		case CTptrace:
X		if(narg > 1)
X			proctrace = yes_or_no(arg[1]);
X		ff(se,"  procedure trace %s", proctrace ? "on" : "off");
X		if(proctrace > 1)
X			ff(se," (%d)",proctrace);
X		ff(se,"\r\n");
X		break;
X
X		case CTpcmd:
X		itmp = strlen(arg[0]);
X		if((tesd = make_esd(256)) == (ESD *)0)
X		{
X			ff(se,"  no memory!!?!\r\n");
X			break;
X		}
X		strcpy(tesd->pb,icmd_cmd + itmp + 1);
X		tesd->cb = strlen(tesd->pb);
X		ff(se,"\r\n");
X		kill_rcvr_process(SIGUSR1);
X		ttymode(2);
X		if(itmp = execute_esd(tesd))
X		{
X			proc_error(itmp);
X			show_esd(tesd,"");
X		}
X		free_esd(tesd);
X		ttymode(1);
X		start_rcvr_process(0);
X		break;
X
X		case CTplog:
X		fputs("  ",se);
X		if(narg > 1)
X		{
X			if(!strcmp(arg[1],"off"))
X				plog_control((char *)0);
X			else
X				plog_control(arg[1]);
X		}
X		
X		if(plog_fp)
X			ff(se,"procedure logging: %s\r\n",plog_name->pb);
X		else
X			fputs("procedure logging off\r\n",se);
X		break;
X
X		case CTduplex:
X		if(narg > 1)
X		{
X			switch(to_lower(*arg[1]))
X			{
X				case 'f': Lfull_duplex = 1; ff(se,"  now "); break;
X				case 'h': Lfull_duplex = 0; ff(se,"  now "); break;
X				default: ff(se,
X"\r\nfirst argument character must be F or H for full or half duplex\r\n");
X					break;
X			}
X		}
X		else		/* no argument */
X			ff(se,"  currently ");
X
X		ff(se,"%s duplex\r\n",(Lfull_duplex) ? "full" : "half");
X		break;
X
X		case CTexit:
X		ff(se,"  disconnecting from line %s\r\n",Lline);
X		return(1);
X
X		case CTfi:
X		file_insert_to_line(narg,arg);
X		break;
X
X		case CThangup:
X		ff(se,"   hanging up ... ");
X		hayes_ATH();
X		ff(se,"done\r\n");
X		break;
X
X		case CThelp:
X		icmd_help(narg,arg);
X		break;
X
X		case CTsdname:
X		if(narg > 1)
X		{
X		char *new_file_name;
X
X			itmp = 0;	/* do not need to free(new_file_name) */
X			if(find_shell_chars(arg[1]))
X			{
X
X				if(expand_cmd_with_wildlist(arg[1],&new_file_name))
X				{
X					ff(se,"  %s\r\n",new_file_name);
X					break;
X				}
X				itmp = 1;	/* need to free(new_file_name) */
X			}
X			else
X				new_file_name = arg[1];
X
X			screen_dump_file_name[0] = 0;
X			if(*new_file_name != '/')
X			{
X				strcpy(screen_dump_file_name,curr_dir);
X				strcat(screen_dump_file_name,"/");
X			}
X			strcat(screen_dump_file_name,arg[1]);
X			if(itmp)
X				free(new_file_name);
X		}
X		ff(se,"\r\nscreen dump name: %s\r\n",screen_dump_file_name);
SHAR_EOF
echo "End of part 4"
echo "File ecuicmd.c is continued in part 5"
echo "5" > 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.



More information about the Alt.sources mailing list