v16i027: ECU async comm package rev 3.0, Part03/35
Warren Tucker
wht at n4hgf.uucp
Sun Jan 6 16:17:39 AEST 1991
Submitted-by: wht at n4hgf.uucp (Warren Tucker)
Posting-number: Volume 16, Issue 27
Archive-name: ecu3/part03
---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is part 03 of ecu3
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= ecufinsert.c ==============
echo 'x - extracting ecufinsert.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecufinsert.c' &&
X#define USE_XON_XOFF
X/*+-------------------------------------------------------------------------
X ecufinsert.c -- insert file onto comm line
X wht at n4hgf.Mt-Park.GA.US
X
X Defined functions:
X expand_filename(fname,maxlen)
X file_insert_clear_xoff()
X file_insert_to_line(narg,arg)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecukey.h"
X
Xextern int interrupt;
Xextern char kbdintr; /* current input INTR */
Xextern ulong colors_current;
Xextern ulong colors_alert;
Xextern ulong colors_errors;
X
X/*+-------------------------------------------------------------------------
X expand_filename(fname) - convert fnames with shell chars
X--------------------------------------------------------------------------*/
Xexpand_filename(fname,maxlen)
Xchar *fname;
Xint maxlen;
X{
Xchar s256[256];
Xchar *expcmd;
X
X if(!find_shell_chars(fname))
X return(0);
X
X sprintf(s256,"`ls %s`",fname);
X if(expand_cmd_with_wildlist(s256,&expcmd))
X {
X ff(se,"\r\nNo files match\r\n");
X return(-1);
X }
X strncpy(fname,expcmd,maxlen);
X fname[maxlen - 1] = 0;
X if(strchr(expcmd,' '))
X {
X fputs("\r\nToo many files:\r\n",se);
X fputs(expcmd,se);
X fputs("\r\n",se);
X free(expcmd);
X return(-1);
X }
X free(expcmd);
X return(0);
X
X} /* end of expand_filename */
X
X/*+-------------------------------------------------------------------------
X file_insert_clear_xoff()
X--------------------------------------------------------------------------*/
Xvoid
Xfile_insert_clear_xoff()
X{
X#ifdef USE_XON_XOFF
Xulong colors_at_entry = colors_current;
X
X lclear_xmtr_xoff();
X#ifdef SAY_CLEARED_XOFF
X setcolor(colors_alert);
X fputs("--> local XOFF cleared\r",se);
X setcolor(colors_at_entry);
X#endif
X#endif
X} /* end of file_insert_clear_xoff */
X
X/*+-------------------------------------------------------------------------
X file_insert_to_line(narg,arg)
X--------------------------------------------------------------------------*/
Xfile_insert_to_line(narg,arg)
Xint narg;
Xchar **arg;
X{
Xregister rchar;
Xint old_ttymode = get_ttymode();
Xlong total_chars = 0L;
Xlong total_lines = 0L;
Xulong colors_at_entry = colors_current;
Xlong timeout_msecs;
XFILE *fp;
Xchar file_string[512];
Xchar s512[512];
Xchar xmit_mode;
X#ifdef USE_XON_XOFF
Xint ixon;
Xint ixoff;
X#endif
Xchar *make_char_graphic();
X
X if(narg > 1)
X strncpy(s512,arg[1],sizeof(s512));
X else
X {
X ff(se,"\r\n--> File to insert on comm line: ");
X ttygets(s512,sizeof(s512),1);
X if( (s512[0] == ESC) || (strlen(s512) == 0) )
X {
X ff(se,"--> no transmission\r\n");
X return(0);
X }
X }
X if(expand_filename(s512,sizeof(s512)))
X return(-1);
X if((fp = fopen(s512,"r")) == (FILE *)0)
X {
X ff(se,"--> ");
X perror(s512); /* print error if we get one */
X ff(se,"\r\n");
X return(-1);
X }
X
X if(narg > 1)
X ff(se,"\r\n");
X
X if(narg > 2)
X xmit_mode = *arg[2];
X else
X {
XASK_OPTION:
X ff(se,"--> (S)ingle line at a time\r\n");
X ff(se," (E)cho pacing\r\n");
X ff(se," (F)ull speed transmission\r\n");
X ff(se," (P)aced transmission (20 msec/schar)\r\n");
X ff(se," (Q)uit (or ESC): ");
X xmit_mode = ttygetc(0) & 0x7F;
X if(xmit_mode > 0x20)
X fputs(make_char_graphic(xmit_mode,0),se);
X fputs("\r\n",se);
X }
X
X kill_rcvr_process(SIGUSR1);
X
X switch(xmit_mode = to_lower(xmit_mode))
X {
X case 's':
X setcolor(colors_alert);
X fputs("--> press SPACE to continue or ESC/'s' to stop\r\n",se);
X setcolor(colors_at_entry);
X break;
X
X case 'e':
X /* fall through */
X
X case 'f':
X case 'p':
X setcolor(colors_alert);
X ff(se,"--> press %s to abort\r\n",make_char_graphic(kbdintr,0));
X setcolor(colors_at_entry);
X ttymode(2);
X break;
X
X case 'q':
X case ESC:
X setcolor(colors_alert);
X ff(se,"--> file insertion aborted\r\n");
X setcolor(colors_at_entry);
X fclose(fp);
X return(0);
X
X default:
X ring_bell();
X fputs("\r\n",se);
X goto ASK_OPTION;
X }
X
X#ifdef USE_XON_XOFF
X lget_xon_xoff(&ixon,&ixoff); /* get current line xon/xoff status */
X lxon_xoff(IXON); /* set it for us */
X#endif
X
X interrupt = 0; /* reset SIGINT flag */
X while(fgets(file_string,sizeof(file_string),fp))
X {
X int xmit_len = strlen(file_string);
X int xmit_cr = xmit_len && (file_string[xmit_len - 1] == NL);
X
X if(xmit_cr)
X {
X xmit_len--;
X file_string[xmit_len] = 0;
X }
X total_chars += xmit_len;
X total_lines++;
X
X/* some destinations, like BBS msg entry, take a blank line to mean
Xend of message, so do not send completely blank lines */
X if(!xmit_len && xmit_cr)
X {
X lputc(' ');
X xmit_len = 1;
X }
X else if(xmit_mode == 'p')
X {
X register char *cptr = file_string;
X while(*cptr)
X {
X lputc(*cptr++);
X nap(20L);
X while(rdchk(shm->Liofd))
X {
X rchar = lgetc_xmtr();
X process_xmtr_rcvd_char((char)rchar,1);
X }
X }
X }
X else
X lputs(file_string);
X if(xmit_cr)
X {
X if(xmit_mode == 'p')
X nap(20L);
X lputc('\r');
X xmit_len++;
X }
X
X if(interrupt)
X break;
X
X switch(xmit_mode)
X {
X case 's':
X while(1)
X {
X if(rdchk(0))
X break;
X rchar = lgetc_timeout(5 * 1000L);
X if(rchar < 0)
X file_insert_clear_xoff();
X else
X process_xmtr_rcvd_char((char)rchar,1);
X if(rchar == 0x0A)
X break;
X }
X rchar = to_lower(ttygetc(1));
X if((rchar == 's') || (rchar == ESC))
X goto INSERT_DONE;
X break;
X
X case 'e':
X timeout_msecs = 5 * 1000L;
X while(1)
X {
X if(interrupt)
X break;
X rchar = lgetc_timeout(timeout_msecs);
X if(rchar < 0)
X {
X if(!xmit_len)
X break;
X file_insert_clear_xoff();
X timeout_msecs = 1 * 1000L;
X }
X else
X {
X process_xmtr_rcvd_char((char)rchar,1);
X timeout_msecs = 100L;
X if(xmit_len)
X xmit_len--;
X }
X if(rchar == 0x0A)
X break;
X }
X break;
X
X case 'f':
X case 'p':
X while(rdchk(shm->Liofd))
X {
X rchar = lgetc_xmtr();
X process_xmtr_rcvd_char((char)rchar,1);
X }
X break;
X }
X if(interrupt)
X break;
X }
X
XINSERT_DONE:
X
X if(interrupt)
X {
X setcolor(colors_error);
X ff(se,"--> Interrupted\r\n");
X setcolor(colors_at_entry);
X }
X
X fclose(fp);
X
X ttymode(old_ttymode); /* restore old console mode */
X
X while(((rchar = lgetc_timeout(200L)) > 0) && !interrupt)
X process_xmtr_rcvd_char((char)rchar,1);
X
X interrupt = 0; /* reset SIGINT flag */
X setcolor(colors_success);
X ff(se,"\r\n--> done ... sent %ld lines, %ld characters\r\n",
X total_lines,total_chars);
X setcolor(colors_at_entry);
X lclear_xmtr_xoff();
X#ifdef USE_XON_XOFF
X lxon_xoff(ixon | ixoff); /* restore old line xon/xoff status */
X#endif
X start_rcvr_process(1);
X return(0);
X
X} /* end of file_insert_to_line */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of ecufinsert.c */
SHAR_EOF
$TOUCH -am 1224222890 'ecufinsert.c' &&
chmod 0644 ecufinsert.c ||
echo 'restore of ecufinsert.c failed'
Wc_c="`wc -c < 'ecufinsert.c'`"
test 6693 -eq "$Wc_c" ||
echo 'ecufinsert.c: original size 6693, current size' "$Wc_c"
# ============= ecufkey.c ==============
echo 'x - extracting ecufkey.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecufkey.c' &&
X/*+-----------------------------------------------------------------
X ecufkey.c -- function key definition
X wht at n4hgf.Mt-Park.GA.US
X
X Defined functions:
X keyset_display()
X keyset_idnum(keystr)
X keyset_idstr(KDEt)
X keyset_init()
X keyset_read(keyset_name)
X xf_to_KDEt(xf)
X
X------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecukey.h"
X#include "ecufkey.h"
X#include "ecuxkey.h"
X#include "ecufork.h"
X
Xextern char kbdintr; /* current input INTR */
Xextern char curr_dir[]; /* current working key defns */
X
XKDE keyset_table[KDE_COUNT];
Xchar keyset_name[32] = "";
X
XXF_KDE_NAME xf_kde_name[] =
X{
X { XFcurup, KDEk_CUU, "CUU" },
X { XFcurdn, KDEk_CUD, "CUD" },
X { XFcurrt, KDEk_CUR, "CUR" },
X { XFcurlf, KDEk_CUL, "CUL" },
X { XFcur5, KDEk_CU5, "CU5" },
X { XFend, KDEk_END, "End" },
X { XFpgdn, KDEk_PGDN, "PgDn" },
X { XFhome, KDEk_HOME, "Home" },
X { XFpgup, KDEk_PGUP, "PgUp" },
X { XFins, KDEk_INS, "Ins" },
X { XF1, KDEk_F1, "F1" },
X { XF2, KDEk_F2, "F2" },
X { XF3, KDEk_F3, "F3" },
X { XF4, KDEk_F4, "F4" },
X { XF5, KDEk_F5, "F5" },
X { XF6, KDEk_F6, "F6" },
X { XF7, KDEk_F7, "F7" },
X { XF8, KDEk_F8, "F8" },
X { XF9, KDEk_F9, "F9" },
X { XF10, KDEk_F10, "F10" },
X { XF11, KDEk_F11, "F11" },
X { XF12, KDEk_F12, "F12" },
X { XFbktab, KDEk_BKTAB, "BkTab" },
X { 0,0,"" }
X};
X
X/*+-------------------------------------------------------------------------
X keyset_init()
X--------------------------------------------------------------------------*/
Xvoid
Xkeyset_init()
X{
Xregister itmp;
Xregister KDE *tkde;
Xchar *make_char_graphic();
X
X for(itmp = 0; itmp < KDE_COUNT; itmp++)
X {
X tkde = &keyset_table[itmp];
X tkde->logical[0] = 0;
X tkde->count = 0;
X tkde->KDEt = (uchar)itmp;
X }
X
X keyset_name[0] = 0;
X
X tkde = &keyset_table[KDEk_BKTAB];
X strcpy(tkde->logical,"redisplay");
X tkde->count = KACT_REDISPLAY;
X
X tkde = &keyset_table[KDEk_HOME];
X strcpy(tkde->logical,"ecu cmd");
X tkde->count = KACT_COMMAND;
X
X tkde = &keyset_table[KDEk_INS];
X strcpy(tkde->logical,"local shell");
X tkde->count = KACT_LOCAL_SHELL;
X
X tkde = &keyset_table[KDEk_CU5];
X strcpy(tkde->logical,"screen dump");
X tkde->str[0] = 0x7F; /* this key is intercepted by kbd read routine */
X tkde->count = 0;
X
X} /* end of keyset_init */
X
X/*+-------------------------------------------------------------------------
X kde_fgets(buf,bufsize,fp)
X--------------------------------------------------------------------------*/
Xint
Xkde_fgets(buf,bufsize,fp)
Xchar *buf;
Xint bufsize;
XFILE *fp;
X{
Xregister itmp;
Xregister char *cptr;
X
X if(!fgets(buf,bufsize,fp))
X {
X return(KDEt_EOF);
X }
X
X if(!(itmp = strlen(buf)))
X return(KDEt_COMMENT);
X if(buf[itmp - 1] == '\n')
X {
X buf[itmp - 1] = 0;
X itmp--;
X }
X if(!itmp)
X return(KDEt_COMMENT);
X
X cptr = buf;
X itmp = (strchr(" \t",*cptr)) ? KDEt_ENTRY : KDEt_NAME;
X while(*cptr && ((*cptr == SPACE) || (*cptr == TAB)))
X cptr++;
X
X if(!*cptr || (*cptr == '#'))
X return(KDEt_COMMENT);
X
X return(itmp);
X
X} /* end of kde_fgets */
X
X/*+-------------------------------------------------------------------------
X keyset_idnum(keystr)
X--------------------------------------------------------------------------*/
Xint
Xkeyset_idnum(keystr)
Xchar *keystr;
X{
Xstruct XF_KDE_NAME *xkn = xf_kde_name;
X while(xkn->xf != 0)
X {
X if(!strcmpi(xkn->name,keystr))
X return((int)xkn->kde);
X xkn++;
X }
X return(-1);
X} /* end of keyset_idnum */
X
X/*+-------------------------------------------------------------------------
X keyset_idstr(KDEt)
X--------------------------------------------------------------------------*/
Xchar *
Xkeyset_idstr(KDEt)
Xint KDEt;
X{
Xstruct XF_KDE_NAME *xkn = xf_kde_name;
X
X while(xkn->xf)
X {
X if((int)xkn->kde == KDEt)
X return(xkn->name);
X xkn++;
X }
X return((char *)0);
X} /* end of keyset_idstr */
X
X/*+-------------------------------------------------------------------------
X xf_to_KDEt(xf)
X--------------------------------------------------------------------------*/
Xint
Xxf_to_KDEt(xf)
Xuchar xf;
X{
Xstruct XF_KDE_NAME *xkn = xf_kde_name;
X
X while(xkn->xf)
X {
X if(xkn->xf == xf)
X return((int)xkn->kde & 0xFF);
X xkn++;
X }
X return(-1);
X} /* end of xf_to_KDEt */
X
X/*+-------------------------------------------------------------------------
X keyset_define_key(bufptr)
X--------------------------------------------------------------------------*/
Xint
Xkeyset_define_key(bufptr)
Xchar *bufptr;
X{
Xregister itmp;
Xregister token_number;
Xregister KDE *tkde;
Xint KDEt;
Xchar token_separator[2];
Xchar *token;
Xchar *str_token();
X
X if(itmp = strlen(bufptr)) /* itmp = len; if > 0 ... */
X bufptr[--itmp] = 0; /* ... strip trailing NL */
X if(!itmp)
X return(0);
X
X if(bufptr[0] == '#') /* comment? */
X return(0);
X if((*bufptr != 0x20) && (*bufptr != TAB)) /* if no leading space */
X return(1);
X if(*bufptr == 0) /* if line all blank, break */
X return(1);
X
X while((*bufptr == 0x20) || (*bufptr == TAB)) /* strip lding sp/tab */
X bufptr++;
X
X token_number = 0;
X strcpy(token_separator,":");
X while(token = str_token(bufptr,token_separator))
X {
X bufptr = (char *)0; /* further calls to str_token need NULL */
X switch(token_number)
X {
X case 0: /* first field is key identifier */
X if((KDEt = keyset_idnum(token)) < 0)
X {
X ff(se," %s is not a legal key identifier\r\n",token);
X return(0);
X }
X if(KDEt == KDEk_HOME)
X {
X ff(se," HOME cannot be redefined!\r\n");
X return(0);
X }
X if(KDEt == KDEk_CU5)
X {
X ff(se," CUR5 cannot be redefined!\r\n");
X return(0);
X }
X if(KDEt == KDEk_BKTAB)
X {
X ff(se," BkTab cannot be redefined!\r\n");
X return(0);
X }
X tkde = &keyset_table[KDEt];
X tkde->logical[0] = 0;
X tkde->count = 0;
X break;
X
X case 1: /* second field is logical key name */
X strncpy(tkde->logical,token,sizeof(tkde->logical));
X tkde->logical[sizeof(tkde->logical) - 1] = 0;
X strcpy(token_separator," \t"); /* whitespace is tok sep now */
X break;
X
X default: /* third and subsequent to define key */
X if(!strlen(token))
X continue;
X if(tkde->count == sizeof(tkde->str))
X {
X ff(se," %s: output count too long",
X keyset_idstr(KDEt));
X return(0);
X }
X if((itmp = ascii_to_hex(token)) < 0)
X {
X ff(se," %s: '%s' invalid\r\n",
X keyset_idstr(KDEt),token);
X return(0);
X }
X tkde->str[tkde->count] = itmp;
X tkde->count++;
X break;
X } /* end of switch(token_number) */
X token_number++;
X } /* end while not end of record */
X
X return(0);
X} /* end of keyset_define_key */
X
X/*+-------------------------------------------------------------------------
X keyset_read(name)
Xreturns 0 on success, -1 if no .ecu/keys, -2 if no 'name'
X--------------------------------------------------------------------------*/
Xint
Xkeyset_read(name)
Xchar *name;
X{
Xregister itmp;
Xregister char *cptr;
Xstatic char ecukeys_name[128];
Xchar readkde_buf[128];
XFILE *fp_keys;
X
X if(!ecukeys_name[0])
X {
X get_home_dir(ecukeys_name);
X strcat(ecukeys_name,"/.ecu/keys");
X }
X
X if((fp_keys = fopen(ecukeys_name,"r")) == NULL)
X return(-1);
X
X/* find keyset name */
X while(fgets(readkde_buf,sizeof(readkde_buf),fp_keys) != NULL)
X {
X if(readkde_buf[0] == '#') /* comment? */
X continue;
X if(itmp = strlen(readkde_buf)) /* itmp = len; if > 0 ... */
X readkde_buf[--itmp] = 0; /* ... strip trailing NL */
X if(!itmp)
X continue;
X if(strcmp(readkde_buf,name) == 0)
X {
X itmp = 1; /* indicate success */
X break;
X }
X itmp = 0; /* if loop terminates w/o find, failure */
X }
X if(!itmp)
X {
X fclose(fp_keys);
X return(-2);
X }
X
X keyset_init(); /* clear any previous key defns */
X
X/* read past any other keyset names matching this set */
X while(fgets(readkde_buf,sizeof(readkde_buf),fp_keys) != NULL)
X {
X cptr = readkde_buf; /* first call to str_token, -> buff */
X if((*cptr == 0x20) || (*cptr == TAB)) /* if leading space */
X {
X (void)keyset_define_key(cptr);
X break;
X }
X }
X
X/* we found the definition ... read it */
X while(fgets(readkde_buf,sizeof(readkde_buf),fp_keys) != NULL)
X {
X if(keyset_define_key(readkde_buf))
X break;
X }
X
X strncpy(keyset_name,name,sizeof(keyset_name));
X keyset_name[sizeof(keyset_name) - 1] = 0;
X fclose(fp_keys);
X return(0);
X} /* end of keyset_read */
X
X/*+-------------------------------------------------------------------------
X ffso(str)
X--------------------------------------------------------------------------*/
Xvoid
Xffso(str)
Xchar *str;
X{
X tcap_stand_out();
X fputs(str,se);
X tcap_stand_end();
X} /* end of ffso */
X
X/*+-------------------------------------------------------------------------
X keyset_display()
X
X F1 xxxxx F2 xxxxx HOME xxxxx PGUP xxxxx
X F3 xxxxx F4 xxxxx END xxxxx PGDN xxxxx
X F5 xxxxx F6 xxxxx INS xxxxx CUR5 xxxxx
X F7 xxxxx F8 xxxxx BkTab xxxxx
X F9 xxxxx F10 xxxxx CUR^ xxxxx CUR> xxxxx
X F11 xxxxx F12 xxxxx CUR< xxxxx CURv xxxxx
X--------------------------------------------------------------------------*/
Xvoid
Xkeyset_display()
X{
Xregister itmp;
Xregister itmp2;
Xint clen1 = 0;
Xchar cfmt1[32];
Xint clen2 = 0;
Xchar cfmt2[32];
Xint clen3 = 0;
Xchar cfmt3[32];
Xchar cfmt4[8];
X
X if(!keyset_name[0])
X {
X keyset_init();
X ff(se," no key definition active\r\n\r\n");
X ff(se,"HOME - command prefix\r\n");
X ff(se,"BkTab - redisplay receiver screen\r\n");
X ff(se,"cursor down - local shell in %s\r\n",curr_dir);
X fputs("\r\n",se);
X }
X else
X {
X for(itmp = 0; itmp < KDE_COUNT; itmp++)
X {
X register KDE *tkde = &keyset_table[itmp];
X itmp2 = strlen(tkde->logical);
X switch(itmp)
X {
X case KDEk_F1: case KDEk_F3: case KDEk_F5: case KDEk_F7:
X case KDEk_F9: case KDEk_F11:
X if(clen1 < itmp2)
X clen1 = itmp2;
X break;
X
X case KDEk_F2: case KDEk_F4: case KDEk_F6: case KDEk_F8:
X case KDEk_F10: case KDEk_F12:
X if(clen2 < itmp2)
X clen2 = itmp2;
X break;
X
X case KDEk_HOME: case KDEk_END: case KDEk_INS:
X case KDEk_CUU: case KDEk_CUL:
X if(clen3 < itmp2)
X clen3 = itmp2;
X break;
X }
X }
X sprintf(cfmt1," %%-%d.%ds",clen1,clen1);
X sprintf(cfmt2," %%-%d.%ds",clen2,clen2);
X sprintf(cfmt3," %%-%d.%ds",clen3,clen3);
X strcpy(cfmt4," %s");
X ff(se," key definition: %s\r\n\r\n",keyset_name);
X
X ffso(" F1 ");ff(se,cfmt1,keyset_table[KDEk_F1].logical);
X fputs(" ",se);
X ffso(" F2 ");ff(se,cfmt2,keyset_table[KDEk_F2].logical);
X fputs(" ",se);
X ffso(" Home ");ff(se,cfmt3,keyset_table[KDEk_HOME].logical);
X fputs(" ",se);
X ffso(" PgUp ");ff(se,cfmt4,keyset_table[KDEk_PGUP].logical);
X fputs("\r\n",se);
X
X ffso(" F3 ");ff(se,cfmt1,keyset_table[KDEk_F3].logical);
X fputs(" ",se);
X ffso(" F4 ");ff(se,cfmt2,keyset_table[KDEk_F4].logical);
X fputs(" ",se);
X ffso(" End ");ff(se,cfmt3,keyset_table[KDEk_END].logical);
X fputs(" ",se);
X ffso(" PgDn ");ff(se,cfmt4,keyset_table[KDEk_PGDN].logical);
X fputs("\r\n",se);
X
X ffso(" F5 ");ff(se,cfmt1,keyset_table[KDEk_F5].logical);
X fputs(" ",se);
X ffso(" F6 ");ff(se,cfmt2,keyset_table[KDEk_F6].logical);
X fputs(" ",se);
X ffso(" Ins ");ff(se,cfmt3,keyset_table[KDEk_INS].logical);
X fputs(" ",se);
X ffso(" CUR5 ");ff(se,cfmt4,keyset_table[KDEk_CU5].logical);
X fputs("\r\n",se);
X
X ffso(" F7 ");ff(se,cfmt1,keyset_table[KDEk_F7].logical);
X fputs(" ",se);
X ffso(" F8 ");ff(se,cfmt2,keyset_table[KDEk_F8].logical);
X fputs(" ",se);
X ffso(" BkTab");ff(se,cfmt3,keyset_table[KDEk_BKTAB].logical);
X fputs("\r\n",se);
X
X ffso(" F9 ");ff(se,cfmt1,keyset_table[KDEk_F9].logical);
X fputs(" ",se);
X ffso(" F10 ");ff(se,cfmt2,keyset_table[KDEk_F10].logical);
X fputs(" ",se);
X ffso(" CUR^ ");ff(se,cfmt3,keyset_table[KDEk_CUU].logical);
X fputs(" ",se);
X ffso(" CUR> ");ff(se,cfmt4,keyset_table[KDEk_CUR].logical);
X fputs("\r\n",se);
X
X ffso(" F11 ");ff(se,cfmt1,keyset_table[KDEk_F11].logical);
X fputs(" ",se);
X ffso(" F12 ");ff(se,cfmt2,keyset_table[KDEk_F12].logical);
X fputs(" ",se);
X ffso(" CUR< ");ff(se,cfmt3,keyset_table[KDEk_CUL].logical);
X fputs(" ",se);
X ffso(" CURv ");ff(se,cfmt4,keyset_table[KDEk_CUD].logical);
X fputs("\r\n\r\n",se);
X }
X
X} /* end of keyset_display */
X
X/* end of ecufkey.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1224222890 'ecufkey.c' &&
chmod 0644 ecufkey.c ||
echo 'restore of ecufkey.c failed'
Wc_c="`wc -c < 'ecufkey.c'`"
test 12100 -eq "$Wc_c" ||
echo 'ecufkey.c: original size 12100, current size' "$Wc_c"
# ============= ecufork.c ==============
echo 'x - extracting ecufork.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecufork.c' &&
X/*+-------------------------------------------------------------------------
X ecufork.c -- ecu spawning ground
X wht at n4hgf.Mt-Park.GA.US
X
X Defined functions:
X exec_cmd(cmdstr)
X expand_cmd_with_wildlist(cmd,expcmd)
X find_executable(progname)
X is_executable(progname)
X shell(shellcmd)
X smart_fork()
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:09-19-1990-19:36-wht at n4hgf-ecu_log_event now gets pid for log from caller */
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecufork.h"
X
Xextern int rcvr_pid;
Xextern int last_child_wait_status;
Xextern int last_child_wait_pid;
X
X/*+-------------------------------------------------------------------------
X smart_fork()
X--------------------------------------------------------------------------*/
Xint
Xsmart_fork()
X{
Xregister int count = 5;
Xregister int pid;
X
X while(count--)
X {
X if((pid = fork()) >= 0)
X return(pid);
X if(count)
X nap(40L);
X }
X return(-1);
X} /* end of smart_fork */
X
X/*+-----------------------------------------------------------------------
X shell(shellcmd)
X
X param 'shellcmd' is a shell command prefixed with either
X a '!', '$', '>' character.
X
X '!' causes the command to run as a normal subshell of a process.
X '$' causes the communications line to be stdin and stdout
X for the spawned shell
X '>' causes spawned shell to receive exactly sames files as ecu
X------------------------------------------------------------------------*/
Xvoid
Xshell(shellcmd)
Xchar *shellcmd;
X{
Xregister shellpid;
Xregister itmp;
Xregister char *cptr;
Xchar s40[40];
Xint wait_status;
X
Xint rcvr_alive = (rcvr_pid > 0);
Xchar *getenv();
X
X if(rcvr_alive)
X kill_rcvr_process(SIGUSR1); /* stop receiver process gracefully */
X
X signal(SIGINT,SIG_IGN);
X signal(SIGTERM,SIG_IGN);
X signal(SIGUSR1,SIG_IGN);
X signal(SIGUSR2,SIG_IGN);
X signal(SIGCLD,SIG_DFL);
X
X if((shellpid = smart_fork()) < 0)
X {
X ff(se,"Cannot fork\r\n");
X if(rcvr_alive)
X start_rcvr_process(1);
X xmtr_signals();
X return;
X }
X
X ttymode(0); /* set canonical tty mode */
X if(shellpid == 0) /* we are the spawned (going to call shell) */
X {
X if(*shellcmd != '>') /* '>' prefix means leave fd's alone! */
X {
X /* Hook-up our "standard output" to either the tty or
X * the line as appropriate for '!' or '$' */
X close(TTYOUT);
X fcntl(((*shellcmd == '$') ? shm->Liofd : TTYERR),F_DUPFD,TTYOUT);
X if(*shellcmd == '$')
X {
X close(TTYIN);
X fcntl(shm->Liofd,F_DUPFD,TTYIN);
X }
X close(shm->Liofd);
X }
X
X child_signals(); /* signals for child */
X
X if(*shellcmd == '!')
X {
X cptr = getenv("SHELL");
X if(cptr == (char *)0)
X cptr = "/bin/csh";
X }
X else
X cptr = "/bin/sh";
X
X shellcmd++;
X child_signals();
X if(ulindex(cptr,"csh") > -1)
X {
X if(*shellcmd == '\0')
X execl(cptr,"csh",(char *)0);
X else
X execl(cptr,"csh","-c",shellcmd,(char *)0);
X }
X else
X {
X if(*shellcmd == '\0')
X execl(cptr,"sh",(char *)0);
X else
X execl(cptr,"sh","-c",shellcmd,(char *)0);
X }
X
X ff(se,"cannot execute %s\r\n",cptr); /* should not get here */
X _exit(255); /* end of spawned process */
X } /* end of if child process */
X
X#if defined(FORK_DEBUG)
X sprintf(s40,"DEBUG fork shell pid %d",shellpid);
X ecu_log_event(getpid(),s40); /* shell */
X#endif
X
X while(((itmp = wait(&wait_status)) != shellpid) && (itmp != -1))
X ;
X last_child_wait_status = wait_status;
X last_child_wait_pid = shellpid;
X
X xmtr_signals(); /* restore standard xmtr signals */
X ttymode(1); /* control tty back to raw mode */
X
X/* any comm program will probably doodle with the line characteristics. */
X/* we want to make sure they are restored to normal */
X lreset_ksr(); /* restore comm line params */
X
X if(rcvr_alive)
X start_rcvr_process(1);
X
X} /* end of shell */
X
X/*+-------------------------------------------------------------------------
X is_executable(progname)
X--------------------------------------------------------------------------*/
Xis_executable(progname)
Xchar *progname;
X{
Xstruct stat ss;
X
X if(stat(progname,&ss) < 0) /* if cannot stat, flunk */
X return(0);
X if((ss.st_mode & 0111) == 0) /* if no --x--x--x, flunk */
X return(0);
X return(1); /* whew, this OUGHT to work */
X
X} /* end of is_executable */
X
X/*+-------------------------------------------------------------------------
X find_executable(progname)
XPATH=':/usr/wht/bin:/bin:/usr/bin:/usr/wht/bin:/etc/tuckerware' len=56
X--------------------------------------------------------------------------*/
Xchar *
Xfind_executable(progname)
Xchar *progname;
X{
Xregister itmp;
Xstatic char *path_buf = (char *)0;
X#define PATHNAME_QUAN 32
Xstatic char *path_name[PATHNAME_QUAN + 1];
Xstatic char rtn_path[256];
Xstatic int path_count = 0;
Xchar *cptr;
Xchar *getenv();
X
X if(path_buf == (char *)0)
X {
X if((cptr = getenv("PATH")) == (char *)0)
X return(cptr);
X if(!(path_buf = malloc(strlen(cptr) + 1)))
X return((char *)0);
X strcpy(path_buf,cptr);
X path_name[PATHNAME_QUAN + 1] = (char *)0;
X cptr = path_buf;
X for(path_count = 0; path_count < PATHNAME_QUAN; path_count++)
X {
X if(*cptr == 0)
X break;
X path_name[path_count] = cptr;
X while((*cptr != ':') && (*cptr != 0))
X cptr++;
X if(*cptr == ':')
X *cptr++ = 0;
X }
X } /* end of get and process path env variable */
X
X/* look for executable */
X for(itmp = 0; itmp < path_count; itmp++)
X {
X if(*path_name[itmp] == 0) /* if null path (./) */
X strcpy(rtn_path,"./");
X else
X sprintf(rtn_path,"%s/",path_name[itmp]);
X strcat(rtn_path,progname);
X if(is_executable(rtn_path))
X return(rtn_path);
X }
X return((char *)0);
X} /* end of find_executable */
X
X/*+-------------------------------------------------------------------------
X exec_cmd(cmdstr) - execute an arbitrary program with arguments
Xkills rcvr process if alive and restarts it when done if was alive
X--------------------------------------------------------------------------*/
Xexec_cmd(cmdstr)
Xchar *cmdstr;
X{
Xchar *cmdpath;
X#define MAX_EXEC_ARG 512
Xchar *cmdargv[MAX_EXEC_ARG];
Xint itmp;
Xint execpid;
Xint rcvr_alive = (rcvr_pid > 0);
Xint old_ttymode = get_ttymode();
Xint wait_status = 0;
Xextern int errno;
Xchar *strrchr();
X
X#if defined(FORK_DEBUG)
Xchar s80[80];
X strcpy(s80,"DEBUG exec ");
X strncat(s80,cmdstr,sizeof(s80)-12);
X s80[sizeof(s80)-12] = 0;
X ecu_log_event(getpid(),s80);
X#endif
X
X build_arg_array(cmdstr,cmdargv,MAX_EXEC_ARG,&itmp);
X if(itmp == MAX_EXEC_ARG)
X {
X ff(se,"Too many arguments to command\r\n");
X return(-1);
X }
X else if(!itmp)
X {
X ff(se,"null command\r\n");
X return(-1);
X }
X
X if(*cmdargv[0] == '/')
X {
X cmdpath = cmdargv[0];
X cmdargv[0] = strrchr(cmdargv[0],'/') + 1;
X }
X else
X {
X if((cmdpath = find_executable(cmdargv[0])) == (char *)0)
X {
X ff(se,"Cannot find %s\r\n",cmdargv[0]);
X return(-1);
X }
X }
X
X if(rcvr_alive)
X kill_rcvr_process(SIGUSR1); /* stop receiver process gracefully */
X
X/* this code executed by the father (forking) process */
X/* wait on death of child (morbid in life, but ok here) */
X
X signal(SIGINT,SIG_IGN);
X signal(SIGTERM,SIG_IGN);
X signal(SIGUSR1,SIG_IGN);
X signal(SIGUSR2,SIG_IGN);
X signal(SIGCLD,SIG_DFL);
X
X if((execpid = smart_fork()) < 0)
X {
X ff(se,"Cannot fork\r\n");
X if(rcvr_alive)
X start_rcvr_process(1);
X xmtr_signals();
X return(-1);
X }
X
X if(execpid == 0) /* we are the spawned (going to call exec) */
X {
X ttymode(0); /* set canonical tty mode */
X child_signals();
X execv(cmdpath,cmdargv);
X perror(cmdpath);
X exit(255); /* end of spawned process */
X } /* end of if child process */
X
X wait_status = 0;
X while(((itmp = wait(&wait_status)) != execpid) && (itmp != -1))
X ;
X last_child_wait_status = wait_status;
X last_child_wait_pid = execpid;
X
X/* resume our normally scheduled program */
X lreset_ksr(); /* restore comm line params */
X ttymode(old_ttymode); /* control tty back to original */
X if(rcvr_alive)
X start_rcvr_process(1);
X xmtr_signals();
X return(last_child_wait_status);
X
X} /* end of exec_cmd */
X
X/*+-------------------------------------------------------------------------
X expand_cmd_with_wildlist(cmd,&expcmd)
Xif return -1, error, expcmd has error message (static message)
Xif return 0, cmd has been expanded, expcmd must be free()'d when done
X--------------------------------------------------------------------------*/
Xexpand_cmd_with_wildlist(cmd,expcmd)
Xchar *cmd;
Xchar **expcmd;
X{
Xregister char *cptr;
X#define P_READ 0
X#define P_WRITE 1
Xint pipe_pid;
Xint stdout_pipe[2];
Xint stderr_pipe[2];
Xint count;
Xint itmp;
Xint wait_status;
Xint rcvr_alive = (rcvr_pid > 0);
Xchar *echo_cmd;
Xstatic char s132[132];
Xextern int errno;
Xextern char *sys_errlist[];
Xchar *strchr();
Xstatic char *pipe_err_msg = "system error: no pipe";
Xstatic char *mem_err_msg = "system error: no memory";
X
X if(strchr(cmd,'<') || strchr(cmd,'>') || strchr(cmd,'&'))
X {
X *expcmd = "illegal characters: '<', '>' or '&'";
X return(-1);
X }
X
X if(pipe(stdout_pipe) < 0)
X {
X *expcmd = pipe_err_msg;
X return(-1);
X }
X if(pipe(stderr_pipe) < 0)
X {
X close(stdout_pipe[P_READ]);
X close(stdout_pipe[P_WRITE]);
X *expcmd = pipe_err_msg;
X return(-1);
X }
X if(!(echo_cmd = malloc(strlen(cmd) + 10)))
X {
X close(stdout_pipe[P_READ]);
X close(stdout_pipe[P_WRITE]);
X close(stderr_pipe[P_READ]);
X close(stderr_pipe[P_WRITE]);
X *expcmd = mem_err_msg;
X return(-1);
X }
X
X strcpy(echo_cmd,"echo ");
X strcat(echo_cmd,cmd);
X
X
X if(rcvr_alive)
X kill_rcvr_process(SIGUSR1); /* stop receiver process gracefully */
X
X signal(SIGINT,SIG_IGN);
X signal(SIGTERM,SIG_IGN);
X signal(SIGUSR1,SIG_IGN);
X signal(SIGUSR2,SIG_IGN);
X signal(SIGCLD,SIG_DFL);
X
X if((pipe_pid = smart_fork()) == 0)
X {
X int null = open("/dev/null",O_WRONLY,0);
X
X close(stdout_pipe[P_READ]);
X close(TTYOUT);
X dup(stdout_pipe[P_WRITE]);
X close(stdout_pipe[P_WRITE]);
X close(TTYERR);
X dup(stderr_pipe[P_WRITE]);
X close(stderr_pipe[P_WRITE]);
X close(null);
X child_signals();
X execl("/bin/csh","csh","-e","-f","-c",echo_cmd,(char *)0);
X _exit(255);
X }
X#if defined(FORK_DEBUG)
X sprintf(s132,"DEBUG expand pid %d",pipe_pid);
X ecu_log_event(getpid(),s132); /* expand_cmd_with_wildlist */
X#endif
X
X free(echo_cmd);
X
X close(stdout_pipe[P_WRITE]);
X close(stderr_pipe[P_WRITE]);
X if(pipe_pid == -1)
X {
X close(stdout_pipe[P_READ]);
X close(stderr_pipe[P_READ]);
X *expcmd = "could not fork";
X if(rcvr_alive)
X start_rcvr_process(0);
X xmtr_signals();
X return(-1);
X }
X
X if(!(*expcmd = malloc(5120)))
X {
X close(stdout_pipe[P_READ]);
X close(stderr_pipe[P_READ]);
X kill(pipe_pid,SIGKILL);
X *expcmd = mem_err_msg;
X if(rcvr_alive)
X start_rcvr_process(0);
X return(-1);
X }
X
X cptr = *expcmd;
X while((count = read(stdout_pipe[P_READ],cptr,64)) != 0)
X {
X if(count < 0)
X {
X if(errno == EINTR)
X {
X errno = 0;
X continue;
X }
X free(*expcmd);
X kill(pipe_pid,SIGKILL);
X close(stdout_pipe[P_READ]);
X close(stderr_pipe[P_READ]);
X *expcmd = "error reading wild list expansion";
X if(rcvr_alive)
X start_rcvr_process(0);
X return(-1);
X }
X cptr += count;
X *cptr = 0;
X if(*(cptr - 1) == '\n')
X {
X *(cptr - 1) = 0;
X break;
X }
X }
X close(stdout_pipe[P_READ]);
X if(!strlen(*expcmd))
X {
X free(*expcmd);
X count = read(stderr_pipe[P_READ],s132,sizeof(s132) - 1);
X if(count < 0)
X strcpy(s132,sys_errlist[errno]);
X else
X s132[count] = 0;
X if(s132[count - 1] == '\n')
X s132[count - 1] = 0;
X close(stderr_pipe[P_READ]);
X if(strncmp(s132,"echo: ",6))
X *expcmd = s132;
X else
X *expcmd = s132 + 6;
X if(rcvr_alive)
X start_rcvr_process(0);
X return(-1);
X }
X
X wait_status = 0;
X while(((itmp = wait(&wait_status)) != pipe_pid) && (itmp != -1))
X ;
X
X xmtr_signals();
X if(wait_status)
X {
X free(*expcmd);
X count = read(stderr_pipe[P_READ],s132,sizeof(s132) - 1);
X if(count < 0)
X strcpy(s132,sys_errlist[errno]);
X else
X s132[count] = 0;
X if(s132[count - 1] == '\n')
X s132[count - 1] = 0;
X close(stderr_pipe[P_READ]);
X if(strncmp(s132,"echo: ",6))
X *expcmd = s132;
X else
X *expcmd = s132 + 6;
X if(rcvr_alive)
X start_rcvr_process(0);
X return(-1);
X }
X close(stderr_pipe[P_READ]);
X
X if(rcvr_alive)
X start_rcvr_process(0);
X return(0);
X} /* end of expand_cmd_with_wildlist */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1224222990 'ecufork.c' &&
chmod 0644 ecufork.c ||
echo 'restore of ecufork.c failed'
Wc_c="`wc -c < 'ecufork.c'`"
test 12087 -eq "$Wc_c" ||
echo 'ecufork.c: original size 12087, current size' "$Wc_c"
# ============= ecuicmaux.c ==============
echo 'x - extracting ecuicmaux.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuicmaux.c' &&
X/*+-------------------------------------------------------------------------
X ecuicmaux.c -- ecuicmd.c auxiliary functions
X wht at n4hgf.Mt-Park.GA.US
X
X Defined functions:
X icmd_escape_str()
X display_ascii_names()
X nlin_nlout_control(token,narg,arg)
X icmd_conversion(token,narg,arg)
X icmd_log(token,narg,arg)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "ecuerror.h"
X#include "ecucmd.h"
X
X#if !defined(M_XENIX) || defined(M_UNIX)
Xextern int cmd_escape; /* icmd escape */
X#endif
Xextern int rcvr_pid;
X
Xchar rcvr_log_file[256]; /* if rcvr_log!= 0,log filename */
Xint rcvr_log = 0; /* rcvr log active if != 0 */
Xint rcvr_log_gen_title = 0; /* gen log header on next open (rcvr process) */
XFILE *rcvr_log_fp; /* rcvr log file */
Xint rcvr_log_append = 1;
Xint rcvr_log_raw = 0;
Xint rcvr_log_flusheach = 0;
X
X/*+-------------------------------------------------------------------------
X icmd_escape_str()
X--------------------------------------------------------------------------*/
Xchar *
Xicmd_escape_str()
X{
X#if defined(M_XENIX) || defined(M_UNIX)
X return("HOME ");
X#else
Xchar *make_char_graphic();
X return(make_char_graphic(cmd_escape,0));
X#endif
X} /* end of icmd_escape_str */
X
X/*+-----------------------------------------------------------------------
X display_ascii_names()
X------------------------------------------------------------------------*/
Xvoid
Xdisplay_ascii_names()
X{
Xregister intval;
X
X for(intval = 0; intval < 32; intval++)
X {
X ff(se,"%s %3d %03o %02x ^%c | ",hex_to_ascii_name((intval)),
X (intval),(intval),(intval),(intval) |0x40);
X ff(se," %3d %03o %02x %c | ",
X intval+32,intval+32,intval+32,intval+32);
X ff(se," %3d %03o %02x %c | ",
X intval+64,intval+64,intval+64,intval+64);
X if(intval != 31)
X {
X ff(se," %3d %03o %02x %c\r\n",
X intval+96,intval+96,intval+96,intval+96);
X }
X else
X {
X ff(se," %3d %03o %02x ^?\r\n",
X intval+96,intval+96,intval+96);
X }
X }
X
X} /* end of display_ascii_names */
X
X/*+-------------------------------------------------------------------------
X icmd_conversion(token,narg,arg)
X--------------------------------------------------------------------------*/
Xvoid
Xicmd_conversion(token,narg,arg)
Xint token;
Xint narg;
Xchar **arg;
X{
Xregister itmp;
X
X switch(token)
X {
X case CTxa:
X case CToa:
X case CTda:
X if(narg > 1)
X {
X int result;
X char format[4];
X sprintf(format,"%%%c",to_lower(*arg[0]));
X if(sscanf(arg[1],format,&result) == 0)
X {
X ff(se," invalid argument\r\n");
X return;
X }
X result &= 0xFF;
X if(result == ' ')
X ff(se," == ' ' 0x20\r\n",make_char_graphic(result,1));
X else
X ff(se," == %s\r\n",make_char_graphic(result,1));
X }
X else
X {
X ff(se,"\r\n");
X display_ascii_names();
X }
X break;
X case CTax:
X if(arg[1] == (char *)0)
X {
X ff(se,"\r\n");
X display_ascii_names();
X break;
X }
X switch(strlen(arg[1]))
X {
X case 1:
X ff(se," == 0x%02x\r\n",*arg[1]);
X break;
X case 2:
X if(*arg[1] == '^')
X {
X itmp = to_upper(*(arg[1] + 1));
X if((itmp < '@') || (itmp > '_'))
X {
X ff(se," not a valid control character\r\n");
X return;
X }
X itmp &= 0x1F;
X ff(se," == 0x%02x %s\r\n",itmp,make_char_graphic(itmp,1));
X break;
X } /* else fall thru */
X case 3:
X if((itmp = ascii_name_to_hex(arg[1])) > -1)
X {
X ff(se," == 0x%02x %s\r\n",itmp,make_char_graphic(itmp,1));
X break;
X } /* else fall thru */
X default:
X ff(se," invalid ... examples of valid parameters:\r\n");
X ff(se," ^A ETX or printable character\r\n");
X break;
X }
X break;
X default:
X ff(se," invalid command\r\n");
X }
X} /* end of icmd_conversion */
X
X/*+-------------------------------------------------------------------------
X icmd_log(token,narg,arg)
X--------------------------------------------------------------------------*/
Xint
Xicmd_log(token,narg,arg)
Xint token;
Xint narg;
Xchar **arg;
X{
Xregister itmp;
Xregister itmp2;
X
X switch(token)
X {
X case CTloff:
X goto LOG_OFF;
X break;
X#if defined(M_XENIX) || defined(M_UNIX)
X case CTllp:
X icmd("log /dev/lp1");
X#endif
X break;
X case CTlog:
X if(narg > 1)
X {
X if(minunique("off",arg[1],3))
X {
XLOG_OFF:
X if(rcvr_log == 0) /* "off",but not logging */
X goto RECORD_REPORT;
X ff(se,"\r\nlogging concluded (file %s)\r\n",rcvr_log_file);
X shmx_set_rcvr_log("",0,0,0);
X rcvr_log = 0;
X rcvr_log_file[0] = 0;
X return(0);
X }
X/* turning logging on */
X itmp2 = -1;
X rcvr_log_append = 1;
X rcvr_log_raw = 0;
X for(itmp = 1; itmp < narg; itmp++)
X {
X if(*arg[itmp] == '-')
X {
X switch(arg[itmp][1])
X {
X case 's': rcvr_log_append = 0; break;
X case 'r': rcvr_log_raw = 1; break;
X case 'f': rcvr_log_flusheach = 1; break;
X default:
X ff(se," unrecognized switch -%c\r\n",
X arg[itmp][1]);
X log_cmd_usage();
X return(eFATAL_ALREADY);
X }
X }
X else
X {
X if(itmp2 > 0)
X {
X ff(se," too many positional arguments\r\n");
X log_cmd_usage();
X return(eFATAL_ALREADY);
X }
X itmp2 = itmp;
X }
X }
X if(itmp2 < 0)
X {
X ff(se," no log file name specified\r\n");
X log_cmd_usage();
X return(eFATAL_ALREADY);
X }
X if(arg[itmp2][0] != '/') /* if log file not full path, ... */
X { /* ... supply current directory */
X get_curr_dir(rcvr_log_file,
X sizeof(rcvr_log_file) - strlen(arg[itmp2]) - 2);
X strcat(rcvr_log_file,"/");
X strcat(rcvr_log_file,arg[itmp2]);
X }
X else
X strcpy(rcvr_log_file,arg[itmp2]);
X
X /* try to open the file if we can */
X rcvr_log_fp = fopen(rcvr_log_file,"a");
X if(rcvr_log_fp != NULL) /* if success */
X {
X fclose(rcvr_log_fp);
X rcvr_log_fp = NULL;
X rcvr_log = 1;
X shmx_set_rcvr_log(rcvr_log_file,rcvr_log_append,rcvr_log_raw,
X rcvr_log_flusheach);
X }
X else /* xmtr() could not open file */
X {
X ff(se," could not open ");
X perror(rcvr_log_file);
X ff(se,"\r\n");
X return(eFATAL_ALREADY);
X }
X rcvr_log_append = 1;
X } /* end of if argument to command */
X
XRECORD_REPORT:
X if(rcvr_log)
X {
X ff(se,"\r\n%sing received %s text to\r\n%s\r\n",
X (rcvr_log_append) ? "append" : "writ",
X (rcvr_log_raw) ? "raw" : "filtered",
X rcvr_log_file);
X ff(se,"use \"%slog off\" to stop logging\r\n",
X icmd_escape_str());
X }
X else
X {
X ff(se," not logging.\r\n");
X ff(se,"use \"%slog <filename>\" to start logging\r\n",
X icmd_escape_str());
X }
X break;
X default:
X ff(se," invalid command\r\n");
X return(eFATAL_ALREADY);
X }
X return(0);
X} /* end of icmd_log */
X
X/*+-------------------------------------------------------------------------
X nlin_nlout_control(token,narg,arg)
X--------------------------------------------------------------------------*/
Xvoid
Xnlin_nlout_control(token,narg,arg)
Xint token;
Xint narg;
Xchar **arg;
X{
X switch(token)
X {
X case CTnlin:
X if(narg != 1)
X shm->Ladd_nl_incoming = yes_or_no(arg[1]);
X ff(se," %sappending NL to incoming CR\r\n",
X (shm->Ladd_nl_incoming) ? "" : "not ");
X break;
X case CTnlout:
X if(narg != 1)
X shm->Ladd_nl_outgoing = yes_or_no(arg[1]);
X ff(se," %sappending NL to outgoing CR\r\n",
X (shm->Ladd_nl_outgoing) ? "" : "not ");
X break;
X default:
X case CTnl:
X ff(se," incoming: %s outgoing: %s\r\n",
X (shm->Ladd_nl_incoming) ? "CR/LF" : "CR",
X (shm->Ladd_nl_outgoing) ? "CR/LF" : "CR");
X break;
X }
X
X} /* end of nlin_nlout_control */
X
X/* end of ecuicmaux.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1224224790 'ecuicmaux.c' &&
chmod 0644 ecuicmaux.c ||
echo 'restore of ecuicmaux.c failed'
Wc_c="`wc -c < 'ecuicmaux.c'`"
test 7552 -eq "$Wc_c" ||
echo 'ecuicmaux.c: original size 7552, current size' "$Wc_c"
# ============= ecuicmd.c ==============
echo 'x - extracting ecuicmd.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuicmd.c' &&
X/*+-----------------------------------------------------------------------
X ecuicmd.c - ECU interactive command handler
X wht at n4hgf.Mt-Park.GA.US
X
X Defined functions:
X icmd(icmd_cmd)
X icmd_do_proc(narg,arg)
X search_cmd_list(cmd_list,cmd)
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:12-24-1990-04:31-wht at n4hgf-experimental esio driver command */
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include "ecu.h"
X#include "esd.h"
X#include "ecufkey.h"
X#include "patchlevel.h"
X
X#define NEED_P_CMD
X#include "ecucmd.h"
X
Xchar *icmd_escape_str();
X
Xextern KDE keyset_table[];
Xextern char *makedate;
Xextern char curr_dir[];
Xextern char hello_str[];
Xextern char keyset_name[];
Xextern char rcvr_log_file[]; /* if rcvr_log!= 0,log filename */
Xextern int interrupt;
Xextern int current_ttymode;
Xextern int errno;
Xextern int proc_level;
Xextern int proctrace;
Xextern int rcvr_log; /* rcvr log active if != 0 */
Xextern int rcvr_log_append; /* if true, append, else scratch */
Xextern int rcvr_log_raw; /* if true, log all, else filter ctl chrs */
Xextern int rcvr_pid;
Xextern ulong colors_current;
Xextern FILE *plog_fp;
Xextern ESD *plog_name;
Xextern char screen_dump_file_name[];
X
Xint protocol_log_packets = 0;
Xint want_bell_notify = 1; /* want bell notify */
Xint cmd_escape;
X
X/*+-------------------------------------------------------------------------
X search_cmd_list(cmd_list,cmd)
Xreturns -1 if cmd not found or insufficient chars for match
Xelse token value for command
Xproc-only commands have 'min' values 0
X--------------------------------------------------------------------------*/
Xsearch_cmd_list(cmd_list,cmd)
Xregister P_CMD *cmd_list;
Xregister char *cmd;
X{
X while(cmd_list->token != -1)
X {
X if(cmd_list->min && minunique(cmd_list->cmd,cmd,cmd_list->min))
X return(cmd_list->token);
X cmd_list++;
X }
X return(-1);
X
X} /* end of search_cmd_list */
X
X/*+-------------------------------------------------------------------------
X icmd_do_proc(narg,arg)
X--------------------------------------------------------------------------*/
Xicmd_do_proc(narg,arg)
Xint narg;
Xchar **arg;
X{
Xregister erc;
Xulong colors_at_entry = colors_current;
X
X kill_rcvr_process(SIGUSR1);
X ttymode(2);
X erc = do_proc(narg,arg);
X proc_file_reset();
X ttymode(1);
X interrupt = 0;
X setcolor(colors_notify);
X ff(se,"[procedure finished]");
X setcolor(colors_at_entry);
X ff(se,"\r\n");
X start_rcvr_process(0);
X return(erc);
X} /* end of icmd_do_proc */
X
X/*+-----------------------------------------------------------------------
X icmd(cmd)
X This function implements the built in commands
X It returns non-zero if program should terminate
X------------------------------------------------------------------------*/
Xint
Xicmd(icmd_cmd)
Xregister char *icmd_cmd;
X{
X
X#define ARG_MAX_QUAN 40
Xchar *arg[ARG_MAX_QUAN];
Xchar cmd[128];
Xint itmp;
Xint token;
Xint narg = 0;
XESD *tesd;
Xchar s80[80];
Xchar *epoch_secs_to_str();
Xlong atol();
Xlong rcvr_chars;
Xlong rcvr_chars_this_connect;
Xchar *find_procedure();
Xchar *xon_status();
X
X icmd_history_add(icmd_cmd); /* add to history list */
X strcpy(cmd,icmd_cmd); /* get local copy of cmd string */
X switch(cmd[0])
X {
X case '.': /* exit xmtr() (generally program too) */
X ff(se," disconnecting from line %s\r\n",shm->Lline);
X return(1);
X case '!':
X case '$':
X case '>':
X ff(se,"\r\n");
X shell(cmd);
X return(0);
X case '-':
X ff(se,"\r\n");
X exec_cmd(&cmd[1]);
X return(0);
X case '^':
X ff(se,"\r\n");
X phrase_help();
X return(0);
X case '?':
X icmd_help(0,(char **)0);
X return(0);
X#ifdef DEBUG_SHM_SCREEN
X case '@':
X {
X FILE *fp = fopen("/tmp/screen","w");
X int y,x;
X char *cptr = (char *)shm->screen;
X for(y = 0; y < 43; y++)
X {
X for(x = 0; x < 80; x++)
X fputc(*cptr++,fp);
X fputc('\n',fp);
X }
X fclose(fp);
X }
X break;
X#endif
X default:
X break;
X }
X
X/* not single character argument */
X build_arg_array(cmd,arg,ARG_MAX_QUAN,&narg);
X
X/* handle phrases */
X if(isdigit(*arg[0]))
X {
X phrases(narg,arg);
X return(0);
X }
X
X/* search command list */
X if((token = search_cmd_list(icmd_cmds,arg[0])) < 0)
X {
X ff(se,"\r\n");
X if(find_procedure(arg[0]))
X {
X icmd_do_proc(narg,arg);
X return(0);
X }
X ff(se,"no such command or procedure ... %s? for help\r\n",
X icmd_escape_str());
X return(0);
X }
X
X switch(token)
X { /* keep alphabetized PLEASE */
X case CTrx:
X case CTry:
X case CTrz:
X case CTrk:
X case CTrs:
X receive_files_from_remote(narg,arg);
X break;
X
X case CTsx:
X case CTsy:
X case CTsz:
X case CTsk:
X case CTss:
X send_files_to_remote(narg,arg);
X break;
X
X case CTbaud:
X if(narg == 1)
X ff(se," baud rate is %u\r\n",shm->Lbaud);
X else
X {
X itmp = atoi(arg[1]);
X if(!lnew_baud_rate(itmp))
X ff(se," baud rate set to %u\r\n",shm->Lbaud);
X else
X {
X ff(se," invalid baud rate: %u\r\n",itmp);
X ff(se,"valid rates: 110,300,600,1200,2400,4800,9600,19200\r\n");
X }
X }
X break;
X
X case CTbreak:
X lbreak();
X ff(se," break sent\r\n");
X break;
X
X case CTcd:
X change_directory(arg[1],(narg == 1) ? 0 : 1);
X break;
X
X case CTclrx:
X lclear_xmtr_xoff();
X break;
X
X case CTdial:
X if(narg > 1)
X {
X ff(se,"\r\n");
X strcpy(shm->Llogical,arg[1]);
X if(!lookup_logical_telno())
X ff(se,"No such entry. Try 'dial' with no arguments\r\n");
X else
X {
X if(isdigit(shm->Llogical[0]) ||
X !find_procedure(shm->Llogical))
X DCE_dial();
X else
X {
X arg[0] = shm->Llogical;
X arg[1] = "!INTERACTIVE";
X icmd_do_proc(2,arg);
X }
X }
X }
X else
X {
X pde_list_manager();
X }
X break;
X
X case CTdo:
X ff(se,"\r\n");
X icmd_do_proc(narg - 1,&arg[1]);
X break;
X
X case CTptrace:
X if(narg > 1)
X proctrace = yes_or_no(arg[1]);
X ff(se," procedure trace %s", proctrace ? "on" : "off");
X if(proctrace > 1)
X ff(se," (%d)",proctrace);
X ff(se,"\r\n");
X break;
X
X case CTpcmd:
X itmp = strlen(arg[0]);
X if((tesd = make_esd(256)) == (ESD *)0)
X {
X ff(se," no memory!!?!\r\n");
X break;
X }
X strcpy(tesd->pb,icmd_cmd + itmp + 1);
X tesd->cb = strlen(tesd->pb);
X ff(se,"\r\n");
X kill_rcvr_process(SIGUSR1);
X ttymode(2);
X if(itmp = execute_esd(tesd))
X {
X proc_error(itmp);
X show_esd(tesd,"");
X }
X free_esd(tesd);
X ttymode(1);
X start_rcvr_process(0);
X break;
X
X case CTplog:
X fputs(" ",se);
X if(narg > 1)
X {
X if(!strcmp(arg[1],"off"))
X plog_control((char *)0);
X else
X plog_control(arg[1]);
X }
X
X if(plog_fp)
X ff(se,"procedure logging: %s\r\n",plog_name->pb);
X else
X fputs("procedure logging off\r\n",se);
X break;
X
X case CTduplex:
X if(narg > 1)
X {
X switch(to_lower(*arg[1]))
X {
X case 'f': shm->Lfull_duplex = 1; ff(se," now "); break;
X case 'h': shm->Lfull_duplex = 0; ff(se," now "); break;
X default: ff(se,
X"\r\nfirst argument character must be F or H for full or half duplex\r\n");
X break;
X }
X }
X else /* no argument */
X ff(se," currently ");
X
X ff(se,"%s duplex\r\n",(shm->Lfull_duplex) ? "full" : "half");
X break;
X
X case CTexit:
X ff(se," disconnecting from line %s\r\n",shm->Lline);
X return(1);
X
X case CTfi:
X file_insert_to_line(narg,arg);
X break;
X
X case CThangup:
X ff(se," hanging up ... ");
X DCE_hangup();
X ff(se,"done\r\n");
X break;
X
X case CThelp:
X icmd_help(narg,arg);
X break;
X
X case CTsdname:
X if(narg > 1)
X {
X char *new_file_name;
X
X itmp = 0; /* do not need to free(new_file_name) */
X if(find_shell_chars(arg[1]))
X {
X
X if(expand_cmd_with_wildlist(arg[1],&new_file_name))
X {
X ff(se," %s\r\n",new_file_name);
X break;
X }
X itmp = 1; /* need to free(new_file_name) */
X }
X else
X new_file_name = arg[1];
X
X screen_dump_file_name[0] = 0;
X if(*new_file_name != '/')
X {
X strcpy(screen_dump_file_name,curr_dir);
X strcat(screen_dump_file_name,"/");
X }
X strcat(screen_dump_file_name,arg[1]);
X if(itmp)
X free(new_file_name);
X }
X ff(se,"\r\nscreen dump name: %s\r\n",screen_dump_file_name);
X break;
X
X case CTlog:
X case CTloff:
X case CTllp:
X icmd_log(token,narg,arg);
X break;
X
X case CTnl:
X case CTnlin:
X case CTnlout:
X nlin_nlout_control(token,narg,arg);
X break;
X
X case CTparity:
X if(narg > 1)
X {
X switch(to_lower(*arg[1]))
X {
X case 'n':
X shm->Lparity = 0; break;
X case 'e':
X case 'o':
X shm->Lparity = to_lower(*arg[1]); break;
X default:
X ff(se," unrecognized parity: %c\r\n",*arg[1]);
X goto PARITY_DONE;
X }
X lset_parity(1);
X }
X ff(se," parity set to %c\r\n",
X (shm->Lparity) ? to_upper(shm->Lparity) : 'N');
XPARITY_DONE: ;
X break;
X
X case CTpid:
X ff(se,": xmtr %d, rcvr: %d, parent: %d, group: %d\r\n",
X getpid(0),rcvr_pid,getppid(0),getpgrp(0));
X break;
X
X case CTpwd:
X fputs(" ",se);
X tcap_stand_out();
X ff(se," %s ",curr_dir);
X tcap_stand_end();
X fputs("\r\n",se);
X break;
X
X case CTredial:
X (void)DCE_redial(arg,narg);
X break;
X
X case CTrev:
X fputs("\r\n",se);
X fputs(hello_str,se);
X fputs("\r\n",se);
X ff(se,"%s\r\n",makedate);
X break;
X
X case CTtime:
X get_tod(4,cmd);
X ff(se,": %s\r\n",cmd);
X break;
X
X case CTts:
X ff(se,"\r\n");
X sprintf(s80,"TTYIN %s (ttymode=%d)",get_ttyname(),current_ttymode);
X disp_line_termio(TTYIN,s80);
X ff(se,"\r\n");
X sprintf(s80,"comm line %s",shm->Lline);
X disp_line_termio(shm->Liofd,s80);
X break;
X
X#if defined(ESIO_IN_USE)
X case CTesio:
X icmd_esio(narg,arg);
X break;
X#endif
X case CTtty:
X ff(se," %s\r\n",get_ttyname());
X break;
X
X case CTda:
X case CToa:
X case CTxa:
X case CTax:
X icmd_conversion(token,narg,arg);
X break;
X
X case CTbn:
X if(narg > 1)
X {
X want_bell_notify = yes_or_no(arg[1]);
X shmx_set_rcvr_bn(want_bell_notify);
X }
X ff(se," bell notify %s%s\r\n",
X want_bell_notify ? "on" : "off",
X (want_bell_notify == 2) ? ": ring on incoming char" : "");
X break;
X
X case CTrtscts:
X if(narg > 1)
X {
X lRTSCTS_control(yes_or_no(arg[1]));
X }
X ff(se," RTS %s CTS %s\r\n",
X (Ltermio.c_cflag & RTSFLOW) ? "on" : "off",
X (Ltermio.c_cflag & CTSFLOW) ? "on" : "off");
X break;
X
X case CTfkey:
X if(narg < 2)
X keyset_display();
X else
X {
X switch(keyset_read(arg[1]))
X {
X case 0: keyset_display(); break;
X case -1: ff(se," cannot find ~/.ecu/keys\r\n"); break;
X case -2: ff(se," not found in ~/.ecu/keys\r\n"); break;
X }
X }
X break;
X
X case CTstat:
X ff(se,"\r\n\r\nDate/time");
X get_tod(4,cmd);
X ff(se,": %s\r\n",cmd);
X ff(se,"Console: %s communications line: %s ",
X get_ttyname(),shm->Lline);
X ff(se,"%u-%c-1\r\n",shm->Lbaud,
X (shm->Lparity) ? to_upper(shm->Lparity) : 'N');
X if(shm->Lmodem_off_hook)
X {
X ff(se,"Connected to %s: %s (%s)\r\n",
X shm->Lrname,shm->Ldescr,shm->Ltelno);
X ff(se,"at %s (elapsed %s)\r\n",
X epoch_secs_to_str(shm->Loff_hook_time,1,s80),
X get_elapsed_time(time((long *)0) - shm->Loff_hook_time));
X }
X ff(se,"Current directory: %s\r\n",curr_dir);
X ff(se,"Total chars transmitted: %ld",shm->xmit_chars);
X if(shm->Lmodem_off_hook)
X ff(se," (since CONNECT %ld)\r\n",
X shm->xmit_chars_this_connect);
X else
X fputs("\r\n",se);
X shmx_rc_report(&rcvr_chars,&rcvr_chars_this_connect);
X ff(se,"Total chars received: %ld",rcvr_chars);
X if(shm->Lmodem_off_hook)
X ff(se," (since CONNECT %ld)\r\n",rcvr_chars_this_connect);
X else
X fputs("\r\n",se);
X if(keyset_name[0])
X ff(se,"Function key set '%s' loaded\r\n",keyset_name);
X else
X ff(se,"No function key set loaded\r\n");
X if(rcvr_log)
X ff(se,"Session log open: %s (%s mode)\r\n",
X rcvr_log_file,(rcvr_log_raw) ? "raw" : "filtered");
X else
X ff(se,"Session logging not active\r\n");
X ff(se,"Bell notify is %s\r\n",(want_bell_notify) ? "on" : "off");
X ff(se,"Duplex: %s\r\n",(shm->Lfull_duplex) ? "full" : "half");
X ff(se,"CR conversion: incoming %s outgoing %s\r\n",
X (shm->Ladd_nl_incoming) ? "CR/LF" : "CR",
X (shm->Ladd_nl_outgoing) ? "CR/LF" : "CR");
X fputs("\r\n",se);
X break;
X
X case CTxlog:
X if(narg > 1)
X {
X protocol_log_packets = yes_or_no(arg[1]);
X }
X ff(se," protocol packet logging %s\r\n",
X (protocol_log_packets) ? "on" : "off");
X break;
X
X case CTxon:
X if(narg > 1)
X {
X if(set_xon_xoff_by_arg(arg[1]))
X ff(se," argument error\r\n");
X else
X ff(se,"\r\n");
X break;
X }
X ff(se," xon/xoff flow control: %s\r\n",xon_status());
X break;
X
X case CTsgr:
X send_get_response(token,narg,arg);
X break;
X
X/*
X case CTmkdir:
X if(narg < 2)
X ff(se," no argument\r\n");
X if(mkdir(arg[2],0755))
X {
X ff(se," ");
X pperror(arg[2]);
X }
X else
X ff(se," made directory %s\r\n",arg[2]);
X break;
X*/
X
X case 0:
X ff(se," procedure command not allowed in interactive mode\r\n");
X break;
X
X default:
X do_proc(narg,arg);
X interrupt = 0;
X break;
X
X }
X return(0); /* 0 == do not end program */
X
X} /* end of icmd */
X
X/* end of ecuicmd.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1224224790 'ecuicmd.c' &&
chmod 0644 ecuicmd.c ||
echo 'restore of ecuicmd.c failed'
Wc_c="`wc -c < 'ecuicmd.c'`"
test 12735 -eq "$Wc_c" ||
echo 'ecuicmd.c: original size 12735, current size' "$Wc_c"
true || echo 'restore of ecuicmhelp.c failed'
echo End of part 3, continue with part 4
exit 0
--------------------------------------------------------------------
Warren Tucker, TuckerWare emory!n4hgf!wht or wht at n4hgf.Mt-Park.GA.US
Hacker Extraordinaire d' async PADs, pods, proteins and protocols
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent at 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 at uunet.uu.net.
More information about the Comp.sources.misc
mailing list