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

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

---- Cut Here and unpack ----
#!/bin/sh
# this is part 10 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecutty.c continued
#
CurArch=10
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 ecutty.c"
sed 's/^X//' << 'SHAR_EOF' >> ecutty.c
X  Defined functions:
X	color_name_to_num(cname)
X	get_ttymode()
X	get_ttyname()
X	ring_bell()
X	setcolor(new_colors)
X	ttyflush(flush_type)
X	ttygetc(xkey_ok)
X	ttygets(str,maxsize,echo_crlf)
X	ttygets_esd(tesd,echo_crlf,append_flag)
X	ttyinit()
X	ttymode(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 <sys/machdep.h>
X#include "ecu.h"
X#include "esd.h"
X#include "ecukey.h"
X#include "ecuxkey.h"
X#include "ecuerror.h"
X
X#define DEFINE_TTY_DATA
X#include "tty.h"
X
Xstatic char *dole_out_rd_char = (char *)0;
X
Xextern int interrupt;
X
Xint current_ttymode = 0;
X
Xstruct termio tty_termio_at_entry;
Xstruct termio tty_termio_current;
X
Xchar kbdeof;			/* current input EOF */
Xchar kbdeol2;			/* current secondary input EOL */
Xchar kbdeol;			/* current input EOL */
Xchar kbderase;			/* current input ERASE */
Xchar kbdintr;			/* current input INTR */
Xchar kbdkill;			/* current input KILL */
Xchar kbdquit;			/* current input QUIT */
Xint echo_erase_char;	/* save users ECHOE bit */
Xint echo_kill_char;		/* save users ECHOK bit */
Xchar kbd_is_7bit;		/* keyboard has parity */
X
Xulong current_colors = 0x00070700;	/* until we learn how to read colors
X									 * default to black and white */
Xint use_colors = 0;		/* set by ttyinit, but default no */
X
Xextern char screen_dump_file_name[];
X
X/*+-------------------------------------------------------------------------
X	color_name_to_num(cname)
X--------------------------------------------------------------------------*/
Xint
Xcolor_name_to_num(cname)
Xchar *cname;
X{
Xregister COLOR *color = colors;
Xregister itmp;
X
X	while(color->name)
X	{
X		if((itmp = strcmp(color->name,cname)) > 0)
X			return(-1);
X		if(!itmp)
X			return(color->num);
X		color++;
X	}
X	return(-1);
X
X}	/* end of color_name_to_num */
X
X/*+-------------------------------------------------------------------------
X	setcolor(new_colors)
X
Xrequires termcap init to have been done
X--------------------------------------------------------------------------*/
Xvoid
Xsetcolor(new_colors)
Xulong new_colors;
X{
X	if(!use_colors)
X		return;
X
X	/* normal */
X	ff(se,"\033[=%ldF\033[=%ldG",
X		(new_colors >> 8) & 0xFF,
X		new_colors & 0xFF);
X
X	/* reverse */
X	ff(se,"\033[=%ldH\033[=%ldI",
X		(new_colors >> 24) & 0xFF,
X		(new_colors >> 16) & 0xFF);
X
X	stand_end();
X	current_colors = new_colors;
X
X}	/* end of setcolor */
X
X/*+-------------------------------------------------------------------------
X	ring_bell()
X--------------------------------------------------------------------------*/
Xvoid
Xring_bell()
X{
X	fputc(7,se);
X}	/* end of ring_bell */
X
X/*+-------------------------------------------------------------------------
X	ttyinit()
X--------------------------------------------------------------------------*/
Xvoid
Xttyinit()
X{
Xint monitor_type;
X
X	/* save initial tty state */
X	ioctl(TTYIN,TCGETA,(char *)&tty_termio_at_entry);
X
X	interrupt = 0;			/* see xmtr signal handlers */
X
X	kbdintr =  (tty_termio_at_entry.c_cc[VINTR])
X		? (tty_termio_at_entry.c_cc[VINTR]  & 0x7F) : '\377';
X	kbdquit =  (tty_termio_at_entry.c_cc[VQUIT])
X		? (tty_termio_at_entry.c_cc[VQUIT]  & 0x7F) : '\377';
X	kbderase = (tty_termio_at_entry.c_cc[VERASE])
X		? (tty_termio_at_entry.c_cc[VERASE] & 0x7F) : '\377';
X	kbdkill =  (tty_termio_at_entry.c_cc[VKILL])
X		? (tty_termio_at_entry.c_cc[VKILL]  & 0x7F) : '\377';
X	kbdeof =   (tty_termio_at_entry.c_cc[VEOF])
X		? (tty_termio_at_entry.c_cc[VEOF]   & 0x7F) : '\04';
X	kbdeol2 =  (tty_termio_at_entry.c_cc[VEOL])
X		? (tty_termio_at_entry.c_cc[VEOL]   & 0x7F) : '\377';
X	kbdeol =   (tty_termio_at_entry.c_iflag & ICRNL)
X		? '\r' : '\n';
X
X	kbd_is_7bit = ((tty_termio_at_entry.c_cflag & PARENB) != 0);
X	if(kbd_is_7bit)
X	{
X		ff(se,"keyboard has parity enabled\n");
X		nap(2000L);
X	}
X	echo_erase_char = tty_termio_at_entry.c_lflag & ECHOE;
X	echo_kill_char = tty_termio_at_entry.c_lflag & ECHOK;
X	tty_termio_current = tty_termio_at_entry;
X	current_ttymode = 0;
X
X	get_home_dir(screen_dump_file_name);
X	strcat(screen_dump_file_name,"/.ecu/screen.dump");
X
X/* this order critical */
X	read_termcap();			/* get cursor,standout/end strings */
X	ioctl(TTYIN,CONS_GET,&monitor_type);
X	use_colors = (monitor_type != MONO);
X	setcolor(0x04070A00L);	/* fgnd: lt_green on black, bgnd: red on white */
X
X}	/* end of ttyinit */
X
X/*+-----------------------------------------------------------------------
X	ttymode(arg) -- control user console (kbd/screen)
X
X  Where arg ==
X	0 restore attributes saved at start of execution
X	1 raw mode (send xon/xoff, but do not respond to it, no ISIG/SIGINT)
X	2 raw mode (same as 1 but allow keyboard interrupts)
X	3 attributes at start of execution, but with echo disabled and no parity
X
X------------------------------------------------------------------------*/
Xvoid
Xttymode(arg)
X{
Xregister char *mode_type;
X
X	if(arg == 0)
X	{
X		ioctl(TTYIN,TCSETAW,(char *)&tty_termio_at_entry);
X		tty_termio_current = tty_termio_at_entry;
X		current_ttymode = 0;
X	}
X	else if((arg == 1) || (arg == 2))
X	{
X		tty_termio_current = tty_termio_at_entry;
X
X		tty_termio_current.c_cflag &= ~(PARENB | PARODD);
X		tty_termio_current.c_cflag |= CS8;
X
X		/* don't want to honor tty xon/xoff, but pass to other end */
X		tty_termio_current.c_iflag &=
X			~(INLCR | ICRNL | IGNCR | IXON | IUCLC | ISTRIP);
X		tty_termio_current.c_iflag |= IXOFF;	/* this end will xon/xoff */
X
X		tty_termio_current.c_oflag |= OPOST;
X		tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
X
X		tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
X		if(arg == 2)
X			tty_termio_current.c_lflag |= ISIG;
X
X		tty_termio_current.c_cc[VMIN] = 1;
X		tty_termio_current.c_cc[VTIME] = 0;
X
X		ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
X		current_ttymode = arg;
X	}
X	else if(arg == 3)
X	{
X		tty_termio_current = tty_termio_at_entry;
X		tty_termio_current.c_cflag &= ~(PARENB | PARODD);
X		tty_termio_current.c_cflag |= CS8;
X		tty_termio_current.c_iflag &= ~(ISTRIP);
X		tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
X		ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
X		current_ttymode = 3;
X	}
X}	/* end of ttymode */
X
X/*+-------------------------------------------------------------------------
X	int	get_ttymode()
X--------------------------------------------------------------------------*/
Xint
Xget_ttymode()
X{
X	return(current_ttymode);
X}	/* end of get_ttymode */
X
X/*+-----------------------------------------------------------------------
X	ttyflush(flush_type) -- flush tty driver input &/or output buffers
X
X0 == input buffer
X1 == output buffer
X2 == both buffers
X------------------------------------------------------------------------*/
Xvoid
Xttyflush(flush_type)
Xint flush_type;
X{
X	ioctl(TTYIN,TCXONC,(char *)0); /* stop tty output */
X	switch(flush_type)	/* avoid compiler warning of cast int to far ptr */
X	{
X		case 0:
X			ioctl(TTYIN,TCFLSH,(char *)0); break;
X		case 1:
X			ioctl(TTYIN,TCFLSH,(char *)1); break;
X		case 2:
X			ioctl(TTYIN,TCFLSH,(char *)2); break;
X	}
X	ioctl(TTYIN,TCXONC,(char *)1); /* restart tty output */
X#if defined(M_XENIX)
X	dole_out_rd_char = (char *)0;	/* see ttygetc() */
X#endif
X	return;
X}	/* end of ttyflush */
X
X/*+-------------------------------------------------------------------------
X	ttygetc(xkey_ok) -- get a key from the keyboard
Xif XENIX, map extended keys to sign-bit-set special value
Xif xkey_ok is 0, disallow extended keys
X--------------------------------------------------------------------------*/
Xuint
Xttygetc(xkey_ok)
Xint xkey_ok;
X{
Xuchar ctmp;
Xextern int errno;
Xregister uint itmp = 0;
Xstatic uchar rd_char[10];
X
X	if(dole_out_rd_char)		/* handle (very unlikely) FAST typist */
X	{
X		if(itmp = *dole_out_rd_char++)
X			return(itmp);
X		else
X			dole_out_rd_char = (char *)0;
X	}
X
XGET_KEY:
X	errno = 0;
X	if(read(TTYIN,&ctmp,1) < 0)
X	{
X		if(errno == EINTR)
X			goto GET_KEY;
X		perror_errmsg("keyboard");
X		hangup(HANGUP_TTYIN_READ_ERROR);
X	}
X
X	if(kbd_is_7bit)
X		ctmp &= 0x7F;
X
X	if(ctmp == ESC)	/* if escape */
X	{
X		itmp = 0;
X		nap(60L);
X		while((!isalpha(ctmp)) && (itmp < sizeof(rd_char) - 1))
X		{
X			if(rdchk(0) <= 0)
X				break;
X			read(TTYIN,&ctmp,1);
X			if(kbd_is_7bit)
X				ctmp &= 0x7F;
X			rd_char[itmp++] = ctmp;
X			nap((long)20);
X		}
X		rd_char[itmp] = 0;
X		if(!itmp)				/* no subsequent chars, so ... */
X			return(ESC);		/* return the escape */
X		else if((itmp == 2) && (rd_char[0] == '['))
X		{
X			switch(rd_char[1] | 0x80)
X			{
X				case XFcur5:
X					screen_dump(screen_dump_file_name);
X					goto GET_KEY;
X				case XFcurup: case XFcurdn: case XFcurrt: case XFcurlf:
X				case XFend: case XFpgdn: case XFhome: case XFpgup: case XFins:
X				case XF1: case XF2: case XF3: case XF4: case XF5: case XF6:
X				case XF7: case XF8: case XF9: case XF10: case XF11: case XF12:
X				case XFbktab:
X					if(xkey_ok)
X						return(rd_char[1] | 0x80);
X					/* fall thru -- xkey not allowed */
X				default:
X					ring_bell();
X					goto GET_KEY;
X			}
X		}
X		else		/* not func key -- we have a FAST typist */
X		{
X			dole_out_rd_char = rd_char;
X			return(ESC);
X		}
X	}
X	else
X		return(ctmp);
X}	/* end if ttygetc */
X
X/*+-----------------------------------------------------------------------
X	ttygets(str,maxsize,echo_crlf)
X------------------------------------------------------------------------*/
Xvoid
Xttygets(str,maxsize,echo_crlf)
Xregister char *str;
Xint maxsize;
Xint echo_crlf;
X{
Xregister inch;
Xregister curcount = 0;
X
X	--maxsize;		/* decrement for safety */
X
X	while(1)
X	{
X		inch = ttygetc(0);
X		if((inch == kbdintr) || (inch == ESC))
X		{
X			while(curcount)
X			{
X				fputc(BS,se);
X				fputc(SPACE,se);
X				fputc(BS,se);
X				curcount--;
X			}
X			*str++ = ESC;
X			*str   = 0;
X			return;
X		}
X		else if(inch == kbdkill)
X		{
X			while(curcount)
X			{
X				fputc(BS,se);
X				fputc(SPACE,se);
X				fputc(BS,se);
X				curcount--;
X			}
X			continue;
X		}
X		else if(inch == kbderase)
X		{
X			if(curcount)
X			{
X				fputc(BS,se);
X				fputc(SPACE,se);
X				fputc(BS,se);
X				curcount--;
X			}
X			continue;
X		}
X
X		switch(inch)
X		{
X			case CR:
X			case NL:
X				str[curcount] = 0;
X				if(echo_crlf)
X					ff(se,"\r\n");
X				return;
X
X
X			case CTL_L:
X			case CTL_R:
X				ff(se,"%s\r\n",make_char_graphic(inch,0));
X				fputs(str,se);
X				break;
X
X			default:
X				inch &= 0x7F;
X				if((curcount == maxsize) || (inch < SPACE) || (inch == 0x7F))
X				{
X					fputc('\7',se);
X					break;
X				}
X				str[curcount++] = inch & 0x7F;
X				fputc(inch,se);
X				str[curcount] = 0;
X				break;
X		}
X	}			/* end of while we have room left in string */
X
X}	/* end of ttygets() */
X
X/*+-------------------------------------------------------------------------
X	ttygets_esd(tesd,echo_crlf,append_flag)
X--------------------------------------------------------------------------*/
Xttygets_esd(tesd,echo_crlf,append_flag)
XESD *tesd;
Xint echo_crlf;
Xint append_flag;
X{
Xchar *pb = tesd->pb;
Xint maxcb = tesd->maxcb;
X
X	if(append_flag)
X	{
X		pb += tesd->cb;
X		maxcb -= tesd->cb;
X	}
X	else
X	{
X		pb = tesd->pb;
X		maxcb = tesd->maxcb;
X		tesd->cb = 0;
X	}
X
X	ttygets(pb,maxcb,echo_crlf);
X
X	if(*pb == ESC)
X	{
X		if(!append_flag)
X			zero_esd(tesd);
X		return(eProcAttn_ESCAPE);
X	}
X
X	tesd->cb = strlen(tesd->pb);
X	plogs(pb);
X	if(echo_crlf)
X		plogc(NL);
X	return(0);
X
X}	/* end of ttygets_esd */
X
X/*+-------------------------------------------------------------------------
X	char *get_ttyname() - return pointer to static string
X--------------------------------------------------------------------------*/
Xchar *
Xget_ttyname()
X{
Xstatic char ttname[64];
X#if BSD4
Xchar *ttyname();
X	strcpy(ttname,ttyname(0));
X	return(ttname);
X#endif
X#if defined(M_XENIX)
Xregister unsigned int rdev;
Xregister char *cptr;
Xstruct stat fst;
X
X	strcpy(ttname,"/dev/tty");
X	cptr = ttname + 8;
X
X	fstat(0,&fst);
X	rdev = (unsigned)fst.st_rdev;
X	if(rdev == 0x0301)
X		strcpy(ttname,"console");
X	else
X	{
X		if(rdev < 0x000C)
X		{
X			*cptr++ = '0' + ((rdev + 1) / 10);
X			*cptr++ = '0' + ((rdev + 1) % 10);
X		}
X		else if(!(rdev & ~0x58F))
X		{
X			*cptr++ = (rdev & 0x0008) ? '2' : '1';
X			*cptr++ = ((rdev & 0x0080) ? 'A' : 'a') + (rdev & 0x0007);
X		}
X		else
X		{
X			*cptr++ = '?';
X			*cptr++ = '?';
X		}
X		*cptr = 0;
X	}
X
X	return(ttname);
X#endif	
X}	/* end of get_ttyname */
X
X/* end of ecutty.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File ecutty.c is complete"
chmod 0644 ecutty.c || echo "restore of ecutty.c fails"
echo "x - extracting ecuuclc.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuuclc.c &&
X/* CHK=0x2EC9 */
X/*+-----------------------------------------------------------------------
X	ecuuclc.c
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	minunique(str1,str2,minquan)
X	to_lower(ch)
X	to_upper(ch)
X	ulcmpb(str1,str2)
X	ulindex(str1,str2)
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
X/*+-------------------------------------------------------------------------
X    to_upper() / to_lower()
X  one would think that these were relatively standard
X  types of thing, but MSC/Xenix specifies toupper() to convert to upper
X  case if not already and Unix says to adjust without testing,
X  so, two stupid little routines here
X  ASCII only -- no EBCDIC gradoo here please
X--------------------------------------------------------------------------*/
Xchar to_upper(ch)
Xregister char ch;
X{ return( ((ch >= 'a') && (ch <= 'z')) ? ch - 0x20 : ch);
X}   /* end of to_upper() */
X
Xchar to_lower(ch)
Xregister char ch;
X{ return( ((ch >= 'A') && (ch <= 'Z')) ? ch + 0x20 : ch);
X}   /* end of to_lower() */
X
X/*+----------------------------------------------------------------------------
X    ulcmpb(str1,str) -- Upper/Lower [case insensitive] Compare Bytes
X
X Returns -1 if strings are equal, else failing character position
X If the second strings terminates with a null and both strings have matched
X character for character until that point, then -1 is returned.
X NOTE:  this is not a test for complete equality of two strings, but allows
X discovery of a string as a substring in a larger containing string.
X-----------------------------------------------------------------------------*/
Xint
Xulcmpb(str1,str2)
Xregister unsigned char    *str1;
Xregister unsigned char    *str2;
X{
Xregister istr;
X
X    for( istr=0 ; ;  ++istr )
X    {
X        if(str2[istr] == '\0')          /* if second string exhausts, match! */
X            return(-1);
X        if((str1[istr] == '\0' ) ||
X			( to_upper(str1[istr]) != to_upper(str2[istr]) ))
X            return(istr);
X    }
X	/*NOTREACHED*/
X} /* end of ulcmpb */
X
X/*+-------------------------------------------------------------------------
X    ulindex:  Upper/Lower [case insensitive] Index functioni
X
X  Returns position of 'str2' in 'str1' if found
X  If 'str2' is null, then 0 is returned (null matches anything)
X  Returns -1 if not found
X
X  uses 'ulcmpb'
X--------------------------------------------------------------------------*/
Xint ulindex(str1,str2)
Xregister char *str1;	/* the (target) string to search */
Xregister char *str2;	/* the (comparand) string to search for */
X{
Xregister istr1 = 0;		/* moving index into str1 */
Xregister char *mstr = str1;	/* moving string pointer */
X
X    if(str2[0] == '\0')             /* null string matches anything */
X        return(0);
X	while(1)
X    {
X        if(*mstr == '\0')           /* if we exhaust target string, flunk */
X            return(-1);
X        /* Can we find either case of first comparand char in target? */
X        if( to_upper(*mstr) == to_upper(str2[0]) )
X        {
X            /* we have a first char match... does rest of string match? */
X            if(ulcmpb(mstr,str2) == -1)         /* if the rest matches, ... */
X                return(istr1);                  /* ... return match position */
X        }
X        /* we did not match this time... increment istr1, mstr and try again */
X        ++istr1;
X        ++mstr;
X    }
X}	/* end of ulindex */
X
X/*+----------------------------------------------------------------
X    minunique(str1,str2,minquan)
X
X  Returns 1 if at least 'minquan' chars of str2 match
X  str1 and there are no chars after the minimum unique
X  chars which do not match str1.  Returns 0 on failure.
X-----------------------------------------------------------------*/
Xint
Xminunique(str1,str2,minquan)
Xregister char *str1;
Xregister char *str2;
Xregister minquan;
X{
Xregister index;
X
X    if(strlen(str2) < minquan)
X        return(0);
X
X    index = ulcmpb(str1,str2);
X    if(index < 0)
X        return(1);
X
X    if(index < minquan)
X        return(0);
X	if(index < strlen(str2))
X		return(0);
X    
X    return(1);
X    
X}   /* end of minunique */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 ecuuclc.c || echo "restore of ecuuclc.c fails"
echo "x - extracting ecuusage.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuusage.c &&
X/* CHK=0x02D3 */
X/*+-----------------------------------------------------------------------
X	ecuusage.c
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	general_usage(uptr)
X	log_cmd_usage()
X	usage()
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 <stdio.h>
X#define se stderr
X
Xextern char *revision;
X
X#if !defined(M_XENIX)
Xchar *usage_text[] = 
X{
X"usage: ecu [-l /dev/tty<ttynum>] [-b <baud_rate>] [-e] [-o]\r\n",
X"           [-c <filename>] [-h] [-k] [-t] [-v[vv...]]\r\n",
X"           [-p <initial_proc> | <phone_number>]\r\n",
X"Default: 2400,N,8 (use -e for even parity, -o for odd 7 data bits)\r\n",
X"-c <filename> use this file rather than ~/.ecumodem\r\n",
X"-h half duplex ... default is full duplex\r\n",
X"-v verbosity ... the more 'v's the more verbosity.\r\n",
X"\r\n",
X"For a list of built in commands, type HOME?<ENTER> once program started\r\n",
X"\r\n",
X"For access to line with no dialing try: ecu - [-eosv]\r\n",
X"However, program default line may be busy or not exist\r\n",
X	(char *)0		/* terminated with null pointer */
X};
X#endif
X
Xchar *log_cmd_usage_text[] = 
X{
X"Usage: log [-s] [-r] <filename>\r\n",
X"       log off   turn logging off\r\n",
X" -s scratch any previous contents of <filename>, else append\r\n",
X" -r raw log, else drop 0x00-0x08,0x11-0x1F,0x7F-0xFF\r\n",
X	(char *)0		/* terminated with null pointer */
X};
X
X/*+-----------------------------------------------------------------------
X	general_usage(uptr)
X------------------------------------------------------------------------*/
Xvoid
Xgeneral_usage(uptr)
Xregister char **uptr;
X{
X	while(*uptr != (char *)0)
X		fputs(*(uptr++),se);
X}	/* end of usage */
X
X/*+-----------------------------------------------------------------------
X	usage()
X------------------------------------------------------------------------*/
Xvoid
Xusage()
X{
X#if !defined(M_XENIX)
X	ff(se,"last revised: %s\r\n",revision);
X	general_usage(usage_text);
X	exit(1);
X	/*NOTREACHED*/
X#endif
X}
X
X/*+-------------------------------------------------------------------------
X	log_cmd_usage()
X--------------------------------------------------------------------------*/
Xvoid
Xlog_cmd_usage()
X{
X	general_usage(log_cmd_usage_text);
X}	/* end of log_cmd_usage */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 ecuusage.c || echo "restore of ecuusage.c fails"
echo "x - extracting ecuutil.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuutil.c &&
X/* CHK=0x97B2 */
X/*+-----------------------------------------------------------------------
X	ecuutil.c -- utility routines for extended calling unit
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	arg_token(parsestr,termchars)
X	ascii_name_to_hex(str3char)
X	ascii_to_hex(ascii)
X	build_arg_array(cmd,arg,arg_max_quan,narg_rtn)
X	build_str_array(cmd,arg,str_max_quan,nstr_rtn)
X	disp_line_termio(fd,text)
X	disp_termio(ttt,text)
X	find_shell_chars(command)
X	get_curr_dir(currdir,currdir_max)
X	get_home_dir(home_dir)
X	hex_to_ascii_name(char_val)
X	make_char_graphic(ch,incl_3char)
X	make_dirs(pathname)
X	make_ecu_subdir()
X	mkdir(dpath,dmode)
X	mode_map(mode,mode_str)
X	pad_zstr_to_len(zstr,len)
X	perror_errmsg(str)
X	print_cwd(curdir,buf_size)
X	skip_ld_break(zstr)
X	str_token(parsestr,termchars)
X	yes_or_no(strarg)
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:10-07-1989-21:11-wht-fix arg_token+fix doc on add_token & str_token */
X/*:07-29-1989-14:39-wht-add CS5,6,7, 8 to disp_termio */
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 "ecufork.h"
X
Xchar *getenv();
X
Xextern int errno;
Xextern int rcvr_pid;		/* ==0 if rcvr process, else pid of rcvr */
Xextern char curr_dir[];
X
Xchar *ascii_ctlstr =
X"NULSOHSTXETXEOTENQACKBELBS HT NL VT FF CR SO SI DLEDC1DC2DC3DC4NAKSYNETBCANEM SUBESCFS GS RS US ";
X
Xchar home_directory[256] = "NONE YET";
X
X/*+-------------------------------------------------------------------------
X	skip_ld_break(zstr) - skip leading spaces and tabs
X--------------------------------------------------------------------------*/
Xchar *
Xskip_ld_break(zstr)
Xregister char *zstr;
X{
X	while(isspace(*zstr))
X		zstr++;
X	return(zstr);
X}	/* end of skip_ld_break */
X
X/*+-----------------------------------------------------------------------
X	pad_zstr_to_len(zstr,len)
X
X  pads with spaces to specified length, unless already longer than
X  len in which case the string is truncated to 'len' characters.
X------------------------------------------------------------------------*/
Xvoid
Xpad_zstr_to_len(zstr,len)
Xchar *zstr;
Xint len;
X{
Xregister izstr;
X
X	izstr = strlen(zstr);
X	if(izstr >= len)
X		zstr[len] = 0;
X	else
X	{
X		while(izstr < len)
X			zstr[izstr++] = 0x20;
X		zstr[izstr] = 0;
X	}
X}	/* end of pad_zstr_to_len */
X
X/*+-----------------------------------------------------------------------
X	arg_token(parsestr,termchars)
X
XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
Xcalls), where tokens are nonempty strings separated by runs of chars
Xfrom termchars.  Writes nulls into parsestr to end tokens.
Xtermchars need not remain constant from call to call.
X
XTreats multiple occurrences of a termchar as one delimiter (does not
Xallow null fields).
X------------------------------------------------------------------------*/
Xstatic char *arg_token_static = (char *)0;
Xchar *arg_token(parsestr,termchars)
Xchar *parsestr;
Xchar *termchars;
X{
Xregister int first = 1;
Xregister char *termptr;
Xregister char *parseptr;
Xchar *token;
X
X	if(parsestr == (char *)0 && arg_token_static == (char *)0)
X		return((char *)0);
X
X	if(parsestr)
X		parseptr = parsestr;
X	else
X       parseptr = arg_token_static;
X
X	while(*parseptr)
X	{
X		if(!strchr(termchars,*parseptr))
X			break;
X		parseptr++;
X	}
X
X	if(!*parseptr)
X	{
X		arg_token_static = (char *)0;
X		return((char *)0);
X	}
X
X	token = parseptr;
X	if(*token == '\'')
X	{
X		token++;
X		parseptr++;
X		while(*parseptr)
X		{
X			if(*parseptr == '\'')
X			{
X				arg_token_static = parseptr + 1;
X				*parseptr = 0;
X				return(token);
X			}
X			parseptr++;
X		}
X		arg_token_static = (char *)0;
X		return(token);
X	}
X	while(*parseptr)
X	{
X		if(strchr(termchars,*parseptr))
X		{
X			*parseptr = 0;
X			arg_token_static = parseptr + 1;
X			while(*arg_token_static)
X			{
X				if(!strchr(termchars,*arg_token_static))
X					break;
X			}
X			return(token);
X		}
X		parseptr++;
X	}
X	arg_token_static = (char *)0;
X	return(token);
X}	/* end of arg_token */
X
X/*+-------------------------------------------------------------------------
X	build_arg_array(cmd,arg,arg_max_quan,&narg)
X--------------------------------------------------------------------------*/
Xvoid
Xbuild_arg_array(cmd,arg,arg_max_quan,narg_rtn)
Xchar *cmd;
Xchar **arg;
Xint arg_max_quan;
Xint *narg_rtn;
X{
Xregister itmp;
Xregister narg;
X
X	for(itmp = 0; itmp < arg_max_quan; itmp++)
X		arg[itmp] = (char *)0;
X	arg[0] = arg_token(cmd," \t\r\n");
X
X	for(narg = 1; narg < arg_max_quan; ++narg)
X	{
X		if((arg[narg] = arg_token((char *)0," \t\r\n")) == (char *)0) 
X			break;
X	}
X
X	*narg_rtn = narg;
X
X}	/* end of build_arg_array */
X
X/*+-----------------------------------------------------------------------
X	str_token(parsestr,termchars)
X
XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
Xcalls), where tokens are nonempty strings separated by runs of chars
Xfrom termchars.  Writes nulls into parsestr to end tokens.
Xtermchars need not remain constant from call to call.
X
XTreats each occurrence of a termchar as delimiter (allows null
Xfields).
X------------------------------------------------------------------------*/
Xstatic char *str_token_static = (char *)0;
Xchar *str_token(parsestr,termchars)
Xchar *parsestr;
Xchar *termchars;
X{
Xregister first = 1;
Xregister char *termptr;
Xregister char *parseptr;
Xchar *token;
X
X	if(parsestr == (char *)0 && str_token_static == (char *)0)
X		return((char *)0);
X
X	if(parsestr)
X		parseptr = parsestr;
X	else
X       parseptr = str_token_static;
X
X	while(*parseptr)
X	{
X		for(termptr = termchars; *termptr != 0; termptr++)
X		{
X			if(*parseptr == *termptr)
X				goto FOUND_TERM;
X		}
X		if(!*termptr)
X			break;
X		parseptr++;
X	}
X
X	if(!*parseptr)
X	{
X		str_token_static = (char *)0;
X		return((char *)0);
X	}
X
XFOUND_TERM:
X	token = parseptr;
X	while(*parseptr)
X	{
X		for(termptr = termchars; *termptr;)
X		{
X			if(*parseptr == *termptr++)
X			{
X				str_token_static = parseptr + 1;
X				*parseptr = 0;
X				return(token);
X			}
X		}
X		parseptr++;
X	}
X	str_token_static = (char *)0;
X	return(token);
X}	/* end of str_token */
X
X/*+-------------------------------------------------------------------------
X	build_str_array(cmd,arg,str_max_quan,&narg)
X--------------------------------------------------------------------------*/
Xvoid
Xbuild_str_array(cmd,arg,str_max_quan,nstr_rtn)
Xchar *cmd;
Xchar **arg;
Xint str_max_quan;
Xint *nstr_rtn;
X{
Xregister itmp;
Xregister narg;
X
X
X	for(itmp = 0; itmp < str_max_quan; itmp++)
X		arg[itmp] = (char *)0;
X	arg[0] = str_token(cmd," \t\r\n");
X
X	for(narg = 1; narg < str_max_quan; ++narg)
X	{
X		if((arg[narg] = str_token((char *)0," \t\r\n")) == (char *)0) 
X			break;
X	}
X
X	*nstr_rtn = narg;
X
X}	/* end of build_str_array */
X
X/*+-----------------------------------------------------------------------
X	make_char_graphic(character,incl_3char) - Make all chars "printable"
X
X  returns pointer to a static string containing printable version
X  of a character.  If control char, printed as "^A", etc.
X  if incl_3char set true, then space + ASCII assignment (e.g. "NUL") is
X  appended to the string for non-printable graphics
X------------------------------------------------------------------------*/
Xchar *make_char_graphic(ch,incl_3char)
Xregister char ch;
Xint incl_3char;
X{
Xstatic char gg[16];
X
X	ch &= 0x7F;
X	if((ch >= 0x20) && (ch < 0x7F))
X	{
X		gg[0] = ch; gg[1] = 0;
X	}
X	else
X	{
X		gg[0] = '^'; 
X		if(ch == 0x7F)
X		{
X			gg[1] = '?';
X			if(incl_3char)
X				strcpy(&gg[2]," DEL");
X		}
X		else
X		{
X			gg[1] = ch + 0x40;
X			if(incl_3char)
X			{
X				gg[2] = 0x20;
X				strncpy(&gg[3],ascii_ctlstr + (ch * 3),3);
X				gg[7] = 0;
X			}
X			else
X				gg[2] = 0;
X		}
X	}
X	return(gg);
X}	/* end of make_char_graphic */
X
X/*+-----------------------------------------------------------------------
X	disp_termio(ttt)
X  display termio 'ttt' on stderr
X------------------------------------------------------------------------*/
Xvoid disp_termio(ttt,text)
Xstruct termio *ttt;
Xchar *text;
X{
Xregister flag;
Xregister i_cc;
Xregister char *cptr;
Xint dbits;
Xchar parity;
X
X	pprintf("---------> %s\n",text);
X
X	flag = ttt->c_iflag;
X	pprintf("iflag: %07o IGNBRK:%d  BRKINT:%d  IGNPAR:%d  PARMRK:%d  INPCK:%d  ISTRIP:%d\n",
X				flag,
X				(flag & IGNBRK) ? 1 : 0,
X				(flag & BRKINT) ? 1 : 0,
X				(flag & IGNPAR) ? 1 : 0,
X				(flag & PARMRK) ? 1 : 0,
X				(flag & INPCK ) ? 1 : 0,
X				(flag & ISTRIP) ? 1 : 0);
X	pprintf(
X"               INLCR:%d  IGNCR:%d  ICRNL:%d  IUCLC:%d  IXON:%d  IXANY:%d  IXOFF:%d\n",
X				(flag & INLCR ) ? 1 : 0,
X				(flag & IGNCR ) ? 1 : 0,
X				(flag & ICRNL ) ? 1 : 0,
SHAR_EOF
echo "End of part 10"
echo "File ecuutil.c is continued in part 11"
echo "11" > 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.