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

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