ecu - SCO XENIX V/{2,3}86 Extended CU part 16/47
Warren Tucker
wht at tridom.uucp
Tue Oct 10 09:29:41 AEST 1989
---- Cut Here and unpack ----
#!/bin/sh
# this is part 16 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file hdbintf.c continued
#
CurArch=16
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 hdbintf.c"
sed 's/^X//' << 'SHAR_EOF' >> hdbintf.c
X--------------------------------------------------------------------------*/
Xint
Xhdb_dial(presult)
Xchar **presult;
X{
Xint itmp;
Xint dial_pid;
Xint wait_status;
Xint old_ttymode = get_ttymode();
Xint (*original_sighdlr)();
Xstruct dvent *dve;
Xchar baudstr[10];
Xchar dial_log[100];
Xchar stripped_num[64];
Xchar *sptr;
Xchar *dptr;
Xstatic char stat_s20[20];
Xulong colors_at_entry = current_colors;
Xextern char *make_char_graphic();
X
X if(!there_is_hdb_on_this_machine)
X return(4);
X
X dve = getdvline(Lline + 8);
X enddvent();
X if(!dve)
X {
X pputs("no Devices entry for line ... using ecu dialer\n");
X return(4);
X }
X
X if(access(dve->dialprog,1))
X {
X sprintf(dial_log,"UUCPDIAL %s: %s",dve->dialprog,sys_errlist[errno]);
X#if defined(LOG_HDBDIAL)
X ecu_log_event(dial_log);
X#endif
X pputs(dial_log + 9);
X pputs("\ntrying ecu dialer\n");
X return(2);
X }
X
X sptr = Ltelno;
X dptr = stripped_num;
X while(*sptr)
X {
X if(strchr("()-",*sptr))
X {
X sptr++;
X continue;
X }
X *dptr++ = *sptr++;
X }
X *dptr = 0;
X
X sprintf(baudstr,"%u",Lbaud);
X if((dial_pid = fork()) == 0)
X {
X signal(SIGINT,SIG_DFL);
X execl(dve->dialprog,"dial",Lline,stripped_num,baudstr,(char *)0);
X exit(-1);
X }
X
X pprintf("Type %s to abort ... ",
X (kbdintr == 0x7F) ? "DEL" : make_char_graphic(kbdintr,0));
X ttymode(2);
X original_sighdlr = signal(SIGCLD,SIG_DFL);
X wait_status = (RC_FAIL | RCE_SIG) << 8;
X while(((itmp = wait(&wait_status)) != dial_pid) &&
X (itmp != -1))
X ;
X signal(SIGCLD,original_sighdlr);
X ttymode(old_ttymode);
X ttyflush(1);
X lreset_ksr(); /* uucp dialers are nice guys, but lets use our termio */
X
X if(interrupt)
X {
X kill(dial_pid,9);
X lputc(0);
X interrupt = 0; /* in case of SIGINT by user */
X }
X
X#if defined(LOG_HDBDIAL)
X sprintf(dial_log,"UUCPDIAL %s %s 0x%04x (%d=%d)",
X dve->dialprog,stripped_num,wait_status,itmp,dial_pid);
X#endif
X
X if(wait_status & 0xFF) /* if system reports interrupt, ... */
X wait_status = (RC_FAIL | RCE_SIG) << 8; /* fake dial-reported status */
X
X if(!wait_status)
X {
X sprintf(stat_s20,"CONNECT %u",Lbaud);
X *presult = stat_s20; /* hayes_dial will report result code */
X return(0);
X }
X
X if((wait_status & 0xFF00) == 0xFF00)
X {
X pputs("uucp dial failure (see ~/.ecu/log) ... trying ecu dialer\n");
X return(2);
X }
X *presult = hdb_dial_error_text((wait_status >> 8) & 0xFF);
X setcolor(0x07000400L); /* red */
X pputs(*presult);
X setcolor(colors_at_entry);
X pputc('\n');
X ltoggle_dtr();
X return((int)iv[0]); /* set by hdb_dial_error_text() */
X} /* end of hdb_dial */
X
X/*+-------------------------------------------------------------------------
X hdb_init()
X--------------------------------------------------------------------------*/
Xvoid
Xhdb_init()
X{
X there_is_hdb_on_this_machine = !access(Devices_file,4);
X
X} /* end of hdb_init */
X
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of hdbintf.c */
SHAR_EOF
echo "File hdbintf.c is complete"
chmod 0644 hdbintf.c || echo "restore of hdbintf.c fails"
echo "x - extracting logevent.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > logevent.c &&
X/* CHK=0x95DF */
X/*+-------------------------------------------------------------------------
X logevent.c - log ecu event
X Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-27-1989-15:32-wht-break out of ecuutil.c */
X
X#include <stdio.h>
X#include <sys/locking.h>
X#include "stdio_lint.h"
X#include "lint_args.h"
X
X/*+-------------------------------------------------------------------------
X ecu_log_event(event_note)
X--------------------------------------------------------------------------*/
Xvoid
Xecu_log_event(event_note)
Xchar *event_note;
X{
Xchar tstr256[256];
XFILE *ecu_log_fp;
Xstatic char logname[128] = "";
X
X if(!logname[0])
X {
X get_home_dir(tstr256);
X strcat(tstr256,"/.ecu/log");
X }
X if((ecu_log_fp = fopen(tstr256,"a")) != NULL)
X {
X locking(fileno(ecu_log_fp),LK_LOCK,0L);
X get_tod(2,tstr256);
X tstr256[10] = '-';
X fputs(tstr256,ecu_log_fp);
X fprintf(ecu_log_fp,"-%05d-",getpid());
X fputs(event_note,ecu_log_fp);
X fputs("\n",ecu_log_fp);
X fflush(ecu_log_fp);
X locking(fileno(ecu_log_fp),LK_UNLCK,0L);
X fclose(ecu_log_fp);
X }
X} /* end of ecu_log_event */
X
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of logevent.c */
SHAR_EOF
chmod 0644 logevent.c || echo "restore of logevent.c fails"
echo "x - extracting pcmd.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > pcmd.c &&
X/* CHK=0x77F9 */
X/*+-------------------------------------------------------------------------
X pcmd.c - ecu procedure commands
X Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X
X Defined functions:
X cmd_baud(param)
X cmd_cd(param)
X cmd_clrx(param)
X cmd_dial(param)
X cmd_duplex(param)
X cmd_echo(param)
X cmd_exit(param)
X cmd_flush(param)
X cmd_hangup(param)
X cmd_hexdump(param)
X cmd_lbreak(param)
X cmd_lgets(param)
X cmd_logevent(param)
X cmd_lookfor(param)
X cmd_nap(param)
X cmd_parity(param)
X cmd_prompt(param)
X cmd_ptrace(param)
X cmd_send(param)
X cmd_set(param)
X cmd_system(param)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-27-1989-15:33-wht-was not freeing delimiter esd in cmd_lgets */
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 "ecuhangup.h"
X#include "ecukey.h"
X#include "esd.h"
X#include "var.h"
X#include "proc.h"
X
Xchar *strchr();
X
Xextern int proctrace;
Xextern int rcvr_pid;
Xextern ulong current_colors;
X
X/*+-------------------------------------------------------------------------
X cmd_baud(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_baud(param)
XESD *param;
X{
Xlong new_baud;
Xint erc;
X
X if(Liofd < 0)
X return(eNoLineAttached);
X
X if(erc = gint(param,&new_baud))
X return(erc);
X if(!valid_baud_rate((uint)new_baud))
X {
X pprintf("invalid baud rate: %lu\n",new_baud);
X return(eFATAL_ALREADY);
X }
X Lbaud = (uint)new_baud;
X lset_baud_rate(1);
X if(proctrace)
X {
X pprintf("baud rate set to %u\n",Lbaud);
X }
X return(0);
X
X} /* end of cmd_baud */
X
X/*+-------------------------------------------------------------------------
X cmd_cd(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_cd(param)
XESD *param;
X{
Xint erc;
XESD *tesd = make_esd(256);
Xextern char curr_dir[]; /* current working directory */
X
X if(!tesd)
X return(eNoMemory);
X if(erc = gstr(param,tesd))
X goto RETURN;
X if(expand_dirname(tesd->pb,tesd->maxcb))
X {
X param->index = param->old_index;
X erc = eFATAL_ALREADY;
X goto RETURN;
X }
X if(chdir(tesd->pb) < 0) /* now change to the new directory */
X {
X pperror(tesd->pb); /* print error if we get one */
X pputs("\n");
X erc = eFATAL_ALREADY;
X goto RETURN;
X }
X get_curr_dir(curr_dir,256);
X
XRETURN:
X free_esd(tesd);
X return(erc);
X} /* end of cmd_cd */
X
X/*+-------------------------------------------------------------------------
X cmd_clrx(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_clrx(param)
XESD *param;
X{
Xint erc;
X
X if(Liofd < 0)
X return(eNoLineAttached);
X
X lclear_xmtr_xoff();
X if(proctrace)
X pputs("transmitter XOFF cleared\n");
X return(0);
X} /* end of cmd_clrx */
X
X/*+-------------------------------------------------------------------------
X cmd_dial(param)
X
X hayes_dial does the following:
X sets I0 to 0==connect,
X 1==failed to connect,
X 2==interrupted,
X 3==modem error
X sets S0 to modem result code
X--------------------------------------------------------------------------*/
Xint
Xcmd_dial(param)
XESD *param;
X{
Xint erc;
XESD *tesd = (ESD *)0;
X
X if(Lmodem_off_hook)
X {
X pputs("Already off hook\n");
X return(eFATAL_ALREADY);
X }
X if(!(tesd = make_esd(64)))
X return(eNoMemory);
X if(erc = gstr(param,tesd))
X {
X free_esd(tesd);
X return(erc);
X }
X strcpy(Llogical,tesd->pb);
X lclear_xmtr_xoff();
X if(lookup_logical_telno())
X (void)hayes_dial();
X else
X {
X pprintf("No such entry: %s\n",tesd->pb);
X erc = eFATAL_ALREADY;
X }
X
X if(!erc && (Liofd < 0))
X erc = eNoLineAttached;
X
X free_esd(tesd);
X
X return(erc);
X} /* end of cmd_dial */
X
X/*+-------------------------------------------------------------------------
X cmd_duplex(param)
Xduplex [f | h]
Xduplex ['f' | 'h']
Xduplex <int> 0 == half, non-0 == full
X--------------------------------------------------------------------------*/
Xint
Xcmd_duplex(param)
XESD *param;
X{
Xint erc;
Xint new_duplex;
XESD *tesd;
X
X if(erc = skip_cmd_break(param))
X return(erc);
X if(!(tesd = make_esd(64)))
X return(eNoMemory);
X erc = gstr(param,tesd);
X new_duplex = to_upper((erc) ? param->pb[param->index] : *tesd->pb);
X free_esd(tesd);
X
X switch(new_duplex)
X {
X case 'f':
X Lfull_duplex = 1;
X break;
X case 'h':
X Lfull_duplex = 0;
X break;
X default:
X erc = eBadParameter;
X }
X if(proctrace && !erc)
X pprintf("duplex set to %s\n",(Lfull_duplex) ? "full" : "half");
X return(erc);
X
X} /* end of cmd_duplex */
X
X/*+-------------------------------------------------------------------------
X cmd_echo(param)
Xecho [-n] <str>
X--------------------------------------------------------------------------*/
Xint
Xcmd_echo(param)
XESD *param;
X{
Xint erc;
XESD *tesd;
Xchar switches[8];
X
X if((tesd = make_esd(256)) == (ESD *)0)
X return(eNoMemory);
X
X get_switches(param,switches,sizeof(switches));
X
X if(erc = gstr(param,tesd))
X {
X free_esd(tesd);
X return(erc);
X }
X pputs(tesd->pb);
X if(!strchr(switches,'n')) /* if no -n */
X pputs("\n");
X free_esd(tesd);
X return(0);
X
X} /* end of cmd_echo */
X
X/*+-------------------------------------------------------------------------
X cmd_exit(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_exit(param)
XESD *param;
X{
Xlong int1;
Xulong colors_at_entry = current_colors;
X
X if(!gint(param,&int1) && int1)
X {
X setcolor(0x00070400L); /* red */
X pprintf("[procedure exiting ecu: user code %ld]\n",int1);
X setcolor(colors_at_entry);
X hangup(HANGUP_INIT_PROC_ERROR+(int)(int1 & 0x1F));
X }
X setcolor(0x00070800L); /* gray */
X pputs("[procedure exiting ecu: normal exit]\n");
X setcolor(colors_at_entry);
X hangup(0);
X} /* end of cmd_exit */
X
X/*+-------------------------------------------------------------------------
X cmd_lgets(param)
X
Xlgets [-er] <strvar> <int1> <int2> [<str>]
X
Xread string into string variable number <stvar>
Xwaiting <int1> 1/10th secs for first char,
Xwaiting <int2> 1/10th secs for subsequent chars,
Xoptionally terminating read upon detection of <str>
X-e echos to screen
X-r completely raw, else strip CRs & NLs from either end of string
X$i0 receives the length of the read
X<strvar> receives the string
X--------------------------------------------------------------------------*/
Xint
Xcmd_lgets(param)
XESD *param;
X{
Xint erc;
Xlong int2;
Xlong int3;
XESD *tesd1 = (ESD *)0;
XESD *svptr;
XLRWT lr;
Xchar switches[8];
XESD *make_esd();
Xchar ctmp;
X
X if(Liofd < 0)
X return(eNoLineAttached);
X
X get_switches(param,switches,sizeof(switches));
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
X if(erc = gint(param,&int2))
X return(erc);
X
X if(erc = gint(param,&int3))
X return(erc);
X
X if((tesd1 = make_esd(64)) == (ESD *)0)
X return(eNoMemory);
X if(gstr(param,tesd1)) /* optional delimiter */
X {
X free_esd(tesd1);
X tesd1 = (ESD *)0;
X }
X
X zero_esd(svptr);
X
X lr.to1 = int2 * 100L;
X lr.to2 = int3 * 100L;
X /* allow interrupts + raw read per -r */
X lr.raw_flag = (strchr(switches,'r')) ? 0x81 : 0x80;
X lr.buffer = svptr->pb;
X lr.bufsize = svptr->maxcb;
X lr.delim = (tesd1) ? tesd1->pb : (char *)0;
X lr.echo = (strchr(switches,'e') != (char *)0);
X (void)lgets_timeout(&lr);
X if(tesd1)
X free_esd(tesd1);
X
X svptr->cb = lr.count;
X null_terminate_esd(svptr);
X iv[0] = (long)lr.count;
X if(proctrace)
X pprintf("lgets read %d chars\n",lr.count);
X return(0);
X
X} /* end of cmd_lgets */
X
X/*+-------------------------------------------------------------------------
X cmd_flush(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_flush(param)
XESD *param;
X{
X if(Liofd < 0)
X return(eNoLineAttached);
X
X lflush(2);
X if(proctrace)
X pputs("line flushed\n");
X return(0);
X} /* end of cmd_flush */
X
X/*+-------------------------------------------------------------------------
X cmd_hangup(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_hangup(param)
XESD *param;
X{
X if(Liofd < 0)
X return(eNoLineAttached);
X
X if(proctrace)
X pputs("hanging up ... ");
X hayes_ATH();
X if(proctrace)
X pputs("line on hook\n");
X return(0);
X} /* end of cmd_hangup */
X
X/*+-------------------------------------------------------------------------
X cmd_hexdump(param)
X
Xhexdump [-s] <str>
Xhexdump -t[s] <str1> <str>
X<str> buf to dump
X<str1> title (if -t)
X-s short (terse) dump
X--------------------------------------------------------------------------*/
Xint
Xcmd_hexdump(param)
XESD *param;
X{
Xint erc;
XESD *title = (ESD *)0;
XESD *buf;
Xchar switches[8];
Xextern FILE *plog_fp;
X
X if((buf = make_esd(256)) == (ESD *)0)
X return(eNoMemory);
X
X get_switches(param,switches,sizeof(switches));
X
X if(strchr(switches,'t')) /* if -t */
X {
X if((title = make_esd(256)) == (ESD *)0)
X {
X erc = eNoMemory;
X goto RETURN;
X }
X if(erc = gstr(param,title))
X goto RETURN;
X }
X
X if(erc = gstr(param,buf))
X goto RETURN;
X
X hex_dump(buf->pb,buf->cb,(title) ? title->pb : "",
X (strchr(switches,'s')) ? 1 : 0);
X
X if(plog_fp)
X hex_dump_fp(plog_fp,buf->pb,buf->cb,(title) ? title->pb : "",
X (strchr(switches,'s')) ? 1 : 0);
X
XRETURN:
X free_esd(buf);
X if(title)
X free_esd(title);
X return(erc);
X
X} /* end of cmd_hexdump */
X
X/*+-------------------------------------------------------------------------
X cmd_lbreak(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_lbreak(param)
XESD *param;
X{
X if(Liofd < 0)
X return(eNoLineAttached);
X
X lbreak();
X return(0);
X} /* end of cmd_lbreak */
X
X/*+-------------------------------------------------------------------------
X cmd_logevent(param)
X
Xlogevent 'cmd'
X--------------------------------------------------------------------------*/
Xint
Xcmd_logevent(param)
XESD *param;
X{
Xint erc;
XESD *eventstr;
Xchar *cptr;
Xextern int last_child_wait_status;
Xchar switches[8];
X
X if((eventstr = make_esd(256)) == (ESD *)0)
X return(eNoMemory);
X
X get_switches(param,switches,sizeof(switches));
X
X/* a hack */
X strcpy(eventstr->pb,"PROC ");
X eventstr->pb += 5;
X eventstr->maxcb -= 5;
X
X if(erc = gstr(param,eventstr))
X {
X eventstr->pb -= 5; /* be nice */
X eventstr->maxcb += 5; /* or surely this will haunt us one day */
X free_esd(eventstr);
X return(erc);
X }
X
X/* rehack */
X eventstr->pb -= 5;
X eventstr->maxcb += 5;
X eventstr->cb += 5;
X
X ecu_log_event(eventstr->pb);
X free_esd(eventstr);
X return(0);
X
X} /* end of eventstr_logevent */
X
X/*+-------------------------------------------------------------------------
X cmd_lookfor(param)
X
Xlookfor [-e] [quiet | <str>] [<int>]
X
X-e echo to screen while looking
Xquiet means look for quiet
X<str> means look for string
X<int> number 1/10ths secs (default 5.0 second) for timeout
X
Xin case of lookfor <str>, $i0 plugged 1 if found, else 0
X--------------------------------------------------------------------------*/
Xint
Xcmd_lookfor(param)
XESD *param;
X{
Xint erc;
Xchar switches[8];
Xchar *cptr = (char *)0;
XESD *tesd = (ESD *)0;
Xulong decisecs = 50; /* default wait is 5 seconds */
Xint echo_flag;
Xchar quiet[8];
Xlong start_secs;
Xlong time();
X
X if(Liofd < 0)
X return(eNoLineAttached);
X
X get_switches(param,switches,sizeof(switches));
X echo_flag = (strchr(switches,'e') != (char *)0);
X
X if(!get_alpha_zstr(param,quiet,sizeof(quiet)))
X {
X if(strcmp(quiet,"quiet"))
X return(eSyntaxError);
X }
X else
X {
X if((tesd = make_esd(64)) == (ESD *)0)
X return(eNoMemory);
X if(erc = gstr(param,tesd))
X goto RETURN;
X if(!tesd->cb)
X {
X pputs("lookfor null string\n");
X erc = eFATAL_ALREADY;
X goto RETURN;
X }
X cptr = tesd->pb;
X }
X
X if(erc = gint(param,&decisecs))
X {
X /* if something there non-integer */
X if(!end_of_cmd(param))
X {
X erc = eSyntaxError;
X goto RETURN;
X }
X }
X erc = 0;
X
X if(proctrace)
X time(&start_secs);
X
X if(cptr)
X {
X iv[0] = (long)llookfor(cptr,decisecs * 100L,echo_flag);
X if(proctrace)
X pprintf("llookfor set $i00 = %ld\n",iv[0]);
X }
X else
X lquiet(decisecs * 100L,echo_flag);
X
X if(proctrace)
X pprintf("waited %ld secs\n",time((long *)0) - start_secs);
X
XRETURN:
X if(tesd)
X free_esd(tesd);
X return(erc);
X
X} /* end of cmd_lookfor */
X
X/*+-------------------------------------------------------------------------
X cmd_nap(param)
Xnap <int>
X<int> number 1/10ths secs
X--------------------------------------------------------------------------*/
Xint
Xcmd_nap(param)
XESD *param;
X{
Xint erc;
Xulong decisecs;
X
X if(erc = gint(param,&decisecs))
X return(erc);
X if(decisecs)
X nap(decisecs * 100L);
X return(0);
X} /* end of cmd_nap */
X
X/*+-------------------------------------------------------------------------
X cmd_parity(param)
Xparity [e | o | n]
Xparity ['e' | 'o' | 'n']
X--------------------------------------------------------------------------*/
Xint
Xcmd_parity(param)
XESD *param;
X{
Xint erc;
Xint new_parity = 0;
XESD *tesd;
X
X if(Liofd < 0)
X return(eNoLineAttached);
X
X if(erc = skip_cmd_break(param))
X return(erc);
X if(!(tesd = make_esd(64)))
X return(eNoMemory);
X erc = gstr(param,tesd);
X new_parity = to_lower((erc) ? param->pb[param->index] : *tesd->pb);
X if(!erc && !tesd->cb)
X new_parity = 0;
X free_esd(tesd);
X
X switch(new_parity)
X {
X case 'n':
X new_parity = 0;
X case 'e':
X case 'o':
X Lparity = new_parity;
X lset_parity(1);
X break;
X default:
X erc = eBadParameter;
X }
X if(proctrace && !erc)
X pprintf("parity set to %s\n",
X (Lparity) ? ((Lparity == 'e') ? "even" : "odd") : "none");
X return(erc);
X
X} /* end of cmd_parity */
X
X/*+-------------------------------------------------------------------------
X cmd_prompt(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_prompt(param)
XESD *param;
X{
Xextern ESD *icmd_prompt;
X
X return(gstr(param,icmd_prompt));
X} /* end of cmd_prompt */
X
X/*+-------------------------------------------------------------------------
X cmd_ptrace(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_ptrace(param)
XESD *param;
X{
Xchar s8[8];
Xregister itmp;
X
X if(get_alpha_zstr(param,s8,sizeof(s8)))
X return(eSyntaxError);
X itmp = strlen(s8);
X while(itmp--)
X s8[itmp] = to_lower(s8[itmp]);
X if(!strcmp(s8,"on"))
X proctrace = 1;
X else if(!strcmp(s8,"off"))
X proctrace = 0;
X else
X return(eSyntaxError);
X return(0);
X} /* end of cmd_ptrace */
X
X/*+-------------------------------------------------------------------------
X cmd_send(param)
Xsend [-n] <str>
X-n do not send trailing CR
X--------------------------------------------------------------------------*/
Xint
Xcmd_send(param)
XESD *param;
X{
Xint erc;
XESD *buf;
Xchar switches[8];
X
X if(Liofd < 0)
X return(eNoLineAttached);
X
X if((buf = make_esd(256)) == (ESD *)0)
X return(eNoMemory);
X
X get_switches(param,switches,sizeof(switches));
X
X if(erc = gstr(param,buf))
X {
X free_esd(buf);
X return(erc);
X }
X
X lputs(buf->pb);
X
X if(!strchr(switches,'n'))
X lputc(CR);
X
X free_esd(buf);
X return(erc);
X} /* end of cmd_send */
X
X/*+-------------------------------------------------------------------------
X cmd_set(param)
X--------------------------------------------------------------------------*/
Xint
Xcmd_set(param)
XESD *param;
X{
Xint erc;
Xulong varnum;
Xuint varmax;
Xchar vartype;
Xchar varstr[16];
Xint show_status;
Xlong *ivptr;
XESD *svptr;
X
X if(erc = skip_cmd_break(param))
X return(erc);
X
X do {
X /* $ is optional */
X if((erc = skip_cmd_char(param,'$')) && (erc != eSyntaxError))
X return(erc);
X /* get variable type */
X if(get_cmd_char(param,&vartype))
X return(eSyntaxError);
X /* validate variable type */
X vartype = to_lower(vartype);
X switch(vartype)
X {
X case 'i':
X varmax = IVQUAN;
X break;
X case 's':
X varmax = SVQUAN;
X break;
X default:
X return(eIllegalVarType);
X }
X
X if(!get_numeric_value(param,&varnum))
X goto TEST_VARNUM;
X else if(*(param->pb + param->index) == '[')
X {
X if(erc = get_subscript(param,&varnum))
X return(erc);
XTEST_VARNUM:
X if((int)varnum >= varmax)
X return(eIllegalVarNumber);
X switch(vartype)
X {
X case 'i':
X ivptr = &iv[(int)varnum];
X break;
X default:
X svptr = sv[(int)varnum];
X }
X }
X else if(get_alphanum_zstr(param,varstr,sizeof(varstr)))
X return(eInvalidVarName);
X else
X {
X varnum = 0x1000L;
X switch(vartype)
X {
X case 'i':
X erc = find_mkvi(varstr,&ivptr);
X break;
X default:
X erc = find_mkvs(varstr,&svptr);
X }
X if(erc)
X return(erc);
X }
X
X show_status = 1;
X if(!skip_cmd_char(param,'=')) /* assignment */
X {
X switch(vartype)
X {
X case 'i':
X if(erc = gint(param,ivptr))
X return(erc);
X break;
X default:
X if(erc = gstr(param,svptr))
X return(erc);
X break;
X }
X if(!proctrace)
X show_status = 0;
X }
X if(show_status)
X {
X switch(vartype)
X {
X case 'i':
X if(varnum != 0x1000L)
X pprintf("$i%02ld = %7ld (0x%08lx,0%lo)\n",varnum,
X *ivptr,*ivptr,*ivptr);
X else
X pprintf("$i%s = %ld (0x%08lx,0%lo)\n",varstr,
X *ivptr,*ivptr,*ivptr);
X break;
X default:
X if(varnum != 0x1000L)
X pprintf("$s%02ld = '%s'\n",varnum,svptr->pb);
X else
X pprintf("$s%s = '%s'\n",varstr,svptr->pb);
X break;
X }
X }
X } while(!skip_comma(param));
X
X if(!end_of_cmd(param))
X return(eSyntaxError);
X
X return(0);
X} /* end of cmd_set */
X
X/*+-------------------------------------------------------------------------
X cmd_system(param)
X
Xsystem [-l] 'cmd'
X-l makes comm line stdin/stdout
X
Xreturns $i0 set to exit status of program or 0x100 if interrupted
X--------------------------------------------------------------------------*/
Xint
Xcmd_system(param)
XESD *param;
X{
Xint erc;
XESD *cmd;
Xchar *cptr;
Xextern int last_child_wait_status;
Xchar switches[8];
X
X if((cmd = make_esd(256)) == (ESD *)0)
X return(eNoMemory);
X
X get_switches(param,switches,sizeof(switches));
X
X/* a hack */
X *cmd->pb++ = (strchr(switches,'l')) ? '$' : '!';
X cmd->maxcb--;
X
X if(erc = gstr(param,cmd))
X {
X cmd->pb--; /* be nice */
X cmd->maxcb++; /* or surely this will haunt us one day */
X free_esd(cmd);
X return(erc);
X }
X
X/* rehack */
X cmd->pb--;
X cmd->cb++;
X cmd->maxcb++;
X
X if(proctrace)
X {
X pputs(cmd->pb + 1);
X pputs("\n");
X }
X
X last_child_wait_status = 0xFF00;
X shell(cmd->pb);
X iv[0] = (last_child_wait_status & 0xFF)
X ? 0x100L : (long)last_child_wait_status >> 8;
X if(proctrace)
X pprintf("$i0 = %ld, (%s)\n",iv[0],
X (iv[0] == 0x100L) ? "interrupted" : "program exit status");
X
X free_esd(cmd);
X return(0);
X} /* end of cmd_system */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of pcmd.c */
SHAR_EOF
chmod 0644 pcmd.c || echo "restore of pcmd.c fails"
echo "x - extracting pcmdfile.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > pcmdfile.c &&
X/* CHK=0xFD1E */
X/*+-------------------------------------------------------------------------
X pcmdfile.c - ecu file-related procedure commands
X Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X
X Defined functions:
X _file_not_open(filenum)
X _gfilenum(param,filenum)
X _param_to_stat(param,pstat_rtnd)
X cmd_fchmod(param)
X cmd_fclose(param)
X cmd_fdel(param)
X cmd_fgetc(param)
X cmd_fgets(param)
X cmd_fopen(param)
X cmd_fputc(param)
X cmd_fputs(param)
X cmd_fread(param)
X cmd_fseek(param)
X cmd_fwrite(param)
X cmd_mkdir(param)
X ifunc_fatime(param,pvalue)
X ifunc_fmode(param,pvalue)
X ifunc_fmtime(param,pvalue)
X ifunc_fsize(param,pvalue)
X ifunc_ftell(param,pvalue)
X ifunc_ischr(param,pvalue)
X ifunc_isdir(param,pvalue)
X ifunc_isreg(param,pvalue)
X proc_file_reset()
X str_to_filemode(modestr,filemode)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*: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 "ecukey.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include "var.h"
X#include "proc.h"
X
X#if !defined(S_IRUSR)
X#define S_IRUSR 00400 /* read permission: owner */
X#define S_IWUSR 00200 /* write permission: owner */
X#define S_IXUSR 00100 /* execute permission: owner */
X#define S_IRWXG 00070 /* read, write, execute: group */
X#define S_IRGRP 00040 /* read permission: group */
X#define S_IWGRP 00020 /* write permission: group */
X#define S_IXGRP 00010 /* execute permission: group */
X#define S_IRWXO 00007 /* read, write, execute: other */
X#define S_IROTH 00004 /* read permission: other */
X#define S_IWOTH 00002 /* write permission: other */
X#define S_IXOTH 00001 /* execute permission: other */
X#endif
X
Xextern int proctrace;
Xextern int rcvr_pid;
Xextern int errno;
Xextern proc_level;
Xextern PCB *pcb_stack[];
X
X#define FILE_MAX 5
X
Xtypedef struct pfile_struct
X{
X FILE *f; /* file pointer */
X ESD *n; /* file name */
X} PFILE;
X
XPFILE pfile[FILE_MAX];
X
Xchar fwrite_error_fmt[] = "file %d write error (not open for write?)\n";
X
X/*+-------------------------------------------------------------------------
X proc_file_reset()
X--------------------------------------------------------------------------*/
Xvoid
Xproc_file_reset()
X{
Xregister itmp;
X
X for(itmp = 0; itmp < FILE_MAX; itmp++)
X {
X if(pfile[itmp].f)
X {
X fclose(pfile[itmp].f);
X pfile[itmp].f = NULL;
X free_esd(pfile[itmp].n);
X }
X }
X} /* end of proc_file_reset */
X
X/*+-------------------------------------------------------------------------
X _file_not_open(filenum)
X--------------------------------------------------------------------------*/
Xint
X_file_not_open(filenum)
Xint filenum;
X{
X pprintf("file %d not open\n",filenum);
X return(eFATAL_ALREADY);
X} /* end of _file_not_open */
X
X/*+-------------------------------------------------------------------------
X _gfilenum(param,filenum)
X--------------------------------------------------------------------------*/
Xint
X_gfilenum(param,filenum)
XESD *param;
Xint *filenum;
X{
Xint erc;
Xulong lvarnum;
Xint old_index;
X
X skip_cmd_break(param);
X old_index = param->old_index;
X if(erc = gint(param,&lvarnum))
X return(erc);
X if(lvarnum > FILE_MAX)
X return(eBadFileNumber);
X *filenum = (int)lvarnum;
X param->old_index = old_index;
X return(0);
X} /* end of _gfilenum */
X
X/*+-------------------------------------------------------------------------
X str_to_filemode(modestr,filemode) - "rwxrwxrwx" to mode integer
X--------------------------------------------------------------------------*/
Xstr_to_filemode(modestr,filemode)
Xchar *modestr;
Xlong *filemode;
X{
Xregister i;
Xregister mode = 0;
Xint erc = 0;
X
X if(strlen(modestr) != 9)
X {
X pprintf("bad length: '%s'\n",modestr);
X return(eFATAL_ALREADY);
X }
X
X for(i=0; i < 9; i++)
X {
X switch(modestr[i])
X {
X
X case 'r':
X if(i == 0)
X mode |= S_IRUSR;
X else if(i == 3)
X mode |= S_IRGRP;
X else if(i == 6)
X mode |= S_IROTH;
X else
X erc = eSyntaxError;
X break;
X
X
X case 'w':
X if(i == 1)
X mode |= S_IWUSR;
X else if(i == 4)
X mode |= S_IWGRP;
X else if(i == 7)
X mode |= S_IWOTH;
X else
X erc = eSyntaxError;
X break;
X
X
X case 'x':
X if(i == 2)
X mode |= S_IXUSR;
X else if(i == 5)
X mode |= S_IXGRP;
X else if(i == 8)
X mode |= S_IXOTH;
X else
X erc = eSyntaxError;
X break;
X
X
X case 's':
X#if defined(FULL_FEATURE_CHMODE)
X if(i == 2)
X {
X mode |= S_ISUID;
X mode |= S_IXUSR;
X }
X else if(i == 5)
X {
X mode |= S_ISGID;
X mode |= S_IXGRP;
X }
X else
X erc = eSyntaxError;
X#else
X pputs("setuid/setgid not allowed\n");
X erc = eFATAL_ALREADY;
X#endif /* defined(FULL_FEATURE_CHMODE) */
X break;
X
X
X case 't':
X#if defined(FULL_FEATURE_CHMODE)
X if(i == 8)
X {
X mode |= S_ISVTX;
X mode |= S_IXOTH;
X }
X else
X erc = eSyntaxError;
X#else
X pputs("set sticky bit not allowed\n");
SHAR_EOF
echo "End of part 16"
echo "File pcmdfile.c is continued in part 17"
echo "17" > 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