home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / ecu / part20 < prev    next >
Encoding:
Text File  |  1992-09-13  |  56.9 KB  |  2,515 lines

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