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

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


---- Cut Here and unpack ----
#!/bin/sh
# this is part 19 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file proc.c continued
#
CurArch=19
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 proc.c"
sed 's/^X//' << 'SHAR_EOF' >> proc.c
X	cmd_do(param)
X	cmd_goto(param)
X	cmd_gotob(param)
X	cmd_return(param)
X	do_proc(argc,argv)
X	dump_proc(pcb)
X	execute_esd(tesd)
X	execute_goto(pcb,goto_type)
X	execute_labelled_esd(tesd)
X	execute_proc(pcb)
X	find_labelled_lcb(label,first,last)
X	find_proc_cmd(cmd_list,cmd)
X	find_procedure(name)
X	free_lcb_chain(lcb)
X	show_error_position(pcb)
X	trace_proc_cmd(pcb)
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
X#define NEED_P_CMD
X#include "ecucmd.h"
X
Xextern int rcvr_pid;
Xextern int interrupt;
Xextern int proc_interrupt;
X
XPCB *pcb_stack[PROC_STACK_MAX];
X
Xint proc_level = 0;
Xint proctrace = 0;
X
Xchar goto_label[64];
X
X/*+-------------------------------------------------------------------------
X	_get_goto_label(param)
X--------------------------------------------------------------------------*/
Xint
X_get_goto_label(param)
XESD *param;
X{
Xregister erc;
Xregister ESD *label_esd;
X
X	goto_label[0] = 0;
X	if(erc = get_alphanum_zstr(param,goto_label,sizeof(goto_label)))
X	{
X		if((label_esd = make_esd(64)) == (ESD *)0)
X			return(eNoMemory);
X		if(!(erc = gstr(param,label_esd)))
X			strcpy(goto_label,label_esd->pb);
X		free_esd(label_esd);
X	}
X
X	return(erc);
X
X}	/* end of __get_goto_label */
X
X/*+-------------------------------------------------------------------------
X	cmd_goto(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_goto(param)
XESD *param;
X{
X
X	if(_get_goto_label(param))
X		return(eInvalidLabel);
X	return(eProcAttn_GOTO);
X
X}	/* end of cmd_goto */
X
X/*+-------------------------------------------------------------------------
X	cmd_gotob(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_gotob(param)
XESD *param;
X{
X
X	if(_get_goto_label(param))
X		return(eInvalidLabel);
X	return(eProcAttn_GOTOB);
X
X}	/* end of cmd_gotob */
X
X/*+-------------------------------------------------------------------------
X	cmd_return(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_return(param)
XESD *param;
X{
Xlong value = 0;
X	if(!gint(param,&value))
X	{
X		value &= (e_USER - 1);
X		if(proctrace)
X			pprintf("return value %ld\n",value);
X		return((int)value);
X	}
X	return(eProcAttn_RETURN);
X}	/* end of cmd_return */
X
X/*+-------------------------------------------------------------------------
X	find_labelled_lcb(label,first,last)
Xsearch for match between label
X--------------------------------------------------------------------------*/
XLCB *
Xfind_labelled_lcb(label,first,last)
Xchar *label;
Xregister LCB *first;
XLCB *last;
X{
Xregister llen = strlen(label);
XESD *text;
X
X	while(first)
X	{
X		text = first->text;
X		if((text->cb >= llen) && (!strncmp(text->pb,label,llen))
X			&& (!text->pb[llen] || isspace(text->pb[llen])))
X			return(first);
X
X		if(first == last)
X			return((LCB *)0);
X		first = first->next;
X	}
X	pputs("find_labelled_lab logic error\n");
X	return((LCB *)0);
X
X}	/* end of find_labelled_lcb */
X
X/*+-------------------------------------------------------------------------
X	execute_goto(pcb,goto_type)
X--------------------------------------------------------------------------*/
Xexecute_goto(pcb,goto_type)
XPCB *pcb;
Xint goto_type;
X{
XLCB *next;	/* next lcb to execute */
X
X	switch(goto_type)
X	{
X		case eProcAttn_GOTO:
X			if(!(next = find_labelled_lcb(goto_label,pcb->current,pcb->last)))
X				next = find_labelled_lcb(goto_label,pcb->first,pcb->current);
X			break;
X		case eProcAttn_GOTOB:
X			if(!(next = find_labelled_lcb(goto_label,pcb->first,pcb->current)))
X				next = find_labelled_lcb(goto_label,pcb->current,pcb->last);
X			break;
X	}
X	if(next)
X	{
X		pcb->current = next;
X		return(0);
X	}
X	pprintf("goto label not found: %s\n",goto_label);
X	return(eFATAL_ALREADY);
X
X}	/* end of execute_goto */
X
X/*+-------------------------------------------------------------------------
X	show_error_position(pcb)
Xcursor MUST be at left margin when this is called
X--------------------------------------------------------------------------*/
Xvoid
Xshow_error_position(pcb)
XPCB *pcb;
X{
XESD *tesd = pcb->current->text;
Xregister itmp = tesd->old_index;
Xchar tag[64];
X
X	sprintf(tag,"%s %u> ",pcb->argv[0],pcb->current->lineno);
X	pputs(tag);
X	pputs(tesd->pb);
X	pputs("\n");
X	itmp = strlen(tag) + tesd->old_index;
X	while(itmp--)
X		pputc(' ');
X	pputs("^\n");
X
X}	/* end of show_error_position */
X
X/*+-------------------------------------------------------------------------
X	find_proc_cmd(cmd_list,cmd)
X--------------------------------------------------------------------------*/
XP_CMD *
Xfind_proc_cmd(cmd_list,cmd)
Xregister P_CMD *cmd_list;
Xregister char *cmd;
X{
X	while(cmd_list->token != -1)
X	{
X		if(!strcmp(cmd_list->cmd,cmd))
X			break;
X		cmd_list++;
X	}
X	return((cmd_list->token == -1) ? (P_CMD *)0 : cmd_list);
X
X}	/* end of find_proc_cmd */
X
X/*+-------------------------------------------------------------------------
X	execute_esd(tesd)
X--------------------------------------------------------------------------*/
Xexecute_esd(tesd)
XESD *tesd;
X{
Xint erc;
XP_CMD *pcmd;
Xstatic P_CMD *set_pcmd = (P_CMD *)0;	/* quick access to 'set' */
Xchar cmd[32];
X
X	/* if blank, skip it */
X	if(skip_cmd_break(tesd))
X		return(0);
X
X	/* if comment, skip it */
X	if(!skip_cmd_char(tesd,'#'))
X		return(0);
X
X	if(*(tesd->pb + tesd->index) == '{')
X	{
X		pputs("invalid '{'\n");
X		return(eFATAL_ALREADY);
X	}
X
X	while(1)
X	{
X		/* get command -- allow leading '$' to assume 'set' command */
X		if(*(tesd->pb + tesd->index) == '$')
X		{
X			/* find 'set' in the list -- save for rapid access later */
X			if(set_pcmd)
X				pcmd = set_pcmd;
X			else if((pcmd = find_proc_cmd(icmd_cmds,"set")) == (P_CMD *)0)
X				return(eInternalLogicError);
X			else
X				set_pcmd = pcmd;
X		}
X		else
X		{
X			if(get_alphanum_zstr(tesd,cmd,sizeof(cmd)))
X				return(eIllegalCommand);
X			/* find it in the list */
X			if((pcmd = find_proc_cmd(icmd_cmds,cmd)) == (P_CMD *)0)
X				return(eIllegalCommand);
X		}
X
X		/* check to see if this command available for procedure */
X		if(!pcmd->proc)
X			return(eInteractiveCmd);
X
X		/* execute the command */
X		if(erc = (*pcmd->proc)(tesd))
X			return(erc);
X
X		/* look for comment */
X		if(!skip_cmd_char(tesd,'#'))
X			break;
X
X		/* look for multiple commands on line */
X		if(skip_cmd_char(tesd,';'))
X			break;
X
X		/* if blank after ';', skip it */
X		if(skip_cmd_break(tesd))
X			break;
X	}
X	return(0);
X		
X}	/* end of execute_esd */
X
X/*+-------------------------------------------------------------------------
X	execute_labelled_esd(tesd)
X--------------------------------------------------------------------------*/
Xexecute_labelled_esd(tesd)
XESD *tesd;
X{
Xregister index = 0;
Xregister cb = tesd->cb;
Xregister char *pb = tesd->pb;
X
X/* reset indices */
X	tesd->index = index;
X	tesd->old_index = index;
X
X/* if comment, skip it */
X	if(!skip_cmd_char(tesd,'#'))
X		return(0);
X
X/* skip over any label */
X	while(!isspace(*(pb + index)) && (index < cb))
X		index++;
X	tesd->index = index;
X	tesd->old_index = index;
X
X	return(execute_esd(tesd));
X}	/* end of execute_labelled_esd */
X
X/*+-------------------------------------------------------------------------
X	dump_proc(pcb)
X--------------------------------------------------------------------------*/
Xvoid
Xdump_proc(pcb)
XPCB *pcb;
X{
Xint itmp;
XLCB *lcb;
X
X	pprintf("------ pcb @ 0x%08lx -----------------\n",pcb);
X	pprintf("argc=%d first=0x%08lx last=0x%08lx\n",pcb->argc,
X		pcb->first,pcb->last);
X	for(itmp = 0; itmp < pcb->argc; itmp++)
X	{
X		pprintf("argv(%d) @ 0x%lx: '%s'\n",itmp,pcb->argv[itmp],
X			pcb->argv[itmp]);
X	}
X	pputs("\n");
X	lcb = pcb->first;
X	while(lcb)
X	{
X		pprintf("lcb @ 0x%08lx   lineno=%u\n",lcb,lcb->lineno);
X		pputs("\n");
X		lcb = lcb->next;
X	}
X	pflush();
X}	/* end of dump_proc */
X
X/*+-------------------------------------------------------------------------
X	trace_proc_cmd(pcb) - if asked, show command
X--------------------------------------------------------------------------*/
Xvoid
Xtrace_proc_cmd(pcb)
XPCB *pcb;
X{
X	if(proctrace)
X	{
X		pprintf("%s %u> ",pcb->argv[0],pcb->current->lineno);
X		pputs(pcb->current->text->pb);
X		pputc('\n');
X	}
X
X}	/* end of trace_proc_cmd */
X
X/*+-------------------------------------------------------------------------
X	execute_proc(pcb)
X--------------------------------------------------------------------------*/
Xexecute_proc(pcb)
XPCB *pcb;
X{
Xregister iargv;
Xint erc = 0;
X
X	if(proc_level == PROC_STACK_MAX)
X		return(eProcStackTooDeep);
X
X	pcb_stack[proc_level++] = pcb;
X	pcb->current = pcb->first;
X	mkv_proc_starting(pcb);
X
X	while(pcb->current)
X	{
X		/* execute the command */
X		trace_proc_cmd(pcb);
X		if(erc = execute_labelled_esd(pcb->current->text))
X		{
X			/* handle other classes of errors */
X			switch(erc & 0xF000)
X			{
X				case e_WARNING:		/* warning */
X					erc = 0;
X					break;
X
X				case e_FATAL:		/* fatal */
X					goto PROC_RETURN;
X
X				case e_ProcAttn:	/* proc attention */
X					switch(erc)
X					{
X						case eProcAttn_GOTO:
X						case eProcAttn_GOTOB:
X							if(erc = execute_goto(pcb,erc))
X								break;	/* didn't find it */
X							continue;	/* pcb->current is now goto target */
X
X						case eProcAttn_RETURN:
X							erc = 0;
X							break;
X
X						case eProcAttn_Interrupt:
X						case eProcAttn_ESCAPE:
X							pprintf(
X								"procedure %s interrupted.\n",pcb->argv[0]);
X							erc = eFATAL_ALREADY;
X							break;
X
X						default:
X							pprintf("procedure error 0x%x\n",erc);
X							erc = eFATAL_ALREADY;
X							break;
X					}
X					goto PROC_RETURN;
X
X				default:	/* must be proc return error code */
X					goto PROC_RETURN;
X					break;
X			}
X		}
X
X		if(proc_interrupt)
X		{
X			proc_interrupt = 0;
X			interrupt = 0;
X			pprintf("procedure %s interrupted\n",pcb->argv[0]);
X			erc = eFATAL_ALREADY;
X		}
X
X		if(erc)
X			break;
X		pcb->current = pcb->current->next;
X	}
X
XPROC_RETURN:
X	mkv_proc_terminating(pcb);
X	if(erc)
X	{
X		if((erc > 0) && (erc < e_USER))
X		{
X			pprintf(">>procedure %s returned %d\n",pcb->argv[0],erc);
X			erc |= e_USER;
X		}
X		else if((erc > e_USER) && (erc <= 0x1FFF))
X		{
X			;	/* already said it */
X		}
X		else
X		{
X			if(erc != eFATAL_ALREADY)
X			{
X				proc_error(erc);
X				erc = eFATAL_ALREADY;
X			}
X			show_error_position(pcb);
X		}
X	}
X	pcb_stack[--proc_level] = (PCB *)0;
X	if(erc && !proc_level)
X		plog_control((char *)0);
X	return(erc);
X}	/* end of execute_proc */
X
X/*+-------------------------------------------------------------------------
X	free_lcb_chain(lcb)
X--------------------------------------------------------------------------*/
Xvoid
Xfree_lcb_chain(lcb)
Xregister LCB *lcb;
X{
XLCB *plcb;
X
X	while(lcb)
X	{
X		if(lcb->text)
X			free_esd(lcb->text);
X		plcb  = lcb;
X		lcb = lcb->next;
X		free((char *)plcb);
X	}
X
X}	/* end of free_lcb_chain */
X
X/*+-------------------------------------------------------------------------
X	find_procedure(name)
X--------------------------------------------------------------------------*/
Xchar *
Xfind_procedure(name)
Xchar *name;
X{
Xstatic char procpath[256];
X
X/* try to find proc file in current directory */
X	strcpy(procpath,name);
X	strcat(procpath,".ep");
X	if(access(procpath,4))
X	{
X		/* try to find proc file in home .ecu subdirectory */
X		get_home_dir(procpath);
X		strcat(procpath,"/.ecu/");
X		strcat(procpath,name);
X		strcat(procpath,".ep");
X		if(access(procpath,4))
X			return((char *)0);
X	}
X	return(procpath);
X
X}	/* end of find_procedure */
X
X/*+-------------------------------------------------------------------------
X	do_proc(argc,argv) - entry from ksr mode
X--------------------------------------------------------------------------*/
Xdo_proc(argc,argv)
Xint argc;
Xchar **argv;
X{
Xregister itmp;
Xint itmp2;
Xint erc;
Xint iargv;
Xchar *pargv[MAX_PARGV];
Xint ipargv = 0;
Xchar s256[256];
Xchar *procpath;
XFILE *fp;
XPCB *pcb = (PCB *)0;
XLCB *lcb;
XLCB *plcb;
Xushort line_count = 0;
Xextern ulong current_colors;
Xulong colors_at_entry = current_colors;
X
X	proc_interrupt = 0;
X	interrupt = 0;
X	for(iargv = 0; iargv < argc; iargv++)
X	{
X		if(ipargv == MAX_PARGV)
X		{
X			pprintf("\nToo many arguments to %s invocation\n",pargv[0]);
X			erc = eFATAL_ALREADY;
X			goto RETURN;
X		}
X		pargv[ipargv++] = argv[iargv];
X	}
X
X	if(!ipargv)
X	{
X		pputs("\nno procedure name given\n");
X		erc = eFATAL_ALREADY;
X		goto RETURN;
X	}
X
X	if(!(procpath = find_procedure(pargv[0])))
X	{
X		pprintf("\nprocedure %s not found\n",pargv[0]);
X		erc = eFATAL_ALREADY;
X		goto RETURN;
X	}
X	fp = fopen(procpath,"r");
X
X	if((pcb = (PCB *)malloc(sizeof(PCB))) == (PCB *)0)
X	{
X		erc = eNoMemory;
X		goto RETURN;
X	}
X
X	pcb->argv = pargv;
X	pcb->argc = ipargv;
X	pcb->first = (LCB *)0;
X
X	plcb = (LCB *)0;
X	line_count = 0;
X	while(1)
X	{
X		if(fgets(s256,sizeof(s256),fp) == NULL)
X			break;
X		line_count++;
X
X		itmp = strlen(s256) - 1;	/* skip blank lines */
X		if(!itmp)
X			continue;
X		s256[itmp] = 0;				/* kill trailing NL */
X		for(itmp2 = 0; itmp2 < itmp; itmp2++)
X		{
X			if(s256[itmp2] == 0x09)
X				s256[itmp2] = 0x20;
X		}
X		if(s256[0] == '#')	 		/* skip comments */
X			continue;
X
X		if((lcb = (LCB *)malloc(sizeof(LCB))) == (LCB *)0)
X		{
X			fclose(fp);
X			erc = eNoMemory;
X			goto RETURN;
X		}
X
X		lcb->prev = plcb;
X		lcb->next = (LCB *)0;
X		lcb->lineno = line_count;
X
X		if(plcb)
X			plcb->next = lcb;
X		else
X			pcb->first = lcb;
X
X		if((lcb->text = make_esd(itmp)) == (ESD *)0)
X		{
X			fclose(fp);
X			erc = eNoMemory;
X			goto RETURN;
X		}
X		strcpy(lcb->text->pb,s256);
X		lcb->text->cb = itmp;
X		null_terminate_esd(lcb->text);
X		plcb = lcb;
X	}
X	fclose(fp);
X	pcb->last = lcb;
X	if(line_count)
X		erc = execute_proc(pcb);
X	else
X		erc = eProcEmpty;
X
XRETURN:
X	if(pcb)
X	{
X		if(pcb->first)
X			free_lcb_chain(pcb->first);
X		free((char *)pcb);
X	}
X	if((erc > e_USER) && (erc <= 0x1FFF))
X		erc -= e_USER;
X	if(erc > e_USER)
X		setcolor(colors_at_entry);
X	return(erc);
X
X}	/* end of do_proc */
X
X/*+-------------------------------------------------------------------------
X	cmd_do(param)
X--------------------------------------------------------------------------*/
Xcmd_do(param)
XESD *param;
X{
Xint erc;
Xregister ipargv;
Xchar *cmd_copy;
Xchar *pargv[MAX_PARGV];
XESD *pargv_esd[MAX_PARGV];
Xint pargc = 0;
X
X	if((cmd_copy = malloc(param->cb)) == (char *)0)
X		return(eNoMemory);
X	strcpy(cmd_copy,param->pb + param->old_index);
X	while(pargc != MAX_PARGV)
X	{
X		if(end_of_cmd(param))
X			break;
X		if((pargv_esd[pargc] = make_esd(256)) == (ESD *)0)
X		{
X			erc = eNoMemory;
X			goto RETURN;
X		}
X		if(erc = gstr(param,pargv_esd[pargc]))
X			goto RETURN;
X		pargv[pargc] = pargv_esd[pargc]->pb;
X		pargc++;
X	}
X
X	if(pargc < MAX_PARGV)
X		erc = do_proc(pargc,pargv);
X	else
X	{
X		pprintf("too many arguments to procedure\n");
X		erc = eFATAL_ALREADY;
X	}
X
XRETURN:
X	free(cmd_copy);
X	for(ipargv = 0; ipargv < pargc; ipargv++)
X		free_esd(pargv_esd[ipargv]);
X	return(erc);
X
X}	/* end of cmd_do */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of proc.c */
SHAR_EOF
echo "File proc.c is complete"
chmod 0644 proc.c || echo "restore of proc.c fails"
echo "x - extracting proc_error.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > proc_error.c &&
X/* CHK=0x2E63 */
X/*+-------------------------------------------------------------------------
X	proc_error.c - print ecu procedure error
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:07-01-1989-16:46-build_err-creation from ecuerror.h */
X
X#include "ecu.h"
X#include "ecuerror.h"
X
X/*+-------------------------------------------------------------------------
X	proc_error(erc) - print error message
X--------------------------------------------------------------------------*/
Xproc_error(erc)
Xint erc;
X{
X	switch(erc)
X	{
X		case eProcEmpty:
X			pputs("empty procedure\n");
X			break;
X		case eConnectFailed:
X			pputs("failed to connect\n");
X			break;
X		case eNoSwitches:
X			pputs("no switches to command\n");
X			break;
X		case eIllegalCommand:
X			pputs("invalid command\n");
X			break;
X		case eNoMemory:
X			pputs("no more memory available\n");
X			break;
X		case eSyntaxError:
X			pputs("syntax error\n");
X			break;
X		case eIllegalVarNumber:
X			pputs("variable number is invalid or out of range\n");
X			break;
X		case eIllegalVarType:
X			pputs("unrecognized variable type\n");
X			break;
X		case eNotInteger:
X			pputs("integer expected and not found\n");
X			break;
X		case eCONINT:
X			pputs("abort due to interrupt\n");
X			break;
X		case eInvalidFunction:
X			pputs("invalid function name\n");
X			break;
X		case eMissingLeftParen:
X			pputs("did not find expected left paren\n");
X			break;
X		case eMissingRightParen:
X			pputs("did not find expected right paren\n");
X			break;
X		case eCommaExpected:
X			pputs("expected comma not found\n");
X			break;
X		case eProcStackTooDeep:
X			pputs("procedure stack depth exceeded\n");
X			break;
X		case eInvalidRelOp:
X			pputs("invalid relational operator\n");
X			break;
X		case eInvalidIntOp:
X			pputs("invalid integer operator\n");
X			break;
X		case eInvalidStrOp:
X			pputs("invalid string operator\n");
X			break;
X		case eNotExecutingProc:
X			pputs("not executing DO at this time\n");
X			break;
X		case eInvalidLabel:
X			pputs("invalid label\n");
X			break;
X		case eInternalLogicError:
X			pputs("internal logic error ... whoops\n");
X			break;
X		case eEOF:
X			pputs("end of file or read error\n");
X			break;
X		case eBufferTooSmall:
X			pputs("string too long\n");
X			break;
X		case eNoParameter:
X			pputs("expected parameter not found\n");
X			break;
X		case eBadParameter:
X			pputs("inappropriate parameter\n");
X			break;
X		case eInvalidHexNumber:
X			pputs("invalid hexadecimal digit\n");
X			break;
X		case eInvalidDecNumber:
X			pputs("invalid decimal digit\n");
X			break;
X		case eInvalidOctNumber:
X			pputs("invalid octal digit\n");
X			break;
X		case eInteractiveCmd:
X			pputs("interactive command\n");
X			break;
X		case eNoLineAttached:
X			pputs("no line (modem) attached\n");
X			break;
X		case eBadFileNumber:
X			pputs("file number out of range\n");
X			break;
X		case eNotImplemented:
X			pputs("not implemented\n");
X			break;
X		case eDuplicateMatch:
X			pputs("more than one condition matches\n");
X			break;
X		case eColonExpected:
X			pputs("expected colon not found\n");
X			break;
X		case eLabelInvalidHere:
X			pputs("label not allowed on this statement\n");
X			break;
X		case eNoCloseFrame:
X			pputs("missing '}' for '{'\n");
X			break;
X		case eNoFrame:
X			pputs("missing command or command group after 'while' or 'if'\n");
X			break;
X		case eMissingCommand:
X			pputs("expected command not found\n");
X			break;
X		case eBreakCommand:
X			pputs("'break' outside 'while'\n");
X			break;
X		case eContinueCommand:
X			pputs("'continue' outside 'while'\n");
X			break;
X		case eElseCommand:
X			pputs("'else' without matching 'if'\n");
X			break;
X		case eInvalidVarName:
X			pputs("invalid variable name\n");
X			break;
X		case eNoSuchVariable:
X			pputs("variable by this name not defined\n");
X			break;
X		case eProcAttn_GOTO:
X			pputs("GOTO detected\n");
X			break;
X		case eProcAttn_GOTOB:
X			pputs("GOTOB detected\n");
X			break;
X		case eProcAttn_RETURN:
X			pputs("RETURN detected\n");
X			break;
X		case eProcAttn_ESCAPE:
X			pputs("ESCAPE detected\n");
X			break;
X		case eProcAttn_Interrupt:
X			pputs("procedure interrupted\n");
X			break;
X		case eFATAL_ALREADY:
X		case eWARNING_ALREADY:
X			break;
X		default:
X			pprintf("unknown error %x\n",erc);
X			break;
X	}
X} /* end of proc_error */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of proc_error.c */
SHAR_EOF
chmod 0644 proc_error.c || echo "restore of proc_error.c fails"
echo "x - extracting procframe.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > procframe.c &&
X/* CHK=0x5527 */
X/*+-------------------------------------------------------------------------
X	procframe.c - execute frame of statements
X	Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	cmd_break(param);
X	cmd_continue(param);
X	execute_frame(truth)
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 "ecukey.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include "var.h"
X#include "proc.h"
X
Xextern PCB *pcb_stack[PROC_STACK_MAX];
Xextern int proc_level;
Xextern int proc_interrupt;
Xextern int proctrace;
X
X/*+-------------------------------------------------------------------------
X	cmd_break(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_break(param)
XESD *param;
X{
X	return(eBreakCommand);
X}	/* end of cmd_break */
X
X/*+-------------------------------------------------------------------------
X	cmd_continue(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_continue(param)
XESD *param;
X{
X	return(eContinueCommand);
X}	/* end of cmd_continue */
X
X/*+-------------------------------------------------------------------------
X	execute_frame(truth)
X
X  pcb_stack[proc_level - 1]->current points to lcb behind frame: one
X  statement or { statements }
X
X  if truth true, execute frame, else skip it
X--------------------------------------------------------------------------*/
Xint
Xexecute_frame(truth)
Xint truth;
X{
Xregister itmp;
Xint erc = 0;
XPCB *pcb = pcb_stack[proc_level - 1];
XLCB *original_lcb = pcb->current;
XLCB *begin_lcb;
XESD *text;
Xint nest_level = 0;
Xint remember_break = 0;
X
X	if(!(pcb->current = pcb->current->next))
X	{
X		pcb->current = original_lcb;
X		return(eNoFrame);
X	}
X
X	text = pcb->current->text;
X	text->old_index = text->index = 0;
X
X	if(*text->pb != SPACE)
X		return(eLabelInvalidHere);
X	skip_cmd_break(text);
X
X/* handle single statement frame */
X	if(*(text->pb + text->index) != '{')
X	{
X		itmp = text->cb - text->index;
X		if( ((itmp > 2) && !strncmp(text->pb + text->index,"if",2)))
X		{
X			pputs("command must appear inside {} or on same line as else\n");
X			erc = eFATAL_ALREADY;
X		}
X		else if( ((itmp > 5) && !strncmp(text->pb + text->index,"while",5)))
X		{
X			pputs("command must appear inside {} within this context\n");
X			erc = eFATAL_ALREADY;
X		}
X		else if(truth)
X		{
X			trace_proc_cmd(pcb);
X			erc = execute_esd(text);
X		}
X		return(erc);
X	}
X
X/* we've got a {} frame */
X	begin_lcb = pcb->current;
X	pcb->current = pcb->current->next;
X	while(pcb->current)
X	{
X		if(proc_interrupt)
X			return(eCONINT);
X		text = pcb->current->text;
X		text->old_index = text->index = 0;
X		if(*text->pb != SPACE)
X			return(eLabelInvalidHere);
X		skip_cmd_break(text);
X		if(*(text->pb + text->index) == '}')
X		{
X			if(!nest_level)
X			{
X				text->index = text->cb;
X				if(remember_break)
X					return(eBreakCommand);
X				return(0);
X			}
X			nest_level--;
X		}
X		else if(truth)
X		{
X			trace_proc_cmd(pcb);
X			if(erc = execute_esd(text))
X			{
X				if(erc != eBreakCommand)
X					return(erc);
X				remember_break = 1;
X				truth = 0;
X			}
X		}
X		else if(*(text->pb + text->index) == '{')
X			nest_level++;
X		pcb->current = pcb->current->next;
X	}
X	pcb->current = begin_lcb;
X	return(eNoCloseFrame);
X	
X}	/* end of execute_frame */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of procframe.c */
SHAR_EOF
chmod 0644 procframe.c || echo "restore of procframe.c fails"
echo "x - extracting regexp.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > regexp.c &&
X/* CHK=0xEDBA */
X/*+-------------------------------------------------------------------------
X	regexp.c -- regular expression functions made sane
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-24-1989-20:40-wht-adapt for ecu */
X
X#include <stdio.h>
X#include "stdio_lint.h"
X#include "lint_args.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include "var.h"
X#include <setjmp.h>
X
X#define	CBRA	2
X#define	CCHR	4
X#define	CDOT	8
X#define	CCL	12
X#define	CDOL	20
X#define	CCEOF	22
X#define	CKET	24
X#define	CBACK	36
X
X#define	STAR	01
X#define	RNGE	03
X
X#define	NBRA	9
X
X#define	PLACE(c)	ep[c >> 3] |= bittab[c & 07]
X#define	ISTHERE(c)	(ep[c >> 3] & bittab[c & 07])
X
Xextern int proctrace;
Xextern int proc_level;
X
Xchar *braslist[NBRA];
Xchar *braelist[NBRA];
Xint nbra,ebra;
Xchar *match_start,*match_end,*locs;
Xint sed;
Xint nodelim;
Xint circf;
Xint low;
Xint size;
X
Xchar bittab[] = 
X{ 
X	1,2,4,8,16,32,64,128 };
X
Xjmp_buf	compile_error_jmpbuf;
X
Xchar *
Xcompile(pattern,ep,endbuf,seof)
Xregister char *ep;
Xchar *pattern,*endbuf;
X{
X	register char *sp = pattern;
X	register c;
X	register eof = seof;
X	char *lastep = pattern;
X	int cclcnt;
X	char bracket[NBRA],*bracketp;
X	int closed;
X	char neg;
X	int lc;
X	int i,cflg;
X
X	lastep = 0;
X	if((c = *sp++) == eof || c == '\n')
X	{
X		if(c == '\n')
X		{
X			--sp;
X			nodelim = 1;
X		}
X		if(*ep == 0 && !sed)
X			longjmp(compile_error_jmpbuf,41);
X		return;
X	}
X	bracketp = bracket;
X	circf = closed = nbra = ebra = 0;
X	if(c == '^')
X		circf++;
X	else
X		--sp;
X	while(1)
X	{
X		if(ep >= endbuf)
X			longjmp(compile_error_jmpbuf,50);
X		c = *sp++;
X		if(c != '*' && ((c != '\\') || (*sp != '{')))
X			lastep = ep;
X		if(c == eof)
X		{
X			*ep++ = CCEOF;
X			return;
X		}
X		switch(c)
X		{
X
X		case '.':
X			*ep++ = CDOT;
X			continue;
X
X		case '\n':
X			if(!sed)
X			{
X				--sp;
X				*ep++ = CCEOF;
X				nodelim = 1;
X				return;
X			}
X			else longjmp(compile_error_jmpbuf,36);
X		case '*':
X			if(lastep==0 || *lastep==CBRA || *lastep==CKET)
X				goto defchar;
X			*lastep |= STAR;
X			continue;
X
X		case '$':
X			if(*sp != eof && *sp != '\n')
X				goto defchar;
X			*ep++ = CDOL;
X			continue;
X
X		case '[':
X			if(&ep[17] >= endbuf)
X				longjmp(compile_error_jmpbuf,50);
X
X			*ep++ = CCL;
X			lc = 0;
X			for(i = 0; i < 16; i++)
X				ep[i] = 0;
X
X			neg = 0;
X			if((c = *sp++) == '^')
X			{
X				neg = 1;
X				c = *sp++;
X			}
X
X			do 
X			{
X				if(c == '\0' || c == '\n')
X					longjmp(compile_error_jmpbuf,49);
X				if(c == '-' && lc != 0)
X				{
X					if((c = *sp++) == ']')
X					{
X						PLACE('-');
X						break;
X					}
X					while(lc < c)
X					{
X						PLACE(lc);
X						lc++;
X					}
X				}
X				if(c == '\\')
X				{
X					switch(c = *sp++)
X					{
X					case 'n':
X						c = '\n';
X						break;
X					}
X				}
X				lc = c;
X				PLACE(c);
X			} while((c = *sp++) != ']');
X			if(neg)
X			{
X				for(cclcnt = 0; cclcnt < 16; cclcnt++)
X					ep[cclcnt] ^= -1;
X				ep[0] &= 0376;
X			}
X
X			ep += 16;
X
X			continue;
X
X		case '\\':
X			switch(c = *sp++)
X			{
X
X			case '(':
X				if(nbra >= NBRA)
X					longjmp(compile_error_jmpbuf,43);
X				*bracketp++ = nbra;
X				*ep++ = CBRA;
X				*ep++ = nbra++;
X				continue;
X
X			case ')':
X				if(bracketp <= bracket || ++ebra != nbra)
X					longjmp(compile_error_jmpbuf,42);
X				*ep++ = CKET;
X				*ep++ = *--bracketp;
X				closed++;
X				continue;
X
X			case '{':
X				if(lastep == (char *) (0))
X					goto defchar;
X				*lastep |= RNGE;
X				cflg = 0;
Xnlim:
X				c = *sp++;
X				i = 0;
X				do 
X				{
X					if('0' <= c && c <= '9')
X						i = 10 * i + c - '0';
X					else
X						longjmp(compile_error_jmpbuf,16);
X				} while(((c = *sp++) != '\\') && (c != ','));
X				if(i >= 255)
X					longjmp(compile_error_jmpbuf,11);
X				*ep++ = i;
X				if(c == ',')
X				{
X					if(cflg++)
X						longjmp(compile_error_jmpbuf,44);
X					if((c = *sp++) == '\\')
X						*ep++ = 255;
X					else 
X					{
X						--sp;
X						goto nlim;
X						/* get 2'nd number */
X					}
X				}
X				if(*sp++ != '}')
X					longjmp(compile_error_jmpbuf,45);
X				if(!cflg)	/* one number */
X					*ep++ = i;
X				else if((ep[-1] & 0377) < (ep[-2] & 0377))
X					longjmp(compile_error_jmpbuf,46);
X				continue;
X
X			case '\n':
X				longjmp(compile_error_jmpbuf,36);
X
X			case 'n':
X				c = '\n';
X				goto defchar;
X
X			default:
X				if(c >= '1' && c <= '9')
X				{
X					if((c -= '1') >= closed)
X						longjmp(compile_error_jmpbuf,25);
X					*ep++ = CBACK;
X					*ep++ = c;
X					continue;
X				}
X			}
X			/* Drop through to default to use \ to turn off special chars */
X
Xdefchar:
X		default:
X			lastep = ep;
X			*ep++ = CCHR;
X			*ep++ = c;
X		}
X	}
X}
X
Xstep(p1,p2)
Xregister char *p1,*p2;
X{
X	register c;
X
X	if(circf)
X	{
X		match_start = p1;
SHAR_EOF
echo "End of part 19"
echo "File regexp.c is continued in part 20"
echo "20" > 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