home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / ecu / part05 < prev    next >
Text File  |  1991-08-05  |  55KB  |  2,213 lines

  1. Newsgroups: comp.sources.misc
  2. From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  3. Subject:  v21i057:  ecu - ECU async comm package rev 3.10, Part05/37
  4. Message-ID: <1991Aug3.033655.28223@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 3407f1d6d9c88d72d96cccd1b9a44883
  6. Date: Sat, 3 Aug 1991 03:36:55 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  10. Posting-number: Volume 21, Issue 57
  11. Archive-name: ecu/part05
  12. Supersedes: ecu3: Volume 16, Issue 25-59
  13. Environment: SCO, XENIX, ISC
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu310.05 (part 5 of ecu310)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ecufkey.c continued
  20. #
  21. if touch 2>&1 | fgrep 'amc' > /dev/null
  22.  then TOUCH=touch
  23.  else TOUCH=true
  24. fi
  25. if test ! -r _shar_seq_.tmp; then
  26.     echo 'Please unpack part 1 first!'
  27.     exit 1
  28. fi
  29. (read Scheck
  30.  if test "$Scheck" != 5; then
  31.     echo Please unpack part "$Scheck" next!
  32.     exit 1
  33.  else
  34.     exit 0
  35.  fi
  36. ) < _shar_seq_.tmp || exit 1
  37. if test ! -f _shar_wnt_.tmp; then
  38.     echo 'x - still skipping ecufkey.c'
  39. else
  40. echo 'x - continuing file ecufkey.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ecufkey.c' &&
  42. Xextern char curr_dir[CURR_DIRSIZ];    /* current working key defns */
  43. X
  44. XKDE        keyset_table[KDE_COUNT];
  45. Xchar keyset_name[32] = "";
  46. X
  47. XXF_KDE_NAME xf_kde_name[] =
  48. X{
  49. X    { XFcurup,    KDEk_CUU,    "CUU" },
  50. X    { XFcurdn,    KDEk_CUD,    "CUD" },
  51. X    { XFcurrt,    KDEk_CUR,    "CUR" },
  52. X    { XFcurlf,    KDEk_CUL,    "CUL" },
  53. X    { XFcur5,    KDEk_CU5,    "CU5" },
  54. X    { XFend,    KDEk_END,    "End" },
  55. X    { XFpgdn,    KDEk_PGDN,    "PgDn" },
  56. X    { XFhome,    KDEk_HOME,    "Home" },
  57. X    { XFpgup,    KDEk_PGUP,    "PgUp" },
  58. X    { XFins,    KDEk_INS,    "Ins" },
  59. X    { XF1,        KDEk_F1,    "F1" },
  60. X    { XF2,        KDEk_F2,    "F2" },
  61. X    { XF3,        KDEk_F3,    "F3" },
  62. X    { XF4,        KDEk_F4,    "F4" },
  63. X    { XF5,        KDEk_F5,    "F5" },
  64. X    { XF6,        KDEk_F6,    "F6" },
  65. X    { XF7,        KDEk_F7,    "F7" },
  66. X    { XF8,        KDEk_F8,    "F8" },
  67. X    { XF9,        KDEk_F9,    "F9" },
  68. X    { XF10,        KDEk_F10,    "F10" },
  69. X    { XF11,        KDEk_F11,    "F11" },
  70. X    { XF12,        KDEk_F12,    "F12" },
  71. X    { XFbktab,    KDEk_BKTAB,    "BkTab" },
  72. X    { 255,        KDEk_InitStr,"IS"},
  73. X    { 0,0,"" }
  74. X};
  75. X
  76. X/*+-------------------------------------------------------------------------
  77. X    keyset_init()
  78. X--------------------------------------------------------------------------*/
  79. Xvoid
  80. Xkeyset_init()
  81. X{
  82. Xregister itmp;
  83. Xregister KDE *tkde;
  84. Xchar *make_char_graphic();
  85. X
  86. X    for(itmp = 0; itmp < KDE_COUNT; itmp++)
  87. X    {
  88. X        tkde = &keyset_table[itmp];
  89. X        tkde->logical[0] = 0;
  90. X        tkde->count = 0;
  91. X        tkde->KDEt = (uchar)itmp;
  92. X    }
  93. X
  94. X    keyset_name[0] = 0;
  95. X
  96. X    tkde = &keyset_table[KDEk_BKTAB];
  97. X    strcpy(tkde->logical,"redisplay");
  98. X    tkde->count = KACT_REDISPLAY;
  99. X
  100. X    tkde = &keyset_table[KDEk_HOME];
  101. X    strcpy(tkde->logical,"ecu cmd");
  102. X    tkde->count = KACT_COMMAND;
  103. X
  104. X    tkde = &keyset_table[KDEk_INS];
  105. X    strcpy(tkde->logical,"local shell");
  106. X    tkde->count = KACT_LOCAL_SHELL;
  107. X
  108. X    tkde = &keyset_table[KDEk_CU5];
  109. X    strcpy(tkde->logical,"screen dump");
  110. X    tkde->str[0] = 0x7F;    /* this key is intercepted by kbd read routine */
  111. X    tkde->count = 0;
  112. X
  113. X}    /* end of keyset_init */
  114. X
  115. X/*+-------------------------------------------------------------------------
  116. X    kde_fgets(buf,bufsize,fp)
  117. X--------------------------------------------------------------------------*/
  118. Xint
  119. Xkde_fgets(buf,bufsize,fp)
  120. Xchar *buf;
  121. Xint bufsize;
  122. XFILE *fp;
  123. X{
  124. Xregister itmp;
  125. Xregister char *cptr;
  126. X
  127. X    if(!fgets(buf,bufsize,fp))
  128. X    {
  129. X        return(KDEt_EOF);
  130. X    }
  131. X
  132. X    if(!(itmp = strlen(buf)))
  133. X        return(KDEt_COMMENT);
  134. X    if(buf[itmp - 1] == '\n')
  135. X    {
  136. X        buf[itmp - 1] = 0;
  137. X        itmp--;
  138. X    }
  139. X    if(!itmp)
  140. X        return(KDEt_COMMENT);
  141. X
  142. X    cptr = buf;
  143. X    itmp = (strchr(" \t",*cptr)) ? KDEt_ENTRY : KDEt_NAME;
  144. X    while(*cptr && ((*cptr == SPACE) || (*cptr == TAB)))
  145. X        cptr++;
  146. X
  147. X    if(!*cptr || (*cptr == '#'))
  148. X        return(KDEt_COMMENT);
  149. X
  150. X    return(itmp);
  151. X    
  152. X}    /* end of kde_fgets */
  153. X
  154. X/*+-------------------------------------------------------------------------
  155. X    keyset_idnum(keystr)
  156. X--------------------------------------------------------------------------*/
  157. Xint
  158. Xkeyset_idnum(keystr)
  159. Xchar *keystr;
  160. X{
  161. Xstruct XF_KDE_NAME *xkn = xf_kde_name;
  162. X    while(xkn->xf != 0)
  163. X    {
  164. X        if(!strcmpi(xkn->name,keystr))
  165. X            return((int)xkn->kde);
  166. X        xkn++;
  167. X    }
  168. X    return(-1);
  169. X}    /* end of keyset_idnum */
  170. X
  171. X/*+-------------------------------------------------------------------------
  172. X    keyset_idstr(KDEt)
  173. X--------------------------------------------------------------------------*/
  174. Xchar *
  175. Xkeyset_idstr(KDEt)
  176. Xint KDEt;
  177. X{
  178. Xstruct XF_KDE_NAME *xkn = xf_kde_name;
  179. X
  180. X    while(xkn->xf)
  181. X    {
  182. X        if((int)xkn->kde == KDEt)
  183. X            return(xkn->name);
  184. X        xkn++;
  185. X    }
  186. X    return((char *)0);
  187. X}    /* end of keyset_idstr */
  188. X
  189. X/*+-------------------------------------------------------------------------
  190. X    xf_to_KDEt(xf)
  191. X--------------------------------------------------------------------------*/
  192. Xint
  193. Xxf_to_KDEt(xf)
  194. Xuchar xf;
  195. X{
  196. Xstruct XF_KDE_NAME *xkn = xf_kde_name;
  197. X
  198. X    while(xkn->xf)
  199. X    {
  200. X        if(xkn->xf == xf)
  201. X            return((int)xkn->kde & 0xFF);
  202. X        xkn++;
  203. X    }
  204. X    return(-1);
  205. X}    /* end of xf_to_KDEt */
  206. X
  207. X/*+-------------------------------------------------------------------------
  208. X    keyset_define_key(bufptr)
  209. X
  210. Xreturn 0 if no error, 1 if done, -1 if error
  211. X--------------------------------------------------------------------------*/
  212. Xint
  213. Xkeyset_define_key(bufptr)
  214. Xchar *bufptr;
  215. X{
  216. Xregister itmp;
  217. Xregister token_number;
  218. Xregister KDE *tkde = (KDE *)0;
  219. Xint KDEt = 0;
  220. Xchar token_separator[8];
  221. Xchar *token;
  222. Xchar *syntax = "syntax error in key definition: %s\n";
  223. Xchar *str_token();
  224. X
  225. X    if(itmp = strlen(bufptr))    /* itmp = len; if > 0 ... */
  226. X        bufptr[--itmp] = 0;        /* ... strip trailing NL */
  227. X    if(!itmp)
  228. X        return(0);
  229. X
  230. X    if(bufptr[0] == '#')        /* comment? */
  231. X        return(0);
  232. X    if((*bufptr != 0x20) && (*bufptr != TAB))    /* if no leading space */
  233. X        return(1);
  234. X    if(*bufptr == 0)                    /* if line all blank, break */
  235. X        return(1);
  236. X
  237. X    while((*bufptr == 0x20) || (*bufptr == TAB))    /* strip lding sp/tab */
  238. X        bufptr++;
  239. X
  240. X    token_number = 0;
  241. X    strcpy(token_separator,":");
  242. X    while(token = str_token(bufptr,token_separator))
  243. X    {
  244. X        bufptr = (char *)0;    /* further calls to str_token need NULL */
  245. X        switch(token_number)
  246. X        {
  247. X            case 0:        /* first field is key identifier */
  248. X                if((KDEt = keyset_idnum(token)) < 0)
  249. X                {
  250. X                    pprintf(syntax,keyset_name);
  251. X                    pprintf("  %s is not a legal key identifier\n",token);
  252. X                    return(-1);
  253. X                }
  254. X                if(KDEt == KDEk_HOME)
  255. X                {
  256. X                    pprintf(syntax,keyset_name);
  257. X                    pprintf("  HOME cannot be redefined!\n");
  258. X                    return(-1);
  259. X                }
  260. X                if(KDEt == KDEk_CU5)
  261. X                {
  262. X                    pprintf(syntax,keyset_name);
  263. X                    pprintf("  CUR5 cannot be redefined!\n");
  264. X                    return(-1);
  265. X                }
  266. X                if(KDEt == KDEk_BKTAB)
  267. X                {
  268. X                    pprintf(syntax,keyset_name);
  269. X                    pprintf("  BkTab cannot be redefined!\n");
  270. X                    return(-1);
  271. X                }
  272. X                tkde = &keyset_table[KDEt];
  273. X                tkde->logical[0] = 0;
  274. X                tkde->count = 0;
  275. X                break;
  276. X
  277. X            case 1:        /* second field is logical key name */
  278. X                strncpy(tkde->logical,token,sizeof(tkde->logical));
  279. X                tkde->logical[sizeof(tkde->logical) - 1] = 0;
  280. X                strcpy(token_separator," \t"); /* whitespace is tok sep now */
  281. X                break;
  282. X
  283. X            default:    /* third and subsequent to define key */
  284. X                if(!strlen(token))
  285. X                    continue;
  286. X                if(tkde->count == sizeof(tkde->str))
  287. X                {
  288. X                    pprintf(syntax,keyset_name);
  289. X                    pprintf("  %s: output count too long",
  290. X                        keyset_idstr(KDEt));
  291. X                    return(-1);
  292. X                }
  293. X                if((itmp = ascii_to_hex(token)) < 0)
  294. X                {
  295. X                    pprintf(syntax,keyset_name);
  296. X                    pprintf("  %s: '%s' invalid code\n",
  297. X                        keyset_idstr(KDEt),token);
  298. X                    return(0);
  299. X                }
  300. X                tkde->str[tkde->count] = itmp;
  301. X                tkde->count++;
  302. X                break;
  303. X        }    /* end of switch(token_number) */
  304. X        token_number++;
  305. X    }        /* end while not end of record */
  306. X
  307. X    return(0);
  308. X}    /* end of keyset_define_key */
  309. X
  310. X/*+-------------------------------------------------------------------------
  311. X    keyset_read(name)
  312. Xreturns 0 on success, -1 if no .ecu/keys, -2 if no 'name', -3 if error
  313. X--------------------------------------------------------------------------*/
  314. Xint
  315. Xkeyset_read(name)
  316. Xchar *name;
  317. X{
  318. Xregister itmp = 0;
  319. Xregister char *cptr;
  320. Xstatic char ecukeys_name[128];
  321. Xchar readkde_buf[128];
  322. XFILE *fp_keys;
  323. X
  324. X    if(!ecukeys_name[0])
  325. X    {
  326. X        get_home_dir(ecukeys_name);
  327. X        strcat(ecukeys_name,"/.ecu/keys");
  328. X    }
  329. X
  330. X    if((fp_keys = fopen(ecukeys_name,"r")) == NULL)
  331. X        return(-1);
  332. X
  333. X/* find keyset name */
  334. X    while(fgets(readkde_buf,sizeof(readkde_buf),fp_keys) != NULL)
  335. X    {
  336. X        if(readkde_buf[0] == '#')        /* comment? */
  337. X            continue;
  338. X        if(itmp = strlen(readkde_buf))    /* itmp = len; if > 0 ... */
  339. X            readkde_buf[--itmp] = 0;    /* ... strip trailing NL */
  340. X        if(!itmp)
  341. X            continue;
  342. X        if(strcmp(readkde_buf,name) == 0)
  343. X        {
  344. X            itmp = 1;        /* indicate success */
  345. X            break;
  346. X        }
  347. X        itmp = 0;            /* if loop terminates w/o find, failure */
  348. X    }
  349. X    if(!itmp)
  350. X    {
  351. X        fclose(fp_keys);
  352. X        return(-2);
  353. X    }
  354. X
  355. X    keyset_init();    /* clear any previous key defns */
  356. X    strncpy(keyset_name,name,sizeof(keyset_name));
  357. X    keyset_name[sizeof(keyset_name) - 1] = 0;
  358. X
  359. X/*
  360. X * read past any other keyset names matching this set
  361. X * process 1st line of definition when found
  362. X */
  363. X    while(fgets(readkde_buf,sizeof(readkde_buf),fp_keys) != NULL)
  364. X    {
  365. X        cptr = readkde_buf;                /* first call to str_token, -> buff */
  366. X        if((*cptr == 0x20) || (*cptr == TAB))    /* if leading space */
  367. X        {
  368. X            if((itmp = keyset_define_key(readkde_buf)) < 0)
  369. X            {
  370. X                fclose(fp_keys);
  371. X                keyset_name[0] = 0;
  372. X                return(-3);
  373. X            }
  374. X            break;
  375. X        }
  376. X    }
  377. X
  378. X/*
  379. X * read rest of definition
  380. X */
  381. X    while(fgets(readkde_buf,sizeof(readkde_buf),fp_keys) != NULL)
  382. X    {
  383. X        if((itmp = keyset_define_key(readkde_buf)) < 0)
  384. X        {
  385. X            fclose(fp_keys);
  386. X            keyset_name[0] = 0;
  387. X            return(-3);
  388. X        }
  389. X        else if(itmp)
  390. X            break;
  391. X    }
  392. X
  393. X    fclose(fp_keys);
  394. X    return(0);
  395. X}    /* end of keyset_read */
  396. X
  397. X/*+-------------------------------------------------------------------------
  398. X    ffso(str)
  399. X--------------------------------------------------------------------------*/
  400. Xvoid
  401. Xffso(str)
  402. Xchar *str;
  403. X{
  404. X    tcap_stand_out();
  405. X    fputs(str,se);
  406. X    tcap_stand_end();
  407. X}    /* end of ffso */
  408. X
  409. X/*+-------------------------------------------------------------------------
  410. X    keyset_display()
  411. X
  412. X F1  xxxxx  F2   xxxxx   HOME xxxxx  PGUP xxxxx
  413. X F3  xxxxx  F4   xxxxx   END  xxxxx  PGDN xxxxx
  414. X F5  xxxxx  F6   xxxxx   INS  xxxxx  CUR5 xxxxx
  415. X F7  xxxxx  F8   xxxxx   BkTab xxxxx
  416. X F9  xxxxx  F10  xxxxx   CUR^ xxxxx  CUR> xxxxx
  417. X F11 xxxxx  F12  xxxxx   CUR< xxxxx  CURv xxxxx
  418. X--------------------------------------------------------------------------*/
  419. Xvoid
  420. Xkeyset_display()
  421. X{
  422. Xint itmp;
  423. Xint itmp2;
  424. Xint clen1 = 0;
  425. Xchar cfmt1[32];
  426. Xint clen2 = 0;
  427. Xchar cfmt2[32];
  428. Xint clen3 = 0;
  429. Xchar cfmt3[32];
  430. Xchar cfmt4[32];
  431. XKDE *tkde;
  432. X
  433. X    if(!keyset_name[0])
  434. X    {
  435. X        keyset_init();
  436. X        ff(se,"   no key definition active\r\n\r\n");
  437. X        ff(se,"HOME - command prefix\r\n");
  438. X        ff(se,"BkTab  - redisplay receiver screen\r\n");
  439. X        ff(se,"cursor down - local shell in %s\r\n",curr_dir);
  440. X        fputs("\r\n",se);
  441. X    }
  442. X    else
  443. X    {
  444. X        for(itmp = 0; itmp < KDE_COUNT; itmp++)
  445. X        {
  446. X            tkde = &keyset_table[itmp];
  447. X            itmp2 = strlen(tkde->logical);
  448. X#if defined(__GNUC__) && !defined(GCC140)
  449. X            /*
  450. X             * do absolutely nothing except defeat optimization
  451. X             * see top of source; function is in ecuutil.c
  452. X             * GCC 1.40 fixed the bug
  453. X             */
  454. X            defeat_optimize_to_work_around_bug(&itmp);
  455. X#endif /* __GNUC__ */
  456. X            switch(itmp)
  457. X            {
  458. X                case KDEk_F1: case KDEk_F3: case KDEk_F5: case KDEk_F7:
  459. X                case KDEk_F9: case KDEk_F11:
  460. X                    if(clen1 < itmp2)
  461. X                        clen1 = itmp2;
  462. X                    break;
  463. X
  464. X                case KDEk_F2: case KDEk_F4: case KDEk_F6: case KDEk_F8:
  465. X                case KDEk_F10: case KDEk_F12:
  466. X                    if(clen2 < itmp2)
  467. X                        clen2 = itmp2;
  468. X                    break;
  469. X
  470. X                case KDEk_HOME: case KDEk_END: case KDEk_INS:
  471. X                case KDEk_CUU: case KDEk_CUL:
  472. X                    if(clen3 < itmp2)
  473. X                        clen3 = itmp2;
  474. X                    break;
  475. X
  476. X                case KDEk_InitStr:    /* initialization string excluded */
  477. X                    break;
  478. X            }
  479. X        }
  480. X        sprintf(cfmt1," %%-%d.%ds",clen1,clen1);
  481. X        sprintf(cfmt2," %%-%d.%ds",clen2,clen2);
  482. X        sprintf(cfmt3," %%-%d.%ds",clen3,clen3);
  483. X        strcpy(cfmt4," %s");
  484. X        ff(se,"   key definition: %s\r\n\r\n",keyset_name);
  485. X
  486. X        ffso(" F1  ");ff(se,cfmt1,keyset_table[KDEk_F1].logical);
  487. X        fputs("  ",se);
  488. X        ffso(" F2  ");ff(se,cfmt2,keyset_table[KDEk_F2].logical);
  489. X        fputs("  ",se);
  490. X        ffso(" Home ");ff(se,cfmt3,keyset_table[KDEk_HOME].logical);
  491. X        fputs("  ",se);
  492. X        ffso(" PgUp ");ff(se,cfmt4,keyset_table[KDEk_PGUP].logical);
  493. X        fputs("\r\n",se);
  494. X
  495. X        ffso(" F3  ");ff(se,cfmt1,keyset_table[KDEk_F3].logical);
  496. X        fputs("  ",se);
  497. X        ffso(" F4  ");ff(se,cfmt2,keyset_table[KDEk_F4].logical);
  498. X        fputs("  ",se);
  499. X        ffso(" End  ");ff(se,cfmt3,keyset_table[KDEk_END].logical);
  500. X        fputs("  ",se);
  501. X        ffso(" PgDn ");ff(se,cfmt4,keyset_table[KDEk_PGDN].logical);
  502. X        fputs("\r\n",se);
  503. X
  504. X        ffso(" F5  ");ff(se,cfmt1,keyset_table[KDEk_F5].logical);
  505. X        fputs("  ",se);
  506. X        ffso(" F6  ");ff(se,cfmt2,keyset_table[KDEk_F6].logical);
  507. X        fputs("  ",se);
  508. X        ffso(" Ins  ");ff(se,cfmt3,keyset_table[KDEk_INS].logical);
  509. X        fputs("  ",se);
  510. X        ffso(" CUR5 ");ff(se,cfmt4,keyset_table[KDEk_CU5].logical);
  511. X        fputs("\r\n",se);
  512. X
  513. X        ffso(" F7  ");ff(se,cfmt1,keyset_table[KDEk_F7].logical);
  514. X        fputs("  ",se);
  515. X        ffso(" F8  ");ff(se,cfmt2,keyset_table[KDEk_F8].logical);
  516. X        fputs("  ",se);
  517. X        ffso(" BkTab");ff(se,cfmt3,keyset_table[KDEk_BKTAB].logical);
  518. X        fputs("\r\n",se);
  519. X
  520. X        ffso(" F9  ");ff(se,cfmt1,keyset_table[KDEk_F9].logical);
  521. X        fputs("  ",se);
  522. X        ffso(" F10 ");ff(se,cfmt2,keyset_table[KDEk_F10].logical);
  523. X        fputs("  ",se);
  524. X        ffso(" CUR^ ");ff(se,cfmt3,keyset_table[KDEk_CUU].logical);
  525. X        fputs("  ",se);
  526. X        ffso(" CUR> ");ff(se,cfmt4,keyset_table[KDEk_CUR].logical);
  527. X        fputs("\r\n",se);
  528. X
  529. X        ffso(" F11 ");ff(se,cfmt1,keyset_table[KDEk_F11].logical);
  530. X        fputs("  ",se);
  531. X        ffso(" F12 ");ff(se,cfmt2,keyset_table[KDEk_F12].logical);
  532. X        fputs("  ",se);
  533. X        ffso(" CUR< ");ff(se,cfmt3,keyset_table[KDEk_CUL].logical);
  534. X        fputs("  ",se);
  535. X        ffso(" CURv ");ff(se,cfmt4,keyset_table[KDEk_CUD].logical);
  536. X        fputs("\r\n\r\n",se);
  537. X    }
  538. X
  539. X}    /* end of keyset_display */
  540. X
  541. X/* end of ecufkey.c */
  542. X/* vi: set tabstop=4 shiftwidth=4: */
  543. SHAR_EOF
  544. echo 'File ecufkey.c is complete' &&
  545. $TOUCH -am 0725125591 'ecufkey.c' &&
  546. chmod 0644 ecufkey.c ||
  547. echo 'restore of ecufkey.c failed'
  548. Wc_c="`wc -c < 'ecufkey.c'`"
  549. test 14071 -eq "$Wc_c" ||
  550.     echo 'ecufkey.c: original size 14071, current size' "$Wc_c"
  551. rm -f _shar_wnt_.tmp
  552. fi
  553. # ============= ecufkey.h ==============
  554. if test -f 'ecufkey.h' -a X"$1" != X"-c"; then
  555.     echo 'x - skipping ecufkey.h (File already exists)'
  556.     rm -f _shar_wnt_.tmp
  557. else
  558. > _shar_wnt_.tmp
  559. echo 'x - extracting ecufkey.h (Text)'
  560. sed 's/^X//' << 'SHAR_EOF' > 'ecufkey.h' &&
  561. X/*+-------------------------------------------------------------------------
  562. X    ecufkey.h -- AT XENIX/UNIX function key phrases
  563. X    wht@n4hgf.Mt-Park.GA.US
  564. X--------------------------------------------------------------------------*/
  565. X/*+:EDITS:*/
  566. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  567. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  568. X
  569. X/*
  570. X * indices to key mapping tables
  571. X *
  572. X * these are close to being magic numbers - don't change w/o looking
  573. X * at KDEk_to_XF in ecutty.c
  574. X */
  575. X#define KDEk_F1            0
  576. X#define KDEk_F2            1
  577. X#define KDEk_F3            2
  578. X#define KDEk_F4            3
  579. X#define KDEk_F5            4
  580. X#define KDEk_F6            5
  581. X#define KDEk_F7            6
  582. X#define KDEk_F8            7
  583. X#define KDEk_F9            8
  584. X#define KDEk_F10        9
  585. X#define KDEk_F11        10
  586. X#define KDEk_F12        11
  587. X#define KDEk_CUU        12
  588. X#define KDEk_CUD        13
  589. X#define KDEk_CUL        14
  590. X#define KDEk_CUR        15
  591. X#define KDEk_CU5        16
  592. X#define KDEk_PGUP        17
  593. X#define KDEk_PGDN        18
  594. X#define KDEk_END        19
  595. X#define KDEk_INS        20
  596. X#define KDEk_BKTAB        21
  597. X#define KDEk_HOME        22
  598. X#define KDEk_InitStr    23        /* initialization string kludge */
  599. X
  600. X#define KDE_COUNT        24
  601. X
  602. X#define KDE_LOGICAL_MAX        12
  603. X#define KDE_OUTSTR_MAX        32
  604. X
  605. X#define KDEt_NAME        1
  606. X#define KDEt_ENTRY        2
  607. X#define KDEt_COMMENT    3
  608. X#define KDEt_EOF        4
  609. X
  610. Xtypedef struct kde
  611. X{
  612. X    char logical[KDE_LOGICAL_MAX];
  613. X    uchar KDEt;
  614. X    char count;
  615. X    char str[KDE_OUTSTR_MAX];
  616. X}    KDE;
  617. X
  618. X/* when an count is not a count but an action: */
  619. X#define KACT_COMMAND            -1
  620. X#define KACT_LOCAL_SHELL        -2
  621. X#define KACT_REDISPLAY            -3
  622. X
  623. Xtypedef struct XF_KDE_NAME
  624. X{
  625. X    uchar xf;
  626. X    char kde;
  627. X    char *name;
  628. X}    XF_KDE_NAME;
  629. X
  630. X/* vi: set tabstop=4 shiftwidth=4: */
  631. X/* end of ecufkey.h */
  632. SHAR_EOF
  633. $TOUCH -am 0725125591 'ecufkey.h' &&
  634. chmod 0644 ecufkey.h ||
  635. echo 'restore of ecufkey.h failed'
  636. Wc_c="`wc -c < 'ecufkey.h'`"
  637. test 1591 -eq "$Wc_c" ||
  638.     echo 'ecufkey.h: original size 1591, current size' "$Wc_c"
  639. rm -f _shar_wnt_.tmp
  640. fi
  641. # ============= ecufork.c ==============
  642. if test -f 'ecufork.c' -a X"$1" != X"-c"; then
  643.     echo 'x - skipping ecufork.c (File already exists)'
  644.     rm -f _shar_wnt_.tmp
  645. else
  646. > _shar_wnt_.tmp
  647. echo 'x - extracting ecufork.c (Text)'
  648. sed 's/^X//' << 'SHAR_EOF' > 'ecufork.c' &&
  649. X/*+-------------------------------------------------------------------------
  650. X    ecufork.c -- ecu spawning ground
  651. X    wht@n4hgf.Mt-Park.GA.US
  652. X
  653. X  Defined functions:
  654. X    exec_cmd(cmdstr)
  655. X    expand_wildcard_list(wild,&expcmd)
  656. X    find_executable(progname)
  657. X    is_executable(progname)
  658. X    shell(shellcmd)
  659. X    smart_fork()
  660. X
  661. X--------------------------------------------------------------------------*/
  662. X/*+:EDITS:*/
  663. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  664. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  665. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  666. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  667. X
  668. X#include "ecu.h"
  669. X#include "ecufork.h"
  670. X
  671. Xextern int rcvr_pid;
  672. Xextern int last_child_wait_status;
  673. Xextern int last_child_wait_pid;
  674. X
  675. X/*+-------------------------------------------------------------------------
  676. X    smart_fork()
  677. X--------------------------------------------------------------------------*/
  678. Xint
  679. Xsmart_fork()
  680. X{
  681. Xregister int count = 5;
  682. Xregister int pid;
  683. X
  684. X    while(count--)
  685. X    {
  686. X        if((pid = fork()) >= 0)
  687. X            return(pid);
  688. X        if(count)
  689. X            nap(40L);
  690. X    }
  691. X    return(-1);
  692. X}    /* end of smart_fork */
  693. X
  694. X/*+-----------------------------------------------------------------------
  695. X    shell(shellcmd)
  696. X
  697. X  param 'shellcmd' is a shell command prefixed with either
  698. X  a '!', '$', '>' character.
  699. X
  700. X  '!' causes the command to run as a normal subshell of a process.
  701. X  '$' causes the communications line to be stdin and stdout
  702. X      for the spawned shell
  703. X  '>' causes spawned shell to receive exactly sames files as ecu
  704. X------------------------------------------------------------------------*/
  705. Xvoid
  706. Xshell(shellcmd)
  707. Xchar *shellcmd;
  708. X{
  709. Xregister shellpid;
  710. Xregister itmp;
  711. Xregister char *cptr;
  712. X#if defined(FORK_DEBUG)
  713. Xchar s40[40];
  714. X#endif
  715. Xint wait_status;
  716. X
  717. Xint rcvr_alive = (rcvr_pid > 0);
  718. Xchar *getenv();
  719. X
  720. X    if(rcvr_alive)
  721. X        kill_rcvr_process(SIGUSR1);        /* stop receiver process gracefully */
  722. X
  723. X    signal(SIGINT,SIG_IGN);
  724. X    signal(SIGTERM,SIG_IGN);
  725. X    signal(SIGUSR1,SIG_IGN);
  726. X    signal(SIGUSR2,SIG_IGN);
  727. X    signal(SIGCLD,SIG_DFL);
  728. X
  729. X    if((shellpid = smart_fork()) < 0)
  730. X    {
  731. X        ff(se,"Cannot fork\r\n");
  732. X        if(rcvr_alive)
  733. X            start_rcvr_process(1);
  734. X        xmtr_signals();
  735. X        return;
  736. X    }
  737. X
  738. X    ttymode(0);                   /* set canonical tty mode */
  739. X    if(shellpid == 0)            /* we are the spawned (going to call shell) */
  740. X    {
  741. X        if(*shellcmd != '>')    /* '>' prefix means leave fd's alone! */
  742. X        {
  743. X            /* Hook-up our "standard output" to either the tty or
  744. X             * the line as appropriate for '!' or '$' */
  745. X            close(TTYOUT);
  746. X            fcntl(((*shellcmd == '$') ? shm->Liofd : TTYERR),F_DUPFD,TTYOUT);
  747. X            if(*shellcmd == '$')
  748. X            {
  749. X                close(TTYIN);
  750. X                fcntl(shm->Liofd,F_DUPFD,TTYIN);
  751. X            }
  752. X            close(shm->Liofd);
  753. X        }
  754. X
  755. X        child_signals();        /* signals for child */
  756. X
  757. X        if(*shellcmd == '!')
  758. X        {
  759. X            cptr = getenv("SHELL");
  760. X            if(cptr == (char *)0)
  761. X                cptr = "/bin/csh";
  762. X        }
  763. X        else
  764. X            cptr = "/bin/sh";
  765. X
  766. X        shellcmd++;
  767. X        child_signals();
  768. X        if(ulindex(cptr,"csh") > -1)
  769. X        {
  770. X            if(*shellcmd == '\0')
  771. X                execl(cptr,"csh",(char *)0);
  772. X            else
  773. X                execl(cptr,"csh","-c",shellcmd,(char *)0);
  774. X        }
  775. X        else
  776. X        {
  777. X            if(*shellcmd == '\0')
  778. X                execl(cptr,"sh",(char *)0);
  779. X            else
  780. X                execl(cptr,"sh","-c",shellcmd,(char *)0);
  781. X        }
  782. X
  783. X        ff(se,"cannot execute %s\r\n",cptr);    /* should not get here */
  784. X        _exit(255);                                /* end of spawned process */
  785. X    }    /* end of if child process */
  786. X
  787. X#if defined(FORK_DEBUG)
  788. X    sprintf(s40,"DEBUG fork shell pid %d",shellpid);
  789. X    ecu_log_event(getpid(),s40); /* shell */
  790. X#endif
  791. X
  792. X    while(((itmp = wait(&wait_status)) != shellpid) && (itmp != -1))
  793. X        ;
  794. X    last_child_wait_status = wait_status;
  795. X    last_child_wait_pid = shellpid;
  796. X
  797. X    xmtr_signals();            /* restore standard xmtr signals */
  798. X    ttymode(1);                /* control tty back to raw mode */
  799. X
  800. X/* any comm program will probably doodle with the line characteristics. */
  801. X/* we want to make sure they are restored to normal */
  802. X    lreset_ksr();            /* restore comm line params */
  803. X
  804. X    if(rcvr_alive)
  805. X        start_rcvr_process(1);
  806. X
  807. X}    /* end of shell */
  808. X
  809. X/*+-------------------------------------------------------------------------
  810. X    is_executable(progname)
  811. X--------------------------------------------------------------------------*/
  812. Xis_executable(progname)
  813. Xchar *progname;
  814. X{
  815. Xstruct stat ss;
  816. X
  817. X    if(stat(progname,&ss) < 0)            /* if cannot stat, flunk */
  818. X        return(0);
  819. X    if((ss.st_mode & 0111) == 0)        /* if no --x--x--x, flunk */
  820. X        return(0);
  821. X    return(1);    /* whew, this OUGHT to work */
  822. X
  823. X}    /* end of is_executable */
  824. X
  825. X/*+-------------------------------------------------------------------------
  826. X    find_executable(progname)
  827. XPATH=':/usr/wht/bin:/bin:/usr/bin:/usr/wht/bin:/etc/tuckerware' len=56
  828. X--------------------------------------------------------------------------*/
  829. Xchar *
  830. Xfind_executable(progname)
  831. Xchar *progname;
  832. X{
  833. Xregister itmp;
  834. Xstatic char *path_buf = (char *)0;
  835. X#define PATHNAME_QUAN 32
  836. Xstatic char *path_name[PATHNAME_QUAN + 1];
  837. Xstatic char rtn_path[256];
  838. Xstatic int path_count = 0;
  839. Xchar *cptr;
  840. Xchar *getenv();
  841. X
  842. X    if(path_buf == (char *)0)
  843. X    {
  844. X        if((cptr = getenv("PATH")) == (char *)0)
  845. X            return(cptr);
  846. X        if(!(path_buf = malloc(strlen(cptr) + 1)))
  847. X            return((char *)0);
  848. X        strcpy(path_buf,cptr);
  849. X        path_name[PATHNAME_QUAN + 1] = (char *)0;
  850. X        cptr = path_buf;
  851. X        for(path_count = 0; path_count < PATHNAME_QUAN; path_count++)
  852. X        {
  853. X            if(*cptr == 0)
  854. X                break;
  855. X            path_name[path_count] = cptr;
  856. X            while((*cptr != ':') && (*cptr != 0))
  857. X                cptr++;
  858. X            if(*cptr == ':')
  859. X                *cptr++ = 0;
  860. X        }
  861. X    }    /* end of get and process path env variable */
  862. X
  863. X/* look for executable */
  864. X    for(itmp = 0; itmp < path_count; itmp++)
  865. X    {
  866. X        if(*path_name[itmp] == 0)    /* if null path (./) */
  867. X            strcpy(rtn_path,"./");
  868. X        else
  869. X            sprintf(rtn_path,"%s/",path_name[itmp]);
  870. X        strcat(rtn_path,progname);
  871. X        if(is_executable(rtn_path))
  872. X            return(rtn_path);
  873. X    }
  874. X    return((char *)0);
  875. X}    /* end of find_executable */
  876. X
  877. X/*+-------------------------------------------------------------------------
  878. X    exec_cmd(cmdstr) - execute an arbitrary program with arguments
  879. Xkills rcvr process if alive and restarts it when done if was alive
  880. X--------------------------------------------------------------------------*/
  881. Xexec_cmd(cmdstr)
  882. Xchar *cmdstr;
  883. X{
  884. Xchar *cmdpath;
  885. X#define MAX_EXEC_ARG 512
  886. Xchar *cmdargv[MAX_EXEC_ARG];
  887. Xint itmp;
  888. Xint execpid;
  889. Xint rcvr_alive = (rcvr_pid > 0);
  890. Xint old_ttymode = get_ttymode();
  891. Xint wait_status = 0;
  892. Xchar *strrchr();
  893. X
  894. X#if defined(FORK_DEBUG)
  895. Xchar s80[80];
  896. X    strcpy(s80,"DEBUG exec ");
  897. X    strncat(s80,cmdstr,sizeof(s80)-12);
  898. X    s80[sizeof(s80)-12] = 0;
  899. X    ecu_log_event(getpid(),s80);
  900. X#endif
  901. X
  902. X    build_arg_array(cmdstr,cmdargv,MAX_EXEC_ARG,&itmp);
  903. X    if(itmp == MAX_EXEC_ARG)
  904. X    {
  905. X        ff(se,"Too many arguments to command\r\n");
  906. X        return(-1);
  907. X    }
  908. X    else if(!itmp)
  909. X    {
  910. X        ff(se,"null command\r\n");
  911. X        return(-1);
  912. X    }
  913. X
  914. X    if(*cmdargv[0] == '/')
  915. X    {
  916. X        cmdpath = cmdargv[0];
  917. X        cmdargv[0] = strrchr(cmdargv[0],'/') + 1;
  918. X    }
  919. X    else
  920. X    {
  921. X        if((cmdpath = find_executable(cmdargv[0])) == (char *)0)
  922. X        {
  923. X            ff(se,"Cannot find %s\r\n",cmdargv[0]);
  924. X            return(-1);
  925. X        }
  926. X    }
  927. X
  928. X    if(rcvr_alive)
  929. X        kill_rcvr_process(SIGUSR1);        /* stop receiver process gracefully */
  930. X
  931. X/* this code executed by the father (forking) process */
  932. X/* wait on death of child (morbid in life, but ok here) */
  933. X
  934. X    signal(SIGINT,SIG_IGN);
  935. X    signal(SIGTERM,SIG_IGN);
  936. X    signal(SIGUSR1,SIG_IGN);
  937. X    signal(SIGUSR2,SIG_IGN);
  938. X    signal(SIGCLD,SIG_DFL);
  939. X
  940. X    if((execpid = smart_fork()) < 0)
  941. X    {
  942. X        ff(se,"Cannot fork\r\n");
  943. X        if(rcvr_alive)
  944. X            start_rcvr_process(1);
  945. X        xmtr_signals();
  946. X        return(-1);
  947. X    }
  948. X
  949. X    if(execpid == 0)            /* we are the spawned (going to call exec) */
  950. X    {
  951. X        ttymode(0);               /* set canonical tty mode */
  952. X        child_signals();
  953. X        execv(cmdpath,cmdargv);
  954. X        perror(cmdpath);
  955. X        exit(255);                /* end of spawned process */
  956. X    }    /* end of if child process */
  957. X
  958. X    wait_status = 0;
  959. X    while(((itmp = wait(&wait_status)) != execpid) && (itmp != -1))
  960. X        ;
  961. X    last_child_wait_status = wait_status;
  962. X    last_child_wait_pid = execpid;
  963. X
  964. X/* resume our normally scheduled program */
  965. X    lreset_ksr();                /* restore comm line params */
  966. X    ttymode(old_ttymode);        /* control tty back to original */
  967. X    if(rcvr_alive)
  968. X        start_rcvr_process(1);
  969. X    xmtr_signals();
  970. X    return(last_child_wait_status);
  971. X
  972. X}    /* end of exec_cmd */
  973. X
  974. X/*+-------------------------------------------------------------------------
  975. X    expand_wildcard_list(wild,&expcmd)
  976. X
  977. Xcalled with 'foo <wildcardlist>' for command expansion prior to exec()
  978. X         or '<wildcardlist>' to expand a list of files.
  979. X
  980. XIf called with 'foo'-style wild, anything you want to protect from csh 
  981. Xglobbing or other interpretation must be properly protected (quoted) --
  982. XAND quoting will be removed one level by the csh.
  983. X
  984. Xif return 0, wild has been expanded, expcmd must be free()'d when done
  985. Xif return -1, error, expcmd has error message (static message: DO NOT FREE)
  986. X--------------------------------------------------------------------------*/
  987. Xexpand_wildcard_list(wild,expcmd)
  988. Xchar *wild;
  989. Xchar **expcmd;
  990. X{
  991. Xregister char *cptr;
  992. X#define P_READ 0
  993. X#define P_WRITE 1
  994. Xint pipe_pid;
  995. Xint stdout_pipe[2];
  996. Xint stderr_pipe[2];
  997. Xint count;
  998. Xint expcmd_size = 0;
  999. Xint itmp;
  1000. Xint wait_status;
  1001. Xint rcvr_alive = (rcvr_pid > 0);
  1002. XFILE *fp_pipe = (FILE *)0;
  1003. Xchar *echo_cmd;
  1004. Xstatic char s132[132];
  1005. Xextern int errno;
  1006. Xextern char *sys_errlist[];
  1007. Xchar *strchr();
  1008. Xstatic char *pipe_err_msg = "system error: no pipe";
  1009. Xstatic char *mem_err_msg = "system error: no memory";
  1010. X
  1011. X    if(strchr(wild,'<') || strchr(wild,'>') || strchr(wild,'&'))
  1012. X    {
  1013. X        *expcmd = "illegal characters: '<', '>' or '&'";
  1014. X        return(-1);
  1015. X    }
  1016. X
  1017. X    if(pipe(stdout_pipe) < 0)
  1018. X    {
  1019. X        *expcmd = pipe_err_msg;
  1020. X        return(-1);
  1021. X    }
  1022. X    if(pipe(stderr_pipe) < 0)
  1023. X    {
  1024. X        close(stdout_pipe[P_READ]);
  1025. X        close(stdout_pipe[P_WRITE]);
  1026. X        *expcmd = pipe_err_msg;
  1027. X        return(-1);
  1028. X    }
  1029. X    if(!(echo_cmd = malloc(strlen(wild) + 10)))
  1030. X    {
  1031. X        close(stdout_pipe[P_READ]);
  1032. X        close(stdout_pipe[P_WRITE]);
  1033. X        close(stderr_pipe[P_READ]);
  1034. X        close(stderr_pipe[P_WRITE]);
  1035. X        *expcmd = mem_err_msg;
  1036. X        return(-1);
  1037. X    }
  1038. X
  1039. X    strcpy(echo_cmd,"echo ");
  1040. X    strcat(echo_cmd,wild);
  1041. X
  1042. X    if(rcvr_alive)
  1043. X        kill_rcvr_process(SIGUSR1);        /* stop receiver process gracefully */
  1044. X
  1045. X    signal(SIGINT,SIG_IGN);
  1046. X    signal(SIGTERM,SIG_IGN);
  1047. X    signal(SIGUSR1,SIG_IGN);
  1048. X    signal(SIGUSR2,SIG_IGN);
  1049. X    signal(SIGCLD,SIG_DFL);
  1050. X
  1051. X    if((pipe_pid = smart_fork()) == 0)
  1052. X    {
  1053. X    int null = open("/dev/null",O_WRONLY,0);
  1054. X
  1055. X        close(stdout_pipe[P_READ]);
  1056. X        close(TTYOUT);
  1057. X        dup(stdout_pipe[P_WRITE]);
  1058. X        close(stdout_pipe[P_WRITE]);
  1059. X        close(TTYERR);
  1060. X        dup(stderr_pipe[P_WRITE]);
  1061. X        close(stderr_pipe[P_WRITE]);
  1062. X        close(null);
  1063. X        child_signals();
  1064. X        execl("/bin/csh","csh","-e","-f","-c",echo_cmd,(char *)0);
  1065. X        _exit(255);
  1066. X    }
  1067. X
  1068. X#if defined(FORK_DEBUG)
  1069. X    sprintf(s132,"DEBUG expand pid %d",pipe_pid);
  1070. X    ecu_log_event(getpid(),s132);        /* expand_wildcard_list */
  1071. X#endif
  1072. X
  1073. X    free(echo_cmd);
  1074. X
  1075. X    close(stdout_pipe[P_WRITE]);
  1076. X    close(stderr_pipe[P_WRITE]);
  1077. X    if(pipe_pid == -1)
  1078. X    {
  1079. X        close(stdout_pipe[P_READ]);
  1080. X        close(stderr_pipe[P_READ]);
  1081. X        *expcmd = "could not fork";
  1082. X        if(rcvr_alive)
  1083. X            start_rcvr_process(0);
  1084. X        xmtr_signals();
  1085. X        return(-1);
  1086. X    }
  1087. X
  1088. X    if(!(*expcmd = malloc(expcmd_size = 5120)))
  1089. X    {
  1090. X        close(stdout_pipe[P_READ]);
  1091. X        close(stderr_pipe[P_READ]);
  1092. X        kill(pipe_pid,SIGKILL);
  1093. X        *expcmd = mem_err_msg;
  1094. X        if(rcvr_alive)
  1095. X            start_rcvr_process(0);
  1096. X        xmtr_signals();
  1097. X        return(-1);
  1098. X    }
  1099. X
  1100. X    if(!(fp_pipe = fdopen(stdout_pipe[P_READ],"r")) ||
  1101. X        ((count = fread(*expcmd,1,expcmd_size,fp_pipe)) < 0))
  1102. X    {
  1103. X            free(*expcmd);
  1104. X            kill(pipe_pid,SIGKILL);
  1105. X            close(stdout_pipe[P_READ]);
  1106. X            close(stderr_pipe[P_READ]);
  1107. X            *expcmd = "error reading wild list expansion";
  1108. X            if(rcvr_alive)
  1109. X                start_rcvr_process(0);
  1110. X            xmtr_signals();
  1111. X            return(-1);
  1112. X    }
  1113. X
  1114. X    /*
  1115. X     * make sure stdout is closed
  1116. X     */
  1117. X    if(fp_pipe)
  1118. X        fclose(fp_pipe);
  1119. X    close(stdout_pipe[P_READ]);
  1120. X
  1121. X    /*
  1122. X     * if no expansion, read stderr to find out why
  1123. X     */
  1124. X    if(!count)
  1125. X    {
  1126. X        free(*expcmd);
  1127. X        count = read(stderr_pipe[P_READ],s132,sizeof(s132) - 1);
  1128. X        if(count < 0)
  1129. X            strcpy(s132,sys_errlist[errno]);
  1130. X        else
  1131. X            s132[count] = 0;
  1132. X        if(s132[count - 1] == '\n')
  1133. X            s132[count - 1] = 0;
  1134. X        close(stderr_pipe[P_READ]);
  1135. X        if(strncmp(s132,"echo: ",6))
  1136. X            *expcmd = s132;
  1137. X        else
  1138. X            *expcmd = s132 + 6;
  1139. X        if(rcvr_alive)
  1140. X            start_rcvr_process(0);
  1141. X        return(-1);
  1142. X    }
  1143. X
  1144. X    /*
  1145. X     * place trailing null
  1146. X     * kill trailing new line
  1147. X     */
  1148. X    if(count)
  1149. X    {
  1150. X        cptr = (*expcmd) + count;
  1151. X        *cptr-- = 0;
  1152. X        if(*cptr == '\n')
  1153. X            *cptr = 0;
  1154. X    }
  1155. X
  1156. X    /*
  1157. X     * clean up zombie
  1158. X     */
  1159. X    wait_status = 0;
  1160. X    while(((itmp = wait(&wait_status)) != pipe_pid) && (itmp != -1))
  1161. X        ;
  1162. X
  1163. X    xmtr_signals();
  1164. X
  1165. X    /*
  1166. X     * if bad termination status, read stderr
  1167. X     */
  1168. X    if(wait_status)
  1169. X    {
  1170. X        free(*expcmd);
  1171. X        count = read(stderr_pipe[P_READ],s132,sizeof(s132) - 1);
  1172. X        if(count < 0)
  1173. X            strcpy(s132,sys_errlist[errno]);
  1174. X        else
  1175. X            s132[count] = 0;
  1176. X        if(s132[count - 1] == '\n')
  1177. X            s132[count - 1] = 0;
  1178. X        close(stderr_pipe[P_READ]);
  1179. X        if(strncmp(s132,"echo: ",6))
  1180. X            *expcmd = s132;
  1181. X        else
  1182. X            *expcmd = s132 + 6;
  1183. X        if(rcvr_alive)
  1184. X            start_rcvr_process(0);
  1185. X        return(-1);
  1186. X    }
  1187. X    close(stderr_pipe[P_READ]);
  1188. X
  1189. X    /*
  1190. X     * whew: we have (I think) a file list expansion
  1191. X     */
  1192. X    if(rcvr_alive)
  1193. X        start_rcvr_process(0);
  1194. X
  1195. X    return(0);
  1196. X}    /* end of expand_wildcard_list */
  1197. X/* vi: set tabstop=4 shiftwidth=4: */
  1198. SHAR_EOF
  1199. $TOUCH -am 0725125591 'ecufork.c' &&
  1200. chmod 0644 ecufork.c ||
  1201. echo 'restore of ecufork.c failed'
  1202. Wc_c="`wc -c < 'ecufork.c'`"
  1203. test 12907 -eq "$Wc_c" ||
  1204.     echo 'ecufork.c: original size 12907, current size' "$Wc_c"
  1205. rm -f _shar_wnt_.tmp
  1206. fi
  1207. # ============= ecufork.h ==============
  1208. if test -f 'ecufork.h' -a X"$1" != X"-c"; then
  1209.     echo 'x - skipping ecufork.h (File already exists)'
  1210.     rm -f _shar_wnt_.tmp
  1211. else
  1212. > _shar_wnt_.tmp
  1213. echo 'x - extracting ecufork.h (Text)'
  1214. sed 's/^X//' << 'SHAR_EOF' > 'ecufork.h' &&
  1215. X/*+-------------------------------------------------------------------------
  1216. X    ecufork.h 
  1217. X    wht@n4hgf.Mt-Park.GA.US
  1218. X
  1219. Xfor now just vehicle for deciding whether or not to debug fork/waits
  1220. X--------------------------------------------------------------------------*/
  1221. X/*+:EDITS:*/
  1222. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  1223. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1224. X
  1225. X/* #define FORK_DEBUG */
  1226. X/* vi: set tabstop=4 shiftwidth=4: */
  1227. SHAR_EOF
  1228. $TOUCH -am 0725125591 'ecufork.h' &&
  1229. chmod 0644 ecufork.h ||
  1230. echo 'restore of ecufork.h failed'
  1231. Wc_c="`wc -c < 'ecufork.h'`"
  1232. test 452 -eq "$Wc_c" ||
  1233.     echo 'ecufork.h: original size 452, current size' "$Wc_c"
  1234. rm -f _shar_wnt_.tmp
  1235. fi
  1236. # ============= ecuicmaux.c ==============
  1237. if test -f 'ecuicmaux.c' -a X"$1" != X"-c"; then
  1238.     echo 'x - skipping ecuicmaux.c (File already exists)'
  1239.     rm -f _shar_wnt_.tmp
  1240. else
  1241. > _shar_wnt_.tmp
  1242. echo 'x - extracting ecuicmaux.c (Text)'
  1243. sed 's/^X//' << 'SHAR_EOF' > 'ecuicmaux.c' &&
  1244. X/*+-------------------------------------------------------------------------
  1245. X    ecuicmaux.c -- ecuicmd.c auxiliary functions
  1246. X    wht@n4hgf.Mt-Park.GA.US
  1247. X
  1248. X  Defined functions:
  1249. X    display_ascii_names()
  1250. X    nlin_nlout_control(token,narg,arg)
  1251. X    icmd_conversion(token,narg,arg)
  1252. X    icmd_log(token,narg,arg)
  1253. X
  1254. X--------------------------------------------------------------------------*/
  1255. X/*+:EDITS:*/
  1256. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  1257. X/*:07-04-1991-20:03-wht@n4hgf-make pcmd_log */
  1258. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1259. X
  1260. X#include "ecu.h"
  1261. X#include "ecuerror.h"
  1262. X#include "ecucmd.h"
  1263. X#include "esd.h"
  1264. X
  1265. Xextern int rcvr_pid;
  1266. X
  1267. Xint rcvr_log = 0;                /* if non-zero, logging rcvd data */
  1268. Xchar rcvr_log_file[256];        /* log filename */
  1269. Xint rcvr_log_gen_title = 0;        /* gen log header on next open (rcvr process) */
  1270. XFILE *rcvr_log_fp = (FILE *)0;    /* rcvr log file */
  1271. Xint rcvr_log_append = 1;
  1272. Xint rcvr_log_raw = 0;
  1273. Xint rcvr_log_flusheach = 0;
  1274. X
  1275. X/*+-----------------------------------------------------------------------
  1276. X    display_ascii_names()
  1277. X------------------------------------------------------------------------*/
  1278. Xvoid
  1279. Xdisplay_ascii_names()
  1280. X{
  1281. Xregister intval;
  1282. X
  1283. X    for(intval = 0; intval < 32; intval++)
  1284. X    {
  1285. X        ff(se,"%s %3d %03o %02x ^%c | ",hex_to_ascii_name((intval)),
  1286. X                (intval),(intval),(intval),(intval) |0x40);
  1287. X        ff(se,"    %3d %03o %02x  %c | ",
  1288. X                intval+32,intval+32,intval+32,intval+32);
  1289. X        ff(se,"    %3d %03o %02x  %c | ",
  1290. X                intval+64,intval+64,intval+64,intval+64);
  1291. X        if(intval != 31)
  1292. X        {
  1293. X            ff(se,"    %3d %03o %02x  %c\r\n",
  1294. X                    intval+96,intval+96,intval+96,intval+96);
  1295. X        }
  1296. X        else
  1297. X        {
  1298. X            ff(se,"    %3d %03o %02x  ^?\r\n",
  1299. X                    intval+96,intval+96,intval+96);
  1300. X        }
  1301. X    }
  1302. X
  1303. X}    /* end of display_ascii_names */
  1304. X
  1305. X/*+-------------------------------------------------------------------------
  1306. X    icmd_conversion(token,narg,arg)
  1307. X--------------------------------------------------------------------------*/
  1308. Xvoid
  1309. Xicmd_conversion(token,narg,arg)
  1310. Xint token;
  1311. Xint narg;
  1312. Xchar **arg;
  1313. X{
  1314. Xregister itmp;
  1315. X
  1316. X    switch(token)
  1317. X    {
  1318. X    case CTxa:
  1319. X    case CToa:
  1320. X    case CTda:
  1321. X        if(narg > 1)
  1322. X        {
  1323. X        int result;
  1324. X        char format[4];
  1325. X            sprintf(format,"%%%c",to_lower(*arg[0]));
  1326. X            if(sscanf(arg[1],format,&result) == 0)
  1327. X            {
  1328. X                ff(se,"  invalid argument\r\n");
  1329. X                return;
  1330. X            }
  1331. X            result &= 0xFF;
  1332. X            if(result == ' ')
  1333. X                ff(se," == ' ' 0x20\r\n",make_char_graphic(result,1));
  1334. X            else
  1335. X                ff(se," == %s\r\n",make_char_graphic(result,1));
  1336. X        }
  1337. X        else
  1338. X        {
  1339. X            ff(se,"\r\n");
  1340. X            display_ascii_names();
  1341. X        }
  1342. X        break;
  1343. X    case CTax:
  1344. X        if(arg[1] == (char *)0)
  1345. X        {
  1346. X            ff(se,"\r\n");
  1347. X            display_ascii_names();
  1348. X            break;
  1349. X        }
  1350. X        switch(strlen(arg[1]))
  1351. X        {
  1352. X            case 1:
  1353. X                ff(se," == 0x%02x\r\n",*arg[1]);
  1354. X                break;
  1355. X            case 2:
  1356. X                if(*arg[1] == '^')
  1357. X                {
  1358. X                    itmp = to_upper(*(arg[1] + 1));
  1359. X                    if((itmp < '@') || (itmp > '_'))
  1360. X                    {
  1361. X                        ff(se,"  not a valid control character\r\n");
  1362. X                        return;
  1363. X                    }
  1364. X                    itmp &= 0x1F;
  1365. X                    ff(se," == 0x%02x %s\r\n",itmp,make_char_graphic(itmp,1));
  1366. X                    break;
  1367. X                }    /* else fall thru */
  1368. X            case 3:
  1369. X                if((itmp = ascii_name_to_hex(arg[1])) > -1)
  1370. X                {
  1371. X                    ff(se," == 0x%02x %s\r\n",itmp,make_char_graphic(itmp,1));
  1372. X                    break;
  1373. X                }    /* else fall thru */
  1374. X            default:
  1375. X                ff(se,"  invalid ... examples of valid parameters:\r\n");
  1376. X                ff(se,"        ^A ETX  or  printable character\r\n");
  1377. X                break;
  1378. X        }
  1379. X        break;
  1380. X    default:
  1381. X        ff(se,"  invalid command\r\n");
  1382. X    }
  1383. X}    /* end of icmd_conversion */
  1384. X
  1385. X/*+-------------------------------------------------------------------------
  1386. X    rcvr_log_control(token,narg,arg)
  1387. X--------------------------------------------------------------------------*/
  1388. Xint
  1389. Xrcvr_log_control(token,narg,arg)
  1390. Xint token;
  1391. Xint narg;
  1392. Xchar **arg;
  1393. X{
  1394. Xregister itmp;
  1395. Xregister itmp2;
  1396. Xextern int proc_level;
  1397. Xextern int proctrace;
  1398. X#if defined(M_XENIX) || defined(M_UNIX)
  1399. Xchar *lparg = "/dev/lp1";
  1400. X#endif
  1401. X
  1402. X    switch(token)
  1403. X    {
  1404. X    case CTloff:
  1405. X        goto LOG_OFF;
  1406. X        break;
  1407. X
  1408. X#if defined(M_XENIX) || defined(M_UNIX)
  1409. X    case CTllp:
  1410. X        narg = 1;
  1411. X        arg = &lparg;
  1412. X        /* fall thru */
  1413. X#endif
  1414. X
  1415. X    case CTlog:
  1416. X        if(narg > 1)
  1417. X        {
  1418. X            if(minunique("off",arg[1],3))
  1419. X            {
  1420. XLOG_OFF:
  1421. X                shmx_set_rcvr_log("",0,0,0);
  1422. X                rcvr_log = 0;
  1423. X                rcvr_log_file[0] = 0;
  1424. X                return(0);
  1425. X            }
  1426. X/* turning logging on */
  1427. X            itmp2 = -1;
  1428. X            rcvr_log_append = 1;
  1429. X            rcvr_log_raw = 0;
  1430. X            for(itmp = 1; itmp < narg; itmp++)
  1431. X            {
  1432. X                if(*arg[itmp] == '-')
  1433. X                {
  1434. X                    switch(arg[itmp][1])
  1435. X                    {
  1436. X                        case 's': rcvr_log_append = 0; break;
  1437. X                        case 'r': rcvr_log_raw = 1; break;
  1438. X                        case 'f': rcvr_log_flusheach = 1; break;
  1439. X                        default:
  1440. X                            pprintf("unrecognized switch -%c\n",arg[itmp][1]);
  1441. X                            log_cmd_usage();
  1442. X                        return(eFATAL_ALREADY);
  1443. X                    }
  1444. X                }
  1445. X                else
  1446. X                {
  1447. X                    if(itmp2 > 0)
  1448. X                    {
  1449. X                        pputs("too many arguments\n");
  1450. X                        log_cmd_usage();
  1451. X                        return(eFATAL_ALREADY);
  1452. X                    }
  1453. X                    itmp2 = itmp;
  1454. X                }
  1455. X            }
  1456. X            if(itmp2 < 0)
  1457. X            {
  1458. X                pputs("no log file name specified\n");
  1459. X                log_cmd_usage();
  1460. X                return(eFATAL_ALREADY);
  1461. X            }
  1462. X            if(arg[itmp2][0] != '/')    /* if log file not full path, ... */
  1463. X            {                            /* ... supply current directory */
  1464. X                get_curr_dir(rcvr_log_file,
  1465. X                    sizeof(rcvr_log_file) - strlen(arg[itmp2]) - 2);
  1466. X                strcat(rcvr_log_file,"/");
  1467. X                strcat(rcvr_log_file,arg[itmp2]);
  1468. X            }
  1469. X            else
  1470. X                strcpy(rcvr_log_file,arg[itmp2]);
  1471. X
  1472. X            /* try to open the file if we can */
  1473. X            rcvr_log_fp = fopen(rcvr_log_file,"a");
  1474. X            if(rcvr_log_fp)        /* if success */
  1475. X            {
  1476. X                fclose(rcvr_log_fp);
  1477. X                rcvr_log_fp = NULL;
  1478. X                rcvr_log = 1;
  1479. X                shmx_set_rcvr_log(rcvr_log_file,rcvr_log_append,rcvr_log_raw,
  1480. X                    rcvr_log_flusheach);
  1481. X            }
  1482. X            else        /* xmtr() could not open file */
  1483. X            {
  1484. X                pputs("could not open ");
  1485. X                pperror(rcvr_log_file);
  1486. X                return(eFATAL_ALREADY);
  1487. X            }
  1488. X            rcvr_log_append = 1;
  1489. X        }    /* end of if argument to command */
  1490. X
  1491. X        if(rcvr_log && (!proc_level || proctrace))
  1492. X        {
  1493. X            pprintf("\n%sing received %s text to\n%s\n",
  1494. X                (rcvr_log_append) ? "append" : "writ",
  1495. X                (rcvr_log_raw)    ? "raw"    : "filtered",
  1496. X                rcvr_log_file);
  1497. X        }
  1498. X        else if (!proc_level || proctrace)
  1499. X            pputs("not logging\n");
  1500. X        break;
  1501. X
  1502. X    default:
  1503. X        pputs("invalid command\n");
  1504. X        return(eFATAL_ALREADY);
  1505. X    }
  1506. X    return(0);
  1507. X}    /* end of rcvr_log_control */
  1508. X
  1509. X/*+-------------------------------------------------------------------------
  1510. X    pcmd_rlog(param) - control receivert logging (script)
  1511. X
  1512. Xrlog [-srf] ['filename']  #  see ecuidmc.d
  1513. Xrlog 'off'
  1514. X
  1515. XThis is a hack to use icmd stuff from proc language
  1516. X--------------------------------------------------------------------------*/
  1517. Xint
  1518. Xpcmd_rlog(param)
  1519. XESD *param;
  1520. X{
  1521. Xint erc;
  1522. Xint lnarg = 0;
  1523. Xchar *larg[3];
  1524. XESD *tesd = esdalloc(256);
  1525. Xchar switches[8];
  1526. X
  1527. X    if(!tesd)
  1528. X        return(eNoMemory);
  1529. X
  1530. X    larg[lnarg++] = "log";
  1531. X
  1532. X    if(!get_switches(param,switches,sizeof(switches)))
  1533. X        larg[lnarg++] = switches;
  1534. X
  1535. X    if(!gstr(param,tesd,1))
  1536. X        larg[lnarg++] = tesd->pb;
  1537. X
  1538. X    erc = rcvr_log_control(CTlog,lnarg,larg);
  1539. X    esdfree(tesd);
  1540. X    return(erc);
  1541. X
  1542. X}    /* end of pcmd_rlog */
  1543. X
  1544. X/*+-------------------------------------------------------------------------
  1545. X    icmd_log(token,narg,arg)
  1546. X--------------------------------------------------------------------------*/
  1547. Xint
  1548. Xicmd_log(token,narg,arg)
  1549. Xint token;
  1550. Xint narg;
  1551. Xchar **arg;
  1552. X{
  1553. Xregister itmp;
  1554. Xregister itmp2;
  1555. X
  1556. X    switch(token)
  1557. X    {
  1558. X    case CTloff:
  1559. X        goto LOG_OFF;
  1560. X        break;
  1561. X#if defined(M_XENIX) || defined(M_UNIX)
  1562. X    case CTllp:
  1563. X        icmd("log /dev/lp1");
  1564. X#endif
  1565. X        break;
  1566. X    case CTlog:
  1567. X        if(narg > 1)
  1568. X        {
  1569. X            if(minunique("off",arg[1],3))
  1570. X            {
  1571. XLOG_OFF:
  1572. X                if(rcvr_log == 0)    /* "off",but not logging */
  1573. X                    goto RECORD_REPORT;
  1574. X                ff(se,"\r\nlogging concluded (file %s)\r\n",rcvr_log_file);
  1575. X                shmx_set_rcvr_log("",0,0,0);
  1576. X                rcvr_log = 0;
  1577. X                rcvr_log_file[0] = 0;
  1578. X                return(0);
  1579. X            }
  1580. X/* turning logging on */
  1581. X            itmp2 = -1;
  1582. X            rcvr_log_append = 1;
  1583. X            rcvr_log_raw = 0;
  1584. X            for(itmp = 1; itmp < narg; itmp++)
  1585. X            {
  1586. X                if(*arg[itmp] == '-')
  1587. X                {
  1588. X                    switch(arg[itmp][1])
  1589. X                    {
  1590. X                        case 's': rcvr_log_append = 0; break;
  1591. X                        case 'r': rcvr_log_raw = 1; break;
  1592. X                        case 'f': rcvr_log_flusheach = 1; break;
  1593. X                        default:
  1594. X                            ff(se,"   unrecognized switch -%c\r\n",
  1595. X                                        arg[itmp][1]);
  1596. X                            log_cmd_usage();
  1597. X                            return(eFATAL_ALREADY);
  1598. X                    }
  1599. X                }
  1600. X                else
  1601. X                {
  1602. X                    if(itmp2 > 0)
  1603. X                    {
  1604. X                        ff(se,"   too many positional arguments\r\n");
  1605. X                        log_cmd_usage();
  1606. X                        return(eFATAL_ALREADY);
  1607. X                    }
  1608. X                    itmp2 = itmp;
  1609. X                }
  1610. X            }
  1611. X            if(itmp2 < 0)
  1612. X            {
  1613. X                ff(se,"   no log file name specified\r\n");
  1614. X                log_cmd_usage();
  1615. X                return(eFATAL_ALREADY);
  1616. X            }
  1617. X            if(arg[itmp2][0] != '/')    /* if log file not full path, ... */
  1618. X            {                            /* ... supply current directory */
  1619. X                get_curr_dir(rcvr_log_file,
  1620. X                    sizeof(rcvr_log_file) - strlen(arg[itmp2]) - 2);
  1621. X                strcat(rcvr_log_file,"/");
  1622. X                strcat(rcvr_log_file,arg[itmp2]);
  1623. X            }
  1624. X            else
  1625. X                strcpy(rcvr_log_file,arg[itmp2]);
  1626. X
  1627. X            /* try to open the file if we can */
  1628. X            rcvr_log_fp = fopen(rcvr_log_file,"a");
  1629. X            if(rcvr_log_fp != NULL)        /* if success */
  1630. X            {
  1631. X                fclose(rcvr_log_fp);
  1632. X                rcvr_log_fp = NULL;
  1633. X                rcvr_log = 1;
  1634. X                shmx_set_rcvr_log(rcvr_log_file,rcvr_log_append,rcvr_log_raw,
  1635. X                    rcvr_log_flusheach);
  1636. X            }
  1637. X            else        /* xmtr() could not open file */
  1638. X            {
  1639. X                ff(se,"   could not open ");
  1640. X                perror(rcvr_log_file);
  1641. X                ff(se,"\r\n");
  1642. X                return(eFATAL_ALREADY);
  1643. X            }
  1644. X            rcvr_log_append = 1;
  1645. X        }    /* end of if argument to command */
  1646. X
  1647. XRECORD_REPORT:
  1648. X        if(rcvr_log)
  1649. X        {
  1650. X            ff(se,"\r\n%sing received %s text to\r\n%s\r\n",
  1651. X                (rcvr_log_append) ? "append" : "writ",
  1652. X                (rcvr_log_raw)    ? "raw"    : "filtered",
  1653. X                rcvr_log_file);
  1654. X            ff(se,"use \"HOME log off\" to stop logging\r\n");
  1655. X        }
  1656. X        else
  1657. X        {
  1658. X            ff(se,"   not logging.\r\n");
  1659. X            ff(se,"use \"HOME slog <filename>\" to start logging\r\n");
  1660. X        }
  1661. X        break;
  1662. X    default:
  1663. X        ff(se,"  invalid command\r\n");
  1664. X        return(eFATAL_ALREADY);
  1665. X    }
  1666. X    return(0);
  1667. X}    /* end of icmd_log */
  1668. X
  1669. X/*+-------------------------------------------------------------------------
  1670. X    nlin_nlout_control(token,narg,arg)
  1671. X--------------------------------------------------------------------------*/
  1672. Xvoid
  1673. Xnlin_nlout_control(token,narg,arg)
  1674. Xint token;
  1675. Xint narg;
  1676. Xchar **arg;
  1677. X{
  1678. X    switch(token)
  1679. X    {
  1680. X    case CTnlin:
  1681. X        if(narg != 1)
  1682. X            shm->Ladd_nl_incoming = yes_or_no(arg[1]);
  1683. X        ff(se,"  %sappending NL to incoming CR\r\n",
  1684. X            (shm->Ladd_nl_incoming) ? "" : "not ");
  1685. X        break;
  1686. X    case CTnlout:
  1687. X        if(narg != 1)
  1688. X            shm->Ladd_nl_outgoing = yes_or_no(arg[1]);
  1689. X        ff(se,"  %sappending NL to outgoing CR\r\n",
  1690. X            (shm->Ladd_nl_outgoing) ? "" : "not ");
  1691. X        break;
  1692. X    default:
  1693. X    case CTnl:
  1694. X        ff(se,"  incoming: %s  outgoing: %s\r\n",
  1695. X            (shm->Ladd_nl_incoming) ? "CR/LF" : "CR",
  1696. X            (shm->Ladd_nl_outgoing) ? "CR/LF" : "CR");
  1697. X        break;
  1698. X    }
  1699. X
  1700. X}    /* end of nlin_nlout_control */
  1701. X
  1702. X/* end of ecuicmaux.c */
  1703. X/* vi: set tabstop=4 shiftwidth=4: */
  1704. SHAR_EOF
  1705. $TOUCH -am 0725125691 'ecuicmaux.c' &&
  1706. chmod 0644 ecuicmaux.c ||
  1707. echo 'restore of ecuicmaux.c failed'
  1708. Wc_c="`wc -c < 'ecuicmaux.c'`"
  1709. test 10590 -eq "$Wc_c" ||
  1710.     echo 'ecuicmaux.c: original size 10590, current size' "$Wc_c"
  1711. rm -f _shar_wnt_.tmp
  1712. fi
  1713. # ============= ecuicmd.c ==============
  1714. if test -f 'ecuicmd.c' -a X"$1" != X"-c"; then
  1715.     echo 'x - skipping ecuicmd.c (File already exists)'
  1716.     rm -f _shar_wnt_.tmp
  1717. else
  1718. > _shar_wnt_.tmp
  1719. echo 'x - extracting ecuicmd.c (Text)'
  1720. sed 's/^X//' << 'SHAR_EOF' > 'ecuicmd.c' &&
  1721. X/*+-----------------------------------------------------------------------
  1722. X    ecuicmd.c - ECU interactive command handler
  1723. X    wht@n4hgf.Mt-Park.GA.US
  1724. X
  1725. X  Defined functions:
  1726. X    icmd(icmd_cmd)
  1727. X    icmd_do_proc(ndoarg,doarg)
  1728. X    search_cmd_list(cmd_list,cmd)
  1729. X
  1730. X------------------------------------------------------------------------*/
  1731. X/*+:EDITS:*/
  1732. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  1733. X/*:05-21-1991-18:22-wht@n4hgf-add pushd/popd commands */
  1734. X/*:05-21-1991-00:46-wht@n4hgf-added -3 error code to keyset_read */
  1735. X/*:03-20-1991-05:25-root@n4hgf-experimental eto command */
  1736. X/*:03-20-1991-04:55-root@n4hgf-Metro Link support + stat cmd changes */
  1737. X/*:02-04-1991-19:03-wht@n4hgf-add multiscreen tag to stat */
  1738. X/*:01-09-1991-22:31-wht@n4hgf-ISC port */
  1739. X/*:12-24-1990-04:31-wht@n4hgf-experimental fasi driver command */
  1740. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1741. X
  1742. X#include "ecu.h"
  1743. X#include "esd.h"
  1744. X#include "ecufkey.h"
  1745. X#include "patchlevel.h"
  1746. X
  1747. X#define NEED_P_CMD
  1748. X#include "ecucmd.h"
  1749. X
  1750. X#if defined(FASI)
  1751. X# include <local/fas.h>
  1752. X#endif
  1753. X
  1754. Xextern KDE keyset_table[];
  1755. Xextern char *makedate;
  1756. Xextern char curr_dir[CURR_DIRSIZ];
  1757. Xextern char hello_str[];
  1758. Xextern char keyset_name[];
  1759. Xextern char rcvr_log_file[];    /* if rcvr_log!= 0,log filename */
  1760. Xextern int sigint;
  1761. Xextern int current_ttymode;
  1762. Xextern long tty_escape_timeout;        /* timeout on waiting for char after ESC */
  1763. Xextern int tcap_COLS;
  1764. Xextern int tcap_LINES;
  1765. Xextern int tty_is_multiscreen;
  1766. Xextern int tty_is_ansi;
  1767. Xextern int tty_is_pty;
  1768. X#if defined(METRLINK_X11R4_PTS)
  1769. Xextern int tty_is_pts;
  1770. X#endif /* METRLINK_X11R4_PTS */
  1771. Xextern int errno;
  1772. Xextern int proc_level;
  1773. Xextern int proctrace;
  1774. Xextern int rcvr_log;            /* rcvr log active if != 0 */
  1775. Xextern int rcvr_log_append;    /* if true, append, else scratch */
  1776. Xextern int rcvr_log_raw;        /* if true, log all, else filter ctl chrs */
  1777. Xextern int rcvr_pid;
  1778. Xextern ulong colors_current;
  1779. Xextern FILE *plog_fp;
  1780. Xextern ESD  *plog_name;
  1781. Xextern char screen_dump_file_name[];
  1782. X
  1783. Xint protocol_log_packets = 0;
  1784. Xint want_bell_notify = 1;    /* want bell notify */
  1785. X
  1786. X/*+-------------------------------------------------------------------------
  1787. X    search_cmd_list(cmd_list,cmd)
  1788. Xreturns -1 if cmd not found or insufficient chars for match
  1789. Xelse token value for command
  1790. Xproc-only commands have 'mincnt' values 0
  1791. X--------------------------------------------------------------------------*/
  1792. Xsearch_cmd_list(cmd_list,cmd)
  1793. Xregister P_CMD *cmd_list;
  1794. Xregister char *cmd;
  1795. X{
  1796. X    while(cmd_list->token != -1)
  1797. X    {
  1798. X        if(cmd_list->mincnt && minunique(cmd_list->cmd,cmd,cmd_list->mincnt))
  1799. X            return(cmd_list->token);
  1800. X        cmd_list++;
  1801. X    }
  1802. X    return(-1);
  1803. X
  1804. X}    /* end of search_cmd_list */
  1805. X
  1806. X/*+-------------------------------------------------------------------------
  1807. X    icmd_do_proc(ndoarg,doarg)
  1808. X--------------------------------------------------------------------------*/
  1809. Xicmd_do_proc(ndoarg,doarg)
  1810. Xint ndoarg;
  1811. Xchar **doarg;
  1812. X{
  1813. Xregister erc;
  1814. Xulong colors_at_entry = colors_current;
  1815. X
  1816. X    kill_rcvr_process(SIGUSR1);
  1817. X    ttymode(2);
  1818. X    erc = do_proc(ndoarg,doarg);
  1819. X    proc_file_reset();
  1820. X    ttymode(1);
  1821. X    sigint = 0;
  1822. X    setcolor(colors_notify);
  1823. X    ff(se,"[procedure finished]");
  1824. X    setcolor(colors_at_entry);
  1825. X    ff(se,"\r\n");
  1826. X    start_rcvr_process(0);
  1827. X    return(erc);
  1828. X}    /* end of icmd_do_proc */
  1829. X
  1830. X/*+-----------------------------------------------------------------------
  1831. X    icmd(cmd)
  1832. X This function implements the built in commands
  1833. X It returns non-zero if program should terminate
  1834. X------------------------------------------------------------------------*/
  1835. Xint
  1836. Xicmd(icmd_cmd)
  1837. Xregister char *icmd_cmd;
  1838. X{
  1839. X#define ARG_MAX_QUAN 40
  1840. Xchar *arg[ARG_MAX_QUAN];
  1841. Xchar cmd[128];
  1842. Xint itmp,itmp2,itmp3;
  1843. Xint token;
  1844. Xint narg = 0;
  1845. XESD *tesd;
  1846. Xchar s80[80];
  1847. Xchar *epoch_secs_to_str();
  1848. Xlong atol();
  1849. Xlong ltmp;
  1850. Xlong ltmp2;
  1851. Xchar *find_procedure();
  1852. Xchar *xon_status();
  1853. X
  1854. X    icmd_history_add(icmd_cmd);        /* add to history list */
  1855. X    strcpy(cmd,icmd_cmd);            /* get local copy of cmd string */
  1856. X    switch(cmd[0]) 
  1857. X    {
  1858. X        case '.':        /* exit xmtr() (generally program too) */
  1859. X            ff(se,"  disconnecting from line %s\r\n",shm->Lline);
  1860. X            return(1);
  1861. X        case '!':
  1862. X        case '$':
  1863. X        case '>':
  1864. X            ff(se,"\r\n");
  1865. X            shell(cmd);
  1866. X            return(0);
  1867. X        case '-':
  1868. X            ff(se,"\r\n");
  1869. X            exec_cmd(&cmd[1]);
  1870. X            return(0);
  1871. X        case '^':
  1872. X            ff(se,"\r\n");
  1873. X            phrase_help();
  1874. X            return(0);
  1875. X        case '?':
  1876. X            icmd_help(0,(char **)0);
  1877. X            return(0);
  1878. X#ifdef DEBUG_SHM_SCREEN
  1879. X        case '@':
  1880. X            {
  1881. X            FILE *fp = fopen("/tmp/screen","w");
  1882. X            int y,x;
  1883. X            char *cptr = (char *)shm->screen;
  1884. X                for(y = 0; y < 43; y++)
  1885. X                {
  1886. X                    for(x = 0; x < 80; x++)
  1887. X                        fputc(*cptr++,fp);
  1888. X                    fputc('\n',fp);
  1889. X                }
  1890. X                fclose(fp);
  1891. X            }
  1892. X            break;
  1893. X#endif
  1894. X        default:
  1895. X            break;
  1896. X    }
  1897. X
  1898. X/* not single character argument */
  1899. X    build_arg_array(cmd,arg,ARG_MAX_QUAN,&narg);
  1900. X
  1901. X/* handle phrases */
  1902. X    if(isdigit(*arg[0]))
  1903. X    {
  1904. X        phrases(narg,arg);
  1905. X        return(0);
  1906. X    }
  1907. X
  1908. X/* search command list */
  1909. X    if((token = search_cmd_list(icmd_cmds,arg[0])) < 0)
  1910. X    {
  1911. X        ff(se,"\r\n");
  1912. X        if(find_procedure(arg[0]))
  1913. X        {
  1914. X            icmd_do_proc(narg,arg);
  1915. X            return(0);
  1916. X        }
  1917. X        ff(se,"no such command or procedure ... HOME ? for help\r\n");
  1918. X        return(0);
  1919. X    }
  1920. X
  1921. X    switch(token)
  1922. X    {                    /* keep alphabetized PLEASE */
  1923. X        case CTrx:
  1924. X        case CTry:
  1925. X        case CTrz:
  1926. X        case CTrk:
  1927. X        case CTrs:
  1928. X        receive_files_from_remote(narg,arg);
  1929. X        break;
  1930. X
  1931. X        case CTsx:
  1932. X        case CTsy:
  1933. X        case CTsz:
  1934. X        case CTsk:
  1935. X        case CTss:
  1936. X        send_files_to_remote(narg,arg);
  1937. X        break;
  1938. X
  1939. X        case CTbaud:
  1940. X        if(narg == 1)
  1941. X            ff(se,"   baud rate is %u\r\n",shm->Lbaud);
  1942. X        else
  1943. X        {
  1944. X            itmp = atoi(arg[1]);
  1945. X            if(!lnew_baud_rate(itmp))
  1946. X                ff(se,"   baud rate set to %u\r\n",shm->Lbaud);
  1947. X            else
  1948. X            {
  1949. X                ff(se,"   invalid baud rate: %u\r\n",itmp);
  1950. X                ff(se,"valid rates: 110,300,600,1200,2400,4800,9600,19200\r\n");
  1951. X            }
  1952. X        }
  1953. X        break;
  1954. X
  1955. X        case CTbreak:
  1956. X        lbreak();
  1957. X        ff(se,"   break sent\r\n");
  1958. X        break;
  1959. X
  1960. X        case CTcd:
  1961. X        (void)change_directory(arg[1],(narg == 1) ? 0 : 1);
  1962. X        break;
  1963. X
  1964. X        case CTpushd:
  1965. X        (void)push_directory(arg[1],(narg == 1) ? 0 : 1,0);
  1966. X        break;
  1967. X
  1968. X        case CTpopd:
  1969. X        (void)pop_directory(arg[1],(narg == 1) ? 0 : 1,0);
  1970. X        break;
  1971. X
  1972. X        case CTclrx:
  1973. X        lclear_xmtr_xoff();
  1974. X        break;
  1975. X
  1976. X        case CTdial:
  1977. X        if(narg > 1)
  1978. X        {
  1979. X            ff(se,"\r\n");
  1980. X            strcpy(shm->Llogical,arg[1]);
  1981. X            if(!lookup_logical_telno())
  1982. X                ff(se,"No such entry. Try 'dial' with no arguments\r\n");
  1983. X            else
  1984. X            {
  1985. X                if(isdigit(shm->Llogical[0]) ||
  1986. X                    !find_procedure(shm->Llogical))
  1987. X                    DCE_dial();
  1988. X                else
  1989. X                {
  1990. X                    arg[0] = shm->Llogical;
  1991. X                    arg[1] = "!INTERACTIVE";
  1992. X                    icmd_do_proc(2,arg);
  1993. X                }
  1994. X            }
  1995. X        }
  1996. X        else
  1997. X        {
  1998. X            pde_list_manager();
  1999. X        }
  2000. X        break;
  2001. X
  2002. X        case CTdo:
  2003. X        ff(se,"\r\n");
  2004. X        icmd_do_proc(narg - 1,&arg[1]);
  2005. X        break;
  2006. X
  2007. X        case CTptrace:
  2008. X        if(narg > 1)
  2009. X            proctrace = yes_or_no(arg[1]);
  2010. X        ff(se,"  procedure trace %s",proctrace ? "on" : "off");
  2011. X        if(proctrace > 1)
  2012. X            ff(se," (%d)",proctrace);
  2013. X        ff(se,"\r\n");
  2014. X        break;
  2015. X
  2016. X        case CTpcmd:
  2017. X        itmp = strlen(arg[0]);
  2018. X        if((tesd = esdalloc(256)) == (ESD *)0)
  2019. X        {
  2020. X            ff(se,"  no memory!!?!\r\n");
  2021. X            break;
  2022. X        }
  2023. X        strcpy(tesd->pb,icmd_cmd + itmp + 1);
  2024. X        tesd->cb = strlen(tesd->pb);
  2025. X        ff(se,"\r\n");
  2026. X        kill_rcvr_process(SIGUSR1);
  2027. X        ttymode(2);
  2028. X        if(itmp = execute_esd(tesd))
  2029. X        {
  2030. X            proc_error(itmp);
  2031. X            esdshow(tesd,"");
  2032. X        }
  2033. X        esdfree(tesd);
  2034. X        ttymode(1);
  2035. X        start_rcvr_process(0);
  2036. X        break;
  2037. X
  2038. X        case CTplog:
  2039. X        fputs("  ",se);
  2040. X        if(narg > 1)
  2041. X        {
  2042. X            if(!strcmp(arg[1],"off"))
  2043. X                plog_control((char *)0);
  2044. X            else
  2045. X                plog_control(arg[1]);
  2046. X        }
  2047. X        
  2048. X        if(plog_fp)
  2049. X            ff(se,"procedure logging: %s\r\n",plog_name->pb);
  2050. X        else
  2051. X            fputs("procedure logging off\r\n",se);
  2052. X        break;
  2053. X
  2054. X        case CTduplex:
  2055. X        if(narg > 1)
  2056. X        {
  2057. X            switch(to_lower(*arg[1]))
  2058. X            {
  2059. X                case 'f': shm->Lfull_duplex = 1; ff(se,"  now "); break;
  2060. X                case 'h': shm->Lfull_duplex = 0; ff(se,"  now "); break;
  2061. X                default: ff(se,
  2062. X"\r\nfirst argument character must be F or H for full or half duplex\r\n");
  2063. X                    break;
  2064. X            }
  2065. X        }
  2066. X        else        /* no argument */
  2067. X            ff(se,"  currently ");
  2068. X
  2069. X        ff(se,"%s duplex\r\n",(shm->Lfull_duplex) ? "full" : "half");
  2070. X        break;
  2071. X
  2072. X        case CTexit:
  2073. X        ff(se,"  disconnecting from line %s\r\n",shm->Lline);
  2074. X        return(1);
  2075. X
  2076. X        case CTfi:
  2077. X        file_insert_to_line(narg,arg);
  2078. X        break;
  2079. X
  2080. X        case CThangup:
  2081. X        ff(se,"  hanging up ...\r\n");
  2082. X        DCE_hangup();
  2083. X#if defined(FASI)
  2084. X        {
  2085. X            uchar msr = fasi_msr();
  2086. X            ff(se,"hangup complete ... DCD is %s\r\n",
  2087. X                (msr & MS_DCD_PRESENT) ? "STILL HIGH" : "low");
  2088. X        }
  2089. X#else
  2090. X        ff(se,"hangup complete\r\n");
  2091. X#endif
  2092. X        break;
  2093. X
  2094. X        case CThelp:
  2095. X        icmd_help(narg,arg);
  2096. X        break;
  2097. X
  2098. X        case CTsdname:
  2099. X        if(narg > 1)
  2100. X        {
  2101. X        char *new_file_name;
  2102. X
  2103. X            itmp = 0;    /* do not need to free(new_file_name) */
  2104. X            if(find_shell_chars(arg[1]))
  2105. X            {
  2106. X
  2107. X                if(expand_wildcard_list(arg[1],&new_file_name))
  2108. X                {
  2109. X                    ff(se,"  %s\r\n",new_file_name);
  2110. X                    break;
  2111. X                }
  2112. X                itmp = 1;    /* need to free(new_file_name) */
  2113. X            }
  2114. X            else
  2115. X                new_file_name = arg[1];
  2116. X
  2117. X            screen_dump_file_name[0] = 0;
  2118. X            if(*new_file_name != '/')
  2119. X            {
  2120. X                strcpy(screen_dump_file_name,curr_dir);
  2121. X                strcat(screen_dump_file_name,"/");
  2122. X            }
  2123. X            strcat(screen_dump_file_name,arg[1]);
  2124. X            if(itmp)
  2125. X                free(new_file_name);
  2126. X        }
  2127. X        ff(se,"\r\nscreen dump name: %s\r\n",screen_dump_file_name);
  2128. X        break;
  2129. X
  2130. X        case CTlog:
  2131. X        case CTloff:
  2132. X        case CTllp:
  2133. X        icmd_log(token,narg,arg);
  2134. X        break;
  2135. X
  2136. X        case CTnl:
  2137. X        case CTnlin:
  2138. X        case CTnlout:
  2139. X        nlin_nlout_control(token,narg,arg);
  2140. X        break;
  2141. X
  2142. X        case CTparity:
  2143. X        if(narg > 1)
  2144. X        {
  2145. X            switch(to_lower(*arg[1]))
  2146. X            {
  2147. X                case 'n':
  2148. X                    shm->Lparity = 0; break;
  2149. X                case 'e':
  2150. X                case 'o':
  2151. X                    shm->Lparity = to_lower(*arg[1]); break;
  2152. X                default:
  2153. X                    ff(se,"   unrecognized parity: %c\r\n",*arg[1]);
  2154. X                    goto PARITY_DONE;
  2155. X            }
  2156. X            lset_parity(1);
  2157. X        }
  2158. X        ff(se,"   parity set to %c\r\n",
  2159. X            (shm->Lparity) ? to_upper(shm->Lparity) : 'N');
  2160. XPARITY_DONE: ;
  2161. X        break;
  2162. X
  2163. X        case CTpid:
  2164. X        ff(se,": xmtr %d, rcvr: %d, parent: %d, group: %d\r\n",
  2165. X            getpid(0),rcvr_pid,getppid(0),getpgrp(0));
  2166. X        break;
  2167. X
  2168. X        case CTpwd:
  2169. X        fputs(" ",se);
  2170. X        tcap_stand_out();
  2171. X        ff(se," %s ",curr_dir);
  2172. X        tcap_stand_end();
  2173. X        fputs("\r\n",se);
  2174. X        break;
  2175. X
  2176. X        case CTredial:
  2177. X        (void)DCE_redial(arg,narg);
  2178. X        break;
  2179. X
  2180. X        case CTrev:
  2181. X        fputs("\r\n",se);
  2182. X        fputs(hello_str,se);
  2183. X        fputs("\r\n",se);
  2184. X        ff(se,"%s\r\n",makedate);
  2185. X#if defined(WHT) && !defined(NOMEMCHECK)
  2186. X        _dump_malloc();
  2187. X#endif
  2188. X        break;
  2189. X
  2190. X        case CTtime:
  2191. X        get_tod(4,cmd);
  2192. X        ff(se,": %s\r\n",cmd);
  2193. X        break;
  2194. X
  2195. X        case CTts:
  2196. SHAR_EOF
  2197. true || echo 'restore of ecuicmd.c failed'
  2198. fi
  2199. echo 'End of ecu310 part 5'
  2200. echo 'File ecuicmd.c is continued in part 6'
  2201. echo 6 > _shar_seq_.tmp
  2202. exit 0
  2203. --------------------------------------------------------------------
  2204. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2205. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2206.  
  2207. exit 0 # Just in case...
  2208. -- 
  2209. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2210. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2211. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2212. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2213.