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

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

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

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is part 13 of ecu3
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= pcmdfile.c ==============
echo 'x - extracting pcmdfile.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'pcmdfile.c' &&
X/*+-------------------------------------------------------------------------
X	pcmdfile.c - ecu file-related procedure commands
X	wht@n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	_file_not_open(filenum)
X	_gfilenum(param,filenum)
X	_param_to_stat(param,pstat_rtnd)
X	pcmd_fchmod(param)
X	pcmd_fclose(param)
X	pcmd_fdel(param)
X	pcmd_fgetc(param)
X	pcmd_fgets(param)
X	pcmd_fopen(param)
X	pcmd_fputc(param)
X	pcmd_fputs(param)
X	pcmd_fread(param)
X	pcmd_fseek(param)
X	pcmd_fwrite(param)
X	pcmd_mkdir(param)
X	pcmd_pclose(param)
X	pcmd_popen(param)
X	ifunc_fatime(param,pvalue)
X	ifunc_fmode(param,pvalue)
X	ifunc_fmtime(param,pvalue)
X	ifunc_fsize(param,pvalue)
X	ifunc_ftell(param,pvalue)
X	ifunc_ischr(param,pvalue)
X	ifunc_isdir(param,pvalue)
X	ifunc_isreg(param,pvalue)
X	proc_file_reset()
X	str_to_filemode(modestr,filemode)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
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 "ecuerror.h"
X#include "esd.h"
X#include "var.h"
X#include "proc.h"
X
X#if !defined(S_IRUSR)
X#define	S_IRUSR	00400		/* read permission: owner */
X#define	S_IWUSR	00200		/* write permission: owner */
X#define	S_IXUSR	00100		/* execute permission: owner */
X#define	S_IRWXG	00070		/* read, write, execute: group */
X#define	S_IRGRP	00040		/* read permission: group */
X#define	S_IWGRP	00020		/* write permission: group */
X#define	S_IXGRP	00010		/* execute permission: group */
X#define	S_IRWXO	00007		/* read, write, execute: other */
X#define	S_IROTH	00004		/* read permission: other */
X#define	S_IWOTH	00002		/* write permission: other */
X#define	S_IXOTH	00001		/* execute permission: other */
X#endif
X
Xextern int proctrace;
Xextern int rcvr_pid;
Xextern int errno;
Xextern proc_level;
Xextern PCB *pcb_stack[];
X
X#define FILE_MAX	5
X
Xtypedef struct pfile_struct
X{
X	FILE *f;	/* file pointer */
X	ESD *n;		/* file name */
X} PFILE;
X
XPFILE pfile[FILE_MAX];
X
Xchar fwrite_error_fmt[] = "file %d write error (not open for write?)\n";
X
X/*+-------------------------------------------------------------------------
X	proc_file_reset()
X--------------------------------------------------------------------------*/
Xvoid
Xproc_file_reset()
X{
Xregister itmp;
X
X	for(itmp = 0; itmp < FILE_MAX; itmp++)
X	{
X		if(pfile[itmp].f)
X		{
X			fclose(pfile[itmp].f);
X			pfile[itmp].f = NULL;
X			free_esd(pfile[itmp].n);
X		}
X	}
X}	/* end of proc_file_reset */
X
X/*+-------------------------------------------------------------------------
X	_file_not_open(filenum)
X--------------------------------------------------------------------------*/
Xint
X_file_not_open(filenum)
Xint filenum;
X{
X	pprintf("file %d not open\n",filenum);
X	return(eFATAL_ALREADY);
X}	/* end of _file_not_open */
X
X/*+-------------------------------------------------------------------------
X	_gfilenum(param,filenum)
X--------------------------------------------------------------------------*/
Xint
X_gfilenum(param,filenum)
XESD *param;
Xint *filenum;
X{
Xint erc;
Xulong lvarnum;
Xint old_index;
X
X	skip_cmd_break(param);
X	old_index = param->old_index;
X	if(erc = gint(param,&lvarnum))
X		return(erc);
X	if(lvarnum > FILE_MAX)
X		return(eBadFileNumber);
X	*filenum = (int)lvarnum;
X	param->old_index = old_index;
X	return(0);
X}	/* end of _gfilenum */
X
X/*+-------------------------------------------------------------------------
X	str_to_filemode(modestr,filemode) - "rwxrwxrwx" to mode integer
X--------------------------------------------------------------------------*/
Xstr_to_filemode(modestr,filemode)
Xchar *modestr;
Xlong *filemode;
X{
Xregister i;
Xregister mode = 0;
Xint erc = 0;
X
X	if(strlen(modestr) != 9)
X	{
X		pprintf("bad length: '%s'\n",modestr);
X		return(eFATAL_ALREADY);
X	}
X
X	for(i=0; i < 9; i++)
X	{
X		switch(modestr[i])
X		{
X
X		case 'r':
X			if(i == 0)
X				mode |= S_IRUSR;
X			else if(i == 3)
X				mode |= S_IRGRP;
X			else if(i == 6)
X				mode |= S_IROTH;
X			else
X				erc = eSyntaxError;
X			break;
X
X
X		case 'w':
X			if(i == 1)
X				mode |= S_IWUSR;
X			else if(i == 4)
X				mode |= S_IWGRP;
X			else if(i == 7)
X				mode |= S_IWOTH;
X			else
X				erc = eSyntaxError;
X			break;
X
X
X		case 'x':
X			if(i == 2)
X				mode |= S_IXUSR;
X			else if(i == 5)
X				mode |= S_IXGRP;
X			else if(i == 8)
X				mode |= S_IXOTH;
X			else
X				erc = eSyntaxError;
X			break;
X
X
X		case 's':
X#if defined(FULL_FEATURE_CHMODE)
X			if(i == 2)
X			{
X				mode |= S_ISUID;
X				mode |= S_IXUSR;
X			}
X			else if(i == 5)
X			{
X				mode |= S_ISGID;
X				mode |= S_IXGRP;
X			}
X			else
X				erc = eSyntaxError;
X#else
X			pputs("setuid/setgid not allowed\n");
X			erc = eFATAL_ALREADY;
X#endif /* defined(FULL_FEATURE_CHMODE) */
X			break;
X
X
X		case 't':
X#if defined(FULL_FEATURE_CHMODE)
X			if(i == 8)
X			{
X				mode |= S_ISVTX;
X				mode |= S_IXOTH;
X			}
X			else
X				erc = eSyntaxError;
X#else
X			pputs("set sticky bit not allowed\n");
X			erc = eFATAL_ALREADY;
X#endif /* defined(FULL_FEATURE_CHMODE) */
X			break;
X		case 'l':
X			if(i == 5)
X			{
X				mode |= S_ISGID;
X				mode &= ~S_IXGRP;
X			}
X			else
X				erc = eSyntaxError;
X			break;
X		case '-':
X			break;
X		default:
X			erc = eSyntaxError;
X		}	/* end switch */
X
X		if(erc)
X			break;
X
X	}		/* end for */
X
X	if(erc)
X	{
X		if(erc != eFATAL_ALREADY)
X			pputs("invalid mode specifier\n");
X		pputs(modestr);
X		while(i--)
X			pputc(' ');
X		pputs("^\n");
X		
X	}
X	else
X		*filemode = (long)mode;
X
X	return(erc);
X
X}	/* end of str_to_filemode */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fgetc(param)
X
Xfgetc <filenum-int> [$][i<varspec> | $s<varspec>]
Xint variable receives 0 if EOF
Xstr var receives null str on eof
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fgetc(param)
XESD *param;
X{
Xint erc;
Xint filenum;
Xint vartype;
Xint inchar;
XESD *svptr;
Xlong *ivptr;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X
X	skip_cmd_char(param,'$');
X	if((param->index >= param->cb) ||
X		( ((vartype = to_lower(*(param->pb + param->index))) != 'i') &&
X			(vartype != 's')))
X		return(eIllegalVarType);
X	param->index++;
X	switch(vartype)
X	{
X		case 'i':
X			erc = get_ivptr(param,&ivptr,1);
X			break;
X		default:
X			erc = get_svptr(param,&svptr,1);
X			break;
X	}
X	if(erc)
X		return(erc);
X
X	if((inchar = fgetc(pfile[filenum].f)) == EOF)
X	{
X		if(proctrace)
X			pputs("fgetc EOF\n");
X		if(vartype == 'i')
X			*ivptr = -1;
X		else
X			zero_esd(svptr);
X	}
X	else if(vartype == 'i')
X		*ivptr = inchar;
X	else
X	{
X		*svptr->pb = inchar;
X		svptr->cb = 1;
X	}
X
X	if(proctrace)
X	{
X		pputs("fgetc set ");
X		pputs((vartype == 'i') ? "int" : "str");
X		pprintf(" var = %lu (0x%02x)\n",inchar,inchar);
X	}
X	return(0);
X
X}	/* end of pcmd_fgetc */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fread(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fread(param)
XESD *param;
X{
X	return(eNotImplemented);
X}	/* end of pcmd_fread */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fgets(param)
Xfgetc <filenum-int> [$][s]<varspec>
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fgets(param)
XESD *param;
X{
Xint erc;
Xint filenum;
Xchar ctmp;
XESD *svptr;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X
X	skip_cmd_char(param,'$');
X	if(erc = get_cmd_char(param,&ctmp))
X		return(erc);
X	if(to_lower(ctmp) != 's')
X		return(eIllegalVarType);
X	if(erc = get_svptr(param,&svptr,1))
X		return(erc);
X	*svptr->pb = 0;
X	svptr->cb = 0;
X	if(!(iv[0] = !fgets(svptr->pb,svptr->maxcb + 1,pfile[filenum].f)))
X	{
X		svptr->cb = strlen(svptr->pb);
X		if(*(svptr->pb + svptr->cb - 1) == NL)
X		{
X			svptr->cb--;
X			null_terminate_esd(svptr);
X		}
X	}
X	if(proctrace)
X		pprintf("fgets set str var = '%s'\n",svptr->pb);
X	return(0);
X
X}	/* end of pcmd_fgets */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fclose(param)
Xfclose <filenum-int>
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fclose(param)
XESD *param;
X{
Xint erc;
Xint filenum;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(pfile[filenum].f)
X	{
X		fclose(pfile[filenum].f);
X		pfile[filenum].f = NULL;
X		free_esd(pfile[filenum].n);
X	}
X
X	return(0);
X
X}	/* end of pcmd_fclose */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fputc(param)
Xfputc <file-num> <int>
Xfputc <file-num> <str>
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fputc(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *buf = (ESD *)0;
Xchar outchar = 0;
Xlong outlong;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X
X	if(!gint(param,&outlong))
X		outchar = (char)outlong;
X	else
X	{
X		if((buf = make_esd(64)) == (ESD *)0)
X			return(eNoMemory);
X		if(erc = gstr(param,buf,1))
X			goto RETURN;
X		if(!buf->cb)
X		{
X			pputs("cannot fputc: zero length string\n");
X			erc = eFATAL_ALREADY;
X			goto RETURN;
X		}
X		outchar = *buf->pb;
X	}
X
X	if(fputc(outchar,pfile[filenum].f) < 0)
X	{
X		pprintf(fwrite_error_fmt,filenum);
X		erc = eFATAL_ALREADY;
X	}
X
XRETURN:
X	if(buf)
X		free_esd(buf);
X	return(erc);
X}	/* end of pcmd_fputc */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fopen(param)
X
Xfopen [-<fopen_switches>] <filenum-int> <filename-str>
Xsets $i0 with result
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fopen(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *fname = (ESD *)0;
Xchar switches[8];
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(get_switches(param,switches,sizeof(switches)))
X	{
X		strcpy(switches,"-r");
X		if(proctrace)
X		{
X			pputs("Warning: fopen defaulting to read\n");
X			show_error_position(pcb_stack[proc_level - 1]);
X		}
X	}
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(pfile[filenum].f)
X	{
X		pprintf("file %d already open\n",filenum);
X		return(eFATAL_ALREADY);
X	}
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname,1))
X		goto RETURN;
X
X	iv[0] = 0;
X	if((pfile[filenum].f = fopen(fname->pb,switches + 1)) == NULL)
X	{
X		if(proctrace)
X		{
X			pprintf("'%s'",fname->pb);
X			pperror(" ");
X			iv[0] = (long)errno;
X		}
X	}
X	else if(proctrace)
X		pprintf("opened '%s' as file %d\n",fname->pb,filenum);
X
X	if(!erc)
X		pfile[filenum].n = fname;
X
XRETURN:
X	if(erc)
X		free_esd(fname);
X	return(erc);
X}	/* end of pcmd_fopen */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fputs(param)
Xfputs [-n] <filenum-int> <str>
X-n do not output newline after <str>
X<filenum-int> file number for operation
X<str> string to write to file
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fputs(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *buf = (ESD *)0;
Xchar switches[8];
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	get_switches(param,switches,sizeof(switches));
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X
X	if((buf = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,buf,1))
X		goto RETURN;
X
X	if(!fputs(buf->pb,pfile[filenum].f) && strlen(buf->pb))
X	{
X		pprintf(fwrite_error_fmt,filenum);
X		erc = eFATAL_ALREADY;
X		goto RETURN;
X	}
X
X	if(!strchr(switches,'n'))
X		fputc(NL,pfile[filenum].f);
X
XRETURN:
X	free_esd(buf);
X	return(erc);
X}	/* end of pcmd_fputs */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fwrite(param)
Xfwrite <filenum-int> <str>
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fwrite(param)
XESD *param;
X{
X	return(eNotImplemented);
X#ifdef USE_FWRITE
Xint erc;
Xint filenum;
XESD *buf = (ESD *)0;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X
X	if((buf = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,buf,1))
X		goto RETURN;
X
X	if(!fputs(buf->pb,pfile[filenum].f) && strlen(buf->pb))
X	{
X		pprintf(fwrite_error_fmt,filenum);
X		erc = eFATAL_ALREADY;
X	}
X
XRETURN:
X	free_esd(buf);
X	return(erc);
X#endif
X}	/* end of pcmd_fwrite */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fchmod(param)
X
Xfchmod <mode-str> | <mode-int> <filenum-int> | <filename-str>
X$i0 = 0 if successful, else errno
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fchmod(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *fname = (ESD *)0;
XESD *mode = (ESD *)0;
Xlong new_mode;
Xchar *cptr;
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if((mode = make_esd(64)) == (ESD *)0)
X	{
X		free_esd(fname);
X		return(eNoMemory);
X	}
X
X	if(erc = skip_cmd_break(param))
X		goto RETURN;
X	else if(!gstr(param,mode,0))
X	{
X		if(erc = str_to_filemode(mode->pb,&new_mode))
X			goto RETURN;
X	}
X	else if(erc = gint(param,&new_mode))
X	{
X		erc = eBadParameter;
X		goto RETURN;
X	}
X
X	if(erc = skip_cmd_break(param))
X		goto RETURN;
X	else if(!gstr(param,fname,1))
X	{
X		cptr = fname->pb;
X		if(iv[0] = (long)chmod(cptr,(int)new_mode &= 0777))
X		{
X			iv[0] = (long)errno;
X			if(proctrace)
X				pperror(cptr);
X		}
X	}
X	else if(!_gfilenum(param,&filenum))
X	{
X		if(!pfile[filenum].f)
X		{
X			erc = (_file_not_open(filenum));
X			iv[0] = EBADF;
X		}
X		else if(iv[0] = (long)chmod(pfile[filenum].n->pb,(int)new_mode & 0777))
X		{
X			iv[0] = (long)errno;
X			if(proctrace)
X			{
X				sprintf(fname->pb,"file %d",filenum);
X				pperror(fname->pb);
X			}
X		}
X		if(!iv[0])
X			cptr = pfile[filenum].n->pb;
X	}
X	else
X		erc = eBadParameter;
X
X	if(proctrace && !erc && !iv[0])
X		pprintf("'%s' mode set to %o\n",cptr,0100000 | (int)new_mode);
X
XRETURN:
X	free_esd(mode);
X	free_esd(fname);
X
X	return(erc);
X
X}	/* end of pcmd_fchmod */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fdel(param)
X
Xfdel <filename-str>
X$i0 = 0 if successful, else errno
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fdel(param)
XESD *param;
X{
Xint erc;
XESD *fname = (ESD *)0;
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname,1))
X		goto RETURN;
X
X	if(iv[0] = (long)unlink(fname->pb))
X		iv[0] = (long)errno;
X
X	if(proctrace)
X	{
X		if(iv[0])
X			pperror(fname->pb);
X		else
X			pprintf("'%s' deleted\n",fname->pb);
X	}
X
XRETURN:
X	free_esd(fname);
X	return(erc);
X}	/* end of pcmd_fdel */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fseek(param)
Xfseek <filenum-int> <filepos-int>
Xsets $i0 with result
X--------------------------------------------------------------------------*/
Xint
Xpcmd_fseek(param)
XESD *param;
X{
Xint erc;
Xint filenum;
Xlong seekpos;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X	if(erc = gint(param,&seekpos))
X		return(erc);
X
X	iv[0] = 0;
X	if(fseek(pfile[filenum].f,seekpos,0) < 0)
X	{
X		if(proctrace)
X		{
X			pprintf("file %d ",filenum);
X			pperror("seekerror");
X		}
X		iv[0] = (int)errno;
X	}
X	else if(proctrace)
X		pprintf("file %d set to position %ld\n",filenum,seekpos);
X
X	return(erc);
X
X}	/* end of pcmd_fseek */
X
X/*+-------------------------------------------------------------------------
X	pcmd_mkdir(param)
X
Xmkdir <filename-str>
X$i0 = 0 if successful, else errno
X--------------------------------------------------------------------------*/
Xint
Xpcmd_mkdir(param)
XESD *param;
X{
Xint erc;
XESD *fname = (ESD *)0;
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname,1))
X		goto RETURN;
X
X	if(iv[0] = (long)mkdir(fname->pb,0755))
X		iv[0] = (long)errno;
X
X	if(proctrace)
X	{
X		if(iv[0])
X			pperror(fname->pb);
X		else
X			pprintf("'%s' deleted\n",fname->pb);
X	}
X
XRETURN:
X	free_esd(fname);
X	return(erc);
X}	/* end of pcmd_mkdir */
X
X/*+-------------------------------------------------------------------------
X	pcmd_pclose(param)
Xpclose <filenum-int>
X--------------------------------------------------------------------------*/
Xint
Xpcmd_pclose(param)
XESD *param;
X{
Xint erc;
Xint filenum;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(pfile[filenum].f)
X	{
X		pclose(pfile[filenum].f);
X		pfile[filenum].f = NULL;
X		free_esd(pfile[filenum].n);
X	}
X
X	return(0);
X
X}	/* end of pcmd_pclose */
X
X/*+-------------------------------------------------------------------------
X	pcmd_popen(param)
X
Xpopen [-<popen_switches>] <filenum-int> <filename-str>
Xsets $i0 with result
X--------------------------------------------------------------------------*/
Xint
Xpcmd_popen(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *fname = (ESD *)0;
Xchar switches[8];
X#if !defined(M_UNIX)
XFILE *popen();
X#endif
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(get_switches(param,switches,sizeof(switches)))
X	{
X		strcpy(switches,"-r");
X		if(proctrace)
X		{
X			pputs("Warning: popen defaulting to read\n");
X			show_error_position(pcb_stack[proc_level - 1]);
X		}
X	}
X
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X
X	if(pfile[filenum].f)
X	{
X		pprintf("file %d already open\n",filenum);
X		return(eFATAL_ALREADY);
X	}
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname,1))
X		goto RETURN;
X
X	iv[0] = 0;
X	if((pfile[filenum].f = popen(fname->pb,switches + 1)) == NULL)
X	{
X		if(proctrace)
X		{
X			pprintf("'%s'",fname->pb);
X			pperror(" ");
X			iv[0] = (long)errno;
X		}
X	}
X	else if(proctrace)
X		pprintf("opened '%s' as file %d\n",fname->pb,filenum);
X
X	if(!erc)
X		pfile[filenum].n = fname;
X
XRETURN:
X	if(erc)
X		free_esd(fname);
X	return(erc);
X}	/* end of pcmd_popen */
X
X/*+-------------------------------------------------------------------------
X	ifunc_ftell(param,pvalue)
X%ftell(<filenum-int>)
X--------------------------------------------------------------------------*/
Xint
Xifunc_ftell(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xint erc;
Xint filenum;
Xlong ftell();
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X	if(erc = skip_paren(param,1))
X		return(erc);
X	if(erc = _gfilenum(param,&filenum))
X		return(erc);
X	if(!pfile[filenum].f)
X		return(_file_not_open(filenum));
X	if(erc = skip_paren(param,0))
X		return(erc);
X
X	*pvalue = ftell(pfile[filenum].f);
X	return(0);
X}	/* end of ifunc_ftell */
X
X/*+-------------------------------------------------------------------------
X	_param_to_stat(param,pstat_rtnd)
X--------------------------------------------------------------------------*/
Xint
X_param_to_stat(param,pstat_rtnd)
XESD *param;
Xstruct stat **pstat_rtnd;
X{
Xint erc;
Xint filenum;
Xstatic struct stat fst;
Xstruct stat *pstat = &fst;
XESD *fname;
X
X	errno = 0;
X
X	if(erc = skip_paren(param,1))
X		return(erc);
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(!gstr(param,fname,1))
X	{
X		if(stat(fname->pb,pstat))
X			pstat = (struct stat *)0;
X	}
X	else if(param->index = param->old_index,!_gfilenum(param,&filenum))
X	{
X		if(!pfile[filenum].f)
X		{
X			free_esd(fname);
X			return(_file_not_open(filenum));
X		}
X		if(stat(pfile[filenum].n->pb,pstat))
X			pstat = (struct stat *)0;
X	}
X	else
X		erc = eBadParameter;
X
X	free_esd(fname);
X
X	if(erc)
X		return(erc);
X
X	if(erc = skip_paren(param,0))
X		return(erc);
X
X	*pstat_rtnd = pstat;
X	if(proctrace && !pstat)
X		pperror("stat");
X	return(0);
X
X}	/* end of _param_to_stat */
X
X/*+-------------------------------------------------------------------------
X	ifunc_fsize(param,pvalue)
X%fsize(<filenum-int>)
X%fsize('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_fsize(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
Xstruct stat *pstat;
X
X	if(erc = _param_to_stat(param,&pstat))
X		return(erc);
X	if(!pstat)
X		*pvalue = -1;
X	else
X		*pvalue = pstat->st_size;
X	return(0);
X}	/* end of ifunc_fsize */
X
X/*+-------------------------------------------------------------------------
X	ifunc_fatime(param,pvalue)
X%fatime(<filenum-int>)
X%fatime('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_fatime(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
Xstruct stat *pstat;
X
X	if(erc = _param_to_stat(param,&pstat))
X		return(erc);
X	if(!pstat)
X		*pvalue = -1;
X	else
X		*pvalue = pstat->st_atime;
X	return(0);
X}	/* end of ifunc_fatime */
X
X/*+-------------------------------------------------------------------------
X	ifunc_fmtime(param,pvalue)
X%fmtime(<filenum-int>)
X%fmtime('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_fmtime(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
Xstruct stat *pstat;
X
X	if(erc = _param_to_stat(param,&pstat))
X		return(erc);
X	if(!pstat)
X		*pvalue = -1;
X	else
X		*pvalue = pstat->st_mtime;
X	return(0);
X}	/* end of ifunc_fmtime */
X
X/*+-------------------------------------------------------------------------
X	ifunc_fmode(param,pvalue)
X%fmode(<filenum-int>)
X%fmode('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_fmode(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
Xstruct stat *pstat;
X
X	if(erc = _param_to_stat(param,&pstat))
X		return(erc);
X	if(!pstat)
X		*pvalue = -1;
X	else
X		*pvalue = (long)pstat->st_mode;
X	return(0);
X}	/* end of ifunc_fmode */
X
X/*+-------------------------------------------------------------------------
X	ifunc_isreg(param,pvalue)
X%isreg(<filenum-int>)
X%isreg('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_isreg(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
X
X	if(erc = ifunc_fmode(param,pvalue))
X		return(erc);
X	if(*pvalue != -1)
X		*pvalue = ((*pvalue & S_IFMT) == S_IFREG);
X	return(0);
X}	/* end of ifunc_isreg */
X
X/*+-------------------------------------------------------------------------
X	ifunc_isdir(param,pvalue)
X%isdir(<filenum-int>)
X%isdir('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_isdir(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
X
X	if(erc = ifunc_fmode(param,pvalue))
X		return(erc);
X	if(*pvalue != -1)
X		*pvalue = ((*pvalue & S_IFMT) == S_IFDIR);
X	return(0);
X}	/* end of ifunc_isdir */
X
X/*+-------------------------------------------------------------------------
X	ifunc_ischr(param,pvalue)
X%ischr(<filenum-int>)
X%ischr('filename')
X--------------------------------------------------------------------------*/
Xint
Xifunc_ischr(param,pvalue)
XESD *param;
Xlong *pvalue;
X{
Xregister erc;
X
X	if(erc = ifunc_fmode(param,pvalue))
X		return(erc);
X	if(*pvalue != -1)
X		*pvalue = ((*pvalue & S_IFMT) == S_IFCHR);
X	return(0);
X}	/* end of ifunc_ischr */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of pcmdfile.c */
SHAR_EOF
$TOUCH -am 1224224190 'pcmdfile.c' &&
chmod 0644 pcmdfile.c ||
echo 'restore of pcmdfile.c failed'
Wc_c="`wc -c < 'pcmdfile.c'`"
test 22839 -eq "$Wc_c" ||
	echo 'pcmdfile.c: original size 22839, current size' "$Wc_c"
