home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / misc / 3947 < prev    next >
Encoding:
Text File  |  1992-09-14  |  57.1 KB  |  2,521 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  4. Subject:  v32i055:  ecu - ECU Asynchronous Communications v3.20, Part20/40
  5. Message-ID: <1992Sep14.143459.20269@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: c117b1baec7dea4b0c5c92f345f27007
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v32i036=ecu.141245@sparky.IMD.Sterling.COM>
  11. Date: Mon, 14 Sep 1992 14:34:59 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2506
  14.  
  15. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  16. Posting-number: Volume 32, Issue 55
  17. Archive-name: ecu/part20
  18. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  19. Supersedes: ecu: Volume 21, Issue 53-89
  20.  
  21. ---- Cut Here and feed the following to sh ----
  22. #!/bin/sh
  23. # this is ecu320.20 (part 20 of ecu320)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file pcmdtty.c continued
  26. #
  27. if test ! -r _shar_seq_.tmp; then
  28.     echo 'Please unpack part 1 first!'
  29.     exit 1
  30. fi
  31. (read Scheck
  32.  if test "$Scheck" != 20; then
  33.     echo Please unpack part "$Scheck" next!
  34.     exit 1
  35.  else
  36.     exit 0
  37.  fi
  38. ) < _shar_seq_.tmp || exit 1
  39. if test ! -f _shar_wnt_.tmp; then
  40.     echo 'x - still skipping pcmdtty.c'
  41. else
  42. echo 'x - continuing file pcmdtty.c'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'pcmdtty.c' &&
  44. X        if(proctrace > 1)
  45. X        {
  46. X            pprintf("normal %ld,%ld current=0x%08lx\n",
  47. X                foreground,background,colors_current);
  48. X        }
  49. X    }
  50. X    else
  51. X    {
  52. X        colors_current &= 0x0000FFFF;
  53. X        colors_current |= (foreground << 24) | (background << 16);
  54. X        if(proctrace > 1)
  55. X        {
  56. X            pprintf("reverse %ld,%ld current=0x%08lx\n",
  57. X                foreground,background,colors_current);
  58. X        }
  59. X    }
  60. X
  61. X    setcolor(colors_current);
  62. X    return(0);
  63. X
  64. XERROR:
  65. X    if(erc)
  66. X        return(erc);
  67. X    pputs("invalid color\n");
  68. X    return(eFATAL_ALREADY);
  69. X
  70. X}    /* end of pcmd_color */
  71. X
  72. X/*+-------------------------------------------------------------------------
  73. X    ifunc_colors(pvalue)
  74. X--------------------------------------------------------------------------*/
  75. Xint
  76. Xifunc_colors(pvalue)
  77. Xulong *pvalue;
  78. X{
  79. X    *pvalue = colors_current;
  80. X    return(0);
  81. X}    /* end of ifunc_colors */
  82. X
  83. X/*+-------------------------------------------------------------------------
  84. X    pcmd_icolor(param)
  85. X--------------------------------------------------------------------------*/
  86. Xpcmd_icolor(param)
  87. XESD *param;
  88. X{
  89. X    int erc;
  90. X    ulong new_colors;
  91. X
  92. X    if(erc = gint(param,&new_colors))
  93. X        return(erc);
  94. X
  95. X    setcolor(new_colors);
  96. X    return(0);
  97. X}    /* end of pcmd_icolor */
  98. X
  99. X/*+-------------------------------------------------------------------------
  100. X    pcmd_cls(param)
  101. X--------------------------------------------------------------------------*/
  102. X/*ARGSUNUSED*/
  103. Xint
  104. Xpcmd_cls(param)
  105. XESD *param;
  106. X{
  107. X    tcap_clear_screen();
  108. X    return(0);
  109. X}    /* end of pcmd_cls */
  110. X
  111. X/*+-------------------------------------------------------------------------
  112. X    pcmd_cursor(param)
  113. X--------------------------------------------------------------------------*/
  114. Xint
  115. Xpcmd_cursor(param)
  116. XESD *param;
  117. X{
  118. X    int erc;
  119. X    long row;
  120. X    long col = 0;
  121. X
  122. X    if(erc = gint(param,&row))
  123. X        return(erc);
  124. X    if(gint(param,&col))
  125. X    {
  126. X        /* if something there non-integer */
  127. X        if(!end_of_cmd(param))
  128. X            return(eSyntaxError);
  129. X    }
  130. X    tcap_cursor((int)row,(int)col);
  131. X    return(0);
  132. X}    /* end of pcmd_cursor */
  133. X
  134. X/*+-------------------------------------------------------------------------
  135. X    pcmd_scrdump(param)
  136. X--------------------------------------------------------------------------*/
  137. Xint
  138. Xpcmd_scrdump(param)
  139. XESD *param;
  140. X{
  141. X    int erc;
  142. X    ESD *fname;
  143. X    FILE *fp;
  144. X
  145. X    if((fname = esdalloc(256)) == (ESD *)0)
  146. X        return(eNoMemory);
  147. X
  148. X    if(erc = gstr(param,fname,1))
  149. X    {
  150. X        if(!end_of_cmd(param))
  151. X        {
  152. X            erc = eSyntaxError;
  153. X            goto RETURN;
  154. X        }
  155. X    }
  156. X
  157. X    if(fname->cb)
  158. X    {
  159. X        if(!(fp = fopen(fname->pb,"a")))
  160. X        {
  161. X            pperror(fname->pb);
  162. X            erc = eFATAL_ALREADY;
  163. X            goto RETURN;
  164. X        }
  165. X        fclose(fp);
  166. X    }
  167. X
  168. X    screen_dump((fname->cb) ? fname->pb : (char *)0);
  169. X
  170. XRETURN:
  171. X    esdfree(fname);
  172. X    return(erc);
  173. X}    /* end of pcmd_scrdump */
  174. X
  175. X/*+-------------------------------------------------------------------------
  176. X    pcmd_vidnorm(param)
  177. X--------------------------------------------------------------------------*/
  178. X/*ARGSUNUSED*/
  179. Xint
  180. Xpcmd_vidnorm(param)
  181. XESD *param;
  182. X{
  183. X    tcap_stand_end();
  184. X    return(0);
  185. X}    /* end of pcmd_vidnorm */
  186. X
  187. X/*+-------------------------------------------------------------------------
  188. X    pcmd_vidrev(param)
  189. X--------------------------------------------------------------------------*/
  190. X/*ARGSUNUSED*/
  191. Xint
  192. Xpcmd_vidrev(param)
  193. XESD *param;
  194. X{
  195. X    tcap_stand_out();
  196. X    return(0);
  197. X}    /* end of pcmd_vidrev */
  198. X
  199. X/*+-------------------------------------------------------------------------
  200. X    pcmd_fkey(param)
  201. X--------------------------------------------------------------------------*/
  202. Xpcmd_fkey(param)
  203. XESD *param;
  204. X{
  205. X    int erc;
  206. X    ESD *tesd;
  207. X
  208. X    if((tesd = esdalloc(64)) == (ESD *)0)
  209. X        return(eNoMemory);
  210. X
  211. X    if(erc = gstr(param,tesd,0))
  212. X        goto RETURN;
  213. X
  214. X    switch(keyset_read(tesd->pb))
  215. X    {
  216. X        case  0:
  217. X            if(proctrace)
  218. X                keyset_display();
  219. X            break;
  220. X        case -1:
  221. X            pprintf("cannot find ~/.ecu/keys\n");
  222. X            erc = eFATAL_ALREADY;
  223. X            break;
  224. X        case -2:
  225. X            pprintf("'%s' not found in ~/.ecu/keys\n",tesd->pb);
  226. X            erc = eFATAL_ALREADY;
  227. X            break;
  228. X        case -3:
  229. X            pprintf("'%s' has a syntax error\n",tesd->pb);
  230. X            erc = eFATAL_ALREADY;
  231. X            break;
  232. X    }
  233. X
  234. XRETURN:
  235. X    esdfree(tesd);
  236. X    return(erc);
  237. X}    /* end of pcmd_fkey */
  238. X
  239. X/*+-------------------------------------------------------------------------
  240. X    pcmd_fkmap(param)
  241. X--------------------------------------------------------------------------*/
  242. Xpcmd_fkmap(param)
  243. XESD *param;
  244. X{
  245. X    int erc = 0;
  246. X    int in_quotes = 0;
  247. X    char *cmd;
  248. X    char *cptr;
  249. X    char ch;
  250. X#define FKMAP_MAXARGS 36
  251. X    char *arg[FKMAP_MAXARGS];
  252. X    int narg;
  253. X
  254. X    skip_cmd_break(param);
  255. X
  256. X    if(!(cmd = strdup(param->pb + param->index)))
  257. X        return(eNoMemory);
  258. X
  259. X    cptr = cmd;
  260. X    while(ch = *cptr++)
  261. X    {
  262. X        if(ch == '\'')
  263. X        {
  264. X            in_quotes = !in_quotes;
  265. X            continue;
  266. X        }
  267. X        else if(ch == '\\')
  268. X        {
  269. X            cptr++;
  270. X            continue;
  271. X        }
  272. X        else if(!in_quotes && strchr("#;",ch))
  273. X            break;
  274. X    }
  275. X    param->index += (int)(cptr - cmd);
  276. X    *cptr = 0;
  277. X
  278. X    arg[0] = "fkmap";
  279. X    build_arg_array(cmd,arg + 1,FKMAP_MAXARGS - 1,&narg);
  280. X    narg++;
  281. X    erc = fkmap_command(narg,arg);
  282. X    free(cmd);
  283. X    return(erc);
  284. X
  285. X}    /* end of pcmd_fkmap */
  286. X
  287. X/*+-------------------------------------------------------------------------
  288. X    pcmd_vidcolor(param)
  289. X
  290. Xvidcolor normal|reverse|notify|success|alert|error fcolor [bcolor]
  291. X--------------------------------------------------------------------------*/
  292. Xint
  293. Xpcmd_vidcolor(param)
  294. XESD *param;
  295. X{
  296. X    int erc;
  297. X    int ntokens = 0;
  298. X    char *tokens[3];
  299. X    int param_index[3];
  300. X    char tokenbuf[64];
  301. X
  302. X    tokens[0] = tokenbuf;
  303. X    tokens[1] = tokenbuf + 20;
  304. X    tokens[2] = tokenbuf + 40;
  305. X
  306. X    while(ntokens < 3)
  307. X    {
  308. X        skip_cmd_break(param);
  309. X        param_index[ntokens] = param->index;
  310. X        if(erc = get_word_zstr(param,tokens[ntokens],20))
  311. X            break;
  312. X        ntokens++;
  313. X    }
  314. X
  315. X    if(erc && ((erc != eNoParameter) || (ntokens < 2)))
  316. X        return(erc);
  317. X
  318. X    switch(erc = setcolor_internal(ntokens,tokens))
  319. X    {
  320. X        case 0:
  321. X            break;
  322. X        default:
  323. X            param->old_index = param->index = param_index[erc - 1];
  324. X            erc = eBadParameter;
  325. X    }
  326. X    return(erc);
  327. X}    /* end of pcmd_vidcolor */
  328. X
  329. X/*+-------------------------------------------------------------------------
  330. X    pcmd_home(param) - home the cursor
  331. X--------------------------------------------------------------------------*/
  332. X/*ARGSUNUSED*/
  333. Xint
  334. Xpcmd_home(param)
  335. XESD *param;
  336. X{
  337. X    tcap_cursor(0,0);
  338. X    return(0);
  339. X}    /* end of pcmd_home */
  340. X
  341. X/*+-------------------------------------------------------------------------
  342. X    pcmd_eeol(param) - erase to end of line
  343. X--------------------------------------------------------------------------*/
  344. X/*ARGSUNUSED*/
  345. Xint
  346. Xpcmd_eeol(param)
  347. XESD *param;
  348. X{
  349. X    tcap_eeol();
  350. X    return(0);
  351. X}    /* end of pcmd_eeol */
  352. X
  353. X/*+-------------------------------------------------------------------------
  354. X    pcmd_insline(param) - insert line in display
  355. X--------------------------------------------------------------------------*/
  356. X/*ARGSUNUSED*/
  357. Xint
  358. Xpcmd_insline(param)
  359. XESD *param;
  360. X{
  361. X    tcap_insert_lines(1);
  362. X    return(0);
  363. X}    /* end of pcmd_insline */
  364. X
  365. X/*+-------------------------------------------------------------------------
  366. X    pcmd_delline(param) - delete line from display
  367. X--------------------------------------------------------------------------*/
  368. X/*ARGSUNUSED*/
  369. Xint
  370. Xpcmd_delline(param)
  371. XESD *param;
  372. X{
  373. X    tcap_delete_lines(1);
  374. X    return(0);
  375. X}    /* end of pcmd_delline */
  376. X
  377. X/* vi: set tabstop=4 shiftwidth=4: */
  378. X/* end of pcmdtty.c */
  379. SHAR_EOF
  380. echo 'File pcmdtty.c is complete' &&
  381. chmod 0644 pcmdtty.c ||
  382. echo 'restore of pcmdtty.c failed'
  383. Wc_c="`wc -c < 'pcmdtty.c'`"
  384. test 9422 -eq "$Wc_c" ||
  385.     echo 'pcmdtty.c: original size 9422, current size' "$Wc_c"
  386. rm -f _shar_wnt_.tmp
  387. fi
  388. # ============= pcmdwhile.c ==============
  389. if test -f 'pcmdwhile.c' -a X"$1" != X"-c"; then
  390.     echo 'x - skipping pcmdwhile.c (File already exists)'
  391.     rm -f _shar_wnt_.tmp
  392. else
  393. > _shar_wnt_.tmp
  394. echo 'x - extracting pcmdwhile.c (Text)'
  395. sed 's/^X//' << 'SHAR_EOF' > 'pcmdwhile.c' &&
  396. X/*+-------------------------------------------------------------------------
  397. X    pcmdwhile.c - ecu while procedure commands
  398. X    wht@n4hgf.Mt-Park.GA.US
  399. X
  400. X    WHILEI $i0 rel-op $i1 cmd
  401. X    WHILES $s0 rel-op $s1 cmd
  402. X
  403. X    where rel-op is "=", "==", "!=", "<>", ">", "<", ">=", "=<"
  404. X
  405. X  Defined functions:
  406. X    pcmd_whilei(param)
  407. X    pcmd_whiles(param)
  408. X
  409. X--------------------------------------------------------------------------*/
  410. X/*+:EDITS:*/
  411. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  412. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  413. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  414. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  415. X
  416. X#include <ctype.h>
  417. X#include "ecu.h"
  418. X#include "ecuerror.h"
  419. X#include "esd.h"
  420. X#include "var.h"
  421. X#include "proc.h"
  422. X#include "relop.h"
  423. X
  424. Xextern PCB *pcb_stack[];
  425. X
  426. X/*+-------------------------------------------------------------------------
  427. X    pcmd_whilei(param)
  428. X--------------------------------------------------------------------------*/
  429. Xint
  430. Xpcmd_whilei(param)
  431. XESD *param;
  432. X{
  433. Xregister erc;
  434. Xint truth;
  435. XPCB *pcb;
  436. XLCB *condition_lcb;
  437. Xint condition_index = param->index;
  438. X
  439. X    if(!proc_level)
  440. X        return(eNotExecutingProc);
  441. X
  442. X    pcb = pcb_stack[proc_level - 1];
  443. X    condition_lcb = pcb->current;
  444. X
  445. XREPEAT_WHILE:
  446. X
  447. X    if(erc = get_truth_int(param,&truth))
  448. X        return(erc);
  449. X
  450. X/* if end of command, execute frame */
  451. X    if(end_of_cmd(param))
  452. X    {
  453. X        if(erc = execute_frame(truth))
  454. X        {
  455. X            if(erc == eContinueCommand)
  456. X                goto CONTINUE;
  457. X            if(erc == eBreakCommand)
  458. X                erc = 0;
  459. X            return(erc);
  460. X        }
  461. X    }
  462. X    else if(truth)
  463. X    {
  464. X        if(erc = execute_esd(param))
  465. X            return(erc);
  466. X    }
  467. X
  468. X/* repeat if indicated */
  469. XCONTINUE:
  470. X    if(truth)
  471. X    {
  472. X        pcb->current = condition_lcb;
  473. X        param->index = param->old_index = condition_index;
  474. X        goto REPEAT_WHILE;
  475. X    }
  476. X
  477. X    return(0);
  478. X}   /* end of pcmd_whilei */
  479. X
  480. X/*+-------------------------------------------------------------------------
  481. X    pcmd_whiles(param)
  482. X--------------------------------------------------------------------------*/
  483. Xint
  484. Xpcmd_whiles(param)
  485. XESD *param;
  486. X{
  487. Xregister erc;
  488. Xint truth;
  489. XPCB *pcb;
  490. XLCB *condition_lcb;
  491. Xint condition_index = param->index;
  492. X
  493. X    if(!proc_level)
  494. X        return(eNotExecutingProc);
  495. X
  496. X    pcb = pcb_stack[proc_level - 1];
  497. X    condition_lcb = pcb->current;
  498. X
  499. XREPEAT_WHILE:
  500. X
  501. X    if(erc = get_truth_str(param,&truth))
  502. X        return(erc);
  503. X
  504. X/* if end of command, execute frame */
  505. X    if(end_of_cmd(param))
  506. X    {
  507. X        if(erc = execute_frame(truth))
  508. X        {
  509. X            if(erc == eContinueCommand)
  510. X                goto CONTINUE;
  511. X            if(erc == eBreakCommand)
  512. X                erc = 0;
  513. X            return(erc);
  514. X        }
  515. X    }
  516. X    else if(truth)
  517. X    {
  518. X        if(erc = execute_esd(param))
  519. X            return(erc);
  520. X    }
  521. X
  522. X/* repeat if indicated */
  523. XCONTINUE:
  524. X    if(truth)
  525. X    {
  526. X        pcb->current = condition_lcb;
  527. X        param->index = param->old_index = condition_index;
  528. X        goto REPEAT_WHILE;
  529. X    }
  530. X
  531. X    return(0);
  532. X}   /* end of pcmd_whiles */
  533. X
  534. X/* vi: set tabstop=4 shiftwidth=4: */
  535. X/* end of pcmdwhile.c */
  536. SHAR_EOF
  537. chmod 0644 pcmdwhile.c ||
  538. echo 'restore of pcmdwhile.c failed'
  539. Wc_c="`wc -c < 'pcmdwhile.c'`"
  540. test 2818 -eq "$Wc_c" ||
  541.     echo 'pcmdwhile.c: original size 2818, current size' "$Wc_c"
  542. rm -f _shar_wnt_.tmp
  543. fi
  544. # ============= pcmdxfer.c ==============
  545. if test -f 'pcmdxfer.c' -a X"$1" != X"-c"; then
  546.     echo 'x - skipping pcmdxfer.c (File already exists)'
  547.     rm -f _shar_wnt_.tmp
  548. else
  549. > _shar_wnt_.tmp
  550. echo 'x - extracting pcmdxfer.c (Text)'
  551. sed 's/^X//' << 'SHAR_EOF' > 'pcmdxfer.c' &&
  552. X/*+-------------------------------------------------------------------------
  553. X    pcmdxfer.c - ecu file transfer related procedure commands
  554. X    wht@n4hgf.Mt-Park.GA.US
  555. X
  556. X  Defined functions:
  557. X    _adjust_erc_and_iv0(adj_erc)
  558. X    _make_bottom_label(param,default_flag,sending_flag)
  559. X    _pcmd_report_send_status()
  560. X    _smart_sender_common(cmd)
  561. X    pcmd_rk(param)
  562. X    pcmd_rs(param)
  563. X    pcmd_rx(param)
  564. X    pcmd_ry(param)
  565. X    pcmd_rz(param)
  566. X    pcmd_sk(param)
  567. X    pcmd_ss(param)
  568. X    pcmd_sx(param)
  569. X    pcmd_sy(param)
  570. X    pcmd_sz(param)
  571. X
  572. X--------------------------------------------------------------------------*/
  573. X/*+:EDITS:*/
  574. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  575. X/*:09-05-1992-15:35-wht@n4hgf-add -r to sz */
  576. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  577. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  578. X/*:04-23-1991-23:44-wht@n4hgf-big time overhaul - better but flames expected */
  579. X/*:04-23-1991-05:10-wht@n4hgf-new cmd build mechanism for long file lists */
  580. X/*:01-17-1991-17:01-wht@n4hgf-skipped files in sz aborted proc */
  581. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  582. X
  583. X#include "ecu.h"
  584. X#include "ecukey.h"
  585. X#include "ecuerror.h"
  586. X#include "esd.h"
  587. X#include "var.h"
  588. X#include "proc.h"
  589. X
  590. X/*
  591. X * file transmission command and pathname list ESD initial size
  592. X * (lengths can grow to ESD_MAXSIZE)
  593. X */
  594. X#define CMDESD_INITIAL_SIZE  384 /* executable command initial size */
  595. X#define PATHESD_INITIAL_SIZE 256 /* pathname list initial size */
  596. X#define CMDSTR_SIZE          384 /* receive command string size */
  597. X
  598. Xextern int proctrace;
  599. Xextern int last_child_wait_status;
  600. Xextern char curr_dir[CURR_DIRSIZ];
  601. X
  602. Xstatic char bottom_label[80];
  603. X
  604. X/*+-------------------------------------------------------------------------
  605. X    _make_bottom_label(param,default_flag)
  606. X--------------------------------------------------------------------------*/
  607. Xint
  608. X_make_bottom_label(param,default_flag,sending_flag)
  609. XESD *param;
  610. Xint default_flag;
  611. Xint sending_flag;
  612. X{
  613. Xregister erc;
  614. XESD *label = (ESD *)0;
  615. X
  616. X    if(default_flag)
  617. X    {
  618. X        sprintf(bottom_label,
  619. X            (sending_flag) ? "-C \"'Connected to %s'\" "
  620. X                           : "-C 'Connected to %s' ",
  621. X            (shm->Lrname[0]) ? shm->Lrname : "?");
  622. X        return(0);
  623. X    }
  624. X    if((label = esdalloc(64)) == (ESD *)0)
  625. X        return(eNoMemory);
  626. X    if(erc = gstr(param,label,0))
  627. X    {
  628. X        esdfree(label);
  629. X        return(erc);
  630. X    }
  631. X    strcpy(bottom_label,(sending_flag) ? "-C \"'" : "-C '");
  632. X    strcat(bottom_label,label->pb);
  633. X    strcat(bottom_label,(sending_flag) ? "'\"" : "'");
  634. X    esdfree(label);
  635. X    return(0);
  636. X
  637. X}    /* end of _make_bottom_label */
  638. X
  639. X/*+-------------------------------------------------------------------------
  640. X    _adjust_erc_and_iv0(adj_erc)
  641. X--------------------------------------------------------------------------*/
  642. Xint
  643. X_adjust_erc_and_iv0(adj_erc)
  644. Xint adj_erc;
  645. X{
  646. X
  647. X    if(adj_erc)
  648. X        return(adj_erc);
  649. X
  650. X    iv[0] = (last_child_wait_status & 0xFF)
  651. X            ? 0x100L : (long)((last_child_wait_status >> 8) & 0xFFFF);
  652. X
  653. X    if(proctrace)
  654. X        pprintf("$i00 = %ld (transfer %s)\n",iv[0],
  655. X            (iv[0] == 0x100L) ? "interrupted" : "program exit status");
  656. X
  657. X    return(0);
  658. X
  659. X}    /* end of _adjust_erc_and_iv0 */
  660. X
  661. X/*+-------------------------------------------------------------------------
  662. X    _pcmd_report_send_status() - report file transmission result
  663. X
  664. Xfor "ecu knowledgeable" protocols only
  665. Xreturns proc-type erc
  666. X--------------------------------------------------------------------------*/
  667. Xint
  668. X_pcmd_report_send_status()
  669. X{
  670. Xregister ushort ustmp;
  671. Xint erc = eFATAL_ALREADY;
  672. Xint iv0_set = 0;
  673. Xchar *signal_name_text();
  674. X
  675. X    ustmp = last_child_wait_status;
  676. X    if((ustmp & 0xFF) == 0)    /* exit() called */
  677. X    {
  678. X        ustmp >>= 8;
  679. X        if(!ustmp)
  680. X        {
  681. X            if(proctrace)
  682. X                pputs("transfer successful\n");
  683. X            erc = 0;
  684. X        }
  685. X        else if(ustmp == 255)
  686. X            pputs("ecu error: transfer program usage error\n");
  687. X        else if(ustmp == 254)
  688. X        {
  689. X            pputs(
  690. X            "protocol failure: bad line conditions or remote not ready\n");
  691. X        }
  692. X        else if(ustmp == 253)
  693. X            pputs("no requested files exist\n");
  694. X        else if(ustmp < 128)
  695. X        {
  696. X            if(proctrace)
  697. X            {
  698. X                if(ustmp == 127)
  699. X                    pputs("127 or more files skipped\n");
  700. X                else
  701. X                    pprintf("%u files rejected\n",ustmp);
  702. X            }
  703. X            iv[0] = (long)ustmp;
  704. X            iv0_set = 1;
  705. X            last_child_wait_status = 0;
  706. X            erc = 0;
  707. X        }
  708. X        else
  709. X        {
  710. X            pprintf("transfer aborted by %s\n",signal_name_text(ustmp & 0x7F));
  711. X            erc = eProcAttn_Interrupt;
  712. X        }
  713. X    }
  714. X    else
  715. X    {
  716. X        pprintf("transfer killed by %s\n",signal_name_text(ustmp & 0x7F));
  717. X        erc = eProcAttn_Interrupt;
  718. X    }
  719. X
  720. X    if(!iv0_set)
  721. X    {
  722. X        iv[0] = (last_child_wait_status & 0xFF)
  723. X            ? 0x100L : (long)((last_child_wait_status >> 8) & 0xFFFF);
  724. X    }
  725. X
  726. X    if(proctrace)
  727. X        pprintf("$i00 = %ld (transfer %s)\n",iv[0],
  728. X            (iv[0] == 0x100L) ? "interrupted" : "program exit status");
  729. X
  730. X    return(erc);
  731. X
  732. X}    /* end of _pcmd_report_send_status */
  733. X
  734. X/*+-------------------------------------------------------------------------
  735. X    _smart_sender_common(cmd) - common exec and bottom processing
  736. X
  737. Xfor "ecu knowledgeable" protocols only
  738. Xreturns proc-type erc
  739. X--------------------------------------------------------------------------*/
  740. Xint
  741. X_smart_sender_common(cmd)
  742. Xchar *cmd;
  743. X{
  744. Xint erc = 0;
  745. X
  746. X    last_child_wait_status = 0;
  747. X    file_xfer_start();
  748. X
  749. X    if(find_shell_chars(cmd))
  750. X    {
  751. X    char *expcmd;
  752. X
  753. X        if(expand_wildcard_list(cmd,&expcmd))
  754. X        {
  755. X            pputs("No files match wildcard list\n");
  756. X            iv[0] = -1;
  757. X            return(0);
  758. X        }
  759. X        else
  760. X        {
  761. X            exec_cmd(expcmd);
  762. X            erc = _pcmd_report_send_status();
  763. X            free(expcmd);
  764. X        }
  765. X    }
  766. X    else
  767. X    {
  768. X        exec_cmd(cmd);
  769. X        erc = _pcmd_report_send_status();
  770. X    }
  771. X
  772. X    lreset_ksr();
  773. X    file_xfer_done_bell();
  774. X
  775. X    return(erc);
  776. X
  777. X}    /* end of _smart_sender_common */
  778. X
  779. X/*+-------------------------------------------------------------------------
  780. X    pcmd_sx(param)
  781. X
  782. Xsx [-ak[l]] [<label-str>] <filelist-str>
  783. X--------------------------------------------------------------------------*/
  784. Xint
  785. Xpcmd_sx(param)
  786. XESD *param;
  787. X{
  788. Xint erc;
  789. Xchar switches[8];
  790. XESD *pathesd = (ESD *)0;
  791. XESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);
  792. X
  793. X    get_switches(param,switches,sizeof(switches));
  794. X
  795. X    if(erc = _make_bottom_label(param,!strchr(switches,'l'),1))
  796. X        return(erc);
  797. X
  798. X    /*
  799. X     * build command at beginning of 'cmdesd' ESD
  800. X     */
  801. X    sprintf(cmdesd->pb,"ecusz -X -. %d ",shm->Liofd);
  802. X    strcat(cmdesd->pb,bottom_label);
  803. X
  804. X#if defined(WHT)    /* for testing */
  805. X    if(strchr(switches,'p'))
  806. X        strcat(cmdesd->pb,"-, ");
  807. X#endif
  808. X
  809. X    if(strchr(switches,'a'))
  810. X        strcat(cmdesd->pb,"-a ");
  811. X
  812. X    if(strchr(switches,'k'))
  813. X        strcat(cmdesd->pb,"-k");
  814. X
  815. X    /*
  816. X     * update cmdesd esd
  817. X     */
  818. X    cmdesd->cb = strlen(cmdesd->pb);
  819. X
  820. X    if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))
  821. X    {
  822. X        erc = eNoMemory;
  823. X        goto FREE_MEM_AND_EXIT;
  824. X    }
  825. X
  826. X    /*
  827. X     * get list of pathnames to send
  828. X     */
  829. X    if(erc = gstr(param,pathesd,1))
  830. X        goto FREE_MEM_AND_EXIT;
  831. X
  832. X    /*
  833. X     * append filelist to command
  834. X     */
  835. X    if(erc = esdcat(cmdesd,pathesd,1))
  836. X        goto FREE_MEM_AND_EXIT;
  837. X
  838. X    /*
  839. X     * perform the operation
  840. X     */
  841. X    erc = _smart_sender_common(cmdesd->pb);
  842. X
  843. XFREE_MEM_AND_EXIT:
  844. X    if(pathesd)
  845. X        esdfree(pathesd);
  846. X    if(cmdesd)
  847. X        esdfree(cmdesd);
  848. X    return(erc);
  849. X
  850. X}    /* end of pcmd_sx */
  851. X
  852. X/*+-------------------------------------------------------------------------
  853. X    pcmd_sy(param)
  854. X
  855. Xsy [-a[l]] [<label-str>] <filelist-str>
  856. X--------------------------------------------------------------------------*/
  857. Xint
  858. Xpcmd_sy(param)
  859. XESD *param;
  860. X{
  861. Xint erc;
  862. Xchar switches[8];
  863. XESD *pathesd = (ESD *)0;
  864. XESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);
  865. X
  866. X    get_switches(param,switches,sizeof(switches));
  867. X
  868. X    if(erc = _make_bottom_label(param,!strchr(switches,'l'),1))
  869. X        return(erc);
  870. X
  871. X    /*
  872. X     * build command at beginning of 'cmdesd' ESD
  873. X     */
  874. X    sprintf(cmdesd->pb,"ecusz -Y -. %d -k ",shm->Liofd);
  875. X    strcat(cmdesd->pb,bottom_label);
  876. X    if(strchr(switches,'a'))
  877. X        strcat(cmdesd->pb,"-a ");
  878. X    else
  879. X        strcat(cmdesd->pb,"-b ");
  880. X
  881. X    /*
  882. X     * update cmdesd esd
  883. X     */
  884. X    cmdesd->cb = strlen(cmdesd->pb);
  885. X
  886. X    if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))
  887. X    {
  888. X        erc = eNoMemory;
  889. X        goto FREE_MEM_AND_EXIT;
  890. X    }
  891. X
  892. X    /*
  893. X     * get list of pathnames to send
  894. X     */
  895. X    if(erc = gstr(param,pathesd,1))
  896. X        goto FREE_MEM_AND_EXIT;
  897. X
  898. X    /*
  899. X     * append filelist to command
  900. X     */
  901. X    if(erc = esdcat(cmdesd,pathesd,1))
  902. X        goto FREE_MEM_AND_EXIT;
  903. X
  904. X    /*
  905. X     * perform the operation
  906. X     */
  907. X    erc = _smart_sender_common(cmdesd->pb);
  908. X
  909. XFREE_MEM_AND_EXIT:
  910. X    if(pathesd)
  911. X        esdfree(pathesd);
  912. X    if(cmdesd)
  913. X        esdfree(cmdesd);
  914. X    return(erc);
  915. X
  916. X}    /* end of pcmd_sy */
  917. X
  918. X/*+-------------------------------------------------------------------------
  919. X    pcmd_sz(param)
  920. X
  921. Xsz [-anf[l]] [<label-str>] <filelist-str>
  922. X-a ascii, else binary
  923. X-n send only newer, else all files
  924. X-f full, else simple pathnames
  925. X-r resume interrupted xfer
  926. X-l non-default bottom line label on transfer string
  927. X$i0 set to:
  928. X    0: file transfer completely successful
  929. X    -1 program did not run
  930. X--------------------------------------------------------------------------*/
  931. Xint
  932. Xpcmd_sz(param)
  933. XESD *param;
  934. X{
  935. Xint erc;
  936. Xchar switches[8];
  937. XESD *pathesd = (ESD *)0;
  938. XESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);
  939. X
  940. X    if(!cmdesd)
  941. X        return(eNoMemory);
  942. X
  943. X    get_switches(param,switches,sizeof(switches));
  944. X
  945. X    if(erc = _make_bottom_label(param,!strchr(switches,'l'),1))
  946. X        return(erc);
  947. X
  948. X    /*
  949. X     * build command at beginning of 'cmdesd' ESD
  950. X     */
  951. X    sprintf(cmdesd->pb,"ecusz -Z -. %d -y ",shm->Liofd);
  952. X    strcat(cmdesd->pb,bottom_label);
  953. X
  954. X    if(strchr(switches,'N'))        /* force "no curses" */
  955. X        strcat(cmdesd->pb,"-@ ");
  956. X
  957. X    if(strchr(switches,'a'))
  958. X        strcat(cmdesd->pb,"-a ");
  959. X
  960. X    if(strchr(switches,'n'))
  961. X        strcat(cmdesd->pb,"-n ");    /* overrides -y choice earlier */
  962. X
  963. X    if(strchr(switches,'f'))
  964. X        strcat(cmdesd->pb,"-f ");
  965. X
  966. X    if(strchr(switches,'r'))
  967. X        strcat(cmdesd->pb,"-r ");
  968. X
  969. X#if defined(WHT)    /* for testing */
  970. X    if(strchr(switches,'p'))
  971. X        strcat(cmdesd->pb,"-, ");
  972. X#endif
  973. X
  974. X    /*
  975. X     * update cmdesd esd
  976. X     */
  977. X    cmdesd->cb = strlen(cmdesd->pb);
  978. X
  979. X    if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))
  980. X    {
  981. X        erc = eNoMemory;
  982. X        goto FREE_MEM_AND_EXIT;
  983. X    }
  984. X
  985. X    /*
  986. X     * get list of pathnames to send
  987. X     */
  988. X    if(erc = gstr(param,pathesd,1))
  989. X        goto FREE_MEM_AND_EXIT;
  990. X
  991. X    /*
  992. X     * append filelist to command
  993. X     */
  994. X    if(erc = esdcat(cmdesd,pathesd,1))
  995. X        goto FREE_MEM_AND_EXIT;
  996. X
  997. X    /*
  998. X     * perform the operation
  999. X     */
  1000. X    erc = _smart_sender_common(cmdesd->pb);
  1001. X
  1002. XFREE_MEM_AND_EXIT:
  1003. X    if(pathesd)
  1004. X        esdfree(pathesd);
  1005. X    if(cmdesd)
  1006. X        esdfree(cmdesd);
  1007. X    return(erc);
  1008. X
  1009. X}    /* end of pcmd_sz */
  1010. X
  1011. X/*+-------------------------------------------------------------------------
  1012. X    pcmd_sk(param)
  1013. X
  1014. Xsk [-a] <str>
  1015. X--------------------------------------------------------------------------*/
  1016. Xint
  1017. Xpcmd_sk(param)
  1018. XESD *param;
  1019. X{
  1020. Xint erc;
  1021. Xchar switches[8];
  1022. XESD *pathesd = (ESD *)0;
  1023. XESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);
  1024. X
  1025. X    if(!cmdesd)
  1026. X        return(eNoMemory);
  1027. X
  1028. X    get_switches(param,switches,sizeof(switches));
  1029. X
  1030. X    /*
  1031. X     * build command at beginning of 'cmdesd' ESD
  1032. X     */
  1033. X    sprintf(cmdesd->pb,"ckermit -l %d -b %u -p %c%s%s -s ",
  1034. X        shm->Liofd,shm->Lbaud,
  1035. X        (shm->Lparity) ? shm->Lparity : 'n',
  1036. X        (strchr(switches,'a')) ? "" : " -i",
  1037. X        (1 /* overwrite*/ ) ? "" : " -w");
  1038. X
  1039. X    if(strchr(switches,'b'))
  1040. X        strcat(cmdesd->pb,"-a ");
  1041. X    else
  1042. X        strcat(cmdesd->pb,"-b ");
  1043. X
  1044. X    if(strchr(switches,'n'))
  1045. X        strcat(cmdesd->pb,"-n ");    /* overrides -y choice earlier */
  1046. X    if(strchr(switches,'f'))
  1047. X        strcat(cmdesd->pb,"-f ");
  1048. X
  1049. X    /*
  1050. X     * update cmdesd esd
  1051. X     */
  1052. X    cmdesd->cb = strlen(cmdesd->pb);
  1053. X
  1054. X    if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))
  1055. X    {
  1056. X        erc = eNoMemory;
  1057. X        goto FREE_MEM_AND_EXIT;
  1058. X    }
  1059. X
  1060. X    /*
  1061. X     * get list of pathnames to send
  1062. X     */
  1063. X    if(erc = gstr(param,pathesd,1))
  1064. X        goto FREE_MEM_AND_EXIT;
  1065. X
  1066. X    /*
  1067. X     * append filelist to command
  1068. X     */
  1069. X    if(erc = esdcat(cmdesd,pathesd,1))
  1070. X        goto FREE_MEM_AND_EXIT;
  1071. X
  1072. X    /*
  1073. X     * perform the operation
  1074. X     */
  1075. X    last_child_wait_status = 0;
  1076. X    if(exec_cmd(cmdesd->pb))
  1077. X        erc = eFATAL_ALREADY;
  1078. X
  1079. XFREE_MEM_AND_EXIT:
  1080. X    if(pathesd)
  1081. X        esdfree(pathesd);
  1082. X    if(cmdesd)
  1083. X        esdfree(cmdesd);
  1084. X
  1085. X    file_xfer_done_bell();
  1086. X    lreset_ksr();
  1087. X
  1088. X    return(_adjust_erc_and_iv0(erc));
  1089. X
  1090. X}    /* end of pcmd_sk */
  1091. X
  1092. X/*+-------------------------------------------------------------------------
  1093. X    pcmd_ss(param)
  1094. X--------------------------------------------------------------------------*/
  1095. Xint
  1096. Xpcmd_ss(param)
  1097. XESD *param;
  1098. X{
  1099. Xint erc;
  1100. XESD *pathesd = (ESD *)0;
  1101. XESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);
  1102. X
  1103. X    if(!cmdesd)
  1104. X        return(eNoMemory);
  1105. X
  1106. X    /*
  1107. X     * build command at beginning of 'cmdesd' ESD
  1108. X     */
  1109. X    sprintf(cmdesd->pb,"ecusea -. %d -/ %s -s ",shm->Liofd,curr_dir);
  1110. X
  1111. X    /*
  1112. X     * update cmdesd esd
  1113. X     */
  1114. X    cmdesd->cb = strlen(cmdesd->pb);
  1115. X
  1116. X    if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))
  1117. X    {
  1118. X        erc = eNoMemory;
  1119. X        goto FREE_MEM_AND_EXIT;
  1120. X    }
  1121. X
  1122. X    /*
  1123. X     * get list of pathnames to send
  1124. X     */
  1125. X    if(erc = gstr(param,pathesd,1))
  1126. X        goto FREE_MEM_AND_EXIT;
  1127. X
  1128. X    /*
  1129. X     * append filelist to command
  1130. X     */
  1131. X    if(erc = esdcat(cmdesd,pathesd,1))
  1132. X        goto FREE_MEM_AND_EXIT;
  1133. X
  1134. X    /*
  1135. X     * perform the operation
  1136. X     */
  1137. X    last_child_wait_status = 0;
  1138. X    if(exec_cmd(cmdesd->pb))
  1139. X        erc = eFATAL_ALREADY;
  1140. X
  1141. XFREE_MEM_AND_EXIT:
  1142. X    if(pathesd)
  1143. X        esdfree(pathesd);
  1144. X    if(cmdesd)
  1145. X        esdfree(cmdesd);
  1146. X
  1147. X    file_xfer_done_bell();
  1148. X    lreset_ksr();
  1149. X
  1150. X    return(_adjust_erc_and_iv0(erc));
  1151. X
  1152. X}    /* end of pcmd_ss */
  1153. X
  1154. X/*+-------------------------------------------------------------------------
  1155. X    pcmd_rx(param)
  1156. X
  1157. Xrx [-b] <str>
  1158. X--------------------------------------------------------------------------*/
  1159. Xint
  1160. Xpcmd_rx(param)
  1161. XESD *param;
  1162. X{
  1163. Xint erc = 0;
  1164. Xchar cmdstr[CMDSTR_SIZE];
  1165. Xchar switches[8];
  1166. XESD *pathesd = esdalloc(PATHESD_INITIAL_SIZE);
  1167. X
  1168. X    if(!pathesd)
  1169. X        return(eNoMemory);
  1170. X
  1171. X    get_switches(param,switches,sizeof(switches));
  1172. X
  1173. X    if(erc = gstr(param,pathesd,1))
  1174. X    {
  1175. X        esdfree(pathesd);
  1176. X        return(erc);
  1177. X    }
  1178. X
  1179. X    if(erc = _make_bottom_label(param,!strchr(switches,'l'),0))
  1180. X        return(erc);
  1181. X
  1182. X    /*
  1183. X     * build command in 'cmdstr' string
  1184. X     */
  1185. X    sprintf(cmdstr,"ecurz -X -. %d -c ",shm->Liofd);
  1186. X    strcat(cmdstr,bottom_label);
  1187. X    if(!strchr(switches,'b'))
  1188. X        strcat(cmdstr,"-b ");
  1189. X    else
  1190. X        strcat(cmdstr,"-a ");
  1191. X    strcat(cmdstr,pathesd->pb);
  1192. X    esdfree(pathesd);
  1193. X    file_xfer_start();
  1194. X
  1195. X    last_child_wait_status = 0;
  1196. X
  1197. X    if(exec_cmd(cmdstr))
  1198. X        erc = eFATAL_ALREADY;
  1199. X    else
  1200. X        erc = _adjust_erc_and_iv0(erc);
  1201. X
  1202. X    file_xfer_done_bell();
  1203. X    lreset_ksr();
  1204. X    return(erc);
  1205. X
  1206. X}    /* end of pcmd_rx */
  1207. X
  1208. X/*+-------------------------------------------------------------------------
  1209. X    pcmd_ry(param)
  1210. X
  1211. Xry
  1212. X--------------------------------------------------------------------------*/
  1213. Xint
  1214. Xpcmd_ry(param)
  1215. XESD *param;
  1216. X{
  1217. Xint erc = 0;
  1218. Xchar cmdstr[CMDSTR_SIZE];
  1219. Xchar switches[8];
  1220. X
  1221. X    get_switches(param,switches,sizeof(switches));
  1222. X
  1223. X    last_child_wait_status = 0;
  1224. X
  1225. X    if(erc = _make_bottom_label(param,!strchr(switches,'l'),0))
  1226. X        return(erc);
  1227. X
  1228. X    /*
  1229. X     * build command in 'cmdstr' string
  1230. X     */
  1231. X    sprintf(cmdstr,"ecurz -Y -. %d -y ",shm->Liofd);
  1232. X    strcat(cmdstr,bottom_label);
  1233. X    file_xfer_start();
  1234. X    if(exec_cmd(cmdstr))
  1235. X        erc = eFATAL_ALREADY;
  1236. X    else
  1237. X        erc = _adjust_erc_and_iv0(erc);
  1238. X
  1239. X    file_xfer_done_bell();
  1240. X    lreset_ksr();
  1241. X
  1242. X    return(erc);
  1243. X}    /* end of pcmd_ry */
  1244. X
  1245. X/*+-------------------------------------------------------------------------
  1246. X    pcmd_rz(param)
  1247. X--------------------------------------------------------------------------*/
  1248. Xint
  1249. Xpcmd_rz(param)
  1250. XESD *param;
  1251. X{
  1252. Xint erc = 0;
  1253. Xchar cmdstr[CMDSTR_SIZE];
  1254. Xchar switches[8];
  1255. X
  1256. X    get_switches(param,switches,sizeof(switches));
  1257. X
  1258. X    last_child_wait_status = 0;
  1259. X
  1260. X    if(erc = _make_bottom_label(param,!strchr(switches,'l'),0))
  1261. X        return(erc);
  1262. X
  1263. X    /*
  1264. X     * build command in 'cmdstr' string
  1265. X     */
  1266. X    sprintf(cmdstr,"ecurz -Z -. %d ",shm->Liofd);
  1267. X    strcat(cmdstr,bottom_label);
  1268. X
  1269. X    if(strchr(switches,'N'))        /* force "no curses" */
  1270. X        strcat(cmdstr,"-@ ");
  1271. X#if defined(WHT)    /* for testing */
  1272. X    if(strchr(switches,'c'))
  1273. X        strcat(cmdstr,"-: ");
  1274. X    if(strchr(switches,'p'))
  1275. X        strcat(cmdstr,"-, ");
  1276. X#endif
  1277. X    file_xfer_start();
  1278. X    if(exec_cmd(cmdstr))
  1279. X        erc = eFATAL_ALREADY;
  1280. X    else
  1281. X        erc = _adjust_erc_and_iv0(erc);
  1282. X
  1283. X    file_xfer_done_bell();
  1284. X    lreset_ksr();
  1285. X
  1286. X    return(erc);
  1287. X}    /* end of pcmd_rz */
  1288. X
  1289. X/*+-------------------------------------------------------------------------
  1290. X    pcmd_rk(param)
  1291. X
  1292. Xrk [-a]
  1293. X--------------------------------------------------------------------------*/
  1294. Xint
  1295. Xpcmd_rk(param)
  1296. XESD *param;
  1297. X{
  1298. Xint erc = 0;
  1299. Xchar cmdstr[CMDSTR_SIZE];
  1300. Xchar switches[8];
  1301. X
  1302. X    get_switches(param,switches,sizeof(switches));
  1303. X
  1304. X    last_child_wait_status = 0;
  1305. X    sprintf(cmdstr,"ckermit -r -e 512 -l %d -b %d -p %c",
  1306. X        shm->Liofd,shm->Lbaud,(shm->Lparity) ? shm->Lparity : 'n');
  1307. X    if(strchr(switches,'a'))
  1308. X        strcat(cmdstr,"-i ");
  1309. X    file_xfer_start();
  1310. X
  1311. X    if(exec_cmd(cmdstr))
  1312. X        erc = eFATAL_ALREADY;
  1313. X    else
  1314. X        erc = _adjust_erc_and_iv0(erc);
  1315. X
  1316. X    file_xfer_done_bell();
  1317. X    lreset_ksr();
  1318. X
  1319. X    return(erc);
  1320. X}    /* end of pcmd_rk */
  1321. X
  1322. X/*+-------------------------------------------------------------------------
  1323. X    pcmd_rs(param)
  1324. Xrs
  1325. X--------------------------------------------------------------------------*/
  1326. X/*ARGSUSED*/
  1327. Xint
  1328. Xpcmd_rs(param)
  1329. XESD *param;
  1330. X{
  1331. Xint erc = 0;
  1332. Xchar cmdstr[CMDSTR_SIZE];
  1333. X
  1334. X    file_xfer_start();
  1335. X    sprintf(cmdstr,"ecusea -r -. %d -/ %s",shm->Liofd,curr_dir);
  1336. X
  1337. X    if(exec_cmd(cmdstr))
  1338. X        erc = eFATAL_ALREADY;
  1339. X    else
  1340. X        erc = _adjust_erc_and_iv0(erc);
  1341. X
  1342. X    file_xfer_done_bell();
  1343. X    lreset_ksr();
  1344. X
  1345. X    return(erc);
  1346. X}    /* end of pcmd_rs */
  1347. X
  1348. X
  1349. X/* vi: set tabstop=4 shiftwidth=4: */
  1350. X/* end of pcmdxfer.c */
  1351. SHAR_EOF
  1352. chmod 0644 pcmdxfer.c ||
  1353. echo 'restore of pcmdxfer.c failed'
  1354. Wc_c="`wc -c < 'pcmdxfer.c'`"
  1355. test 16669 -eq "$Wc_c" ||
  1356.     echo 'pcmdxfer.c: original size 16669, current size' "$Wc_c"
  1357. rm -f _shar_wnt_.tmp
  1358. fi
  1359. # ============= poutput.c ==============
  1360. if test -f 'poutput.c' -a X"$1" != X"-c"; then
  1361.     echo 'x - skipping poutput.c (File already exists)'
  1362.     rm -f _shar_wnt_.tmp
  1363. else
  1364. > _shar_wnt_.tmp
  1365. echo 'x - extracting poutput.c (Text)'
  1366. sed 's/^X//' << 'SHAR_EOF' > 'poutput.c' &&
  1367. X/*+-------------------------------------------------------------------------
  1368. X    poutput.c - ecu procedure output routines
  1369. X    wht@n4hgf.Mt-Park.GA.US
  1370. X
  1371. X  Defined functions:
  1372. X    pcmd_plog(param)
  1373. X    pflush()
  1374. X    plog_control(fname)
  1375. X    plogc(ch)
  1376. X    plogs(str)
  1377. X    poutput_init()
  1378. X    pperror(str)
  1379. X    pputc(ch)
  1380. X    pputs(str)
  1381. X
  1382. X--------------------------------------------------------------------------*/
  1383. X/*+:EDITS:*/
  1384. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  1385. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  1386. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1387. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1388. X
  1389. X#include "ecu.h"
  1390. X#include "ecukey.h"
  1391. X#include "ecuerror.h"
  1392. X#include "esd.h"
  1393. X
  1394. Xextern int proctrace;
  1395. Xextern FILE *rcvr_log_fp;
  1396. X
  1397. XFILE *plog_fp = (FILE *)0;
  1398. XESD *plog_name = (ESD *)0;
  1399. X
  1400. X/*+-------------------------------------------------------------------------
  1401. X    plogs(str)
  1402. X--------------------------------------------------------------------------*/
  1403. Xvoid
  1404. Xplogs(str)
  1405. Xchar *str;
  1406. X{
  1407. X    if(plog_fp)
  1408. X        fputs(str,plog_fp);
  1409. X}    /* end of plogs */
  1410. X
  1411. X/*+-------------------------------------------------------------------------
  1412. X    plogc(ch)
  1413. X--------------------------------------------------------------------------*/
  1414. Xvoid
  1415. Xplogc(ch)
  1416. Xchar ch;
  1417. X{
  1418. X    if(plog_fp)
  1419. X        fputc(ch,plog_fp);
  1420. X}    /* end of plogc */
  1421. X
  1422. X/*+-------------------------------------------------------------------------
  1423. X    pputc(ch) - put procedure output character to stderr and log
  1424. X--------------------------------------------------------------------------*/
  1425. Xvoid
  1426. Xpputc(ch)
  1427. Xchar ch;
  1428. X{
  1429. X    if(ch == NL)
  1430. X        fputc(CRET,se);
  1431. X    fputc(ch,se);
  1432. X    if(plog_fp && (ch != CRET))
  1433. X        fputc(ch,plog_fp);
  1434. X    if(rcvr_log_fp && (ch != CRET))
  1435. X        fputc(ch,rcvr_log_fp);
  1436. X}    /* end of pputc */
  1437. X
  1438. X/*+-------------------------------------------------------------------------
  1439. X    pputs(str) - put procedure output string to stderr and log
  1440. X--------------------------------------------------------------------------*/
  1441. Xvoid
  1442. Xpputs(str)
  1443. Xregister char *str;
  1444. X{
  1445. X    while(*str)
  1446. X    {
  1447. X        if(*str == NL)
  1448. X            fputc(CRET,se);
  1449. X        fputc(*str,se);
  1450. X        if(plog_fp && (*str != CRET))
  1451. X            fputc(*str,plog_fp);
  1452. X        if(rcvr_log_fp && (*str != CRET))
  1453. X            fputc(*str,rcvr_log_fp);
  1454. X        str++;
  1455. X    }
  1456. X}    /* end of pputs */
  1457. X
  1458. X/*+-------------------------------------------------------------------------
  1459. X    pflush()
  1460. X--------------------------------------------------------------------------*/
  1461. Xvoid
  1462. Xpflush()
  1463. X{
  1464. X    if(plog_fp)
  1465. X        fflush(plog_fp);
  1466. X}    /* end of pflush */
  1467. X
  1468. X/*+-------------------------------------------------------------------------
  1469. X    pperror(str)
  1470. X--------------------------------------------------------------------------*/
  1471. Xvoid
  1472. Xpperror(str)
  1473. Xchar *str;
  1474. X{
  1475. Xint save_errno = errno;
  1476. X
  1477. X    if(str && *str)
  1478. X    {
  1479. X        pputs(str);
  1480. X        pputs(": ");
  1481. X    }
  1482. X    pputs(errno_text(save_errno));
  1483. X    pputs("\n");
  1484. X}    /* end of pperror */
  1485. X
  1486. X/*+-------------------------------------------------------------------------
  1487. X    plog_control(fname)
  1488. X fname == 0, close
  1489. X fname == 1, plog_name already plugged
  1490. X--------------------------------------------------------------------------*/
  1491. Xint
  1492. Xplog_control(fname)
  1493. Xchar *fname;
  1494. X{
  1495. X    if(!fname)    /* close */
  1496. X    {
  1497. X        if(plog_fp)
  1498. X            fclose(plog_fp);
  1499. X        plog_fp = (FILE *)0;
  1500. X        return(0);
  1501. X    }
  1502. X
  1503. X    if(plog_fp)
  1504. X        plog_control((char *)0);
  1505. X
  1506. X    if(fname != (char *)1)
  1507. X    {
  1508. X        strcpy(plog_name->pb,fname);
  1509. X        plog_name->cb = strlen(fname);
  1510. X    }
  1511. X
  1512. X    if((plog_fp = fopen(plog_name->pb,"a")) == NULL)
  1513. X    {
  1514. X        pperror(plog_name->pb);
  1515. X        return(eFATAL_ALREADY);
  1516. X    }
  1517. X    return(0);
  1518. X}    /* end of plog_control */
  1519. X
  1520. X/*+-------------------------------------------------------------------------
  1521. X    pcmd_plog(param)
  1522. X
  1523. Xplog $s0     log to file
  1524. Xplog off     stop logging
  1525. Xplog         show status
  1526. X--------------------------------------------------------------------------*/
  1527. Xint
  1528. Xpcmd_plog(param)
  1529. XESD *param;
  1530. X{
  1531. Xint erc = eSyntaxError;
  1532. Xchar off_str[8];
  1533. X
  1534. X    if(!skip_cmd_break(param))    /* if arguments */
  1535. X    {
  1536. X        if(!get_alpha_zstr(param,off_str,sizeof(off_str)))
  1537. X        {
  1538. X            if(strcmp(off_str,"off"))
  1539. X                return(eBadParameter);
  1540. X            erc = plog_control((char *)0);
  1541. X        }
  1542. X        else
  1543. X        {
  1544. X            if(erc = gstr(param,plog_name,1))
  1545. X                return(erc);
  1546. X            erc = plog_control((char *)1);
  1547. X        }
  1548. X    }
  1549. X    return(erc);
  1550. X
  1551. X}    /* end of pcmd_plog */
  1552. X
  1553. X/*+-------------------------------------------------------------------------
  1554. X    poutput_init()
  1555. X--------------------------------------------------------------------------*/
  1556. Xvoid
  1557. Xpoutput_init()
  1558. X{
  1559. X    if((plog_name = esdalloc(256)) == (ESD *)0)
  1560. X    {
  1561. X        ff(se,"Out of memory\r\n");
  1562. X        termecu(TERMECU_MALLOC);
  1563. X    }
  1564. X}    /* end of poutput_init */
  1565. X
  1566. X/* vi: set tabstop=4 shiftwidth=4: */
  1567. X/* end of poutput.c */
  1568. SHAR_EOF
  1569. chmod 0644 poutput.c ||
  1570. echo 'restore of poutput.c failed'
  1571. Wc_c="`wc -c < 'poutput.c'`"
  1572. test 4481 -eq "$Wc_c" ||
  1573.     echo 'poutput.c: original size 4481, current size' "$Wc_c"
  1574. rm -f _shar_wnt_.tmp
  1575. fi
  1576. # ============= pprintf.c ==============
  1577. if test -f 'pprintf.c' -a X"$1" != X"-c"; then
  1578.     echo 'x - skipping pprintf.c (File already exists)'
  1579.     rm -f _shar_wnt_.tmp
  1580. else
  1581. > _shar_wnt_.tmp
  1582. echo 'x - extracting pprintf.c (Text)'
  1583. sed 's/^X//' << 'SHAR_EOF' > 'pprintf.c' &&
  1584. X/*+-------------------------------------------------------------------------
  1585. X    pprintf.c - procedure printf
  1586. X
  1587. X  This module has been hacked a bit to work for ECU applications
  1588. X  as of its writing.  If you use this with SCO MSC, the ifdefs
  1589. X  will work in any environment.  Using it without any SCO
  1590. X  predefines will cause %p to print as a 32-bit linear pointer.
  1591. X  M_I286 assumes %p is a segmented pointer unless M_SDATA is
  1592. X  supplied too, in which case %p prints as a 16-bit segment offset.
  1593. X--------------------------------------------------------------------------*/
  1594. X/*+:EDITS:*/
  1595. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  1596. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  1597. X/*:08-21-1991-02:12-wht@n4hgf-handle char *sprintf */
  1598. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1599. X/*:01-09-1991-22:31-wht@n4hgf-ISC port */
  1600. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1601. X
  1602. X/* based on Portable vsprintf  by Robert A. Larson <blarson@skat.usc.edu> */
  1603. X
  1604. X/* Copyright 1989 Robert A. Larson.
  1605. X * Distribution in any form is allowed as long as the author
  1606. X * retains credit, changes are noted by their author and the
  1607. X * copyright message remains intact.  This program comes as-is
  1608. X * with no warentee of fitness for any purpouse.
  1609. X *
  1610. X * Thanks to Doug Gwen, Chris Torek, and others who helped clarify
  1611. X * the ansi printf specs.
  1612. X *
  1613. X * Please send any bug fixes and improvments to blarson@skat.usc.edu .
  1614. X * The use of goto is NOT a bug.
  1615. X */
  1616. X
  1617. X#if !defined(BUILDING_PROTOTYPES)
  1618. X
  1619. X#include <stdio.h>
  1620. X#include <varargs.h>
  1621. X
  1622. X#if defined(M_I386) || defined(i386)
  1623. X#define LONGINT
  1624. X#endif
  1625. X
  1626. X/* This must be a typedef not a #define! */
  1627. X#define NOVOID
  1628. X#if defined(NOVOID)
  1629. Xtypedef char *pointer;
  1630. X#else
  1631. Xtypedef void *pointer;
  1632. X#endif
  1633. X
  1634. Xtypedef int *intp;
  1635. X
  1636. X/*+-------------------------------------------------------------------------
  1637. X    pprintf(format,va_alist)
  1638. X--------------------------------------------------------------------------*/
  1639. Xvoid
  1640. Xpprintf(format,va_alist)
  1641. Xregister char *format;
  1642. Xva_dcl
  1643. X{
  1644. Xva_list args;
  1645. Xregister char c;
  1646. Xregister char *tp;
  1647. Xchar tempfmt[64];
  1648. X#if !defined(LONGINT)
  1649. Xint longflag;
  1650. X#endif
  1651. Xchar accum_string[256];
  1652. Xregister char *dp = accum_string;
  1653. X
  1654. X    va_start(args);
  1655. X
  1656. X    tempfmt[0] = '%';
  1657. X    while(c = *format++)
  1658. X    {
  1659. X        if(c=='%')
  1660. X        {
  1661. X            tp = &tempfmt[1];
  1662. X#if !defined(LONGINT)
  1663. X            longflag = 0;
  1664. X#endif
  1665. Xcontinue_format:
  1666. X            switch(c = *format++)
  1667. X            {
  1668. X            case 's':
  1669. X                *tp++ = c;
  1670. X                *tp = '\0';
  1671. X#if defined(INT_SPRINTF)
  1672. X                dp += sprintf(dp,tempfmt,va_arg(args,char *));
  1673. X#else
  1674. X                sprintf(dp,tempfmt,va_arg(args,char *));
  1675. X                dp += strlen(dp);
  1676. X#endif
  1677. X                break;
  1678. X            case 'u':
  1679. X            case 'x':
  1680. X            case 'o':
  1681. X            case 'X':
  1682. X#if defined(UNSIGNEDSPECIAL)
  1683. X                *tp++ = c;
  1684. X                *tp = '\0';
  1685. X#if !defined(LONGINT)
  1686. X                if(longflag)
  1687. X                {
  1688. X#if defined(INT_SPRINTF)
  1689. X                    dp += sprintf(dp,tempfmt,va_arg(args,unsigned long));
  1690. X#else
  1691. X                    sprintf(dp,tempfmt,va_arg(args,unsigned long));
  1692. X                    dp += strlen(dp);
  1693. X#endif
  1694. X                }
  1695. X                else
  1696. X#endif /* LONGINT */
  1697. X                {
  1698. X#if defined(INT_SPRINTF)
  1699. X                    dp += sprintf(dp,tempfmt,va_arg(args,unsigned));
  1700. X#else
  1701. X                    sprintf(dp,tempfmt,va_arg(args,unsigned));
  1702. X                    dp += strlen(dp);
  1703. X#endif
  1704. X                break;
  1705. X#endif
  1706. X            case 'd':
  1707. X            case 'c':
  1708. X            case 'i':
  1709. X                *tp++ = c;
  1710. X                *tp = '\0';
  1711. X#if !defined(LONGINT)
  1712. X                if(longflag)
  1713. X                {
  1714. X#if defined(INT_SPRINTF)
  1715. X                    dp += sprintf(dp,tempfmt,va_arg(args,long));
  1716. X#else
  1717. X                    sprintf(dp,tempfmt,va_arg(args,long));
  1718. X                    dp += strlen(dp);
  1719. X#endif
  1720. X                }
  1721. X                else
  1722. X#endif
  1723. X                {
  1724. X#if defined(INT_SPRINTF)
  1725. X                    dp += sprintf(dp,tempfmt,va_arg(args,int));
  1726. X#else
  1727. X                    sprintf(dp,tempfmt,va_arg(args,int));
  1728. X                    dp += strlen(dp);
  1729. X#endif
  1730. X                }
  1731. X                break;
  1732. X            case 'f':
  1733. X            case 'e':
  1734. X            case 'E':
  1735. X            case 'g':
  1736. X            case 'G':
  1737. X                *tp++ = c;
  1738. X                *tp = '\0';
  1739. X#if defined(INT_SPRINTF)
  1740. X                dp += sprintf(dp,tempfmt,va_arg(args,double));
  1741. X#else
  1742. X                sprintf(dp,tempfmt,va_arg(args,double));
  1743. X                dp += strlen(dp);
  1744. X#endif
  1745. X                break;
  1746. X            case 'p':
  1747. X#if defined(M_I286)
  1748. X                tp = va_arg(args,pointer);
  1749. X#if defined(M_SDATA)
  1750. X                dp += sprintf(dp,"0x%04x",tp);
  1751. X#else
  1752. X                dp += sprintf(dp,"%04x:%04x",(int)tp,(int)((long)tp >> 16));
  1753. X#endif /* M_SDATA */
  1754. X#else
  1755. X#if defined(INT_SPRINTF)
  1756. X                dp += sprintf(dp,"0x%08lx",va_arg(args,pointer));
  1757. X#else
  1758. X                sprintf(dp,"0x%08lx",va_arg(args,pointer));
  1759. X                dp += strlen(dp);
  1760. X#endif
  1761. X#endif /* M_I286 */
  1762. X                break;
  1763. X            case '-':
  1764. X            case '+':
  1765. X            case '0':
  1766. X            case '1':
  1767. X            case '2':
  1768. X            case '3':
  1769. X            case '4':
  1770. X            case '5':
  1771. X            case '6':
  1772. X            case '7':
  1773. X            case '8':
  1774. X            case '9':
  1775. X            case '.':
  1776. X            case ' ':
  1777. X            case '#':
  1778. X            case 'h':
  1779. X                *tp++ = c;
  1780. X                goto continue_format;
  1781. X            case 'l':
  1782. X#if !defined(LONGINT)
  1783. X                longflag = 1;
  1784. X                *tp++ = c;
  1785. X#endif
  1786. X                goto continue_format;
  1787. X            case '*':
  1788. X#if defined(INT_SPRINTF)
  1789. X                tp += sprintf(tp,"%d",va_arg(args,int));
  1790. X#else
  1791. X                printf(tp,"%d",va_arg(args,int));
  1792. X                tp += strlen(tp);
  1793. X#endif
  1794. X                goto continue_format;
  1795. X            case '%':
  1796. X            default:
  1797. X                *dp++ = c;
  1798. X                break;
  1799. X            }
  1800. X        }
  1801. X        else *dp++ = c;
  1802. X    }
  1803. X    *dp = '\0';
  1804. X    va_end(args);
  1805. X    pputs(accum_string);
  1806. X}    /* end of pprintf */
  1807. X#endif /* !defined(BUILDING_PROTOTYPES) */
  1808. X
  1809. X/* vi: set tabstop=4 shiftwidth=4: */
  1810. X/* end of pprintf.c */
  1811. SHAR_EOF
  1812. chmod 0644 pprintf.c ||
  1813. echo 'restore of pprintf.c failed'
  1814. Wc_c="`wc -c < 'pprintf.c'`"
  1815. test 5047 -eq "$Wc_c" ||
  1816.     echo 'pprintf.c: original size 5047, current size' "$Wc_c"
  1817. rm -f _shar_wnt_.tmp
  1818. fi
  1819. # ============= proc.c ==============
  1820. if test -f 'proc.c' -a X"$1" != X"-c"; then
  1821.     echo 'x - skipping proc.c (File already exists)'
  1822.     rm -f _shar_wnt_.tmp
  1823. else
  1824. > _shar_wnt_.tmp
  1825. echo 'x - extracting proc.c (Text)'
  1826. sed 's/^X//' << 'SHAR_EOF' > 'proc.c' &&
  1827. X/*+-------------------------------------------------------------------------
  1828. X    proc.c - procedure command and control
  1829. X    wht@n4hgf.Mt-Park.GA.US
  1830. X
  1831. X  Defined functions:
  1832. X    _cmd_gosub_common(param,type)
  1833. X    _get_goto_label(param)
  1834. X    do_proc(argc,argv)
  1835. X    dump_proc(pcb)
  1836. X    execute_esd(tesd)
  1837. X    execute_goto(pcb,goto_type)
  1838. X    execute_labelled_esd(tesd)
  1839. X    execute_proc(pcb,use_goto_label)
  1840. X    find_labelled_lcb(label,first,last)
  1841. X    find_proc_cmd(cmd_list,cmd)
  1842. X    find_procedure(name)
  1843. X    free_lcb_chain(lcb)
  1844. X    pcmd_do(param)
  1845. X    pcmd_gosub(param)
  1846. X    pcmd_gosubb(param)
  1847. X    pcmd_goto(param)
  1848. X    pcmd_gotob(param)
  1849. X    pcmd_return(param)
  1850. X    pcmd_upon(param)
  1851. X    proc_dcdloss_handler(pcb)
  1852. X    show_error_position(pcb)
  1853. X    trace_proc_cmd(pcb)
  1854. X
  1855. X--------------------------------------------------------------------------*/
  1856. X/*+:EDITS:*/
  1857. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  1858. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  1859. X/*:11-16-1991-15:39-wht@n4hgf2-add pcmd_upon stub */
  1860. X/*:11-16-1991-14:53-wht@n4hgf2-add proc_dcdloss_handler */
  1861. X/*:11-16-1991-14:01-wht@n4hgf-calloc pcb instead of malloc */
  1862. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1863. X/*:07-01-1991-01:53-wht@n4hgf-fix return with value */
  1864. X/*:05-01-1991-04:18-wht@n4hgf-new find_procedure failed on home subdir match */
  1865. X/*:04-30-1991-03:19-root@n4hgf-add search for .ep in ecu lib ep subdir */
  1866. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1867. X
  1868. X#include "ecu.h"
  1869. X#include "ecuerror.h"
  1870. X#include "ecukey.h"
  1871. X#include "esd.h"
  1872. X#include "var.h"
  1873. X#include "proc.h"
  1874. X
  1875. X#define NEED_P_CMD
  1876. X#include "ecucmd.h"
  1877. X
  1878. XPCB *pcb_stack[PROC_STACK_MAX];
  1879. X
  1880. Xint proc_level = 0;
  1881. Xint proctrace = 0;
  1882. X
  1883. Xchar goto_label[64];
  1884. X
  1885. X/*+-------------------------------------------------------------------------
  1886. X    _get_goto_label(param)
  1887. X--------------------------------------------------------------------------*/
  1888. Xint
  1889. X_get_goto_label(param)
  1890. XESD *param;
  1891. X{
  1892. X    register erc;
  1893. X    register ESD *label_esd;
  1894. X
  1895. X    goto_label[0] = 0;
  1896. X    if(erc = get_alphanum_zstr(param,goto_label,sizeof(goto_label)))
  1897. X    {
  1898. X        if((label_esd = esdalloc(64)) == (ESD *)0)
  1899. X            return(eNoMemory);
  1900. X        if(!(erc = gstr(param,label_esd,0)))
  1901. X            strcpy(goto_label,label_esd->pb);
  1902. X        esdfree(label_esd);
  1903. X    }
  1904. X
  1905. X    return(erc);
  1906. X
  1907. X}    /* end of _get_goto_label */
  1908. X
  1909. X/*+-------------------------------------------------------------------------
  1910. X    pcmd_goto(param)
  1911. X--------------------------------------------------------------------------*/
  1912. Xint
  1913. Xpcmd_goto(param)
  1914. XESD *param;
  1915. X{
  1916. X
  1917. X    if(!proc_level)
  1918. X        return(eNotExecutingProc);
  1919. X    if(_get_goto_label(param))
  1920. X        return(eInvalidLabel);
  1921. X    return(eProcAttn_GOTO);
  1922. X
  1923. X}    /* end of pcmd_goto */
  1924. X
  1925. X/*+-------------------------------------------------------------------------
  1926. X    pcmd_gotob(param)
  1927. X--------------------------------------------------------------------------*/
  1928. Xint
  1929. Xpcmd_gotob(param)
  1930. XESD *param;
  1931. X{
  1932. X
  1933. X    if(!proc_level)
  1934. X        return(eNotExecutingProc);
  1935. X    if(_get_goto_label(param))
  1936. X        return(eInvalidLabel);
  1937. X    return(eProcAttn_GOTOB);
  1938. X
  1939. X}    /* end of pcmd_gotob */
  1940. X
  1941. X/*+-------------------------------------------------------------------------
  1942. X    _cmd_gosub_common(param,type)
  1943. X--------------------------------------------------------------------------*/
  1944. Xint
  1945. X_cmd_gosub_common(param,type)
  1946. XESD *param;
  1947. Xint type;
  1948. X{
  1949. X    int erc;
  1950. X    LCB *current_save;
  1951. X    int index_save;
  1952. X
  1953. X    if(_get_goto_label(param))
  1954. X        return(eInvalidLabel);
  1955. X    current_save = pcb_stack[proc_level - 1]->current;
  1956. X    index_save = current_save->text->index;
  1957. X    if(!(erc = execute_proc(pcb_stack[proc_level - 1],type)))
  1958. X    {
  1959. X        pcb_stack[proc_level - 1]->current = current_save;
  1960. X        current_save->text->index = index_save;
  1961. X    }
  1962. X    return(erc);
  1963. X
  1964. X}    /* end of _cmd_gosub_common */
  1965. X
  1966. X/*+-------------------------------------------------------------------------
  1967. X    pcmd_gosub(param)
  1968. X--------------------------------------------------------------------------*/
  1969. Xint
  1970. Xpcmd_gosub(param)
  1971. XESD *param;
  1972. X{
  1973. X    if(!proc_level)
  1974. X        return(eNotExecutingProc);
  1975. X    return(_cmd_gosub_common(param,eProcAttn_GOTO));
  1976. X}    /* end of pcmd_gosub */
  1977. X
  1978. X/*+-------------------------------------------------------------------------
  1979. X    pcmd_return(param)
  1980. X--------------------------------------------------------------------------*/
  1981. Xint
  1982. Xpcmd_upon(param)
  1983. XESD *param;
  1984. X{
  1985. X    pprintf("'upon' not implimented\n");
  1986. X    param->index = param->cb;
  1987. X    return(0);
  1988. X}    /* end of pcmd_return */
  1989. X
  1990. X/*+-------------------------------------------------------------------------
  1991. X    pcmd_gosubb(param)
  1992. X--------------------------------------------------------------------------*/
  1993. Xint
  1994. Xpcmd_gosubb(param)
  1995. XESD *param;
  1996. X{
  1997. X    if(!proc_level)
  1998. X        return(eNotExecutingProc);
  1999. X    return(_cmd_gosub_common(param,eProcAttn_GOTO));
  2000. X}    /* end of pcmd_gosubb */
  2001. X
  2002. X/*+-------------------------------------------------------------------------
  2003. X    pcmd_return(param)
  2004. X--------------------------------------------------------------------------*/
  2005. Xint
  2006. Xpcmd_return(param)
  2007. XESD *param;
  2008. X{
  2009. X    long value = 0;
  2010. X    if(!gint(param,&value))
  2011. X    {
  2012. X        if((value < 0) || (value > 255))
  2013. X            value = 255;
  2014. X        if(proctrace)
  2015. X            pprintf("return value %ld\n",value);
  2016. X        if(value)
  2017. X            value += e_USER;
  2018. X        return((int)value);
  2019. X    }
  2020. X    return(eProcAttn_RETURN);
  2021. X}    /* end of pcmd_return */
  2022. X
  2023. X/*+-------------------------------------------------------------------------
  2024. X    find_labelled_lcb(label,first,last)
  2025. Xsearch for match between label
  2026. X--------------------------------------------------------------------------*/
  2027. XLCB *
  2028. Xfind_labelled_lcb(label,first,last)
  2029. Xchar *label;
  2030. Xregister LCB *first;
  2031. XLCB *last;
  2032. X{
  2033. X    register llen = strlen(label);
  2034. X    ESD *text;
  2035. X
  2036. X    while(first)
  2037. X    {
  2038. X        text = first->text;
  2039. X        if((text->cb >= llen) && (!strncmp(text->pb,label,llen))
  2040. X            && (!text->pb[llen] || isspace(text->pb[llen])))
  2041. X            return(first);
  2042. X
  2043. X        if(first == last)
  2044. X            return((LCB *)0);
  2045. X        first = first->next;
  2046. X    }
  2047. X    pputs("find_labelled_lab logic error\n");
  2048. X    return((LCB *)0);
  2049. X
  2050. X}    /* end of find_labelled_lcb */
  2051. X
  2052. X/*+-------------------------------------------------------------------------
  2053. X    execute_goto(pcb,goto_type)
  2054. X--------------------------------------------------------------------------*/
  2055. Xexecute_goto(pcb,goto_type)
  2056. XPCB *pcb;
  2057. Xint goto_type;
  2058. X{
  2059. X    LCB *next = (LCB *)0;    /* next lcb to execute */
  2060. X
  2061. X    switch(goto_type)
  2062. X    {
  2063. X        case eProcAttn_GOTO:
  2064. X            if(!(next = find_labelled_lcb(goto_label,pcb->current,pcb->last)))
  2065. X                next = find_labelled_lcb(goto_label,pcb->first,pcb->current);
  2066. X            break;
  2067. X        case eProcAttn_GOTOB:
  2068. X            if(!(next = find_labelled_lcb(goto_label,pcb->first,pcb->current)))
  2069. X                next = find_labelled_lcb(goto_label,pcb->current,pcb->last);
  2070. X            break;
  2071. X    }
  2072. X    if(next)
  2073. X    {
  2074. X        pcb->current = next;
  2075. X        return(0);
  2076. X    }
  2077. X    pprintf("goto/gosub label not found: %s\n",goto_label);
  2078. X    return(eFATAL_ALREADY);
  2079. X
  2080. X}    /* end of execute_goto */
  2081. X
  2082. X/*+-------------------------------------------------------------------------
  2083. X    show_error_position(pcb)
  2084. Xcursor MUST be at left margin when this is called
  2085. X--------------------------------------------------------------------------*/
  2086. Xvoid
  2087. Xshow_error_position(pcb)
  2088. XPCB *pcb;
  2089. X{
  2090. X    ESD *tesd = pcb->current->text;
  2091. X    register itmp = tesd->old_index;
  2092. X    char tag[64];
  2093. X
  2094. X    sprintf(tag,"%s %u> ",pcb->argv[0],pcb->current->lineno);
  2095. X    pputs(tag);
  2096. X    pputs(tesd->pb);
  2097. X    pputs("\n");
  2098. X    itmp = strlen(tag) + tesd->old_index;
  2099. X    while(itmp--)
  2100. X        pputc(' ');
  2101. X    pputs("^\n");
  2102. X
  2103. X}    /* end of show_error_position */
  2104. X
  2105. X/*+-------------------------------------------------------------------------
  2106. X    find_proc_cmd(cmd_list,cmd)
  2107. X--------------------------------------------------------------------------*/
  2108. XP_CMD *
  2109. Xfind_proc_cmd(cmd_list,cmd)
  2110. Xregister P_CMD *cmd_list;
  2111. Xregister char *cmd;
  2112. X{
  2113. X    while(cmd_list->token != -1)
  2114. X    {
  2115. X        if(!strcmp(cmd_list->cmd,cmd))
  2116. X            break;
  2117. X        cmd_list++;
  2118. X    }
  2119. X    return((cmd_list->token == -1) ? (P_CMD *)0 : cmd_list);
  2120. X
  2121. X}    /* end of find_proc_cmd */
  2122. X
  2123. X/*+-------------------------------------------------------------------------
  2124. X    execute_esd(tesd)
  2125. X--------------------------------------------------------------------------*/
  2126. Xint
  2127. Xexecute_esd(tesd)
  2128. XESD *tesd;
  2129. X{
  2130. X    int erc;
  2131. X    P_CMD *pcmd;
  2132. X    static P_CMD *set_pcmd = (P_CMD *)0;    /* quick access to 'set' */
  2133. X    char cmd[32];
  2134. X    extern int proc_interrupt;
  2135. X
  2136. X    /* if interrupt, exit */
  2137. X    if(sigint | proc_interrupt)
  2138. X        return(eCONINT);
  2139. X
  2140. X    /* if blank, skip it */
  2141. X    if(skip_cmd_break(tesd))
  2142. X        return(0);
  2143. X
  2144. X    /* if comment, skip it */
  2145. X    if(!skip_cmd_char(tesd,'#'))
  2146. X        return(0);
  2147. X
  2148. X    if(*(tesd->pb + tesd->index) == '{')
  2149. X    {
  2150. X        pputs("invalid '{'\n");
  2151. X        return(eFATAL_ALREADY);
  2152. X    }
  2153. X
  2154. X    while(1)
  2155. X    {
  2156. X        /* get command -- allow leading '$' to assume 'set' command */
  2157. X        if(*(tesd->pb + tesd->index) == '$')
  2158. X        {
  2159. X            /* find 'set' in the list -- save for rapid access later */
  2160. X            if(set_pcmd)
  2161. X                pcmd = set_pcmd;
  2162. X            else if((pcmd = find_proc_cmd(icmd_cmds,"set")) == (P_CMD *)0)
  2163. X                return(eInternalLogicError);
  2164. X            else
  2165. X                set_pcmd = pcmd;
  2166. X        }
  2167. X        else
  2168. X        {
  2169. X            if(get_alphanum_zstr(tesd,cmd,sizeof(cmd)))
  2170. X                return(eIllegalCommand);
  2171. X            /* find it in the list */
  2172. X            if((pcmd = find_proc_cmd(icmd_cmds,cmd)) == (P_CMD *)0)
  2173. X                return(eIllegalCommand);
  2174. X        }
  2175. X
  2176. X        /* check to see if this command available for procedure */
  2177. X        if(!pcmd->proc)
  2178. X            return(eInteractiveCmd);
  2179. X
  2180. X        /* execute the command */
  2181. X        if(erc = (*pcmd->proc)(tesd))
  2182. X            return(erc);
  2183. X
  2184. X        /* look for comment */
  2185. X        if(!skip_cmd_char(tesd,'#'))
  2186. X            break;
  2187. X
  2188. X        /* look for multiple commands on line */
  2189. X        if(skip_cmd_char(tesd,';'))
  2190. X            break;
  2191. X
  2192. X        /* if blank after ';', skip it */
  2193. X        if(skip_cmd_break(tesd))
  2194. X            break;
  2195. X    }
  2196. X    return(0);
  2197. X        
  2198. X}    /* end of execute_esd */
  2199. X
  2200. X/*+-------------------------------------------------------------------------
  2201. X    execute_labelled_esd(tesd)
  2202. X--------------------------------------------------------------------------*/
  2203. Xexecute_labelled_esd(tesd)
  2204. XESD *tesd;
  2205. X{
  2206. X    register index = 0;
  2207. X    register cb = tesd->cb;
  2208. X    register char *pb = tesd->pb;
  2209. X
  2210. X/* reset indices */
  2211. X    tesd->index = index;
  2212. X    tesd->old_index = index;
  2213. X
  2214. X/* if comment, skip it */
  2215. X    if(!skip_cmd_char(tesd,'#'))
  2216. X        return(0);
  2217. X
  2218. X/* skip over any label */
  2219. X    while(!isspace(*(pb + index)) && (index < cb))
  2220. X        index++;
  2221. X    tesd->index = index;
  2222. X    tesd->old_index = index;
  2223. X
  2224. X    return(execute_esd(tesd));
  2225. X}    /* end of execute_labelled_esd */
  2226. X
  2227. X/*+-------------------------------------------------------------------------
  2228. X    dump_proc(pcb)
  2229. X--------------------------------------------------------------------------*/
  2230. X#if 0
  2231. Xvoid
  2232. Xdump_proc(pcb)
  2233. XPCB *pcb;
  2234. X{
  2235. X    int itmp;
  2236. X    LCB *lcb;
  2237. X
  2238. X    pprintf("------ pcb @ 0x%08lx -----------------\n",pcb);
  2239. X    pprintf("argc=%d first=0x%08lx last=0x%08lx\n",pcb->argc,
  2240. X        pcb->first,pcb->last);
  2241. X    for(itmp = 0; itmp < pcb->argc; itmp++)
  2242. X    {
  2243. X        pprintf("argv(%d) @ 0x%lx: '%s'\n",itmp,pcb->argv[itmp],
  2244. X            pcb->argv[itmp]);
  2245. X    }
  2246. X    pputs("\n");
  2247. X    lcb = pcb->first;
  2248. X    while(lcb)
  2249. X    {
  2250. X        pprintf("lcb @ 0x%08lx   lineno=%u\n",lcb,lcb->lineno);
  2251. X        pputs("\n");
  2252. X        lcb = lcb->next;
  2253. X    }
  2254. X    pflush();
  2255. X}    /* end of dump_proc */
  2256. X#endif
  2257. X
  2258. X/*+-------------------------------------------------------------------------
  2259. X    trace_proc_cmd(pcb) - if asked, show command
  2260. X--------------------------------------------------------------------------*/
  2261. Xvoid
  2262. Xtrace_proc_cmd(pcb)
  2263. XPCB *pcb;
  2264. X{
  2265. X    if(proctrace)
  2266. X    {
  2267. X        pprintf("%s %u> ",pcb->argv[0],pcb->current->lineno);
  2268. X        pputs(pcb->current->text->pb);
  2269. X        pputc('\n');
  2270. X    }
  2271. X
  2272. X}    /* end of trace_proc_cmd */
  2273. X
  2274. X/*+-------------------------------------------------------------------------
  2275. X    proc_dcdloss_handler(pcb) - a statement execution found DCD loss
  2276. X--------------------------------------------------------------------------*/
  2277. Xint
  2278. Xproc_dcdloss_handler(pcb)
  2279. XPCB *pcb;
  2280. X{
  2281. X    int erc = 0;
  2282. X    int itmp;
  2283. X    ESD esdcopy;
  2284. X    ESD *tesd;
  2285. X
  2286. X    if(pcb->upon_dcdloss.pb)
  2287. X    {
  2288. X        esdcopy = pcb->upon_dcdloss;    /* a copy to preserve pcb->index */    
  2289. X        tesd = &esdcopy;
  2290. X        if(proctrace)
  2291. X        {
  2292. X            pprintf("%s DCDLOSS> ",pcb->argv[0]);
  2293. X            pputs(tesd->pb + tesd->index);
  2294. X            pputc('\n');
  2295. X        }
  2296. X        if(erc = execute_esd(tesd))
  2297. X        {
  2298. X            if(erc != eFATAL_ALREADY)
  2299. X                proc_error(erc);
  2300. X            pprintf("error in 'upon dcdloss' statement\n");
  2301. X            pputs(tesd->pb + pcb->upon_dcdloss.index);
  2302. X            pputs("\n");
  2303. X            itmp = tesd->old_index - pcb->upon_dcdloss.index;;
  2304. X            while(itmp--)
  2305. X                pputc(' ');
  2306. X            pputs("^\ninvoked while executing:\n");
  2307. X            erc = eFATAL_ALREADY;
  2308. X        }
  2309. X    }
  2310. X    else    /* DCD watch enabled but no 'upon dcdloss' in effect */
  2311. X    {
  2312. X        pprintf("Connection terminated during procedure execution\n");
  2313. X        pputs("while executing:\n");
  2314. X        erc = eFATAL_ALREADY;
  2315. X    }
  2316. X    return(erc);
  2317. X}    /* end of proc_dcdloss_handler */
  2318. X
  2319. X/*+-------------------------------------------------------------------------
  2320. X    execute_proc(pcb,use_goto_label) - execute a memory-resident procedure
  2321. X--------------------------------------------------------------------------*/
  2322. Xexecute_proc(pcb,use_goto_label)
  2323. XPCB *pcb;
  2324. Xint use_goto_label;
  2325. X{
  2326. X    int erc = 0;
  2327. X    extern int proc_interrupt;
  2328. X
  2329. X    if(proc_level == PROC_STACK_MAX)
  2330. X        return(eProcStackTooDeep);
  2331. X
  2332. X    pcb_stack[proc_level++] = pcb;
  2333. X    if(use_goto_label)
  2334. X    {
  2335. X        if(erc = execute_goto(pcb,use_goto_label))
  2336. X            return(erc);
  2337. X    }
  2338. X    else
  2339. X        pcb->current = pcb->first;
  2340. X
  2341. X    mkv_proc_starting(pcb);
  2342. X
  2343. X    while(pcb->current)
  2344. X    {
  2345. X        /* execute the command */
  2346. X        trace_proc_cmd(pcb);
  2347. X        if(erc = execute_labelled_esd(pcb->current->text))
  2348. X        {
  2349. X            /* handle other classes of errors */
  2350. X            switch(erc & 0xF000)
  2351. X            {
  2352. X                case e_WARNING:        /* warning */
  2353. X                    erc = 0;
  2354. X                    break;
  2355. X
  2356. X                case e_FATAL:        /* fatal */
  2357. X                    goto PROC_RETURN;
  2358. X
  2359. X                case e_ProcAttn:    /* proc attention */
  2360. X                    switch(erc)
  2361. X                    {
  2362. X                        case eProcAttn_GOTO:
  2363. X                        case eProcAttn_GOTOB:
  2364. X                            if(erc = execute_goto(pcb,erc))
  2365. X                                break;    /* didn't find it */
  2366. X                            continue;    /* pcb->current is now goto target */
  2367. X
  2368. X                        case eProcAttn_RETURN:
  2369. X                            erc = 0;
  2370. X                            break;
  2371. X
  2372. X                        case eProcAttn_Interrupt:
  2373. X                        case eProcAttn_ESCAPE:
  2374. X                            pprintf(
  2375. X                                "procedure %s interrupted.\n",pcb->argv[0]);
  2376. X                            erc = eFATAL_ALREADY;
  2377. X                            break;
  2378. X
  2379. X                        case eProcAttn_DCDloss:
  2380. X                            erc = proc_dcdloss_handler(pcb);
  2381. X                            break;
  2382. X
  2383. X                        default:
  2384. X                            pprintf("procedure error 0x%x\n",erc);
  2385. X                            erc = eFATAL_ALREADY;
  2386. X                            break;
  2387. X                    }
  2388. X                    goto PROC_RETURN;
  2389. X
  2390. X                default:    /* must be proc return error code */
  2391. X                    goto PROC_RETURN;
  2392. X            }
  2393. X        }
  2394. X
  2395. X        if(sigint || proc_interrupt)
  2396. X        {
  2397. X            proc_interrupt = 0;
  2398. X            sigint = 0;
  2399. X            pprintf("procedure %s interrupted\n",pcb->argv[0]);
  2400. X            erc = eFATAL_ALREADY;
  2401. X        }
  2402. X
  2403. X        if(erc)
  2404. X            break;
  2405. X        pcb->current = pcb->current->next;
  2406. X    }
  2407. X
  2408. XPROC_RETURN:
  2409. X    mkv_proc_terminating(pcb);
  2410. X    if(erc)
  2411. X    {
  2412. X        if((erc > 0) && (erc < e_USER))
  2413. X        {
  2414. X            pprintf(">>procedure %s returned %d\n",pcb->argv[0],erc);
  2415. X            erc |= e_USER;
  2416. X        }
  2417. X        else if((erc > e_USER) && (erc <= 0x1FFF))
  2418. X        {
  2419. X            ;    /* already said it */
  2420. X        }
  2421. X        else
  2422. X        {
  2423. X            if(erc != eFATAL_ALREADY)
  2424. X            {
  2425. X                proc_error(erc);
  2426. X                erc = eFATAL_ALREADY;
  2427. X            }
  2428. X            show_error_position(pcb);
  2429. X        }
  2430. X    }
  2431. X    pcb_stack[--proc_level] = (PCB *)0;
  2432. X#if 0
  2433. X    if(erc && !proc_level)
  2434. X        plog_control((char *)0);
  2435. X#endif
  2436. X    return(erc);
  2437. X}    /* end of execute_proc */
  2438. X
  2439. X/*+-------------------------------------------------------------------------
  2440. X    free_lcb_chain(lcb)
  2441. X--------------------------------------------------------------------------*/
  2442. Xvoid
  2443. Xfree_lcb_chain(lcb)
  2444. Xregister LCB *lcb;
  2445. X{
  2446. X    LCB *plcb;
  2447. X
  2448. X    while(lcb)
  2449. X    {
  2450. X        if(lcb->text)
  2451. X            esdfree(lcb->text);
  2452. X        plcb  = lcb;
  2453. X        lcb = lcb->next;
  2454. X        free((char *)plcb);
  2455. X    }
  2456. X
  2457. X}    /* end of free_lcb_chain */
  2458. X
  2459. X/*+-------------------------------------------------------------------------
  2460. X    find_procedure(name) - find procedure if it exists
  2461. X--------------------------------------------------------------------------*/
  2462. Xchar *
  2463. Xfind_procedure(name)
  2464. Xchar *name;
  2465. X{
  2466. X    static char procpath[256];
  2467. X
  2468. X/*
  2469. X * try to find proc file in current directory
  2470. X */
  2471. X    strcpy(procpath,name);
  2472. X    strcat(procpath,".ep");
  2473. X    if(!access(procpath,4))
  2474. X        return(procpath);
  2475. X    if(proctrace && (errno != ENOENT))
  2476. X        pperror(procpath);
  2477. X
  2478. X/*
  2479. X * try to find proc file in home .ecu subdirectory
  2480. X */
  2481. X    get_home_dir(procpath);
  2482. X    strcat(procpath,"/.ecu/");
  2483. X    strcat(procpath,name);
  2484. X    strcat(procpath,".ep");
  2485. X    if(!access(procpath,4))
  2486. X        return(procpath);
  2487. X    if(proctrace && (errno != ENOENT))
  2488. X        pperror(procpath);
  2489. X
  2490. X/*
  2491. X * try to find proc file in library ep subdirectory
  2492. X */
  2493. X    strcpy(procpath,ECULIBDIR);
  2494. X    strcat(procpath,"/ep/");
  2495. X    strcat(procpath,name);
  2496. X    strcat(procpath,".ep");
  2497. X    if(!access(procpath,4))
  2498. X        return(procpath);
  2499. X    if(proctrace && (errno != ENOENT) && (errno != ENOTDIR))
  2500. X        pperror(procpath);
  2501. X
  2502. X/*
  2503. X * no luck
  2504. X */
  2505. X    return((char *)0);
  2506. X
  2507. X}    /* end of find_procedure */
  2508. X
  2509. X/*+-------------------------------------------------------------------------
  2510. X    do_proc(argc,argv) - read in a disk-based procedure and execute it
  2511. X--------------------------------------------------------------------------*/
  2512. SHAR_EOF
  2513. true || echo 'restore of proc.c failed'
  2514. fi
  2515. echo 'End of ecu320 part 20'
  2516. echo 'File proc.c is continued in part 21'
  2517. echo 21 > _shar_seq_.tmp
  2518. exit 0
  2519.  
  2520. exit 0 # Just in case...
  2521.