home *** CD-ROM | disk | FTP | other *** search
- From: wht@n4hgf.uucp (Warren Tucker)
- Newsgroups: comp.sources.misc
- Subject: v16i038: ECU async comm package rev 3.0, Part14/35
- Message-ID: <1991Jan6.052202.27970@sparky.IMD.Sterling.COM>
- Date: 6 Jan 91 05:22:02 GMT
- Approved: kent@sparky.imd.sterling.com
- X-Checksum-Snefru: 79bf8233 8714f8f2 43e8b8aa ac7fecbd
-
- Submitted-by: wht@n4hgf.uucp (Warren Tucker)
- Posting-number: Volume 16, Issue 38
- Archive-name: ecu3/part14
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # This is part 14 of ecu3
- if touch 2>&1 | fgrep 'amc' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- fi
- # ============= pcmdxfer.c ==============
- echo 'x - extracting pcmdxfer.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'pcmdxfer.c' &&
- X/*+-------------------------------------------------------------------------
- X pcmdxfer.c - ecu file transfer related procedure commands
- X wht@n4hgf.Mt-Park.GA.US
- X
- X Defined functions:
- X _make_bottom_label(param,default_flag,sending_flag)
- X _rx_error()
- X _send_common(execcmd)
- X pcmd_rk(param)
- X pcmd_rs(param)
- X pcmd_rx(param)
- X pcmd_ry(param)
- X pcmd_rz(param)
- X pcmd_sk(param)
- X pcmd_ss(param)
- X pcmd_sx(param)
- X pcmd_sy(param)
- X pcmd_sz(param)
- 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
- Xchar *strchr();
- X
- Xextern int proctrace;
- Xextern int last_child_wait_status;
- Xextern char curr_dir[];
- Xextern proc_level;
- Xextern PCB *pcb_stack[];
- X
- Xstatic char bottom_label[80];
- X
- X/*+-------------------------------------------------------------------------
- X _make_bottom_label(param,default_flag)
- X--------------------------------------------------------------------------*/
- X_make_bottom_label(param,default_flag,sending_flag)
- XESD *param;
- Xint default_flag;
- Xint sending_flag;
- X{
- Xregister erc;
- XESD *label = (ESD *)0;
- X
- X if(default_flag)
- X {
- X sprintf(bottom_label,
- X (sending_flag) ? "-C \"'Connected to %s'\" "
- X : "-C 'Connected to %s' ",
- X (shm->Lrname[0]) ? shm->Lrname : "?");
- X return(0);
- X }
- X if((label = make_esd(64)) == (ESD *)0)
- X return(eNoMemory);
- X if(erc = gstr(param,label,0))
- X {
- X free_esd(label);
- X return(erc);
- X }
- X strcpy(bottom_label,(sending_flag) ? "-C \"'" : "-C '");
- X strcat(bottom_label,label->pb);
- X strcat(bottom_label,(sending_flag) ? "'\"" : "'");
- X free_esd(label);
- X return(0);
- X
- X} /* end of _make_bottom_label */
- X
- X/*+-------------------------------------------------------------------------
- X _send_common(execcmd)
- Xfor "ecu knowledgeable" protocols only
- X--------------------------------------------------------------------------*/
- Xint
- X_send_common(execcmd)
- Xchar *execcmd;
- X{
- Xint erc = 0;
- X
- X file_xfer_start();
- X if(find_shell_chars(execcmd))
- X {
- X char *expcmd;
- X
- X if(expand_cmd_with_wildlist(execcmd,&expcmd))
- X {
- X pputs("No files match wildcard list\n");
- X iv[0] = -1;
- X return(0);
- X }
- X else
- X {
- X if(exec_cmd(expcmd))
- X erc = eFATAL_ALREADY;
- X free(expcmd);
- X }
- X }
- X else
- X {
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X }
- X lreset_ksr();
- X file_xfer_done_bell();
- X if(erc)
- X return(erc);
- X erc = report_send_status();
- X if(!erc)
- X iv[0] = 0;
- X if(erc == eProcAttn_Interrupt)
- X {
- X erc = 0;
- X iv[0] = 0x100L;
- X }
- X return(erc);
- X
- X
- X} /* end of _send_common */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_sx(param)
- X
- Xsx [-ak[l]] [<label-str>] <filelist-str>
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_sx(param)
- XESD *param;
- X{
- Xint erc;
- Xchar execcmd[384];
- Xchar switches[8];
- XESD *pathlist;
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,1))
- X return(erc);
- X
- X sprintf(execcmd,"ecusz -X -. %d ",shm->Liofd);
- X strcat(execcmd,bottom_label);
- X if(strchr(switches,'a'))
- X strcat(execcmd,"-a ");
- X else
- X strcat(execcmd,"-b ");
- X if(strchr(switches,'k'))
- X strcat(execcmd,"-k");
- X
- X if((pathlist = make_esd(256)) == (ESD *)0)
- X return(eNoMemory);
- X
- X if(erc = gstr(param,pathlist,1))
- X {
- X free_esd(pathlist);
- X return(erc);
- X }
- X
- X strcat(execcmd,pathlist->pb);
- X free_esd(pathlist);
- X return(_send_common(execcmd));
- X
- X} /* end of pcmd_sx */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_sy(param)
- X
- Xsy [-a[l]] [<label-str>] <filelist-str>
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_sy(param)
- XESD *param;
- X{
- Xint erc;
- Xchar execcmd[384];
- Xchar switches[8];
- XESD *pathlist;
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,1))
- X return(erc);
- X
- X sprintf(execcmd,"ecusz -Y -. %d -k ",shm->Liofd);
- X strcat(execcmd,bottom_label);
- X if(strchr(switches,'a'))
- X strcat(execcmd,"-a ");
- X else
- X strcat(execcmd,"-b ");
- X
- X if((pathlist = make_esd(256)) == (ESD *)0)
- X return(eNoMemory);
- X
- X if(erc = gstr(param,pathlist,1))
- X {
- X free_esd(pathlist);
- X return(erc);
- X }
- X
- X strcat(execcmd,pathlist->pb);
- X free_esd(pathlist);
- X return(_send_common(execcmd));
- X
- X} /* end of pcmd_sy */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_sz(param)
- X
- Xsz [-anf[l]] [<label-str>] <filelist-str>
- X-a ascii, else binary
- X-n send only newer, else all files
- X-f full, else simple pathnames
- X-l non-default bottom line label on transfer string
- X$i0 set to:
- X 0: file transfer completely successful
- X -1 program did not run
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_sz(param)
- XESD *param;
- X{
- Xint erc;
- Xchar execcmd[384];
- Xchar switches[8];
- XESD *pathlist;
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,1))
- X return(erc);
- X
- X sprintf(execcmd,"ecusz -Z -. %d -y ",shm->Liofd);
- X strcat(execcmd,bottom_label);
- X if(strchr(switches,'a'))
- X strcat(execcmd,"-a ");
- X else
- X strcat(execcmd,"-b ");
- X if(strchr(switches,'n'))
- X strcat(execcmd,"-n "); /* overrides -y choice earlier */
- X if(strchr(switches,'f'))
- X strcat(execcmd,"-f ");
- X
- X#ifdef WHT /* for testing */
- X if(strchr(switches,'p'))
- X strcat(execcmd,"-, ");
- X if(strchr(switches,'n'))
- X strcat(execcmd,"-@ ");
- X#endif
- X
- X if((pathlist = make_esd(256)) == (ESD *)0)
- X return(eNoMemory);
- X
- X if(erc = gstr(param,pathlist,1))
- X {
- X free_esd(pathlist);
- X return(erc);
- X }
- X
- X strcat(execcmd,pathlist->pb);
- X free_esd(pathlist);
- X return(_send_common(execcmd));
- X
- X} /* end of pcmd_sz */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_sk(param)
- X
- Xsk [-a] <str>
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_sk(param)
- XESD *param;
- X{
- Xint erc;
- Xchar execcmd[384];
- XESD *pathlist;
- Xchar switches[8];
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X sprintf(execcmd,"ckermit -l %d -b %u -p %c%s%s -s ",
- X shm->Liofd,shm->Lbaud,
- X (shm->Lparity) ? shm->Lparity : 'n',
- X (strchr(switches,'a')) ? "" : " -i",
- X (1 /* overwrite*/ ) ? "" : " -w");
- X
- X if(strchr(switches,'b'))
- X strcat(execcmd,"-a ");
- X else
- X strcat(execcmd,"-b ");
- X if(strchr(switches,'n'))
- X strcat(execcmd,"-n "); /* overrides -y choice earlier */
- X if(strchr(switches,'f'))
- X strcat(execcmd,"-f ");
- X
- X if((pathlist = make_esd(256)) == (ESD *)0)
- X return(eNoMemory);
- X
- X if(erc = gstr(param,pathlist,1))
- X {
- X free_esd(pathlist);
- X return(erc);
- X }
- X
- X file_xfer_start();
- X strcat(execcmd,pathlist->pb);
- X free_esd(pathlist);
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X file_xfer_done_bell();
- X lreset_ksr();
- X return(erc);
- X} /* end of pcmd_sk */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_ss(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_ss(param)
- XESD *param;
- X{
- Xint erc;
- Xchar execcmd[384];
- XESD *pathlist;
- X
- X sprintf(execcmd,"ecusea -. %d -/ %s -s ",shm->Liofd,curr_dir);
- X if((pathlist = make_esd(256)) == (ESD *)0)
- X return(eNoMemory);
- X
- X if(erc = gstr(param,pathlist,1))
- X {
- X free_esd(pathlist);
- X return(erc);
- X }
- X
- X strcat(execcmd,pathlist->pb);
- X free_esd(pathlist);
- X return(_send_common(execcmd));
- X
- X} /* end of pcmd_ss */
- X
- X/*+-------------------------------------------------------------------------
- X _rx_error()
- X--------------------------------------------------------------------------*/
- Xvoid
- X_rx_error()
- X{
- Xextern int last_child_wait_status;
- X
- X iv[0] = (last_child_wait_status & 0xFF)
- X ? 0x100L : (long)last_child_wait_status >> 8;
- X if(proctrace)
- X pprintf("$i00 = %ld, (%s)\n",iv[0],
- X (iv[0] == 0x100L) ? "interrupted" : "program exit status");
- X file_xfer_done_bell();
- X} /* end of _rx_error */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_rx(param)
- X
- Xrx [-b] <str>
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_rx(param)
- XESD *param;
- X{
- Xint erc = 0;
- Xchar execcmd[512];
- Xchar switches[8];
- XESD *tesd = make_esd(256);
- X
- X if(!tesd)
- X return(eNoMemory);
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X if(erc = gstr(param,tesd,1))
- X {
- X free_esd(tesd);
- X return(erc);
- X }
- X
- X last_child_wait_status = 0;
- X if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,0))
- X return(erc);
- X
- X sprintf(execcmd,"ecurz -X -. %d -c ",shm->Liofd);
- X strcat(execcmd,bottom_label);
- X if(!strchr(switches,'b'))
- X strcat(execcmd,"-b ");
- X else
- X strcat(execcmd,"-a ");
- X strcat(execcmd,tesd->pb);
- X free_esd(tesd);
- X file_xfer_start();
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X else
- X _rx_error();
- X return(erc);
- X} /* end of pcmd_rx */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_ry(param)
- X
- Xry
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_ry(param)
- XESD *param;
- X{
- Xint erc = 0;
- Xchar execcmd[512];
- Xchar switches[8];
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,0))
- X return(erc);
- X
- X last_child_wait_status = 0;
- X sprintf(execcmd,"ecurz -Y -. %d -y ",shm->Liofd);
- X strcat(execcmd,bottom_label);
- X file_xfer_start();
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X else
- X _rx_error();
- X return(erc);
- X} /* end of pcmd_ry */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_rz(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_rz(param)
- XESD *param;
- X{
- Xint erc = 0;
- Xchar execcmd[512];
- Xchar switches[8];
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,0))
- X return(erc);
- X
- X last_child_wait_status = 0;
- X sprintf(execcmd,"ecurz -Z -. %d ",shm->Liofd);
- X#ifdef WHT /* for testing */
- X if(strchr(switches,'c'))
- X strcat(execcmd,"-: ");
- X if(strchr(switches,'p'))
- X strcat(execcmd,"-, ");
- X if(strchr(switches,'n'))
- X strcat(execcmd,"-@ ");
- X#endif
- X strcat(execcmd,bottom_label);
- X file_xfer_start();
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X else
- X _rx_error();
- X return(erc);
- X} /* end of pcmd_rz */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_rk(param)
- X
- Xrk [-a]
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_rk(param)
- XESD *param;
- X{
- Xint erc = 0;
- Xchar execcmd[300];
- Xchar switches[8];
- X
- X get_switches(param,switches,sizeof(switches));
- X
- X last_child_wait_status = 0;
- X sprintf(execcmd,"ckermit -r -e 512 -l %d -b %d -p %c",
- X shm->Liofd,shm->Lbaud,(shm->Lparity) ? shm->Lparity : 'n');
- X if(strchr(switches,'a'))
- X strcat(execcmd,"-i ");
- X file_xfer_start();
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X file_xfer_done_bell();
- X return(erc);
- X} /* end of pcmd_rk */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_rs(param)
- X
- Xrs
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_rs(param)
- XESD *param;
- X{
- Xint erc = 0;
- Xchar execcmd[128];
- X
- X file_xfer_start();
- X sprintf(execcmd,"ecusea -r -. %d -/ %s",shm->Liofd,curr_dir);
- X if(exec_cmd(execcmd))
- X erc = eFATAL_ALREADY;
- X file_xfer_done_bell();
- X return(erc);
- X} /* end of pcmd_rs */
- X
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of pcmdxfer.c */
- SHAR_EOF
- $TOUCH -am 1224224290 'pcmdxfer.c' &&
- chmod 0644 pcmdxfer.c ||
- echo 'restore of pcmdxfer.c failed'
- Wc_c="`wc -c < 'pcmdxfer.c'`"
- test 11327 -eq "$Wc_c" ||
- echo 'pcmdxfer.c: original size 11327, current size' "$Wc_c"
- # ============= poutput.c ==============
- echo 'x - extracting poutput.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'poutput.c' &&
- X/*+-------------------------------------------------------------------------
- X poutput.c - ecu procedure output routines
- X wht@n4hgf.Mt-Park.GA.US
- X
- X Defined functions:
- X pcmd_plog(param)
- X pperror(str)
- X pputc(ch)
- X pputs(str)
- 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
- Xextern int proctrace;
- Xextern FILE *rcvr_log_fp;
- X
- XFILE *plog_fp = (FILE *)0;
- XESD *plog_name = (ESD *)0;
- X
- X/*+-------------------------------------------------------------------------
- X plogs(str)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xplogs(str)
- Xchar *str;
- X{
- X if(plog_fp)
- X fputs(str,plog_fp);
- X} /* end of plogs */
- X
- X/*+-------------------------------------------------------------------------
- X plogc(ch)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xplogc(ch)
- Xchar ch;
- X{
- X if(plog_fp)
- X fputc(ch,plog_fp);
- X} /* end of plogc */
- X
- X/*+-------------------------------------------------------------------------
- X pputc(ch) - put procedure output character to stderr and log
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpputc(ch)
- Xchar ch;
- X{
- X if(ch == NL)
- X fputc(CR,se);
- X fputc(ch,se);
- X if(plog_fp && (ch != CR))
- X fputc(ch,plog_fp);
- X if(rcvr_log_fp && (ch != CR))
- X fputc(ch,rcvr_log_fp);
- X} /* end of pputc */
- X
- X/*+-------------------------------------------------------------------------
- X pputs(str) - put procedure output string to stderr and log
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpputs(str)
- Xregister char *str;
- X{
- X while(*str)
- X {
- X if(*str == NL)
- X fputc(CR,se);
- X fputc(*str,se);
- X if(plog_fp && (*str != CR))
- X fputc(*str,plog_fp);
- X if(rcvr_log_fp && (*str != CR))
- X fputc(*str,rcvr_log_fp);
- X str++;
- X }
- X} /* end of pputs */
- X
- X/*+-------------------------------------------------------------------------
- X pflush()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpflush()
- X{
- X if(plog_fp)
- X fflush(plog_fp);
- X} /* end of pflush */
- X
- X/*+-------------------------------------------------------------------------
- X pperror(str)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpperror(str)
- Xchar *str;
- X{
- Xextern char *sys_errlist[];
- Xextern int sys_nerr;
- Xextern int errno;
- Xint save_errno = errno;
- X
- X if(str && *str)
- X {
- X pputs(str);
- X pputs(": ");
- X }
- X if(save_errno <= sys_nerr)
- X pputs(sys_errlist[save_errno]);
- X else
- X pprintf("error %d",save_errno);
- X pputs("\n");
- X} /* end of pperror */
- X
- X/*+-------------------------------------------------------------------------
- X plog_control(fname)
- X fname == 0, close
- X fname == 1, plog_name already plugged
- X--------------------------------------------------------------------------*/
- Xint
- Xplog_control(fname)
- Xchar *fname;
- X{
- X if(!fname) /* close */
- X {
- X if(plog_fp)
- X fclose(plog_fp);
- X plog_fp = (FILE *)0;
- X return(0);
- X }
- X
- X if(plog_fp)
- X plog_control((char *)0);
- X
- X if(fname != (char *)1)
- X {
- X strcpy(plog_name->pb,fname);
- X plog_name->cb = strlen(fname);
- X }
- X
- X if((plog_fp = fopen(plog_name->pb,"a")) == NULL)
- X {
- X pperror(plog_name->pb);
- X return(eFATAL_ALREADY);
- X }
- X return(0);
- X} /* end of plog_control */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_plog(param)
- X
- Xplog $s0 log to file
- Xplog off stop logging
- Xplog show status
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_plog(param)
- XESD *param;
- X{
- Xint erc;
- Xchar off_str[8];
- X
- X if(!skip_cmd_break(param)) /* if arguments */
- X {
- X if(!get_alpha_zstr(param,off_str,sizeof(off_str)))
- X {
- X if(strcmp(off_str,"off"))
- X return(eBadParameter);
- X erc = plog_control((char *)0);
- X }
- X else
- X {
- X if(erc = gstr(param,plog_name,1))
- X return(erc);
- X erc = plog_control((char *)1);
- X }
- X }
- X return(erc);
- X
- X} /* end of pcmd_plog */
- X
- X/*+-------------------------------------------------------------------------
- X poutput_init()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpoutput_init()
- X{
- X if((plog_name = make_esd(256)) == (ESD *)0)
- X {
- X ff(se,"Out of memory\r\n");
- X hangup(1);
- X }
- X} /* end of poutput_init */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of poutput.c */
- SHAR_EOF
- $TOUCH -am 1224224290 'poutput.c' &&
- chmod 0644 poutput.c ||
- echo 'restore of poutput.c failed'
- Wc_c="`wc -c < 'poutput.c'`"
- test 4352 -eq "$Wc_c" ||
- echo 'poutput.c: original size 4352, current size' "$Wc_c"
- # ============= pprintf.c ==============
- echo 'x - extracting pprintf.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'pprintf.c' &&
- X/*+-------------------------------------------------------------------------
- X pprintf.c - preocedure printf
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
- X
- X/* based on Portable vsprintf by Robert A. Larson <blarson@skat.usc.edu> */
- X
- X/* Copyright 1989 Robert A. Larson.
- X * Distribution in any form is allowed as long as the author
- X * retains credit, changes are noted by their author and the
- X * copyright message remains intact. This program comes as-is
- X * with no warentee of fitness for any purpouse.
- X *
- X * Thanks to Doug Gwen, Chris Torek, and others who helped clarify
- X * the ansi printf specs.
- X *
- X * Please send any bug fixes and improvments to blarson@skat.usc.edu .
- X * The use of goto is NOT a bug.
- X */
- X
- X#if !defined(BUILDING_LINT_ARGS)
- X
- X#include <stdio.h>
- X#include <varargs.h>
- X
- X#if defined(M_I386)
- X#define LONGINT
- X#endif
- X
- X/* This must be a typedef not a #define! */
- X#define NOVOID
- X#ifdef NOVOID
- Xtypedef char *pointer;
- X#else
- Xtypedef void *pointer;
- X#endif
- X
- Xtypedef int *intp;
- X
- X/*+-------------------------------------------------------------------------
- X pprintf(format,va_alist)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xpprintf(format,va_alist)
- Xregister char *format;
- Xva_dcl
- X{
- Xva_list args;
- Xregister char c;
- Xregister char *tp;
- Xchar tempfmt[64];
- X#ifndef LONGINT
- Xint longflag;
- X#endif
- Xchar accum_string[256];
- Xregister char *dp = accum_string;
- X
- X va_start(args);
- X
- X tempfmt[0] = '%';
- X while(c = *format++)
- X {
- X if(c=='%')
- X {
- X tp = &tempfmt[1];
- X#ifndef LONGINT
- X longflag = 0;
- X#endif
- Xcontinue_format:
- X switch(c = *format++)
- X {
- X case 's':
- X *tp++ = c;
- X *tp = '\0';
- X dp += sprintf(dp,tempfmt,va_arg(args,char *));
- X break;
- X case 'u':
- X case 'x':
- X case 'o':
- X case 'X':
- X#ifdef UNSIGNEDSPECIAL
- X *tp++ = c;
- X *tp = '\0';
- X#ifndef LONGINT
- X if(longflag)
- X dp += sprintf(dp,tempfmt,va_arg(args,unsigned long));
- X else
- X#endif
- X dp += sprintf(dp,tempfmt,va_arg(args,unsigned));
- X break;
- X#endif
- X case 'd':
- X case 'c':
- X case 'i':
- X *tp++ = c;
- X *tp = '\0';
- X#ifndef LONGINT
- X if(longflag)
- X dp += sprintf(dp,tempfmt,va_arg(args,long));
- X else
- X#endif
- X dp += sprintf(dp,tempfmt,va_arg(args,int));
- X break;
- X case 'f':
- X case 'e':
- X case 'E':
- X case 'g':
- X case 'G':
- X *tp++ = c;
- X *tp = '\0';
- X dp += sprintf(dp,tempfmt,va_arg(args,double));
- X break;
- X case 'p':
- X#if defined(M_I386)
- X dp += sprintf(dp,"0x%08lx",va_arg(args,pointer));
- X#else
- X#if defined(M_I286)
- X tp = va_arg(args,pointer);
- X#if defined(M_SDATA)
- X dp += sprintf(dp,"0x%04x",tp);
- X#else
- X dp += sprintf(dp,"%04x:%04x",(int)tp,(int)((long)tp >> 16));
- X#endif /* M_SDATA */
- X#else
- X>>>>>>>>>>>> model problem
- X#endif /* M_I286 */
- X#endif /* M_I386 */
- X break;
- X case '-':
- X case '+':
- X case '0':
- X case '1':
- X case '2':
- X case '3':
- X case '4':
- X case '5':
- X case '6':
- X case '7':
- X case '8':
- X case '9':
- X case '.':
- X case ' ':
- X case '#':
- X case 'h':
- X *tp++ = c;
- X goto continue_format;
- X case 'l':
- X#ifndef LONGINT
- X longflag = 1;
- X *tp++ = c;
- X#endif
- X goto continue_format;
- X case '*':
- X tp += sprintf(tp,"%d",va_arg(args,int));
- X goto continue_format;
- X case '%':
- X default:
- X *dp++ = c;
- X break;
- X }
- X }
- X else *dp++ = c;
- X }
- X *dp = '\0';
- X va_end(args);
- X pputs(accum_string);
- X} /* end of pprintf */
- X#endif /* !defined(BUILDING_LINT_ARGS) */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of pprintf.c */
- SHAR_EOF
- $TOUCH -am 1224224390 'pprintf.c' &&
- chmod 0644 pprintf.c ||
- echo 'restore of pprintf.c failed'
- Wc_c="`wc -c < 'pprintf.c'`"
- test 3525 -eq "$Wc_c" ||
- echo 'pprintf.c: original size 3525, current size' "$Wc_c"
- # ============= proc.c ==============
- echo 'x - extracting proc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'proc.c' &&
- X/*+-------------------------------------------------------------------------
- X proc.c - procedure command and control
- X wht@n4hgf.Mt-Park.GA.US
- X
- X Defined functions:
- X _cmd_gosub_common(param,type)
- X _get_goto_label(param)
- X pcmd_do(param)
- X pcmd_gosub(param)
- X pcmd_gosubb(param)
- X pcmd_goto(param)
- X pcmd_gotob(param)
- X pcmd_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,use_goto_label)
- 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/*: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
- 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,0)))
- 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 pcmd_goto(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_goto(param)
- XESD *param;
- X{
- X
- X if(!proc_level)
- X return(eNotExecutingProc);
- X if(_get_goto_label(param))
- X return(eInvalidLabel);
- X return(eProcAttn_GOTO);
- X
- X} /* end of pcmd_goto */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_gotob(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_gotob(param)
- XESD *param;
- X{
- X
- X if(!proc_level)
- X return(eNotExecutingProc);
- X if(_get_goto_label(param))
- X return(eInvalidLabel);
- X return(eProcAttn_GOTOB);
- X
- X} /* end of pcmd_gotob */
- X
- X/*+-------------------------------------------------------------------------
- X _cmd_gosub_common(param,type)
- X--------------------------------------------------------------------------*/
- Xint
- X_cmd_gosub_common(param,type)
- XESD *param;
- Xint type;
- X{
- Xint erc;
- XLCB *current_save;
- Xint index_save;
- X
- X if(_get_goto_label(param))
- X return(eInvalidLabel);
- X current_save = pcb_stack[proc_level - 1]->current;
- X index_save = current_save->text->index;
- X if(!(erc = execute_proc(pcb_stack[proc_level - 1],type)))
- X {
- X pcb_stack[proc_level - 1]->current = current_save;
- X current_save->text->index = index_save;
- X }
- X return(erc);
- X
- X} /* end of _cmd_gosub_common */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_gosub(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_gosub(param)
- XESD *param;
- X{
- X if(!proc_level)
- X return(eNotExecutingProc);
- X return(_cmd_gosub_common(param,eProcAttn_GOTO));
- X} /* end of pcmd_gosub */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_gosubb(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_gosubb(param)
- XESD *param;
- X{
- X if(!proc_level)
- X return(eNotExecutingProc);
- X return(_cmd_gosub_common(param,eProcAttn_GOTO));
- X} /* end of pcmd_gosubb */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_return(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_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 pcmd_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/gosub 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 interrupt, exit */
- X if(interrupt)
- X {
- X proc_interrupt = 1;
- X return(eCONINT);
- X }
- 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,use_goto_label) - execute a memory-resident procedure
- X--------------------------------------------------------------------------*/
- Xexecute_proc(pcb,use_goto_label)
- XPCB *pcb;
- Xint use_goto_label;
- X{
- Xint erc = 0;
- X
- X if(proc_level == PROC_STACK_MAX)
- X return(eProcStackTooDeep);
- X
- X pcb_stack[proc_level++] = pcb;
- X if(use_goto_label)
- X {
- X if(erc = execute_goto(pcb,use_goto_label))
- X return(erc);
- X }
- X else
- X pcb->current = pcb->first;
- X
- 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) - read in a disk-based procedure and execute it
- 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 colors_current;
- Xulong colors_at_entry = colors_current;
- 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 if(!fp)
- X {
- X pperror(procpath);
- X erc = eFATAL_ALREADY;
- X goto RETURN;
- X }
- X if(proctrace)
- X pprintf("DO: %s\n",procpath);
- X
- X if(!(pcb = (PCB *)malloc(sizeof(PCB))))
- 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))))
- 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,0);
- 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 pcmd_do(param)
- X--------------------------------------------------------------------------*/
- Xpcmd_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 = (char *)malloc(param->cb)))
- 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],1))
- 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 pcmd_do */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of proc.c */
- SHAR_EOF
- $TOUCH -am 1224224390 'proc.c' &&
- chmod 0644 proc.c ||
- echo 'restore of proc.c failed'
- Wc_c="`wc -c < 'proc.c'`"
- test 16834 -eq "$Wc_c" ||
- echo 'proc.c: original size 16834, current size' "$Wc_c"
- # ============= proc_error.c ==============
- echo 'x - extracting proc_error.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'proc_error.c' &&
- X/* CHK=0xF047 */
- X/*+-------------------------------------------------------------------------
- X proc_error.c - print ecu procedure error
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:09-19-1990-23:00-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--------------------------------------------------------------------------*/
- Xvoid
- 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 switch(es) 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("bad 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 eInvalidLogicOp:
- X pputs("invalid logical operator\n");
- X break;
- X case eExpectRespondFail:
- X pputs("expect-respond failed\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
- $TOUCH -am 1224224390 'proc_error.c' &&
- chmod 0644 proc_error.c ||
- echo 'restore of proc_error.c failed'
- Wc_c="`wc -c < 'proc_error.c'`"
- test 4423 -eq "$Wc_c" ||
- echo 'proc_error.c: original size 4423, current size' "$Wc_c"
- # ============= procframe.c ==============
- echo 'x - extracting procframe.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'procframe.c' &&
- X/*+-------------------------------------------------------------------------
- X procframe.c - execute frame of procedure statements
- X wht@n4hgf.Mt-Park.GA.US
- X
- X Defined functions:
- X pcmd_break(param);
- X pcmd_continue(param);
- X execute_frame(truth)
- 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 "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 pcmd_break(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_break(param)
- XESD *param;
- X{
- X return(eBreakCommand);
- X} /* end of pcmd_break */
- X
- X/*+-------------------------------------------------------------------------
- X pcmd_continue(param)
- X--------------------------------------------------------------------------*/
- Xint
- Xpcmd_continue(param)
- XESD *param;
- X{
- X return(eContinueCommand);
- X} /* end of pcmd_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
- $TOUCH -am 1224224390 'procframe.c' &&
- chmod 0644 procframe.c ||
- echo 'restore of procframe.c failed'
- Wc_c="`wc -c < 'procframe.c'`"
- test 3397 -eq "$Wc_c" ||
- echo 'procframe.c: original size 3397, current size' "$Wc_c"
- true || echo 'restore of regexp.c failed'
- echo End of part 14, continue with part 15
- 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.
-