# ============= pcmdif.c ==============
echo 'x - extracting pcmdif.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'pcmdif.c' &&
X/*+-------------------------------------------------------------------------
X	pcmdif.c - ecu if procedure commands
X	wht@n4hgf.Mt-Park.GA.US
X
X    IFI $i0 rel-op $i1 cmd
X    IFS $s0 rel-op $s1 cmd
X	IFLT, IFLE, IFZ, IFNZ, IFGE, IFGT $i0
X
X    where rel-op is "=", "==", "!=", "<>", ">", "<", ">=", "=<"
X
X  Defined functions:
X	_cmd_ifrel_common(param,relop)
X	_if_common(param,truth)
X	pcmd_else(param)
X	pcmd_ifge(param)
X	pcmd_ifgt(param)
X	pcmd_ifi(param)
X	pcmd_ifle(param)
X	pcmd_iflt(param)
X	pcmd_ifnz(param)
X	pcmd_ifs(param)
X	pcmd_ifz(param)
X	get_logicop(param,op_returned)
X	get_relop(param,op_returned)
X	get_truth_int(param,truth)
X	get_truth_str(param,truth)
X	test_truth_int(int1,relop,int2)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-26-1990-22:23-wht@n4hgf-fix zero-relative if commands */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include <ctype.h>
X#include "ecu.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include "var.h"
X#include "proc.h"
X#include "relop.h"
X
Xextern PCB *pcb_stack[];
Xextern int proc_level;
Xextern int proctrace;
X
X#define MAX_IF 40	/* damn enough */
Xuchar if_level = 0;
Xuchar truth_already[MAX_IF];
X
X/*+-------------------------------------------------------------------------
X    get_relop(param,&op_returned)
X--------------------------------------------------------------------------*/
Xint
Xget_relop(param,op_returned)
XESD *param;
Xint *op_returned;
X{
Xregister erc;
X
X	if(erc = skip_cmd_break(param))
X		return(eInvalidRelOp);
X
X	switch(param->pb[param->index++]) /* index decremented in default */
X	{
X	case '=':
X		if((param->cb != param->index) && (param->pb[param->index] == '='))
X			param->index++;
X		*op_returned = OP_EQ;
X		return(0);
X
X	case '!':
X		if(param->cb == param->index)
X			return(eInvalidRelOp);
X		switch(param->pb[param->index])
X		{
X		case '=':
X			param->index++;
X			*op_returned = OP_NE;
X			return(0);
X		default:
X			return(eInvalidRelOp);
X		}
X
X	case '<':
X		if(param->cb == param->index)
X		{
X			*op_returned = OP_LT;
X			return(0);
X		}
X		switch(param->pb[param->index])
X		{
X		case '>':
X			param->index++;
X			*op_returned = OP_NE;
X			return(0);
X		case '=':
X			param->index++;
X			*op_returned = OP_LE;
X			return(0);
X		default:
X			*op_returned = OP_LT;
X			return(0);
X		}
X
X	case '>':
X		if(param->cb == param->index)
X		{
X			*op_returned = OP_LT;
X			return(0);
X		}
X		switch(param->pb[param->index])
X		{
X		case '=':
X			param->index++;
X			*op_returned = OP_GE;
X			return(0);
X		default:
X			*op_returned = OP_GT;
X			return(0);
X		}
X	default:
X		param->index--;
X	}
X	return(eInvalidRelOp);
X}   /* end of get_relop */
X
X/*+-------------------------------------------------------------------------
X	get_logicop(param,op_returned)
X--------------------------------------------------------------------------*/
Xint
Xget_logicop(param,op_returned)
XESD *param;
Xint *op_returned;
X{
Xregister erc;
Xregister char *cptr;
X
X	if(erc = skip_cmd_break(param))
X		return(eInvalidLogicOp);
X
X	if((param->cb - param->index) < 2)
X		return(eInvalidLogicOp);
X
X	cptr = param->pb + param->index;
X	erc = eInvalidLogicOp;
X	if(!strncmp(cptr,"&&",2))
X	{
X		*op_returned = OP_AND;
X		erc = 0;
X	}
X	else if(!strncmp(cptr,"||",2))
X	{
X		*op_returned = OP_OR;
X		erc = 0;
X	}
X	if(!erc)
X		param->index += 2;
X	return(erc);
X
X}	/* end of get_logicop */
X
X/*+-------------------------------------------------------------------------
X	test_truth_int(int1,relop,int2)
X--------------------------------------------------------------------------*/
Xint
Xtest_truth_int(int1,relop,int2)
Xlong int1;
Xint relop;
Xlong int2;
X{
Xregister truth;
X
X	switch(relop)
X	{
X	case OP_EQ:
X		truth = (int1 == int2);
X		break;
X	case OP_NE:
X		truth = (int1 != int2);
X		break;
X	case OP_GT:
X		truth = (int1 > int2);
X		break;
X	case OP_LT:
X		truth = (int1 < int2);
X		break;
X	case OP_GE:
X		truth = (int1 >= int2);
X		break;
X	case OP_LE:
X		truth = (int1 <= int2);
X		break;
X	}
X	return(truth);
X
X}	/* end of test_truth_int */
X
X/*+-------------------------------------------------------------------------
X	get_truth_int(param,truth)
X--------------------------------------------------------------------------*/
Xint
Xget_truth_int(param,truth)
XESD *param;
Xint *truth;
X{
Xregister erc;
Xlong int1;
Xlong int2;
Xint operator;
Xint truth2;
X
X	if(erc = gint(param,&int1))
X		return(erc);
X	if(erc = get_relop(param,&operator))
X		return(erc);
X	if(erc = gint(param,&int2))
X		return(erc);
X	*truth = test_truth_int(int1,operator,int2);
X
X	while(!get_logicop(param,&operator))
X	{
X		if(erc = get_truth_int(param,&truth2))
X			return(erc);
X		switch(operator)
X		{
X			case OP_AND:
X				*truth &= truth2;
X				break;
X
X			case OP_OR:
X				*truth |= truth2;
X				break;
X		}
X	}
X	return(erc);
X
X
X}	/* end of get_truth_int */
X
X/*+-------------------------------------------------------------------------
X    get_truth_str(param,truth)
X--------------------------------------------------------------------------*/
Xint
Xget_truth_str(param,truth)
XESD *param;
Xint *truth;
X{
Xregister erc;
XESD *tesd1 = (ESD *)0;
XESD *tesd2 = (ESD *)0;
Xint operator;
Xint strcmp_result;
Xint truth2;
X
X	if(!(tesd1 = make_esd(256)) || !(tesd2 = make_esd(256)))
X	{
X		erc = eNoMemory;
X		goto RETURN;
X	}	
X
X	if(erc = gstr(param,tesd1,1))
X		goto RETURN;
X	if(erc = get_relop(param,&operator))
X		goto RETURN;
X	if(erc = gstr(param,tesd2,1))
X		goto RETURN;
X
X	strcmp_result = strcmp(tesd1->pb,tesd2->pb);
X
X	switch(operator)
X	{
X		case OP_EQ:
X			*truth = (strcmp_result == 0);
X			break;
X		case OP_NE:
X			*truth = (strcmp_result != 0);
X			break;
X		case OP_GT:
X			*truth = (strcmp_result > 0);
X			break;
X		case OP_LT:
X			*truth = (strcmp_result < 0);
X			break;
X		case OP_GE:
X			*truth = (strcmp_result >= 0);
X			break;
X		case OP_LE:
X			*truth = (strcmp_result <= 0);
X			break;
X		default:
X			return(eInvalidStrOp);
X	}
X
X	while(!get_logicop(param,&operator))
X	{
X		if(erc = get_truth_str(param,&truth2))
X			return(erc);
X		switch(operator)
X		{
X			case OP_AND:
X				*truth &= truth2;
X				break;
X
X			case OP_OR:
X				*truth |= truth2;
X				break;
X		}
X	}
X
X	erc = 0;
X
XRETURN:
X	if(tesd1)
X		free_esd(tesd1);
X	if(tesd2)
X		free_esd(tesd2);
X	return(erc);
X
X}   /* end of get_truth_str */
X
X/*+-------------------------------------------------------------------------
X	_if_common(param,truth)
X--------------------------------------------------------------------------*/
Xint
X_if_common(param,truth)
XESD *param;
Xint truth;
X{
Xregister erc = 0;
Xchar s80[80];
XPCB *pcb;
XESD *else_line;
Xint label_on_else_line;
Xint truth2;
Xint save_index;
Xlong int1;
X
X	if(proctrace > 1)
X	{
X		pprintf("if condition %s",(truth) ? "TRUE: " : "FALSE\n");
X		if(truth)
X		{
X			skip_cmd_break(param);
X			pputs(param->pb + param->index);
X			pputc('\n');
X		}
X	}
X
X	truth_already[if_level] = truth;
X
X/* if end of command, execute frame else conditionally execute rest of esd */
X	s80[0] = 0;
X	if(end_of_cmd(param))
X		erc = execute_frame(truth);
X	else if(truth)
X		erc = execute_esd(param);
X	else
X		param->index = param->cb;
X
X	if(erc)
X		return(erc);
X
X/* check for else statement */
X	pcb = pcb_stack[proc_level - 1];
X	if(!pcb->current->next)		/* if no next line, no "else" */
X		return(0);
X
X	else_line = pcb->current->next->text;
X	else_line->index = else_line->old_index = 0;
X	if(label_on_else_line = (*else_line->pb != 0x20))
X	{	/* strip label */
X		if(get_alphanum_zstr(else_line,s80,sizeof(s80)))
X			return(eInvalidLabel);
X	}
X	if(get_alphanum_zstr(else_line,s80,sizeof(s80)))
X		return(0);		/* not "else" */
X	if(strcmp(s80,"else"))
X		return(0);		/* not "else" */
X	if(label_on_else_line)
X	{
X		else_line->old_index = 0;
X		pputs("label not allowed on else statement\n");
X		return(eFATAL_ALREADY);
X	}
X
X/* we have an "else" condition */
X	truth = !truth;
X	pcb->current = pcb->current->next;
X
X	trace_proc_cmd(pcb);
X
X	if(end_of_cmd(else_line))
X		erc = execute_frame(truth);
X	else
X	{
X		save_index = else_line->old_index = else_line->index;
X		s80[0] = 0;
X		if((*(else_line->pb + else_line->index) != '$') &&
X			get_alpha_zstr(else_line,s80,sizeof(s80)))
X		{
X			pputs("illegal command after 'else'\n");
X			return(eFATAL_ALREADY);
X		}
X		if(!strcmp(s80,"ifi"))
X		{
X			if(erc = get_truth_int(else_line,&truth2))
X				return(erc);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"ifs"))
X		{
X			if(erc = get_truth_str(else_line,&truth2))
X				return(erc);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"ifz"))
X		{
X			if(erc = gint(else_line,&int1))
X				return(erc);
X			truth2 = test_truth_int(int1,OP_EQ,0L);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"ifnz"))
X		{
X			if(erc = gint(else_line,&int1))
X				return(erc);
X			truth2 = test_truth_int(int1,OP_NE,0L);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"iflt"))
X		{
X			if(erc = gint(else_line,&int1))
X				return(erc);
X			truth2 = test_truth_int(int1,OP_LT,0L);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"ifle"))
X		{
X			if(erc = gint(else_line,&int1))
X				return(erc);
X			truth2 = test_truth_int(int1,OP_LE,0L);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"ifgt"))
X		{
X			if(erc = gint(else_line,&int1))
X				return(erc);
X			truth2 = test_truth_int(int1,OP_GT,0L);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strcmp(s80,"ifge"))
X		{
X			if(erc = gint(else_line,&int1))
X				return(erc);
X			truth2 = test_truth_int(int1,OP_GE,0L);
X			erc = _if_common(else_line,!truth_already[if_level] & truth2);
X			truth_already[if_level] |= truth2;
X		}
X		else if(!strncmp(s80,"while",5))
X		{
X			pputs("'while' command not allowed as 'else' conditional\n");
X			return(eFATAL_ALREADY);
X		}
X		else
X		{
X			else_line->index = save_index;
X			if(truth)
X				erc = execute_esd(else_line);
X		}
X	}
X
X	return(erc);
X}	/* end of _if_common */
X
X/*+-------------------------------------------------------------------------
X    pcmd_ifi(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifi(param)
XESD *param;
X{
Xregister erc;
Xint truth;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(if_level == MAX_IF)
X	{
X		pputs("if statements nested too deeply\n");
X		return(eFATAL_ALREADY);
X	}
X	if_level++;
X	truth_already[if_level] = 0;
X
X	if(!(erc = get_truth_int(param,&truth)))
X		erc = _if_common(param,truth);
X	if_level--;
X	return(erc);
X
X}   /* end of pcmd_ifi */
X
X/*+-------------------------------------------------------------------------
X	_cmd_ifrel_common(param,relop)
X--------------------------------------------------------------------------*/
Xint
X_cmd_ifrel_common(param,relop)
XESD *param;
Xint relop;
X{
Xregister erc;
Xint truth;
Xlong int1;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(if_level == MAX_IF)
X	{
X		pputs("if statements nested too deeply\n");
X		return(eFATAL_ALREADY);
X	}
X	if_level++;
X	truth_already[if_level] = 0;
X
X	if(erc = gint(param,&int1))
X		return(erc);
X	truth = test_truth_int(int1,relop,0L);
X	erc = _if_common(param,truth);
X	if_level--;
X	return(erc);
X
X}	/* end of _cmd_ifrel_common */
X
X/*+-------------------------------------------------------------------------
X	pcmd_ifz(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifz(param)
XESD *param;
X{
X	return(_cmd_ifrel_common(param,OP_EQ));
X}	/* end of pcmd_ifz */
X
X/*+-------------------------------------------------------------------------
X	pcmd_ifnz(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifnz(param)
XESD *param;
X{
X	return(_cmd_ifrel_common(param,OP_NE));
X}	/* end of pcmd_ifnz */
X
X/*+-------------------------------------------------------------------------
X	pcmd_ifle(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifle(param)
XESD *param;
X{
X	return(_cmd_ifrel_common(param,OP_LE));
X}	/* end of pcmd_ifle */
X
X/*+-------------------------------------------------------------------------
X	pcmd_ifge(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifge(param)
XESD *param;
X{
X	return(_cmd_ifrel_common(param,OP_GE));
X}	/* end of pcmd_ifge */
X
X/*+-------------------------------------------------------------------------
X	pcmd_iflt(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_iflt(param)
XESD *param;
X{
X	return(_cmd_ifrel_common(param,OP_LT));
X}	/* end of pcmd_iflt */
X
X/*+-------------------------------------------------------------------------
X	pcmd_ifgt(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifgt(param)
XESD *param;
X{
X	return(_cmd_ifrel_common(param,OP_GT));
X}	/* end of pcmd_ifgt */
X
X/*+-------------------------------------------------------------------------
X    pcmd_ifs(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_ifs(param)
XESD *param;
X{
Xregister erc;
Xint truth;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	if(if_level == MAX_IF)
X	{
X		pputs("if statements nested too deeply\n");
X		return(eFATAL_ALREADY);
X	}
X	if_level++;
X	truth_already[if_level] = 0;
X
X	if(!(erc = get_truth_str(param,&truth)))
X		erc = _if_common(param,truth);
X	if_level--;
X	return(erc);
X
X}   /* end of pcmd_ifs */
X
X/*+-------------------------------------------------------------------------
X	pcmd_else(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_else(param)
XESD *param;
X{
X	return(eElseCommand);
X}	/* end of pcmd_else */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of pcmdif.c */
SHAR_EOF
$TOUCH -am 1224224190 'pcmdif.c' &&
chmod 0644 pcmdif.c ||
echo 'restore of pcmdif.c failed'
Wc_c="`wc -c < 'pcmdif.c'`"
test 13817 -eq "$Wc_c" ||
	echo 'pcmdif.c: original size 13817, current size' "$Wc_c"
