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

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i037:  ECU async comm package rev 3.0, Part13/35
  4. Message-ID: <1991Jan6.052144.27913@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:21:44 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: ae6b5579 49cb61a0 7bd7a719 1bf330cb
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 37
  11. Archive-name: ecu3/part13
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 13 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= pcmdfile.c ==============
  21. echo 'x - extracting pcmdfile.c (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'pcmdfile.c' &&
  23. X/*+-------------------------------------------------------------------------
  24. X    pcmdfile.c - ecu file-related procedure commands
  25. X    wht@n4hgf.Mt-Park.GA.US
  26. X
  27. X  Defined functions:
  28. X    _file_not_open(filenum)
  29. X    _gfilenum(param,filenum)
  30. X    _param_to_stat(param,pstat_rtnd)
  31. X    pcmd_fchmod(param)
  32. X    pcmd_fclose(param)
  33. X    pcmd_fdel(param)
  34. X    pcmd_fgetc(param)
  35. X    pcmd_fgets(param)
  36. X    pcmd_fopen(param)
  37. X    pcmd_fputc(param)
  38. X    pcmd_fputs(param)
  39. X    pcmd_fread(param)
  40. X    pcmd_fseek(param)
  41. X    pcmd_fwrite(param)
  42. X    pcmd_mkdir(param)
  43. X    pcmd_pclose(param)
  44. X    pcmd_popen(param)
  45. X    ifunc_fatime(param,pvalue)
  46. X    ifunc_fmode(param,pvalue)
  47. X    ifunc_fmtime(param,pvalue)
  48. X    ifunc_fsize(param,pvalue)
  49. X    ifunc_ftell(param,pvalue)
  50. X    ifunc_ischr(param,pvalue)
  51. X    ifunc_isdir(param,pvalue)
  52. X    ifunc_isreg(param,pvalue)
  53. X    proc_file_reset()
  54. X    str_to_filemode(modestr,filemode)
  55. X
  56. X--------------------------------------------------------------------------*/
  57. X/*+:EDITS:*/
  58. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  59. X
  60. X#include "ecu.h"
  61. X#include "ecukey.h"
  62. X#include "ecuerror.h"
  63. X#include "esd.h"
  64. X#include "var.h"
  65. X#include "proc.h"
  66. X
  67. X#if !defined(S_IRUSR)
  68. X#define    S_IRUSR    00400        /* read permission: owner */
  69. X#define    S_IWUSR    00200        /* write permission: owner */
  70. X#define    S_IXUSR    00100        /* execute permission: owner */
  71. X#define    S_IRWXG    00070        /* read, write, execute: group */
  72. X#define    S_IRGRP    00040        /* read permission: group */
  73. X#define    S_IWGRP    00020        /* write permission: group */
  74. X#define    S_IXGRP    00010        /* execute permission: group */
  75. X#define    S_IRWXO    00007        /* read, write, execute: other */
  76. X#define    S_IROTH    00004        /* read permission: other */
  77. X#define    S_IWOTH    00002        /* write permission: other */
  78. X#define    S_IXOTH    00001        /* execute permission: other */
  79. X#endif
  80. X
  81. Xextern int proctrace;
  82. Xextern int rcvr_pid;
  83. Xextern int errno;
  84. Xextern proc_level;
  85. Xextern PCB *pcb_stack[];
  86. X
  87. X#define FILE_MAX    5
  88. X
  89. Xtypedef struct pfile_struct
  90. X{
  91. X    FILE *f;    /* file pointer */
  92. X    ESD *n;        /* file name */
  93. X} PFILE;
  94. X
  95. XPFILE pfile[FILE_MAX];
  96. X
  97. Xchar fwrite_error_fmt[] = "file %d write error (not open for write?)\n";
  98. X
  99. X/*+-------------------------------------------------------------------------
  100. X    proc_file_reset()
  101. X--------------------------------------------------------------------------*/
  102. Xvoid
  103. Xproc_file_reset()
  104. X{
  105. Xregister itmp;
  106. X
  107. X    for(itmp = 0; itmp < FILE_MAX; itmp++)
  108. X    {
  109. X        if(pfile[itmp].f)
  110. X        {
  111. X            fclose(pfile[itmp].f);
  112. X            pfile[itmp].f = NULL;
  113. X            free_esd(pfile[itmp].n);
  114. X        }
  115. X    }
  116. X}    /* end of proc_file_reset */
  117. X
  118. X/*+-------------------------------------------------------------------------
  119. X    _file_not_open(filenum)
  120. X--------------------------------------------------------------------------*/
  121. Xint
  122. X_file_not_open(filenum)
  123. Xint filenum;
  124. X{
  125. X    pprintf("file %d not open\n",filenum);
  126. X    return(eFATAL_ALREADY);
  127. X}    /* end of _file_not_open */
  128. X
  129. X/*+-------------------------------------------------------------------------
  130. X    _gfilenum(param,filenum)
  131. X--------------------------------------------------------------------------*/
  132. Xint
  133. X_gfilenum(param,filenum)
  134. XESD *param;
  135. Xint *filenum;
  136. X{
  137. Xint erc;
  138. Xulong lvarnum;
  139. Xint old_index;
  140. X
  141. X    skip_cmd_break(param);
  142. X    old_index = param->old_index;
  143. X    if(erc = gint(param,&lvarnum))
  144. X        return(erc);
  145. X    if(lvarnum > FILE_MAX)
  146. X        return(eBadFileNumber);
  147. X    *filenum = (int)lvarnum;
  148. X    param->old_index = old_index;
  149. X    return(0);
  150. X}    /* end of _gfilenum */
  151. X
  152. X/*+-------------------------------------------------------------------------
  153. X    str_to_filemode(modestr,filemode) - "rwxrwxrwx" to mode integer
  154. X--------------------------------------------------------------------------*/
  155. Xstr_to_filemode(modestr,filemode)
  156. Xchar *modestr;
  157. Xlong *filemode;
  158. X{
  159. Xregister i;
  160. Xregister mode = 0;
  161. Xint erc = 0;
  162. X
  163. X    if(strlen(modestr) != 9)
  164. X    {
  165. X        pprintf("bad length: '%s'\n",modestr);
  166. X        return(eFATAL_ALREADY);
  167. X    }
  168. X
  169. X    for(i=0; i < 9; i++)
  170. X    {
  171. X        switch(modestr[i])
  172. X        {
  173. X
  174. X        case 'r':
  175. X            if(i == 0)
  176. X                mode |= S_IRUSR;
  177. X            else if(i == 3)
  178. X                mode |= S_IRGRP;
  179. X            else if(i == 6)
  180. X                mode |= S_IROTH;
  181. X            else
  182. X                erc = eSyntaxError;
  183. X            break;
  184. X
  185. X
  186. X        case 'w':
  187. X            if(i == 1)
  188. X                mode |= S_IWUSR;
  189. X            else if(i == 4)
  190. X                mode |= S_IWGRP;
  191. X            else if(i == 7)
  192. X                mode |= S_IWOTH;
  193. X            else
  194. X                erc = eSyntaxError;
  195. X            break;
  196. X
  197. X
  198. X        case 'x':
  199. X            if(i == 2)
  200. X                mode |= S_IXUSR;
  201. X            else if(i == 5)
  202. X                mode |= S_IXGRP;
  203. X            else if(i == 8)
  204. X                mode |= S_IXOTH;
  205. X            else
  206. X                erc = eSyntaxError;
  207. X            break;
  208. X
  209. X
  210. X        case 's':
  211. X#if defined(FULL_FEATURE_CHMODE)
  212. X            if(i == 2)
  213. X            {
  214. X                mode |= S_ISUID;
  215. X                mode |= S_IXUSR;
  216. X            }
  217. X            else if(i == 5)
  218. X            {
  219. X                mode |= S_ISGID;
  220. X                mode |= S_IXGRP;
  221. X            }
  222. X            else
  223. X                erc = eSyntaxError;
  224. X#else
  225. X            pputs("setuid/setgid not allowed\n");
  226. X            erc = eFATAL_ALREADY;
  227. X#endif /* defined(FULL_FEATURE_CHMODE) */
  228. X            break;
  229. X
  230. X
  231. X        case 't':
  232. X#if defined(FULL_FEATURE_CHMODE)
  233. X            if(i == 8)
  234. X            {
  235. X                mode |= S_ISVTX;
  236. X                mode |= S_IXOTH;
  237. X            }
  238. X            else
  239. X                erc = eSyntaxError;
  240. X#else
  241. X            pputs("set sticky bit not allowed\n");
  242. X            erc = eFATAL_ALREADY;
  243. X#endif /* defined(FULL_FEATURE_CHMODE) */
  244. X            break;
  245. X        case 'l':
  246. X            if(i == 5)
  247. X            {
  248. X                mode |= S_ISGID;
  249. X                mode &= ~S_IXGRP;
  250. X            }
  251. X            else
  252. X                erc = eSyntaxError;
  253. X            break;
  254. X        case '-':
  255. X            break;
  256. X        default:
  257. X            erc = eSyntaxError;
  258. X        }    /* end switch */
  259. X
  260. X        if(erc)
  261. X            break;
  262. X
  263. X    }        /* end for */
  264. X
  265. X    if(erc)
  266. X    {
  267. X        if(erc != eFATAL_ALREADY)
  268. X            pputs("invalid mode specifier\n");
  269. X        pputs(modestr);
  270. X        while(i--)
  271. X            pputc(' ');
  272. X        pputs("^\n");
  273. X        
  274. X    }
  275. X    else
  276. X        *filemode = (long)mode;
  277. X
  278. X    return(erc);
  279. X
  280. X}    /* end of str_to_filemode */
  281. X
  282. X/*+-------------------------------------------------------------------------
  283. X    pcmd_fgetc(param)
  284. X
  285. Xfgetc <filenum-int> [$][i<varspec> | $s<varspec>]
  286. Xint variable receives 0 if EOF
  287. Xstr var receives null str on eof
  288. X--------------------------------------------------------------------------*/
  289. Xint
  290. Xpcmd_fgetc(param)
  291. XESD *param;
  292. X{
  293. Xint erc;
  294. Xint filenum;
  295. Xint vartype;
  296. Xint inchar;
  297. XESD *svptr;
  298. Xlong *ivptr;
  299. X
  300. X    if(!proc_level)
  301. X        return(eNotExecutingProc);
  302. X
  303. X    if(erc = _gfilenum(param,&filenum))
  304. X        return(erc);
  305. X
  306. X    if(!pfile[filenum].f)
  307. X        return(_file_not_open(filenum));
  308. X
  309. X    skip_cmd_char(param,'$');
  310. X    if((param->index >= param->cb) ||
  311. X        ( ((vartype = to_lower(*(param->pb + param->index))) != 'i') &&
  312. X            (vartype != 's')))
  313. X        return(eIllegalVarType);
  314. X    param->index++;
  315. X    switch(vartype)
  316. X    {
  317. X        case 'i':
  318. X            erc = get_ivptr(param,&ivptr,1);
  319. X            break;
  320. X        default:
  321. X            erc = get_svptr(param,&svptr,1);
  322. X            break;
  323. X    }
  324. X    if(erc)
  325. X        return(erc);
  326. X
  327. X    if((inchar = fgetc(pfile[filenum].f)) == EOF)
  328. X    {
  329. X        if(proctrace)
  330. X            pputs("fgetc EOF\n");
  331. X        if(vartype == 'i')
  332. X            *ivptr = -1;
  333. X        else
  334. X            zero_esd(svptr);
  335. X    }
  336. X    else if(vartype == 'i')
  337. X        *ivptr = inchar;
  338. X    else
  339. X    {
  340. X        *svptr->pb = inchar;
  341. X        svptr->cb = 1;
  342. X    }
  343. X
  344. X    if(proctrace)
  345. X    {
  346. X        pputs("fgetc set ");
  347. X        pputs((vartype == 'i') ? "int" : "str");
  348. X        pprintf(" var = %lu (0x%02x)\n",inchar,inchar);
  349. X    }
  350. X    return(0);
  351. X
  352. X}    /* end of pcmd_fgetc */
  353. X
  354. X/*+-------------------------------------------------------------------------
  355. X    pcmd_fread(param)
  356. X--------------------------------------------------------------------------*/
  357. Xint
  358. Xpcmd_fread(param)
  359. XESD *param;
  360. X{
  361. X    return(eNotImplemented);
  362. X}    /* end of pcmd_fread */
  363. X
  364. X/*+-------------------------------------------------------------------------
  365. X    pcmd_fgets(param)
  366. Xfgetc <filenum-int> [$][s]<varspec>
  367. X--------------------------------------------------------------------------*/
  368. Xint
  369. Xpcmd_fgets(param)
  370. XESD *param;
  371. X{
  372. Xint erc;
  373. Xint filenum;
  374. Xchar ctmp;
  375. XESD *svptr;
  376. X
  377. X    if(!proc_level)
  378. X        return(eNotExecutingProc);
  379. X
  380. X    if(erc = _gfilenum(param,&filenum))
  381. X        return(erc);
  382. X
  383. X    if(!pfile[filenum].f)
  384. X        return(_file_not_open(filenum));
  385. X
  386. X    skip_cmd_char(param,'$');
  387. X    if(erc = get_cmd_char(param,&ctmp))
  388. X        return(erc);
  389. X    if(to_lower(ctmp) != 's')
  390. X        return(eIllegalVarType);
  391. X    if(erc = get_svptr(param,&svptr,1))
  392. X        return(erc);
  393. X    *svptr->pb = 0;
  394. X    svptr->cb = 0;
  395. X    if(!(iv[0] = !fgets(svptr->pb,svptr->maxcb + 1,pfile[filenum].f)))
  396. X    {
  397. X        svptr->cb = strlen(svptr->pb);
  398. X        if(*(svptr->pb + svptr->cb - 1) == NL)
  399. X        {
  400. X            svptr->cb--;
  401. X            null_terminate_esd(svptr);
  402. X        }
  403. X    }
  404. X    if(proctrace)
  405. X        pprintf("fgets set str var = '%s'\n",svptr->pb);
  406. X    return(0);
  407. X
  408. X}    /* end of pcmd_fgets */
  409. X
  410. X/*+-------------------------------------------------------------------------
  411. X    pcmd_fclose(param)
  412. Xfclose <filenum-int>
  413. X--------------------------------------------------------------------------*/
  414. Xint
  415. Xpcmd_fclose(param)
  416. XESD *param;
  417. X{
  418. Xint erc;
  419. Xint filenum;
  420. X
  421. X    if(!proc_level)
  422. X        return(eNotExecutingProc);
  423. X
  424. X    if(erc = _gfilenum(param,&filenum))
  425. X        return(erc);
  426. X
  427. X    if(pfile[filenum].f)
  428. X    {
  429. X        fclose(pfile[filenum].f);
  430. X        pfile[filenum].f = NULL;
  431. X        free_esd(pfile[filenum].n);
  432. X    }
  433. X
  434. X    return(0);
  435. X
  436. X}    /* end of pcmd_fclose */
  437. X
  438. X/*+-------------------------------------------------------------------------
  439. X    pcmd_fputc(param)
  440. Xfputc <file-num> <int>
  441. Xfputc <file-num> <str>
  442. X--------------------------------------------------------------------------*/
  443. Xint
  444. Xpcmd_fputc(param)
  445. XESD *param;
  446. X{
  447. Xint erc;
  448. Xint filenum;
  449. XESD *buf = (ESD *)0;
  450. Xchar outchar = 0;
  451. Xlong outlong;
  452. X
  453. X    if(!proc_level)
  454. X        return(eNotExecutingProc);
  455. X
  456. X    if(erc = _gfilenum(param,&filenum))
  457. X        return(erc);
  458. X
  459. X    if(!pfile[filenum].f)
  460. X        return(_file_not_open(filenum));
  461. X
  462. X    if(!gint(param,&outlong))
  463. X        outchar = (char)outlong;
  464. X    else
  465. X    {
  466. X        if((buf = make_esd(64)) == (ESD *)0)
  467. X            return(eNoMemory);
  468. X        if(erc = gstr(param,buf,1))
  469. X            goto RETURN;
  470. X        if(!buf->cb)
  471. X        {
  472. X            pputs("cannot fputc: zero length string\n");
  473. X            erc = eFATAL_ALREADY;
  474. X            goto RETURN;
  475. X        }
  476. X        outchar = *buf->pb;
  477. X    }
  478. X
  479. X    if(fputc(outchar,pfile[filenum].f) < 0)
  480. X    {
  481. X        pprintf(fwrite_error_fmt,filenum);
  482. X        erc = eFATAL_ALREADY;
  483. X    }
  484. X
  485. XRETURN:
  486. X    if(buf)
  487. X        free_esd(buf);
  488. X    return(erc);
  489. X}    /* end of pcmd_fputc */
  490. X
  491. X/*+-------------------------------------------------------------------------
  492. X    pcmd_fopen(param)
  493. X
  494. Xfopen [-<fopen_switches>] <filenum-int> <filename-str>
  495. Xsets $i0 with result
  496. X--------------------------------------------------------------------------*/
  497. Xint
  498. Xpcmd_fopen(param)
  499. XESD *param;
  500. X{
  501. Xint erc;
  502. Xint filenum;
  503. XESD *fname = (ESD *)0;
  504. Xchar switches[8];
  505. X
  506. X    if(!proc_level)
  507. X        return(eNotExecutingProc);
  508. X
  509. X    if(get_switches(param,switches,sizeof(switches)))
  510. X    {
  511. X        strcpy(switches,"-r");
  512. X        if(proctrace)
  513. X        {
  514. X            pputs("Warning: fopen defaulting to read\n");
  515. X            show_error_position(pcb_stack[proc_level - 1]);
  516. X        }
  517. X    }
  518. X
  519. X    if(erc = _gfilenum(param,&filenum))
  520. X        return(erc);
  521. X
  522. X    if(pfile[filenum].f)
  523. X    {
  524. X        pprintf("file %d already open\n",filenum);
  525. X        return(eFATAL_ALREADY);
  526. X    }
  527. X
  528. X    if((fname = make_esd(256)) == (ESD *)0)
  529. X        return(eNoMemory);
  530. X
  531. X    if(erc = gstr(param,fname,1))
  532. X        goto RETURN;
  533. X
  534. X    iv[0] = 0;
  535. X    if((pfile[filenum].f = fopen(fname->pb,switches + 1)) == NULL)
  536. X    {
  537. X        if(proctrace)
  538. X        {
  539. X            pprintf("'%s'",fname->pb);
  540. X            pperror(" ");
  541. X            iv[0] = (long)errno;
  542. X        }
  543. X    }
  544. X    else if(proctrace)
  545. X        pprintf("opened '%s' as file %d\n",fname->pb,filenum);
  546. X
  547. X    if(!erc)
  548. X        pfile[filenum].n = fname;
  549. X
  550. XRETURN:
  551. X    if(erc)
  552. X        free_esd(fname);
  553. X    return(erc);
  554. X}    /* end of pcmd_fopen */
  555. X
  556. X/*+-------------------------------------------------------------------------
  557. X    pcmd_fputs(param)
  558. Xfputs [-n] <filenum-int> <str>
  559. X-n do not output newline after <str>
  560. X<filenum-int> file number for operation
  561. X<str> string to write to file
  562. X--------------------------------------------------------------------------*/
  563. Xint
  564. Xpcmd_fputs(param)
  565. XESD *param;
  566. X{
  567. Xint erc;
  568. Xint filenum;
  569. XESD *buf = (ESD *)0;
  570. Xchar switches[8];
  571. X
  572. X    if(!proc_level)
  573. X        return(eNotExecutingProc);
  574. X
  575. X    get_switches(param,switches,sizeof(switches));
  576. X
  577. X    if(erc = _gfilenum(param,&filenum))
  578. X        return(erc);
  579. X
  580. X    if(!pfile[filenum].f)
  581. X        return(_file_not_open(filenum));
  582. X
  583. X    if((buf = make_esd(256)) == (ESD *)0)
  584. X        return(eNoMemory);
  585. X
  586. X    if(erc = gstr(param,buf,1))
  587. X        goto RETURN;
  588. X
  589. X    if(!fputs(buf->pb,pfile[filenum].f) && strlen(buf->pb))
  590. X    {
  591. X        pprintf(fwrite_error_fmt,filenum);
  592. X        erc = eFATAL_ALREADY;
  593. X        goto RETURN;
  594. X    }
  595. X
  596. X    if(!strchr(switches,'n'))
  597. X        fputc(NL,pfile[filenum].f);
  598. X
  599. XRETURN:
  600. X    free_esd(buf);
  601. X    return(erc);
  602. X}    /* end of pcmd_fputs */
  603. X
  604. X/*+-------------------------------------------------------------------------
  605. X    pcmd_fwrite(param)
  606. Xfwrite <filenum-int> <str>
  607. X--------------------------------------------------------------------------*/
  608. Xint
  609. Xpcmd_fwrite(param)
  610. XESD *param;
  611. X{
  612. X    return(eNotImplemented);
  613. X#ifdef USE_FWRITE
  614. Xint erc;
  615. Xint filenum;
  616. XESD *buf = (ESD *)0;
  617. X
  618. X    if(!proc_level)
  619. X        return(eNotExecutingProc);
  620. X
  621. X    if(erc = _gfilenum(param,&filenum))
  622. X        return(erc);
  623. X
  624. X    if(!pfile[filenum].f)
  625. X        return(_file_not_open(filenum));
  626. X
  627. X    if((buf = make_esd(256)) == (ESD *)0)
  628. X        return(eNoMemory);
  629. X
  630. X    if(erc = gstr(param,buf,1))
  631. X        goto RETURN;
  632. X
  633. X    if(!fputs(buf->pb,pfile[filenum].f) && strlen(buf->pb))
  634. X    {
  635. X        pprintf(fwrite_error_fmt,filenum);
  636. X        erc = eFATAL_ALREADY;
  637. X    }
  638. X
  639. XRETURN:
  640. X    free_esd(buf);
  641. X    return(erc);
  642. X#endif
  643. X}    /* end of pcmd_fwrite */
  644. X
  645. X/*+-------------------------------------------------------------------------
  646. X    pcmd_fchmod(param)
  647. X
  648. Xfchmod <mode-str> | <mode-int> <filenum-int> | <filename-str>
  649. X$i0 = 0 if successful, else errno
  650. X--------------------------------------------------------------------------*/
  651. Xint
  652. Xpcmd_fchmod(param)
  653. XESD *param;
  654. X{
  655. Xint erc;
  656. Xint filenum;
  657. XESD *fname = (ESD *)0;
  658. XESD *mode = (ESD *)0;
  659. Xlong new_mode;
  660. Xchar *cptr;
  661. X
  662. X    if((fname = make_esd(256)) == (ESD *)0)
  663. X        return(eNoMemory);
  664. X
  665. X    if((mode = make_esd(64)) == (ESD *)0)
  666. X    {
  667. X        free_esd(fname);
  668. X        return(eNoMemory);
  669. X    }
  670. X
  671. X    if(erc = skip_cmd_break(param))
  672. X        goto RETURN;
  673. X    else if(!gstr(param,mode,0))
  674. X    {
  675. X        if(erc = str_to_filemode(mode->pb,&new_mode))
  676. X            goto RETURN;
  677. X    }
  678. X    else if(erc = gint(param,&new_mode))
  679. X    {
  680. X        erc = eBadParameter;
  681. X        goto RETURN;
  682. X    }
  683. X
  684. X    if(erc = skip_cmd_break(param))
  685. X        goto RETURN;
  686. X    else if(!gstr(param,fname,1))
  687. X    {
  688. X        cptr = fname->pb;
  689. X        if(iv[0] = (long)chmod(cptr,(int)new_mode &= 0777))
  690. X        {
  691. X            iv[0] = (long)errno;
  692. X            if(proctrace)
  693. X                pperror(cptr);
  694. X        }
  695. X    }
  696. X    else if(!_gfilenum(param,&filenum))
  697. X    {
  698. X        if(!pfile[filenum].f)
  699. X        {
  700. X            erc = (_file_not_open(filenum));
  701. X            iv[0] = EBADF;
  702. X        }
  703. X        else if(iv[0] = (long)chmod(pfile[filenum].n->pb,(int)new_mode & 0777))
  704. X        {
  705. X            iv[0] = (long)errno;
  706. X            if(proctrace)
  707. X            {
  708. X                sprintf(fname->pb,"file %d",filenum);
  709. X                pperror(fname->pb);
  710. X            }
  711. X        }
  712. X        if(!iv[0])
  713. X            cptr = pfile[filenum].n->pb;
  714. X    }
  715. X    else
  716. X        erc = eBadParameter;
  717. X
  718. X    if(proctrace && !erc && !iv[0])
  719. X        pprintf("'%s' mode set to %o\n",cptr,0100000 | (int)new_mode);
  720. X
  721. XRETURN:
  722. X    free_esd(mode);
  723. X    free_esd(fname);
  724. X
  725. X    return(erc);
  726. X
  727. X}    /* end of pcmd_fchmod */
  728. X
  729. X/*+-------------------------------------------------------------------------
  730. X    pcmd_fdel(param)
  731. X
  732. Xfdel <filename-str>
  733. X$i0 = 0 if successful, else errno
  734. X--------------------------------------------------------------------------*/
  735. Xint
  736. Xpcmd_fdel(param)
  737. XESD *param;
  738. X{
  739. Xint erc;
  740. XESD *fname = (ESD *)0;
  741. X
  742. X    if((fname = make_esd(256)) == (ESD *)0)
  743. X        return(eNoMemory);
  744. X
  745. X    if(erc = gstr(param,fname,1))
  746. X        goto RETURN;
  747. X
  748. X    if(iv[0] = (long)unlink(fname->pb))
  749. X        iv[0] = (long)errno;
  750. X
  751. X    if(proctrace)
  752. X    {
  753. X        if(iv[0])
  754. X            pperror(fname->pb);
  755. X        else
  756. X            pprintf("'%s' deleted\n",fname->pb);
  757. X    }
  758. X
  759. XRETURN:
  760. X    free_esd(fname);
  761. X    return(erc);
  762. X}    /* end of pcmd_fdel */
  763. X
  764. X/*+-------------------------------------------------------------------------
  765. X    pcmd_fseek(param)
  766. Xfseek <filenum-int> <filepos-int>
  767. Xsets $i0 with result
  768. X--------------------------------------------------------------------------*/
  769. Xint
  770. Xpcmd_fseek(param)
  771. XESD *param;
  772. X{
  773. Xint erc;
  774. Xint filenum;
  775. Xlong seekpos;
  776. X
  777. X    if(!proc_level)
  778. X        return(eNotExecutingProc);
  779. X    if(erc = _gfilenum(param,&filenum))
  780. X        return(erc);
  781. X    if(!pfile[filenum].f)
  782. X        return(_file_not_open(filenum));
  783. X    if(erc = gint(param,&seekpos))
  784. X        return(erc);
  785. X
  786. X    iv[0] = 0;
  787. X    if(fseek(pfile[filenum].f,seekpos,0) < 0)
  788. X    {
  789. X        if(proctrace)
  790. X        {
  791. X            pprintf("file %d ",filenum);
  792. X            pperror("seekerror");
  793. X        }
  794. X        iv[0] = (int)errno;
  795. X    }
  796. X    else if(proctrace)
  797. X        pprintf("file %d set to position %ld\n",filenum,seekpos);
  798. X
  799. X    return(erc);
  800. X
  801. X}    /* end of pcmd_fseek */
  802. X
  803. X/*+-------------------------------------------------------------------------
  804. X    pcmd_mkdir(param)
  805. X
  806. Xmkdir <filename-str>
  807. X$i0 = 0 if successful, else errno
  808. X--------------------------------------------------------------------------*/
  809. Xint
  810. Xpcmd_mkdir(param)
  811. XESD *param;
  812. X{
  813. Xint erc;
  814. XESD *fname = (ESD *)0;
  815. X
  816. X    if((fname = make_esd(256)) == (ESD *)0)
  817. X        return(eNoMemory);
  818. X
  819. X    if(erc = gstr(param,fname,1))
  820. X        goto RETURN;
  821. X
  822. X    if(iv[0] = (long)mkdir(fname->pb,0755))
  823. X        iv[0] = (long)errno;
  824. X
  825. X    if(proctrace)
  826. X    {
  827. X        if(iv[0])
  828. X            pperror(fname->pb);
  829. X        else
  830. X            pprintf("'%s' deleted\n",fname->pb);
  831. X    }
  832. X
  833. XRETURN:
  834. X    free_esd(fname);
  835. X    return(erc);
  836. X}    /* end of pcmd_mkdir */
  837. X
  838. X/*+-------------------------------------------------------------------------
  839. X    pcmd_pclose(param)
  840. Xpclose <filenum-int>
  841. X--------------------------------------------------------------------------*/
  842. Xint
  843. Xpcmd_pclose(param)
  844. XESD *param;
  845. X{
  846. Xint erc;
  847. Xint filenum;
  848. X
  849. X    if(!proc_level)
  850. X        return(eNotExecutingProc);
  851. X
  852. X    if(erc = _gfilenum(param,&filenum))
  853. X        return(erc);
  854. X
  855. X    if(pfile[filenum].f)
  856. X    {
  857. X        pclose(pfile[filenum].f);
  858. X        pfile[filenum].f = NULL;
  859. X        free_esd(pfile[filenum].n);
  860. X    }
  861. X
  862. X    return(0);
  863. X
  864. X}    /* end of pcmd_pclose */
  865. X
  866. X/*+-------------------------------------------------------------------------
  867. X    pcmd_popen(param)
  868. X
  869. Xpopen [-<popen_switches>] <filenum-int> <filename-str>
  870. Xsets $i0 with result
  871. X--------------------------------------------------------------------------*/
  872. Xint
  873. Xpcmd_popen(param)
  874. XESD *param;
  875. X{
  876. Xint erc;
  877. Xint filenum;
  878. XESD *fname = (ESD *)0;
  879. Xchar switches[8];
  880. X#if !defined(M_UNIX)
  881. XFILE *popen();
  882. X#endif
  883. X
  884. X    if(!proc_level)
  885. X        return(eNotExecutingProc);
  886. X
  887. X    if(get_switches(param,switches,sizeof(switches)))
  888. X    {
  889. X        strcpy(switches,"-r");
  890. X        if(proctrace)
  891. X        {
  892. X            pputs("Warning: popen defaulting to read\n");
  893. X            show_error_position(pcb_stack[proc_level - 1]);
  894. X        }
  895. X    }
  896. X
  897. X    if(erc = _gfilenum(param,&filenum))
  898. X        return(erc);
  899. X
  900. X    if(pfile[filenum].f)
  901. X    {
  902. X        pprintf("file %d already open\n",filenum);
  903. X        return(eFATAL_ALREADY);
  904. X    }
  905. X
  906. X    if((fname = make_esd(256)) == (ESD *)0)
  907. X        return(eNoMemory);
  908. X
  909. X    if(erc = gstr(param,fname,1))
  910. X        goto RETURN;
  911. X
  912. X    iv[0] = 0;
  913. X    if((pfile[filenum].f = popen(fname->pb,switches + 1)) == NULL)
  914. X    {
  915. X        if(proctrace)
  916. X        {
  917. X            pprintf("'%s'",fname->pb);
  918. X            pperror(" ");
  919. X            iv[0] = (long)errno;
  920. X        }
  921. X    }
  922. X    else if(proctrace)
  923. X        pprintf("opened '%s' as file %d\n",fname->pb,filenum);
  924. X
  925. X    if(!erc)
  926. X        pfile[filenum].n = fname;
  927. X
  928. XRETURN:
  929. X    if(erc)
  930. X        free_esd(fname);
  931. X    return(erc);
  932. X}    /* end of pcmd_popen */
  933. X
  934. X/*+-------------------------------------------------------------------------
  935. X    ifunc_ftell(param,pvalue)
  936. X%ftell(<filenum-int>)
  937. X--------------------------------------------------------------------------*/
  938. Xint
  939. Xifunc_ftell(param,pvalue)
  940. XESD *param;
  941. Xlong *pvalue;
  942. X{
  943. Xint erc;
  944. Xint filenum;
  945. Xlong ftell();
  946. X
  947. X    if(!proc_level)
  948. X        return(eNotExecutingProc);
  949. X    if(erc = skip_paren(param,1))
  950. X        return(erc);
  951. X    if(erc = _gfilenum(param,&filenum))
  952. X        return(erc);
  953. X    if(!pfile[filenum].f)
  954. X        return(_file_not_open(filenum));
  955. X    if(erc = skip_paren(param,0))
  956. X        return(erc);
  957. X
  958. X    *pvalue = ftell(pfile[filenum].f);
  959. X    return(0);
  960. X}    /* end of ifunc_ftell */
  961. X
  962. X/*+-------------------------------------------------------------------------
  963. X    _param_to_stat(param,pstat_rtnd)
  964. X--------------------------------------------------------------------------*/
  965. Xint
  966. X_param_to_stat(param,pstat_rtnd)
  967. XESD *param;
  968. Xstruct stat **pstat_rtnd;
  969. X{
  970. Xint erc;
  971. Xint filenum;
  972. Xstatic struct stat fst;
  973. Xstruct stat *pstat = &fst;
  974. XESD *fname;
  975. X
  976. X    errno = 0;
  977. X
  978. X    if(erc = skip_paren(param,1))
  979. X        return(erc);
  980. X
  981. X    if((fname = make_esd(256)) == (ESD *)0)
  982. X        return(eNoMemory);
  983. X
  984. X    if(!gstr(param,fname,1))
  985. X    {
  986. X        if(stat(fname->pb,pstat))
  987. X            pstat = (struct stat *)0;
  988. X    }
  989. X    else if(param->index = param->old_index,!_gfilenum(param,&filenum))
  990. X    {
  991. X        if(!pfile[filenum].f)
  992. X        {
  993. X            free_esd(fname);
  994. X            return(_file_not_open(filenum));
  995. X        }
  996. X        if(stat(pfile[filenum].n->pb,pstat))
  997. X            pstat = (struct stat *)0;
  998. X    }
  999. X    else
  1000. X        erc = eBadParameter;
  1001. X
  1002. X    free_esd(fname);
  1003. X
  1004. X    if(erc)
  1005. X        return(erc);
  1006. X
  1007. X    if(erc = skip_paren(param,0))
  1008. X        return(erc);
  1009. X
  1010. X    *pstat_rtnd = pstat;
  1011. X    if(proctrace && !pstat)
  1012. X        pperror("stat");
  1013. X    return(0);
  1014. X
  1015. X}    /* end of _param_to_stat */
  1016. X
  1017. X/*+-------------------------------------------------------------------------
  1018. X    ifunc_fsize(param,pvalue)
  1019. X%fsize(<filenum-int>)
  1020. X%fsize('filename')
  1021. X--------------------------------------------------------------------------*/
  1022. Xint
  1023. Xifunc_fsize(param,pvalue)
  1024. XESD *param;
  1025. Xlong *pvalue;
  1026. X{
  1027. Xregister erc;
  1028. Xstruct stat *pstat;
  1029. X
  1030. X    if(erc = _param_to_stat(param,&pstat))
  1031. X        return(erc);
  1032. X    if(!pstat)
  1033. X        *pvalue = -1;
  1034. X    else
  1035. X        *pvalue = pstat->st_size;
  1036. X    return(0);
  1037. X}    /* end of ifunc_fsize */
  1038. X
  1039. X/*+-------------------------------------------------------------------------
  1040. X    ifunc_fatime(param,pvalue)
  1041. X%fatime(<filenum-int>)
  1042. X%fatime('filename')
  1043. X--------------------------------------------------------------------------*/
  1044. Xint
  1045. Xifunc_fatime(param,pvalue)
  1046. XESD *param;
  1047. Xlong *pvalue;
  1048. X{
  1049. Xregister erc;
  1050. Xstruct stat *pstat;
  1051. X
  1052. X    if(erc = _param_to_stat(param,&pstat))
  1053. X        return(erc);
  1054. X    if(!pstat)
  1055. X        *pvalue = -1;
  1056. X    else
  1057. X        *pvalue = pstat->st_atime;
  1058. X    return(0);
  1059. X}    /* end of ifunc_fatime */
  1060. X
  1061. X/*+-------------------------------------------------------------------------
  1062. X    ifunc_fmtime(param,pvalue)
  1063. X%fmtime(<filenum-int>)
  1064. X%fmtime('filename')
  1065. X--------------------------------------------------------------------------*/
  1066. Xint
  1067. Xifunc_fmtime(param,pvalue)
  1068. XESD *param;
  1069. Xlong *pvalue;
  1070. X{
  1071. Xregister erc;
  1072. Xstruct stat *pstat;
  1073. X
  1074. X    if(erc = _param_to_stat(param,&pstat))
  1075. X        return(erc);
  1076. X    if(!pstat)
  1077. X        *pvalue = -1;
  1078. X    else
  1079. X        *pvalue = pstat->st_mtime;
  1080. X    return(0);
  1081. X}    /* end of ifunc_fmtime */
  1082. X
  1083. X/*+-------------------------------------------------------------------------
  1084. X    ifunc_fmode(param,pvalue)
  1085. X%fmode(<filenum-int>)
  1086. X%fmode('filename')
  1087. X--------------------------------------------------------------------------*/
  1088. Xint
  1089. Xifunc_fmode(param,pvalue)
  1090. XESD *param;
  1091. Xlong *pvalue;
  1092. X{
  1093. Xregister erc;
  1094. Xstruct stat *pstat;
  1095. X
  1096. X    if(erc = _param_to_stat(param,&pstat))
  1097. X        return(erc);
  1098. X    if(!pstat)
  1099. X        *pvalue = -1;
  1100. X    else
  1101. X        *pvalue = (long)pstat->st_mode;
  1102. X    return(0);
  1103. X}    /* end of ifunc_fmode */
  1104. X
  1105. X/*+-------------------------------------------------------------------------
  1106. X    ifunc_isreg(param,pvalue)
  1107. X%isreg(<filenum-int>)
  1108. X%isreg('filename')
  1109. X--------------------------------------------------------------------------*/
  1110. Xint
  1111. Xifunc_isreg(param,pvalue)
  1112. XESD *param;
  1113. Xlong *pvalue;
  1114. X{
  1115. Xregister erc;
  1116. X
  1117. X    if(erc = ifunc_fmode(param,pvalue))
  1118. X        return(erc);
  1119. X    if(*pvalue != -1)
  1120. X        *pvalue = ((*pvalue & S_IFMT) == S_IFREG);
  1121. X    return(0);
  1122. X}    /* end of ifunc_isreg */
  1123. X
  1124. X/*+-------------------------------------------------------------------------
  1125. X    ifunc_isdir(param,pvalue)
  1126. X%isdir(<filenum-int>)
  1127. X%isdir('filename')
  1128. X--------------------------------------------------------------------------*/
  1129. Xint
  1130. Xifunc_isdir(param,pvalue)
  1131. XESD *param;
  1132. Xlong *pvalue;
  1133. X{
  1134. Xregister erc;
  1135. X
  1136. X    if(erc = ifunc_fmode(param,pvalue))
  1137. X        return(erc);
  1138. X    if(*pvalue != -1)
  1139. X        *pvalue = ((*pvalue & S_IFMT) == S_IFDIR);
  1140. X    return(0);
  1141. X}    /* end of ifunc_isdir */
  1142. X
  1143. X/*+-------------------------------------------------------------------------
  1144. X    ifunc_ischr(param,pvalue)
  1145. X%ischr(<filenum-int>)
  1146. X%ischr('filename')
  1147. X--------------------------------------------------------------------------*/
  1148. Xint
  1149. Xifunc_ischr(param,pvalue)
  1150. XESD *param;
  1151. Xlong *pvalue;
  1152. X{
  1153. Xregister erc;
  1154. X
  1155. X    if(erc = ifunc_fmode(param,pvalue))
  1156. X        return(erc);
  1157. X    if(*pvalue != -1)
  1158. X        *pvalue = ((*pvalue & S_IFMT) == S_IFCHR);
  1159. X    return(0);
  1160. X}    /* end of ifunc_ischr */
  1161. X
  1162. X/* vi: set tabstop=4 shiftwidth=4: */
  1163. X/* end of pcmdfile.c */
  1164. SHAR_EOF
  1165. $TOUCH -am 1224224190 'pcmdfile.c' &&
  1166. chmod 0644 pcmdfile.c ||
  1167. echo 'restore of pcmdfile.c failed'
  1168. Wc_c="`wc -c < 'pcmdfile.c'`"
  1169. test 22839 -eq "$Wc_c" ||
  1170.     echo 'pcmdfile.c: original size 22839, current size' "$Wc_c"
  1171. # ============= pcmdif.c ==============
  1172. echo 'x - extracting pcmdif.c (Text)'
  1173. sed 's/^X//' << 'SHAR_EOF' > 'pcmdif.c' &&
  1174. X/*+-------------------------------------------------------------------------
  1175. X    pcmdif.c - ecu if procedure commands
  1176. X    wht@n4hgf.Mt-Park.GA.US
  1177. X
  1178. X    IFI $i0 rel-op $i1 cmd
  1179. X    IFS $s0 rel-op $s1 cmd
  1180. X    IFLT, IFLE, IFZ, IFNZ, IFGE, IFGT $i0
  1181. X
  1182. X    where rel-op is "=", "==", "!=", "<>", ">", "<", ">=", "=<"
  1183. X
  1184. X  Defined functions:
  1185. X    _cmd_ifrel_common(param,relop)
  1186. X    _if_common(param,truth)
  1187. X    pcmd_else(param)
  1188. X    pcmd_ifge(param)
  1189. X    pcmd_ifgt(param)
  1190. X    pcmd_ifi(param)
  1191. X    pcmd_ifle(param)
  1192. X    pcmd_iflt(param)
  1193. X    pcmd_ifnz(param)
  1194. X    pcmd_ifs(param)
  1195. X    pcmd_ifz(param)
  1196. X    get_logicop(param,op_returned)
  1197. X    get_relop(param,op_returned)
  1198. X    get_truth_int(param,truth)
  1199. X    get_truth_str(param,truth)
  1200. X    test_truth_int(int1,relop,int2)
  1201. X
  1202. X--------------------------------------------------------------------------*/
  1203. X/*+:EDITS:*/
  1204. X/*:08-26-1990-22:23-wht@n4hgf-fix zero-relative if commands */
  1205. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1206. X
  1207. X#include <ctype.h>
  1208. X#include "ecu.h"
  1209. X#include "ecuerror.h"
  1210. X#include "esd.h"
  1211. X#include "var.h"
  1212. X#include "proc.h"
  1213. X#include "relop.h"
  1214. X
  1215. Xextern PCB *pcb_stack[];
  1216. Xextern int proc_level;
  1217. Xextern int proctrace;
  1218. X
  1219. X#define MAX_IF 40    /* damn enough */
  1220. Xuchar if_level = 0;
  1221. Xuchar truth_already[MAX_IF];
  1222. X
  1223. X/*+-------------------------------------------------------------------------
  1224. X    get_relop(param,&op_returned)
  1225. X--------------------------------------------------------------------------*/
  1226. Xint
  1227. Xget_relop(param,op_returned)
  1228. XESD *param;
  1229. Xint *op_returned;
  1230. X{
  1231. Xregister erc;
  1232. X
  1233. X    if(erc = skip_cmd_break(param))
  1234. X        return(eInvalidRelOp);
  1235. X
  1236. X    switch(param->pb[param->index++]) /* index decremented in default */
  1237. X    {
  1238. X    case '=':
  1239. X        if((param->cb != param->index) && (param->pb[param->index] == '='))
  1240. X            param->index++;
  1241. X        *op_returned = OP_EQ;
  1242. X        return(0);
  1243. X
  1244. X    case '!':
  1245. X        if(param->cb == param->index)
  1246. X            return(eInvalidRelOp);
  1247. X        switch(param->pb[param->index])
  1248. X        {
  1249. X        case '=':
  1250. X            param->index++;
  1251. X            *op_returned = OP_NE;
  1252. X            return(0);
  1253. X        default:
  1254. X            return(eInvalidRelOp);
  1255. X        }
  1256. X
  1257. X    case '<':
  1258. X        if(param->cb == param->index)
  1259. X        {
  1260. X            *op_returned = OP_LT;
  1261. X            return(0);
  1262. X        }
  1263. X        switch(param->pb[param->index])
  1264. X        {
  1265. X        case '>':
  1266. X            param->index++;
  1267. X            *op_returned = OP_NE;
  1268. X            return(0);
  1269. X        case '=':
  1270. X            param->index++;
  1271. X            *op_returned = OP_LE;
  1272. X            return(0);
  1273. X        default:
  1274. X            *op_returned = OP_LT;
  1275. X            return(0);
  1276. X        }
  1277. X
  1278. X    case '>':
  1279. X        if(param->cb == param->index)
  1280. X        {
  1281. X            *op_returned = OP_LT;
  1282. X            return(0);
  1283. X        }
  1284. X        switch(param->pb[param->index])
  1285. X        {
  1286. X        case '=':
  1287. X            param->index++;
  1288. X            *op_returned = OP_GE;
  1289. X            return(0);
  1290. X        default:
  1291. X            *op_returned = OP_GT;
  1292. X            return(0);
  1293. X        }
  1294. X    default:
  1295. X        param->index--;
  1296. X    }
  1297. X    return(eInvalidRelOp);
  1298. X}   /* end of get_relop */
  1299. X
  1300. X/*+-------------------------------------------------------------------------
  1301. X    get_logicop(param,op_returned)
  1302. X--------------------------------------------------------------------------*/
  1303. Xint
  1304. Xget_logicop(param,op_returned)
  1305. XESD *param;
  1306. Xint *op_returned;
  1307. X{
  1308. Xregister erc;
  1309. Xregister char *cptr;
  1310. X
  1311. X    if(erc = skip_cmd_break(param))
  1312. X        return(eInvalidLogicOp);
  1313. X
  1314. X    if((param->cb - param->index) < 2)
  1315. X        return(eInvalidLogicOp);
  1316. X
  1317. X    cptr = param->pb + param->index;
  1318. X    erc = eInvalidLogicOp;
  1319. X    if(!strncmp(cptr,"&&",2))
  1320. X    {
  1321. X        *op_returned = OP_AND;
  1322. X        erc = 0;
  1323. X    }
  1324. X    else if(!strncmp(cptr,"||",2))
  1325. X    {
  1326. X        *op_returned = OP_OR;
  1327. X        erc = 0;
  1328. X    }
  1329. X    if(!erc)
  1330. X        param->index += 2;
  1331. X    return(erc);
  1332. X
  1333. X}    /* end of get_logicop */
  1334. X
  1335. X/*+-------------------------------------------------------------------------
  1336. X    test_truth_int(int1,relop,int2)
  1337. X--------------------------------------------------------------------------*/
  1338. Xint
  1339. Xtest_truth_int(int1,relop,int2)
  1340. Xlong int1;
  1341. Xint relop;
  1342. Xlong int2;
  1343. X{
  1344. Xregister truth;
  1345. X
  1346. X    switch(relop)
  1347. X    {
  1348. X    case OP_EQ:
  1349. X        truth = (int1 == int2);
  1350. X        break;
  1351. X    case OP_NE:
  1352. X        truth = (int1 != int2);
  1353. X        break;
  1354. X    case OP_GT:
  1355. X        truth = (int1 > int2);
  1356. X        break;
  1357. X    case OP_LT:
  1358. X        truth = (int1 < int2);
  1359. X        break;
  1360. X    case OP_GE:
  1361. X        truth = (int1 >= int2);
  1362. X        break;
  1363. X    case OP_LE:
  1364. X        truth = (int1 <= int2);
  1365. X        break;
  1366. X    }
  1367. X    return(truth);
  1368. X
  1369. X}    /* end of test_truth_int */
  1370. X
  1371. X/*+-------------------------------------------------------------------------
  1372. X    get_truth_int(param,truth)
  1373. X--------------------------------------------------------------------------*/
  1374. Xint
  1375. Xget_truth_int(param,truth)
  1376. XESD *param;
  1377. Xint *truth;
  1378. X{
  1379. Xregister erc;
  1380. Xlong int1;
  1381. Xlong int2;
  1382. Xint operator;
  1383. Xint truth2;
  1384. X
  1385. X    if(erc = gint(param,&int1))
  1386. X        return(erc);
  1387. X    if(erc = get_relop(param,&operator))
  1388. X        return(erc);
  1389. X    if(erc = gint(param,&int2))
  1390. X        return(erc);
  1391. X    *truth = test_truth_int(int1,operator,int2);
  1392. X
  1393. X    while(!get_logicop(param,&operator))
  1394. X    {
  1395. X        if(erc = get_truth_int(param,&truth2))
  1396. X            return(erc);
  1397. X        switch(operator)
  1398. X        {
  1399. X            case OP_AND:
  1400. X                *truth &= truth2;
  1401. X                break;
  1402. X
  1403. X            case OP_OR:
  1404. X                *truth |= truth2;
  1405. X                break;
  1406. X        }
  1407. X    }
  1408. X    return(erc);
  1409. X
  1410. X
  1411. X}    /* end of get_truth_int */
  1412. X
  1413. X/*+-------------------------------------------------------------------------
  1414. X    get_truth_str(param,truth)
  1415. X--------------------------------------------------------------------------*/
  1416. Xint
  1417. Xget_truth_str(param,truth)
  1418. XESD *param;
  1419. Xint *truth;
  1420. X{
  1421. Xregister erc;
  1422. XESD *tesd1 = (ESD *)0;
  1423. XESD *tesd2 = (ESD *)0;
  1424. Xint operator;
  1425. Xint strcmp_result;
  1426. Xint truth2;
  1427. X
  1428. X    if(!(tesd1 = make_esd(256)) || !(tesd2 = make_esd(256)))
  1429. X    {
  1430. X        erc = eNoMemory;
  1431. X        goto RETURN;
  1432. X    }    
  1433. X
  1434. X    if(erc = gstr(param,tesd1,1))
  1435. X        goto RETURN;
  1436. X    if(erc = get_relop(param,&operator))
  1437. X        goto RETURN;
  1438. X    if(erc = gstr(param,tesd2,1))
  1439. X        goto RETURN;
  1440. X
  1441. X    strcmp_result = strcmp(tesd1->pb,tesd2->pb);
  1442. X
  1443. X    switch(operator)
  1444. X    {
  1445. X        case OP_EQ:
  1446. X            *truth = (strcmp_result == 0);
  1447. X            break;
  1448. X        case OP_NE:
  1449. X            *truth = (strcmp_result != 0);
  1450. X            break;
  1451. X        case OP_GT:
  1452. X            *truth = (strcmp_result > 0);
  1453. X            break;
  1454. X        case OP_LT:
  1455. X            *truth = (strcmp_result < 0);
  1456. X            break;
  1457. X        case OP_GE:
  1458. X            *truth = (strcmp_result >= 0);
  1459. X            break;
  1460. X        case OP_LE:
  1461. X            *truth = (strcmp_result <= 0);
  1462. X            break;
  1463. X        default:
  1464. X            return(eInvalidStrOp);
  1465. X    }
  1466. X
  1467. X    while(!get_logicop(param,&operator))
  1468. X    {
  1469. X        if(erc = get_truth_str(param,&truth2))
  1470. X            return(erc);
  1471. X        switch(operator)
  1472. X        {
  1473. X            case OP_AND:
  1474. X                *truth &= truth2;
  1475. X                break;
  1476. X
  1477. X            case OP_OR:
  1478. X                *truth |= truth2;
  1479. X                break;
  1480. X        }
  1481. X    }
  1482. X
  1483. X    erc = 0;
  1484. X
  1485. XRETURN:
  1486. X    if(tesd1)
  1487. X        free_esd(tesd1);
  1488. X    if(tesd2)
  1489. X        free_esd(tesd2);
  1490. X    return(erc);
  1491. X
  1492. X}   /* end of get_truth_str */
  1493. X
  1494. X/*+-------------------------------------------------------------------------
  1495. X    _if_common(param,truth)
  1496. X--------------------------------------------------------------------------*/
  1497. Xint
  1498. X_if_common(param,truth)
  1499. XESD *param;
  1500. Xint truth;
  1501. X{
  1502. Xregister erc = 0;
  1503. Xchar s80[80];
  1504. XPCB *pcb;
  1505. XESD *else_line;
  1506. Xint label_on_else_line;
  1507. Xint truth2;
  1508. Xint save_index;
  1509. Xlong int1;
  1510. X
  1511. X    if(proctrace > 1)
  1512. X    {
  1513. X        pprintf("if condition %s",(truth) ? "TRUE: " : "FALSE\n");
  1514. X        if(truth)
  1515. X        {
  1516. X            skip_cmd_break(param);
  1517. X            pputs(param->pb + param->index);
  1518. X            pputc('\n');
  1519. X        }
  1520. X    }
  1521. X
  1522. X    truth_already[if_level] = truth;
  1523. X
  1524. X/* if end of command, execute frame else conditionally execute rest of esd */
  1525. X    s80[0] = 0;
  1526. X    if(end_of_cmd(param))
  1527. X        erc = execute_frame(truth);
  1528. X    else if(truth)
  1529. X        erc = execute_esd(param);
  1530. X    else
  1531. X        param->index = param->cb;
  1532. X
  1533. X    if(erc)
  1534. X        return(erc);
  1535. X
  1536. X/* check for else statement */
  1537. X    pcb = pcb_stack[proc_level - 1];
  1538. X    if(!pcb->current->next)        /* if no next line, no "else" */
  1539. X        return(0);
  1540. X
  1541. X    else_line = pcb->current->next->text;
  1542. X    else_line->index = else_line->old_index = 0;
  1543. X    if(label_on_else_line = (*else_line->pb != 0x20))
  1544. X    {    /* strip label */
  1545. X        if(get_alphanum_zstr(else_line,s80,sizeof(s80)))
  1546. X            return(eInvalidLabel);
  1547. X    }
  1548. X    if(get_alphanum_zstr(else_line,s80,sizeof(s80)))
  1549. X        return(0);        /* not "else" */
  1550. X    if(strcmp(s80,"else"))
  1551. X        return(0);        /* not "else" */
  1552. X    if(label_on_else_line)
  1553. X    {
  1554. X        else_line->old_index = 0;
  1555. X        pputs("label not allowed on else statement\n");
  1556. X        return(eFATAL_ALREADY);
  1557. X    }
  1558. X
  1559. X/* we have an "else" condition */
  1560. X    truth = !truth;
  1561. X    pcb->current = pcb->current->next;
  1562. X
  1563. X    trace_proc_cmd(pcb);
  1564. X
  1565. X    if(end_of_cmd(else_line))
  1566. X        erc = execute_frame(truth);
  1567. X    else
  1568. X    {
  1569. X        save_index = else_line->old_index = else_line->index;
  1570. X        s80[0] = 0;
  1571. X        if((*(else_line->pb + else_line->index) != '$') &&
  1572. X            get_alpha_zstr(else_line,s80,sizeof(s80)))
  1573. X        {
  1574. X            pputs("illegal command after 'else'\n");
  1575. X            return(eFATAL_ALREADY);
  1576. X        }
  1577. X        if(!strcmp(s80,"ifi"))
  1578. X        {
  1579. X            if(erc = get_truth_int(else_line,&truth2))
  1580. X                return(erc);
  1581. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1582. X            truth_already[if_level] |= truth2;
  1583. X        }
  1584. X        else if(!strcmp(s80,"ifs"))
  1585. X        {
  1586. X            if(erc = get_truth_str(else_line,&truth2))
  1587. X                return(erc);
  1588. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1589. X            truth_already[if_level] |= truth2;
  1590. X        }
  1591. X        else if(!strcmp(s80,"ifz"))
  1592. X        {
  1593. X            if(erc = gint(else_line,&int1))
  1594. X                return(erc);
  1595. X            truth2 = test_truth_int(int1,OP_EQ,0L);
  1596. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1597. X            truth_already[if_level] |= truth2;
  1598. X        }
  1599. X        else if(!strcmp(s80,"ifnz"))
  1600. X        {
  1601. X            if(erc = gint(else_line,&int1))
  1602. X                return(erc);
  1603. X            truth2 = test_truth_int(int1,OP_NE,0L);
  1604. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1605. X            truth_already[if_level] |= truth2;
  1606. X        }
  1607. X        else if(!strcmp(s80,"iflt"))
  1608. X        {
  1609. X            if(erc = gint(else_line,&int1))
  1610. X                return(erc);
  1611. X            truth2 = test_truth_int(int1,OP_LT,0L);
  1612. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1613. X            truth_already[if_level] |= truth2;
  1614. X        }
  1615. X        else if(!strcmp(s80,"ifle"))
  1616. X        {
  1617. X            if(erc = gint(else_line,&int1))
  1618. X                return(erc);
  1619. X            truth2 = test_truth_int(int1,OP_LE,0L);
  1620. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1621. X            truth_already[if_level] |= truth2;
  1622. X        }
  1623. X        else if(!strcmp(s80,"ifgt"))
  1624. X        {
  1625. X            if(erc = gint(else_line,&int1))
  1626. X                return(erc);
  1627. X            truth2 = test_truth_int(int1,OP_GT,0L);
  1628. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1629. X            truth_already[if_level] |= truth2;
  1630. X        }
  1631. X        else if(!strcmp(s80,"ifge"))
  1632. X        {
  1633. X            if(erc = gint(else_line,&int1))
  1634. X                return(erc);
  1635. X            truth2 = test_truth_int(int1,OP_GE,0L);
  1636. X            erc = _if_common(else_line,!truth_already[if_level] & truth2);
  1637. X            truth_already[if_level] |= truth2;
  1638. X        }
  1639. X        else if(!strncmp(s80,"while",5))
  1640. X        {
  1641. X            pputs("'while' command not allowed as 'else' conditional\n");
  1642. X            return(eFATAL_ALREADY);
  1643. X        }
  1644. X        else
  1645. X        {
  1646. X            else_line->index = save_index;
  1647. X            if(truth)
  1648. X                erc = execute_esd(else_line);
  1649. X        }
  1650. X    }
  1651. X
  1652. X    return(erc);
  1653. X}    /* end of _if_common */
  1654. X
  1655. X/*+-------------------------------------------------------------------------
  1656. X    pcmd_ifi(param)
  1657. X--------------------------------------------------------------------------*/
  1658. Xint
  1659. Xpcmd_ifi(param)
  1660. XESD *param;
  1661. X{
  1662. Xregister erc;
  1663. Xint truth;
  1664. X
  1665. X    if(!proc_level)
  1666. X        return(eNotExecutingProc);
  1667. X
  1668. X    if(if_level == MAX_IF)
  1669. X    {
  1670. X        pputs("if statements nested too deeply\n");
  1671. X        return(eFATAL_ALREADY);
  1672. X    }
  1673. X    if_level++;
  1674. X    truth_already[if_level] = 0;
  1675. X
  1676. X    if(!(erc = get_truth_int(param,&truth)))
  1677. X        erc = _if_common(param,truth);
  1678. X    if_level--;
  1679. X    return(erc);
  1680. X
  1681. X}   /* end of pcmd_ifi */
  1682. X
  1683. X/*+-------------------------------------------------------------------------
  1684. X    _cmd_ifrel_common(param,relop)
  1685. X--------------------------------------------------------------------------*/
  1686. Xint
  1687. X_cmd_ifrel_common(param,relop)
  1688. XESD *param;
  1689. Xint relop;
  1690. X{
  1691. Xregister erc;
  1692. Xint truth;
  1693. Xlong int1;
  1694. X
  1695. X    if(!proc_level)
  1696. X        return(eNotExecutingProc);
  1697. X
  1698. X    if(if_level == MAX_IF)
  1699. X    {
  1700. X        pputs("if statements nested too deeply\n");
  1701. X        return(eFATAL_ALREADY);
  1702. X    }
  1703. X    if_level++;
  1704. X    truth_already[if_level] = 0;
  1705. X
  1706. X    if(erc = gint(param,&int1))
  1707. X        return(erc);
  1708. X    truth = test_truth_int(int1,relop,0L);
  1709. X    erc = _if_common(param,truth);
  1710. X    if_level--;
  1711. X    return(erc);
  1712. X
  1713. X}    /* end of _cmd_ifrel_common */
  1714. X
  1715. X/*+-------------------------------------------------------------------------
  1716. X    pcmd_ifz(param)
  1717. X--------------------------------------------------------------------------*/
  1718. Xint
  1719. Xpcmd_ifz(param)
  1720. XESD *param;
  1721. X{
  1722. X    return(_cmd_ifrel_common(param,OP_EQ));
  1723. X}    /* end of pcmd_ifz */
  1724. X
  1725. X/*+-------------------------------------------------------------------------
  1726. X    pcmd_ifnz(param)
  1727. X--------------------------------------------------------------------------*/
  1728. Xint
  1729. Xpcmd_ifnz(param)
  1730. XESD *param;
  1731. X{
  1732. X    return(_cmd_ifrel_common(param,OP_NE));
  1733. X}    /* end of pcmd_ifnz */
  1734. X
  1735. X/*+-------------------------------------------------------------------------
  1736. X    pcmd_ifle(param)
  1737. X--------------------------------------------------------------------------*/
  1738. Xint
  1739. Xpcmd_ifle(param)
  1740. XESD *param;
  1741. X{
  1742. X    return(_cmd_ifrel_common(param,OP_LE));
  1743. X}    /* end of pcmd_ifle */
  1744. X
  1745. X/*+-------------------------------------------------------------------------
  1746. X    pcmd_ifge(param)
  1747. X--------------------------------------------------------------------------*/
  1748. Xint
  1749. Xpcmd_ifge(param)
  1750. XESD *param;
  1751. X{
  1752. X    return(_cmd_ifrel_common(param,OP_GE));
  1753. X}    /* end of pcmd_ifge */
  1754. X
  1755. X/*+-------------------------------------------------------------------------
  1756. X    pcmd_iflt(param)
  1757. X--------------------------------------------------------------------------*/
  1758. Xint
  1759. Xpcmd_iflt(param)
  1760. XESD *param;
  1761. X{
  1762. X    return(_cmd_ifrel_common(param,OP_LT));
  1763. X}    /* end of pcmd_iflt */
  1764. X
  1765. X/*+-------------------------------------------------------------------------
  1766. X    pcmd_ifgt(param)
  1767. X--------------------------------------------------------------------------*/
  1768. Xint
  1769. Xpcmd_ifgt(param)
  1770. XESD *param;
  1771. X{
  1772. X    return(_cmd_ifrel_common(param,OP_GT));
  1773. X}    /* end of pcmd_ifgt */
  1774. X
  1775. X/*+-------------------------------------------------------------------------
  1776. X    pcmd_ifs(param)
  1777. X--------------------------------------------------------------------------*/
  1778. Xint
  1779. Xpcmd_ifs(param)
  1780. XESD *param;
  1781. X{
  1782. Xregister erc;
  1783. Xint truth;
  1784. X
  1785. X    if(!proc_level)
  1786. X        return(eNotExecutingProc);
  1787. X
  1788. X    if(if_level == MAX_IF)
  1789. X    {
  1790. X        pputs("if statements nested too deeply\n");
  1791. X        return(eFATAL_ALREADY);
  1792. X    }
  1793. X    if_level++;
  1794. X    truth_already[if_level] = 0;
  1795. X
  1796. X    if(!(erc = get_truth_str(param,&truth)))
  1797. X        erc = _if_common(param,truth);
  1798. X    if_level--;
  1799. X    return(erc);
  1800. X
  1801. X}   /* end of pcmd_ifs */
  1802. X
  1803. X/*+-------------------------------------------------------------------------
  1804. X    pcmd_else(param)
  1805. X--------------------------------------------------------------------------*/
  1806. Xint
  1807. Xpcmd_else(param)
  1808. XESD *param;
  1809. X{
  1810. X    return(eElseCommand);
  1811. X}    /* end of pcmd_else */
  1812. X
  1813. X/* vi: set tabstop=4 shiftwidth=4: */
  1814. X/* end of pcmdif.c */
  1815. SHAR_EOF
  1816. $TOUCH -am 1224224190 'pcmdif.c' &&
  1817. chmod 0644 pcmdif.c ||
  1818. echo 'restore of pcmdif.c failed'
  1819. Wc_c="`wc -c < 'pcmdif.c'`"
  1820. test 13817 -eq "$Wc_c" ||
  1821.     echo 'pcmdif.c: original size 13817, current size' "$Wc_c"
  1822. # ============= pcmdtty.c ==============
  1823. echo 'x - extracting pcmdtty.c (Text)'
  1824. sed 's/^X//' << 'SHAR_EOF' > 'pcmdtty.c' &&
  1825. X/*+-------------------------------------------------------------------------
  1826. X    pcmdtty.c - tty (console) related procedure commands
  1827. X    wht@n4hgf.Mt-Park.GA.US
  1828. X
  1829. X  Defined functions:
  1830. X    pcmd_cls(param)
  1831. X    pcmd_color(param)
  1832. X    pcmd_cursor(param)
  1833. X    pcmd_delline(param)
  1834. X    pcmd_eeol(param)
  1835. X    pcmd_fkey(param)
  1836. X    pcmd_home(param)
  1837. X    pcmd_icolor(param)
  1838. X    pcmd_insline(param)
  1839. X    pcmd_scrdump(param)
  1840. X    pcmd_vidcolor(param)
  1841. X    pcmd_vidnorm(param)
  1842. X    pcmd_vidrev(param)
  1843. X    ifunc_colors(pvalue)
  1844. X
  1845. X--------------------------------------------------------------------------*/
  1846. X/*+:EDITS:*/
  1847. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1848. X
  1849. X#include "ecu.h"
  1850. X#include "ecuerror.h"
  1851. X#include "esd.h"
  1852. X#include "ecutty.h"
  1853. X
  1854. Xextern int proctrace;
  1855. Xextern ulong colors_current;
  1856. X
  1857. X/*+-------------------------------------------------------------------------
  1858. X    pcmd_color(param)
  1859. X
  1860. XUsage:   color [-r] [argument] [argument]
  1861. XOptions:
  1862. X   color color      Set foreground and background normal video colors
  1863. X   -r color color   Set foreground & background reverse video colors
  1864. X
  1865. XColor names
  1866. X   blue      magenta      brown      black
  1867. X   lt_blue   lt_magenta   yellow     gray
  1868. X   cyan      white        green      red
  1869. X   lt_cyan   hi_white     lt_green   lt_red
  1870. X
  1871. X--------------------------------------------------------------------------*/
  1872. Xpcmd_color(param)
  1873. XESD *param;
  1874. X{
  1875. Xregister erc;
  1876. Xchar switches[8];
  1877. Xint normal;
  1878. Xchar s32[32];
  1879. Xulong foreground;
  1880. Xulong background;
  1881. X
  1882. X    get_switches(param,switches,sizeof(switches));
  1883. X    if(!strlen(switches))
  1884. X        normal = 1;
  1885. X    else if(switches[1] == 'r')
  1886. X        normal = 0;        /* reverse */
  1887. X    else
  1888. X    {
  1889. X        pputs("unrecognized switch\n");
  1890. X        return(eFATAL_ALREADY);
  1891. X    }
  1892. X
  1893. X    if((erc = get_alpha_zstr(param,s32,sizeof(s32))) ||
  1894. X            ((foreground = color_name_to_num(s32))) < 0)
  1895. X        goto ERROR;
  1896. X
  1897. X    if(erc = get_alpha_zstr(param,s32,sizeof(s32)))
  1898. X    {
  1899. X        if(!end_of_cmd(param))
  1900. X            goto ERROR;
  1901. X        background = 0;
  1902. X    }
  1903. X    else if((background = color_name_to_num(s32)) < 0)
  1904. X        goto ERROR;
  1905. X
  1906. X    if(normal)
  1907. X    {
  1908. X        colors_current &= 0xFFFF0000;
  1909. X        colors_current |= (foreground << 8) | background;
  1910. X        if(proctrace > 1)
  1911. X        {
  1912. X            pprintf("normal %ld,%ld current=0x%08lx\n",
  1913. X                foreground,background,colors_current);
  1914. X        }
  1915. X    }
  1916. X    else
  1917. X    {
  1918. X        colors_current &= 0x0000FFFF;
  1919. X        colors_current |= (foreground << 24) | (background << 16);
  1920. X        if(proctrace > 1)
  1921. X        {
  1922. X            pprintf("reverse %ld,%ld current=0x%08lx\n",
  1923. X                foreground,background,colors_current);
  1924. X        }
  1925. X    }
  1926. X
  1927. X    setcolor(colors_current);
  1928. X    return(0);
  1929. X
  1930. XERROR:
  1931. X    if(erc)
  1932. X        return(erc);
  1933. X    pputs("invalid color\n");
  1934. X    return(eFATAL_ALREADY);
  1935. X
  1936. X}    /* end of pcmd_color */
  1937. X
  1938. X/*+-------------------------------------------------------------------------
  1939. X    ifunc_colors(pvalue)
  1940. X--------------------------------------------------------------------------*/
  1941. Xint
  1942. Xifunc_colors(pvalue)
  1943. Xulong *pvalue;
  1944. X{
  1945. X    *pvalue = colors_current;
  1946. X    return(0);
  1947. X}    /* end of ifunc_colors */
  1948. X
  1949. X/*+-------------------------------------------------------------------------
  1950. X    pcmd_icolor(param)
  1951. X--------------------------------------------------------------------------*/
  1952. Xpcmd_icolor(param)
  1953. XESD *param;
  1954. X{
  1955. Xint erc;
  1956. Xulong new_colors;
  1957. X
  1958. X    if(erc = gint(param,&new_colors))
  1959. X        return(erc);
  1960. X
  1961. X    setcolor(new_colors);
  1962. X    return(0);
  1963. X}    /* end of pcmd_icolor */
  1964. X
  1965. X/*+-------------------------------------------------------------------------
  1966. X    pcmd_cls(param)
  1967. X--------------------------------------------------------------------------*/
  1968. Xint
  1969. Xpcmd_cls(param)
  1970. XESD *param;
  1971. X{
  1972. X    tcap_clear_screen();
  1973. X    return(0);
  1974. X}    /* end of pcmd_cls */
  1975. X
  1976. X/*+-------------------------------------------------------------------------
  1977. X    pcmd_cursor(param)
  1978. X--------------------------------------------------------------------------*/
  1979. Xint
  1980. Xpcmd_cursor(param)
  1981. XESD *param;
  1982. X{
  1983. Xint erc;
  1984. Xlong row;
  1985. Xlong col = 0;
  1986. X
  1987. X    if(erc = gint(param,&row))
  1988. X        return(erc);
  1989. X    if(gint(param,&col))
  1990. X    {
  1991. X        /* if something there non-integer */
  1992. X        if(!end_of_cmd(param))
  1993. X            return(eSyntaxError);
  1994. X    }
  1995. X    tcap_cursor((int)row,(int)col);
  1996. X    return(0);
  1997. X}    /* end of pcmd_cursor */
  1998. X
  1999. X/*+-------------------------------------------------------------------------
  2000. X    pcmd_scrdump(param)
  2001. X--------------------------------------------------------------------------*/
  2002. Xint
  2003. Xpcmd_scrdump(param)
  2004. XESD *param;
  2005. X{
  2006. Xint erc;
  2007. XESD *fname;
  2008. XFILE *fp;
  2009. X
  2010. X    if((fname = make_esd(256)) == (ESD *)0)
  2011. X        return(eNoMemory);
  2012. X
  2013. X    if(erc = gstr(param,fname,1))
  2014. X    {
  2015. X        if(!end_of_cmd(param))
  2016. X        {
  2017. X            erc = eSyntaxError;
  2018. X            goto RETURN;
  2019. X        }
  2020. X    }
  2021. X
  2022. X    if(fname->cb)
  2023. X    {
  2024. X        if((fp = fopen(fname->pb,"a")) == NULL)
  2025. X        {
  2026. X            pperror(fname->pb);
  2027. X            erc = eFATAL_ALREADY;
  2028. X            goto RETURN;
  2029. X        }
  2030. X        fclose(fp);
  2031. X    }
  2032. X
  2033. X    screen_dump((fname->cb) ? fname->pb : (char *)0);
  2034. X
  2035. XRETURN:
  2036. X    free_esd(fname);
  2037. X    return(erc);
  2038. X}    /* end of pcmd_scrdump */
  2039. X
  2040. X/*+-------------------------------------------------------------------------
  2041. X    pcmd_vidnorm(param)
  2042. X--------------------------------------------------------------------------*/
  2043. Xint
  2044. Xpcmd_vidnorm(param)
  2045. XESD *param;
  2046. X{
  2047. X    tcap_stand_end();
  2048. X    return(0);
  2049. X}    /* end of pcmd_vidnorm */
  2050. X
  2051. X/*+-------------------------------------------------------------------------
  2052. X    pcmd_vidrev(param)
  2053. X--------------------------------------------------------------------------*/
  2054. Xint
  2055. Xpcmd_vidrev(param)
  2056. XESD *param;
  2057. X{
  2058. X    tcap_stand_out();
  2059. X    return(0);
  2060. X}    /* end of pcmd_vidrev */
  2061. X
  2062. X/*+-------------------------------------------------------------------------
  2063. X    pcmd_fkey(param)
  2064. X--------------------------------------------------------------------------*/
  2065. Xpcmd_fkey(param)
  2066. XESD *param;
  2067. X{
  2068. Xint erc;
  2069. XESD *tesd;
  2070. X
  2071. X    if((tesd = make_esd(64)) == (ESD *)0)
  2072. X        return(eNoMemory);
  2073. X
  2074. X    if(erc = gstr(param,tesd,0))
  2075. X        goto RETURN;
  2076. X
  2077. X    switch(keyset_read(tesd->pb))
  2078. X    {
  2079. X        case  0:
  2080. X            if(proctrace)
  2081. X                keyset_display();
  2082. X            break;
  2083. X        case -1:
  2084. X            pprintf("cannot find ~/.ecu/keys\n");
  2085. X            erc = eFATAL_ALREADY;
  2086. X            break;
  2087. X        case -2:
  2088. X            pprintf("'%s' not found in ~/.ecu/keys\n",tesd->pb);
  2089. X            erc = eFATAL_ALREADY;
  2090. X            break;
  2091. X    }
  2092. X
  2093. XRETURN:
  2094. X    free_esd(tesd);
  2095. X    return(erc);
  2096. X}    /* end of pcmd_fkey */
  2097. X
  2098. X/*+-------------------------------------------------------------------------
  2099. X    pcmd_vidcolor(param)
  2100. X
  2101. Xvidcolor normal|reverse|notify|success|alert|error fcolor [bcolor]
  2102. X--------------------------------------------------------------------------*/
  2103. Xint
  2104. Xpcmd_vidcolor(param)
  2105. XESD *param;
  2106. X{
  2107. Xint erc;
  2108. Xint ntokens = 0;
  2109. Xchar *tokens[3];
  2110. Xint param_index[3];
  2111. Xchar tokenbuf[64];
  2112. X
  2113. X    tokens[0] = tokenbuf;
  2114. X    tokens[1] = tokenbuf + 20;
  2115. X    tokens[2] = tokenbuf + 40;
  2116. X
  2117. X    while(ntokens < 3)
  2118. X    {
  2119. X        skip_cmd_break(param);
  2120. X        param_index[ntokens] = param->index;
  2121. X        if(erc = get_word_zstr(param,tokens[ntokens],20))
  2122. X            break;
  2123. X        ntokens++;
  2124. X    }
  2125. X
  2126. X    if(erc && ((erc != eNoParameter) || (ntokens < 2)))
  2127. X        return(erc);
  2128. X
  2129. X    switch(erc = setcolor_internal(ntokens,tokens))
  2130. X    {
  2131. X        case 0:
  2132. X            break;
  2133. X        default:
  2134. X            param->old_index = param->index = param_index[erc - 1];
  2135. X            erc = eBadParameter;
  2136. X    }
  2137. X    return(erc);
  2138. X}    /* end of pcmd_vidcolor */
  2139. X
  2140. X/*+-------------------------------------------------------------------------
  2141. X    pcmd_home(param) - home the cursor
  2142. X--------------------------------------------------------------------------*/
  2143. Xint
  2144. Xpcmd_home(param)
  2145. XESD *param;
  2146. X{
  2147. X    tcap_cursor(0,0);
  2148. X    return(0);
  2149. X}    /* end of pcmd_home */
  2150. X
  2151. X/*+-------------------------------------------------------------------------
  2152. X    pcmd_eeol(param) - erase to end of line
  2153. X--------------------------------------------------------------------------*/
  2154. Xint
  2155. Xpcmd_eeol(param)
  2156. XESD *param;
  2157. X{
  2158. X    tcap_eeol();
  2159. X    return(0);
  2160. X}    /* end of pcmd_eeol */
  2161. X
  2162. X/*+-------------------------------------------------------------------------
  2163. X    pcmd_insline(param) - insert line in display
  2164. X--------------------------------------------------------------------------*/
  2165. Xint
  2166. Xpcmd_insline(param)
  2167. XESD *param;
  2168. X{
  2169. X    tcap_insert_lines(1);
  2170. X    return(0);
  2171. X}    /* end of pcmd_insline */
  2172. X
  2173. X/*+-------------------------------------------------------------------------
  2174. X    pcmd_delline(param) - delete line from display
  2175. X--------------------------------------------------------------------------*/
  2176. Xint
  2177. Xpcmd_delline(param)
  2178. XESD *param;
  2179. X{
  2180. X    tcap_delete_lines(1);
  2181. X    return(0);
  2182. X}    /* end of pcmd_delline */
  2183. X
  2184. X/* vi: set tabstop=4 shiftwidth=4: */
  2185. X/* end of pcmdtty.c */
  2186. SHAR_EOF
  2187. $TOUCH -am 1224224290 'pcmdtty.c' &&
  2188. chmod 0644 pcmdtty.c ||
  2189. echo 'restore of pcmdtty.c failed'
  2190. Wc_c="`wc -c < 'pcmdtty.c'`"
  2191. test 7941 -eq "$Wc_c" ||
  2192.     echo 'pcmdtty.c: original size 7941, current size' "$Wc_c"
  2193. # ============= pcmdwhile.c ==============
  2194. echo 'x - extracting pcmdwhile.c (Text)'
  2195. sed 's/^X//' << 'SHAR_EOF' > 'pcmdwhile.c' &&
  2196. X/*+-------------------------------------------------------------------------
  2197. X    pcmdwhile.c - ecu while procedure commands
  2198. X    wht@n4hgf.Mt-Park.GA.US
  2199. X
  2200. X    WHILEI $i0 rel-op $i1 cmd
  2201. X    WHILES $s0 rel-op $s1 cmd
  2202. X
  2203. X    where rel-op is "=", "==", "!=", "<>", ">", "<", ">=", "=<"
  2204. X
  2205. X  Defined functions:
  2206. X    pcmd_whilei(param)
  2207. X    pcmd_whiles(param)
  2208. X
  2209. X--------------------------------------------------------------------------*/
  2210. X/*+:EDITS:*/
  2211. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2212. X
  2213. X#include <ctype.h>
  2214. X#include "ecu.h"
  2215. X#include "ecuerror.h"
  2216. X#include "esd.h"
  2217. X#include "var.h"
  2218. X#include "proc.h"
  2219. X#include "relop.h"
  2220. X
  2221. Xextern PCB *pcb_stack[];
  2222. Xextern int proc_level;
  2223. X
  2224. X/*+-------------------------------------------------------------------------
  2225. X    pcmd_whilei(param)
  2226. X--------------------------------------------------------------------------*/
  2227. Xint
  2228. Xpcmd_whilei(param)
  2229. XESD *param;
  2230. X{
  2231. Xregister erc;
  2232. Xint truth;
  2233. XPCB *pcb;
  2234. XLCB *condition_lcb;
  2235. Xint condition_index = param->index;
  2236. X
  2237. X    if(!proc_level)
  2238. X        return(eNotExecutingProc);
  2239. X
  2240. X    pcb = pcb_stack[proc_level - 1];
  2241. X    condition_lcb = pcb->current;
  2242. X
  2243. XREPEAT_WHILE:
  2244. X
  2245. X    if(erc = get_truth_int(param,&truth))
  2246. X        return(erc);
  2247. X
  2248. X/* if end of command, execute frame */
  2249. X    if(end_of_cmd(param))
  2250. X    {
  2251. X        if(erc = execute_frame(truth))
  2252. X        {
  2253. X            if(erc == eContinueCommand)
  2254. X                goto CONTINUE;
  2255. X            if(erc == eBreakCommand)
  2256. X                erc = 0;
  2257. X            return(erc);
  2258. X        }
  2259. X    }
  2260. X    else if(truth)
  2261. X    {
  2262. X        if(erc = execute_esd(param))
  2263. X            return(erc);
  2264. X    }
  2265. X
  2266. X/* repeat if indicated */
  2267. XCONTINUE:
  2268. X    if(truth)
  2269. X    {
  2270. X        pcb->current = condition_lcb;
  2271. X        param->index = param->old_index = condition_index;
  2272. X        goto REPEAT_WHILE;
  2273. X    }
  2274. X
  2275. X    return(0);
  2276. X}   /* end of pcmd_whilei */
  2277. X
  2278. X/*+-------------------------------------------------------------------------
  2279. X    pcmd_whiles(param)
  2280. X--------------------------------------------------------------------------*/
  2281. Xint
  2282. Xpcmd_whiles(param)
  2283. XESD *param;
  2284. X{
  2285. Xregister erc;
  2286. Xint truth;
  2287. XPCB *pcb;
  2288. XLCB *condition_lcb;
  2289. Xint condition_index = param->index;
  2290. X
  2291. X    if(!proc_level)
  2292. X        return(eNotExecutingProc);
  2293. X
  2294. X    pcb = pcb_stack[proc_level - 1];
  2295. X    condition_lcb = pcb->current;
  2296. X
  2297. XREPEAT_WHILE:
  2298. X
  2299. X    if(erc = get_truth_str(param,&truth))
  2300. X        return(erc);
  2301. X
  2302. X/* if end of command, execute frame */
  2303. X    if(end_of_cmd(param))
  2304. X    {
  2305. X        if(erc = execute_frame(truth))
  2306. X        {
  2307. X            if(erc == eContinueCommand)
  2308. X                goto CONTINUE;
  2309. X            if(erc == eBreakCommand)
  2310. X                erc = 0;
  2311. X            return(erc);
  2312. X        }
  2313. X    }
  2314. X    else if(truth)
  2315. X    {
  2316. X        if(erc = execute_esd(param))
  2317. X            return(erc);
  2318. X    }
  2319. X
  2320. X/* repeat if indicated */
  2321. XCONTINUE:
  2322. X    if(truth)
  2323. X    {
  2324. X        pcb->current = condition_lcb;
  2325. X        param->index = param->old_index = condition_index;
  2326. X        goto REPEAT_WHILE;
  2327. X    }
  2328. X
  2329. X    return(0);
  2330. X}   /* end of pcmd_whiles */
  2331. X
  2332. X/* vi: set tabstop=4 shiftwidth=4: */
  2333. X/* end of pcmdwhile.c */
  2334. SHAR_EOF
  2335. $TOUCH -am 1224224290 'pcmdwhile.c' &&
  2336. chmod 0644 pcmdwhile.c ||
  2337. echo 'restore of pcmdwhile.c failed'
  2338. Wc_c="`wc -c < 'pcmdwhile.c'`"
  2339. test 2686 -eq "$Wc_c" ||
  2340.     echo 'pcmdwhile.c: original size 2686, current size' "$Wc_c"
  2341. true || echo 'restore of pcmdxfer.c failed'
  2342. echo End of part 13, continue with part 14
  2343. exit 0
  2344. --------------------------------------------------------------------
  2345. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2346. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2347.  
  2348. exit 0 # Just in case...
  2349. -- 
  2350. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2351. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2352. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2353. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2354.