home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume23 / abc / part18 < prev    next >
Encoding:
Internet Message Format  |  1991-01-08  |  54.3 KB

  1. Subject:  v23i097:  ABC interactive programming environment, Part18/25
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 6b39f011 f6c290da 79edface 2b74f748
  5.  
  6. Submitted-by: Steven Pemberton <steven@cwi.nl>
  7. Posting-number: Volume 23, Issue 97
  8. Archive-name: abc/part18
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  abc/bed/e1cell.c abc/bed/e1gram.c abc/bed/e1ins2.c
  17. #   abc/bint1/i1nug.c abc/bint3/i3fpr.c abc/ihdrs/i2nod.h
  18. #   abc/stc/i2tcp.c
  19. # Wrapped by rsalz@litchi.bbn.com on Mon Dec 17 13:28:14 1990
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 18 (of 25)."'
  23. if test -f 'abc/bed/e1cell.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'abc/bed/e1cell.c'\"
  25. else
  26.   echo shar: Extracting \"'abc/bed/e1cell.c'\" \(7336 characters\)
  27.   sed "s/^X//" >'abc/bed/e1cell.c' <<'END_OF_FILE'
  28. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  29. X
  30. X/*
  31. X * B editor -- Screen management package, cell list manipulation routines.
  32. X */
  33. X
  34. X#include "b.h"
  35. X#include "b0lan.h"
  36. X#include "bedi.h"
  37. X#include "bmem.h"
  38. X#include "bobj.h"
  39. X#include "node.h"
  40. X#include "cell.h"
  41. X#include "args.h"
  42. X
  43. Xextern bool noscroll;
  44. X
  45. X/*
  46. X * Definitions for internals of cell manipulations.
  47. X */
  48. X
  49. XHidden cell *freelist;
  50. X
  51. X#define CELLSIZE (sizeof(cell))
  52. X
  53. X#ifndef PAGESIZE /* 4.2 BSD freaks compile with -DPAGESIZE='getpagesize()' */
  54. X#define PAGESIZE 1024
  55. X#endif
  56. X
  57. X#ifndef MALLOCLOSS
  58. X#define MALLOCLOSS (sizeof(char*))
  59. X    /* number of bytes taken by malloc administration per block */
  60. X#endif
  61. X
  62. X
  63. X/*
  64. X * Replace `oldlcnt' cells from `tops', starting at the one numbered `oldlno',
  65. X * by the list `rep'.
  66. X * Returns a pointer to the deleted chain (with a Nil end pointer).
  67. X */
  68. X
  69. XVisible cell *
  70. Xreplist(tops, rep, oldlno, oldlcnt)
  71. X    cell *tops;
  72. X    cell *rep;
  73. X    int oldlno;
  74. X    register int oldlcnt;
  75. X{
  76. X    cell head;
  77. X    register cell *p;
  78. X    register cell *q;
  79. X    register cell *old;
  80. X    register cell *end;
  81. X    register int diff;
  82. X    int i;
  83. X    int replcnt;
  84. X
  85. X    if (!tops) /* Start with empty list */
  86. X        return rep;
  87. X    head.c_link = tops;
  88. X    p = &head;
  89. X    for (diff = oldlno; diff > 0; --diff) {
  90. X        p = p->c_link;
  91. X        Assert(p);
  92. X    }
  93. X    q = p;
  94. X    for (i = oldlcnt; i > 0 && p; --i)
  95. X        p = p->c_link;
  96. X    if (i > 0) {
  97. X#ifndef NDEBUG
  98. X    if (dflag)
  99. X        debug("[replist jackpot]");
  100. X#endif /* NDEBUG */
  101. X        oldlcnt -= i;
  102. X    }
  103. X    old = q->c_link;
  104. X    q->c_link = rep;
  105. X    if (p) {
  106. X        end = p->c_link;
  107. X        p->c_link = Cnil;
  108. X    }
  109. X    for (replcnt = 0; q->c_link; ++replcnt, q = q->c_link)
  110. X        ;
  111. X    dupmatch(old, rep, oldlcnt, replcnt);
  112. X    discard(old);
  113. X    if (p)
  114. X        q->c_link = end;
  115. X    return head.c_link;
  116. X}
  117. X
  118. X
  119. X/*
  120. X * Allocate a new cell.
  121. X */
  122. X
  123. XHidden cell *
  124. Xnewcell()
  125. X{
  126. X    register cell *p;
  127. X
  128. X    if (!freelist)
  129. X        feedfreelist();
  130. X    p = freelist;
  131. X    freelist = p->c_link;
  132. X    p->c_link = Cnil;
  133. X    return p;
  134. X}
  135. X
  136. X
  137. X/*
  138. X * Feed the free list with a block of new entries.
  139. X * We try to keep them together on a page
  140. X * to keep consecutive accesses fast.
  141. X */
  142. X
  143. XHidden Procedure
  144. Xfeedfreelist()
  145. X{
  146. X    register int n = (PAGESIZE-MALLOCLOSS) / CELLSIZE;
  147. X    register cell *p = (cell*) getmem((unsigned)(n*CELLSIZE));
  148. X#ifdef MEMTRACE
  149. X    fixmem((ptr) p);
  150. X#endif
  151. X    Assert(n > 0);
  152. X    freelist = p;
  153. X    for (; n > 1; --n, ++p)
  154. X        p->c_link = p+1;
  155. X    p->c_link = Cnil;
  156. X}
  157. X
  158. X
  159. X/*
  160. X * Discard all entries of a list of cells.
  161. X */
  162. X
  163. XVisible Procedure
  164. Xdiscard(p)
  165. X    register cell *p;
  166. X{
  167. X    register cell *savefreelist;
  168. X
  169. X    if (!p)
  170. X        return;
  171. X    savefreelist = p;
  172. X    for (;;) {
  173. X        noderelease(p->c_data);
  174. X        p->c_data = Nnil;
  175. X        if (!p->c_link)
  176. X            break;
  177. X        p = p->c_link;
  178. X    }
  179. X    p->c_link = freelist;
  180. X    freelist = savefreelist;
  181. X}
  182. X
  183. X
  184. X/*
  185. X * Replace the `onscreen' fields in the replacement chain by those
  186. X * in the old chain, if they match.
  187. X */
  188. X
  189. XHidden Procedure
  190. Xdupmatch(old, rep, oldcnt, repcnt)
  191. X    register cell *old;
  192. X    register cell *rep;
  193. X    int oldcnt;
  194. X    int repcnt;
  195. X{
  196. X    register int diff = repcnt - oldcnt;
  197. X
  198. X#ifndef NDEBUG
  199. X    if (dflag)
  200. X        debug("[dupmatch(oldcnt=%d, newcnt=%d)]", oldcnt, repcnt);
  201. X#endif /* NDEBUG */
  202. X    while (rep && old) {
  203. X        if (old->c_length == rep->c_length
  204. X            && eqlines(old->c_data, rep->c_data)) {
  205. X            if (old->c_onscreen != Nowhere) {
  206. X                rep->c_onscreen = old->c_onscreen;
  207. X                rep->c_oldindent = old->c_oldindent;
  208. X                rep->c_oldvhole = old->c_oldvhole;
  209. X                rep->c_oldfocus = old->c_oldfocus;
  210. X            }
  211. X            rep = rep->c_link;
  212. X            old = old->c_link;
  213. X        }
  214. X        else {
  215. X            if (diff >= 0) {
  216. X                --diff;
  217. X                rep = rep->c_link;
  218. X            }
  219. X            if (diff < 0) {
  220. X                ++diff;
  221. X                old = old->c_link;
  222. X            }
  223. X        }
  224. X    }
  225. X}
  226. X
  227. X
  228. X/*
  229. X * Build a list of cells consisting of the first `lcnt' lines of the tree.
  230. X */
  231. X
  232. XVisible cell *
  233. Xbuild(p, lcnt)
  234. X    /*auto*/ path p;
  235. X    register int lcnt;
  236. X{
  237. X    cell head;
  238. X    register cell *q = &head;
  239. X
  240. X    p = pathcopy(p);
  241. X    for (;;) {
  242. X        q = q->c_link = newcell();
  243. X        q->c_onscreen = Nowhere;
  244. X        q->c_data = nodecopy(tree(p));
  245. X        q->c_length = linelen(q->c_data);
  246. X        q->c_newindent = Level(p) * INDENTSIZE;
  247. X        q->c_oldindent = 0;
  248. X        q->c_oldvhole = q->c_newvhole = q->c_oldfocus = q->c_newfocus = No;
  249. X        --lcnt;
  250. X        if (lcnt <= 0)
  251. X            break;
  252. X        if (!nextline(&p)) Abort();
  253. X    }
  254. X    q->c_link = Cnil;
  255. X    pathrelease(p);
  256. X    return head.c_link;
  257. X}
  258. X
  259. X
  260. X/*
  261. X * Decide which line is to be on top of the screen.
  262. X * We slide a window through the list of lines, recognizing
  263. X * lines of the focus and lines already on the screen,
  264. X * and stop as soon as we find a reasonable focus position.
  265. X *
  266. X * - The focus must always be on the screen completely;
  267. X *   if it is larger than the screen, its first line must be
  268. X *   on top of the screen.
  269. X * - When old lines can be retained, at least one line above
  270. X *   and below the focus must be shown; the retained lines
  271. X *   should be moved as little as possible.
  272. X * - As little as possible blank space should be shown at the
  273. X *   bottom, even if the focus is at the end of the unit.
  274. X * - If no rule applies, try to center the focus on the screen.
  275. X * - If noscroll is Yes (the terminal can't scroll), and the top
  276. X *   line can't be retained, also try to center the focus on the
  277. X *   screen.
  278. X */
  279. X
  280. XVisible cell *
  281. Xgettop(tops)
  282. X    cell *tops;
  283. X{
  284. X    register cell *pfwa = tops; /* First line of sliding window */
  285. X    register cell *plwa = tops; /* Last+1 line of sliding window */
  286. X    register cell *pffocus = Cnil; /* First line of focus */
  287. X    cell *pscreen = Cnil; /* First line still on screen */
  288. X    register int nfwa = 0; /* Corresponding line numbers in parse tree */
  289. X    register int nlwa = 0;
  290. X    register int nffocus;
  291. X    int nlfocus;
  292. X    int nscreen;
  293. X    int size;
  294. X
  295. X    for (;;) { /* plwa is the current candidate for top line. */
  296. X        if (!pfwa) {
  297. X#ifndef NDEBUG
  298. X            debug("[Lost the focus!]");
  299. X#endif /* NDEBUG */
  300. X            return tops; /* To show *something*... */
  301. X        }
  302. X        while (plwa && nlwa < nfwa+winheight) {
  303. X            /* Find first line *not* in window */
  304. X            size = Space(plwa);
  305. X            if (plwa->c_newfocus) { /* Hit a focus line */
  306. X                if (!pffocus) { /* Note first focus line */
  307. X                    pffocus = plwa;
  308. X                    nffocus = nlwa;
  309. X                }
  310. X                nlfocus = nlwa + size;
  311. X            }
  312. X            if (plwa->c_onscreen != Nowhere) { /* Hello old chap */
  313. X                if (!pscreen) { /* Note first line on screen */
  314. X                    pscreen = plwa;
  315. X                    nscreen = nlwa;
  316. X                }
  317. X            }
  318. X            nlwa += size;
  319. X            plwa = plwa->c_link;
  320. X        }
  321. X        if (pffocus) {
  322. X            /* Focus in sight; stop at first reasonable opportunity */
  323. X            if (pffocus == pfwa)
  324. X                break; /* Grab last chance! */
  325. X            if (!noscroll && nlwa - nfwa <= winheight - winheight/3)
  326. X                break; /* Don't show too much white space at bottom */
  327. X            if (pffocus == pfwa->c_link && nlfocus < nfwa+winheight)
  328. X                break; /* Near top line */
  329. X            if (pscreen && (!noscroll || nffocus > nscreen)) {
  330. X                /* Conservatism may succeed */
  331. X                if (pscreen->c_onscreen >= nscreen - nfwa
  332. X                    && (nlfocus < nfwa+winheight
  333. X                        || !plwa && nlfocus == nfwa+winheight))
  334. X                    break; /* focus entirely on screen */
  335. X            }
  336. X            else { /* No comrades seen */
  337. X                if (nffocus - nfwa <= nfwa+winheight - nlfocus
  338. X                    || !plwa && nlwa <= nfwa+winheight)
  339. X                    break; /* Nicely centered focus or end of unit */
  340. X            }
  341. X        }
  342. X        if (pfwa == pscreen) { /* Say farewell to oldest comrade */
  343. X            pscreen->c_onscreen = Nowhere;
  344. X            do { /* Find next in age */
  345. X                nscreen += Space(pscreen);
  346. X                pscreen = pscreen->c_link;
  347. X                if (pscreen == plwa) {
  348. X                    pscreen = Cnil;
  349. X                    break;
  350. X                }
  351. X            } while (pscreen->c_onscreen == Nowhere);
  352. X        }
  353. X        nfwa += Space(pfwa);
  354. X        pfwa = pfwa->c_link; /* Pass the buck */
  355. X    }
  356. X    return pfwa; /* This is what all those breaks aim at */
  357. X}
  358. END_OF_FILE
  359.   if test 7336 -ne `wc -c <'abc/bed/e1cell.c'`; then
  360.     echo shar: \"'abc/bed/e1cell.c'\" unpacked with wrong size!
  361.   fi
  362.   # end of 'abc/bed/e1cell.c'
  363. fi
  364. if test -f 'abc/bed/e1gram.c' -a "${1}" != "-c" ; then 
  365.   echo shar: Will not clobber existing file \"'abc/bed/e1gram.c'\"
  366. else
  367.   echo shar: Extracting \"'abc/bed/e1gram.c'\" \(7451 characters\)
  368.   sed "s/^X//" >'abc/bed/e1gram.c' <<'END_OF_FILE'
  369. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  370. X
  371. X/*
  372. X * B editor -- All routines referencing the grammar table are in this file.
  373. X */
  374. X
  375. X#include "b.h"
  376. X#include "bedi.h"
  377. X#include "etex.h"
  378. X#include "bmem.h"
  379. X#include "feat.h"
  380. X#include "bobj.h"
  381. X#include "node.h"
  382. X#include "gram.h"
  383. X#include "supr.h"
  384. X#include "tabl.h"
  385. X#include "code.h"    /* not strictly necessary, only for initcodes() */
  386. X#include "args.h"
  387. X
  388. X/*
  389. X * Test whether sym is in the given class.
  390. X */
  391. X
  392. XVisible bool
  393. Xisinclass(sym, ci)
  394. X    register int sym;
  395. X    struct classinfo *ci;
  396. X{
  397. X    register classptr cp;
  398. X
  399. X    Assert(ci && ci->c_class);
  400. X    if (sym == Hole)
  401. X        return !isinclass(Optional, ci);
  402. X    for (cp = ci->c_class; *cp; ++cp)
  403. X        if (sym == *cp)
  404. X            return Yes;
  405. X    return No;
  406. X}
  407. X
  408. X
  409. X/*
  410. X * Deliver the representation array for the given node.
  411. X * If the node is actually just a "text" value, construct
  412. X * one in static storage -- which is overwritten at each call.
  413. X * In this case there are two deficiencies: the next call to
  414. X * noderepr which uses the same feature overwrites the reply
  415. X * value of the previous call, AND if the text value itself
  416. X * is changed, the representation may change, too.
  417. X * In practical use this is no problem at all, however.
  418. X */
  419. X
  420. XVisible string *
  421. Xnoderepr(n)
  422. X    register node n;
  423. X{
  424. X    register int sym;
  425. X
  426. X    if (n && Is_etext(n)) {
  427. X        static string buf[2];
  428. X        if (buf[0]) e_fstrval(buf[0]);
  429. X        buf[0] = e_sstrval((value)n);
  430. X        return buf;
  431. X    }
  432. X    sym = symbol(n);
  433. X    return table[sym].r_repr;
  434. X}
  435. X
  436. X#ifdef MEMTRACE
  437. XVisible Procedure endnoderepr() { /* hack to free noderepr static store */
  438. X    value v= mk_etext("dummy");
  439. X    string *s= noderepr((node)v);
  440. X    freemem((ptr) s[0]);
  441. X    release(v);
  442. X}
  443. X#endif
  444. X
  445. X/*
  446. X * Deliver the prototype node for the given symbol.
  447. X */
  448. X
  449. XVisible node
  450. Xgram(sym)
  451. X    register int sym;
  452. X{
  453. X    Assert(0 <= sym && sym < TABLEN);
  454. X    return table[sym].r_node;
  455. X}
  456. X
  457. X#ifdef SAVEBUF
  458. X
  459. X/*
  460. X * Deliver the name of a symbol.
  461. X */
  462. X
  463. XVisible string
  464. Xsymname(sym)
  465. X    int sym;
  466. X{
  467. X    static char buf[20];
  468. X
  469. X    if (sym >= 0 && sym < TABLEN && table[sym].r_name)
  470. X        return table[sym].r_name;
  471. X    sprintf(buf, "%d", sym);
  472. X    return buf;
  473. X}
  474. X
  475. X
  476. X/*
  477. X * Find the symbol corresponding to a given name.
  478. X * Return -1 if not found.
  479. X */
  480. X
  481. XVisible int
  482. Xnametosym(str)
  483. X    register string str;
  484. X{
  485. X    register int sym;
  486. X    register string name;
  487. X
  488. X    for (sym = 0; sym < TABLEN; ++sym) {
  489. X        name = table[sym].r_name;
  490. X        if (name && !strcmp(name, str))
  491. X            return sym;
  492. X    }
  493. X    return -1;
  494. X}
  495. X
  496. X#endif /* SAVEBUF */
  497. X
  498. X/*
  499. X * Test whether `sym' may replace the node in the path `p'.
  500. X */
  501. X
  502. XVisible bool
  503. Xallowed(p, sym)
  504. X    register path p;
  505. X    register int sym;
  506. X{
  507. X    register path pa = parent(p);
  508. X    register int ich = ichild(p);
  509. X    register int sympa = pa ? symbol(tree(pa)) : Rootsymbol;
  510. X
  511. X    Assert(sympa >= 0 && sympa < TABLEN && ich > 0 && ich <= MAXCHILD);
  512. X    return isinclass(sym, table[sympa].r_class[ich-1]);
  513. X}
  514. X
  515. X
  516. X/*
  517. X * Initialize (and verify) the grammar table.
  518. X * (sets refcnt to infinity)
  519. X */
  520. X
  521. XVisible Procedure
  522. Xinitgram()
  523. X{
  524. X    register int sym;
  525. X    register int nch;
  526. X    register struct classinfo **cp;
  527. X    register struct classinfo *sp;
  528. X    node ch[MAXCHILD];
  529. X
  530. X#ifndef NDEBUG
  531. X    if (dflag)
  532. X        putstr(DEBUGFILE, "*** initgram();\n");
  533. X#endif /* NDEBUG */
  534. X    /* Set the node pointers in the table and check the representations.
  535. X       The code assumes Optional and Hole are the last
  536. X       symbols in the table, i.e. the first processed by the loop. */
  537. X
  538. X    for (sym = TABLEN-1; sym >= 0; --sym) {
  539. X        cp = table[sym].r_class;
  540. X        for (nch = 0; nch < MAXCHILD && (sp = cp[nch]); ++nch)
  541. X            ch[nch] =
  542. X                table[sp->c_class[0] == Optional ? 
  543. X                    Optional : Hole].r_node;
  544. X        table[sym].r_node = newnode(nch, sym, ch);
  545. X        fix_refcnt(table[sym].r_node);
  546. X    }
  547. X    initcodes();
  548. X}
  549. X
  550. X/*
  551. X * Set a node's refcnt to infinity, so it will never be released.
  552. X */
  553. X
  554. XHidden Procedure
  555. Xfix_refcnt(n)
  556. X    register node n;
  557. X{
  558. X    Assert(n->refcnt > 0);
  559. X    n->refcnt = Maxrefcnt;
  560. X#ifdef MEMTRACE
  561. X    fixmem((ptr) n);
  562. X#endif
  563. X}
  564. X
  565. X/*
  566. X * Add built-in commands to the suggestion tables.
  567. X */
  568. X
  569. XVisible Procedure
  570. Xinitclasses()
  571. X{
  572. X#ifdef USERSUGG
  573. X    register struct table *tp;
  574. X    
  575. X    tp= &table[Rootsymbol];
  576. X    Assert(isinclass(Suggestion, tp->r_class[0]));
  577. X    makesugg(tp->r_class[0]->c_class);
  578. X#endif /* USERSUGG */
  579. X}
  580. X
  581. X#ifdef USERSUGG
  582. X
  583. X/*
  584. X * Extract suggestions from class list.
  585. X */
  586. X
  587. XHidden Procedure
  588. Xmakesugg(cp)
  589. X    classptr cp;
  590. X{
  591. X    struct table *tp;
  592. X    string *rp;
  593. X    char buffer[1000];
  594. X    string bp;
  595. X    string sp;
  596. X    int i;
  597. X    int nch;
  598. X
  599. X    for (; *cp; ++cp) {
  600. X        if (*cp >= TABLEN)
  601. X            continue;
  602. X        Assert(*cp > 0);
  603. X        tp = &table[*cp];
  604. X        rp = tp->r_repr;
  605. X        if (rp[0] && isupper(rp[0][0])) {
  606. X            bp = buffer;
  607. X            nch = nchildren(tp->r_node);
  608. X            for (i = 0; i <= nch; ++i) {
  609. X                if (rp[i]) {
  610. X                    for (sp = rp[i]; *sp >= ' '; ++sp)
  611. X                        *bp++ = *sp;
  612. X                }
  613. X                if (i < nch && !isinclass(Optional, tp->r_class[i]))
  614. X                    *bp++ = '?';
  615. X            }
  616. X            if (bp > buffer) {
  617. X                *bp = 0;
  618. X                addsugg(buffer, (int) *cp);
  619. X            }
  620. X        }
  621. X    }
  622. X}
  623. X
  624. X#endif /* USERSUGG */
  625. X
  626. X/*
  627. X * Set the root of the grammar to the given symbol.  It must exist.
  628. X */
  629. X
  630. XVisible Procedure
  631. Xsetroot(isym) int isym; {    /* symbols defined in tabl.h */
  632. X    register int ich;
  633. X
  634. X    table[Rootsymbol].r_name = table[isym].r_name;
  635. X    for (ich = 0; ich < MAXCHILD; ++ich) {
  636. X        table[Rootsymbol].r_repr[ich] = table[isym].r_repr[ich];
  637. X        table[Rootsymbol].r_class[ich] = table[isym].r_class[ich];
  638. X    }
  639. X    table[Rootsymbol].r_repr[ich] = table[isym].r_repr[ich];
  640. X    table[Rootsymbol].r_node = table[isym].r_node;
  641. X}
  642. X
  643. X/*
  644. X * The remainder of this file is specific for the currently used grammar.
  645. X */
  646. X
  647. X/*
  648. X * Table indicating which symbols are used to form lists of items.
  649. X * Consulted via predicate 'issublist'.
  650. X */
  651. X
  652. XHidden classelem Asublists[] = {
  653. X    Exp_plus, Formal_naming_plus,
  654. X    And, And_kw, Or, Or_kw,
  655. X    0
  656. X};
  657. X
  658. XHidden struct classinfo sublists[] = {Asublists};
  659. X
  660. X
  661. X/*
  662. X * Predicate telling whether two symbols can form lists together.
  663. X * This is important for list whose elements must alternate in some
  664. X * way, as is the case for [KEYWORD [expression] ]*.
  665. X *
  666. X * This code must be in this file, otherwise the names and values
  667. X * of the symbols would have to be made public.
  668. X */
  669. X
  670. XVisible bool
  671. Xsamelevel(sym, sym1)
  672. X    register int sym;
  673. X    register int sym1;
  674. X{
  675. X    register int zzz;
  676. X
  677. X    if (sym1 == sym)
  678. X        return Yes;
  679. X    if (sym1 < sym)
  680. X        zzz = sym, sym = sym1, sym1 = zzz; /* Ensure sym <= sym1 */
  681. X    /* Now always sym < sym1 */
  682. X    return sym == Kw_plus && sym1 == Exp_plus
  683. X        || sym == Formal_kw_plus && sym1 == Formal_naming_plus
  684. X        || sym == And && sym1 == And_kw
  685. X        || sym == Or && sym1 == Or_kw;
  686. X}
  687. X
  688. X
  689. X/*
  690. X * Predicate to tell whether a symbol can form chained lists.
  691. X * By definition, all right-recursive symbols can do so;
  692. X * in addition, those listed in the class 'sublists' can do
  693. X * it, too (this is used for lists formed of alternating members
  694. X * such as KW expr KW ...).
  695. X */
  696. X
  697. XVisible bool
  698. Xissublist(sym)
  699. X    register int sym;
  700. X{
  701. X    register int i;
  702. X    register string repr;
  703. X
  704. X    Assert(sym < TABLEN);
  705. X    if (isinclass(sym, sublists))
  706. X        return Yes;
  707. X    repr = table[sym].r_repr[0];
  708. X    if (Fw_positive(repr))
  709. X        return No;
  710. X    for (i = 0; i < MAXCHILD && table[sym].r_class[i]; ++i)
  711. X        ;
  712. X    if (i <= 0)
  713. X        return No;
  714. X    repr = table[sym].r_repr[i];
  715. X    if (!Fw_zero(repr))
  716. X        return No;
  717. X    return isinclass(sym, table[sym].r_class[i-1]);
  718. X}
  719. X
  720. X/* true iff parent allows a command with a colon (a control-command);
  721. X * this is false for grammar constructs allowing simple-commands
  722. X * following a colon.
  723. X * sym == symbol(tree(parent(ep->focus)))
  724. X */
  725. XVisible bool allows_colon(sym) int sym; {
  726. X    switch (sym) {
  727. X    case Short_comp:
  728. X    case Test_suite:
  729. X    case Short_unit:
  730. X    case Refinement:
  731. X        return No;
  732. X    default:
  733. X        return Yes;
  734. X    }
  735. X    /*NOTREACHED*/
  736. X}
  737. END_OF_FILE
  738.   if test 7451 -ne `wc -c <'abc/bed/e1gram.c'`; then
  739.     echo shar: \"'abc/bed/e1gram.c'\" unpacked with wrong size!
  740.   fi
  741.   # end of 'abc/bed/e1gram.c'
  742. fi
  743. if test -f 'abc/bed/e1ins2.c' -a "${1}" != "-c" ; then 
  744.   echo shar: Will not clobber existing file \"'abc/bed/e1ins2.c'\"
  745. else
  746.   echo shar: Extracting \"'abc/bed/e1ins2.c'\" \(7384 characters\)
  747.   sed "s/^X//" >'abc/bed/e1ins2.c' <<'END_OF_FILE'
  748. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  749. X
  750. X/*
  751. X * B editor -- Insert characters from keyboard.
  752. X */
  753. X
  754. X#include "b.h"
  755. X#include "bedi.h"
  756. X#include "etex.h"
  757. X#include "bobj.h"
  758. X#include "node.h"
  759. X#include "supr.h"
  760. X#include "queu.h"
  761. X#include "gram.h"
  762. X#include "tabl.h"
  763. X
  764. X/*
  765. X * Insert a character.
  766. X */
  767. X
  768. Xextern bool justgoon;
  769. X
  770. XHidden bool quot_in_tag(c, ep) int c; environ *ep; {
  771. X    /* hack to not surround part of name or keyword;
  772. X     * fixes bug 890417
  773. X     */
  774. X    int sym= symbol(tree(ep->focus));
  775. X    
  776. X    return (ep->s2 > 0 &&
  777. X        ((char)c == '\'' || (char)c == '\"')
  778. X        &&
  779. X        (sym == Name || sym == Keyword));
  780. X}
  781. X
  782. XVisible bool
  783. Xins_char(ep, c, alt_c)
  784. X    register environ *ep;
  785. X    int c;
  786. X    int alt_c;
  787. X{
  788. X    auto queue q = Qnil;
  789. X    auto queue qf = Qnil;
  790. X    value copyout();
  791. X    auto string str;
  792. X    char buf[2];
  793. X    int where;
  794. X    bool spwhere;
  795. X
  796. X    if (!justgoon) {
  797. X        higher(ep);
  798. X        shrink(ep);
  799. X        if (strchr("({[`'\"", (char)c)
  800. X            && !ishole(ep)
  801. X            && !quot_in_tag(c, ep)) {
  802. X            /* Surround something.  Wonder what will happen! */
  803. X            qf = (queue) copyout(ep);
  804. X            if (!delbody(ep)) {
  805. X                qrelease(qf);
  806. X                return No;
  807. X            }
  808. X        }
  809. X        fixit(ep);
  810. X    }
  811. X    ep->changed = Yes;
  812. X    buf[0] = c;
  813. X    buf[1] = 0;
  814. X    if (!ins_string(ep, buf, &q, alt_c))
  815. X        return No;
  816. X    if (!emptyqueue(q) || !emptyqueue(qf)) {
  817. X        /* Slight variation on app_queue */
  818. X        if (!emptyqueue(qf) && emptyqueue(q))
  819. X            ritevhole(ep); /* Wizardry.  Why does this work? */
  820. X        spwhere = ep->spflag;
  821. X        ep->spflag = No;
  822. X        where = focoffset(ep);
  823. X        markpath(&ep->focus, 1);
  824. X        ep->spflag = spwhere;
  825. X        if (ep->mode == FHOLE && ep->s2 > 0) {
  826. X            /* If we just caused a suggestion, insert the remains
  827. X               after the suggested text, not after its first character. */
  828. X            str = "";
  829. X            if (!soften(ep, &str, 0)) {
  830. X                ep->mode = ATEND;
  831. X                leftvhole(ep);
  832. X                if (symbol(tree(ep->focus)) == Hole) {
  833. X                    ep->mode = ATBEGIN;
  834. X                    leftvhole(ep);
  835. X                }
  836. X            }
  837. X        }
  838. X        if (!emptyqueue(q)) { /* Re-insert stuff queued by ins_string */
  839. X            if (!ins_queue(ep, &q, &q))
  840. X                return No;
  841. X            where += spwhere;
  842. X            spwhere = No;
  843. X        }
  844. X        if (!emptyqueue(qf)) { /* Re-insert deleted old focus */
  845. X            if (!firstmarked(&ep->focus, 1)) Abort();
  846. X            fixfocus(ep, where);
  847. X            if (!ins_queue(ep, &qf, &qf))
  848. X                return No;
  849. X        }
  850. X        if (!firstmarked(&ep->focus, 1)) Abort();
  851. X        unmkpath(&ep->focus, 1);
  852. X        ep->spflag = No;
  853. X        fixfocus(ep, where + spwhere);
  854. X    }
  855. X    return Yes;
  856. X}
  857. X
  858. X
  859. X/*
  860. X * Insert a newline.
  861. X */
  862. X
  863. XVisible bool
  864. Xins_newline(ep)
  865. X    register environ *ep;
  866. X{
  867. X    register node n;
  868. X    register int sym;
  869. X    auto bool mayindent;
  870. X
  871. X    ep->changed = Yes;
  872. X    if (!fiddle(ep, &mayindent))
  873. X        return No;
  874. X    for (;;) {
  875. X        switch (ep->mode) {
  876. X
  877. X        case VHOLE:
  878. X            ep->mode = ATEND;
  879. X            continue;
  880. X
  881. X        case FHOLE:
  882. X            ep->s2 = lenitem(ep);
  883. X            if (!fix_move(ep))
  884. X                return No;
  885. X            continue;
  886. X
  887. X        case ATEND:
  888. X            if (!joinstring(&ep->focus, "\n", No, 0, mayindent)) {
  889. X                if (!move_on(ep))
  890. X                    return No;
  891. X                continue;
  892. X            }
  893. X            s_downi(ep, 2);
  894. X            s_downi(ep, 1);
  895. X            ep->mode = WHOLE;
  896. X            Assert((sym = symbol(tree(ep->focus))) == Hole || sym == Optional);
  897. X            return Yes;
  898. X
  899. X        case ATBEGIN:
  900. X            n = tree(ep->focus);
  901. X            if (Is_etext(n)) {
  902. X                ep->mode = ATEND;
  903. X                continue;
  904. X            }
  905. X            sym = symbol(n);
  906. X            if (sym == Hole || sym == Optional) {
  907. X                ep->mode = WHOLE;
  908. X                continue;
  909. X            }
  910. X            n = nodecopy(n);
  911. X            if (!fitstring(&ep->focus, "\n", 0)) {
  912. X                if (!down(&ep->focus))
  913. X                    ep->mode = ATEND;
  914. X                noderelease(n);
  915. X                continue;
  916. X            }
  917. X            s_downrite(ep);
  918. X            if (fitnode(&ep->focus, n)) {
  919. X                noderelease(n);
  920. X                s_up(ep);
  921. X                s_down(ep);
  922. X                ep->mode = WHOLE;
  923. X                return Yes;
  924. X            }
  925. X            s_up(ep);
  926. X            s_down(ep);
  927. X            if (!fitnode(&ep->focus, n)) {
  928. X                noderelease(n);
  929. X#ifndef NDEBUG
  930. X                debug("[Sorry, I don't see how to insert a newline here]");
  931. X#endif /* NDEBUG */
  932. X                return No;
  933. X            }
  934. X            noderelease(n);
  935. X            ep->mode = ATBEGIN;
  936. X            return Yes;
  937. X
  938. X        case WHOLE:
  939. X            Assert((sym = symbol(tree(ep->focus))) == Hole || sym == Optional);
  940. X            if (!fitstring(&ep->focus, "\n", 0)) {
  941. X                ep->mode = ATEND;
  942. X                continue;
  943. X            }
  944. X            s_downi(ep, 1);
  945. X            Assert((sym = symbol(tree(ep->focus))) == Hole || sym == Optional);
  946. X            ep->mode = WHOLE;
  947. X            return Yes;
  948. X
  949. X        default:
  950. X            Abort();
  951. X
  952. X        }
  953. X    }
  954. X}
  955. X
  956. X
  957. X/*
  958. X * Refinement for ins_newline() to do the initial processing.
  959. X */
  960. X
  961. XHidden bool
  962. Xfiddle(ep, pmayindent)
  963. X    register environ *ep;
  964. X    bool *pmayindent;
  965. X{
  966. X    register int level;
  967. X    auto string str = "";
  968. X
  969. X    higher(ep);
  970. X    while (rnarrow(ep))
  971. X        ;
  972. X    fixit(ep);
  973. X    VOID soften(ep, &str, 0);
  974. X    higher(ep);
  975. X    *pmayindent = Yes;
  976. X    if (atdedent(ep)) {
  977. X        *pmayindent = No;
  978. X        s_up(ep);
  979. X        level = Level(ep->focus);
  980. X        delfocus(&ep->focus);
  981. X        if (symbol(tree(ep->focus)) == Hole) {
  982. X            if (hackhack(ep))
  983. X                return Yes;
  984. X        }
  985. X        while (Level(ep->focus) >= level) {
  986. X            if (!nexthole(ep)) {
  987. X                ep->mode = ATEND;
  988. X                break;
  989. X            }
  990. X        }
  991. X        if (ep->mode == ATEND) {
  992. X            leftvhole(ep);
  993. X            ep->mode = ATEND;
  994. X            while (Level(ep->focus) >= level) {
  995. X                if (!up(&ep->focus))
  996. X                    return No;
  997. X            }
  998. X        }
  999. X        return Yes;
  1000. X    }
  1001. X    else if (atrealhole(ep))
  1002. X        return No;
  1003. X    return Yes;
  1004. X}
  1005. X
  1006. X
  1007. X/*
  1008. X * "Hier komen de houthakkers."
  1009. X *
  1010. X * Incredibly ugly hack to delete a join whose second child begins with \n,
  1011. X * such as a suite after an IF, FOR or WHILE or  unit heading.
  1012. X * Inspects the parent node.
  1013. X * If this has rp[0] ands rp[1] both empty, replace it by its first child.
  1014. X * (caller assures this makes sense).
  1015. X * Return Yes if this happened AND rp[1] contained a \t.
  1016. X */
  1017. X
  1018. XHidden Procedure
  1019. Xhackhack(ep)
  1020. X    environ *ep;
  1021. X{
  1022. X    node n;
  1023. X    int ich = ichild(ep->focus);
  1024. X    string *rp;
  1025. X
  1026. X    if (!up(&ep->focus))
  1027. X        return No;
  1028. X    higher(ep);
  1029. X    rp = noderepr(tree(ep->focus));
  1030. X    if (!Fw_zero(rp[0]) || !Fw_zero(rp[1])) {
  1031. X        s_downi(ep, ich);
  1032. X        return No;
  1033. X    }
  1034. X    n = nodecopy(firstchild(tree(ep->focus)));
  1035. X    delfocus(&ep->focus);
  1036. X    treereplace(&ep->focus, n);
  1037. X    ep->mode = ATEND;
  1038. X    return rp[1] && rp[1][0] == '\t';
  1039. X}
  1040. X    
  1041. X
  1042. X/*
  1043. X * Refinement for fiddle() to find out whether we are at a possible
  1044. X * decrease-indentation position.
  1045. X */
  1046. X
  1047. XHidden bool
  1048. Xatdedent(ep)
  1049. X    register environ *ep;
  1050. X{
  1051. X    register path pa;
  1052. X    register node npa;
  1053. X    register int i;
  1054. X    register int sym = symbol(tree(ep->focus));
  1055. X
  1056. X    if (sym != Hole && sym != Optional)
  1057. X        return No;
  1058. X    if (ichild(ep->focus) != 1)
  1059. X        return No;
  1060. X    switch (ep->mode) {
  1061. X    case FHOLE:
  1062. X        if (ep->s1 != 1 || ep->s2 != 0)
  1063. X            return No;
  1064. X        break;
  1065. X    case ATBEGIN:
  1066. X    case WHOLE:
  1067. X    case SUBSET:
  1068. X        break;
  1069. X    default:
  1070. X        return No;
  1071. X    }
  1072. X    pa = parent(ep->focus);
  1073. X    if (!pa)
  1074. X        return No;
  1075. X    npa = tree(pa);
  1076. X    if (fwidth(noderepr(npa)[0]) >= 0)
  1077. X        return No;
  1078. X    for (i = nchildren(npa); i > 1; --i) {
  1079. X        sym = symbol(child(npa, i));
  1080. X        if (sym != Hole && sym != Optional)
  1081. X            return No;
  1082. X    }
  1083. X    return Yes; /* Sigh! */
  1084. X}
  1085. X
  1086. X/*
  1087. X * Refinement for ins_node() and fiddle() to find the next hole,
  1088. X * skipping blank space only.
  1089. X */
  1090. X
  1091. XHidden bool
  1092. Xnexthole(ep)
  1093. X    register environ *ep;
  1094. X{
  1095. X    register node n;
  1096. X    register int ich;
  1097. X    register string repr;
  1098. X
  1099. X    do {
  1100. X        ich = ichild(ep->focus);
  1101. X        if (!up(&ep->focus))
  1102. X            return No;
  1103. X        higher(ep);
  1104. X        n = tree(ep->focus);
  1105. X        repr = noderepr(n)[ich];
  1106. X        if (!Fw_zero(repr) && !allspaces(repr))
  1107. X            return No;
  1108. X    } while (ich >= nchildren(n));
  1109. X    s_downi(ep, ich+1);
  1110. X    return Yes;
  1111. X}
  1112. X
  1113. XHidden int atrealhole(ep) environ *ep; {
  1114. X    node n;
  1115. X    int i;
  1116. X    
  1117. X    n= tree(ep->focus);
  1118. X    
  1119. X    if (symbol(n) == Hole)
  1120. X        return Yes;
  1121. X    if (ep->mode == FHOLE
  1122. X        && strlen(noderepr(n)[i= ep->s1/2]) <= ep->s2) {
  1123. X        if (i < nchildren(n)) {
  1124. X            n= child(n, i+1);
  1125. X            if (Is_etext(n))
  1126. X                return No;
  1127. X            if (symbol(n) == Hole
  1128. X                || symbol(n) == Exp_plus 
  1129. X                   && symbol(child(n, 1)) == Hole
  1130. X               )
  1131. X                return Yes;
  1132. X        }
  1133. X    }
  1134. X    return No;
  1135. X}
  1136. END_OF_FILE
  1137.   if test 7384 -ne `wc -c <'abc/bed/e1ins2.c'`; then
  1138.     echo shar: \"'abc/bed/e1ins2.c'\" unpacked with wrong size!
  1139.   fi
  1140.   # end of 'abc/bed/e1ins2.c'
  1141. fi
  1142. if test -f 'abc/bint1/i1nug.c' -a "${1}" != "-c" ; then 
  1143.   echo shar: Will not clobber existing file \"'abc/bint1/i1nug.c'\"
  1144. else
  1145.   echo shar: Extracting \"'abc/bint1/i1nug.c'\" \(4268 characters\)
  1146.   sed "s/^X//" >'abc/bint1/i1nug.c' <<'END_OF_FILE'
  1147. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1988. */
  1148. X
  1149. X#include "b.h"
  1150. X#include "feat.h"     /* for EXT_RANGE */
  1151. X#include "bobj.h"
  1152. X#include "i1num.h"
  1153. X
  1154. X
  1155. X/*
  1156. X * Routines for greatest common divisor calculation
  1157. X * "Binary gcd algorithm"
  1158. X *
  1159. X * Assumptions about built-in arithmetic:
  1160. X * x>>1 == x/2  (if x >= 0)
  1161. X * 1<<k == 2**k (if it fits in a word)
  1162. X */
  1163. X
  1164. X/* Single-precision gcd for integers > 0 */
  1165. X
  1166. XHidden digit dig_gcd(u, v) register digit u, v; {
  1167. X    register digit temp;
  1168. X    register int k = 0;
  1169. X
  1170. X    if (u <= 0 || v <= 0) syserr(MESS(900, "dig_gcd of number(s) <= 0"));
  1171. X
  1172. X    while (Even(u) && Even(v)) ++k, u >>= 1, v >>= 1;
  1173. X
  1174. X    /* u or v is odd */
  1175. X    
  1176. X    while (Even(u)) u >>= 1;
  1177. X
  1178. X    while (v) {
  1179. X        /* u is odd */
  1180. X        
  1181. X        while (Even(v)) v >>= 1;
  1182. X        
  1183. X        /* u and v odd */
  1184. X        
  1185. X        if (u > v) { temp = v; v = u - v; u = temp; }
  1186. X        else v = v - u;
  1187. X        
  1188. X        /* u is odd and v even */
  1189. X    }
  1190. X
  1191. X    return u * (1<<k);
  1192. X}
  1193. X
  1194. XVisible integer int_half(v) integer v; {
  1195. X    register int i;
  1196. X    register long carry;
  1197. X
  1198. X    if (IsSmallInt(v))
  1199. X        return (integer) MkSmallInt(SmallIntVal(v) / 2);
  1200. X
  1201. X    if (Msd(v) < 0) {
  1202. X        i = Length(v)-2;
  1203. X        if (i < 0) {
  1204. X            Release(v);
  1205. X            return int_0;
  1206. X        }
  1207. X        carry = BASE;
  1208. X    }
  1209. X    else {
  1210. X        carry = 0;
  1211. X        i = Length(v)-1;
  1212. X    }
  1213. X
  1214. X    if (Refcnt(v) > 1) uniql((value *) &v);
  1215. X
  1216. X    for (; i >= 0; --i) {
  1217. X        carry += Digit(v,i);
  1218. X        Digit(v,i) = carry/2;
  1219. X        carry = carry&1 ? BASE : 0;
  1220. X    }
  1221. X
  1222. X    return int_canon(v);
  1223. X}
  1224. X
  1225. X/*
  1226. X * u or v is a smallint
  1227. X * call int_mod() to make the other smallint too
  1228. X * call dig_gcd()
  1229. X * multiply with twopow
  1230. X */
  1231. XHidden integer gcd_small(u, v, twopow) integer u, v, twopow; {
  1232. X    integer g;
  1233. X
  1234. X    if (!IsSmallInt(u) && !IsSmallInt(v))
  1235. X        syserr(MESS(901, "gcd_small of numbers > smallint"));
  1236. X
  1237. X    if (!IsSmallInt(v))
  1238. X        { g = u; u = v; v = g; }    
  1239. X    if (v == int_0)
  1240. X        g = (integer) Copy(u);
  1241. X    else if (v == int_1)
  1242. X        g = int_1;
  1243. X    else {
  1244. X        u= IsSmallInt(u) ? (integer) Copy(u) : int_mod(u, v);
  1245. X        if (u == int_0)
  1246. X            g = (integer) Copy(v);
  1247. X        else if (u == int_1)
  1248. X            g = int_1;
  1249. X        else  g= (integer) MkSmallInt(
  1250. X            dig_gcd(SmallIntVal(u), SmallIntVal(v)));
  1251. X        Release(u);
  1252. X    }
  1253. X
  1254. X    g = int_prod(u= g, twopow);
  1255. X    Release(u);
  1256. X
  1257. X    if (interrupted && g == int_0)
  1258. X        { Release(g); g = int_1; }
  1259. X    return g;
  1260. X}
  1261. X
  1262. XHidden int lwb_lendiff = (3 / tenlogBASE) + 1;
  1263. X
  1264. X#define Modgcd(u, v) (Length(u) - Length(v) > lwb_lendiff)
  1265. X
  1266. X/* Multi-precision gcd of integers > 0 */
  1267. X
  1268. XVisible integer int_gcd(u1, v1) integer u1, v1; {
  1269. X    integer t, u, v;
  1270. X    integer twopow= int_1;
  1271. X    long k = 0;
  1272. X
  1273. X    if (Msd(u1) <= 0 || Msd(v1) <= 0)
  1274. X        syserr(MESS(902, "gcd of number(s) <= 0"));
  1275. X    
  1276. X    if (IsSmallInt(u1) || IsSmallInt(v1))
  1277. X        return gcd_small(u1, v1, int_1);
  1278. X
  1279. X    u = (integer) Copy(u1);
  1280. X    v = (integer) Copy(v1);
  1281. X
  1282. X    if (int_comp(u, v) < 0)
  1283. X        { t = u; u = v; v = t; }
  1284. X
  1285. X    while (Modgcd(u, v)) {
  1286. X        t = int_mod(u, v); /* u > v > t >= 0 */
  1287. X        Release(u);
  1288. X        u = v;
  1289. X        v = t;
  1290. X        if (IsSmallInt(v))
  1291. X            goto smallint;
  1292. X    }
  1293. X    
  1294. X
  1295. X    while (Even(Lsd(u)) && Even(Lsd(v))) {
  1296. X        u = int_half(u);
  1297. X        v = int_half(v);
  1298. X        if (++k < 0) {
  1299. X            /*It's a number we can't cope with,
  1300. X              with too many common factors 2.
  1301. X              Though the user can't help it,
  1302. X              the least we can do is to allow
  1303. X              continuation of the session.
  1304. X            */
  1305. X            interr(MESS(903, "exceptionally large rational number"));
  1306. X            k = 0;
  1307. X        }
  1308. X    }
  1309. X    
  1310. X    t= mk_int((double) k);
  1311. X    twopow= (integer) power((value) int_2, (value) t);
  1312. X    Release(t);
  1313. X    
  1314. X    if (IsSmallInt(v))
  1315. X        goto smallint;
  1316. X    
  1317. X    while (Even(Lsd(u)))
  1318. X        u = int_half(u);
  1319. X        
  1320. X    if (IsSmallInt(u))
  1321. X        goto smallint;
  1322. X
  1323. X    /* u is odd */
  1324. X    
  1325. X    while (v != int_0) {
  1326. X        
  1327. X        while (Even(Lsd(v)))
  1328. X            v = int_half(v);
  1329. X            
  1330. X        if (IsSmallInt(v))
  1331. X            goto smallint;
  1332. X
  1333. X        /* u and v are odd */
  1334. X        
  1335. X        if (int_comp(u, v) > 0) {
  1336. X            if (Modgcd(u, v))
  1337. X                t = int_mod(u, v); /* u>v>t>=0 */
  1338. X                /* t can be odd */
  1339. X            else
  1340. X                t = int_diff(u, v);
  1341. X                /* t is even */
  1342. X            Release(u);
  1343. X            u = v;
  1344. X            v = t;
  1345. X        }
  1346. X        else {
  1347. X            if (Modgcd(v, u))
  1348. X                t = int_mod(v, u); /* v>u>t>=0 */
  1349. X                /* t can be odd */
  1350. X            else
  1351. X                t = int_diff(v, u);
  1352. X                /* t is even */
  1353. X            Release(v);
  1354. X            v = t;
  1355. X        }
  1356. X        /* u is odd
  1357. X         * v can be odd too, but in that case is the new value
  1358. X         * smaller than the old one
  1359. X         */
  1360. X    }
  1361. X            
  1362. X    Release(v);
  1363. X
  1364. X    u = int_prod(v = u, twopow);
  1365. X    Release(v); Release(twopow);
  1366. X
  1367. X    if (interrupted && u == int_0)
  1368. X        { Release(u); u = int_1; }
  1369. X    return u;
  1370. X
  1371. Xsmallint:
  1372. X    t = gcd_small(u, v, twopow);
  1373. X    Release(u); Release(v); Release(twopow);
  1374. X    
  1375. X    return t;
  1376. X}
  1377. END_OF_FILE
  1378.   if test 4268 -ne `wc -c <'abc/bint1/i1nug.c'`; then
  1379.     echo shar: \"'abc/bint1/i1nug.c'\" unpacked with wrong size!
  1380.   fi
  1381.   # end of 'abc/bint1/i1nug.c'
  1382. fi
  1383. if test -f 'abc/bint3/i3fpr.c' -a "${1}" != "-c" ; then 
  1384.   echo shar: Will not clobber existing file \"'abc/bint3/i3fpr.c'\"
  1385. else
  1386.   echo shar: Extracting \"'abc/bint3/i3fpr.c'\" \(7591 characters\)
  1387.   sed "s/^X//" >'abc/bint3/i3fpr.c' <<'END_OF_FILE'
  1388. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  1389. X
  1390. X/* B formula/predicate invocation */
  1391. X#include "b.h"
  1392. X#include "bint.h"
  1393. X#include "feat.h"
  1394. X#include "bobj.h"
  1395. X#include "i0err.h"
  1396. X#include "b0lan.h"
  1397. X#include "i1num.h"
  1398. X#include "i2par.h"
  1399. X#include "i3sou.h"
  1400. X
  1401. X#define Other 0
  1402. X#define Nume 1        /* e.g. number1 + number2 */
  1403. X#define Adjust 5    /* e.g. v >< number2 */
  1404. X#define Numpair 2    /* e.g. angle(x,y) has numeric pair */
  1405. X#define Nonzero 3    /* e.g. 0 sin x undefined */
  1406. X#define Textual 4    /* e.g. stripped t */
  1407. X
  1408. X#define Xact 0
  1409. X#define In 1
  1410. X#define Not_in 2
  1411. X
  1412. X/*
  1413. X * Table defining all predefined functions (but not propositions).
  1414. X */
  1415. X
  1416. Xstruct funtab {
  1417. X    string f_name; literal f_adic, f_kind;
  1418. X    value    (*f_fun)();
  1419. X    char /* bool */ f_extended;
  1420. X} funtab[] = {
  1421. X    {S_ABOUT,    Mfd, Nume, approximate},
  1422. X    {S_PLUS,    Mfd, Nume, copy},
  1423. X    {S_PLUS,    Dfd, Nume, sum},
  1424. X    {S_MINUS,    Mfd, Nume, negated},
  1425. X    {S_MINUS,    Dfd, Nume, diff},
  1426. X    {S_NUMERATOR,    Mfd, Nume, numerator},
  1427. X    {S_DENOMINATOR,    Mfd, Nume, denominator},
  1428. X
  1429. X    {S_TIMES,    Dfd, Nume, prod},
  1430. X    {S_OVER,    Dfd, Nume, quot},
  1431. X    {S_POWER,    Dfd, Nume, power},
  1432. X
  1433. X    {S_BEHEAD,    Dfd, Other, behead},
  1434. X    {S_CURTAIL,    Dfd, Other, curtail},
  1435. X    {S_JOIN,    Dfd, Other, concat},
  1436. X    {S_REPEAT,    Dfd, Other, repeat},
  1437. X    {S_LEFT_ADJUST,    Dfd, Adjust, adjleft},
  1438. X    {S_CENTER,    Dfd, Adjust, centre},
  1439. X    {S_RIGHT_ADJUST, Dfd, Adjust, adjright},
  1440. X
  1441. X    {S_NUMBER,    Mfd, Other, size},
  1442. X    {S_NUMBER,    Dfd, Other, size2},
  1443. X
  1444. X    {F_pi,        Zfd, Other, pi},
  1445. X    {F_e,        Zfd, Other, e},
  1446. X    {F_now,        Zfd, Other, nowisthetime},
  1447. X    
  1448. X    {F_abs,        Mfd, Nume, absval},
  1449. X    {F_sign,       Mfd, Nume, signum},
  1450. X    {F_floor,      Mfd, Nume, floorf},
  1451. X    {F_ceiling,    Mfd, Nume, ceilf},
  1452. X    {F_round,      Mfd, Nume, round1},
  1453. X    {F_round,      Dfd, Nume, round2},
  1454. X    {F_mod,        Dfd, Nume, mod},
  1455. X    {F_root,       Mfd, Nume, root1},
  1456. X    {F_root,       Dfd, Nume, root2},
  1457. X    {F_random,     Zfd, Nume, random},
  1458. X    
  1459. X    {F_exactly,    Mfd, Nume, exactly},
  1460. X
  1461. X    {F_sin,        Mfd, Nume, sin1},
  1462. X    {F_cos,     Mfd, Nume, cos1},
  1463. X    {F_tan,        Mfd, Nume, tan1},
  1464. X    {F_arctan,    Mfd, Nume, arctan1},
  1465. X    {F_angle,    Mfd, Numpair, angle1},
  1466. X    {F_radius,    Mfd, Numpair, radius},
  1467. X
  1468. X    {F_sin,        Dfd, Nonzero, sin2},
  1469. X    {F_cos,     Dfd, Nonzero, cos2},
  1470. X    {F_tan,     Dfd, Nonzero, tan2},
  1471. X    {F_arctan,    Dfd, Nume, arctan2},
  1472. X    {F_angle,    Dfd, Numpair, angle2},
  1473. X    
  1474. X    {F_exp,        Mfd, Nume, exp1},
  1475. X    {F_log,        Mfd, Nume, log1},
  1476. X    {F_log,        Dfd, Nume, log2},
  1477. X
  1478. X    {F_stripped,    Mfd, Textual, stripped},
  1479. X    {F_split,    Mfd, Textual, split},
  1480. X    {F_upper,    Mfd, Textual, upper},
  1481. X    {F_lower,    Mfd, Textual, lower},
  1482. X
  1483. X    {F_keys,    Mfd, Other, keys},
  1484. X#ifdef B_COMPAT
  1485. X    {F_thof,     Dfd, Other, th_of},
  1486. X#endif
  1487. X    {F_item,     Dfd, Other, item},
  1488. X    {F_min,      Mfd, Other, min1},
  1489. X    {F_min,      Dfd, Other, min2},
  1490. X    {F_max,      Mfd, Other, max1},
  1491. X    {F_max,      Dfd, Other, max2},
  1492. X    {F_choice,     Mfd, Other, choice},
  1493. X    {"",         Dfd, Other, NULL} /*sentinel*/
  1494. X};
  1495. X
  1496. XVisible Procedure initfpr() {
  1497. X    struct funtab *fp; value r, f, pname;
  1498. X
  1499. X    for (fp= funtab; *(fp->f_name) != '\0'; ++fp) {
  1500. X        /* Define function */
  1501. X        r= mk_text(fp->f_name);
  1502. X        f= mk_fun(fp->f_adic, (intlet) (fp-funtab), NilTree, Yes);
  1503. X        pname= permkey(r, fp->f_adic);
  1504. X        def_unit(pname, f);
  1505. X        release(f); release(r); release(pname);
  1506. X    }
  1507. X
  1508. X    defprd(P_exact, Mpd, Xact);
  1509. X    defprd(P_in, Dpd, In);
  1510. X    defprd(P_notin, Dpd, Not_in);
  1511. X}
  1512. X
  1513. XHidden Procedure defprd(repr, adic, pre) string repr; literal adic; intlet pre; {
  1514. X    value r= mk_text(repr), p= mk_prd(adic, pre, NilTree, Yes), pname;
  1515. X    pname= permkey(r, adic);
  1516. X    def_unit(pname, p);
  1517. X    release(p); release(r); release(pname);
  1518. X}
  1519. X
  1520. X/* returns if a given test/yield exists *without faults* */
  1521. XHidden bool is_funprd(t, f, adicity, func) value t, *f; literal adicity; bool func; {
  1522. X    value *aa;
  1523. X    *f= Vnil;
  1524. X    if (!Valid(t) || !Is_text(t))
  1525. X        return No;
  1526. X    if (!is_unit(t, adicity, &aa)) return No;
  1527. X    if (still_ok) {
  1528. X        if (func) {
  1529. X            if (!Is_function(*aa)) return No;
  1530. X        } else {
  1531. X            if (!Is_predicate(*aa)) return No;
  1532. X        }
  1533. X        *f= *aa; return Yes;
  1534. X    } else return No;
  1535. X}
  1536. X
  1537. XVisible bool is_zerfun(t, f) value t, *f; {
  1538. X    return is_funprd(t, f, Zfd, Yes);
  1539. X}
  1540. X
  1541. XVisible bool is_monfun(t, f) value t, *f; {
  1542. X    return is_funprd(t, f, Mfd, Yes);
  1543. X}
  1544. X
  1545. XVisible bool is_dyafun(t, f) value t, *f; {
  1546. X    return is_funprd(t, f, Dfd, Yes);
  1547. X}
  1548. X
  1549. XVisible bool is_zerprd(t, p) value t, *p; {
  1550. X    return is_funprd(t, p, Zpd, No);
  1551. X}
  1552. X
  1553. XVisible bool is_monprd(t, p) value t, *p; {
  1554. X    return is_funprd(t, p, Mpd, No);
  1555. X}
  1556. X
  1557. XVisible bool is_dyaprd(t, p) value t, *p; {
  1558. X    return is_funprd(t, p, Dpd, No);
  1559. X}
  1560. X
  1561. X/* the following is a boolean function or predicate for the static type check,
  1562. X * telling whether a certain name was overwritten by a how-to
  1563. X * definition of the user.
  1564. X * unlike the above one's this one doesn't load the definition if it
  1565. X * is not in memory.
  1566. X */
  1567. X
  1568. XVisible bool is_udfpr(name, type) value name; literal type; {
  1569. X    value pname;
  1570. X    bool res;
  1571. X    value *aa;
  1572. X    
  1573. X    pname= permkey(name, type);
  1574. X    res= p_exists(pname, &aa);
  1575. X    release(pname);
  1576. X    return res;
  1577. X}
  1578. X
  1579. X#define Is_numpair(v) (Is_compound(v) && Nfields(v) == 2 && \
  1580. X            Is_number(*Field(v, 0)) && Is_number(*Field(v, 1)))
  1581. X
  1582. XVisible value pre_fun(nd1, pre, nd2) value nd1, nd2; intlet pre; {
  1583. X    struct funtab *fp= &funtab[pre];
  1584. X    literal adic= fp->f_adic, kind= fp->f_kind;
  1585. X    value name= mk_text(fp->f_name);
  1586. X    switch (adic) {
  1587. X    case Dfd:
  1588. X        if ((kind==Nume||kind==Numpair||kind==Nonzero) && !Is_number(nd1)) {
  1589. X    interrV(MESS(3200, "in x %s y, x is not a number"), name);
  1590. X            release(name);
  1591. X            return Vnil;
  1592. X        }
  1593. X        else if ((kind==Nume||kind==Nonzero||kind==Adjust)
  1594. X             && !Is_number(nd2)) {
  1595. X    interrV(MESS(3201, "in x %s y, y is not a number"), name);
  1596. X            release(name);
  1597. X            return Vnil;
  1598. X        }
  1599. X        else if (kind==Numpair && !Is_numpair(nd2)) {
  1600. X    interrV(MESS(3202, "in x %s y, y is not a compound of two numbers"), name);
  1601. X            release(name);
  1602. X            return Vnil;
  1603. X        } else if (kind==Nonzero && numcomp(nd1, zero)==0) {
  1604. X    interrV(MESS(3203,"in c %s x, c is zero"), name);
  1605. X            release(name);
  1606. X            return Vnil;
  1607. X        }
  1608. X        break;
  1609. X    case Mfd:
  1610. X        switch (kind) {
  1611. X        case Nume:
  1612. X            if (!Is_number(nd2)) {
  1613. X    interrV(MESS(3204, "in %s x, x is not a number"), name);
  1614. X                release(name);
  1615. X                return Vnil;
  1616. X            }
  1617. X            break;
  1618. X        case Numpair:
  1619. X            if (!Is_numpair(nd2)) {
  1620. X    interrV(MESS(3205, "in %s y, y is not a compound of two numbers"), name);
  1621. X                release(name);
  1622. X                return Vnil;
  1623. X            }
  1624. X            break;
  1625. X        case Textual:
  1626. X            if (!Is_text(nd2)) {
  1627. X    interrV(MESS(3206, "in %s t, t is not a text"), name);
  1628. X                release(name);
  1629. X                return Vnil;
  1630. X            }
  1631. X            break;
  1632. X        }
  1633. X        break;
  1634. X    }
  1635. X    release(name);
  1636. X    
  1637. X    switch (adic) {
  1638. X    case Zfd: return((*fp->f_fun)());
  1639. X    case Mfd:
  1640. X        if (fp->f_kind == Numpair)
  1641. X            return((*fp->f_fun)(*Field(nd2,0), *Field(nd2,1)));
  1642. X        else
  1643. X            return((*fp->f_fun)(nd2));
  1644. X    case Dfd:
  1645. X        if (fp->f_kind == Numpair)
  1646. X            return((*fp->f_fun)(nd1, *Field(nd2,0), *Field(nd2,1)));
  1647. X        else
  1648. X            return((*fp->f_fun)(nd1, nd2));
  1649. X    default: syserr(MESS(3207, "pre-defined fpr wrong"));
  1650. X         /*NOTREACHED*/
  1651. X    }
  1652. X}
  1653. X
  1654. XVisible bool pre_prop(nd1, pre, nd2) value nd1, nd2; intlet pre; {
  1655. X    switch (pre) {
  1656. X    case Xact:
  1657. X        if (!Is_number(nd2)) {
  1658. X        interr(MESS(3208, "in the test exact x, x is not a number"));
  1659. X            return No;
  1660. X        }
  1661. X        return exact(nd2);
  1662. X    case In:
  1663. X        if (!Is_tlt(nd2)) {
  1664. Xinterr(MESS(3209, "in the test e in t, t is not a text list or table"));
  1665. X            return No;
  1666. X        }
  1667. X        if (Is_text(nd2) && (!character(nd1))) {
  1668. X            interr(
  1669. XMESS(3210, "in the test e in t, t is a text, but e is not a character")
  1670. X            );
  1671. X            return No;
  1672. X        }
  1673. X        return in(nd1, nd2);
  1674. X    case Not_in:
  1675. X        if (!Is_tlt(nd2)) {
  1676. X            interr(
  1677. XMESS(3211, "in the test e not.in t, t is not a text list or table"));
  1678. X            return No;
  1679. X        }
  1680. X        if (Is_text(nd2) && (!character(nd1))) {
  1681. X            interr(
  1682. XMESS(3212, "in the test e not.in t, t is a text, but e isn't a character")
  1683. X            );
  1684. X            return No;
  1685. X        }
  1686. X        return !in(nd1, nd2);
  1687. X    default:
  1688. X        syserr(MESS(3213, "predicate not covered by proposition"));
  1689. X        /*NOTREACHED*/
  1690. X    }
  1691. X}
  1692. END_OF_FILE
  1693.   if test 7591 -ne `wc -c <'abc/bint3/i3fpr.c'`; then
  1694.     echo shar: \"'abc/bint3/i3fpr.c'\" unpacked with wrong size!
  1695.   fi
  1696.   # end of 'abc/bint3/i3fpr.c'
  1697. fi
  1698. if test -f 'abc/ihdrs/i2nod.h' -a "${1}" != "-c" ; then 
  1699.   echo shar: Will not clobber existing file \"'abc/ihdrs/i2nod.h'\"
  1700. else
  1701.   echo shar: Extracting \"'abc/ihdrs/i2nod.h'\" \(7578 characters\)
  1702.   sed "s/^X//" >'abc/ihdrs/i2nod.h' <<'END_OF_FILE'
  1703. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  1704. X
  1705. X/* Units */
  1706. X
  1707. Xtypedef intlet typenode;
  1708. X
  1709. X#define _Nodetype(len)     ((len) & 0377)
  1710. X#define _Nbranches(len)  ((len) >> 8)
  1711. X#define Nodetype(v)   _Nodetype((v)->len)
  1712. X#define Nbranches(v)  _Nbranches((v)->len)
  1713. X#define Branch(v, n)  ((Ats(v)+(n)))
  1714. X
  1715. X#define Unit(n)       (n>=HOW_TO && n<=REFINEMENT)
  1716. X#ifndef GFX
  1717. X#define Command(n)    (n>=SUITE && n<=EXTENDED_COMMAND)
  1718. X#else
  1719. X#define Command(n)    (n>=SUITE && n<=EXTENDED_COMMAND || \
  1720. X               n>=GFX_first && n<=GFX_last)
  1721. X#endif
  1722. X#define Expression(n) ((n>=TAG && n<=TAB_DIS)||(n>=TAGformal && n<=TAGzerprd))
  1723. X#define Comparison(n) (n>=LESS_THAN && n<=UNEQUAL)
  1724. X
  1725. X#define HOW_TO            0
  1726. X#define YIELD            1
  1727. X#define TEST            2
  1728. X#define REFINEMENT        3
  1729. X
  1730. X/* Commands */
  1731. X
  1732. X#define SUITE            4
  1733. X#define PUT            5
  1734. X#define INSERT            6
  1735. X#define REMOVE            7
  1736. X#define SET_RANDOM        8
  1737. X#define DELETE            9
  1738. X#define CHECK            10
  1739. X#define SHARE            11
  1740. X#define PASS            12
  1741. X
  1742. X#define WRITE            13 /* collateral expression */
  1743. X#define WRITE1            14 /* single expression */
  1744. X#define READ            15
  1745. X#define READ_RAW        16
  1746. X
  1747. X#define IF            17
  1748. X#define WHILE            18
  1749. X#define FOR            19
  1750. X
  1751. X#define SELECT            20
  1752. X#define TEST_SUITE        21
  1753. X#define ELSE            22
  1754. X
  1755. X#define QUIT            23
  1756. X#define RETURN            24
  1757. X#define REPORT            25
  1758. X#define SUCCEED         26
  1759. X#define FAIL            27
  1760. X
  1761. X#define USER_COMMAND        28
  1762. X#define EXTENDED_COMMAND    29
  1763. X
  1764. X/* Expressions, targets, tests */
  1765. X
  1766. X#define TAG            30
  1767. X#define COMPOUND        31
  1768. X
  1769. X/* Expressions, targets */
  1770. X
  1771. X#define COLLATERAL        32
  1772. X#define SELECTION        33
  1773. X#define BEHEAD            34
  1774. X#define CURTAIL         35
  1775. X
  1776. X/* Expressions, tests */
  1777. X
  1778. X#define UNPARSED        36
  1779. X
  1780. X/* Expressions */
  1781. X
  1782. X#define MONF            37
  1783. X#define DYAF            38
  1784. X#define NUMBER            39
  1785. X#define TEXT_DIS        40
  1786. X#define TEXT_LIT        41
  1787. X#define TEXT_CONV        42
  1788. X#define ELT_DIS         43
  1789. X#define LIST_DIS        44
  1790. X#define RANGE_BNDS        45
  1791. X#define TAB_DIS         46
  1792. X
  1793. X/* Tests */
  1794. X
  1795. X#define AND            47
  1796. X#define OR            48
  1797. X#define NOT            49
  1798. X#define SOME_IN         50
  1799. X#define EACH_IN         51
  1800. X#define NO_IN            52
  1801. X#define MONPRD            53
  1802. X#define DYAPRD            54
  1803. X#define LESS_THAN        55
  1804. X#define AT_MOST         56
  1805. X#define GREATER_THAN        57
  1806. X#define AT_LEAST        58
  1807. X#define EQUAL            59
  1808. X#define UNEQUAL         60
  1809. X#define Nonode            61
  1810. X
  1811. X#define TAGformal        62
  1812. X#define TAGlocal        63
  1813. X#define TAGglobal        64
  1814. X#define TAGrefinement        65
  1815. X#define TAGzerfun        66
  1816. X#define TAGzerprd        67
  1817. X
  1818. X#define ACTUAL            68
  1819. X#define FORMAL            69
  1820. X
  1821. X#ifndef GFX
  1822. X
  1823. X#define COLON_NODE        70
  1824. X    /* special node on top of suite inside WHILE or TEST_SUITE */
  1825. X#define NTYPES            71
  1826. X    /* number of nodetypes */
  1827. X
  1828. X#else    /* GFX */
  1829. X
  1830. X#define SPACE            70
  1831. X#define LINE            71
  1832. X#define CLEAR            72
  1833. X#define GFX_first        SPACE
  1834. X#define GFX_last        CLEAR
  1835. X
  1836. X#define COLON_NODE        73
  1837. X#define NTYPES            74
  1838. X
  1839. X#endif    /* GFX */
  1840. X
  1841. Xvalue node1();
  1842. Xvalue node2();
  1843. Xvalue node3();
  1844. Xvalue node4();
  1845. Xvalue node5();
  1846. Xvalue node6();
  1847. Xvalue node8();
  1848. Xvalue node9();
  1849. Xtypenode nodetype();
  1850. X/* Procedure display(); */
  1851. X/* Procedure fix_nodes(); */
  1852. X
  1853. X#define First_fieldnr    0
  1854. X
  1855. X#define UNIT_NAME    First_fieldnr
  1856. X#define HOW_FORMALS    First_fieldnr + 1    /* HOW'TO */
  1857. X#define HOW_COMMENT    First_fieldnr + 2
  1858. X#define HOW_SUITE    First_fieldnr + 3
  1859. X#define HOW_REFINEMENT    First_fieldnr + 4
  1860. X#define HOW_R_NAMES    First_fieldnr + 5
  1861. X#define HOW_NLOCALS    First_fieldnr + 6
  1862. X#define FPR_ADICITY    First_fieldnr + 1    /* YIELD, TEST */
  1863. X#define FPR_FORMALS    First_fieldnr + 2
  1864. X#define FPR_COMMENT    First_fieldnr + 3
  1865. X#define FPR_SUITE    First_fieldnr + 4
  1866. X#define FPR_REFINEMENT    First_fieldnr + 5
  1867. X#define FPR_R_NAMES    First_fieldnr + 6
  1868. X#define FPR_NLOCALS    First_fieldnr + 7
  1869. X
  1870. X#define FML_KEYW    First_fieldnr        /* FORMALS HOW'TO */
  1871. X#define FML_TAG     First_fieldnr + 1
  1872. X#define FML_NEXT    First_fieldnr + 2
  1873. X
  1874. X#define SUI_LINO    First_fieldnr        /* SUITE */
  1875. X#define SUI_CMD     First_fieldnr + 1
  1876. X#define SUI_COMMENT    First_fieldnr + 2
  1877. X#define SUI_NEXT    First_fieldnr + 3
  1878. X#define REF_NAME    First_fieldnr        /* REFINEMENT */
  1879. X#define REF_COMMENT    First_fieldnr + 1
  1880. X#define REF_SUITE    First_fieldnr + 2
  1881. X#define REF_NEXT    First_fieldnr + 3
  1882. X#define REF_START    First_fieldnr + 4
  1883. X
  1884. X#define PUT_EXPR    First_fieldnr        /* PUT */
  1885. X#define PUT_TARGET    First_fieldnr + 1
  1886. X#define INS_EXPR    First_fieldnr        /* INSERT */
  1887. X#define INS_TARGET    First_fieldnr + 1
  1888. X#define RMV_EXPR    First_fieldnr        /* REMOVE */
  1889. X#define RMV_TARGET    First_fieldnr + 1
  1890. X#define SET_EXPR    First_fieldnr        /* SET'RANDOM */
  1891. X#define DEL_TARGET    First_fieldnr        /* DELETE */
  1892. X#define CHK_TEST    First_fieldnr        /* CHECK */
  1893. X#define SHR_TARGET    First_fieldnr        /* SHARE */
  1894. X
  1895. X#define WRT_L_LINES    First_fieldnr        /* WRITE */
  1896. X#define WRT_EXPR    First_fieldnr + 1
  1897. X#define WRT_R_LINES    First_fieldnr + 2
  1898. X#define RD_TARGET    First_fieldnr        /* READ */
  1899. X#define RD_EXPR     First_fieldnr + 1
  1900. X#define RDW_TARGET    First_fieldnr        /* READ'RAW */
  1901. X
  1902. X#define IF_TEST     First_fieldnr        /* IF */
  1903. X#define IF_COMMENT    First_fieldnr + 1
  1904. X#define IF_SUITE    First_fieldnr + 2
  1905. X#define WHL_LINO    First_fieldnr        /* WHILE */
  1906. X#define WHL_TEST    First_fieldnr + 1
  1907. X#define WHL_COMMENT    First_fieldnr + 2
  1908. X#define WHL_SUITE    First_fieldnr + 3
  1909. X#define FOR_TARGET    First_fieldnr        /* FOR */
  1910. X#define FOR_EXPR    First_fieldnr + 1
  1911. X#define FOR_COMMENT    First_fieldnr + 2
  1912. X#define FOR_SUITE    First_fieldnr + 3
  1913. X
  1914. X#define SLT_COMMENT    First_fieldnr        /* SELECT */
  1915. X#define SLT_TSUITE    First_fieldnr + 1
  1916. X#define TSUI_LINO    First_fieldnr        /* TEST SUITE */
  1917. X#define TSUI_TEST    First_fieldnr + 1
  1918. X#define TSUI_COMMENT    First_fieldnr + 2
  1919. X#define TSUI_SUITE    First_fieldnr + 3
  1920. X#define TSUI_NEXT    First_fieldnr + 4
  1921. X#define ELSE_LINO    First_fieldnr        /* ELSE */
  1922. X#define ELSE_COMMENT    First_fieldnr + 1
  1923. X#define ELSE_SUITE    First_fieldnr + 2
  1924. X
  1925. X#define RTN_EXPR    First_fieldnr        /* RETURN */
  1926. X#define RPT_TEST    First_fieldnr        /* REPORT */
  1927. X
  1928. X#define UCMD_NAME    First_fieldnr        /* USER COMMAND */
  1929. X#define UCMD_ACTUALS    First_fieldnr + 1
  1930. X#define UCMD_DEF    First_fieldnr + 2
  1931. X#define ACT_KEYW    First_fieldnr        /* ACTUALS USER COMMAND */
  1932. X#define ACT_EXPR    First_fieldnr + 1
  1933. X#define ACT_NEXT    First_fieldnr + 2
  1934. X
  1935. X#define ECMD_NAME    First_fieldnr        /* EXTENDED COMMAND */
  1936. X#define ECMD_ACTUALS    First_fieldnr + 1
  1937. X
  1938. X#define COMP_FIELD    First_fieldnr        /* COMPOUND */
  1939. X#define COLL_SEQ    First_fieldnr        /* COLLATERAL */
  1940. X#define MON_NAME    First_fieldnr        /* MONADIC FUNCTION */
  1941. X#define MON_RIGHT    First_fieldnr + 1
  1942. X#define MON_FCT     First_fieldnr + 2
  1943. X#define DYA_NAME    First_fieldnr + 1    /* DYADIC FUNCTION */
  1944. X#define DYA_LEFT    First_fieldnr
  1945. X#define DYA_RIGHT    First_fieldnr + 2
  1946. X#define DYA_FCT     First_fieldnr + 3
  1947. X#define TAG_NAME    First_fieldnr        /* TAG */
  1948. X#define TAG_ID        First_fieldnr + 1
  1949. X#define NUM_VALUE    First_fieldnr        /* NUMBER */
  1950. X#define NUM_TEXT    First_fieldnr + 1
  1951. X#define XDIS_QUOTE    First_fieldnr        /* TEXT DIS */
  1952. X#define XDIS_NEXT    First_fieldnr + 1
  1953. X#define XLIT_TEXT    First_fieldnr        /* TEXT LIT */
  1954. X#define XLIT_NEXT    First_fieldnr + 1
  1955. X#define XCON_EXPR    First_fieldnr        /* TEXT CONV */
  1956. X#define XCON_NEXT    First_fieldnr + 1
  1957. X#define LDIS_SEQ    First_fieldnr        /* LIST DIS */
  1958. X#define TDIS_SEQ    First_fieldnr        /* TAB_DIS */
  1959. X#define SEL_TABLE    First_fieldnr        /* SELECTION */
  1960. X#define SEL_KEY     First_fieldnr + 1
  1961. X#define TRIM_LEFT    First_fieldnr        /* BEHEAD, CURTAIL */
  1962. X#define TRIM_RIGHT    First_fieldnr + 1
  1963. X#define UNP_SEQ     First_fieldnr        /* UNPARSED */
  1964. X#define UNP_TEXT    First_fieldnr + 1
  1965. X
  1966. X#define AND_LEFT    First_fieldnr        /* AND */
  1967. X#define AND_RIGHT    First_fieldnr + 1
  1968. X#define OR_LEFT     First_fieldnr        /* OR */
  1969. X#define OR_RIGHT    First_fieldnr + 1
  1970. X#define NOT_RIGHT    First_fieldnr        /* NOT */
  1971. X#define QUA_TARGET    First_fieldnr        /* QUANTIFICATION */
  1972. X#define QUA_EXPR    First_fieldnr + 1
  1973. X#define QUA_TEST    First_fieldnr + 2
  1974. X#define REL_LEFT    First_fieldnr        /* ORDER TEST */
  1975. X#define REL_RIGHT    First_fieldnr + 1
  1976. X
  1977. X#ifdef GFX
  1978. X#define SPACE_FROM    First_fieldnr
  1979. X#define SPACE_TO    First_fieldnr + 1
  1980. X#define LINE_FROM    First_fieldnr
  1981. X#define LINE_TO     First_fieldnr + 1
  1982. X#endif
  1983. X
  1984. X#define COLON_SUITE    First_fieldnr        /* COLON_NODE */
  1985. X
  1986. END_OF_FILE
  1987.   if test 7578 -ne `wc -c <'abc/ihdrs/i2nod.h'`; then
  1988.     echo shar: \"'abc/ihdrs/i2nod.h'\" unpacked with wrong size!
  1989.   fi
  1990.   # end of 'abc/ihdrs/i2nod.h'
  1991. fi
  1992. if test -f 'abc/stc/i2tcp.c' -a "${1}" != "-c" ; then 
  1993.   echo shar: Will not clobber existing file \"'abc/stc/i2tcp.c'\"
  1994. else
  1995.   echo shar: Extracting \"'abc/stc/i2tcp.c'\" \(7399 characters\)
  1996.   sed "s/^X//" >'abc/stc/i2tcp.c' <<'END_OF_FILE'
  1997. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  1998. X
  1999. X/* polytype representation */
  2000. X
  2001. X#include "b.h"
  2002. X#include "bobj.h"
  2003. X#include "i2stc.h"
  2004. X
  2005. X/* A polytype is a compound with two fields.
  2006. X * The first field is a B text, and holds the typekind.
  2007. X * If the typekind is 'Variable', the second field is 
  2008. X *   a B text, holding the identifier of the variable;
  2009. X * otherwise, the second field is a compound of sub(poly)types,
  2010. X *   indexed from 0 to one less then the number of subtypes.
  2011. X */
  2012. X
  2013. X#define Kin    0
  2014. X#define Sub    1
  2015. X#define Id    Sub
  2016. X#define Asc    0
  2017. X#define Key    1
  2018. X
  2019. X#define Kind(u)        ((typekind) *Field((value) (u), Kin))
  2020. X#define Psubtypes(u)    (Field((value) (u), Sub))
  2021. X#define Ident(u)    (*Field((value) (u), Id))
  2022. X
  2023. Xtypekind var_kind;
  2024. Xtypekind num_kind;
  2025. Xtypekind tex_kind;
  2026. Xtypekind lis_kind;
  2027. Xtypekind tab_kind;
  2028. Xtypekind com_kind;
  2029. Xtypekind t_n_kind;
  2030. Xtypekind l_t_kind;
  2031. Xtypekind tlt_kind;
  2032. Xtypekind err_kind;
  2033. Xtypekind ext_kind;
  2034. X
  2035. Xpolytype num_type;
  2036. Xpolytype tex_type;
  2037. Xpolytype err_type;
  2038. Xpolytype t_n_type;
  2039. X
  2040. X/* Making, setting and accessing (the fields of) polytypes */
  2041. X
  2042. XVisible polytype mkt_polytype(k, nsub) typekind k; intlet nsub; {
  2043. X    value u;
  2044. X    
  2045. X    u = mk_compound(2);
  2046. X    *Field(u, Kin)= copy((value) k);
  2047. X    *Field(u, Sub)= mk_compound(nsub);
  2048. X    return (polytype) u;
  2049. X}
  2050. X
  2051. XProcedure putsubtype(sub, u, isub) polytype sub, u; intlet isub; {
  2052. X    *Field(*Psubtypes(u), isub)= (value) sub;
  2053. X}
  2054. X
  2055. Xtypekind kind(u) polytype u; {
  2056. X    return Kind(u);
  2057. X}
  2058. X
  2059. Xintlet nsubtypes(u) polytype u; {
  2060. X    return Nfields(*Psubtypes(u));
  2061. X}
  2062. X
  2063. Xpolytype subtype(u, i) polytype u; intlet i; {
  2064. X    return (polytype) *Field(*Psubtypes(u), i);
  2065. X}
  2066. X
  2067. Xpolytype asctype(u) polytype u; {
  2068. X    return subtype(u, Asc);
  2069. X}
  2070. X
  2071. Xpolytype keytype(u) polytype u; {
  2072. X    return subtype(u, Key);
  2073. X}
  2074. X
  2075. Xvalue ident(u) polytype u; {
  2076. X    return Ident(u);
  2077. X}
  2078. X
  2079. X/* making new polytypes */
  2080. X
  2081. Xpolytype mkt_number() {
  2082. X    return p_copy(num_type);
  2083. X}
  2084. X
  2085. Xpolytype mkt_text() {
  2086. X    return p_copy(tex_type);
  2087. X}
  2088. X
  2089. Xpolytype mkt_tn() {
  2090. X    return p_copy(t_n_type);
  2091. X}
  2092. X
  2093. Xpolytype mkt_error() {
  2094. X    return p_copy(err_type);
  2095. X}
  2096. X
  2097. Xpolytype mkt_list(s) polytype s; {
  2098. X    polytype u;
  2099. X    
  2100. X    u = mkt_polytype(lis_kind, 1);
  2101. X    putsubtype(s, u, Asc);
  2102. X    return u;
  2103. X}
  2104. X
  2105. Xpolytype mkt_table(k, a) polytype k, a; {
  2106. X    polytype u;
  2107. X    
  2108. X    u = mkt_polytype(tab_kind, 2);
  2109. X    putsubtype(a, u, Asc);
  2110. X    putsubtype(k, u, Key);
  2111. X    return u;
  2112. X}
  2113. X
  2114. Xpolytype mkt_lt(s) polytype s; {
  2115. X    polytype u;
  2116. X    
  2117. X    u = mkt_polytype(l_t_kind, 1);
  2118. X    putsubtype(s, u, Asc);
  2119. X    return u;
  2120. X}
  2121. X
  2122. Xpolytype mkt_tlt(s) polytype s; {
  2123. X    polytype u;
  2124. X    
  2125. X    u = mkt_polytype(tlt_kind, 1);
  2126. X    putsubtype(s, u, Asc);
  2127. X    return u;
  2128. X}
  2129. X
  2130. Xpolytype mkt_compound(nsub) intlet nsub; {
  2131. X    return mkt_polytype(com_kind, nsub);
  2132. X}
  2133. X
  2134. Xpolytype mkt_var(id) value id; {
  2135. X    polytype u;
  2136. X    
  2137. X    u = mk_compound(2);
  2138. X    *Field(u, Kin)= copy((value) var_kind);
  2139. X    *Field(u, Id)= id;
  2140. X    return u;
  2141. X}
  2142. X
  2143. XHidden value nnewvar;
  2144. X
  2145. Xpolytype mkt_newvar() {
  2146. X    value v;
  2147. X    v = sum(nnewvar, one);
  2148. X    release(nnewvar);
  2149. X    nnewvar = v;
  2150. X    return mkt_var(convert(nnewvar, No, No));
  2151. X}
  2152. X
  2153. XHidden value n_external;  /* external variable types used by how-to's */
  2154. X
  2155. XVisible Procedure new_externals() {
  2156. X    n_external= zero;
  2157. X}
  2158. X
  2159. XVisible polytype mkt_ext() {
  2160. X    polytype u;
  2161. X    value v;
  2162. X    
  2163. X    v = sum(n_external, one);
  2164. X    release(n_external);
  2165. X    n_external = v;
  2166. X    
  2167. X    u= mk_compound(2);
  2168. X    *Field(u, Kin)= copy((value) ext_kind);
  2169. X    *Field(u, Id)= convert(n_external, No, No);
  2170. X    
  2171. X    return u;
  2172. X}
  2173. X
  2174. Xpolytype p_copy(u) polytype u; {
  2175. X    return (polytype) copy((polytype) u);
  2176. X}
  2177. X
  2178. XProcedure p_release(u) polytype u; {
  2179. X    release((polytype) u);
  2180. X}
  2181. X
  2182. X/* predicates */
  2183. X
  2184. Xbool are_same_types(u, v) polytype u, v; {
  2185. X    if (compare((value) Kind(u), (value) Kind(v)) != 0)
  2186. X        return No;
  2187. X    else if (t_is_var(Kind(u)))
  2188. X        return (compare(Ident(u), Ident(v)) == 0);
  2189. X    else
  2190. X        return (
  2191. X            (nsubtypes(u) == nsubtypes(v))
  2192. X            &&
  2193. X            (compare(*Psubtypes(u), *Psubtypes(v)) == 0)
  2194. X        );
  2195. X}
  2196. X
  2197. Xbool have_same_structure(u, v) polytype u, v; {
  2198. X    return(
  2199. X        (compare((value) Kind(u), (value) Kind(v)) == 0)
  2200. X        &&
  2201. X        nsubtypes(u) == nsubtypes(v)
  2202. X    );
  2203. X}
  2204. X
  2205. Xbool t_is_number(kind) typekind kind; {
  2206. X    return (compare((value) kind, (value) num_kind) == 0 ? Yes : No);
  2207. X}
  2208. X
  2209. Xbool t_is_text(kind) typekind kind; {
  2210. X    return (compare((value) kind, (value) tex_kind) == 0 ? Yes : No);
  2211. X}
  2212. X
  2213. Xbool t_is_tn(kind) typekind kind; {
  2214. X    return (compare((value) kind, (value) t_n_kind) == 0 ? Yes : No);
  2215. X}
  2216. X
  2217. Xbool t_is_error(kind) typekind kind; {
  2218. X    return (compare((value) kind, (value) err_kind) == 0 ? Yes : No);
  2219. X}
  2220. X
  2221. Xbool t_is_list(kind) typekind kind; {
  2222. X    return (compare((value) kind, (value) lis_kind) == 0 ? Yes : No);
  2223. X}
  2224. X
  2225. Xbool t_is_table(kind) typekind kind; {
  2226. X    return (compare((value) kind, (value) tab_kind) == 0 ? Yes : No);
  2227. X}
  2228. X
  2229. Xbool t_is_lt(kind) typekind kind; {
  2230. X    return (compare((value) kind, (value) l_t_kind) == 0 ? Yes : No);
  2231. X}
  2232. X
  2233. Xbool t_is_tlt(kind) typekind kind; {
  2234. X    return (compare((value) kind, (value) tlt_kind) == 0 ? Yes : No);
  2235. X}
  2236. X
  2237. Xbool t_is_compound(kind) typekind kind; {
  2238. X    return (compare((value) kind, (value) com_kind) == 0 ? Yes : No);
  2239. X}
  2240. X
  2241. Xbool t_is_var(kind) typekind kind; {
  2242. X    return (compare((value) kind, (value) var_kind) == 0 ? Yes : No);
  2243. X}
  2244. X
  2245. Xbool t_is_ext(kind) typekind kind; {
  2246. X    return (compare((value) kind, (value) ext_kind) == 0 ? Yes : No);
  2247. X}
  2248. X
  2249. Xbool has_number(kind) typekind kind; {
  2250. X    if (compare(kind, num_kind) == 0 || compare(kind, t_n_kind) == 0)
  2251. X        return Yes;
  2252. X    else
  2253. X        return No;
  2254. X}
  2255. X
  2256. Xbool has_text(kind) typekind kind; {
  2257. X    if (compare(kind, tex_kind) == 0 || compare(kind, t_n_kind) == 0)
  2258. X        return Yes;
  2259. X    else
  2260. X        return No;
  2261. X}
  2262. X
  2263. Xbool has_lt(kind) typekind kind; {
  2264. X    if (compare(kind, l_t_kind) == 0 || compare(kind, tlt_kind) == 0)
  2265. X        return Yes;
  2266. X    else
  2267. X        return No;
  2268. X}
  2269. X
  2270. X/* The table "ptype_of" maps the identifiers of the variables (B texts)
  2271. X * to polytypes.
  2272. X */
  2273. Xvalue ptype_of;
  2274. X
  2275. XProcedure repl_type_of(u, p) polytype u, p; {
  2276. X    replace((value) p, &ptype_of, Ident(u));
  2277. X}
  2278. X
  2279. Xbool table_has_type_of(u) polytype u; {
  2280. X    return in_keys(Ident(u), ptype_of);
  2281. X}
  2282. X
  2283. X#define    Table_type_of(u) ((polytype) *adrassoc(ptype_of, Ident(u)))
  2284. X
  2285. XVisible polytype bottomtype(u) polytype u; {
  2286. X    while (t_is_var(Kind(u)) && table_has_type_of(u)) {
  2287. X        u = Table_type_of(u);
  2288. X    }
  2289. X    return u;
  2290. X}
  2291. X
  2292. Xpolytype bottomvar(u) polytype u; {
  2293. X    polytype b;
  2294. X
  2295. X    if (!t_is_var(Kind(u)))
  2296. X        return u;
  2297. X    /* Kind(u) == Variable */
  2298. X    while (table_has_type_of(u)) {
  2299. X        b = Table_type_of(u);
  2300. X        if (t_is_var(Kind(b)))
  2301. X            u = b;
  2302. X        else
  2303. X            break;
  2304. X    }
  2305. X    /* Kind(u) == Variable &&
  2306. X       !(table_has_type_of(u) && Kind(Table_type_of(u)) == Variable) */
  2307. X    return u;
  2308. X}
  2309. X
  2310. XVisible Procedure usetypetable(t) value t; {
  2311. X    ptype_of = t;
  2312. X}
  2313. X
  2314. XVisible Procedure deltypetable() {
  2315. X    release(ptype_of);
  2316. X}
  2317. X
  2318. X/* init */
  2319. X
  2320. XVisible Procedure initpol() {
  2321. X    num_kind = mk_text("Number");
  2322. X    num_type = mkt_polytype(num_kind, 0);
  2323. X    tex_kind = mk_text("Text");
  2324. X    tex_type = mkt_polytype(tex_kind, 0);
  2325. X    t_n_kind = mk_text("TN");
  2326. X    t_n_type = mkt_polytype(t_n_kind, 0);
  2327. X    err_kind = mk_text("Error");
  2328. X    err_type = mkt_polytype(err_kind, 0);
  2329. X    
  2330. X    lis_kind = mk_text("List");
  2331. X    tab_kind = mk_text("Table");
  2332. X    com_kind = mk_text("Compound");
  2333. X    l_t_kind = mk_text("LT");
  2334. X    tlt_kind = mk_text("TLT");
  2335. X    var_kind = mk_text("Variable");
  2336. X    ext_kind = mk_text("External");
  2337. X    
  2338. X    nnewvar = zero;
  2339. X}
  2340. X
  2341. XVisible Procedure endpol() {
  2342. X    release((value) num_kind);
  2343. X    release((value) num_type);
  2344. X    release((value) tex_kind);
  2345. X    release((value) tex_type);
  2346. X    release((value) t_n_kind);
  2347. X    release((value) t_n_type);
  2348. X    release((value) err_kind);
  2349. X    release((value) err_type);
  2350. X    release((value) lis_kind);
  2351. X    release((value) tab_kind);
  2352. X    release((value) com_kind);
  2353. X    release((value) l_t_kind);
  2354. X    release((value) tlt_kind);
  2355. X    release((value) var_kind);
  2356. X}
  2357. END_OF_FILE
  2358.   if test 7399 -ne `wc -c <'abc/stc/i2tcp.c'`; then
  2359.     echo shar: \"'abc/stc/i2tcp.c'\" unpacked with wrong size!
  2360.   fi
  2361.   # end of 'abc/stc/i2tcp.c'
  2362. fi
  2363. echo shar: End of archive 18 \(of 25\).
  2364. cp /dev/null ark18isdone
  2365. MISSING=""
  2366. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ; do
  2367.     if test ! -f ark${I}isdone ; then
  2368.     MISSING="${MISSING} ${I}"
  2369.     fi
  2370. done
  2371. if test "${MISSING}" = "" ; then
  2372.     echo You have unpacked all 25 archives.
  2373.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2374. else
  2375.     echo You still must unpack the following archives:
  2376.     echo "        " ${MISSING}
  2377. fi
  2378. exit 0 # Just in case...
  2379.