# ============= pcmdtty.c ==============
echo 'x - extracting pcmdtty.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'pcmdtty.c' &&
X/*+-------------------------------------------------------------------------
X	pcmdtty.c - tty (console) related procedure commands
X	wht@n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	pcmd_cls(param)
X	pcmd_color(param)
X	pcmd_cursor(param)
X	pcmd_delline(param)
X	pcmd_eeol(param)
X	pcmd_fkey(param)
X	pcmd_home(param)
X	pcmd_icolor(param)
X	pcmd_insline(param)
X	pcmd_scrdump(param)
X	pcmd_vidcolor(param)
X	pcmd_vidnorm(param)
X	pcmd_vidrev(param)
X	ifunc_colors(pvalue)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include "ecutty.h"
X
Xextern int proctrace;
Xextern ulong colors_current;
X
X/*+-------------------------------------------------------------------------
X	pcmd_color(param)
X
XUsage:   color [-r] [argument] [argument]
XOptions:
X   color color      Set foreground and background normal video colors
X   -r color color   Set foreground & background reverse video colors
X
XColor names
X   blue      magenta      brown      black
X   lt_blue   lt_magenta   yellow     gray
X   cyan      white        green      red
X   lt_cyan   hi_white     lt_green   lt_red
X
X--------------------------------------------------------------------------*/
Xpcmd_color(param)
XESD *param;
X{
Xregister erc;
Xchar switches[8];
Xint normal;
Xchar s32[32];
Xulong foreground;
Xulong background;
X
X	get_switches(param,switches,sizeof(switches));
X	if(!strlen(switches))
X		normal = 1;
X	else if(switches[1] == 'r')
X		normal = 0;		/* reverse */
X	else
X	{
X		pputs("unrecognized switch\n");
X		return(eFATAL_ALREADY);
X	}
X
X	if((erc = get_alpha_zstr(param,s32,sizeof(s32))) ||
X			((foreground = color_name_to_num(s32))) < 0)
X		goto ERROR;
X
X	if(erc = get_alpha_zstr(param,s32,sizeof(s32)))
X	{
X		if(!end_of_cmd(param))
X			goto ERROR;
X		background = 0;
X	}
X	else if((background = color_name_to_num(s32)) < 0)
X		goto ERROR;
X
X	if(normal)
X	{
X		colors_current &= 0xFFFF0000;
X		colors_current |= (foreground << 8) | background;
X		if(proctrace > 1)
X		{
X			pprintf("normal %ld,%ld current=0x%08lx\n",
X				foreground,background,colors_current);
X		}
X	}
X	else
X	{
X		colors_current &= 0x0000FFFF;
X		colors_current |= (foreground << 24) | (background << 16);
X		if(proctrace > 1)
X		{
X			pprintf("reverse %ld,%ld current=0x%08lx\n",
X				foreground,background,colors_current);
X		}
X	}
X
X	setcolor(colors_current);
X	return(0);
X
XERROR:
X	if(erc)
X		return(erc);
X	pputs("invalid color\n");
X	return(eFATAL_ALREADY);
X
X}	/* end of pcmd_color */
X
X/*+-------------------------------------------------------------------------
X	ifunc_colors(pvalue)
X--------------------------------------------------------------------------*/
Xint
Xifunc_colors(pvalue)
Xulong *pvalue;
X{
X	*pvalue = colors_current;
X	return(0);
X}	/* end of ifunc_colors */
X
X/*+-------------------------------------------------------------------------
X	pcmd_icolor(param)
X--------------------------------------------------------------------------*/
Xpcmd_icolor(param)
XESD *param;
X{
Xint erc;
Xulong new_colors;
X
X	if(erc = gint(param,&new_colors))
X		return(erc);
X
X	setcolor(new_colors);
X	return(0);
X}	/* end of pcmd_icolor */
X
X/*+-------------------------------------------------------------------------
X	pcmd_cls(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_cls(param)
XESD *param;
X{
X	tcap_clear_screen();
X	return(0);
X}	/* end of pcmd_cls */
X
X/*+-------------------------------------------------------------------------
X	pcmd_cursor(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_cursor(param)
XESD *param;
X{
Xint erc;
Xlong row;
Xlong col = 0;
X
X	if(erc = gint(param,&row))
X		return(erc);
X	if(gint(param,&col))
X	{
X		/* if something there non-integer */
X		if(!end_of_cmd(param))
X			return(eSyntaxError);
X	}
X	tcap_cursor((int)row,(int)col);
X	return(0);
X}	/* end of pcmd_cursor */
X
X/*+-------------------------------------------------------------------------
X	pcmd_scrdump(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_scrdump(param)
XESD *param;
X{
Xint erc;
XESD *fname;
XFILE *fp;
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname,1))
X	{
X		if(!end_of_cmd(param))
X		{
X			erc = eSyntaxError;
X			goto RETURN;
X		}
X	}
X
X	if(fname->cb)
X	{
X		if((fp = fopen(fname->pb,"a")) == NULL)
X		{
X			pperror(fname->pb);
X			erc = eFATAL_ALREADY;
X			goto RETURN;
X		}
X		fclose(fp);
X	}
X
X	screen_dump((fname->cb) ? fname->pb : (char *)0);
X
XRETURN:
X	free_esd(fname);
X	return(erc);
X}	/* end of pcmd_scrdump */
X
X/*+-------------------------------------------------------------------------
X	pcmd_vidnorm(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_vidnorm(param)
XESD *param;
X{
X	tcap_stand_end();
X	return(0);
X}	/* end of pcmd_vidnorm */
X
X/*+-------------------------------------------------------------------------
X	pcmd_vidrev(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_vidrev(param)
XESD *param;
X{
X	tcap_stand_out();
X	return(0);
X}	/* end of pcmd_vidrev */
X
X/*+-------------------------------------------------------------------------
X	pcmd_fkey(param)
X--------------------------------------------------------------------------*/
Xpcmd_fkey(param)
XESD *param;
X{
Xint erc;
XESD *tesd;
X
X	if((tesd = make_esd(64)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,tesd,0))
X		goto RETURN;
X
X	switch(keyset_read(tesd->pb))
X	{
X		case  0:
X			if(proctrace)
X				keyset_display();
X			break;
X		case -1:
X			pprintf("cannot find ~/.ecu/keys\n");
X			erc = eFATAL_ALREADY;
X			break;
X		case -2:
X			pprintf("'%s' not found in ~/.ecu/keys\n",tesd->pb);
X			erc = eFATAL_ALREADY;
X			break;
X	}
X
XRETURN:
X	free_esd(tesd);
X	return(erc);
X}	/* end of pcmd_fkey */
X
X/*+-------------------------------------------------------------------------
X	pcmd_vidcolor(param)
X
Xvidcolor normal|reverse|notify|success|alert|error fcolor [bcolor]
X--------------------------------------------------------------------------*/
Xint
Xpcmd_vidcolor(param)
XESD *param;
X{
Xint erc;
Xint ntokens = 0;
Xchar *tokens[3];
Xint param_index[3];
Xchar tokenbuf[64];
X
X	tokens[0] = tokenbuf;
X	tokens[1] = tokenbuf + 20;
X	tokens[2] = tokenbuf + 40;
X
X	while(ntokens < 3)
X	{
X		skip_cmd_break(param);
X		param_index[ntokens] = param->index;
X		if(erc = get_word_zstr(param,tokens[ntokens],20))
X			break;
X		ntokens++;
X	}
X
X	if(erc && ((erc != eNoParameter) || (ntokens < 2)))
X		return(erc);
X
X	switch(erc = setcolor_internal(ntokens,tokens))
X	{
X		case 0:
X			break;
X		default:
X			param->old_index = param->index = param_index[erc - 1];
X			erc = eBadParameter;
X	}
X	return(erc);
X}	/* end of pcmd_vidcolor */
X
X/*+-------------------------------------------------------------------------
X	pcmd_home(param) - home the cursor
X--------------------------------------------------------------------------*/
Xint
Xpcmd_home(param)
XESD *param;
X{
X	tcap_cursor(0,0);
X	return(0);
X}	/* end of pcmd_home */
X
X/*+-------------------------------------------------------------------------
X	pcmd_eeol(param) - erase to end of line
X--------------------------------------------------------------------------*/
Xint
Xpcmd_eeol(param)
XESD *param;
X{
X	tcap_eeol();
X	return(0);
X}	/* end of pcmd_eeol */
X
X/*+-------------------------------------------------------------------------
X	pcmd_insline(param) - insert line in display
X--------------------------------------------------------------------------*/
Xint
Xpcmd_insline(param)
XESD *param;
X{
X	tcap_insert_lines(1);
X	return(0);
X}	/* end of pcmd_insline */
X
X/*+-------------------------------------------------------------------------
X	pcmd_delline(param) - delete line from display
X--------------------------------------------------------------------------*/
Xint
Xpcmd_delline(param)
XESD *param;
X{
X	tcap_delete_lines(1);
X	return(0);
X}	/* end of pcmd_delline */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of pcmdtty.c */
SHAR_EOF
$TOUCH -am 1224224290 'pcmdtty.c' &&
chmod 0644 pcmdtty.c ||
echo 'restore of pcmdtty.c failed'
Wc_c="`wc -c < 'pcmdtty.c'`"
test 7941 -eq "$Wc_c" ||
	echo 'pcmdtty.c: original size 7941, current size' "$Wc_c"
