home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume16 / ecu3 / part14 < prev    next >
Internet Message Format  |  1991-01-06  |  49KB

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i038:  ECU async comm package rev 3.0, Part14/35
  4. Message-ID: <1991Jan6.052202.27970@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:22:02 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 79bf8233 8714f8f2 43e8b8aa ac7fecbd
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 38
  11. Archive-name: ecu3/part14
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 14 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= pcmdxfer.c ==============
  21. echo 'x - extracting pcmdxfer.c (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'pcmdxfer.c' &&
  23. X/*+-------------------------------------------------------------------------
  24. X    pcmdxfer.c - ecu file transfer related procedure commands
  25. X    wht@n4hgf.Mt-Park.GA.US
  26. X
  27. X  Defined functions:
  28. X    _make_bottom_label(param,default_flag,sending_flag)
  29. X    _rx_error()
  30. X    _send_common(execcmd)
  31. X    pcmd_rk(param)
  32. X    pcmd_rs(param)
  33. X    pcmd_rx(param)
  34. X    pcmd_ry(param)
  35. X    pcmd_rz(param)
  36. X    pcmd_sk(param)
  37. X    pcmd_ss(param)
  38. X    pcmd_sx(param)
  39. X    pcmd_sy(param)
  40. X    pcmd_sz(param)
  41. X
  42. X--------------------------------------------------------------------------*/
  43. X/*+:EDITS:*/
  44. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  45. X
  46. X#include "ecu.h"
  47. X#include "ecukey.h"
  48. X#include "ecuerror.h"
  49. X#include "esd.h"
  50. X#include "var.h"
  51. X#include "proc.h"
  52. X
  53. Xchar *strchr();
  54. X
  55. Xextern int proctrace;
  56. Xextern int last_child_wait_status;
  57. Xextern char curr_dir[];
  58. Xextern proc_level;
  59. Xextern PCB *pcb_stack[];
  60. X
  61. Xstatic char bottom_label[80];
  62. X
  63. X/*+-------------------------------------------------------------------------
  64. X    _make_bottom_label(param,default_flag)
  65. X--------------------------------------------------------------------------*/
  66. X_make_bottom_label(param,default_flag,sending_flag)
  67. XESD *param;
  68. Xint default_flag;
  69. Xint sending_flag;
  70. X{
  71. Xregister erc;
  72. XESD *label = (ESD *)0;
  73. X
  74. X    if(default_flag)
  75. X    {
  76. X        sprintf(bottom_label,
  77. X            (sending_flag) ? "-C \"'Connected to %s'\" "
  78. X                           : "-C 'Connected to %s' ",
  79. X            (shm->Lrname[0]) ? shm->Lrname : "?");
  80. X        return(0);
  81. X    }
  82. X    if((label = make_esd(64)) == (ESD *)0)
  83. X        return(eNoMemory);
  84. X    if(erc = gstr(param,label,0))
  85. X    {
  86. X        free_esd(label);
  87. X        return(erc);
  88. X    }
  89. X    strcpy(bottom_label,(sending_flag) ? "-C \"'" : "-C '");
  90. X    strcat(bottom_label,label->pb);
  91. X    strcat(bottom_label,(sending_flag) ? "'\"" : "'");
  92. X    free_esd(label);
  93. X    return(0);
  94. X
  95. X}    /* end of _make_bottom_label */
  96. X
  97. X/*+-------------------------------------------------------------------------
  98. X    _send_common(execcmd)
  99. Xfor "ecu knowledgeable" protocols only
  100. X--------------------------------------------------------------------------*/
  101. Xint
  102. X_send_common(execcmd)
  103. Xchar *execcmd;
  104. X{
  105. Xint erc = 0;
  106. X
  107. X    file_xfer_start();
  108. X    if(find_shell_chars(execcmd))
  109. X    {
  110. X    char *expcmd;
  111. X
  112. X        if(expand_cmd_with_wildlist(execcmd,&expcmd))
  113. X        {
  114. X            pputs("No files match wildcard list\n");
  115. X            iv[0] = -1;
  116. X            return(0);
  117. X        }
  118. X        else
  119. X        {
  120. X            if(exec_cmd(expcmd))
  121. X                erc = eFATAL_ALREADY;
  122. X            free(expcmd);
  123. X        }
  124. X    }
  125. X    else
  126. X    {
  127. X        if(exec_cmd(execcmd))
  128. X            erc = eFATAL_ALREADY;
  129. X    }
  130. X    lreset_ksr();
  131. X    file_xfer_done_bell();
  132. X    if(erc)
  133. X        return(erc);
  134. X    erc = report_send_status();
  135. X    if(!erc)
  136. X        iv[0] = 0;
  137. X    if(erc == eProcAttn_Interrupt)
  138. X    {
  139. X        erc = 0;
  140. X        iv[0] = 0x100L;
  141. X    }
  142. X    return(erc);
  143. X        
  144. X
  145. X}    /* end of _send_common */
  146. X
  147. X/*+-------------------------------------------------------------------------
  148. X    pcmd_sx(param)
  149. X
  150. Xsx [-ak[l]] [<label-str>] <filelist-str>
  151. X--------------------------------------------------------------------------*/
  152. Xint
  153. Xpcmd_sx(param)
  154. XESD *param;
  155. X{
  156. Xint erc;
  157. Xchar execcmd[384];
  158. Xchar switches[8];
  159. XESD *pathlist;
  160. X
  161. X    get_switches(param,switches,sizeof(switches));
  162. X
  163. X    if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,1))
  164. X        return(erc);
  165. X
  166. X    sprintf(execcmd,"ecusz -X -. %d ",shm->Liofd);
  167. X    strcat(execcmd,bottom_label);
  168. X    if(strchr(switches,'a'))
  169. X        strcat(execcmd,"-a ");
  170. X    else
  171. X        strcat(execcmd,"-b ");
  172. X    if(strchr(switches,'k'))
  173. X        strcat(execcmd,"-k");
  174. X
  175. X    if((pathlist = make_esd(256)) == (ESD *)0)
  176. X        return(eNoMemory);
  177. X
  178. X    if(erc = gstr(param,pathlist,1))
  179. X    {
  180. X        free_esd(pathlist);
  181. X        return(erc);
  182. X    }
  183. X
  184. X    strcat(execcmd,pathlist->pb);
  185. X    free_esd(pathlist);
  186. X    return(_send_common(execcmd));
  187. X
  188. X}    /* end of pcmd_sx */
  189. X
  190. X/*+-------------------------------------------------------------------------
  191. X    pcmd_sy(param)
  192. X
  193. Xsy [-a[l]] [<label-str>] <filelist-str>
  194. X--------------------------------------------------------------------------*/
  195. Xint
  196. Xpcmd_sy(param)
  197. XESD *param;
  198. X{
  199. Xint erc;
  200. Xchar execcmd[384];
  201. Xchar switches[8];
  202. XESD *pathlist;
  203. X
  204. X    get_switches(param,switches,sizeof(switches));
  205. X
  206. X    if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,1))
  207. X        return(erc);
  208. X
  209. X    sprintf(execcmd,"ecusz -Y -. %d -k ",shm->Liofd);
  210. X    strcat(execcmd,bottom_label);
  211. X    if(strchr(switches,'a'))
  212. X        strcat(execcmd,"-a ");
  213. X    else
  214. X        strcat(execcmd,"-b ");
  215. X
  216. X    if((pathlist = make_esd(256)) == (ESD *)0)
  217. X        return(eNoMemory);
  218. X
  219. X    if(erc = gstr(param,pathlist,1))
  220. X    {
  221. X        free_esd(pathlist);
  222. X        return(erc);
  223. X    }
  224. X
  225. X    strcat(execcmd,pathlist->pb);
  226. X    free_esd(pathlist);
  227. X    return(_send_common(execcmd));
  228. X
  229. X}    /* end of pcmd_sy */
  230. X
  231. X/*+-------------------------------------------------------------------------
  232. X    pcmd_sz(param)
  233. X
  234. Xsz [-anf[l]] [<label-str>] <filelist-str>
  235. X-a ascii, else binary
  236. X-n send only newer, else all files
  237. X-f full, else simple pathnames
  238. X-l non-default bottom line label on transfer string
  239. X$i0 set to:
  240. X    0: file transfer completely successful
  241. X    -1 program did not run
  242. X--------------------------------------------------------------------------*/
  243. Xint
  244. Xpcmd_sz(param)
  245. XESD *param;
  246. X{
  247. Xint erc;
  248. Xchar execcmd[384];
  249. Xchar switches[8];
  250. XESD *pathlist;
  251. X
  252. X    get_switches(param,switches,sizeof(switches));
  253. X
  254. X    if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,1))
  255. X        return(erc);
  256. X
  257. X    sprintf(execcmd,"ecusz -Z -. %d -y ",shm->Liofd);
  258. X    strcat(execcmd,bottom_label);
  259. X    if(strchr(switches,'a'))
  260. X        strcat(execcmd,"-a ");
  261. X    else
  262. X        strcat(execcmd,"-b ");
  263. X    if(strchr(switches,'n'))
  264. X        strcat(execcmd,"-n ");    /* overrides -y choice earlier */
  265. X    if(strchr(switches,'f'))
  266. X        strcat(execcmd,"-f ");
  267. X
  268. X#ifdef WHT    /* for testing */
  269. X    if(strchr(switches,'p'))
  270. X        strcat(execcmd,"-, ");
  271. X    if(strchr(switches,'n'))
  272. X        strcat(execcmd,"-@ ");
  273. X#endif
  274. X
  275. X    if((pathlist = make_esd(256)) == (ESD *)0)
  276. X        return(eNoMemory);
  277. X
  278. X    if(erc = gstr(param,pathlist,1))
  279. X    {
  280. X        free_esd(pathlist);
  281. X        return(erc);
  282. X    }
  283. X
  284. X    strcat(execcmd,pathlist->pb);
  285. X    free_esd(pathlist);
  286. X    return(_send_common(execcmd));
  287. X
  288. X}    /* end of pcmd_sz */
  289. X
  290. X/*+-------------------------------------------------------------------------
  291. X    pcmd_sk(param)
  292. X
  293. Xsk [-a] <str>
  294. X--------------------------------------------------------------------------*/
  295. Xint
  296. Xpcmd_sk(param)
  297. XESD *param;
  298. X{
  299. Xint erc;
  300. Xchar execcmd[384];
  301. XESD *pathlist;
  302. Xchar switches[8];
  303. X
  304. X    get_switches(param,switches,sizeof(switches));
  305. X
  306. X    sprintf(execcmd,"ckermit -l %d -b %u -p %c%s%s -s ",
  307. X        shm->Liofd,shm->Lbaud,
  308. X        (shm->Lparity) ? shm->Lparity : 'n',
  309. X        (strchr(switches,'a')) ? "" : " -i",
  310. X        (1 /* overwrite*/ ) ? "" : " -w");
  311. X
  312. X    if(strchr(switches,'b'))
  313. X        strcat(execcmd,"-a ");
  314. X    else
  315. X        strcat(execcmd,"-b ");
  316. X    if(strchr(switches,'n'))
  317. X        strcat(execcmd,"-n ");    /* overrides -y choice earlier */
  318. X    if(strchr(switches,'f'))
  319. X        strcat(execcmd,"-f ");
  320. X
  321. X    if((pathlist = make_esd(256)) == (ESD *)0)
  322. X        return(eNoMemory);
  323. X
  324. X    if(erc = gstr(param,pathlist,1))
  325. X    {
  326. X        free_esd(pathlist);
  327. X        return(erc);
  328. X    }
  329. X
  330. X    file_xfer_start();
  331. X    strcat(execcmd,pathlist->pb);
  332. X    free_esd(pathlist);
  333. X    if(exec_cmd(execcmd))
  334. X        erc = eFATAL_ALREADY;
  335. X    file_xfer_done_bell();
  336. X    lreset_ksr();
  337. X    return(erc);
  338. X}    /* end of pcmd_sk */
  339. X
  340. X/*+-------------------------------------------------------------------------
  341. X    pcmd_ss(param)
  342. X--------------------------------------------------------------------------*/
  343. Xint
  344. Xpcmd_ss(param)
  345. XESD *param;
  346. X{
  347. Xint erc;
  348. Xchar execcmd[384];
  349. XESD *pathlist;
  350. X
  351. X    sprintf(execcmd,"ecusea -. %d -/ %s -s ",shm->Liofd,curr_dir);
  352. X    if((pathlist = make_esd(256)) == (ESD *)0)
  353. X        return(eNoMemory);
  354. X
  355. X    if(erc = gstr(param,pathlist,1))
  356. X    {
  357. X        free_esd(pathlist);
  358. X        return(erc);
  359. X    }
  360. X
  361. X    strcat(execcmd,pathlist->pb);
  362. X    free_esd(pathlist);
  363. X    return(_send_common(execcmd));
  364. X
  365. X}    /* end of pcmd_ss */
  366. X
  367. X/*+-------------------------------------------------------------------------
  368. X    _rx_error()
  369. X--------------------------------------------------------------------------*/
  370. Xvoid
  371. X_rx_error()
  372. X{
  373. Xextern int last_child_wait_status;
  374. X
  375. X    iv[0] = (last_child_wait_status & 0xFF)
  376. X            ? 0x100L : (long)last_child_wait_status >> 8;
  377. X    if(proctrace)
  378. X        pprintf("$i00 = %ld, (%s)\n",iv[0],
  379. X            (iv[0] == 0x100L) ? "interrupted" : "program exit status");
  380. X    file_xfer_done_bell();
  381. X}    /* end of _rx_error */
  382. X
  383. X/*+-------------------------------------------------------------------------
  384. X    pcmd_rx(param)
  385. X
  386. Xrx [-b] <str>
  387. X--------------------------------------------------------------------------*/
  388. Xint
  389. Xpcmd_rx(param)
  390. XESD *param;
  391. X{
  392. Xint erc = 0;
  393. Xchar execcmd[512];
  394. Xchar switches[8];
  395. XESD *tesd = make_esd(256);
  396. X
  397. X    if(!tesd)
  398. X        return(eNoMemory);
  399. X
  400. X    get_switches(param,switches,sizeof(switches));
  401. X
  402. X    if(erc = gstr(param,tesd,1))
  403. X    {
  404. X        free_esd(tesd);
  405. X        return(erc);
  406. X    }
  407. X
  408. X    last_child_wait_status = 0;
  409. X    if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,0))
  410. X        return(erc);
  411. X
  412. X    sprintf(execcmd,"ecurz -X -. %d -c ",shm->Liofd);
  413. X    strcat(execcmd,bottom_label);
  414. X    if(!strchr(switches,'b'))
  415. X        strcat(execcmd,"-b ");
  416. X    else
  417. X        strcat(execcmd,"-a ");
  418. X    strcat(execcmd,tesd->pb);
  419. X    free_esd(tesd);
  420. X    file_xfer_start();
  421. X    if(exec_cmd(execcmd))
  422. X        erc = eFATAL_ALREADY;
  423. X    else
  424. X        _rx_error();
  425. X    return(erc);
  426. X}    /* end of pcmd_rx */
  427. X
  428. X/*+-------------------------------------------------------------------------
  429. X    pcmd_ry(param)
  430. X
  431. Xry
  432. X--------------------------------------------------------------------------*/
  433. Xint
  434. Xpcmd_ry(param)
  435. XESD *param;
  436. X{
  437. Xint erc = 0;
  438. Xchar execcmd[512];
  439. Xchar switches[8];
  440. X
  441. X    get_switches(param,switches,sizeof(switches));
  442. X
  443. X    if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,0))
  444. X        return(erc);
  445. X
  446. X    last_child_wait_status = 0;
  447. X    sprintf(execcmd,"ecurz -Y -. %d -y ",shm->Liofd);
  448. X    strcat(execcmd,bottom_label);
  449. X    file_xfer_start();
  450. X    if(exec_cmd(execcmd))
  451. X        erc = eFATAL_ALREADY;
  452. X    else
  453. X        _rx_error();
  454. X    return(erc);
  455. X}    /* end of pcmd_ry */
  456. X
  457. X/*+-------------------------------------------------------------------------
  458. X    pcmd_rz(param)
  459. X--------------------------------------------------------------------------*/
  460. Xint
  461. Xpcmd_rz(param)
  462. XESD *param;
  463. X{
  464. Xint erc = 0;
  465. Xchar execcmd[512];
  466. Xchar switches[8];
  467. X
  468. X    get_switches(param,switches,sizeof(switches));
  469. X
  470. X    if(erc = _make_bottom_label(param,strchr(switches,'l') == (char *)0,0))
  471. X        return(erc);
  472. X
  473. X    last_child_wait_status = 0;
  474. X    sprintf(execcmd,"ecurz -Z -. %d ",shm->Liofd);
  475. X#ifdef WHT    /* for testing */
  476. X    if(strchr(switches,'c'))
  477. X        strcat(execcmd,"-: ");
  478. X    if(strchr(switches,'p'))
  479. X        strcat(execcmd,"-, ");
  480. X    if(strchr(switches,'n'))
  481. X        strcat(execcmd,"-@ ");
  482. X#endif
  483. X    strcat(execcmd,bottom_label);
  484. X    file_xfer_start();
  485. X    if(exec_cmd(execcmd))
  486. X        erc = eFATAL_ALREADY;
  487. X    else
  488. X        _rx_error();
  489. X    return(erc);
  490. X}    /* end of pcmd_rz */
  491. X
  492. X/*+-------------------------------------------------------------------------
  493. X    pcmd_rk(param)
  494. X
  495. Xrk [-a]
  496. X--------------------------------------------------------------------------*/
  497. Xint
  498. Xpcmd_rk(param)
  499. XESD *param;
  500. X{
  501. Xint erc = 0;
  502. Xchar execcmd[300];
  503. Xchar switches[8];
  504. X
  505. X    get_switches(param,switches,sizeof(switches));
  506. X
  507. X    last_child_wait_status = 0;
  508. X    sprintf(execcmd,"ckermit -r -e 512 -l %d -b %d -p %c",
  509. X        shm->Liofd,shm->Lbaud,(shm->Lparity) ? shm->Lparity : 'n');
  510. X    if(strchr(switches,'a'))
  511. X        strcat(execcmd,"-i ");
  512. X    file_xfer_start();
  513. X    if(exec_cmd(execcmd))
  514. X        erc = eFATAL_ALREADY;
  515. X    file_xfer_done_bell();
  516. X    return(erc);
  517. X}    /* end of pcmd_rk */
  518. X
  519. X/*+-------------------------------------------------------------------------
  520. X    pcmd_rs(param)
  521. X
  522. Xrs
  523. X--------------------------------------------------------------------------*/
  524. Xint
  525. Xpcmd_rs(param)
  526. XESD *param;
  527. X{
  528. Xint erc = 0;
  529. Xchar execcmd[128];
  530. X
  531. X    file_xfer_start();
  532. X    sprintf(execcmd,"ecusea -r -. %d -/ %s",shm->Liofd,curr_dir);
  533. X    if(exec_cmd(execcmd))
  534. X        erc = eFATAL_ALREADY;
  535. X    file_xfer_done_bell();
  536. X    return(erc);
  537. X}    /* end of pcmd_rs */
  538. X
  539. X
  540. X/* vi: set tabstop=4 shiftwidth=4: */
  541. X/* end of pcmdxfer.c */
  542. SHAR_EOF
  543. $TOUCH -am 1224224290 'pcmdxfer.c' &&
  544. chmod 0644 pcmdxfer.c ||
  545. echo 'restore of pcmdxfer.c failed'
  546. Wc_c="`wc -c < 'pcmdxfer.c'`"
  547. test 11327 -eq "$Wc_c" ||
  548.     echo 'pcmdxfer.c: original size 11327, current size' "$Wc_c"
  549. # ============= poutput.c ==============
  550. echo 'x - extracting poutput.c (Text)'
  551. sed 's/^X//' << 'SHAR_EOF' > 'poutput.c' &&
  552. X/*+-------------------------------------------------------------------------
  553. X    poutput.c - ecu procedure output routines
  554. X    wht@n4hgf.Mt-Park.GA.US
  555. X
  556. X  Defined functions:
  557. X    pcmd_plog(param)
  558. X    pperror(str)
  559. X    pputc(ch)
  560. X    pputs(str)
  561. X
  562. X--------------------------------------------------------------------------*/
  563. X/*+:EDITS:*/
  564. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  565. X
  566. X#include "ecu.h"
  567. X#include "ecukey.h"
  568. X#include "ecuerror.h"
  569. X#include "esd.h"
  570. X
  571. Xextern int proctrace;
  572. Xextern FILE *rcvr_log_fp;
  573. X
  574. XFILE *plog_fp = (FILE *)0;
  575. XESD *plog_name = (ESD *)0;
  576. X
  577. X/*+-------------------------------------------------------------------------
  578. X    plogs(str)
  579. X--------------------------------------------------------------------------*/
  580. Xvoid
  581. Xplogs(str)
  582. Xchar *str;
  583. X{
  584. X    if(plog_fp)
  585. X        fputs(str,plog_fp);
  586. X}    /* end of plogs */
  587. X
  588. X/*+-------------------------------------------------------------------------
  589. X    plogc(ch)
  590. X--------------------------------------------------------------------------*/
  591. Xvoid
  592. Xplogc(ch)
  593. Xchar ch;
  594. X{
  595. X    if(plog_fp)
  596. X        fputc(ch,plog_fp);
  597. X}    /* end of plogc */
  598. X
  599. X/*+-------------------------------------------------------------------------
  600. X    pputc(ch) - put procedure output character to stderr and log
  601. X--------------------------------------------------------------------------*/
  602. Xvoid
  603. Xpputc(ch)
  604. Xchar ch;
  605. X{
  606. X    if(ch == NL)
  607. X        fputc(CR,se);
  608. X    fputc(ch,se);
  609. X    if(plog_fp && (ch != CR))
  610. X        fputc(ch,plog_fp);
  611. X    if(rcvr_log_fp && (ch != CR))
  612. X        fputc(ch,rcvr_log_fp);
  613. X}    /* end of pputc */
  614. X
  615. X/*+-------------------------------------------------------------------------
  616. X    pputs(str) - put procedure output string to stderr and log
  617. X--------------------------------------------------------------------------*/
  618. Xvoid
  619. Xpputs(str)
  620. Xregister char *str;
  621. X{
  622. X    while(*str)
  623. X    {
  624. X        if(*str == NL)
  625. X            fputc(CR,se);
  626. X        fputc(*str,se);
  627. X        if(plog_fp && (*str != CR))
  628. X            fputc(*str,plog_fp);
  629. X        if(rcvr_log_fp && (*str != CR))
  630. X            fputc(*str,rcvr_log_fp);
  631. X        str++;
  632. X    }
  633. X}    /* end of pputs */
  634. X
  635. X/*+-------------------------------------------------------------------------
  636. X    pflush()
  637. X--------------------------------------------------------------------------*/
  638. Xvoid
  639. Xpflush()
  640. X{
  641. X    if(plog_fp)
  642. X        fflush(plog_fp);
  643. X}    /* end of pflush */
  644. X
  645. X/*+-------------------------------------------------------------------------
  646. X    pperror(str)
  647. X--------------------------------------------------------------------------*/
  648. Xvoid
  649. Xpperror(str)
  650. Xchar *str;
  651. X{
  652. Xextern char *sys_errlist[];
  653. Xextern int sys_nerr;
  654. Xextern int errno;
  655. Xint save_errno = errno;
  656. X
  657. X    if(str && *str)
  658. X    {
  659. X        pputs(str);
  660. X        pputs(": ");
  661. X    }
  662. X    if(save_errno <= sys_nerr)
  663. X        pputs(sys_errlist[save_errno]);
  664. X    else
  665. X        pprintf("error %d",save_errno);
  666. X    pputs("\n");
  667. X}    /* end of pperror */
  668. X
  669. X/*+-------------------------------------------------------------------------
  670. X    plog_control(fname)
  671. X fname == 0, close
  672. X fname == 1, plog_name already plugged
  673. X--------------------------------------------------------------------------*/
  674. Xint
  675. Xplog_control(fname)
  676. Xchar *fname;
  677. X{
  678. X    if(!fname)    /* close */
  679. X    {
  680. X        if(plog_fp)
  681. X            fclose(plog_fp);
  682. X        plog_fp = (FILE *)0;
  683. X        return(0);
  684. X    }
  685. X
  686. X    if(plog_fp)
  687. X        plog_control((char *)0);
  688. X
  689. X    if(fname != (char *)1)
  690. X    {
  691. X        strcpy(plog_name->pb,fname);
  692. X        plog_name->cb = strlen(fname);
  693. X    }
  694. X
  695. X    if((plog_fp = fopen(plog_name->pb,"a")) == NULL)
  696. X    {
  697. X        pperror(plog_name->pb);
  698. X        return(eFATAL_ALREADY);
  699. X    }
  700. X    return(0);
  701. X}    /* end of plog_control */
  702. X
  703. X/*+-------------------------------------------------------------------------
  704. X    pcmd_plog(param)
  705. X
  706. Xplog $s0     log to file
  707. Xplog off     stop logging
  708. Xplog         show status
  709. X--------------------------------------------------------------------------*/
  710. Xint
  711. Xpcmd_plog(param)
  712. XESD *param;
  713. X{
  714. Xint erc;
  715. Xchar off_str[8];
  716. X
  717. X    if(!skip_cmd_break(param))    /* if arguments */
  718. X    {
  719. X        if(!get_alpha_zstr(param,off_str,sizeof(off_str)))
  720. X        {
  721. X            if(strcmp(off_str,"off"))
  722. X                return(eBadParameter);
  723. X            erc = plog_control((char *)0);
  724. X        }
  725. X        else
  726. X        {
  727. X            if(erc = gstr(param,plog_name,1))
  728. X                return(erc);
  729. X            erc = plog_control((char *)1);
  730. X        }
  731. X    }
  732. X    return(erc);
  733. X
  734. X}    /* end of pcmd_plog */
  735. X
  736. X/*+-------------------------------------------------------------------------
  737. X    poutput_init()
  738. X--------------------------------------------------------------------------*/
  739. Xvoid
  740. Xpoutput_init()
  741. X{
  742. X    if((plog_name = make_esd(256)) == (ESD *)0)
  743. X    {
  744. X        ff(se,"Out of memory\r\n");
  745. X        hangup(1);
  746. X    }
  747. X}    /* end of poutput_init */
  748. X
  749. X/* vi: set tabstop=4 shiftwidth=4: */
  750. X/* end of poutput.c */
  751. SHAR_EOF
  752. $TOUCH -am 1224224290 'poutput.c' &&
  753. chmod 0644 poutput.c ||
  754. echo 'restore of poutput.c failed'
  755. Wc_c="`wc -c < 'poutput.c'`"
  756. test 4352 -eq "$Wc_c" ||
  757.     echo 'poutput.c: original size 4352, current size' "$Wc_c"
  758. # ============= pprintf.c ==============
  759. echo 'x - extracting pprintf.c (Text)'
  760. sed 's/^X//' << 'SHAR_EOF' > 'pprintf.c' &&
  761. X/*+-------------------------------------------------------------------------
  762. X    pprintf.c - preocedure printf
  763. X--------------------------------------------------------------------------*/
  764. X/*+:EDITS:*/
  765. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  766. X
  767. X/* based on Portable vsprintf  by Robert A. Larson <blarson@skat.usc.edu> */
  768. X
  769. X/* Copyright 1989 Robert A. Larson.
  770. X * Distribution in any form is allowed as long as the author
  771. X * retains credit, changes are noted by their author and the
  772. X * copyright message remains intact.  This program comes as-is
  773. X * with no warentee of fitness for any purpouse.
  774. X *
  775. X * Thanks to Doug Gwen, Chris Torek, and others who helped clarify
  776. X * the ansi printf specs.
  777. X *
  778. X * Please send any bug fixes and improvments to blarson@skat.usc.edu .
  779. X * The use of goto is NOT a bug.
  780. X */
  781. X
  782. X#if !defined(BUILDING_LINT_ARGS)
  783. X
  784. X#include <stdio.h>
  785. X#include <varargs.h>
  786. X
  787. X#if defined(M_I386)
  788. X#define LONGINT
  789. X#endif
  790. X
  791. X/* This must be a typedef not a #define! */
  792. X#define NOVOID
  793. X#ifdef NOVOID
  794. Xtypedef char *pointer;
  795. X#else
  796. Xtypedef void *pointer;
  797. X#endif
  798. X
  799. Xtypedef int *intp;
  800. X
  801. X/*+-------------------------------------------------------------------------
  802. X    pprintf(format,va_alist)
  803. X--------------------------------------------------------------------------*/
  804. Xvoid
  805. Xpprintf(format,va_alist)
  806. Xregister char *format;
  807. Xva_dcl
  808. X{
  809. Xva_list args;
  810. Xregister char c;
  811. Xregister char *tp;
  812. Xchar tempfmt[64];
  813. X#ifndef LONGINT
  814. Xint longflag;
  815. X#endif
  816. Xchar accum_string[256];
  817. Xregister char *dp = accum_string;
  818. X
  819. X    va_start(args);
  820. X
  821. X    tempfmt[0] = '%';
  822. X    while(c = *format++)
  823. X    {
  824. X        if(c=='%')
  825. X        {
  826. X            tp = &tempfmt[1];
  827. X#ifndef LONGINT
  828. X            longflag = 0;
  829. X#endif
  830. Xcontinue_format:
  831. X            switch(c = *format++)
  832. X            {
  833. X            case 's':
  834. X                *tp++ = c;
  835. X                *tp = '\0';
  836. X                dp += sprintf(dp,tempfmt,va_arg(args,char *));
  837. X                break;
  838. X            case 'u':
  839. X            case 'x':
  840. X            case 'o':
  841. X            case 'X':
  842. X#ifdef UNSIGNEDSPECIAL
  843. X                *tp++ = c;
  844. X                *tp = '\0';
  845. X#ifndef LONGINT
  846. X                if(longflag)
  847. X                    dp += sprintf(dp,tempfmt,va_arg(args,unsigned long));
  848. X                else
  849. X#endif
  850. X                    dp += sprintf(dp,tempfmt,va_arg(args,unsigned));
  851. X                break;
  852. X#endif
  853. X            case 'd':
  854. X            case 'c':
  855. X            case 'i':
  856. X                *tp++ = c;
  857. X                *tp = '\0';
  858. X#ifndef LONGINT
  859. X                if(longflag)
  860. X                    dp += sprintf(dp,tempfmt,va_arg(args,long));
  861. X                else
  862. X#endif
  863. X                    dp += sprintf(dp,tempfmt,va_arg(args,int));
  864. X                break;
  865. X            case 'f':
  866. X            case 'e':
  867. X            case 'E':
  868. X            case 'g':
  869. X            case 'G':
  870. X                *tp++ = c;
  871. X                *tp = '\0';
  872. X                dp += sprintf(dp,tempfmt,va_arg(args,double));
  873. X                break;
  874. X            case 'p':
  875. X#if defined(M_I386)
  876. X                dp += sprintf(dp,"0x%08lx",va_arg(args,pointer));
  877. X#else
  878. X#if defined(M_I286)
  879. X                tp = va_arg(args,pointer);
  880. X#if defined(M_SDATA)
  881. X                dp += sprintf(dp,"0x%04x",tp);
  882. X#else
  883. X                dp += sprintf(dp,"%04x:%04x",(int)tp,(int)((long)tp >> 16));
  884. X#endif /* M_SDATA */
  885. X#else
  886. X>>>>>>>>>>>> model problem
  887. X#endif /* M_I286 */
  888. X#endif /* M_I386 */
  889. X                break;
  890. X            case '-':
  891. X            case '+':
  892. X            case '0':
  893. X            case '1':
  894. X            case '2':
  895. X            case '3':
  896. X            case '4':
  897. X            case '5':
  898. X            case '6':
  899. X            case '7':
  900. X            case '8':
  901. X            case '9':
  902. X            case '.':
  903. X            case ' ':
  904. X            case '#':
  905. X            case 'h':
  906. X                *tp++ = c;
  907. X                goto continue_format;
  908. X            case 'l':
  909. X#ifndef LONGINT
  910. X                longflag = 1;
  911. X                *tp++ = c;
  912. X#endif
  913. X                goto continue_format;
  914. X            case '*':
  915. X                tp += sprintf(tp,"%d",va_arg(args,int));
  916. X                goto continue_format;
  917. X            case '%':
  918. X            default:
  919. X                *dp++ = c;
  920. X                break;
  921. X            }
  922. X        }
  923. X        else *dp++ = c;
  924. X    }
  925. X    *dp = '\0';
  926. X    va_end(args);
  927. X    pputs(accum_string);
  928. X}    /* end of pprintf */
  929. X#endif /* !defined(BUILDING_LINT_ARGS) */
  930. X
  931. X/* vi: set tabstop=4 shiftwidth=4: */
  932. X/* end of pprintf.c */
  933. SHAR_EOF
  934. $TOUCH -am 1224224390 'pprintf.c' &&
  935. chmod 0644 pprintf.c ||
  936. echo 'restore of pprintf.c failed'
  937. Wc_c="`wc -c < 'pprintf.c'`"
  938. test 3525 -eq "$Wc_c" ||
  939.     echo 'pprintf.c: original size 3525, current size' "$Wc_c"
  940. # ============= proc.c ==============
  941. echo 'x - extracting proc.c (Text)'
  942. sed 's/^X//' << 'SHAR_EOF' > 'proc.c' &&
  943. X/*+-------------------------------------------------------------------------
  944. X    proc.c - procedure command and control
  945. X    wht@n4hgf.Mt-Park.GA.US
  946. X
  947. X  Defined functions:
  948. X    _cmd_gosub_common(param,type)
  949. X    _get_goto_label(param)
  950. X    pcmd_do(param)
  951. X    pcmd_gosub(param)
  952. X    pcmd_gosubb(param)
  953. X    pcmd_goto(param)
  954. X    pcmd_gotob(param)
  955. X    pcmd_return(param)
  956. X    do_proc(argc,argv)
  957. X    dump_proc(pcb)
  958. X    execute_esd(tesd)
  959. X    execute_goto(pcb,goto_type)
  960. X    execute_labelled_esd(tesd)
  961. X    execute_proc(pcb,use_goto_label)
  962. X    find_labelled_lcb(label,first,last)
  963. X    find_proc_cmd(cmd_list,cmd)
  964. X    find_procedure(name)
  965. X    free_lcb_chain(lcb)
  966. X    show_error_position(pcb)
  967. X    trace_proc_cmd(pcb)
  968. X
  969. X--------------------------------------------------------------------------*/
  970. X/*+:EDITS:*/
  971. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  972. X
  973. X#include <ctype.h>
  974. X#include "ecu.h"
  975. X#include "ecuerror.h"
  976. X#include "esd.h"
  977. X#include "var.h"
  978. X#include "proc.h"
  979. X
  980. X#define NEED_P_CMD
  981. X#include "ecucmd.h"
  982. X
  983. Xextern int rcvr_pid;
  984. Xextern int interrupt;
  985. Xextern int proc_interrupt;
  986. X
  987. XPCB *pcb_stack[PROC_STACK_MAX];
  988. X
  989. Xint proc_level = 0;
  990. Xint proctrace = 0;
  991. X
  992. Xchar goto_label[64];
  993. X
  994. X/*+-------------------------------------------------------------------------
  995. X    _get_goto_label(param)
  996. X--------------------------------------------------------------------------*/
  997. Xint
  998. X_get_goto_label(param)
  999. XESD *param;
  1000. X{
  1001. Xregister erc;
  1002. Xregister ESD *label_esd;
  1003. X
  1004. X    goto_label[0] = 0;
  1005. X    if(erc = get_alphanum_zstr(param,goto_label,sizeof(goto_label)))
  1006. X    {
  1007. X        if((label_esd = make_esd(64)) == (ESD *)0)
  1008. X            return(eNoMemory);
  1009. X        if(!(erc = gstr(param,label_esd,0)))
  1010. X            strcpy(goto_label,label_esd->pb);
  1011. X        free_esd(label_esd);
  1012. X    }
  1013. X
  1014. X    return(erc);
  1015. X
  1016. X}    /* end of _get_goto_label */
  1017. X
  1018. X/*+-------------------------------------------------------------------------
  1019. X    pcmd_goto(param)
  1020. X--------------------------------------------------------------------------*/
  1021. Xint
  1022. Xpcmd_goto(param)
  1023. XESD *param;
  1024. X{
  1025. X
  1026. X    if(!proc_level)
  1027. X        return(eNotExecutingProc);
  1028. X    if(_get_goto_label(param))
  1029. X        return(eInvalidLabel);
  1030. X    return(eProcAttn_GOTO);
  1031. X
  1032. X}    /* end of pcmd_goto */
  1033. X
  1034. X/*+-------------------------------------------------------------------------
  1035. X    pcmd_gotob(param)
  1036. X--------------------------------------------------------------------------*/
  1037. Xint
  1038. Xpcmd_gotob(param)
  1039. XESD *param;
  1040. X{
  1041. X
  1042. X    if(!proc_level)
  1043. X        return(eNotExecutingProc);
  1044. X    if(_get_goto_label(param))
  1045. X        return(eInvalidLabel);
  1046. X    return(eProcAttn_GOTOB);
  1047. X
  1048. X}    /* end of pcmd_gotob */
  1049. X
  1050. X/*+-------------------------------------------------------------------------
  1051. X    _cmd_gosub_common(param,type)
  1052. X--------------------------------------------------------------------------*/
  1053. Xint
  1054. X_cmd_gosub_common(param,type)
  1055. XESD *param;
  1056. Xint type;
  1057. X{
  1058. Xint erc;
  1059. XLCB *current_save;
  1060. Xint index_save;
  1061. X
  1062. X    if(_get_goto_label(param))
  1063. X        return(eInvalidLabel);
  1064. X    current_save = pcb_stack[proc_level - 1]->current;
  1065. X    index_save = current_save->text->index;
  1066. X    if(!(erc = execute_proc(pcb_stack[proc_level - 1],type)))
  1067. X    {
  1068. X        pcb_stack[proc_level - 1]->current = current_save;
  1069. X        current_save->text->index = index_save;
  1070. X    }
  1071. X    return(erc);
  1072. X
  1073. X}    /* end of _cmd_gosub_common */
  1074. X
  1075. X/*+-------------------------------------------------------------------------
  1076. X    pcmd_gosub(param)
  1077. X--------------------------------------------------------------------------*/
  1078. Xint
  1079. Xpcmd_gosub(param)
  1080. XESD *param;
  1081. X{
  1082. X    if(!proc_level)
  1083. X        return(eNotExecutingProc);
  1084. X    return(_cmd_gosub_common(param,eProcAttn_GOTO));
  1085. X}    /* end of pcmd_gosub */
  1086. X
  1087. X/*+-------------------------------------------------------------------------
  1088. X    pcmd_gosubb(param)
  1089. X--------------------------------------------------------------------------*/
  1090. Xint
  1091. Xpcmd_gosubb(param)
  1092. XESD *param;
  1093. X{
  1094. X    if(!proc_level)
  1095. X        return(eNotExecutingProc);
  1096. X    return(_cmd_gosub_common(param,eProcAttn_GOTO));
  1097. X}    /* end of pcmd_gosubb */
  1098. X
  1099. X/*+-------------------------------------------------------------------------
  1100. X    pcmd_return(param)
  1101. X--------------------------------------------------------------------------*/
  1102. Xint
  1103. Xpcmd_return(param)
  1104. XESD *param;
  1105. X{
  1106. Xlong value = 0;
  1107. X    if(!gint(param,&value))
  1108. X    {
  1109. X        value &= (e_USER - 1);
  1110. X        if(proctrace)
  1111. X            pprintf("return value %ld\n",value);
  1112. X        return((int)value);
  1113. X    }
  1114. X    return(eProcAttn_RETURN);
  1115. X}    /* end of pcmd_return */
  1116. X
  1117. X/*+-------------------------------------------------------------------------
  1118. X    find_labelled_lcb(label,first,last)
  1119. Xsearch for match between label
  1120. X--------------------------------------------------------------------------*/
  1121. XLCB *
  1122. Xfind_labelled_lcb(label,first,last)
  1123. Xchar *label;
  1124. Xregister LCB *first;
  1125. XLCB *last;
  1126. X{
  1127. Xregister llen = strlen(label);
  1128. XESD *text;
  1129. X
  1130. X    while(first)
  1131. X    {
  1132. X        text = first->text;
  1133. X        if((text->cb >= llen) && (!strncmp(text->pb,label,llen))
  1134. X            && (!text->pb[llen] || isspace(text->pb[llen])))
  1135. X            return(first);
  1136. X
  1137. X        if(first == last)
  1138. X            return((LCB *)0);
  1139. X        first = first->next;
  1140. X    }
  1141. X    pputs("find_labelled_lab logic error\n");
  1142. X    return((LCB *)0);
  1143. X
  1144. X}    /* end of find_labelled_lcb */
  1145. X
  1146. X/*+-------------------------------------------------------------------------
  1147. X    execute_goto(pcb,goto_type)
  1148. X--------------------------------------------------------------------------*/
  1149. Xexecute_goto(pcb,goto_type)
  1150. XPCB *pcb;
  1151. Xint goto_type;
  1152. X{
  1153. XLCB *next;    /* next lcb to execute */
  1154. X
  1155. X    switch(goto_type)
  1156. X    {
  1157. X        case eProcAttn_GOTO:
  1158. X            if(!(next = find_labelled_lcb(goto_label,pcb->current,pcb->last)))
  1159. X                next = find_labelled_lcb(goto_label,pcb->first,pcb->current);
  1160. X            break;
  1161. X        case eProcAttn_GOTOB:
  1162. X            if(!(next = find_labelled_lcb(goto_label,pcb->first,pcb->current)))
  1163. X                next = find_labelled_lcb(goto_label,pcb->current,pcb->last);
  1164. X            break;
  1165. X    }
  1166. X    if(next)
  1167. X    {
  1168. X        pcb->current = next;
  1169. X        return(0);
  1170. X    }
  1171. X    pprintf("goto/gosub label not found: %s\n",goto_label);
  1172. X    return(eFATAL_ALREADY);
  1173. X
  1174. X}    /* end of execute_goto */
  1175. X
  1176. X/*+-------------------------------------------------------------------------
  1177. X    show_error_position(pcb)
  1178. Xcursor MUST be at left margin when this is called
  1179. X--------------------------------------------------------------------------*/
  1180. Xvoid
  1181. Xshow_error_position(pcb)
  1182. XPCB *pcb;
  1183. X{
  1184. XESD *tesd = pcb->current->text;
  1185. Xregister itmp = tesd->old_index;
  1186. Xchar tag[64];
  1187. X
  1188. X    sprintf(tag,"%s %u> ",pcb->argv[0],pcb->current->lineno);
  1189. X    pputs(tag);
  1190. X    pputs(tesd->pb);
  1191. X    pputs("\n");
  1192. X    itmp = strlen(tag) + tesd->old_index;
  1193. X    while(itmp--)
  1194. X        pputc(' ');
  1195. X    pputs("^\n");
  1196. X
  1197. X}    /* end of show_error_position */
  1198. X
  1199. X/*+-------------------------------------------------------------------------
  1200. X    find_proc_cmd(cmd_list,cmd)
  1201. X--------------------------------------------------------------------------*/
  1202. XP_CMD *
  1203. Xfind_proc_cmd(cmd_list,cmd)
  1204. Xregister P_CMD *cmd_list;
  1205. Xregister char *cmd;
  1206. X{
  1207. X    while(cmd_list->token != -1)
  1208. X    {
  1209. X        if(!strcmp(cmd_list->cmd,cmd))
  1210. X            break;
  1211. X        cmd_list++;
  1212. X    }
  1213. X    return((cmd_list->token == -1) ? (P_CMD *)0 : cmd_list);
  1214. X
  1215. X}    /* end of find_proc_cmd */
  1216. X
  1217. X/*+-------------------------------------------------------------------------
  1218. X    execute_esd(tesd)
  1219. X--------------------------------------------------------------------------*/
  1220. Xexecute_esd(tesd)
  1221. XESD *tesd;
  1222. X{
  1223. Xint erc;
  1224. XP_CMD *pcmd;
  1225. Xstatic P_CMD *set_pcmd = (P_CMD *)0;    /* quick access to 'set' */
  1226. Xchar cmd[32];
  1227. X
  1228. X    /* if interrupt, exit */
  1229. X    if(interrupt)
  1230. X    {
  1231. X        proc_interrupt = 1;
  1232. X        return(eCONINT);
  1233. X    }
  1234. X
  1235. X    /* if blank, skip it */
  1236. X    if(skip_cmd_break(tesd))
  1237. X        return(0);
  1238. X
  1239. X    /* if comment, skip it */
  1240. X    if(!skip_cmd_char(tesd,'#'))
  1241. X        return(0);
  1242. X
  1243. X    if(*(tesd->pb + tesd->index) == '{')
  1244. X    {
  1245. X        pputs("invalid '{'\n");
  1246. X        return(eFATAL_ALREADY);
  1247. X    }
  1248. X
  1249. X    while(1)
  1250. X    {
  1251. X        /* get command -- allow leading '$' to assume 'set' command */
  1252. X        if(*(tesd->pb + tesd->index) == '$')
  1253. X        {
  1254. X            /* find 'set' in the list -- save for rapid access later */
  1255. X            if(set_pcmd)
  1256. X                pcmd = set_pcmd;
  1257. X            else if((pcmd = find_proc_cmd(icmd_cmds,"set")) == (P_CMD *)0)
  1258. X                return(eInternalLogicError);
  1259. X            else
  1260. X                set_pcmd = pcmd;
  1261. X        }
  1262. X        else
  1263. X        {
  1264. X            if(get_alphanum_zstr(tesd,cmd,sizeof(cmd)))
  1265. X                return(eIllegalCommand);
  1266. X            /* find it in the list */
  1267. X            if((pcmd = find_proc_cmd(icmd_cmds,cmd)) == (P_CMD *)0)
  1268. X                return(eIllegalCommand);
  1269. X        }
  1270. X
  1271. X        /* check to see if this command available for procedure */
  1272. X        if(!pcmd->proc)
  1273. X            return(eInteractiveCmd);
  1274. X
  1275. X        /* execute the command */
  1276. X        if(erc = (*pcmd->proc)(tesd))
  1277. X            return(erc);
  1278. X
  1279. X        /* look for comment */
  1280. X        if(!skip_cmd_char(tesd,'#'))
  1281. X            break;
  1282. X
  1283. X        /* look for multiple commands on line */
  1284. X        if(skip_cmd_char(tesd,';'))
  1285. X            break;
  1286. X
  1287. X        /* if blank after ';', skip it */
  1288. X        if(skip_cmd_break(tesd))
  1289. X            break;
  1290. X    }
  1291. X    return(0);
  1292. X        
  1293. X}    /* end of execute_esd */
  1294. X
  1295. X/*+-------------------------------------------------------------------------
  1296. X    execute_labelled_esd(tesd)
  1297. X--------------------------------------------------------------------------*/
  1298. Xexecute_labelled_esd(tesd)
  1299. XESD *tesd;
  1300. X{
  1301. Xregister index = 0;
  1302. Xregister cb = tesd->cb;
  1303. Xregister char *pb = tesd->pb;
  1304. X
  1305. X/* reset indices */
  1306. X    tesd->index = index;
  1307. X    tesd->old_index = index;
  1308. X
  1309. X/* if comment, skip it */
  1310. X    if(!skip_cmd_char(tesd,'#'))
  1311. X        return(0);
  1312. X
  1313. X/* skip over any label */
  1314. X    while(!isspace(*(pb + index)) && (index < cb))
  1315. X        index++;
  1316. X    tesd->index = index;
  1317. X    tesd->old_index = index;
  1318. X
  1319. X    return(execute_esd(tesd));
  1320. X}    /* end of execute_labelled_esd */
  1321. X
  1322. X/*+-------------------------------------------------------------------------
  1323. X    dump_proc(pcb)
  1324. X--------------------------------------------------------------------------*/
  1325. Xvoid
  1326. Xdump_proc(pcb)
  1327. XPCB *pcb;
  1328. X{
  1329. Xint itmp;
  1330. XLCB *lcb;
  1331. X
  1332. X    pprintf("------ pcb @ 0x%08lx -----------------\n",pcb);
  1333. X    pprintf("argc=%d first=0x%08lx last=0x%08lx\n",pcb->argc,
  1334. X        pcb->first,pcb->last);
  1335. X    for(itmp = 0; itmp < pcb->argc; itmp++)
  1336. X    {
  1337. X        pprintf("argv(%d) @ 0x%lx: '%s'\n",itmp,pcb->argv[itmp],
  1338. X            pcb->argv[itmp]);
  1339. X    }
  1340. X    pputs("\n");
  1341. X    lcb = pcb->first;
  1342. X    while(lcb)
  1343. X    {
  1344. X        pprintf("lcb @ 0x%08lx   lineno=%u\n",lcb,lcb->lineno);
  1345. X        pputs("\n");
  1346. X        lcb = lcb->next;
  1347. X    }
  1348. X    pflush();
  1349. X}    /* end of dump_proc */
  1350. X
  1351. X/*+-------------------------------------------------------------------------
  1352. X    trace_proc_cmd(pcb) - if asked, show command
  1353. X--------------------------------------------------------------------------*/
  1354. Xvoid
  1355. Xtrace_proc_cmd(pcb)
  1356. XPCB *pcb;
  1357. X{
  1358. X    if(proctrace)
  1359. X    {
  1360. X        pprintf("%s %u> ",pcb->argv[0],pcb->current->lineno);
  1361. X        pputs(pcb->current->text->pb);
  1362. X        pputc('\n');
  1363. X    }
  1364. X
  1365. X}    /* end of trace_proc_cmd */
  1366. X
  1367. X/*+-------------------------------------------------------------------------
  1368. X    execute_proc(pcb,use_goto_label) - execute a memory-resident procedure
  1369. X--------------------------------------------------------------------------*/
  1370. Xexecute_proc(pcb,use_goto_label)
  1371. XPCB *pcb;
  1372. Xint use_goto_label;
  1373. X{
  1374. Xint erc = 0;
  1375. X
  1376. X    if(proc_level == PROC_STACK_MAX)
  1377. X        return(eProcStackTooDeep);
  1378. X
  1379. X    pcb_stack[proc_level++] = pcb;
  1380. X    if(use_goto_label)
  1381. X    {
  1382. X        if(erc = execute_goto(pcb,use_goto_label))
  1383. X            return(erc);
  1384. X    }
  1385. X    else
  1386. X        pcb->current = pcb->first;
  1387. X
  1388. X    mkv_proc_starting(pcb);
  1389. X
  1390. X    while(pcb->current)
  1391. X    {
  1392. X        /* execute the command */
  1393. X        trace_proc_cmd(pcb);
  1394. X        if(erc = execute_labelled_esd(pcb->current->text))
  1395. X        {
  1396. X            /* handle other classes of errors */
  1397. X            switch(erc & 0xF000)
  1398. X            {
  1399. X                case e_WARNING:        /* warning */
  1400. X                    erc = 0;
  1401. X                    break;
  1402. X
  1403. X                case e_FATAL:        /* fatal */
  1404. X                    goto PROC_RETURN;
  1405. X
  1406. X                case e_ProcAttn:    /* proc attention */
  1407. X                    switch(erc)
  1408. X                    {
  1409. X                        case eProcAttn_GOTO:
  1410. X                        case eProcAttn_GOTOB:
  1411. X                            if(erc = execute_goto(pcb,erc))
  1412. X                                break;    /* didn't find it */
  1413. X                            continue;    /* pcb->current is now goto target */
  1414. X
  1415. X                        case eProcAttn_RETURN:
  1416. X                            erc = 0;
  1417. X                            break;
  1418. X
  1419. X                        case eProcAttn_Interrupt:
  1420. X                        case eProcAttn_ESCAPE:
  1421. X                            pprintf(
  1422. X                                "procedure %s interrupted.\n",pcb->argv[0]);
  1423. X                            erc = eFATAL_ALREADY;
  1424. X                            break;
  1425. X
  1426. X                        default:
  1427. X                            pprintf("procedure error 0x%x\n",erc);
  1428. X                            erc = eFATAL_ALREADY;
  1429. X                            break;
  1430. X                    }
  1431. X                    goto PROC_RETURN;
  1432. X
  1433. X                default:    /* must be proc return error code */
  1434. X                    goto PROC_RETURN;
  1435. X                    break;
  1436. X            }
  1437. X        }
  1438. X
  1439. X        if(proc_interrupt)
  1440. X        {
  1441. X            proc_interrupt = 0;
  1442. X            interrupt = 0;
  1443. X            pprintf("procedure %s interrupted\n",pcb->argv[0]);
  1444. X            erc = eFATAL_ALREADY;
  1445. X        }
  1446. X
  1447. X        if(erc)
  1448. X            break;
  1449. X        pcb->current = pcb->current->next;
  1450. X    }
  1451. X
  1452. XPROC_RETURN:
  1453. X    mkv_proc_terminating(pcb);
  1454. X    if(erc)
  1455. X    {
  1456. X        if((erc > 0) && (erc < e_USER))
  1457. X        {
  1458. X            pprintf(">>procedure %s returned %d\n",pcb->argv[0],erc);
  1459. X            erc |= e_USER;
  1460. X        }
  1461. X        else if((erc > e_USER) && (erc <= 0x1FFF))
  1462. X        {
  1463. X            ;    /* already said it */
  1464. X        }
  1465. X        else
  1466. X        {
  1467. X            if(erc != eFATAL_ALREADY)
  1468. X            {
  1469. X                proc_error(erc);
  1470. X                erc = eFATAL_ALREADY;
  1471. X            }
  1472. X            show_error_position(pcb);
  1473. X        }
  1474. X    }
  1475. X    pcb_stack[--proc_level] = (PCB *)0;
  1476. X    if(erc && !proc_level)
  1477. X        plog_control((char *)0);
  1478. X    return(erc);
  1479. X}    /* end of execute_proc */
  1480. X
  1481. X/*+-------------------------------------------------------------------------
  1482. X    free_lcb_chain(lcb)
  1483. X--------------------------------------------------------------------------*/
  1484. Xvoid
  1485. Xfree_lcb_chain(lcb)
  1486. Xregister LCB *lcb;
  1487. X{
  1488. XLCB *plcb;
  1489. X
  1490. X    while(lcb)
  1491. X    {
  1492. X        if(lcb->text)
  1493. X            free_esd(lcb->text);
  1494. X        plcb  = lcb;
  1495. X        lcb = lcb->next;
  1496. X        free((char *)plcb);
  1497. X    }
  1498. X
  1499. X}    /* end of free_lcb_chain */
  1500. X
  1501. X/*+-------------------------------------------------------------------------
  1502. X    find_procedure(name)
  1503. X--------------------------------------------------------------------------*/
  1504. Xchar *
  1505. Xfind_procedure(name)
  1506. Xchar *name;
  1507. X{
  1508. Xstatic char procpath[256];
  1509. X
  1510. X/* try to find proc file in current directory */
  1511. X    strcpy(procpath,name);
  1512. X    strcat(procpath,".ep");
  1513. X    if(access(procpath,4))
  1514. X    {
  1515. X        /* try to find proc file in home .ecu subdirectory */
  1516. X        get_home_dir(procpath);
  1517. X        strcat(procpath,"/.ecu/");
  1518. X        strcat(procpath,name);
  1519. X        strcat(procpath,".ep");
  1520. X        if(access(procpath,4))
  1521. X            return((char *)0);
  1522. X    }
  1523. X    return(procpath);
  1524. X
  1525. X}    /* end of find_procedure */
  1526. X
  1527. X/*+-------------------------------------------------------------------------
  1528. X    do_proc(argc,argv) - read in a disk-based procedure and execute it
  1529. X--------------------------------------------------------------------------*/
  1530. Xdo_proc(argc,argv)
  1531. Xint argc;
  1532. Xchar **argv;
  1533. X{
  1534. Xregister itmp;
  1535. Xint itmp2;
  1536. Xint erc;
  1537. Xint iargv;
  1538. Xchar *pargv[MAX_PARGV];
  1539. Xint ipargv = 0;
  1540. Xchar s256[256];
  1541. Xchar *procpath;
  1542. XFILE *fp;
  1543. XPCB *pcb = (PCB *)0;
  1544. XLCB *lcb;
  1545. XLCB *plcb;
  1546. Xushort line_count = 0;
  1547. Xextern ulong colors_current;
  1548. Xulong colors_at_entry = colors_current;
  1549. X
  1550. X    proc_interrupt = 0;
  1551. X    interrupt = 0;
  1552. X    for(iargv = 0; iargv < argc; iargv++)
  1553. X    {
  1554. X        if(ipargv == MAX_PARGV)
  1555. X        {
  1556. X            pprintf("\nToo many arguments to %s invocation\n",pargv[0]);
  1557. X            erc = eFATAL_ALREADY;
  1558. X            goto RETURN;
  1559. X        }
  1560. X        pargv[ipargv++] = argv[iargv];
  1561. X    }
  1562. X
  1563. X    if(!ipargv)
  1564. X    {
  1565. X        pputs("\nno procedure name given\n");
  1566. X        erc = eFATAL_ALREADY;
  1567. X        goto RETURN;
  1568. X    }
  1569. X
  1570. X    if(!(procpath = find_procedure(pargv[0])))
  1571. X    {
  1572. X        pprintf("\nprocedure %s not found\n",pargv[0]);
  1573. X        erc = eFATAL_ALREADY;
  1574. X        goto RETURN;
  1575. X    }
  1576. X    fp = fopen(procpath,"r");
  1577. X    if(!fp)
  1578. X    {
  1579. X        pperror(procpath);
  1580. X        erc = eFATAL_ALREADY;
  1581. X        goto RETURN;
  1582. X    }
  1583. X    if(proctrace)
  1584. X        pprintf("DO: %s\n",procpath);
  1585. X
  1586. X    if(!(pcb = (PCB *)malloc(sizeof(PCB))))
  1587. X    {
  1588. X        erc = eNoMemory;
  1589. X        goto RETURN;
  1590. X    }
  1591. X
  1592. X    pcb->argv = pargv;
  1593. X    pcb->argc = ipargv;
  1594. X    pcb->first = (LCB *)0;
  1595. X
  1596. X    plcb = (LCB *)0;
  1597. X    line_count = 0;
  1598. X    while(1)
  1599. X    {
  1600. X        if(fgets(s256,sizeof(s256),fp) == NULL)
  1601. X            break;
  1602. X        line_count++;
  1603. X
  1604. X        itmp = strlen(s256) - 1;    /* skip blank lines */
  1605. X        if(!itmp)
  1606. X            continue;
  1607. X        s256[itmp] = 0;                /* kill trailing NL */
  1608. X        for(itmp2 = 0; itmp2 < itmp; itmp2++)
  1609. X        {
  1610. X            if(s256[itmp2] == 0x09)
  1611. X                s256[itmp2] = 0x20;
  1612. X        }
  1613. X        if(s256[0] == '#')             /* skip comments */
  1614. X            continue;
  1615. X
  1616. X        if(!(lcb = (LCB *)malloc(sizeof(LCB))))
  1617. X        {
  1618. X            fclose(fp);
  1619. X            erc = eNoMemory;
  1620. X            goto RETURN;
  1621. X        }
  1622. X
  1623. X        lcb->prev = plcb;
  1624. X        lcb->next = (LCB *)0;
  1625. X        lcb->lineno = line_count;
  1626. X
  1627. X        if(plcb)
  1628. X            plcb->next = lcb;
  1629. X        else
  1630. X            pcb->first = lcb;
  1631. X
  1632. X        if((lcb->text = make_esd(itmp)) == (ESD *)0)
  1633. X        {
  1634. X            fclose(fp);
  1635. X            erc = eNoMemory;
  1636. X            goto RETURN;
  1637. X        }
  1638. X        strcpy(lcb->text->pb,s256);
  1639. X        lcb->text->cb = itmp;
  1640. X        null_terminate_esd(lcb->text);
  1641. X        plcb = lcb;
  1642. X    }
  1643. X    fclose(fp);
  1644. X    pcb->last = lcb;
  1645. X    if(line_count)
  1646. X        erc = execute_proc(pcb,0);
  1647. X    else
  1648. X        erc = eProcEmpty;
  1649. X
  1650. XRETURN:
  1651. X    if(pcb)
  1652. X    {
  1653. X        if(pcb->first)
  1654. X            free_lcb_chain(pcb->first);
  1655. X        free((char *)pcb);
  1656. X    }
  1657. X    if((erc > e_USER) && (erc <= 0x1FFF))
  1658. X        erc -= e_USER;
  1659. X    if(erc > e_USER)
  1660. X        setcolor(colors_at_entry);
  1661. X    return(erc);
  1662. X
  1663. X}    /* end of do_proc */
  1664. X
  1665. X/*+-------------------------------------------------------------------------
  1666. X    pcmd_do(param)
  1667. X--------------------------------------------------------------------------*/
  1668. Xpcmd_do(param)
  1669. XESD *param;
  1670. X{
  1671. Xint erc;
  1672. Xregister ipargv;
  1673. Xchar *cmd_copy;
  1674. Xchar *pargv[MAX_PARGV];
  1675. XESD *pargv_esd[MAX_PARGV];
  1676. Xint pargc = 0;
  1677. X
  1678. X    if(!(cmd_copy = (char *)malloc(param->cb)))
  1679. X        return(eNoMemory);
  1680. X    strcpy(cmd_copy,param->pb + param->old_index);
  1681. X    while(pargc != MAX_PARGV)
  1682. X    {
  1683. X        if(end_of_cmd(param))
  1684. X            break;
  1685. X        if((pargv_esd[pargc] = make_esd(256)) == (ESD *)0)
  1686. X        {
  1687. X            erc = eNoMemory;
  1688. X            goto RETURN;
  1689. X        }
  1690. X        if(erc = gstr(param,pargv_esd[pargc],1))
  1691. X            goto RETURN;
  1692. X        pargv[pargc] = pargv_esd[pargc]->pb;
  1693. X        pargc++;
  1694. X    }
  1695. X
  1696. X    if(pargc < MAX_PARGV)
  1697. X        erc = do_proc(pargc,pargv);
  1698. X    else
  1699. X    {
  1700. X        pprintf("too many arguments to procedure\n");
  1701. X        erc = eFATAL_ALREADY;
  1702. X    }
  1703. X
  1704. XRETURN:
  1705. X    free(cmd_copy);
  1706. X    for(ipargv = 0; ipargv < pargc; ipargv++)
  1707. X        free_esd(pargv_esd[ipargv]);
  1708. X    return(erc);
  1709. X
  1710. X}    /* end of pcmd_do */
  1711. X
  1712. X/* vi: set tabstop=4 shiftwidth=4: */
  1713. X/* end of proc.c */
  1714. SHAR_EOF
  1715. $TOUCH -am 1224224390 'proc.c' &&
  1716. chmod 0644 proc.c ||
  1717. echo 'restore of proc.c failed'
  1718. Wc_c="`wc -c < 'proc.c'`"
  1719. test 16834 -eq "$Wc_c" ||
  1720.     echo 'proc.c: original size 16834, current size' "$Wc_c"
  1721. # ============= proc_error.c ==============
  1722. echo 'x - extracting proc_error.c (Text)'
  1723. sed 's/^X//' << 'SHAR_EOF' > 'proc_error.c' &&
  1724. X/* CHK=0xF047 */
  1725. X/*+-------------------------------------------------------------------------
  1726. X    proc_error.c - print ecu procedure error
  1727. X--------------------------------------------------------------------------*/
  1728. X/*+:EDITS:*/
  1729. X/*:09-19-1990-23:00-build_err-creation from ecuerror.h */
  1730. X
  1731. X#include "ecu.h"
  1732. X#include "ecuerror.h"
  1733. X
  1734. X/*+-------------------------------------------------------------------------
  1735. X    proc_error(erc) - print error message
  1736. X--------------------------------------------------------------------------*/
  1737. Xvoid
  1738. Xproc_error(erc)
  1739. Xint erc;
  1740. X{
  1741. X    switch(erc)
  1742. X    {
  1743. X        case eProcEmpty:
  1744. X            pputs("empty procedure\n");
  1745. X            break;
  1746. X        case eConnectFailed:
  1747. X            pputs("failed to connect\n");
  1748. X            break;
  1749. X        case eNoSwitches:
  1750. X            pputs("no switch(es) to command\n");
  1751. X            break;
  1752. X        case eIllegalCommand:
  1753. X            pputs("invalid command\n");
  1754. X            break;
  1755. X        case eNoMemory:
  1756. X            pputs("no more memory available\n");
  1757. X            break;
  1758. X        case eSyntaxError:
  1759. X            pputs("syntax error\n");
  1760. X            break;
  1761. X        case eIllegalVarNumber:
  1762. X            pputs("variable number is invalid or out of range\n");
  1763. X            break;
  1764. X        case eIllegalVarType:
  1765. X            pputs("unrecognized variable type\n");
  1766. X            break;
  1767. X        case eNotInteger:
  1768. X            pputs("integer expected and not found\n");
  1769. X            break;
  1770. X        case eCONINT:
  1771. X            pputs("abort due to interrupt\n");
  1772. X            break;
  1773. X        case eInvalidFunction:
  1774. X            pputs("invalid function name\n");
  1775. X            break;
  1776. X        case eMissingLeftParen:
  1777. X            pputs("did not find expected left paren\n");
  1778. X            break;
  1779. X        case eMissingRightParen:
  1780. X            pputs("did not find expected right paren\n");
  1781. X            break;
  1782. X        case eCommaExpected:
  1783. X            pputs("expected comma not found\n");
  1784. X            break;
  1785. X        case eProcStackTooDeep:
  1786. X            pputs("procedure stack depth exceeded\n");
  1787. X            break;
  1788. X        case eInvalidRelOp:
  1789. X            pputs("invalid relational operator\n");
  1790. X            break;
  1791. X        case eInvalidIntOp:
  1792. X            pputs("invalid integer operator\n");
  1793. X            break;
  1794. X        case eInvalidStrOp:
  1795. X            pputs("invalid string operator\n");
  1796. X            break;
  1797. X        case eNotExecutingProc:
  1798. X            pputs("not executing DO at this time\n");
  1799. X            break;
  1800. X        case eInvalidLabel:
  1801. X            pputs("invalid label\n");
  1802. X            break;
  1803. X        case eInternalLogicError:
  1804. X            pputs("internal logic error ... whoops\n");
  1805. X            break;
  1806. X        case eEOF:
  1807. X            pputs("end of file or read error\n");
  1808. X            break;
  1809. X        case eBufferTooSmall:
  1810. X            pputs("string too long\n");
  1811. X            break;
  1812. X        case eNoParameter:
  1813. X            pputs("expected parameter not found\n");
  1814. X            break;
  1815. X        case eBadParameter:
  1816. X            pputs("bad parameter\n");
  1817. X            break;
  1818. X        case eInvalidHexNumber:
  1819. X            pputs("invalid hexadecimal digit\n");
  1820. X            break;
  1821. X        case eInvalidDecNumber:
  1822. X            pputs("invalid decimal digit\n");
  1823. X            break;
  1824. X        case eInvalidOctNumber:
  1825. X            pputs("invalid octal digit\n");
  1826. X            break;
  1827. X        case eInteractiveCmd:
  1828. X            pputs("interactive command\n");
  1829. X            break;
  1830. X        case eNoLineAttached:
  1831. X            pputs("no line (modem) attached\n");
  1832. X            break;
  1833. X        case eBadFileNumber:
  1834. X            pputs("file number out of range\n");
  1835. X            break;
  1836. X        case eNotImplemented:
  1837. X            pputs("not implemented\n");
  1838. X            break;
  1839. X        case eDuplicateMatch:
  1840. X            pputs("more than one condition matches\n");
  1841. X            break;
  1842. X        case eColonExpected:
  1843. X            pputs("expected colon not found\n");
  1844. X            break;
  1845. X        case eLabelInvalidHere:
  1846. X            pputs("label not allowed on this statement\n");
  1847. X            break;
  1848. X        case eNoCloseFrame:
  1849. X            pputs("missing '}' for '{'\n");
  1850. X            break;
  1851. X        case eNoFrame:
  1852. X            pputs("missing command or command group after 'while' or 'if'\n");
  1853. X            break;
  1854. X        case eMissingCommand:
  1855. X            pputs("expected command not found\n");
  1856. X            break;
  1857. X        case eBreakCommand:
  1858. X            pputs("'break' outside 'while'\n");
  1859. X            break;
  1860. X        case eContinueCommand:
  1861. X            pputs("'continue' outside 'while'\n");
  1862. X            break;
  1863. X        case eElseCommand:
  1864. X            pputs("'else' without matching 'if'\n");
  1865. X            break;
  1866. X        case eInvalidVarName:
  1867. X            pputs("invalid variable name\n");
  1868. X            break;
  1869. X        case eNoSuchVariable:
  1870. X            pputs("variable by this name not defined\n");
  1871. X            break;
  1872. X        case eInvalidLogicOp:
  1873. X            pputs("invalid logical operator\n");
  1874. X            break;
  1875. X        case eExpectRespondFail:
  1876. X            pputs("expect-respond failed\n");
  1877. X            break;
  1878. X        case eProcAttn_GOTO:
  1879. X            pputs("GOTO detected\n");
  1880. X            break;
  1881. X        case eProcAttn_GOTOB:
  1882. X            pputs("GOTOB detected\n");
  1883. X            break;
  1884. X        case eProcAttn_RETURN:
  1885. X            pputs("RETURN detected\n");
  1886. X            break;
  1887. X        case eProcAttn_ESCAPE:
  1888. X            pputs("ESCAPE detected\n");
  1889. X            break;
  1890. X        case eProcAttn_Interrupt:
  1891. X            pputs("procedure interrupted\n");
  1892. X            break;
  1893. X        case eFATAL_ALREADY:
  1894. X        case eWARNING_ALREADY:
  1895. X            break;
  1896. X        default:
  1897. X            pprintf("unknown error %x\n",erc);
  1898. X            break;
  1899. X    }
  1900. X} /* end of proc_error */
  1901. X
  1902. X/* vi: set tabstop=4 shiftwidth=4: */
  1903. X/* end of proc_error.c */
  1904. SHAR_EOF
  1905. $TOUCH -am 1224224390 'proc_error.c' &&
  1906. chmod 0644 proc_error.c ||
  1907. echo 'restore of proc_error.c failed'
  1908. Wc_c="`wc -c < 'proc_error.c'`"
  1909. test 4423 -eq "$Wc_c" ||
  1910.     echo 'proc_error.c: original size 4423, current size' "$Wc_c"
  1911. # ============= procframe.c ==============
  1912. echo 'x - extracting procframe.c (Text)'
  1913. sed 's/^X//' << 'SHAR_EOF' > 'procframe.c' &&
  1914. X/*+-------------------------------------------------------------------------
  1915. X    procframe.c - execute frame of procedure statements
  1916. X    wht@n4hgf.Mt-Park.GA.US
  1917. X
  1918. X  Defined functions:
  1919. X    pcmd_break(param);
  1920. X    pcmd_continue(param);
  1921. X    execute_frame(truth)
  1922. X
  1923. X--------------------------------------------------------------------------*/
  1924. X/*+:EDITS:*/
  1925. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1926. X
  1927. X#include <ctype.h>
  1928. X#include "ecu.h"
  1929. X#include "ecukey.h"
  1930. X#include "ecuerror.h"
  1931. X#include "esd.h"
  1932. X#include "var.h"
  1933. X#include "proc.h"
  1934. X
  1935. Xextern PCB *pcb_stack[PROC_STACK_MAX];
  1936. Xextern int proc_level;
  1937. Xextern int proc_interrupt;
  1938. Xextern int proctrace;
  1939. X
  1940. X/*+-------------------------------------------------------------------------
  1941. X    pcmd_break(param)
  1942. X--------------------------------------------------------------------------*/
  1943. Xint
  1944. Xpcmd_break(param)
  1945. XESD *param;
  1946. X{
  1947. X    return(eBreakCommand);
  1948. X}    /* end of pcmd_break */
  1949. X
  1950. X/*+-------------------------------------------------------------------------
  1951. X    pcmd_continue(param)
  1952. X--------------------------------------------------------------------------*/
  1953. Xint
  1954. Xpcmd_continue(param)
  1955. XESD *param;
  1956. X{
  1957. X    return(eContinueCommand);
  1958. X}    /* end of pcmd_continue */
  1959. X
  1960. X/*+-------------------------------------------------------------------------
  1961. X    execute_frame(truth)
  1962. X
  1963. X  pcb_stack[proc_level - 1]->current points to lcb behind frame: one
  1964. X  statement or { statements }
  1965. X
  1966. X  if truth true, execute frame, else skip it
  1967. X--------------------------------------------------------------------------*/
  1968. Xint
  1969. Xexecute_frame(truth)
  1970. Xint truth;
  1971. X{
  1972. Xregister itmp;
  1973. Xint erc = 0;
  1974. XPCB *pcb = pcb_stack[proc_level - 1];
  1975. XLCB *original_lcb = pcb->current;
  1976. XLCB *begin_lcb;
  1977. XESD *text;
  1978. Xint nest_level = 0;
  1979. Xint remember_break = 0;
  1980. X
  1981. X    if(!(pcb->current = pcb->current->next))
  1982. X    {
  1983. X        pcb->current = original_lcb;
  1984. X        return(eNoFrame);
  1985. X    }
  1986. X
  1987. X    text = pcb->current->text;
  1988. X    text->old_index = text->index = 0;
  1989. X
  1990. X    if(*text->pb != SPACE)
  1991. X        return(eLabelInvalidHere);
  1992. X    skip_cmd_break(text);
  1993. X
  1994. X/* handle single statement frame */
  1995. X    if(*(text->pb + text->index) != '{')
  1996. X    {
  1997. X        itmp = text->cb - text->index;
  1998. X        if( ((itmp > 2) && !strncmp(text->pb + text->index,"if",2)))
  1999. X        {
  2000. X            pputs("command must appear inside {} or on same line as else\n");
  2001. X            erc = eFATAL_ALREADY;
  2002. X        }
  2003. X        else if( ((itmp > 5) && !strncmp(text->pb + text->index,"while",5)))
  2004. X        {
  2005. X            pputs("command must appear inside {} within this context\n");
  2006. X            erc = eFATAL_ALREADY;
  2007. X        }
  2008. X        else if(truth)
  2009. X        {
  2010. X            trace_proc_cmd(pcb);
  2011. X            erc = execute_esd(text);
  2012. X        }
  2013. X        return(erc);
  2014. X    }
  2015. X
  2016. X/* we've got a {} frame */
  2017. X    begin_lcb = pcb->current;
  2018. X    pcb->current = pcb->current->next;
  2019. X    while(pcb->current)
  2020. X    {
  2021. X        if(proc_interrupt)
  2022. X            return(eCONINT);
  2023. X        text = pcb->current->text;
  2024. X        text->old_index = text->index = 0;
  2025. X        if(*text->pb != SPACE)
  2026. X            return(eLabelInvalidHere);
  2027. X        skip_cmd_break(text);
  2028. X        if(*(text->pb + text->index) == '}')
  2029. X        {
  2030. X            if(!nest_level)
  2031. X            {
  2032. X                text->index = text->cb;
  2033. X                if(remember_break)
  2034. X                    return(eBreakCommand);
  2035. X                return(0);
  2036. X            }
  2037. X            nest_level--;
  2038. X        }
  2039. X        else if(truth)
  2040. X        {
  2041. X            trace_proc_cmd(pcb);
  2042. X            if(erc = execute_esd(text))
  2043. X            {
  2044. X                if(erc != eBreakCommand)
  2045. X                    return(erc);
  2046. X                remember_break = 1;
  2047. X                truth = 0;
  2048. X            }
  2049. X        }
  2050. X        else if(*(text->pb + text->index) == '{')
  2051. X            nest_level++;
  2052. X        pcb->current = pcb->current->next;
  2053. X    }
  2054. X    pcb->current = begin_lcb;
  2055. X    return(eNoCloseFrame);
  2056. X    
  2057. X}    /* end of execute_frame */
  2058. X
  2059. X/* vi: set tabstop=4 shiftwidth=4: */
  2060. X/* end of procframe.c */
  2061. SHAR_EOF
  2062. $TOUCH -am 1224224390 'procframe.c' &&
  2063. chmod 0644 procframe.c ||
  2064. echo 'restore of procframe.c failed'
  2065. Wc_c="`wc -c < 'procframe.c'`"
  2066. test 3397 -eq "$Wc_c" ||
  2067.     echo 'procframe.c: original size 3397, current size' "$Wc_c"
  2068. true || echo 'restore of regexp.c failed'
  2069. echo End of part 14, continue with part 15
  2070. exit 0
  2071. --------------------------------------------------------------------
  2072. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2073. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2074.  
  2075. exit 0 # Just in case...
  2076. -- 
  2077. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2078. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2079. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2080. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2081.