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

  1. Newsgroups: comp.sources.misc
  2. From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  3. Subject:  v21i070:  ecu - ECU async comm package rev 3.10, Part18/37
  4. Message-ID: <1991Aug4.015901.9219@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 44090c46690eb739d81a4a6ba6f6cc04
  6. Date: Sun, 4 Aug 1991 01:59:01 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  10. Posting-number: Volume 21, Issue 70
  11. Archive-name: ecu/part18
  12. Environment: SCO, XENIX, ISC
  13. Supersedes: ecu3: Volume 16, Issue 25-59
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu310.18 (part 18 of ecu310)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file proc.c continued
  20. #
  21. if touch 2>&1 | fgrep 'amc' > /dev/null
  22.  then TOUCH=touch
  23.  else TOUCH=true
  24. fi
  25. if test ! -r _shar_seq_.tmp; then
  26.     echo 'Please unpack part 1 first!'
  27.     exit 1
  28. fi
  29. (read Scheck
  30.  if test "$Scheck" != 18; then
  31.     echo Please unpack part "$Scheck" next!
  32.     exit 1
  33.  else
  34.     exit 0
  35.  fi
  36. ) < _shar_seq_.tmp || exit 1
  37. if test ! -f _shar_wnt_.tmp; then
  38.     echo 'x - still skipping proc.c'
  39. else
  40. echo 'x - continuing file proc.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'proc.c' &&
  42. X/*:04-30-1991-03:19-root@n4hgf-add search for .ep in ecu lib ep subdir */
  43. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  44. X
  45. X#include "ecu.h"
  46. X#include "ecuerror.h"
  47. X#include "ecukey.h"
  48. X#include "esd.h"
  49. X#include "var.h"
  50. X#include "proc.h"
  51. X
  52. X#define NEED_P_CMD
  53. X#include "ecucmd.h"
  54. X
  55. Xextern int rcvr_pid;
  56. Xextern int sigint;
  57. Xextern int proc_interrupt;
  58. X
  59. XPCB *pcb_stack[PROC_STACK_MAX];
  60. X
  61. Xint proc_level = 0;
  62. Xint proctrace = 0;
  63. X
  64. Xchar goto_label[64];
  65. X
  66. X/*+-------------------------------------------------------------------------
  67. X    _get_goto_label(param)
  68. X--------------------------------------------------------------------------*/
  69. Xint
  70. X_get_goto_label(param)
  71. XESD *param;
  72. X{
  73. Xregister erc;
  74. Xregister ESD *label_esd;
  75. X
  76. X    goto_label[0] = 0;
  77. X    if(erc = get_alphanum_zstr(param,goto_label,sizeof(goto_label)))
  78. X    {
  79. X        if((label_esd = esdalloc(64)) == (ESD *)0)
  80. X            return(eNoMemory);
  81. X        if(!(erc = gstr(param,label_esd,0)))
  82. X            strcpy(goto_label,label_esd->pb);
  83. X        esdfree(label_esd);
  84. X    }
  85. X
  86. X    return(erc);
  87. X
  88. X}    /* end of _get_goto_label */
  89. X
  90. X/*+-------------------------------------------------------------------------
  91. X    pcmd_goto(param)
  92. X--------------------------------------------------------------------------*/
  93. Xint
  94. Xpcmd_goto(param)
  95. XESD *param;
  96. X{
  97. X
  98. X    if(!proc_level)
  99. X        return(eNotExecutingProc);
  100. X    if(_get_goto_label(param))
  101. X        return(eInvalidLabel);
  102. X    return(eProcAttn_GOTO);
  103. X
  104. X}    /* end of pcmd_goto */
  105. X
  106. X/*+-------------------------------------------------------------------------
  107. X    pcmd_gotob(param)
  108. X--------------------------------------------------------------------------*/
  109. Xint
  110. Xpcmd_gotob(param)
  111. XESD *param;
  112. X{
  113. X
  114. X    if(!proc_level)
  115. X        return(eNotExecutingProc);
  116. X    if(_get_goto_label(param))
  117. X        return(eInvalidLabel);
  118. X    return(eProcAttn_GOTOB);
  119. X
  120. X}    /* end of pcmd_gotob */
  121. X
  122. X/*+-------------------------------------------------------------------------
  123. X    _cmd_gosub_common(param,type)
  124. X--------------------------------------------------------------------------*/
  125. Xint
  126. X_cmd_gosub_common(param,type)
  127. XESD *param;
  128. Xint type;
  129. X{
  130. Xint erc;
  131. XLCB *current_save;
  132. Xint index_save;
  133. X
  134. X    if(_get_goto_label(param))
  135. X        return(eInvalidLabel);
  136. X    current_save = pcb_stack[proc_level - 1]->current;
  137. X    index_save = current_save->text->index;
  138. X    if(!(erc = execute_proc(pcb_stack[proc_level - 1],type)))
  139. X    {
  140. X        pcb_stack[proc_level - 1]->current = current_save;
  141. X        current_save->text->index = index_save;
  142. X    }
  143. X    return(erc);
  144. X
  145. X}    /* end of _cmd_gosub_common */
  146. X
  147. X/*+-------------------------------------------------------------------------
  148. X    pcmd_gosub(param)
  149. X--------------------------------------------------------------------------*/
  150. Xint
  151. Xpcmd_gosub(param)
  152. XESD *param;
  153. X{
  154. X    if(!proc_level)
  155. X        return(eNotExecutingProc);
  156. X    return(_cmd_gosub_common(param,eProcAttn_GOTO));
  157. X}    /* end of pcmd_gosub */
  158. X
  159. X/*+-------------------------------------------------------------------------
  160. X    pcmd_gosubb(param)
  161. X--------------------------------------------------------------------------*/
  162. Xint
  163. Xpcmd_gosubb(param)
  164. XESD *param;
  165. X{
  166. X    if(!proc_level)
  167. X        return(eNotExecutingProc);
  168. X    return(_cmd_gosub_common(param,eProcAttn_GOTO));
  169. X}    /* end of pcmd_gosubb */
  170. X
  171. X/*+-------------------------------------------------------------------------
  172. X    pcmd_return(param)
  173. X--------------------------------------------------------------------------*/
  174. Xint
  175. Xpcmd_return(param)
  176. XESD *param;
  177. X{
  178. Xlong value = 0;
  179. X    if(!gint(param,&value))
  180. X    {
  181. X        if((value < 0) || (value > 255))
  182. X            value = 255;
  183. X        if(proctrace)
  184. X            pprintf("return value %ld\n",value);
  185. X        if(value)
  186. X            value += e_USER;
  187. X        return((int)value);
  188. X    }
  189. X    return(eProcAttn_RETURN);
  190. X}    /* end of pcmd_return */
  191. X
  192. X/*+-------------------------------------------------------------------------
  193. X    find_labelled_lcb(label,first,last)
  194. Xsearch for match between label
  195. X--------------------------------------------------------------------------*/
  196. XLCB *
  197. Xfind_labelled_lcb(label,first,last)
  198. Xchar *label;
  199. Xregister LCB *first;
  200. XLCB *last;
  201. X{
  202. Xregister llen = strlen(label);
  203. XESD *text;
  204. X
  205. X    while(first)
  206. X    {
  207. X        text = first->text;
  208. X        if((text->cb >= llen) && (!strncmp(text->pb,label,llen))
  209. X            && (!text->pb[llen] || isspace(text->pb[llen])))
  210. X            return(first);
  211. X
  212. X        if(first == last)
  213. X            return((LCB *)0);
  214. X        first = first->next;
  215. X    }
  216. X    pputs("find_labelled_lab logic error\n");
  217. X    return((LCB *)0);
  218. X
  219. X}    /* end of find_labelled_lcb */
  220. X
  221. X/*+-------------------------------------------------------------------------
  222. X    execute_goto(pcb,goto_type)
  223. X--------------------------------------------------------------------------*/
  224. Xexecute_goto(pcb,goto_type)
  225. XPCB *pcb;
  226. Xint goto_type;
  227. X{
  228. XLCB *next = (LCB *)0;    /* next lcb to execute */
  229. X
  230. X    switch(goto_type)
  231. X    {
  232. X        case eProcAttn_GOTO:
  233. X            if(!(next = find_labelled_lcb(goto_label,pcb->current,pcb->last)))
  234. X                next = find_labelled_lcb(goto_label,pcb->first,pcb->current);
  235. X            break;
  236. X        case eProcAttn_GOTOB:
  237. X            if(!(next = find_labelled_lcb(goto_label,pcb->first,pcb->current)))
  238. X                next = find_labelled_lcb(goto_label,pcb->current,pcb->last);
  239. X            break;
  240. X    }
  241. X    if(next)
  242. X    {
  243. X        pcb->current = next;
  244. X        return(0);
  245. X    }
  246. X    pprintf("goto/gosub label not found: %s\n",goto_label);
  247. X    return(eFATAL_ALREADY);
  248. X
  249. X}    /* end of execute_goto */
  250. X
  251. X/*+-------------------------------------------------------------------------
  252. X    show_error_position(pcb)
  253. Xcursor MUST be at left margin when this is called
  254. X--------------------------------------------------------------------------*/
  255. Xvoid
  256. Xshow_error_position(pcb)
  257. XPCB *pcb;
  258. X{
  259. XESD *tesd = pcb->current->text;
  260. Xregister itmp = tesd->old_index;
  261. Xchar tag[64];
  262. X
  263. X    sprintf(tag,"%s %u> ",pcb->argv[0],pcb->current->lineno);
  264. X    pputs(tag);
  265. X    pputs(tesd->pb);
  266. X    pputs("\n");
  267. X    itmp = strlen(tag) + tesd->old_index;
  268. X    while(itmp--)
  269. X        pputc(' ');
  270. X    pputs("^\n");
  271. X
  272. X}    /* end of show_error_position */
  273. X
  274. X/*+-------------------------------------------------------------------------
  275. X    find_proc_cmd(cmd_list,cmd)
  276. X--------------------------------------------------------------------------*/
  277. XP_CMD *
  278. Xfind_proc_cmd(cmd_list,cmd)
  279. Xregister P_CMD *cmd_list;
  280. Xregister char *cmd;
  281. X{
  282. X    while(cmd_list->token != -1)
  283. X    {
  284. X        if(!strcmp(cmd_list->cmd,cmd))
  285. X            break;
  286. X        cmd_list++;
  287. X    }
  288. X    return((cmd_list->token == -1) ? (P_CMD *)0 : cmd_list);
  289. X
  290. X}    /* end of find_proc_cmd */
  291. X
  292. X/*+-------------------------------------------------------------------------
  293. X    execute_esd(tesd)
  294. X--------------------------------------------------------------------------*/
  295. Xexecute_esd(tesd)
  296. XESD *tesd;
  297. X{
  298. Xint erc;
  299. XP_CMD *pcmd;
  300. Xstatic P_CMD *set_pcmd = (P_CMD *)0;    /* quick access to 'set' */
  301. Xchar cmd[32];
  302. X
  303. X    /* if interrupt, exit */
  304. X    if(sigint)
  305. X    {
  306. X        proc_interrupt = 1;
  307. X        return(eCONINT);
  308. X    }
  309. X
  310. X    /* if blank, skip it */
  311. X    if(skip_cmd_break(tesd))
  312. X        return(0);
  313. X
  314. X    /* if comment, skip it */
  315. X    if(!skip_cmd_char(tesd,'#'))
  316. X        return(0);
  317. X
  318. X    if(*(tesd->pb + tesd->index) == '{')
  319. X    {
  320. X        pputs("invalid '{'\n");
  321. X        return(eFATAL_ALREADY);
  322. X    }
  323. X
  324. X    while(1)
  325. X    {
  326. X        /* get command -- allow leading '$' to assume 'set' command */
  327. X        if(*(tesd->pb + tesd->index) == '$')
  328. X        {
  329. X            /* find 'set' in the list -- save for rapid access later */
  330. X            if(set_pcmd)
  331. X                pcmd = set_pcmd;
  332. X            else if((pcmd = find_proc_cmd(icmd_cmds,"set")) == (P_CMD *)0)
  333. X                return(eInternalLogicError);
  334. X            else
  335. X                set_pcmd = pcmd;
  336. X        }
  337. X        else
  338. X        {
  339. X            if(get_alphanum_zstr(tesd,cmd,sizeof(cmd)))
  340. X                return(eIllegalCommand);
  341. X            /* find it in the list */
  342. X            if((pcmd = find_proc_cmd(icmd_cmds,cmd)) == (P_CMD *)0)
  343. X                return(eIllegalCommand);
  344. X        }
  345. X
  346. X        /* check to see if this command available for procedure */
  347. X        if(!pcmd->proc)
  348. X            return(eInteractiveCmd);
  349. X
  350. X        /* execute the command */
  351. X        if(erc = (*pcmd->proc)(tesd))
  352. X            return(erc);
  353. X
  354. X        /* look for comment */
  355. X        if(!skip_cmd_char(tesd,'#'))
  356. X            break;
  357. X
  358. X        /* look for multiple commands on line */
  359. X        if(skip_cmd_char(tesd,';'))
  360. X            break;
  361. X
  362. X        /* if blank after ';', skip it */
  363. X        if(skip_cmd_break(tesd))
  364. X            break;
  365. X    }
  366. X    return(0);
  367. X        
  368. X}    /* end of execute_esd */
  369. X
  370. X/*+-------------------------------------------------------------------------
  371. X    execute_labelled_esd(tesd)
  372. X--------------------------------------------------------------------------*/
  373. Xexecute_labelled_esd(tesd)
  374. XESD *tesd;
  375. X{
  376. Xregister index = 0;
  377. Xregister cb = tesd->cb;
  378. Xregister char *pb = tesd->pb;
  379. X
  380. X/* reset indices */
  381. X    tesd->index = index;
  382. X    tesd->old_index = index;
  383. X
  384. X/* if comment, skip it */
  385. X    if(!skip_cmd_char(tesd,'#'))
  386. X        return(0);
  387. X
  388. X/* skip over any label */
  389. X    while(!isspace(*(pb + index)) && (index < cb))
  390. X        index++;
  391. X    tesd->index = index;
  392. X    tesd->old_index = index;
  393. X
  394. X    return(execute_esd(tesd));
  395. X}    /* end of execute_labelled_esd */
  396. X
  397. X/*+-------------------------------------------------------------------------
  398. X    dump_proc(pcb)
  399. X--------------------------------------------------------------------------*/
  400. Xvoid
  401. Xdump_proc(pcb)
  402. XPCB *pcb;
  403. X{
  404. Xint itmp;
  405. XLCB *lcb;
  406. X
  407. X    pprintf("------ pcb @ 0x%08lx -----------------\n",pcb);
  408. X    pprintf("argc=%d first=0x%08lx last=0x%08lx\n",pcb->argc,
  409. X        pcb->first,pcb->last);
  410. X    for(itmp = 0; itmp < pcb->argc; itmp++)
  411. X    {
  412. X        pprintf("argv(%d) @ 0x%lx: '%s'\n",itmp,pcb->argv[itmp],
  413. X            pcb->argv[itmp]);
  414. X    }
  415. X    pputs("\n");
  416. X    lcb = pcb->first;
  417. X    while(lcb)
  418. X    {
  419. X        pprintf("lcb @ 0x%08lx   lineno=%u\n",lcb,lcb->lineno);
  420. X        pputs("\n");
  421. X        lcb = lcb->next;
  422. X    }
  423. X    pflush();
  424. X}    /* end of dump_proc */
  425. X
  426. X/*+-------------------------------------------------------------------------
  427. X    trace_proc_cmd(pcb) - if asked, show command
  428. X--------------------------------------------------------------------------*/
  429. Xvoid
  430. Xtrace_proc_cmd(pcb)
  431. XPCB *pcb;
  432. X{
  433. X    if(proctrace)
  434. X    {
  435. X        pprintf("%s %u> ",pcb->argv[0],pcb->current->lineno);
  436. X        pputs(pcb->current->text->pb);
  437. X        pputc('\n');
  438. X    }
  439. X
  440. X}    /* end of trace_proc_cmd */
  441. X
  442. X/*+-------------------------------------------------------------------------
  443. X    execute_proc(pcb,use_goto_label) - execute a memory-resident procedure
  444. X--------------------------------------------------------------------------*/
  445. Xexecute_proc(pcb,use_goto_label)
  446. XPCB *pcb;
  447. Xint use_goto_label;
  448. X{
  449. Xint erc = 0;
  450. X
  451. X    if(proc_level == PROC_STACK_MAX)
  452. X        return(eProcStackTooDeep);
  453. X
  454. X    pcb_stack[proc_level++] = pcb;
  455. X    if(use_goto_label)
  456. X    {
  457. X        if(erc = execute_goto(pcb,use_goto_label))
  458. X            return(erc);
  459. X    }
  460. X    else
  461. X        pcb->current = pcb->first;
  462. X
  463. X    mkv_proc_starting(pcb);
  464. X
  465. X    while(pcb->current)
  466. X    {
  467. X        /* execute the command */
  468. X        trace_proc_cmd(pcb);
  469. X        if(erc = execute_labelled_esd(pcb->current->text))
  470. X        {
  471. X            /* handle other classes of errors */
  472. X            switch(erc & 0xF000)
  473. X            {
  474. X                case e_WARNING:        /* warning */
  475. X                    erc = 0;
  476. X                    break;
  477. X
  478. X                case e_FATAL:        /* fatal */
  479. X                    goto PROC_RETURN;
  480. X
  481. X                case e_ProcAttn:    /* proc attention */
  482. X                    switch(erc)
  483. X                    {
  484. X                        case eProcAttn_GOTO:
  485. X                        case eProcAttn_GOTOB:
  486. X                            if(erc = execute_goto(pcb,erc))
  487. X                                break;    /* didn't find it */
  488. X                            continue;    /* pcb->current is now goto target */
  489. X
  490. X                        case eProcAttn_RETURN:
  491. X                            erc = 0;
  492. X                            break;
  493. X
  494. X                        case eProcAttn_Interrupt:
  495. X                        case eProcAttn_ESCAPE:
  496. X                            pprintf(
  497. X                                "procedure %s interrupted.\n",pcb->argv[0]);
  498. X                            erc = eFATAL_ALREADY;
  499. X                            break;
  500. X
  501. X                        default:
  502. X                            pprintf("procedure error 0x%x\n",erc);
  503. X                            erc = eFATAL_ALREADY;
  504. X                            break;
  505. X                    }
  506. X                    goto PROC_RETURN;
  507. X
  508. X                default:    /* must be proc return error code */
  509. X                    goto PROC_RETURN;
  510. X                    break;
  511. X            }
  512. X        }
  513. X
  514. X        if(proc_interrupt)
  515. X        {
  516. X            proc_interrupt = 0;
  517. X            sigint = 0;
  518. X            pprintf("procedure %s interrupted\n",pcb->argv[0]);
  519. X            erc = eFATAL_ALREADY;
  520. X        }
  521. X
  522. X        if(erc)
  523. X            break;
  524. X        pcb->current = pcb->current->next;
  525. X    }
  526. X
  527. XPROC_RETURN:
  528. X    mkv_proc_terminating(pcb);
  529. X    if(erc)
  530. X    {
  531. X        if((erc > 0) && (erc < e_USER))
  532. X        {
  533. X            pprintf(">>procedure %s returned %d\n",pcb->argv[0],erc);
  534. X            erc |= e_USER;
  535. X        }
  536. X        else if((erc > e_USER) && (erc <= 0x1FFF))
  537. X        {
  538. X            ;    /* already said it */
  539. X        }
  540. X        else
  541. X        {
  542. X            if(erc != eFATAL_ALREADY)
  543. X            {
  544. X                proc_error(erc);
  545. X                erc = eFATAL_ALREADY;
  546. X            }
  547. X            show_error_position(pcb);
  548. X        }
  549. X    }
  550. X    pcb_stack[--proc_level] = (PCB *)0;
  551. X    if(erc && !proc_level)
  552. X        plog_control((char *)0);
  553. X    return(erc);
  554. X}    /* end of execute_proc */
  555. X
  556. X/*+-------------------------------------------------------------------------
  557. X    free_lcb_chain(lcb)
  558. X--------------------------------------------------------------------------*/
  559. Xvoid
  560. Xfree_lcb_chain(lcb)
  561. Xregister LCB *lcb;
  562. X{
  563. XLCB *plcb;
  564. X
  565. X    while(lcb)
  566. X    {
  567. X        if(lcb->text)
  568. X            esdfree(lcb->text);
  569. X        plcb  = lcb;
  570. X        lcb = lcb->next;
  571. X        free((char *)plcb);
  572. X    }
  573. X
  574. X}    /* end of free_lcb_chain */
  575. X
  576. X/*+-------------------------------------------------------------------------
  577. X    find_procedure(name) - find procedure if it exists
  578. X--------------------------------------------------------------------------*/
  579. Xchar *
  580. Xfind_procedure(name)
  581. Xchar *name;
  582. X{
  583. Xstatic char procpath[256];
  584. X
  585. X/*
  586. X * try to find proc file in current directory
  587. X */
  588. X    strcpy(procpath,name);
  589. X    strcat(procpath,".ep");
  590. X    if(!access(procpath,4))
  591. X        return(procpath);
  592. X    if(proctrace && (errno != ENOENT))
  593. X        pperror(procpath);
  594. X
  595. X/*
  596. X * try to find proc file in home .ecu subdirectory
  597. X */
  598. X    get_home_dir(procpath);
  599. X    strcat(procpath,"/.ecu/");
  600. X    strcat(procpath,name);
  601. X    strcat(procpath,".ep");
  602. X    if(!access(procpath,4))
  603. X        return(procpath);
  604. X    if(proctrace && (errno != ENOENT))
  605. X        pperror(procpath);
  606. X
  607. X/*
  608. X * try to find proc file in library ep subdirectory
  609. X */
  610. X    strcpy(procpath,ECULIBDIR);
  611. X    strcat(procpath,"/ep/");
  612. X    strcat(procpath,name);
  613. X    strcat(procpath,".ep");
  614. X    if(!access(procpath,4))
  615. X        return(procpath);
  616. X    if(proctrace && (errno != ENOENT) && (errno != ENOTDIR))
  617. X        pperror(procpath);
  618. X
  619. X/*
  620. X * no luck
  621. X */
  622. X    return((char *)0);
  623. X
  624. X}    /* end of find_procedure */
  625. X
  626. X/*+-------------------------------------------------------------------------
  627. X    do_proc(argc,argv) - read in a disk-based procedure and execute it
  628. X--------------------------------------------------------------------------*/
  629. Xdo_proc(argc,argv)
  630. Xint argc;
  631. Xchar **argv;
  632. X{
  633. Xregister itmp;
  634. Xint itmp2;
  635. Xint erc;
  636. Xint iargv;
  637. Xchar *pargv[MAX_PARGV];
  638. Xint ipargv = 0;
  639. Xchar s256[256];
  640. Xchar *procpath;
  641. XFILE *fp;
  642. XPCB *pcb = (PCB *)0;
  643. XLCB *lcb = (LCB *)0;
  644. XLCB *plcb;
  645. Xushort line_count = 0;
  646. Xextern ulong colors_current;
  647. Xulong colors_at_entry = colors_current;
  648. X
  649. X    proc_interrupt = 0;
  650. X    sigint = 0;
  651. X    for(iargv = 0; iargv < argc; iargv++)
  652. X    {
  653. X        if(ipargv == MAX_PARGV)
  654. X        {
  655. X            pprintf("\nToo many arguments to %s invocation\n",pargv[0]);
  656. X            erc = eFATAL_ALREADY;
  657. X            goto RETURN;
  658. X        }
  659. X        pargv[ipargv++] = argv[iargv];
  660. X    }
  661. X
  662. X    if(!ipargv)
  663. X    {
  664. X        pputs("\nno procedure name given\n");
  665. X        erc = eFATAL_ALREADY;
  666. X        goto RETURN;
  667. X    }
  668. X
  669. X    if(!(procpath = find_procedure(pargv[0])))
  670. X    {
  671. X        pprintf("\nprocedure %s not found\n",pargv[0]);
  672. X        erc = eFATAL_ALREADY;
  673. X        goto RETURN;
  674. X    }
  675. X    fp = fopen(procpath,"r");
  676. X    if(!fp)
  677. X    {
  678. X        pperror(procpath);
  679. X        erc = eFATAL_ALREADY;
  680. X        goto RETURN;
  681. X    }
  682. X    if(proctrace)
  683. X        pprintf("DO: %s\n",procpath);
  684. X
  685. X    if(!(pcb = (PCB *)malloc(sizeof(PCB))))
  686. X    {
  687. X        erc = eNoMemory;
  688. X        goto RETURN;
  689. X    }
  690. X
  691. X    pcb->argv = pargv;
  692. X    pcb->argc = ipargv;
  693. X    pcb->first = (LCB *)0;
  694. X
  695. X    plcb = (LCB *)0;
  696. X    line_count = 0;
  697. X    while(1)
  698. X    {
  699. X        if(fgets(s256,sizeof(s256),fp) == NULL)
  700. X            break;
  701. X        line_count++;
  702. X
  703. X        itmp = strlen(s256) - 1;    /* skip blank lines */
  704. X        if(!itmp)
  705. X            continue;
  706. X        s256[itmp] = 0;                /* kill trailing NL */
  707. X        for(itmp2 = 0; itmp2 < itmp; itmp2++)
  708. X        {    /* convert tabs to spaces so we don't have to scan for each */
  709. X            if(s256[itmp2] == TAB)
  710. X                s256[itmp2] = SPACE;
  711. X        }
  712. X        if(s256[0] == '#')             /* skip comments */
  713. X            continue;
  714. X
  715. X        if(!(lcb = (LCB *)malloc(sizeof(LCB))))
  716. X        {
  717. X            fclose(fp);
  718. X            erc = eNoMemory;
  719. X            goto RETURN;
  720. X        }
  721. X
  722. X        lcb->prev = plcb;
  723. X        lcb->next = (LCB *)0;
  724. X        lcb->lineno = line_count;
  725. X
  726. X        if(plcb)
  727. X            plcb->next = lcb;
  728. X        else
  729. X            pcb->first = lcb;
  730. X
  731. X        if((lcb->text = esdalloc(itmp)) == (ESD *)0)
  732. X        {
  733. X            fclose(fp);
  734. X            erc = eNoMemory;
  735. X            goto RETURN;
  736. X        }
  737. X        strcpy(lcb->text->pb,s256);
  738. X        lcb->text->cb = itmp;
  739. X        esd_null_terminate(lcb->text);
  740. X        plcb = lcb;
  741. X    }
  742. X    fclose(fp);
  743. X    pcb->last = lcb;
  744. X    if(line_count)
  745. X        erc = execute_proc(pcb,0);
  746. X    else
  747. X        erc = eProcEmpty;
  748. X
  749. XRETURN:
  750. X    if(pcb)
  751. X    {
  752. X        if(pcb->first)
  753. X            free_lcb_chain(pcb->first);
  754. X        free((char *)pcb);
  755. X    }
  756. X    if((erc > e_USER) && (erc <= 0x1FFF))
  757. X        erc -= e_USER;
  758. X    if(erc > e_USER)
  759. X        setcolor(colors_at_entry);
  760. X    return(erc);
  761. X
  762. X}    /* end of do_proc */
  763. X
  764. X/*+-------------------------------------------------------------------------
  765. X    pcmd_do(param)
  766. X--------------------------------------------------------------------------*/
  767. Xpcmd_do(param)
  768. XESD *param;
  769. X{
  770. Xint erc;
  771. Xregister ipargv;
  772. Xchar *cmd_copy;
  773. Xchar *pargv[MAX_PARGV];
  774. XESD *pargv_esd[MAX_PARGV];
  775. Xint pargc = 0;
  776. X
  777. X    if(!(cmd_copy = (char *)malloc(param->cb)))
  778. X        return(eNoMemory);
  779. X    strcpy(cmd_copy,param->pb + param->old_index);
  780. X    while(pargc != MAX_PARGV)
  781. X    {
  782. X        if(end_of_cmd(param))
  783. X            break;
  784. X        if((pargv_esd[pargc] = esdalloc(256)) == (ESD *)0)
  785. X        {
  786. X            erc = eNoMemory;
  787. X            goto RETURN;
  788. X        }
  789. X        if(erc = gstr(param,pargv_esd[pargc],1))
  790. X            goto RETURN;
  791. X        pargv[pargc] = pargv_esd[pargc]->pb;
  792. X        pargc++;
  793. X    }
  794. X
  795. X    if(pargc < MAX_PARGV)
  796. X        erc = do_proc(pargc,pargv);
  797. X    else
  798. X    {
  799. X        pprintf("too many arguments to procedure\n");
  800. X        erc = eFATAL_ALREADY;
  801. X    }
  802. X
  803. XRETURN:
  804. X    free(cmd_copy);
  805. X    for(ipargv = 0; ipargv < pargc; ipargv++)
  806. X        esdfree(pargv_esd[ipargv]);
  807. X    return(erc);
  808. X
  809. X}    /* end of pcmd_do */
  810. X
  811. X/* vi: set tabstop=4 shiftwidth=4: */
  812. X/* end of proc.c */
  813. SHAR_EOF
  814. echo 'File proc.c is complete' &&
  815. $TOUCH -am 0725125991 'proc.c' &&
  816. chmod 0644 proc.c ||
  817. echo 'restore of proc.c failed'
  818. Wc_c="`wc -c < 'proc.c'`"
  819. test 17690 -eq "$Wc_c" ||
  820.     echo 'proc.c: original size 17690, current size' "$Wc_c"
  821. rm -f _shar_wnt_.tmp
  822. fi
  823. # ============= proc.h ==============
  824. if test -f 'proc.h' -a X"$1" != X"-c"; then
  825.     echo 'x - skipping proc.h (File already exists)'
  826.     rm -f _shar_wnt_.tmp
  827. else
  828. > _shar_wnt_.tmp
  829. echo 'x - extracting proc.h (Text)'
  830. sed 's/^X//' << 'SHAR_EOF' > 'proc.h' &&
  831. X/*+-------------------------------------------------------------------------
  832. X    proc.h
  833. X    wht@n4hgf.Mt-Park.GA.US
  834. X--------------------------------------------------------------------------*/
  835. X/*+:EDITS:*/
  836. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  837. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  838. X
  839. X
  840. Xtypedef struct lcb_type
  841. X{
  842. X    ESD *text;                /* line's text buffer */
  843. X    struct lcb_type *next;    /* next lcb in chain; if==NULL, no more in chain */
  844. X    struct lcb_type *prev;    /* previous lcb in chain; if==NULL, top of chain */
  845. X    ushort lineno;            /* line number */
  846. X} LCB;
  847. X
  848. Xtypedef struct pcb_type
  849. X{
  850. X    int argc;
  851. X    char **argv;
  852. X    LCB *first;            /* first in procedure */
  853. X    LCB *last;            /* last in procedure */
  854. X    LCB *current;        /* currently executing or last executed line */
  855. X    char *mkvs_last;    /* actually MKV *, but ... */
  856. X    char *mkvi_last;    /* ... see var.c for details */
  857. X} PCB;
  858. X
  859. X#define MAX_PARGV 20    /* max args to procedure, including name */
  860. X#define PROC_STACK_MAX    10    /* max proc nest */
  861. SHAR_EOF
  862. $TOUCH -am 0725125991 'proc.h' &&
  863. chmod 0644 proc.h ||
  864. echo 'restore of proc.h failed'
  865. Wc_c="`wc -c < 'proc.h'`"
  866. test 988 -eq "$Wc_c" ||
  867.     echo 'proc.h: original size 988, current size' "$Wc_c"
  868. rm -f _shar_wnt_.tmp
  869. fi
  870. # ============= proc_error.c ==============
  871. if test -f 'proc_error.c' -a X"$1" != X"-c"; then
  872.     echo 'x - skipping proc_error.c (File already exists)'
  873.     rm -f _shar_wnt_.tmp
  874. else
  875. > _shar_wnt_.tmp
  876. echo 'x - extracting proc_error.c (Text)'
  877. sed 's/^X//' << 'SHAR_EOF' > 'proc_error.c' &&
  878. X/* CHK=0xD771 */
  879. X/*+-------------------------------------------------------------------------
  880. X    proc_error.c - print ecu procedure error
  881. X--------------------------------------------------------------------------*/
  882. X/*+:EDITS:*/
  883. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  884. X/*:07-06-1991-22:58-build_err-creation from ecuerror.h */
  885. X
  886. X#include "ecu.h"
  887. X#include "ecuerror.h"
  888. X
  889. X/*+-------------------------------------------------------------------------
  890. X    proc_error(erc) - print error message
  891. X--------------------------------------------------------------------------*/
  892. Xvoid
  893. Xproc_error(erc)
  894. Xint erc;
  895. X{
  896. X    switch(erc)
  897. X    {
  898. X        case eProcEmpty:
  899. X            pputs("empty procedure\n");
  900. X            break;
  901. X        case eConnectFailed:
  902. X            pputs("failed to connect\n");
  903. X            break;
  904. X        case eNoSwitches:
  905. X            pputs("no switch(es) to command\n");
  906. X            break;
  907. X        case eIllegalCommand:
  908. X            pputs("invalid command\n");
  909. X            break;
  910. X        case eNoMemory:
  911. X            pputs("no more memory available\n");
  912. X            break;
  913. X        case eSyntaxError:
  914. X            pputs("syntax error\n");
  915. X            break;
  916. X        case eIllegalVarNumber:
  917. X            pputs("number is invalid or out of range\n");
  918. X            break;
  919. X        case eIllegalVarType:
  920. X            pputs("unrecognized variable type\n");
  921. X            break;
  922. X        case eNotInteger:
  923. X            pputs("integer expected and not found\n");
  924. X            break;
  925. X        case eCONINT:
  926. X            pputs("abort due to interrupt\n");
  927. X            break;
  928. X        case eInvalidFunction:
  929. X            pputs("invalid function name\n");
  930. X            break;
  931. X        case eMissingLeftParen:
  932. X            pputs("did not find expected left paren\n");
  933. X            break;
  934. X        case eMissingRightParen:
  935. X            pputs("did not find expected right paren\n");
  936. X            break;
  937. X        case eCommaExpected:
  938. X            pputs("expected comma not found\n");
  939. X            break;
  940. X        case eProcStackTooDeep:
  941. X            pputs("procedure stack depth exceeded\n");
  942. X            break;
  943. X        case eInvalidRelOp:
  944. X            pputs("invalid relational operator\n");
  945. X            break;
  946. X        case eInvalidIntOp:
  947. X            pputs("invalid integer operator\n");
  948. X            break;
  949. X        case eInvalidStrOp:
  950. X            pputs("invalid string operator\n");
  951. X            break;
  952. X        case eNotExecutingProc:
  953. X            pputs("not executing DO at this time\n");
  954. X            break;
  955. X        case eInvalidLabel:
  956. X            pputs("invalid label\n");
  957. X            break;
  958. X        case eInternalLogicError:
  959. X            pputs("internal logic error ... whoops\n");
  960. X            break;
  961. X        case eEOF:
  962. X            pputs("end of file or read error\n");
  963. X            break;
  964. X        case eBufferTooSmall:
  965. X            pputs("string too long\n");
  966. X            break;
  967. X        case eNoParameter:
  968. X            pputs("expected parameter not found\n");
  969. X            break;
  970. X        case eBadParameter:
  971. X            pputs("bad parameter\n");
  972. X            break;
  973. X        case eInvalidHexNumber:
  974. X            pputs("invalid hexadecimal digit\n");
  975. X            break;
  976. X        case eInvalidDecNumber:
  977. X            pputs("invalid decimal digit\n");
  978. X            break;
  979. X        case eInvalidOctNumber:
  980. X            pputs("invalid octal digit\n");
  981. X            break;
  982. X        case eInteractiveCmd:
  983. X            pputs("interactive command\n");
  984. X            break;
  985. X        case eNoLineAttached:
  986. X            pputs("no line (modem) attached\n");
  987. X            break;
  988. X        case eBadFileNumber:
  989. X            pputs("file number out of range\n");
  990. X            break;
  991. X        case eNotImplemented:
  992. X            pputs("not implemented\n");
  993. X            break;
  994. X        case eDuplicateMatch:
  995. X            pputs("more than one condition matches\n");
  996. X            break;
  997. X        case eColonExpected:
  998. X            pputs("expected colon not found\n");
  999. X            break;
  1000. X        case eLabelInvalidHere:
  1001. X            pputs("label not allowed on this statement\n");
  1002. X            break;
  1003. X        case eNoCloseFrame:
  1004. X            pputs("missing '}' for '{'\n");
  1005. X            break;
  1006. X        case eNoFrame:
  1007. X            pputs("missing command or command group after 'while' or 'if'\n");
  1008. X            break;
  1009. X        case eMissingCommand:
  1010. X            pputs("expected command not found\n");
  1011. X            break;
  1012. X        case eBreakCommand:
  1013. X            pputs("'break' outside 'while'\n");
  1014. X            break;
  1015. X        case eContinueCommand:
  1016. X            pputs("'continue' outside 'while'\n");
  1017. X            break;
  1018. X        case eElseCommand:
  1019. X            pputs("'else' without matching 'if'\n");
  1020. X            break;
  1021. X        case eInvalidVarName:
  1022. X            pputs("invalid variable name\n");
  1023. X            break;
  1024. X        case eNoSuchVariable:
  1025. X            pputs("variable by this name not defined\n");
  1026. X            break;
  1027. X        case eInvalidLogicOp:
  1028. X            pputs("invalid logical operator\n");
  1029. X            break;
  1030. X        case eExpectRespondFail:
  1031. X            pputs("expect-respond failed\n");
  1032. X            break;
  1033. X        case eProcAttn_GOTO:
  1034. X            pputs("GOTO detected\n");
  1035. X            break;
  1036. X        case eProcAttn_GOTOB:
  1037. X            pputs("GOTOB detected\n");
  1038. X            break;
  1039. X        case eProcAttn_RETURN:
  1040. X            pputs("RETURN detected\n");
  1041. X            break;
  1042. X        case eProcAttn_ESCAPE:
  1043. X            pputs("ESCAPE detected\n");
  1044. X            break;
  1045. X        case eProcAttn_Interrupt:
  1046. X            pputs("procedure interrupted\n");
  1047. X            break;
  1048. X        case eFATAL_ALREADY:
  1049. X        case eWARNING_ALREADY:
  1050. X            break;
  1051. X        default:
  1052. X            pprintf("unknown error %x\n",erc);
  1053. X            break;
  1054. X    }
  1055. X} /* end of proc_error */
  1056. X
  1057. X/* vi: set tabstop=4 shiftwidth=4: */
  1058. X/* end of proc_error.c */
  1059. SHAR_EOF
  1060. $TOUCH -am 0725125991 'proc_error.c' &&
  1061. chmod 0644 proc_error.c ||
  1062. echo 'restore of proc_error.c failed'
  1063. Wc_c="`wc -c < 'proc_error.c'`"
  1064. test 4464 -eq "$Wc_c" ||
  1065.     echo 'proc_error.c: original size 4464, current size' "$Wc_c"
  1066. rm -f _shar_wnt_.tmp
  1067. fi
  1068. # ============= procframe.c ==============
  1069. if test -f 'procframe.c' -a X"$1" != X"-c"; then
  1070.     echo 'x - skipping procframe.c (File already exists)'
  1071.     rm -f _shar_wnt_.tmp
  1072. else
  1073. > _shar_wnt_.tmp
  1074. echo 'x - extracting procframe.c (Text)'
  1075. sed 's/^X//' << 'SHAR_EOF' > 'procframe.c' &&
  1076. X/*+-------------------------------------------------------------------------
  1077. X    procframe.c - execute frame of procedure statements
  1078. X    wht@n4hgf.Mt-Park.GA.US
  1079. X
  1080. X  Defined functions:
  1081. X    pcmd_break(param);
  1082. X    pcmd_continue(param);
  1083. X    execute_frame(truth)
  1084. X
  1085. X--------------------------------------------------------------------------*/
  1086. X/*+:EDITS:*/
  1087. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1088. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1089. X
  1090. X#include <ctype.h>
  1091. X#include "ecu.h"
  1092. X#include "ecukey.h"
  1093. X#include "ecuerror.h"
  1094. X#include "esd.h"
  1095. X#include "var.h"
  1096. X#include "proc.h"
  1097. X
  1098. Xextern PCB *pcb_stack[PROC_STACK_MAX];
  1099. Xextern int proc_level;
  1100. Xextern int proc_interrupt;
  1101. Xextern int proctrace;
  1102. X
  1103. X/*+-------------------------------------------------------------------------
  1104. X    pcmd_break(param)
  1105. X--------------------------------------------------------------------------*/
  1106. Xint
  1107. Xpcmd_break(param)
  1108. XESD *param;
  1109. X{
  1110. X    return(eBreakCommand);
  1111. X}    /* end of pcmd_break */
  1112. X
  1113. X/*+-------------------------------------------------------------------------
  1114. X    pcmd_continue(param)
  1115. X--------------------------------------------------------------------------*/
  1116. Xint
  1117. Xpcmd_continue(param)
  1118. XESD *param;
  1119. X{
  1120. X    return(eContinueCommand);
  1121. X}    /* end of pcmd_continue */
  1122. X
  1123. X/*+-------------------------------------------------------------------------
  1124. X    execute_frame(truth)
  1125. X
  1126. X  pcb_stack[proc_level - 1]->current points to lcb behind frame: one
  1127. X  statement or { statements }
  1128. X
  1129. X  if truth true, execute frame, else skip it
  1130. X--------------------------------------------------------------------------*/
  1131. Xint
  1132. Xexecute_frame(truth)
  1133. Xint truth;
  1134. X{
  1135. Xregister itmp;
  1136. Xint erc = 0;
  1137. XPCB *pcb = pcb_stack[proc_level - 1];
  1138. XLCB *original_lcb = pcb->current;
  1139. XLCB *begin_lcb;
  1140. XESD *text;
  1141. Xint nest_level = 0;
  1142. Xint remember_break = 0;
  1143. X
  1144. X    if(!(pcb->current = pcb->current->next))
  1145. X    {
  1146. X        pcb->current = original_lcb;
  1147. X        return(eNoFrame);
  1148. X    }
  1149. X
  1150. X    text = pcb->current->text;
  1151. X    text->old_index = text->index = 0;
  1152. X
  1153. X    if(*text->pb != SPACE)    /* tabs were converted to spaces at read time */
  1154. X        return(eLabelInvalidHere);
  1155. X    skip_cmd_break(text);
  1156. X
  1157. X/* handle single statement frame */
  1158. X    if(*(text->pb + text->index) != '{')
  1159. X    {
  1160. X        itmp = text->cb - text->index;
  1161. X        if( ((itmp > 2) && !strncmp(text->pb + text->index,"if",2)))
  1162. X        {
  1163. X            pputs("command must appear inside {} or on same line as else\n");
  1164. X            erc = eFATAL_ALREADY;
  1165. X        }
  1166. X        else if( ((itmp > 5) && !strncmp(text->pb + text->index,"while",5)))
  1167. X        {
  1168. X            pputs("command must appear inside {} within this context\n");
  1169. X            erc = eFATAL_ALREADY;
  1170. X        }
  1171. X        else if(truth)
  1172. X        {
  1173. X            trace_proc_cmd(pcb);
  1174. X            erc = execute_esd(text);
  1175. X        }
  1176. X        return(erc);
  1177. X    }
  1178. X
  1179. X/* we've got a {} frame */
  1180. X    begin_lcb = pcb->current;
  1181. X    pcb->current = pcb->current->next;
  1182. X    while(pcb->current)
  1183. X    {
  1184. X        if(proc_interrupt)
  1185. X            return(eCONINT);
  1186. X        text = pcb->current->text;
  1187. X        text->old_index = text->index = 0;
  1188. X        if(*text->pb != SPACE)    /* tabs were converted to spaces at read time */
  1189. X            return(eLabelInvalidHere);
  1190. X        skip_cmd_break(text);
  1191. X        if(*(text->pb + text->index) == '}')
  1192. X        {
  1193. X            if(!nest_level)
  1194. X            {
  1195. X                text->index = text->cb;
  1196. X                if(remember_break)
  1197. X                    return(eBreakCommand);
  1198. X                return(0);
  1199. X            }
  1200. X            nest_level--;
  1201. X        }
  1202. X        else if(truth)
  1203. X        {
  1204. X            trace_proc_cmd(pcb);
  1205. X            if(erc = execute_esd(text))
  1206. X            {
  1207. X                if(erc != eBreakCommand)
  1208. X                    return(erc);
  1209. X                remember_break = 1;
  1210. X                truth = 0;
  1211. X            }
  1212. X        }
  1213. X        else if(*(text->pb + text->index) == '{')
  1214. X            nest_level++;
  1215. X        pcb->current = pcb->current->next;
  1216. X    }
  1217. X    pcb->current = begin_lcb;
  1218. X    return(eNoCloseFrame);
  1219. X    
  1220. X}    /* end of execute_frame */
  1221. X
  1222. X/* vi: set tabstop=4 shiftwidth=4: */
  1223. X/* end of procframe.c */
  1224. SHAR_EOF
  1225. $TOUCH -am 0725125991 'procframe.c' &&
  1226. chmod 0644 procframe.c ||
  1227. echo 'restore of procframe.c failed'
  1228. Wc_c="`wc -c < 'procframe.c'`"
  1229. test 3545 -eq "$Wc_c" ||
  1230.     echo 'procframe.c: original size 3545, current size' "$Wc_c"
  1231. rm -f _shar_wnt_.tmp
  1232. fi
  1233. # ============= regexp.c ==============
  1234. if test -f 'regexp.c' -a X"$1" != X"-c"; then
  1235.     echo 'x - skipping regexp.c (File already exists)'
  1236.     rm -f _shar_wnt_.tmp
  1237. else
  1238. > _shar_wnt_.tmp
  1239. echo 'x - extracting regexp.c (Text)'
  1240. sed 's/^X//' << 'SHAR_EOF' > 'regexp.c' &&
  1241. X/*+-------------------------------------------------------------------------
  1242. X    regexp.c -- regular expression functions made sane
  1243. X--------------------------------------------------------------------------*/
  1244. X/*+:EDITS:*/
  1245. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1246. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1247. X
  1248. X#include <stdio.h>
  1249. X#include "stdio_lint.h"
  1250. X#include "lint_args.h"
  1251. X#include "ecuerror.h"
  1252. X#include "esd.h"
  1253. X#include "var.h"
  1254. X#include <setjmp.h>
  1255. X
  1256. X#define    CBRA    2
  1257. X#define    CCHR    4
  1258. X#define    CDOT    8
  1259. X#define    CCL    12
  1260. X#define    CDOL    20
  1261. X#define    CCEOF    22
  1262. X#define    CKET    24
  1263. X#define    CBACK    36
  1264. X
  1265. X#define    STAR    01
  1266. X#define    RNGE    03
  1267. X
  1268. X#define    NBRA    9
  1269. X
  1270. X#define    PLACE(c)    ep[c >> 3] |= bittab[c & 07]
  1271. X#define    ISTHERE(c)    (ep[c >> 3] & bittab[c & 07])
  1272. X
  1273. Xvoid getrnge();
  1274. X
  1275. Xextern int proctrace;
  1276. Xextern int proc_level;
  1277. X
  1278. Xchar *braslist[NBRA];
  1279. Xchar *braelist[NBRA];
  1280. Xint nbra,ebra;
  1281. Xchar *match_start,*match_end,*locs;
  1282. Xint sed;
  1283. Xint nodelim;
  1284. Xint circf;
  1285. Xint low;
  1286. Xint size;
  1287. X
  1288. Xchar bittab[] = { 1,2,4,8,16,32,64,128 };
  1289. X
  1290. Xjmp_buf    compile_error_jmpbuf;
  1291. X
  1292. Xvoid
  1293. Xcompile(pattern,ep,endbuf,seof)
  1294. Xchar *pattern;
  1295. Xregister char *ep;
  1296. Xchar *endbuf;
  1297. Xint seof;
  1298. X{
  1299. X    register char *sp = pattern;
  1300. X    register c;
  1301. X    register eof = seof;
  1302. X    char *lastep = pattern;
  1303. X    int cclcnt;
  1304. X    char bracket[NBRA],*bracketp;
  1305. X    int closed;
  1306. X    char neg;
  1307. X    int lc;
  1308. X    int i,cflg;
  1309. X
  1310. X    lastep = 0;
  1311. X    if((c = *sp++) == eof || c == '\n')
  1312. X    {
  1313. X        if(c == '\n')
  1314. X        {
  1315. X            --sp;
  1316. X            nodelim = 1;
  1317. X        }
  1318. X        if(*ep == 0 && !sed)
  1319. X            longjmp(compile_error_jmpbuf,41);
  1320. X        return;
  1321. X    }
  1322. X    bracketp = bracket;
  1323. X    circf = closed = nbra = ebra = 0;
  1324. X    if(c == '^')
  1325. X        circf++;
  1326. X    else
  1327. X        --sp;
  1328. X    while(1)
  1329. X    {
  1330. X        if(ep >= endbuf)
  1331. X            longjmp(compile_error_jmpbuf,50);
  1332. X        c = *sp++;
  1333. X        if(c != '*' && ((c != '\\') || (*sp != '{')))
  1334. X            lastep = ep;
  1335. X        if(c == eof)
  1336. X        {
  1337. X            *ep++ = CCEOF;
  1338. X            return;
  1339. X        }
  1340. X        switch(c)
  1341. X        {
  1342. X
  1343. X        case '.':
  1344. X            *ep++ = CDOT;
  1345. X            continue;
  1346. X
  1347. X        case '\n':
  1348. X            if(!sed)
  1349. X            {
  1350. X                --sp;
  1351. X                *ep++ = CCEOF;
  1352. X                nodelim = 1;
  1353. X                return;
  1354. X            }
  1355. X            else longjmp(compile_error_jmpbuf,36);
  1356. X        case '*':
  1357. X            if(lastep==0 || *lastep==CBRA || *lastep==CKET)
  1358. X                goto defchar;
  1359. X            *lastep |= STAR;
  1360. X            continue;
  1361. X
  1362. X        case '$':
  1363. X            if(*sp != eof && *sp != '\n')
  1364. X                goto defchar;
  1365. X            *ep++ = CDOL;
  1366. X            continue;
  1367. X
  1368. X        case '[':
  1369. X            if(&ep[17] >= endbuf)
  1370. X                longjmp(compile_error_jmpbuf,50);
  1371. X
  1372. X            *ep++ = CCL;
  1373. X            lc = 0;
  1374. X            for(i = 0; i < 16; i++)
  1375. X                ep[i] = 0;
  1376. X
  1377. X            neg = 0;
  1378. X            if((c = *sp++) == '^')
  1379. X            {
  1380. X                neg = 1;
  1381. X                c = *sp++;
  1382. X            }
  1383. X
  1384. X            do 
  1385. X            {
  1386. X                if(c == '\0' || c == '\n')
  1387. X                    longjmp(compile_error_jmpbuf,49);
  1388. X                if(c == '-' && lc != 0)
  1389. X                {
  1390. X                    if((c = *sp++) == ']')
  1391. X                    {
  1392. X                        PLACE('-');
  1393. X                        break;
  1394. X                    }
  1395. X                    while(lc < c)
  1396. X                    {
  1397. X                        PLACE(lc);
  1398. X                        lc++;
  1399. X                    }
  1400. X                }
  1401. X                if(c == '\\')
  1402. X                {
  1403. X                    switch(c = *sp++)
  1404. X                    {
  1405. X                    case 'n':
  1406. X                        c = '\n';
  1407. X                        break;
  1408. X                    }
  1409. X                }
  1410. X                lc = c;
  1411. X                PLACE(c);
  1412. X            } while((c = *sp++) != ']');
  1413. X            if(neg)
  1414. X            {
  1415. X                for(cclcnt = 0; cclcnt < 16; cclcnt++)
  1416. X                    ep[cclcnt] ^= -1;
  1417. X                ep[0] &= 0376;
  1418. X            }
  1419. X
  1420. X            ep += 16;
  1421. X
  1422. X            continue;
  1423. X
  1424. X        case '\\':
  1425. X            switch(c = *sp++)
  1426. X            {
  1427. X
  1428. X            case '(':
  1429. X                if(nbra >= NBRA)
  1430. X                    longjmp(compile_error_jmpbuf,43);
  1431. X                *bracketp++ = nbra;
  1432. X                *ep++ = CBRA;
  1433. X                *ep++ = nbra++;
  1434. X                continue;
  1435. X
  1436. X            case ')':
  1437. X                if(bracketp <= bracket || ++ebra != nbra)
  1438. X                    longjmp(compile_error_jmpbuf,42);
  1439. X                *ep++ = CKET;
  1440. X                *ep++ = *--bracketp;
  1441. X                closed++;
  1442. X                continue;
  1443. X
  1444. X            case '{':
  1445. X                if(lastep == (char *) (0))
  1446. X                    goto defchar;
  1447. X                *lastep |= RNGE;
  1448. X                cflg = 0;
  1449. Xnlim:
  1450. X                c = *sp++;
  1451. X                i = 0;
  1452. X                do 
  1453. X                {
  1454. X                    if('0' <= c && c <= '9')
  1455. X                        i = 10 * i + c - '0';
  1456. X                    else
  1457. X                        longjmp(compile_error_jmpbuf,16);
  1458. X                } while(((c = *sp++) != '\\') && (c != ','));
  1459. X                if(i >= 255)
  1460. X                    longjmp(compile_error_jmpbuf,11);
  1461. X                *ep++ = i;
  1462. X                if(c == ',')
  1463. X                {
  1464. X                    if(cflg++)
  1465. X                        longjmp(compile_error_jmpbuf,44);
  1466. X                    if((c = *sp++) == '\\')
  1467. X                        *ep++ = 255;
  1468. X                    else 
  1469. X                    {
  1470. X                        --sp;
  1471. X                        goto nlim;
  1472. X                        /* get 2'nd number */
  1473. X                    }
  1474. X                }
  1475. X                if(*sp++ != '}')
  1476. X                    longjmp(compile_error_jmpbuf,45);
  1477. X                if(!cflg)    /* one number */
  1478. X                    *ep++ = i;
  1479. X                else if((ep[-1] & 0377) < (ep[-2] & 0377))
  1480. X                    longjmp(compile_error_jmpbuf,46);
  1481. X                continue;
  1482. X
  1483. X            case '\n':
  1484. X                longjmp(compile_error_jmpbuf,36);
  1485. X
  1486. X            case 'n':
  1487. X                c = '\n';
  1488. X                goto defchar;
  1489. X
  1490. X            default:
  1491. X                if(c >= '1' && c <= '9')
  1492. X                {
  1493. X                    if((c -= '1') >= closed)
  1494. X                        longjmp(compile_error_jmpbuf,25);
  1495. X                    *ep++ = CBACK;
  1496. X                    *ep++ = c;
  1497. X                    continue;
  1498. X                }
  1499. X            }
  1500. X            /* Drop through to default to use \ to turn off special chars */
  1501. X
  1502. Xdefchar:
  1503. X        default:
  1504. X            lastep = ep;
  1505. X            *ep++ = CCHR;
  1506. X            *ep++ = c;
  1507. X        }
  1508. X    }
  1509. X}
  1510. X
  1511. Xstep(p1,p2)
  1512. Xregister char *p1,*p2;
  1513. X{
  1514. X    register c;
  1515. X
  1516. X    if(circf)
  1517. X    {
  1518. X        match_start = p1;
  1519. X        return(advance(p1,p2));
  1520. X    }
  1521. X    /* fast check for first character */
  1522. X    if(*p2==CCHR)
  1523. X    {
  1524. X        c = p2[1];
  1525. X        do 
  1526. X        {
  1527. X            if(*p1 != c)
  1528. X                continue;
  1529. X            if(advance(p1,p2))
  1530. X            {
  1531. X                match_start = p1;
  1532. X                return(1);
  1533. X            }
  1534. X        } while(*p1++);
  1535. X        return(0);
  1536. X    }
  1537. X    /* regular algorithm */
  1538. X    do 
  1539. X    {
  1540. X        if(advance(p1,p2))
  1541. X        {
  1542. X            match_start = p1;
  1543. X            return(1);
  1544. X        }
  1545. X    } while(*p1++);
  1546. X    return(0);
  1547. X}
  1548. X
  1549. Xadvance(lp,ep)
  1550. Xregister char *lp,*ep;
  1551. X{
  1552. X    register char *curlp;
  1553. X    char c;
  1554. X    char *bbeg;
  1555. X    int ct;
  1556. X
  1557. X    while(1)
  1558. X        switch(*ep++)
  1559. X        {
  1560. X
  1561. X        case CCHR:
  1562. X            if(*ep++ == *lp++)
  1563. X                continue;
  1564. X            return(0);
  1565. X
  1566. X        case CDOT:
  1567. X            if(*lp++)
  1568. X                continue;
  1569. X            return(0);
  1570. X
  1571. X        case CDOL:
  1572. X            if(*lp==0)
  1573. X                continue;
  1574. X            return(0);
  1575. X
  1576. X        case CCEOF:
  1577. X            match_end = lp;
  1578. X            return(1);
  1579. X
  1580. X        case CCL:
  1581. X            c = *lp++ & 0177;
  1582. X            if(ISTHERE(c))
  1583. X            {
  1584. X                ep += 16;
  1585. X                continue;
  1586. X            }
  1587. X            return(0);
  1588. X        case CBRA:
  1589. X            braslist[*ep++] = lp;
  1590. X            continue;
  1591. X
  1592. X        case CKET:
  1593. X            braelist[*ep++] = lp;
  1594. X            continue;
  1595. X
  1596. X        case CCHR|RNGE:
  1597. X            c = *ep++;
  1598. X            getrnge(ep);
  1599. X            while(low--)
  1600. X                if(*lp++ != c)
  1601. X                    return(0);
  1602. X            curlp = lp;
  1603. X            while(size--)
  1604. X                if(*lp++ != c)
  1605. X                    break;
  1606. X            if(size < 0)
  1607. X                lp++;
  1608. X            ep += 2;
  1609. X            goto star;
  1610. X
  1611. X        case CDOT|RNGE:
  1612. X            getrnge(ep);
  1613. X            while(low--)
  1614. X                if(*lp++ == '\0')
  1615. X                    return(0);
  1616. X            curlp = lp;
  1617. X            while(size--)
  1618. X                if(*lp++ == '\0')
  1619. X                    break;
  1620. X            if(size < 0)
  1621. X                lp++;
  1622. X            ep += 2;
  1623. X            goto star;
  1624. X
  1625. X        case CCL|RNGE:
  1626. X            getrnge(ep + 16);
  1627. X            while(low--)
  1628. X            {
  1629. X                c = *lp++ & 0177;
  1630. X                if(!ISTHERE(c))
  1631. X                    return(0);
  1632. X            }
  1633. X            curlp = lp;
  1634. X            while(size--)
  1635. X            {
  1636. X                c = *lp++ & 0177;
  1637. X                if(!ISTHERE(c))
  1638. X                    break;
  1639. X            }
  1640. X            if(size < 0)
  1641. X                lp++;
  1642. X            ep += 18;        /* 16 + 2 */
  1643. X            goto star;
  1644. X
  1645. X        case CBACK:
  1646. X            bbeg = braslist[*ep];
  1647. X            ct = braelist[*ep++] - bbeg;
  1648. X
  1649. X            if(ecmp(bbeg,lp,ct))
  1650. X            {
  1651. X                lp += ct;
  1652. X                continue;
  1653. X            }
  1654. X            return(0);
  1655. X
  1656. X        case CBACK|STAR:
  1657. X            bbeg = braslist[*ep];
  1658. X            ct = braelist[*ep++] - bbeg;
  1659. X            curlp = lp;
  1660. X            while(ecmp(bbeg,lp,ct))
  1661. X                lp += ct;
  1662. X
  1663. X            while(lp >= curlp)
  1664. X            {
  1665. X                if(advance(lp,ep))    return(1);
  1666. X                lp -= ct;
  1667. X            }
  1668. X            return(0);
  1669. X
  1670. X
  1671. X        case CDOT|STAR:
  1672. X            curlp = lp;
  1673. X            while(*lp++);
  1674. X            goto star;
  1675. X
  1676. X        case CCHR|STAR:
  1677. X            curlp = lp;
  1678. X            while(*lp++ == *ep);
  1679. X            ep++;
  1680. X            goto star;
  1681. X
  1682. X        case CCL|STAR:
  1683. X            curlp = lp;
  1684. X            do 
  1685. X            {
  1686. X                c = *lp++ & 0177;
  1687. X            } while(ISTHERE(c));
  1688. X            ep += 16;
  1689. X            goto star;
  1690. X
  1691. Xstar:
  1692. X            do 
  1693. X            {
  1694. X                if(--lp == locs)
  1695. X                    break;
  1696. X                if(advance(lp,ep))
  1697. X                    return(1);
  1698. X            } while(lp > curlp);
  1699. X            return(0);
  1700. X
  1701. X        }
  1702. X}
  1703. X
  1704. Xvoid
  1705. Xgetrnge(regexp)
  1706. Xregister char *regexp;
  1707. X{
  1708. X    low = *regexp++ & 0377;
  1709. X    size = ((*regexp & 0377) == 255) ? 20000 : (*regexp & 0377) - low;
  1710. X}
  1711. X
  1712. Xecmp(a,b,count)
  1713. Xregister char *a,*b;
  1714. Xregister count;
  1715. X{
  1716. X    while(count--)
  1717. X        if(*a++ != *b++)
  1718. X            return(0);
  1719. X    return(1);
  1720. X}
  1721. X
  1722. X/*+-------------------------------------------------------------------------
  1723. X    itmp = regexp_compile(regexp,cmpbuf,cmpbuf_size,emsg)
  1724. X
  1725. Xreturns 0 if no compile error,
  1726. Xelse error occurred (*emsg points to error message text)
  1727. X--------------------------------------------------------------------------*/
  1728. Xint
  1729. Xregexp_compile(regexp,cmpbuf,cmpbuf_size,emsg)
  1730. Xchar *regexp;
  1731. Xchar *cmpbuf;
  1732. Xint cmpbuf_size;
  1733. Xchar **emsg;
  1734. X{
  1735. X    register int itmp;
  1736. X    static char errm[40];
  1737. X
  1738. X    if(itmp = setjmp(compile_error_jmpbuf))
  1739. X    {
  1740. X        switch(itmp)
  1741. X        {
  1742. X        case 11:
  1743. X            *emsg = "Range endpoint too large";
  1744. X            break;
  1745. X        case 16:
  1746. X            *emsg = "Bad number";
  1747. X            break;
  1748. X        case 25:
  1749. X            *emsg = "\"\\digit\" out of range";
  1750. X            break;
  1751. X        case 36:
  1752. X            *emsg = "Illegal or missing delimiter";
  1753. X            break;
  1754. X        case 41:
  1755. X            *emsg = "No previous regular expression";
  1756. X            break;
  1757. X        case 42:
  1758. X            *emsg = "More \\)'s than \\('s in regular expression";
  1759. X            break;
  1760. X        case 43:
  1761. X            *emsg = "More \\('s than \\)'s in regular expression";
  1762. X            break;
  1763. X        case 44:
  1764. X            *emsg = "More than 2 numbers in \\{ \\}";
  1765. X            break;
  1766. X        case 45:
  1767. X            *emsg = "} expected after \\";
  1768. X            break;
  1769. X        case 46:
  1770. X            *emsg = "First number exceeds second in \\{ \\}";
  1771. X            break;
  1772. X        case 49:
  1773. X            *emsg = "[] imbalance";
  1774. X            break;
  1775. X        case 50:
  1776. X            *emsg = "Regular expression too complex";
  1777. X            break;
  1778. X        default:
  1779. X            sprintf(errm,"Unknown regexp compile error %d",itmp);
  1780. X            *emsg = errm;
  1781. X            break;
  1782. X        }
  1783. X        return(itmp);
  1784. X    }
  1785. X
  1786. X    compile(regexp,cmpbuf,cmpbuf + cmpbuf_size,0);
  1787. X    return(0);
  1788. X}    /* end of regexp_compile */
  1789. X
  1790. X/*+-------------------------------------------------------------------------
  1791. X    regexp_scan(cmpbuf,str_to_search,&match,&matchlen)
  1792. Xreturn 1 if string match found, else 0
  1793. Xif string matches, match receives pointer to first byte, matchlen = length
  1794. Xof matching string
  1795. X--------------------------------------------------------------------------*/
  1796. Xregexp_scan(cmpbuf,str_to_search,match,matchlen)
  1797. Xchar *cmpbuf;
  1798. Xchar *str_to_search;
  1799. Xchar **match;
  1800. Xint *matchlen;
  1801. X{
  1802. X    register int itmp = step(str_to_search,cmpbuf);
  1803. X    if(itmp)
  1804. X    {
  1805. X        *match = match_start;
  1806. X        *matchlen = (int)(match_end - match_start);
  1807. X    }
  1808. X    return(itmp);
  1809. X}    /* end of regexp_scan */
  1810. X
  1811. X#define CMPBUF_SIZE    256
  1812. Xchar cmpbuf[CMPBUF_SIZE];
  1813. X
  1814. X/*+-------------------------------------------------------------------------
  1815. X    regexp_operation(match_str,regexp_str,rtn_value)
  1816. X
  1817. Xone stop operation: determine if 'match_str' matches 'regexp_str',
  1818. Xreturning the index of the match in *rtn_value and setting #I0 to
  1819. Xthe length of the match
  1820. X--------------------------------------------------------------------------*/
  1821. Xint
  1822. Xregexp_operation(match_str,regexp_str,rtn_value)
  1823. Xchar *match_str;
  1824. Xchar *regexp_str;
  1825. Xlong *rtn_value;
  1826. X{
  1827. Xchar *emsg;
  1828. Xchar *match;
  1829. Xint matchlen;
  1830. X
  1831. X    if(regexp_compile(regexp_str,cmpbuf,sizeof(cmpbuf),&emsg))
  1832. X    {
  1833. X        pprintf("compile 1 error: %s\n",emsg);
  1834. X        return(eFATAL_ALREADY);
  1835. X    }
  1836. X
  1837. X    if(regexp_scan(cmpbuf,match_str,&match,&matchlen))
  1838. X    {
  1839. X        *rtn_value = (long)(match - match_str);
  1840. X        iv[0] = (long)matchlen;
  1841. X        if(proc_level && proctrace)
  1842. X            pprintf("%match set $i00 = %ld\n",iv[0]);
  1843. X    }
  1844. X    else
  1845. X        *rtn_value = -1;
  1846. X
  1847. X    return(0);
  1848. X}    /* end of regexp_operation */
  1849. X
  1850. X/* vi: set tabstop=4 shiftwidth=4: */
  1851. X/* end of regexp.c */
  1852. SHAR_EOF
  1853. $TOUCH -am 0725125991 'regexp.c' &&
  1854. chmod 0644 regexp.c ||
  1855. echo 'restore of regexp.c failed'
  1856. Wc_c="`wc -c < 'regexp.c'`"
  1857. test 10453 -eq "$Wc_c" ||
  1858.     echo 'regexp.c: original size 10453, current size' "$Wc_c"
  1859. rm -f _shar_wnt_.tmp
  1860. fi
  1861. # ============= relop.h ==============
  1862. if test -f 'relop.h' -a X"$1" != X"-c"; then
  1863.     echo 'x - skipping relop.h (File already exists)'
  1864.     rm -f _shar_wnt_.tmp
  1865. else
  1866. > _shar_wnt_.tmp
  1867. echo 'x - extracting relop.h (Text)'
  1868. sed 's/^X//' << 'SHAR_EOF' > 'relop.h' &&
  1869. X/*+-------------------------------------------------------------------------
  1870. X    relop.h - operator definitions (relative and logical)
  1871. X    wht@n4hgf.Mt-Park.GA.US
  1872. X--------------------------------------------------------------------------*/
  1873. X/*+:EDITS:*/
  1874. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1875. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1876. X
  1877. X#define OP_EQ   1
  1878. X#define OP_NE   2
  1879. X#define OP_LT   3
  1880. X#define OP_LE   4
  1881. X#define OP_GT   5
  1882. X#define OP_GE   6
  1883. X
  1884. X#define OP_AND    20
  1885. X#define OP_OR    21
  1886. X
  1887. X/* vi: set tabstop=4 shiftwidth=4: */
  1888. X/* end of relop.h */
  1889. SHAR_EOF
  1890. $TOUCH -am 0725125991 'relop.h' &&
  1891. chmod 0644 relop.h ||
  1892. echo 'restore of relop.h failed'
  1893. Wc_c="`wc -c < 'relop.h'`"
  1894. test 566 -eq "$Wc_c" ||
  1895.     echo 'relop.h: original size 566, current size' "$Wc_c"
  1896. rm -f _shar_wnt_.tmp
  1897. fi
  1898. # ============= smap.c ==============
  1899. if test -f 'smap.c' -a X"$1" != X"-c"; then
  1900.     echo 'x - skipping smap.c (File already exists)'
  1901.     rm -f _shar_wnt_.tmp
  1902. else
  1903. > _shar_wnt_.tmp
  1904. echo 'x - extracting smap.c (Text)'
  1905. sed 's/^X//' << 'SHAR_EOF' > 'smap.c' &&
  1906. X/* CHK=0x7CB8 */
  1907. X/*
  1908. X *    @(#)smap.c    1.2    30/08/88    16:28:19    agc
  1909. X *
  1910. X *    Copyright 1988, Joypace Ltd., UK. This product is "careware".
  1911. X *    If you find it useful, I suggest that you send what you think
  1912. X *    it is worth to the charity of your choice.
  1913. X *
  1914. X *    Alistair G. Crooks,                +44 5805 3114
  1915. X *    Joypace Ltd.,
  1916. X *    2 Vale Road,
  1917. X *    Hawkhurst,
  1918. X *    Kent TN18 4BU,
  1919. X *    UK.
  1920. X *
  1921. X *    UUCP Europe                 ...!mcvax!unido!nixpbe!nixbln!agc
  1922. X *    UUCP everywhere else ...!uunet!linus!nixbur!nixpbe!nixbln!agc
  1923. X *
  1924. X *    smap.c - source file for debugging aids.
  1925. X */
  1926. X/*+:EDITS:*/
  1927. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1928. X/*:04-19-1990-03:08-wht@n4hgf-GCC run found unused vars -- rm them */
  1929. X/*:03-25-1990-14:12-wht@n4hgf------ x2.70 ------- */
  1930. X/*:07-03-1989-22:57-wht------ x2.00 ----- */
  1931. X/*:06-24-1989-16:52-wht-flush edits --- ecu 1.95 */
  1932. X
  1933. X#ifndef __GNUC__
  1934. X#ifndef NOMEMCHECK
  1935. X
  1936. X#include <stdio.h>
  1937. X#include <signal.h>
  1938. X#include "stdio_lint.h"
  1939. X#include "lint_args.h"
  1940. X
  1941. Xtypedef struct _slotstr
  1942. X{
  1943. X    char *s_ptr;                /* the allocated area */
  1944. X    unsigned int s_size;        /* its size */
  1945. X    char s_freed;                /* whether it's been freed yet */
  1946. X    char s_blkno;                /* program block reference number */
  1947. X} SLOT;
  1948. X
  1949. X#ifndef MAXSLOTS
  1950. X#define MAXSLOTS    4096
  1951. X#endif /* MAXSLOTS */
  1952. X
  1953. Xstatic SLOT    slots[MAXSLOTS];
  1954. Xstatic int slotc;
  1955. Xstatic int blkno;
  1956. X
  1957. X#define WARNING(s1, s2)        (void) fprintf(stderr, s1, s2)
  1958. X
  1959. X/* __STDC__ dependency hasn't invaded this module yet */
  1960. Xchar *malloc();
  1961. Xchar *calloc();
  1962. Xchar *realloc();
  1963. Xvoid _abort();
  1964. X
  1965. X/*+-------------------------------------------------------------------------
  1966. X    _dump_malloc()
  1967. X--------------------------------------------------------------------------*/
  1968. Xvoid
  1969. X_dump_malloc()
  1970. X{
  1971. Xregister islot;
  1972. Xregister slot_count = 0;
  1973. Xchar dfile[32];
  1974. Xchar title[64];
  1975. XFILE *fp;
  1976. XSLOT *slot;
  1977. X
  1978. X    sprintf(dfile,"/tmp/m%05d.dmp",getpid());
  1979. X    fp = fopen(dfile,"w");
  1980. X    fprintf(stderr,"\r\n\n\ndumping malloc status to %s\r\n",dfile);
  1981. X    for(islot = 0; islot < slotc; islot++)
  1982. X    {
  1983. X        slot = &slots[islot];
  1984. X        if(slot->s_freed)
  1985. X            continue;
  1986. X        sprintf(title,"%d (%d) %08x size %u",
  1987. X            slot_count,islot,slot->s_ptr,slot->s_size);
  1988. X        hex_dump_fp(fp,slot->s_ptr,slot->s_size,title,0);
  1989. X        slot_count++;
  1990. X    }
  1991. X    fclose(fp);
  1992. X    fprintf(stderr,"done\r\n");
  1993. X
  1994. X}    /* end of _dump_malloc */
  1995. X
  1996. X
  1997. X/*
  1998. X *    _malloc - wrapper around malloc. Warns if unusual size given, or the
  1999. X *    real malloc returns a 0 pointer. Returns a pointer to the
  2000. X *    malloc'd area
  2001. X */
  2002. Xchar *
  2003. X_malloc(size)
  2004. Xunsigned int size;
  2005. X{
  2006. X    register SLOT *sp;
  2007. X    char *ptr;
  2008. X    register int i;
  2009. X
  2010. X    if(size == 0)
  2011. X        WARNING("_malloc: unusual size %d bytes\r\n",size);
  2012. X    if((ptr = (char *) malloc(size)) == (char *) 0)
  2013. X        _abort("_malloc: unable to malloc %u bytes\r\n",size);
  2014. X    for(i = 0,sp = slots ; i < slotc ; i++,sp++)
  2015. X        if(sp->s_ptr == ptr)
  2016. X            break;
  2017. X    if(i == slotc)
  2018. X    {
  2019. X        if(slotc == MAXSLOTS - 1)
  2020. X        {
  2021. X            _dump_malloc();
  2022. X            _abort("_malloc: run out of slots\r\n","");
  2023. X        }
  2024. X        sp = &slots[slotc++];
  2025. X    }
  2026. X    else if(!sp->s_freed)
  2027. X        WARNING("_malloc: malloc returned a non-freed pointer\r\n","");
  2028. X    sp->s_size = size;
  2029. X    sp->s_freed = 0;
  2030. X    sp->s_ptr = ptr;
  2031. X    sp->s_blkno = blkno;
  2032. X#ifndef NO_EXTRA_HELP
  2033. X    memset(sp->s_ptr,0x12,sp->s_size);
  2034. X#endif
  2035. X    return(sp->s_ptr);
  2036. X}
  2037. X
  2038. X
  2039. X/*
  2040. X *    _calloc - wrapper for calloc. Calls _malloc to allocate the area, and
  2041. X *    then sets the contents of the area to NUL bytes. Returns its address.
  2042. X */
  2043. Xchar *
  2044. X_calloc(nel,size)
  2045. Xint nel;
  2046. Xunsigned int size;
  2047. X{
  2048. X    unsigned int tot;
  2049. X    register char *ptr;
  2050. X
  2051. X    tot = nel * size;
  2052. X    ptr = _malloc(tot);
  2053. X    if(ptr == (char *)0)
  2054. X        return((char *)0);
  2055. X    memset(ptr,0,tot);
  2056. X    return(ptr);
  2057. X}
  2058. X
  2059. X
  2060. X/*
  2061. X *    _realloc - wrapper for realloc. Checks area already alloc'd and
  2062. X *    not freed. Returns its address
  2063. X */
  2064. Xchar *
  2065. X_realloc(ptr,size)
  2066. Xchar *ptr;
  2067. Xunsigned int size;
  2068. X{
  2069. X    register SLOT *sp;
  2070. X    register int i;
  2071. X
  2072. X    for(i = 0,sp = slots ; i < slotc ; i++,sp++)
  2073. X        if(sp->s_ptr == ptr)
  2074. X            break;
  2075. X    if(i == slotc)
  2076. X        _abort("_realloc: realloc on unallocated area\r\n","");
  2077. X    if(sp->s_freed)
  2078. X        WARNING("_realloc: realloc on freed area\r\n","");
  2079. X    if((sp->s_ptr = (char *) realloc(ptr,size)) == (char *)0)
  2080. X        WARNING("_realloc: realloc failure %d bytes\r\n",size);
  2081. X    sp->s_size = size;
  2082. X    sp->s_blkno = blkno;
  2083. X    return(sp->s_ptr);
  2084. X}
  2085. X
  2086. X
  2087. X/*
  2088. X *    _free - wrapper for free. Loop through allocated slots, until you
  2089. X *    find the one corresponding to pointer. If none, then it's an attempt
  2090. X *    to free an unallocated area. If it's already freed, then tell user.
  2091. X */
  2092. Xvoid
  2093. X_free(ptr)
  2094. Xchar *ptr;
  2095. X{
  2096. X    register SLOT *sp;
  2097. X    register int i;
  2098. X
  2099. X    for(i = 0,sp = slots ; i < slotc ; i++,sp++)
  2100. X        if(sp->s_ptr == ptr)
  2101. X            break;
  2102. X    if(i == slotc)
  2103. X        _abort("_free: free not previously malloc'd\r\n","");
  2104. X    if(sp->s_freed)
  2105. X        _abort("_free: free after previous freeing\r\n","");
  2106. X    (void) free(sp->s_ptr);
  2107. X    sp->s_freed = 1;
  2108. X}
  2109. X
  2110. X
  2111. X/*
  2112. X *    _blkstart - start of a program block. Increase the block reference
  2113. X *    number by one.
  2114. X */
  2115. Xvoid
  2116. X_blkstart()
  2117. X{
  2118. X    blkno += 1;
  2119. X}
  2120. X
  2121. X
  2122. X/*
  2123. X *    _blkend - end of a program block. Check all areas allocated in this
  2124. X *    block have been freed. Decrease the block number by one.
  2125. X */
  2126. Xvoid
  2127. X_blkend()
  2128. X{
  2129. X    register SLOT *sp;
  2130. X    register int i;
  2131. X
  2132. X    if(blkno == 0)
  2133. X    {
  2134. X        WARNING("_blkend: unmatched call to _blkend\r\n","");
  2135. X        return;
  2136. X    }
  2137. X    for(i = 0,sp = slots ; i < slotc ; i++,sp++)
  2138. X        if(sp->s_blkno == blkno && !sp->s_freed)
  2139. X            WARNING("_blkend: %d bytes unfreed\r\n",sp->s_size);
  2140. X    blkno -= 1;
  2141. X}
  2142. X
  2143. X
  2144. X/*
  2145. X *    _blkignore - find the slot corresponding to ptr, and set its block
  2146. X *    number to zero, to avoid _blkend picking it up when checking.
  2147. X */
  2148. Xvoid
  2149. X_blkignore(ptr)
  2150. Xchar *ptr;
  2151. X{
  2152. X    register SLOT *sp;
  2153. X    register int i;
  2154. X
  2155. X    for(i = 0,sp = slots ; i < slotc ; i++,sp++)
  2156. X        if(sp->s_ptr == ptr)
  2157. X            break;
  2158. X    if(i == slotc)
  2159. X        WARNING("_blkignore: pointer has not been allocated\r\n","");
  2160. X    else
  2161. X        sp->s_blkno = 0;
  2162. X}
  2163. X
  2164. X/*
  2165. X *    _abort - print a warning on stderr, and send a SIGQUIT to ourself
  2166. X */
  2167. X#if !defined(BUILDING_LINT_ARGS)
  2168. Xstatic void
  2169. X_abort(s1,s2)
  2170. Xchar *s1;
  2171. Xchar *s2;
  2172. X{
  2173. X#ifdef M_I386
  2174. Xchar *kaboom = (char *)90000000;
  2175. X    
  2176. X    WARNING(s1,s2);
  2177. X    *kaboom = 1;
  2178. X#else
  2179. X    WARNING(s1,s2);
  2180. X    (void) kill(getpid(),SIGIOT);    /* core dump here */
  2181. X#endif
  2182. X}
  2183. X#endif
  2184. X#endif /* NOMEMCHECK */
  2185. X#endif /* __GNUC__ */
  2186. SHAR_EOF
  2187. $TOUCH -am 0725125991 'smap.c' &&
  2188. chmod 0644 smap.c ||
  2189. echo 'restore of smap.c failed'
  2190. Wc_c="`wc -c < 'smap.c'`"
  2191. test 6019 -eq "$Wc_c" ||
  2192.     echo 'smap.c: original size 6019, current size' "$Wc_c"
  2193. rm -f _shar_wnt_.tmp
  2194. fi
  2195. # ============= smap.h ==============
  2196. if test -f 'smap.h' -a X"$1" != X"-c"; then
  2197.     echo 'x - skipping smap.h (File already exists)'
  2198.     rm -f _shar_wnt_.tmp
  2199. else
  2200. > _shar_wnt_.tmp
  2201. echo 'x - extracting smap.h (Text)'
  2202. sed 's/^X//' << 'SHAR_EOF' > 'smap.h' &&
  2203. X/*
  2204. X *    @(#)smap.h    1.1    30/08/88    16:07:36    agc
  2205. X *
  2206. X *    Copyright 1988, Joypace Ltd., UK. This product is "careware".
  2207. X *    If you find it useful, I suggest that you send what you think
  2208. X *    it is worth to the charity of your choice.
  2209. X *
  2210. X *    Alistair G. Crooks,                +44 5805 3114
  2211. X *    Joypace Ltd.,
  2212. X *    2 Vale Road,
  2213. X *    Hawkhurst,
  2214. X *    Kent TN18 4BU,
  2215. X *    UK.
  2216. X *
  2217. X *    UUCP Europe                 ...!mcvax!unido!nixpbe!nixbln!agc
  2218. X *    UUCP everywhere else ...!uunet!linus!nixbur!nixpbe!nixbln!agc
  2219. X *
  2220. X *    smap.h - include file for debugging aids. This file must be included,
  2221. X *    before any calls, in any source file that calls malloc, calloc,
  2222. X *    realloc, or free. (Note alloca is not included in this list).
  2223. X */
  2224. X/*+:EDITS:*/
  2225. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  2226. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2227. X
  2228. X#ifndef WHT
  2229. X#define NOMEMCHECK
  2230. X#endif
  2231. X
  2232. X#ifndef __GNUC__
  2233. X#if !defined(VTYPE)
  2234. X#if defined(__STDC__)    /* sigh ... malloc and such types */
  2235. X#define VTYPE void
  2236. X#else
  2237. X#define VTYPE char
  2238. X#endif
  2239. X#endif
  2240. X
  2241. X#ifdef NOMEMCHECK
  2242. X#define    _blkstart()
  2243. X#define _blkend()
  2244. X#define _blkignore(p)
  2245. XVTYPE *malloc();
  2246. XVTYPE *calloc();
  2247. XVTYPE *realloc();
  2248. Xvoid free();
  2249. X#else /* not NOMEMCHECK */
  2250. X#ifndef malloc
  2251. X#define malloc    _malloc
  2252. X#define calloc    _calloc
  2253. X#define realloc    _realloc
  2254. X#define free    _free
  2255. XVTYPE *_malloc();
  2256. XVTYPE *_calloc();
  2257. XVTYPE *_realloc();
  2258. Xvoid _free();
  2259. X#endif /* not malloc */
  2260. Xvoid    _blkstart();
  2261. Xvoid    _blkend();
  2262. Xvoid    _blkignore();
  2263. X#endif /* not NOMEMCHECK */
  2264. X
  2265. X#endif /* __GNUC__ */
  2266. SHAR_EOF
  2267. $TOUCH -am 0725125991 'smap.h' &&
  2268. chmod 0644 smap.h ||
  2269. echo 'restore of smap.h failed'
  2270. Wc_c="`wc -c < 'smap.h'`"
  2271. test 1476 -eq "$Wc_c" ||
  2272.     echo 'smap.h: original size 1476, current size' "$Wc_c"
  2273. rm -f _shar_wnt_.tmp
  2274. fi
  2275. # ============= stdio_lint.h ==============
  2276. if test -f 'stdio_lint.h' -a X"$1" != X"-c"; then
  2277.     echo 'x - skipping stdio_lint.h (File already exists)'
  2278.     rm -f _shar_wnt_.tmp
  2279. else
  2280. > _shar_wnt_.tmp
  2281. echo 'x - extracting stdio_lint.h (Text)'
  2282. sed 's/^X//' << 'SHAR_EOF' > 'stdio_lint.h' &&
  2283. X/*+-------------------------------------------------------------------------
  2284. X    stdio_lint.h -- prototyping for library routines
  2285. X    wht@n4hgf.Mt-Park.GA.US
  2286. X--------------------------------------------------------------------------*/
  2287. X/*+:EDITS:*/
  2288. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  2289. X/*:01-18-1991-11:55-wht@n4hgf-fix strchr/strrchr per steve@nshore.ncoast.org */
  2290. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2291. X
  2292. X#if defined(__STDC__)
  2293. Xchar *gets(char *);
  2294. Xchar *getenv(char *);
  2295. Xint access(char *,int);
  2296. Xint chmod(char *,int);
  2297. Xint close(int);
  2298. Xint creat(char *,int);
  2299. Xint dup(int);
  2300. Xint fcloseall(void);
  2301. Xint isatty(int);
  2302. Xlong lseek(int,long,int);
  2303. Xint puts(char *);
  2304. Xint read(int,char *,unsigned int);
  2305. X#ifndef __GNUC__
  2306. Xint stat(char *,struct stat *);
  2307. Xint fstat(int,struct stat *);
  2308. X#endif
  2309. Xlong time(long *);
  2310. Xint unlink(char *);
  2311. Xint write(int,char *,unsigned int);
  2312. X#else
  2313. Xchar *fgets();
  2314. Xvoid free();
  2315. Xchar *getenv();
  2316. Xchar *gets();
  2317. Xlong ftell();
  2318. Xlong lseek();
  2319. Xvoid perror();
  2320. Xvoid rewind();
  2321. Xvoid setbuf();
  2322. Xlong time();
  2323. Xchar *strcpy();
  2324. Xchar *strncpy();
  2325. Xchar *strcat();
  2326. Xchar *strncat();
  2327. Xchar *strchr();
  2328. Xchar *strrchr();
  2329. X#endif
  2330. X/* vi: set tabstop=4 shiftwidth=4: */
  2331. SHAR_EOF
  2332. $TOUCH -am 0725125991 'stdio_lint.h' &&
  2333. chmod 0644 stdio_lint.h ||
  2334. echo 'restore of stdio_lint.h failed'
  2335. Wc_c="`wc -c < 'stdio_lint.h'`"
  2336. test 1173 -eq "$Wc_c" ||
  2337.     echo 'stdio_lint.h: original size 1173, current size' "$Wc_c"
  2338. rm -f _shar_wnt_.tmp
  2339. fi
  2340. # ============= termecu.h ==============
  2341. if test -f 'termecu.h' -a X"$1" != X"-c"; then
  2342.     echo 'x - skipping termecu.h (File already exists)'
  2343.     rm -f _shar_wnt_.tmp
  2344. else
  2345. > _shar_wnt_.tmp
  2346. echo 'x - extracting termecu.h (Text)'
  2347. sed 's/^X//' << 'SHAR_EOF' > 'termecu.h' &&
  2348. X/*+-------------------------------------------------------------------------
  2349. X    termecu.h -- termecu (exit()) codes
  2350. X    wht@n4hgf.Mt-Park.GA.US
  2351. X
  2352. X  1 - 64    reserved for signals
  2353. X  193 - 223 reserved for procedure 'exit' codes
  2354. X--------------------------------------------------------------------------*/
  2355. X/*+:EDITS:*/
  2356. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  2357. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2358. X
  2359. X#define TERMECU_OK                    0
  2360. X#define TERMECU_SIG1                1
  2361. X#define TERMECU_SIGN                64
  2362. X#define TERMECU_LINE_READ_ERROR        129
  2363. X#define TERMECU_XMTR_WRITE_ERROR    130
  2364. X#define TERMECU_XMTR_FATAL_ERROR    131
  2365. SHAR_EOF
  2366. true || echo 'restore of termecu.h failed'
  2367. fi
  2368. echo 'End of ecu310 part 18'
  2369. echo 'File termecu.h is continued in part 19'
  2370. echo 19 > _shar_seq_.tmp
  2371. exit 0
  2372. --------------------------------------------------------------------
  2373. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2374. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2375.  
  2376. exit 0 # Just in case...
  2377. -- 
  2378. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2379. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2380. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2381. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2382.