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

Warren Tucker wht at tridom.uucp
Tue Oct 10 09:30:26 AEST 1989


---- Cut Here and unpack ----
#!/bin/sh
# this is part 17 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file pcmdfile.c continued
#
CurArch=17
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 pcmdfile.c"
sed 's/^X//' << 'SHAR_EOF' >> pcmdfile.c
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	cmd_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
Xcmd_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);
X			break;
X		default:
X			erc = get_svptr(param,&svptr);
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 cmd_fgetc */
X
X/*+-------------------------------------------------------------------------
X	cmd_fread(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_fread(param)
XESD *param;
X{
X	return(eNotImplemented);
X}	/* end of cmd_fread */
X
X/*+-------------------------------------------------------------------------
X	cmd_fgets(param)
Xfgetc <filenum-int> [$][s]<varspec>
X--------------------------------------------------------------------------*/
Xint
Xcmd_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))
X		return(erc);
X	*svptr->pb = 0;
X	svptr->cb = 0;
X	if(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 cmd_fgets */
X
X/*+-------------------------------------------------------------------------
X	cmd_fclose(param)
Xfclose <filenum-int>
X--------------------------------------------------------------------------*/
Xint
Xcmd_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 cmd_fclose */
X
X/*+-------------------------------------------------------------------------
X	cmd_fputc(param)
Xfputc <file-num> <int>
Xfputc <file-num> <str>
X--------------------------------------------------------------------------*/
Xint
Xcmd_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))
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 cmd_fputc */
X
X/*+-------------------------------------------------------------------------
X	cmd_fopen(param)
X
Xfopen [-<fopen_switches>] <filenum-int> <filename-str>
Xsets $i0 with result
X--------------------------------------------------------------------------*/
Xint
Xcmd_fopen(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *filename = (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((filename = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,filename))
X		goto RETURN;
X
X	iv[0] = 0;
X	if((pfile[filenum].f = fopen(filename->pb,switches + 1)) == NULL)
X	{
X		if(proctrace)
X		{
X			pprintf("'%s'",filename->pb);
X			pperror(" ");
X			iv[0] = (long)errno;
X		}
X	}
X	else if(proctrace)
X		pprintf("opened '%s' as file %d\n",filename->pb,filenum);
X
X	if(!erc)
X		pfile[filenum].n = filename;
X
XRETURN:
X	if(erc)
X		free_esd(filename);
X	return(erc);
X}	/* end of cmd_fopen */
X
X/*+-------------------------------------------------------------------------
X	cmd_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
Xcmd_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))
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 cmd_fputs */
X
X/*+-------------------------------------------------------------------------
X	cmd_fwrite(param)
Xfwrite <filenum-int> <str>
X--------------------------------------------------------------------------*/
Xint
Xcmd_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))
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 cmd_fwrite */
X
X/*+-------------------------------------------------------------------------
X	cmd_fchmod(param)
X
Xfchmod <mode-str> | <mode-int> <filenum-int> | <filename-str>
X$i0 = 0 if successful, else errno
X--------------------------------------------------------------------------*/
Xint
Xcmd_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))
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))
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 cmd_fchmod */
X
X/*+-------------------------------------------------------------------------
X	cmd_fdel(param)
X
Xfdel <filename-str>
X$i0 = 0 if successful, else errno
X--------------------------------------------------------------------------*/
Xint
Xcmd_fdel(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *fname = (ESD *)0;
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname))
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 cmd_fdel */
X
X/*+-------------------------------------------------------------------------
X	cmd_fseek(param)
Xfseek <filenum-int> <filepos-int>
Xsets $i0 with result
X--------------------------------------------------------------------------*/
Xint
Xcmd_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 cmd_fseek */
X
X/*+-------------------------------------------------------------------------
X	cmd_mkdir(param)
X
Xmkdir <filename-str>
X$i0 = 0 if successful, else errno
X--------------------------------------------------------------------------*/
Xint
Xcmd_mkdir(param)
XESD *param;
X{
Xint erc;
Xint filenum;
XESD *fname = (ESD *)0;
X
X	if((fname = make_esd(256)) == (ESD *)0)
X		return(eNoMemory);
X
X	if(erc = gstr(param,fname))
X		goto RETURN;
X
X	if(iv[0] = (long)mkdir(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 cmd_mkdir */
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))
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
echo "File pcmdfile.c is complete"
chmod 0644 pcmdfile.c || echo "restore of pcmdfile.c fails"
echo "x - extracting pcmdif.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > pcmdif.c &&
X/* CHK=0x5189 */
X/*+-------------------------------------------------------------------------
X	pcmdif.c - ecu procedure if commands
X	Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X
X    IFI $i0 rel-op $i1 cmd
X    IFS $s0 rel-op $s1 cmd
X
X    where rel-op is "=", "==", "!=", "<>", ">", "<", ">=", "=<"
X
X  Defined functions:
X	_evaluate_ifi(param,ptruth)
X	_evaluate_ifs(param,ptruth)
X	_if_common(param,truth)
X	cmd_else(param)
X	cmd_ifi(param)
X	cmd_ifs(param)
X	get_relop(param,op_returned)
X	test_truth_int(int1,relop,int2)
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 <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/*+-------------------------------------------------------------------------
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	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    _evaluate_ifi(param,ptruth)
X--------------------------------------------------------------------------*/
Xint
X_evaluate_ifi(param,ptruth)
XESD *param;
Xint *ptruth;
X{
Xregister erc;
Xint relop;
Xlong int1;
Xlong int2;
X
X	if(erc = gint(param,&int1))
X		return(erc);
X	if(erc = get_relop(param,&relop))
X		return(erc);
X	if(erc = gint(param,&int2))
X		return(erc);
X
X	*ptruth = test_truth_int(int1,relop,int2);
X	return(0);
X
X}   /* end of _evaluate_ifi */
X
X/*+-------------------------------------------------------------------------
X    _evaluate_ifs(param,ptruth)
X--------------------------------------------------------------------------*/
Xint
X_evaluate_ifs(param,ptruth)
XESD *param;
Xint *ptruth;
X{
Xregister erc;
XESD str1,str2;
Xchar str1_str[256];
Xchar str2_str[256];
Xint relop;
Xint strcmp_result;
X
X	str1.pb = str1_str;
X	str1.maxcb = sizeof(str1_str) - 1;
X	str1.cb = 0;
X	str1.index = 0;
X
X	str2.pb = str2_str;
X	str2.maxcb = sizeof(str2_str) - 1;
X	str2.cb = 0;
X	str2.index = 0;
X
X	if(erc = gstr(param,&str1))
X		return(erc);
X	if(erc = get_relop(param,&relop))
X		return(erc);
X	if(erc = gstr(param,&str2))
X		return(erc);
X
X	null_terminate_esd(&str1);
X	null_terminate_esd(&str2);
X
X	strcmp_result = strcmp(str1.pb,str2.pb);
X
X	switch(relop)
X	{
X	case OP_EQ:
X		*ptruth = (strcmp_result == 0);
X		break;
X	case OP_NE:
X		*ptruth = (strcmp_result != 0);
X		break;
X	case OP_GT:
X		*ptruth = (strcmp_result > 0);
X		break;
X	case OP_LT:
X		*ptruth = (strcmp_result < 0);
X		break;
X	case OP_GE:
X		*ptruth = (strcmp_result >= 0);
X		break;
X	case OP_LE:
X		*ptruth = (strcmp_result <= 0);
X		break;
X	default:
X		return(eInvalidStrOp);
X	}
X
X	return(0);
X
X}   /* end of _evaluate_ifs */
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;
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 = _evaluate_ifi(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 = _evaluate_ifs(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(!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    cmd_ifi(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_ifi(param)
XESD *param;
X{
Xregister erc;
Xint relop;
Xlong int1;
Xlong int2;
Xint truth;
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(!proc_level)
X		return(eNotExecutingProc);
X
X	if(erc = gint(param,&int1))
X		return(erc);
X	if(erc = get_relop(param,&relop))
X		return(erc);
X	if(erc = gint(param,&int2))
X		return(erc);
X
X	truth = test_truth_int(int1,relop,int2);
X	erc = _if_common(param,truth);
X	if_level--;
X	return(erc);
X
X}   /* end of cmd_ifi */
X
X/*+-------------------------------------------------------------------------
X    cmd_ifs(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_ifs(param)
XESD *param;
X{
Xregister erc;
Xregister truth = 0;
XESD str1,str2;
Xchar str1_str[256];
Xchar str2_str[256];
Xint relop;
Xint strcmp_result;
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	str1.pb = str1_str;
X	str1.maxcb = sizeof(str1_str) - 1;
X	str1.cb = 0;
X	str1.index = 0;
X
X	str2.pb = str2_str;
X	str2.maxcb = sizeof(str2_str) - 1;
X	str2.cb = 0;
X	str2.index = 0;
X
X	if(erc = gstr(param,&str1))
X		return(erc);
X	if(erc = get_relop(param,&relop))
X		return(erc);
X	if(erc = gstr(param,&str2))
X		return(erc);
X
X	null_terminate_esd(&str1);
X	null_terminate_esd(&str2);
X	strcmp_result = strcmp(str1.pb,str2.pb);
X	switch(relop)
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	erc = _if_common(param,truth);
X	if_level--;
X	return(erc);
X
X}   /* end of cmd_ifs */
X
X/*+-------------------------------------------------------------------------
X	cmd_else(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_else(param)
XESD *param;
X{
X	return(eElseCommand);
X}	/* end of cmd_else */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of pcmdif.c */
SHAR_EOF
chmod 0644 pcmdif.c || echo "restore of pcmdif.c fails"
echo "x - extracting pcmdtty.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > pcmdtty.c &&
X/* CHK=0x426A */
X/*+-------------------------------------------------------------------------
X	pcmdtty.c - tty (console) related procedure commands
X	Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	cmd_cls(param)
X	cmd_color(param)
X	cmd_cursor(param)
X	cmd_fkey(param)
X	cmd_icolor(param)
X	cmd_scrdump(param)
X	cmd_vidnorm(param)
X	cmd_vidrev(param)
X	ifunc_colors(pvalue)
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 "esd.h"
X#include "tty.h"
X
Xextern int proctrace;
Xextern ulong current_colors;
X
X/*+-------------------------------------------------------------------------
X	cmd_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--------------------------------------------------------------------------*/
Xcmd_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;
SHAR_EOF
echo "End of part 17"
echo "File pcmdtty.c is continued in part 18"
echo "18" > 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