# ============= pcmdwhile.c ==============
echo 'x - extracting pcmdwhile.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'pcmdwhile.c' &&
X/*+-------------------------------------------------------------------------
X	pcmdwhile.c - ecu while procedure commands
X	wht@n4hgf.Mt-Park.GA.US
X
X    WHILEI $i0 rel-op $i1 cmd
X    WHILES $s0 rel-op $s1 cmd
X
X    where rel-op is "=", "==", "!=", "<>", ">", "<", ">=", "=<"
X
X  Defined functions:
X	pcmd_whilei(param)
X	pcmd_whiles(param)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include <ctype.h>
X#include "ecu.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include "var.h"
X#include "proc.h"
X#include "relop.h"
X
Xextern PCB *pcb_stack[];
Xextern int proc_level;
X
X/*+-------------------------------------------------------------------------
X    pcmd_whilei(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_whilei(param)
XESD *param;
X{
Xregister erc;
Xint truth;
XPCB *pcb;
XLCB *condition_lcb;
Xint condition_index = param->index;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	pcb = pcb_stack[proc_level - 1];
X	condition_lcb = pcb->current;
X
XREPEAT_WHILE:
X
X	if(erc = get_truth_int(param,&truth))
X		return(erc);
X
X/* if end of command, execute frame */
X	if(end_of_cmd(param))
X	{
X		if(erc = execute_frame(truth))
X		{
X			if(erc == eContinueCommand)
X				goto CONTINUE;
X			if(erc == eBreakCommand)
X				erc = 0;
X			return(erc);
X		}
X	}
X	else if(truth)
X	{
X		if(erc = execute_esd(param))
X			return(erc);
X	}
X
X/* repeat if indicated */
XCONTINUE:
X	if(truth)
X	{
X		pcb->current = condition_lcb;
X		param->index = param->old_index = condition_index;
X		goto REPEAT_WHILE;
X	}
X
X	return(0);
X}   /* end of pcmd_whilei */
X
X/*+-------------------------------------------------------------------------
X    pcmd_whiles(param)
X--------------------------------------------------------------------------*/
Xint
Xpcmd_whiles(param)
XESD *param;
X{
Xregister erc;
Xint truth;
XPCB *pcb;
XLCB *condition_lcb;
Xint condition_index = param->index;
X
X	if(!proc_level)
X		return(eNotExecutingProc);
X
X	pcb = pcb_stack[proc_level - 1];
X	condition_lcb = pcb->current;
X
XREPEAT_WHILE:
X
X	if(erc = get_truth_str(param,&truth))
X		return(erc);
X
X/* if end of command, execute frame */
X	if(end_of_cmd(param))
X	{
X		if(erc = execute_frame(truth))
X		{
X			if(erc == eContinueCommand)
X				goto CONTINUE;
X			if(erc == eBreakCommand)
X				erc = 0;
X			return(erc);
X		}
X	}
X	else if(truth)
X	{
X		if(erc = execute_esd(param))
X			return(erc);
X	}
X
X/* repeat if indicated */
XCONTINUE:
X	if(truth)
X	{
X		pcb->current = condition_lcb;
X		param->index = param->old_index = condition_index;
X		goto REPEAT_WHILE;
X	}
X
X	return(0);
X}   /* end of pcmd_whiles */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of pcmdwhile.c */
SHAR_EOF
$TOUCH -am 1224224290 'pcmdwhile.c' &&
chmod 0644 pcmdwhile.c ||
echo 'restore of pcmdwhile.c failed'
Wc_c="`wc -c < 'pcmdwhile.c'`"
test 2686 -eq "$Wc_c" ||
	echo 'pcmdwhile.c: original size 2686, current size' "$Wc_c"
true || echo 'restore of pcmdxfer.c failed'
echo End of part 13, continue with part 14
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.