home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume23 / abc / part05 < prev    next >
Text File  |  1991-01-08  |  55KB  |  1,725 lines

  1. Subject:  v23i084:  ABC interactive programming environment, Part05/25
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 224c79f8 954feef4 fe09aa85 4d07f6a4
  5.  
  6. Submitted-by: Steven Pemberton <steven@cwi.nl>
  7. Posting-number: Volume 23, Issue 84
  8. Archive-name: abc/part05
  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/bio/DEP abc/btr/i1lta.c abc/tc/termcap.5
  17. # Wrapped by rsalz@litchi.bbn.com on Mon Dec 17 13:27:54 1990
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 5 (of 25)."'
  21. if test -f 'abc/bio/DEP' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'abc/bio/DEP'\"
  23. else
  24.   echo shar: Extracting \"'abc/bio/DEP'\" \(1990 characters\)
  25.   sed "s/^X//" >'abc/bio/DEP' <<'END_OF_FILE'
  26. Xi4bio.o: i4bio.c
  27. Xi4bio.o: ../bhdrs/b.h
  28. Xi4bio.o: ../uhdrs/osconf.h
  29. Xi4bio.o: ../uhdrs/os.h
  30. Xi4bio.o: ../uhdrs/conf.h
  31. Xi4bio.o: ../uhdrs/config.h
  32. Xi4bio.o: ../bhdrs/bint.h
  33. Xi4bio.o: ../bhdrs/bmem.h
  34. Xi4bio.o: ../bhdrs/bobj.h
  35. Xi4bio.o: ../ihdrs/i2par.h
  36. Xi4bio.o: ../ihdrs/i3scr.h
  37. Xi4bio.o: ../ihdrs/i3sou.h
  38. Xi4bio.o: ./i4bio.h
  39. Xi4fil.o: i4fil.c
  40. Xi4fil.o: ../bhdrs/b.h
  41. Xi4fil.o: ../uhdrs/osconf.h
  42. Xi4fil.o: ../uhdrs/os.h
  43. Xi4fil.o: ../uhdrs/conf.h
  44. Xi4fil.o: ../uhdrs/config.h
  45. Xi4fil.o: ../bhdrs/bfil.h
  46. Xi4fil.o: ../bhdrs/bmem.h
  47. Xi4fil.o: ../bhdrs/bobj.h
  48. Xi4fil.o: ../ihdrs/i3sou.h
  49. Xi4grp.o: i4grp.c
  50. Xi4grp.o: ../bhdrs/b.h
  51. Xi4grp.o: ../uhdrs/osconf.h
  52. Xi4grp.o: ../uhdrs/os.h
  53. Xi4grp.o: ../uhdrs/conf.h
  54. Xi4grp.o: ../uhdrs/config.h
  55. Xi4grp.o: ../bhdrs/bfil.h
  56. Xi4grp.o: ../bhdrs/bobj.h
  57. Xi4grp.o: ../ihdrs/i3bws.h
  58. Xi4grp.o: ../ihdrs/i3sou.h
  59. Xi4grp.o: ./i4bio.h
  60. Xi4inp.o: i4inp.c
  61. Xi4inp.o: ../bhdrs/b.h
  62. Xi4inp.o: ../uhdrs/osconf.h
  63. Xi4inp.o: ../uhdrs/os.h
  64. Xi4inp.o: ../uhdrs/conf.h
  65. Xi4inp.o: ../uhdrs/config.h
  66. Xi4inp.o: ../bhdrs/bmem.h
  67. Xi4inp.o: ../bhdrs/bobj.h
  68. Xi4inp.o: ./i4bio.h
  69. Xi4lis.o: i4lis.c
  70. Xi4lis.o: ../bhdrs/b.h
  71. Xi4lis.o: ../uhdrs/osconf.h
  72. Xi4lis.o: ../uhdrs/os.h
  73. Xi4lis.o: ../uhdrs/conf.h
  74. Xi4lis.o: ../uhdrs/config.h
  75. Xi4lis.o: ../bhdrs/bmem.h
  76. Xi4lis.o: ../bhdrs/bobj.h
  77. Xi4lis.o: ../bhdrs/bfil.h
  78. Xi4lis.o: ../ihdrs/i3sou.h
  79. Xi4lis.o: ./i4bio.h
  80. Xi4out.o: i4out.c
  81. Xi4out.o: ../bhdrs/b.h
  82. Xi4out.o: ../uhdrs/osconf.h
  83. Xi4out.o: ../uhdrs/os.h
  84. Xi4out.o: ../uhdrs/conf.h
  85. Xi4out.o: ../uhdrs/config.h
  86. Xi4out.o: ../bhdrs/bint.h
  87. Xi4out.o: ../bhdrs/bmem.h
  88. Xi4out.o: ../bhdrs/bobj.h
  89. Xi4out.o: ../ihdrs/i3env.h
  90. Xi4out.o: ../ihdrs/i3scr.h
  91. Xi4out.o: ../ihdrs/i3sou.h
  92. Xi4out.o: ./i4bio.h
  93. Xi4rec.o: i4rec.c
  94. Xi4rec.o: ../bhdrs/b.h
  95. Xi4rec.o: ../uhdrs/osconf.h
  96. Xi4rec.o: ../uhdrs/os.h
  97. Xi4rec.o: ../uhdrs/conf.h
  98. Xi4rec.o: ../uhdrs/config.h
  99. Xi4rec.o: ../uhdrs/feat.h
  100. Xi4rec.o: ../bhdrs/bint.h
  101. Xi4rec.o: ../bhdrs/bfil.h
  102. Xi4rec.o: ../bhdrs/bmem.h
  103. Xi4rec.o: ../bhdrs/bobj.h
  104. Xi4rec.o: ../ihdrs/i2nod.h
  105. Xi4rec.o: ../ihdrs/i2par.h
  106. Xi4rec.o: ../ihdrs/i3scr.h
  107. Xi4rec.o: ../ihdrs/i3sou.h
  108. Xi4rec.o: ./i4bio.h
  109. END_OF_FILE
  110.   if test 1990 -ne `wc -c <'abc/bio/DEP'`; then
  111.     echo shar: \"'abc/bio/DEP'\" unpacked with wrong size!
  112.   fi
  113.   # end of 'abc/bio/DEP'
  114. fi
  115. if test -f 'abc/btr/i1lta.c' -a "${1}" != "-c" ; then 
  116.   echo shar: Will not clobber existing file \"'abc/btr/i1lta.c'\"
  117. else
  118.   echo shar: Extracting \"'abc/btr/i1lta.c'\" \(24025 characters\)
  119.   sed "s/^X//" >'abc/btr/i1lta.c' <<'END_OF_FILE'
  120. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  121. X
  122. X/* Access and update lists and tables */
  123. X
  124. X#include "b.h"
  125. X#include "bobj.h"
  126. X#include "i1btr.h"
  127. X#include "i3scr.h" /* For at_nwl */
  128. X#include "i1tlt.h"
  129. X
  130. X#define REMOVE_ENTRY    MESS(100, "removing non-existent list entry")
  131. X
  132. X#define REMOVE_RAN    MESS(101, "cannot remove from large range")
  133. X#define INSERT_RAN    MESS(102, "cannot insert in large range")
  134. X
  135. X#define KEYS_TAB    MESS(103, "in keys t, t is not a table")
  136. X
  137. X#define SEL_TAB        MESS(104, "in t[k], t is not a table")
  138. X#define SEL_KEY        MESS(105, "in t[k], k is not a key of t")
  139. X
  140. X#ifndef DEBUG
  141. X#define check(v, where) /*nothing*/
  142. X#endif
  143. X
  144. X#define IsInner(p) (Flag(p) == Inner)
  145. X#define IsBottom(p) (Flag(p) == Bottom)
  146. X
  147. X#define _Pxitm(p, l, iw) (IsInner(p) ? Piitm(p, l, iw) : Pbitm(p, l, iw))
  148. X
  149. XHidden itemptr Pxitm(p, l, iw) btreeptr p; intlet l, iw; {
  150. X    return _Pxitm(p, l, iw);
  151. X}
  152. X
  153. X#define Inil ((itemptr)0)
  154. X
  155. X#define Incr(p, n) ((p) += (n))
  156. X
  157. XVisible width itemwidth[4]= {Cw, Lw, Tw, Kw};
  158. X
  159. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  160. X
  161. Xtypedef struct {
  162. X    btreeptr s_ptr;
  163. X    int s_lim;
  164. X} finger[Maxheight], *fingertip;
  165. X
  166. X#define Snil ((fingertip)0)
  167. X
  168. X#define Push(s, p, l) ((s)->s_ptr= (p), ((s)->s_lim= (l)), (s)++)
  169. X#define Top(s, p, l) ((p)= ((s)-1)->s_ptr, (l)= ((s)-1)->s_lim)
  170. X#define Drop(s) (--(s))
  171. X#define Pop(s, p, l) (--(s), (p)= (s)->s_ptr, (l)= (s)->s_lim)
  172. X    /* Pop(s, p, l) is equivalent to Top(s, p, l); Drop(s) */
  173. X
  174. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  175. X
  176. XVisible fingertip unzip(p, at, s) btreeptr p; int at; fingertip s; {
  177. X    int syz; intlet l;
  178. X    if (p == Bnil) return s;
  179. X    for (;;) {
  180. X        if (at <= 0) l= 0;
  181. X        else if (at >= Size(p)) l= Lim(p);
  182. X        else if (IsInner(p)) {
  183. X            l= 0;
  184. X            while (at > (syz= Size(Ptr(p, l)))) {
  185. X                ++l;
  186. X                at -= syz+1;
  187. X            }
  188. X        }
  189. X        else if (at >= Lim(p)) l= Lim(p) - 1; /* for Irange/Crange */
  190. X        else l= at; /* Assume Bottom */
  191. X        Push(s, p, l);
  192. X        if (!IsInner(p)) break;
  193. X        p= Ptr(p, l);
  194. X    }
  195. X    return s;
  196. X}
  197. X
  198. XVisible Procedure cpynptrs(to, from, n) btreeptr *to, *from; int n; {
  199. X    while (--n >= 0) {
  200. X        *to= copybtree(*from);
  201. X        Incr(to, 1);
  202. X        Incr(from, 1);
  203. X    }
  204. X}
  205. X
  206. XVisible int movnptrs(to, from, n) btreeptr *to, *from; int n; {
  207. X    int syz= 0; /* Collects sum of sizes */
  208. X    while (--n >= 0) {
  209. X        *to= *from;
  210. X        syz += Size(*from);
  211. X        Incr(to, 1);
  212. X        Incr(from, 1);
  213. X    }
  214. X    return syz;
  215. X}
  216. X
  217. X/* The following two routines may prove machine-dependent when moving
  218. X   N pointers is not equivalent to moving N*sizeof(pointer) characters.
  219. X   Also, the latter may be slower. */
  220. X
  221. XVisible Procedure movnitms(to, from, n, iw) itemptr to, from; intlet n, iw; {
  222. X    register char *t= (char *)to, *f= (char *)from;
  223. X    n *= iw;
  224. X    while (--n >= 0) *t++ = *f++;
  225. X}
  226. X
  227. XHidden Procedure shift(p, l, iw) btreeptr p; intlet l, iw; {
  228. X    /* Move items and pointers from l upwards one to the right */
  229. X    btreeptr *to, *from;
  230. X    intlet n= (Lim(p)-l) * iw; bool inner= IsInner(p);
  231. X    char *f= (char *) Pxitm(p, Lim(p), iw);
  232. X    char *t= f+iw;
  233. X    while (--n >= 0) *--t = *--f;
  234. X    if (inner) {
  235. X        from= &Ptr(p, Lim(p));
  236. X        to= from;
  237. X        Incr(to, 1);
  238. X        n= Lim(p)-l;
  239. X        while (--n >= 0) {
  240. X            *to= *from;
  241. X            Incr(to, -1);
  242. X            Incr(from, -1);
  243. X        }
  244. X    }
  245. X}
  246. X
  247. XVisible Procedure cpynitms(to, from, n, it) itemptr to, from; intlet n, it; {
  248. X    intlet i, iw= Itemwidth(it);
  249. X    movnitms(to, from, n, iw);
  250. X    switch (it) {
  251. X    case Lt:
  252. X    case Kt:
  253. X    case Tt:
  254. X        for (i= 0; i < n; ++i) {
  255. X            copy(Keyval(to));
  256. X            if (it == Tt) copy(Ascval(to));
  257. X            else if (it == Kt) Ascval(to)= Vnil;
  258. X            to= (itemptr) ((char*)to + iw);
  259. X        }
  260. X    }
  261. X}
  262. X
  263. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  264. X
  265. X/* Uflow uses a character array to hold the items.  This may be wrong. */
  266. X
  267. XVisible Procedure uflow(n, l, cbuf, pbuf, it)
  268. X intlet n, l; char cbuf[]; btreeptr pbuf[]; intlet it; {
  269. X    char ncbuf[3*Maxbottom*sizeof(btritem)], *cp= ncbuf;
  270. X    btreeptr npbuf[3*Maxinner], *pp= npbuf, q;
  271. X    intlet iw= Itemwidth(it); bool inner= IsInner(pbuf[0]);
  272. X    intlet i, j, k, nn, l1= l>0 ? l-1 : l, l2= l<n ? l+1 : l;
  273. X    for (i= l1; i <= l2; ++i) {
  274. X        q= pbuf[i]; j= Lim(q);
  275. X        cpynitms((itemptr)cp, Pxitm(q, 0, iw), j, it);
  276. X        cp += j*iw;
  277. X        if (inner) {
  278. X            cpynptrs(pp, &Ptr(q, 0), j+1);
  279. X            Incr(pp, j+1);
  280. X        }
  281. X        if (i < l2) {
  282. X            movnitms((itemptr)cp, (itemptr)(cbuf+i*iw), 1, iw);
  283. X            cp += iw;
  284. X        }
  285. X        relbtree(q, it);
  286. X    }
  287. X    nn= (cp-ncbuf)/iw;
  288. X    k= inner ? Maxinner : Maxbottom;
  289. X    if (nn <= k) k= 1;
  290. X    else if (nn <= 2*k) k= 2;
  291. X    else k= 3;
  292. X    /* (k <= l2-l1+1) */
  293. X    cp= ncbuf; pp= npbuf;
  294. X    for (i= 0; i < k; ++i) {
  295. X        if (i > 0) {
  296. X            movnitms((itemptr)(cbuf+(l1+i-1)*iw), (itemptr)cp, 1, iw);
  297. X            cp += iw;
  298. X            --nn;
  299. X        }
  300. X        pbuf[l1+i]= q= grabbtreenode(inner ? Inner : Bottom, it);
  301. X        Lim(q)= Size(q)= j= nn/(k-i); nn -= j;
  302. X        movnitms(Pxitm(q, 0, iw), (itemptr)cp, j, iw);
  303. X        cp += j*iw;
  304. X        if (inner) {
  305. X            Size(q) += movnptrs(&Ptr(q, 0), pp, j+1);
  306. X            Incr(pp, j+1);
  307. X        }
  308. X    }
  309. X    if (k < l2-l1+1) {
  310. X        movnitms((itemptr)(cbuf+(l1+k-1)*iw), (itemptr)(cbuf+l2*iw), n-l2, iw);
  311. X        VOID movnptrs(pbuf+l1+k, pbuf+l2+1, n-l2);
  312. X        n -= l2-l1+1 - k;
  313. X    }
  314. X    return n;
  315. X}
  316. X
  317. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  318. X
  319. X/* Low level access routines */
  320. X
  321. X/* Meaning of 'flags' parameter to searchkey: */
  322. X#define NORMAL 0
  323. X#define UNIQUE 1 /* uniquify visited nodes */
  324. X#define DYAMAX 2 /* special for dyadic max (= previous element) */
  325. X#define DYAMIN 4 /* special for dyadic min (= next element) */
  326. X
  327. XHidden bool searchkey(v, pw, flags, ft)
  328. X value v, *pw; int flags; fingertip *ft; {
  329. X    btreeptr p, *pp;
  330. X    intlet l, mid, h, it= Itemtype(*pw), iw= Itemwidth(it);
  331. X    bool inner; relation r;
  332. X    pp= &Root(*pw);
  333. X    if (flags&UNIQUE) {
  334. X        killranges(pw);
  335. X        uniql(pw);
  336. X        pp= &Root(*pw);
  337. X    }
  338. X    if (*pp == Bnil) return No;
  339. X    for (;;) {
  340. X        if (flags&UNIQUE) uniqlbtreenode(pp, it);
  341. X        p= *pp;
  342. X        inner= IsInner(p);
  343. X        l= 0; h= Lim(p);
  344. X        r= 1; /* For the (illegal?) case that there are no items */
  345. X        while (l < h) { /* Binary search in {l..h-1} */
  346. X            mid= (l+h)/2;
  347. X            r= compare(v, Keyval(Pxitm(p, mid, iw)));
  348. X            if (!comp_ok) return No;
  349. X            if (r == 0) { /* Found it */
  350. X                if (flags&(DYAMIN|DYAMAX)) {
  351. X                    /* Pretend not found */
  352. X                    if (flags&DYAMIN) r= 1;
  353. X                    else r= -1;
  354. X                }
  355. X                else { /* Normal case, report success */
  356. X                    l= mid;
  357. X                    break;
  358. X                }
  359. X            }
  360. X            if (r < 0) h= mid; /* Continue in {l..mid-1} */
  361. X            else if (r > 0) l= mid+1; /* Cont. in {mid+1..h-i} */
  362. X        }
  363. X        Push(*ft, p, l);
  364. X        if (r == 0) return Yes;
  365. X        if (!inner) {
  366. X            switch (Flag(p)) {
  367. X            case Irange: return h > 0 && l < Lim(p) && integral(v);
  368. X            case Crange: return h > 0 && l < Lim(p) && character(v);
  369. X            default: case Bottom: return No;
  370. X            }
  371. X        }
  372. X        pp= &Ptr(p, l);
  373. X    }
  374. X}
  375. X
  376. XHidden Procedure killranges(pv) value *pv; {
  377. X    btreeptr p= Root(*pv);
  378. X    if (p == Bnil) return;
  379. X    switch (Flag(p)) {
  380. X    case Crange: killCrange(p, pv); break;
  381. X    case Irange: killIrange(p, pv); break;
  382. X    }
  383. X}
  384. X
  385. XHidden Procedure killCrange(p, pv) btreeptr p; value *pv; {
  386. X    value w; intlet lwbchar= Lwbchar(p), upbchar= Upbchar(p);
  387. X    release(*pv);
  388. X    *pv= mk_elt();
  389. X    do {
  390. X        w= mkchar(lwbchar);
  391. X        insert(w, pv);
  392. X        release(w);
  393. X    } while (++lwbchar <= upbchar);
  394. X}
  395. X
  396. XHidden Procedure killIrange(p, pv) btreeptr p; value *pv; {
  397. X    value w, lwb, upb;
  398. X    
  399. X    lwb= copy(Lwbval(p)), upb= copy(Upbval(p));
  400. X    release(*pv);
  401. X    *pv= mk_elt();
  402. X    do {
  403. X        insert(lwb, pv);
  404. X        if (compare(lwb, upb) >= 0) break;
  405. X        w= lwb;
  406. X        lwb= sum(lwb, one);
  407. X        release(w);
  408. X    } while (still_ok);
  409. X    release(lwb);
  410. X    release(upb);
  411. X}
  412. X
  413. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  414. X
  415. XHidden btreeptr rem(f, ft, it) fingertip f, ft; intlet it; {
  416. X    btreeptr p, q, *pp; itemptr ip; intlet l, iw= Itemwidth(it);
  417. X    bool inner, underflow;
  418. X    Pop(ft, p, l);
  419. X    inner= IsInner(p);
  420. X    if (!inner) ip= Pbitm(p, l, iw);
  421. X    else {
  422. X        ip= Piitm(p, l, iw);
  423. X        do {
  424. X            Push(ft, p, l);
  425. X            uniqlbtreenode(pp= &Ptr(p, l), it);
  426. X            p= *pp;
  427. X            l= Lim(p);
  428. X        } while (IsInner(p));
  429. X        inner= No;
  430. X        l -= 2; /* So the movnitms below works fine */
  431. X    }
  432. X    release(Keyval(ip));
  433. X    if (it == Tt || it == Kt) release(Ascval(ip));
  434. X    --Lim(p);
  435. X    movnitms(ip, Pbitm(p, l+1, iw), Lim(p)-l, iw);
  436. X    for (;;) {
  437. X        underflow= Lim(p) < (inner ? Mininner : Minbottom);
  438. X        --Size(p);
  439. X        if (ft == f) break;
  440. X        Pop(ft, p, l);
  441. X        if (underflow)
  442. X            Lim(p)= uflow(Lim(p), l, (string)Piitm(p, 0, iw), &Ptr(p, 0), it);
  443. X        inner= Yes;
  444. X    }
  445. X    if (Lim(p) == 0) { /* Reduce tree level */
  446. X        q= p;
  447. X        p= inner ? copybtree(Ptr(p, 0)) : Bnil;
  448. X        relbtree(q, it);
  449. X    }
  450. X    return p;
  451. X}
  452. X
  453. XHidden btreeptr ins(ip, f, ft, it) itemptr ip; fingertip f, ft; intlet it; {
  454. X    btritem new, old; btreeptr p, q= Bnil, pq, oldq, *pp;
  455. X    intlet l, iw= Itemwidth(it), nn, np, nq; bool inner, overflow;
  456. X    if (ft == f) {
  457. X        /* unify with rest? */
  458. X        p= grabbtreenode(Bottom, it);
  459. X        movnitms(Pbitm(p, 0, iw), ip, 1, iw);
  460. X        Lim(p)= Size(p)= 1;
  461. X        return p;
  462. X    }
  463. X    Pop(ft, p, l);
  464. X    while (IsInner(p)) {
  465. X        Push(ft, p, l);
  466. X        uniqlbtreenode(pp= &Ptr(p, l), it);
  467. X        p= *pp;
  468. X        l= Lim(p);
  469. X    }
  470. X    overflow= Yes; inner= No;
  471. X    for (;;) {
  472. X        pq= p;
  473. X        if (overflow) {
  474. X            oldq= q;
  475. X            movnitms(&old, ip, 1, iw);
  476. X            ip= &new;
  477. X            overflow= Lim(p) == (inner ? Maxinner : Maxbottom);
  478. X            if (overflow) {
  479. X                nn= Lim(p); np= nn/2; nq= nn-np-1;
  480. X                q= grabbtreenode(inner ? Inner : Bottom, it);
  481. X                Size(q)= Lim(q)= nq;
  482. X                movnitms(&new, Pxitm(p, np, iw), 1, iw);
  483. X                movnitms(Pxitm(q, 0, iw), Pxitm(p, np+1, iw), nq, iw);
  484. X                if (inner) 
  485. X                    Size(q) += movnptrs(&Ptr(q, 0), &Ptr(p, np+1), nq+1);
  486. X                Lim(p)= np;
  487. X                Size(p) -= Size(q)+1;
  488. X                if (l > np) {
  489. X                    l -= np+1;
  490. X                    pq= q;
  491. X                }
  492. X            }
  493. X            shift(pq, l, iw);
  494. X            movnitms(Pxitm(pq, l, iw), &old, 1, iw);
  495. X            ++Lim(pq);
  496. X            if (inner) {
  497. X                Size(p) -= Size(oldq);
  498. X                Size(pq) += movnptrs(&Ptr(pq, l+1), &oldq, 1);
  499. X            }
  500. X        }
  501. X        ++Size(pq);
  502. X        if (ft == f) break;
  503. X        Pop(ft, p, l);
  504. X        inner= Yes;
  505. X    }
  506. X    if (overflow)
  507. X        p= mknewroot(p, ip, q, it);
  508. X    return p;
  509. X}
  510. X
  511. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  512. X
  513. X/* Tables */
  514. X
  515. XVisible Procedure replace(a, pt, k) value a, *pt, k; {
  516. X    btritem new; finger f; fingertip ft= f; btreeptr p; value *pp;
  517. X    intlet it, iw, l;
  518. X    check(*pt, " (replace in)");
  519. X    if (Is_ELT(*pt)) { (*pt)->type= Tab; Itemtype(*pt)= Tt; }
  520. X    it= Itemtype(*pt);
  521. X    if (searchkey(k, pt, UNIQUE, &ft)) {
  522. X        iw= Itemwidth(it);
  523. X        Pop(ft, p, l);
  524. X        pp= &Ascval(Pxitm(p, l, iw));
  525. X        release(*pp);
  526. X        *pp= copy(a);
  527. X    }
  528. X    else {
  529. X        if (!comp_ok) return;
  530. X        Keyval(&new)= copy(k); Ascval(&new)= copy(a);
  531. X        Root(*pt)= ins(&new, f, ft, it);
  532. X    }
  533. X    check(*pt, " (replace out)");
  534. X}
  535. X
  536. XVisible /*bool*/ delete(pt, k) value *pt, k; {
  537. X    finger f; fingertip ft= f; intlet it= Itemtype(*pt);
  538. X    check(*pt, " (delete in)");
  539. X    if (!searchkey(k, pt, UNIQUE, &ft)) return No;
  540. X    Root(*pt)= rem(f, ft, it);
  541. X    check(*pt, " (delete out)");
  542. X    return Yes;
  543. X}
  544. X
  545. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  546. X
  547. X/* Lists */
  548. X
  549. XHidden bool is_large_range(v) value v; {
  550. X    value s; bool l;
  551. X    s= size(v);
  552. X    l= large(s);
  553. X    release(s);
  554. X    return l;
  555. X}
  556. X
  557. XVisible Procedure insert(v, pl) value v, *pl; {
  558. X    btritem new; finger f; fingertip ft= f; intlet it= Itemtype(*pl);
  559. X    check(*pl, " (insert in)");
  560. X    if (is_large_range(*pl)) {
  561. X        interr(INSERT_RAN);
  562. X        return;
  563. X    }
  564. X    if (Is_ELT(*pl)) (*pl)->type= Lis;
  565. X    VOID searchkey(v, pl, UNIQUE, &ft);
  566. X    if (!comp_ok) return;
  567. X    Keyval(&new)= copy(v); Ascval(&new)= Vnil;
  568. X    Root(*pl)= ins(&new, f, ft, it);
  569. X    check(*pl, " (insert out)");
  570. X}
  571. X
  572. XVisible Procedure remove(v, pl) value v, *pl; {
  573. X    if (is_large_range(*pl)) {
  574. X        interr(REMOVE_RAN);
  575. X        return;
  576. X    }
  577. X    if (!delete(pl, v) && still_ok)
  578. X        interr(REMOVE_ENTRY);
  579. X}
  580. X
  581. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  582. X
  583. X/* Miscellaneous accesses */
  584. X
  585. XHidden itemptr findkey(key, pv, flags) value key, *pv; int flags; {
  586. X    finger f; fingertip ft= f; btreeptr p;
  587. X    intlet it= Itemtype(*pv), iw= Itemwidth(it), l;
  588. X    if (!searchkey(key, pv, flags, &ft)) return Inil;
  589. X    Pop(ft, p, l);
  590. X    return Pxitm(p, l, iw);
  591. X}
  592. X
  593. XVisible value associate(t, k) value t, k; { /* t[k] */
  594. X    itemptr ip;
  595. X    if (!Is_table(t)) {
  596. X        interr(SEL_TAB);
  597. X        return Vnil;
  598. X    }
  599. X    ip= findkey(k, &t, NORMAL);
  600. X    if (!ip) {
  601. X        if (still_ok) /* Could be type error; then shut up! */
  602. X            interr(SEL_KEY);
  603. X        return Vnil;
  604. X    }
  605. X    return copy(Ascval(ip));
  606. X}
  607. X
  608. XVisible value* adrassoc(t, k) value t, k; { /* &t[k] */
  609. X    itemptr ip= findkey(k, &t, NORMAL);
  610. X    if (!ip) return Pnil;
  611. X    return &Ascval(ip);
  612. X}
  613. X
  614. XVisible bool uniq_assoc(t, k) value t, k; { /* uniql(&t[k]) */
  615. X    itemptr ip= findkey(k, &t, UNIQUE);
  616. X    if (ip == Inil) return No;
  617. X    uniql(&Ascval(ip));
  618. X    return Yes;
  619. X}
  620. X
  621. XVisible bool in_keys(k, t) value k, t; { /* k in keys t */
  622. X    return findkey(k, &t, NORMAL) != Inil;
  623. X}
  624. X
  625. XVisible value keys(t) value t; { /* keys t */
  626. X    value v;
  627. X    if (!Is_table(t)) {
  628. X        interr(KEYS_TAB);
  629. X        return Vnil;
  630. X    }
  631. X    v= grab(Lis, Kt);
  632. X    Root(v)= copybtree(Root(t));
  633. X    return v;
  634. X}
  635. X
  636. X/* WARNING!  The following routine is not reentrant, since (for range lists)
  637. X   it may return a pointer to static storage. */
  638. X
  639. XHidden itemptr getkth(k, v) int k; value v; {
  640. X    finger f; fingertip ft; btreeptr p;
  641. X    intlet it= Itemtype(v), iw= Itemwidth(it), l;
  642. X    static btritem baked; value vk;
  643. X    if (Root(v) == Bnil) return Inil;
  644. X    ft= unzip(Root(v), k, f);
  645. X    do {
  646. X        if (ft == f) return Inil;
  647. X        Pop(ft, p, l);
  648. X    } while (l >= Lim(p));
  649. X    switch (Flag(p)) {
  650. X        default:
  651. X        case Inner:
  652. X        case Bottom:
  653. X            return Pxitm(p, l, iw);
  654. X        case Irange:
  655. X            release(Keyval(&baked));
  656. X            Keyval(&baked)= sum(Lwbval(p), vk= mk_integer(k));
  657. X            release(vk);
  658. X            return &baked;
  659. X        case Crange:
  660. X            release(Keyval(&baked));
  661. X            Keyval(&baked)= mkchar(Lwbchar(p) + k);
  662. X            return &baked;
  663. X    }
  664. X}
  665. X
  666. XVisible value* key(v, k) value v; intlet k; { /* &(++k th'of keys v) */
  667. X    itemptr ip= getkth(k, v);
  668. X    return ip ? &Keyval(ip) : Pnil;
  669. X}
  670. X
  671. XVisible value* assoc(v, k) value v; intlet k; { /* &v[++k th'of keys v] */
  672. X    itemptr ip= getkth(k, v);
  673. X    return ip ? &Ascval(ip) : Pnil;
  674. X}
  675. X
  676. XVisible value thof(k, v) int k; value v; { /* k th'of v */
  677. X    itemptr ip= getkth(k-1, v);
  678. X    if (!ip) return Vnil;
  679. X    switch (Type(v)) {
  680. X    case Tex: return mkchar(Charval(ip));
  681. X    case Lis: return copy(Keyval(ip));
  682. X    case Tab: return copy(Ascval(ip));
  683. X    default: return Vnil;
  684. X    }
  685. X}
  686. X
  687. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  688. X
  689. X/* Compare B-trees.  Should use fingers, but to keep things simple
  690. X   (especially in the presence of range type nodes), doesn't.  This
  691. X   makes its behaviour O(N log N), where it could be O(N), alas. */
  692. X
  693. X/* WARNING!  getkth may return a pointer to static storage (when retrieving
  694. X   elements from a range list).  Therefore after the second call to getkth,
  695. X   the return value of the first may be invalid, but only for lists.
  696. X   So we extract the 'Key' values immediately after the call to getkth. */
  697. X
  698. XVisible relation comp_tlt(u, v) value u, v; {
  699. X    itemptr up, vp; int k, ulen, vlen, len; relation r= 0;
  700. X    bool tex= Is_text(u), tab= Is_table(u);
  701. X    value key_u;
  702. X    len= ulen= Tltsize(u); vlen= Tltsize(v);
  703. X    if (vlen < len) len= vlen;
  704. X    for (k= 0; k < len; ++k) {
  705. X        up= getkth(k, u);
  706. X        if (!tex) key_u= copy(Keyval(up));
  707. X        vp= getkth(k, v);
  708. X        if (tex) r= Charval(up) - Charval(vp);
  709. X        else {
  710. X            r= compare(key_u, Keyval(vp));
  711. X            release(key_u);
  712. X            if (tab && r == 0)
  713. X                r= compare(Ascval(up), Ascval(vp));
  714. X        }
  715. X        if (r != 0) break;
  716. X    }
  717. X    if (r == 0) r= ulen - vlen;
  718. X    return r;
  719. X}
  720. X
  721. X/* Compare texts.  When both texts are bottom nodes, compare with
  722. X   strncmp(), to speed up the most common use (look-up by the
  723. X   system of tags in a symbol table).  Otherwise, call comp_tlt(). */
  724. X
  725. XVisible relation comp_text(u, v) value u, v; {
  726. X    btreeptr p, q; int len; relation r;
  727. X    if (!Is_text(u) || !Is_text(v)) 
  728. X        syserr(MESS(106, "comp_text"));
  729. X    p= Root(u), q= Root(v);
  730. X    if (p EQ Bnil) return (q EQ Bnil) ? 0 : -1;
  731. X    if (q EQ Bnil) return 1;
  732. X    if (Flag(p) EQ Bottom && Flag(q) EQ Bottom) {
  733. X        len= Lim(p);
  734. X        if (Lim(q) < len) len= Lim(q);
  735. X        r= strncmp(&Bchar(p, 0), &Bchar(q, 0), len);
  736. X        if (r NE 0) return r;
  737. X        return Lim(p) - Lim(q);
  738. X    }
  739. X    return comp_tlt(u, v);
  740. X}
  741. X
  742. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  743. X
  744. X/* Range type nodes */
  745. X
  746. XVisible bool is_rangelist(v) value v; {
  747. X    return (bool) (Root(v) != Bnil
  748. X               && 
  749. X               (Flag(Root(v)) == Irange || Flag(Root(v)) == Crange)
  750. X              );
  751. X}
  752. X
  753. XHidden value mk_numrange(lwb, upb) value lwb, upb; {
  754. X    value lis;
  755. X    btreeptr proot;
  756. X
  757. X    lis= grab(Lis, Lt);
  758. X    if (numcomp(lwb, upb) > 0)
  759. X        Root(lis)= Bnil;
  760. X    else {
  761. X        Root(lis)= proot= grabbtreenode(Irange, Lt);
  762. X        Lwbval(proot)= copy(lwb);
  763. X        Upbval(proot)= copy(upb);
  764. X        set_size_and_lim(proot);
  765. X    }
  766. X    return(lis);
  767. X}
  768. X
  769. XHidden value i_range(lo, hi) value lo, hi; {
  770. X    value x, res= Vnil;
  771. X
  772. X    x= diff(lo, hi);
  773. X    if (compare(x, one) >= 0)
  774. X        res= mk_elt();
  775. X    else
  776. X        res= mk_numrange(lo, hi);
  777. X    release(x);
  778. X
  779. X    return res;
  780. X}
  781. X
  782. XHidden value mk_charrange(lwb, upb) value lwb, upb; {
  783. X    value lis;
  784. X    btreeptr proot;
  785. X    intlet rsyz;
  786. X
  787. X    lis= grab(Lis, Lt);
  788. X    rsyz= Bchar(Root(upb), 0) - Bchar(Root(lwb), 0) + 1;
  789. X    if (rsyz <= 0)
  790. X        Root(lis)= Bnil;
  791. X    else {
  792. X        Root(lis)= proot= grabbtreenode(Crange, Lt);
  793. X        Size(proot)= rsyz;
  794. X        Lim(proot)= rsyz > 1 ? 2 : 1;
  795. X        Lwbval(proot)= copy(lwb);
  796. X        Upbval(proot)= copy(upb);
  797. X    }
  798. X    return lis;
  799. X}
  800. X
  801. X
  802. XHidden value c_range(lo, hi) value lo, hi; {
  803. X    char a, z;
  804. X
  805. X    a= charval(lo); z= charval(hi);
  806. X    if (z <= a-1) return mk_elt();
  807. X    else return mk_charrange(lo, hi);
  808. X}
  809. X
  810. XVisible value mk_range(v1, v2) value v1, v2; {
  811. X    if (Is_text(v1)) return c_range(v1, v2);
  812. X    else         return i_range(v1, v2);
  813. X}
  814. X
  815. X
  816. X/* set size and lim for integer range node */
  817. XHidden Procedure set_size_and_lim(pnode) btreeptr pnode; {
  818. X    value smin, s;
  819. X    smin= diff(Upbval(pnode), Lwbval(pnode));
  820. X    s= sum(smin, one);
  821. X    if (large(s)) {
  822. X        Size(pnode)= Bigsize;
  823. X        Lim(pnode)= 2;
  824. X    }
  825. X    else {
  826. X        Size(pnode)= intval(s);
  827. X        Lim(pnode)= Size(pnode) > 1 ? 2 : 1;
  828. X    }
  829. X    release(s); release(smin);
  830. X}
  831. X
  832. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  833. X
  834. X/* Dyadic min, max, size of lists */
  835. X
  836. XVisible value l2min(e, v) value e, v; { /* e min v */
  837. X    finger f; fingertip ft= f; btreeptr p;
  838. X    intlet it= Itemtype(v), iw= Itemwidth(it), l;
  839. X    VOID searchkey(e, &v, DYAMIN, &ft);
  840. X    for (;;) {
  841. X        if (ft == f) return Vnil;
  842. X        Top(ft, p, l);
  843. X        if (l < Lim(p)) {
  844. X            switch (Flag(p)) {
  845. X            case Inner:
  846. X                return copy(Keyval(Piitm(p, l, iw)));
  847. X            case Bottom:
  848. X                return copy(Keyval(Pbitm(p, l, iw)));
  849. X            case Irange:
  850. X                if (l == 0) return copy(Lwbval(p));
  851. X                if (integral(e)) return sum(e, one);
  852. X                return ceilf(e);
  853. X            case Crange:
  854. X                if (l == 0) return copy(Lwbval(p));
  855. X                return mkchar(Bchar(Root(e), 0) + 1);
  856. X            }
  857. X        }
  858. X        Drop(ft);
  859. X    }
  860. X}
  861. X
  862. XVisible value l2max(e, v) value e, v; { /* e max v */
  863. X    finger f; fingertip ft= f; btreeptr p;
  864. X    intlet it= Itemtype(v), iw= Itemwidth(it), l;
  865. X    VOID searchkey(e, &v, DYAMAX, &ft);
  866. X    for (;;) {
  867. X        if (ft == f) return Vnil;
  868. X        Top(ft, p, l);
  869. X        --l;
  870. X        if (l >= 0) {
  871. X            switch (Flag(p)) {
  872. X            case Inner:
  873. X                return copy(Keyval(Piitm(p, l, iw)));
  874. X            case Bottom:
  875. X                return copy(Keyval(Pbitm(p, l, iw)));
  876. X            case Irange:
  877. X                if (l == 1) return copy(Upbval(p));
  878. X                if (integral(e)) return diff(e, one);
  879. X                return floorf(e);
  880. X            case Crange:
  881. X                if (l == 1) return copy(Upbval(p));
  882. X                return mkchar(Bchar(Root(e), 0) - 1);
  883. X            }
  884. X        }
  885. X        Drop(ft);
  886. X    }
  887. X}
  888. X
  889. XVisible int l2size(e, v) value e, v; { /* e#v */
  890. X    finger f; fingertip ft= f; btreeptr p;
  891. X    int count= 0; intlet it= Itemtype(v), iw= Itemwidth(it), l, r;
  892. X    VOID searchkey(e, &v, DYAMIN, &ft);
  893. X    for (;;) {
  894. X        if (ft == f) return count;
  895. X        Pop(ft, p, l);
  896. X        while (--l >= 0) {
  897. X            r= compare(Keyval(Pxitm(p, l, iw)), e);
  898. X            if (r != 0) {
  899. X                switch (Flag(p)) {
  900. X                case Irange: /* See footnote */
  901. X                    if (l==0 && count==0 && integral(e))
  902. X                        ++count;
  903. X                    break;
  904. X                case Crange: /* See footnote */
  905. X                    if (l==0 && count==0 && !character(e))
  906. X                        ++count;
  907. X                    break;
  908. X                }
  909. X                return count;
  910. X            }
  911. X            ++count;
  912. X            while (IsInner(p)) {
  913. X                Push(ft, p, l);
  914. X                p= Ptr(p, l);
  915. X                l= Lim(p);
  916. X            }
  917. X        }
  918. X    }
  919. X}
  920. X
  921. X/* Clarification of what happens for x#{a..b}:
  922. X * Consider these five cases: x<a; x=a; a<x<b; x=b; b<x.
  923. X * Only the case a<x<b need be treated specially.  How do we find which
  924. X * case we're in?
  925. X * Searchkey gives us the following values for l on the stack, respectively:
  926. X * 0; 1; 1; 2; 2.  After --l, this becomes -1; 0; 0; 1; 1.
  927. X * In cases x=a or x=b, the compare returns 0, and we go another time
  928. X * through the loop.  So when the compare returns r!=0, the value of l
  929. X * is, respectively: -1; -1; 0; 0; 1.  The -1 cases in fact don't even
  930. X * get at the compare, and the correct count is returned automatically.
  931. X * So we need to do extra work only if l==0, except if x==b.
  932. X * The latter condition is cared for by count==0 (if x==b, count is
  933. X * surely >= 1; if a<x<b, count is surely 0).  This works even when
  934. X * range nodes may be mixed with other node types in one tree.
  935. X */
  936. X
  937. X/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  938. X
  939. X#ifdef DEBUG
  940. X/* Debug code */
  941. X
  942. XHidden char fmtstr[20];
  943. X
  944. XHidden Procedure check(v, whence) value v; string whence; {
  945. X    if (!still_ok) return;
  946. X    switch (Type(v)) {
  947. X    case ELT:
  948. X        return;
  949. X    case Lis:
  950. X    case Tab:
  951. X        break;
  952. X    default:
  953. X        debug("value not a list or table", whence);
  954. X        return;
  955. X    }
  956. X    if (Root(v) != Bnil)
  957. X        VOID cktree(Inil, Root(v), Inil, Itemtype(v), whence);
  958. X    if (!still_ok && !Interrupted()) {
  959. X        dumptree(Root(v), 0, Itemtype(v));
  960. X        putnewline(stdout);
  961. X        fflush(stdout);
  962. X    }
  963. X}
  964. X
  965. XHidden int cktree(left, p, right, it, whence)
  966. X itemptr left; btreeptr p; itemptr right; intlet it; string whence; {
  967. X    /* returns size of checked subtree */
  968. X    intlet i, iw= Itemwidth(it); int sz= 0;
  969. X    if (!still_ok) return 0;
  970. X    if (p == Bnil) {
  971. X        debug("unexpected nil subtree", whence);
  972. X        return 0;
  973. X    }
  974. X    switch (Flag(p)) {
  975. X    case Inner:
  976. X        for (i= 0; i < Lim(p); ++i) {
  977. X            sz += 1 +
  978. X              cktree(left, Ptr(p, i), Piitm(p, i, iw), it, whence);
  979. X            if (!still_ok) return;
  980. X            left= Piitm(p, i, iw);
  981. X        }
  982. X        sz += cktree(left, Ptr(p, i), right, it, whence);
  983. X        if (still_ok && sz != Size(p))
  984. X            debug("size mismatch", whence);
  985. X        break;
  986. X    case Bottom:
  987. X        for (i= 0; i < Lim(p); ++i) {
  988. X            if (left != Inil && compare(Keyval(left),
  989. X                    Keyval(Pbitm(p, i, iw))) > 0) {
  990. X                debug("bottom items out of order", whence);
  991. X                break;
  992. X            }
  993. X            left= Pbitm(p, i, iw);
  994. X            sz++;
  995. X        }
  996. X        if (still_ok && right != Inil
  997. X            && compare(Keyval(left), Keyval(right)) > 0)
  998. X                debug("bottom items out of order", whence);
  999. X        return sz;
  1000. X    case Irange:
  1001. X        if (left != Inil && compare(Keyval(left), Lwbval(p)) > 0
  1002. X            || right != Inil
  1003. X                && compare(Upbval(p), Keyval(right)) > 0)
  1004. X            debug("irange items out of order", whence);
  1005. X        sz= Size(p);
  1006. X    default:
  1007. X        debug("bad node type", whence);
  1008. X    }
  1009. X    return sz;
  1010. X}
  1011. X
  1012. X#ifdef NOT_USED
  1013. XVisible Procedure e_dumptree(v) value v; {
  1014. X    check(v, "");
  1015. X    if (still_ok) {
  1016. X        if (!at_nwl) putnewline(stdout);
  1017. X        dumptree(Root(v), 0, Itemtype(v));
  1018. X        putnewline(stdout);
  1019. X        fflush(stdout);
  1020. X        at_nwl= Yes;
  1021. X    }
  1022. X}
  1023. X#endif
  1024. X
  1025. XHidden Procedure dumptree(p, indent, it) btreeptr p; intlet indent, it; {
  1026. X    intlet i, iw= Itemwidth(it);
  1027. X    int n;
  1028. X    if (Interrupted()) return;
  1029. X    for (n= 0; n<3*indent; n++)
  1030. X        putchr(stdout, ' ');
  1031. X    if (p == Bnil) { putstr(stdout, "<nil>"); return; }
  1032. X    switch (Flag(p)) {
  1033. X    case Inner:
  1034. X        putstr(stdout, "(\n");
  1035. X        for (i= 0; !Interrupted() && i <= Lim(p); ++i) {
  1036. X            if (i > 0) {
  1037. X                for (n= 0; n<3*indent; n++)
  1038. X                    putchr(stdout, ' ');
  1039. X                dumpval(Keyval(Piitm(p, i-1, iw)));
  1040. X                putnewline(stdout);
  1041. X            }
  1042. X            dumptree(Ptr(p, i), indent+1, it);
  1043. X            putnewline(stdout);
  1044. X        }
  1045. X        for (n= 0; n<3*indent; n++)
  1046. X            putchr(stdout, ' ');
  1047. X        putchr(stdout, ')');
  1048. X        break;
  1049. X    case Bottom:
  1050. X        putchr(stdout, '[');
  1051. X        for (i= 0; i < Lim(p); ++i) {
  1052. X            if (i > 0) putchr(stdout, ' ');
  1053. X            dumpval(Keyval(Pbitm(p, i, iw)));
  1054. X        }
  1055. X        putchr(stdout, ']');
  1056. X        break;
  1057. X    case Irange:
  1058. X        putchr(stdout, '{');
  1059. X        dumpval(Lwbval(p));
  1060. X        putstr(stdout, " .. ");
  1061. X        dumpval(Upbval(p));
  1062. X        putchr(stdout, '}');
  1063. X        break;
  1064. X    default:
  1065. X        sprintf(fmtstr, "?type='%c'?", Flag(p));
  1066. X        putstr(stdout, fmtstr);
  1067. X        break;
  1068. X    }
  1069. X}
  1070. X
  1071. XHidden Procedure dumpval(v) value v; {
  1072. X    if (Interrupted()) return;
  1073. X    if (v == Vnil) putstr(stdout, "(nil)");
  1074. X    else switch(Type(v)) {
  1075. X    case Num: case Tex: case Lis: case Tab: case ELT: case Com:
  1076. X        wri(v, No, No, No);
  1077. X        break;
  1078. X    default:
  1079. X        sprintf(fmtstr, "0x%lx", (long)v);
  1080. X        putstr(stdout, fmtstr);
  1081. X    }
  1082. X}
  1083. X
  1084. XHidden Procedure debug(s1, s2) string s1, s2; {
  1085. X    value v1= mk_text(s1);
  1086. X    value v2= mk_text(s2);
  1087. X    value v= concat(v1, v2);
  1088. X    interrV(-1, v);
  1089. X    release(v1); release(v2);
  1090. X    release(v);
  1091. X}
  1092. X
  1093. X#endif /* DEBUG */
  1094. X
  1095. END_OF_FILE
  1096.   if test 24025 -ne `wc -c <'abc/btr/i1lta.c'`; then
  1097.     echo shar: \"'abc/btr/i1lta.c'\" unpacked with wrong size!
  1098.   fi
  1099.   # end of 'abc/btr/i1lta.c'
  1100. fi
  1101. if test -f 'abc/tc/termcap.5' -a "${1}" != "-c" ; then 
  1102.   echo shar: Will not clobber existing file \"'abc/tc/termcap.5'\"
  1103. else
  1104.   echo shar: Extracting \"'abc/tc/termcap.5'\" \(25213 characters\)
  1105.   sed "s/^X//" >'abc/tc/termcap.5' <<'END_OF_FILE'
  1106. X.tr ||
  1107. X.TH TERMCAP 5 "10 May 1980"
  1108. X.UC
  1109. X.SH NAME
  1110. Xtermcap \- terminal capability data base
  1111. X.SH SYNOPSIS
  1112. X/etc/termcap
  1113. X.SH DESCRIPTION
  1114. X.I Termcap
  1115. Xis a data base describing terminals,
  1116. Xused,
  1117. X.IR e.g. ,
  1118. Xby
  1119. X.IR vi (1)
  1120. Xand
  1121. X.IR curses (3X).
  1122. XTerminals are described in
  1123. X.I termcap
  1124. Xby giving a set of capabilities which they have, and by describing
  1125. Xhow operations are performed.
  1126. XPadding requirements and initialization sequences
  1127. Xare included in
  1128. X.I termcap.
  1129. X.PP
  1130. XEntries in
  1131. X.I termcap
  1132. Xconsist of a number of `:' separated fields.
  1133. XThe first entry for each terminal gives the names which are known for the
  1134. Xterminal, separated by `|' characters.  The first name is always 2 characters
  1135. Xlong and is used by older version 6 systems which store the terminal type
  1136. Xin a 16 bit word in a systemwide data base.
  1137. XThe second name given is the most common abbreviation for the terminal, and the
  1138. Xlast name given should be a long name fully identifying the terminal.
  1139. XThe second name should contain no blanks; the last name may well contain
  1140. Xblanks for readability.
  1141. X.SH CAPABILITIES
  1142. X.nf
  1143. X(P) indicates padding may be specified
  1144. X(P*) indicates that padding may be based on no. lines affected
  1145. X
  1146. X.ta \w'k0-k9  'u +\w'Type  'u +\w'Pad?  'u
  1147. X\fBName    Type    Pad?    Description\fR
  1148. Xae    str    (P)    End alternate character set
  1149. Xal    str    (P*)    Add new blank line
  1150. Xam    bool        Terminal has automatic margins
  1151. Xas    str    (P)    Start alternate character set
  1152. Xbc    str        Backspace if not \fB^H\fR
  1153. Xbs    bool        Terminal can backspace with \fB^H\fR
  1154. Xbt    str    (P)    Back tab
  1155. Xbw    bool        Backspace wraps from column 0 to last column
  1156. XCC    str        Command character in prototype if terminal settable
  1157. Xcd    str    (P*)    Clear to end of display
  1158. Xce    str    (P)    Clear to end of line
  1159. Xch    str    (P)    Like cm but horizontal motion only, line stays same
  1160. Xcl    str    (P*)    Clear screen
  1161. Xcm    str    (P)    Cursor motion
  1162. Xco    num        Number of columns in a line
  1163. Xcr    str    (P*)    Carriage return, (default \fB^M\fR)
  1164. Xcs    str    (P)    Change scrolling region (vt100), like cm
  1165. Xcv    str    (P)    Like ch but vertical only.
  1166. Xda    bool        Display may be retained above
  1167. XdB    num        Number of millisec of bs delay needed
  1168. Xdb    bool        Display may be retained below
  1169. XdC    num        Number of millisec of cr delay needed
  1170. Xdc    str    (P*)    Delete character
  1171. XdF    num        Number of millisec of ff delay needed
  1172. Xdl    str    (P*)    Delete line
  1173. Xdm    str        Delete mode (enter)
  1174. XdN    num        Number of millisec of nl delay needed
  1175. Xdo    str        Down one line
  1176. XdT    num        Number of millisec of tab delay needed
  1177. Xed    str        End delete mode
  1178. Xei    str        End insert mode; give \*(lq:ei=:\*(rq if \fBic\fR
  1179. Xeo    str        Can erase overstrikes with a blank
  1180. Xff    str    (P*)    Hardcopy terminal page eject (default \fB^L\fR)
  1181. Xhc    bool        Hardcopy terminal
  1182. Xhd    str        Half-line down (forward 1/2 linefeed)
  1183. Xho    str        Home cursor (if no \fBcm\fR)
  1184. Xhu    str        Half-line up (reverse 1/2 linefeed)
  1185. Xhz    str        Hazeltine; can't print ~'s
  1186. Xic    str    (P)    Insert character
  1187. Xif    str        Name of file containing \fBis\fR
  1188. Xim    bool        Insert mode (enter); give \*(lq:im=:\*(rq if \fBic\fR
  1189. Xin    bool        Insert mode distinguishes nulls on display
  1190. Xip    str    (P*)    Insert pad after character inserted
  1191. Xis    str        Terminal initialization string
  1192. Xk0-k9    str        Sent by \*(lqother\*(rq function keys 0-9
  1193. Xkb    str        Sent by backspace key
  1194. Xkd    str        Sent by terminal down arrow key
  1195. Xke    str        Out of \*(lqkeypad transmit\*(rq mode
  1196. Xkh    str        Sent by home key
  1197. Xkl    str        Sent by terminal left arrow key
  1198. Xkn    num        Number of \*(lqother\*(rq keys
  1199. Xko    str        Termcap entries for other non-function keys
  1200. Xkr    str        Sent by terminal right arrow key
  1201. Xks    str        Put terminal in \*(lqkeypad transmit\*(rq mode
  1202. Xku    str        Sent by terminal up arrow key
  1203. Xl0-l9    str        Labels on \*(lqother\*(rq function keys
  1204. Xli    num        Number of lines on screen or page
  1205. Xll    str        Last line, first column (if no \fBcm\fR)
  1206. Xma    str        Arrow key map, used by vi version 2 only
  1207. Xmi    bool        Safe to move while in insert mode
  1208. Xml    str        Memory lock on above cursor.
  1209. Xms    bool        Safe to move while in standout and underline mode
  1210. Xmu    str        Memory unlock (turn off memory lock).
  1211. Xnc    bool        No correctly working carriage return (DM2500,H2000)
  1212. Xnd    str        Non-destructive space (cursor right)
  1213. Xnl    str    (P*)    Newline character (default \fB\en\fR)
  1214. Xns    bool        Terminal is a \s-2CRT\s+2 but doesn't scroll.
  1215. Xos    bool        Terminal overstrikes
  1216. Xpc    str        Pad character (rather than null)
  1217. Xpt    bool        Has hardware tabs (may need to be set with \fBis\fR)
  1218. Xse    str        End stand out mode
  1219. Xsf    str    (P)    Scroll forwards
  1220. Xsg    num        Number of blank chars left by so or se
  1221. Xso    str        Begin stand out mode
  1222. Xsr    str    (P)    Scroll reverse (backwards)
  1223. Xta    str    (P)    Tab (other than \fB^I\fR or with padding)
  1224. Xtc    str        Entry of similar terminal - must be last
  1225. Xte    str        String to end programs that use \fBcm\fP
  1226. Xti    str        String to begin programs that use \fBcm\fR
  1227. Xuc    str        Underscore one char and move past it
  1228. Xue    str        End underscore mode
  1229. Xug    num        Number of blank chars left by us or ue
  1230. Xul    bool        Terminal underlines even though it doesn't overstrike
  1231. Xup    str        Upline (cursor up)
  1232. Xus    str        Start underscore mode
  1233. Xvb    str        Visible bell (may not move cursor)
  1234. Xve    str        Sequence to end open/visual mode
  1235. Xvs    str        Sequence to start open/visual mode
  1236. Xxb    bool        Beehive (f1=escape, f2=ctrl C)
  1237. Xxn    bool        A newline is ignored after a wrap (Concept)
  1238. Xxr    bool        Return acts like \fBce\fP \er \en (Delta Data)
  1239. Xxs    bool        Standout not erased by writing over it (HP 264?)
  1240. Xxt    bool        Tabs are destructive, magic so char (Teleray 1061)
  1241. X.fi
  1242. X.PP
  1243. X.B A Sample Entry
  1244. X.PP
  1245. XThe following entry, which describes the Concept\-100, is among the more
  1246. Xcomplex entries in the
  1247. X.I termcap
  1248. Xfile as of this writing.
  1249. X(This particular concept entry is outdated,
  1250. Xand is used as an example only.)
  1251. X.PP
  1252. X.nf
  1253. Xc1\||\|c100\||\|concept100:is=\eEU\eEf\eE7\eE5\eE8\eEl\eENH\eEK\eE\e200\eEo&\e200:\e
  1254. X        :al=3*\eE^R:am:bs:cd=16*\eE^C:ce=16\eE^S:cl=2*^L:cm=\eEa%+ %+ :co#80:\e
  1255. X        :dc=16\eE^A:dl=3*\eE^B:ei=\eE\e200:eo:im=\eE^P:in:ip=16*:li#24:mi:nd=\eE=:\e
  1256. X        :se=\eEd\eEe:so=\eED\eEE:ta=8\et:ul:up=\eE;:vb=\eEk\eEK:xn:
  1257. X.fi
  1258. X.PP
  1259. XEntries may continue onto multiple lines by giving a \e as the last
  1260. Xcharacter of a line, and that empty fields
  1261. Xmay be included for readability (here between the last field on a line
  1262. Xand the first field on the next).
  1263. XCapabilities in
  1264. X.I termcap
  1265. Xare of three types:
  1266. XBoolean capabilities which indicate that the terminal has
  1267. Xsome particular feature, numeric capabilities giving the size of the terminal
  1268. Xor the size of particular delays, and string
  1269. Xcapabilities, which give a sequence which can be used to perform particular
  1270. Xterminal operations.
  1271. X.PP
  1272. X.B Types of Capabilities
  1273. X.PP
  1274. XAll capabilities have two letter codes.  For instance, the fact that
  1275. Xthe Concept has \*(lqautomatic margins\*(rq (i.e. an automatic return and linefeed
  1276. Xwhen the end of a line is reached) is indicated by the capability \fBam\fR.
  1277. XHence the description of the Concept includes \fBam\fR.
  1278. XNumeric capabilities are followed by the character `#' and then the value.
  1279. XThus \fBco\fR which indicates the number of columns the terminal has
  1280. Xgives the value `80' for the Concept.
  1281. X.PP
  1282. XFinally, string valued capabilities, such as \fBce\fR (clear to end of line
  1283. Xsequence) are given by the two character code, an `=', and then a string
  1284. Xending at the next following `:'.  A delay in milliseconds may appear after
  1285. Xthe `=' in such a capability, and padding characters are supplied by the
  1286. Xeditor after the remainder of the string is sent to provide this delay.
  1287. XThe delay can be either a integer, e.g. `20', or an integer followed by
  1288. Xan `*', i.e. `3*'.  A `*' indicates that the padding required is proportional
  1289. Xto the number of lines affected by the operation, and the amount given is
  1290. Xthe per-affected-unit padding required.
  1291. XWhen a `*' is specified, it is sometimes useful to give a delay of the form
  1292. X`3.5' specify a delay per unit to tenths of milliseconds.
  1293. X.PP
  1294. XA number of escape sequences are provided in the string valued capabilities
  1295. Xfor easy encoding of characters there.  A \fB\eE\fR maps to an \s-2ESCAPE\s0
  1296. Xcharacter, \fB^x\fR maps to a control-x for any appropriate x, and the sequences
  1297. X\fB\en \er \et \eb \ef\fR give a newline, return, tab, backspace and formfeed.
  1298. XFinally, characters may be given as three octal digits after a \fB\e\fR,
  1299. Xand the characters \fB^\fR and \fB\e\fR may be given as \fB\e^\fR and \fB\e\e\fR.
  1300. XIf it is necessary to place a \fB:\fR in a capability it must be escaped in
  1301. Xoctal as \fB\e072\fR.
  1302. XIf it is necessary to place a null character in a string capability it
  1303. Xmust be encoded as \fB\e200\fR.  The routines which deal with
  1304. X.I termcap
  1305. Xuse C strings, and strip the high bits of the output very late so that
  1306. Xa \fB\e200\fR comes out as a \fB\e000\fR would.
  1307. X.br
  1308. X.ne 5
  1309. X.PP
  1310. X.B Preparing Descriptions
  1311. X.PP
  1312. XWe now outline how to prepare descriptions of terminals.
  1313. XThe most effective way to prepare a terminal description is by imitating
  1314. Xthe description of a similar terminal in
  1315. X.I termcap
  1316. Xand to build up a description gradually, using partial descriptions
  1317. Xwith
  1318. X.I ex
  1319. Xto check that they are correct.
  1320. XBe aware that a very unusual terminal may expose deficiencies in
  1321. Xthe ability of the
  1322. X.I termcap
  1323. Xfile to describe it
  1324. Xor bugs in
  1325. X.I ex.
  1326. XTo easily test a new terminal description you can set the environment variable
  1327. XTERMCAP to a pathname of a file containing the description you are working
  1328. Xon and the editor will look there rather than in
  1329. X.I /etc/termcap.
  1330. XTERMCAP can also be set to the termcap entry itself
  1331. Xto avoid reading the file when starting up the editor.
  1332. X(This only works on version 7 systems.)
  1333. X.PP
  1334. X.B Basic capabilities
  1335. X.PP
  1336. XThe number of columns on each line for the terminal is given by the
  1337. X\fBco\fR numeric capability.  If the terminal is a \s-2CRT\s0, then the
  1338. Xnumber of lines on the screen is given by the \fBli\fR capability.
  1339. XIf the terminal wraps around to the beginning of the next line when
  1340. Xit reaches the right margin, then it should have the \fBam\fR capability.
  1341. XIf the terminal can clear its screen, then this is given by the
  1342. X\fBcl\fR string capability.  If the terminal can backspace, then it
  1343. Xshould have the \fBbs\fR capability, unless a backspace is accomplished
  1344. Xby a character other than \fB^H\fR (ugh) in which case you should give
  1345. Xthis character as the \fBbc\fR string capability.  If it overstrikes
  1346. X(rather than clearing a position when a character is struck over)
  1347. Xthen it should have the \fBos\fR capability.
  1348. X.PP
  1349. XA very important point here is that the local cursor motions encoded
  1350. Xin
  1351. X.I termcap
  1352. Xare undefined at the left and top edges of a \s-2CRT\s0 terminal.
  1353. XThe editor will never attempt to backspace around the left edge, nor
  1354. Xwill it attempt to go up locally off the top.  The editor assumes that
  1355. Xfeeding off the bottom of the screen will cause the screen to scroll up,
  1356. Xand the \fBam\fR capability tells whether the cursor sticks at the right
  1357. Xedge of the screen.  If the terminal has switch selectable automatic margins,
  1358. Xthe
  1359. X.I termcap
  1360. Xfile usually assumes that this is on, i.e. \fBam\fR.
  1361. X.PP
  1362. XThese capabilities suffice to describe hardcopy and \*(lqglass-tty\*(rq terminals.
  1363. XThus the model 33 teletype is described as
  1364. X.PP
  1365. X.DT
  1366. X    t3\||\|33\||\|tty33:co#72:os
  1367. X.PP
  1368. Xwhile the Lear Siegler \s-2ADM\-3\s0 is described as
  1369. X.PP
  1370. X.DT
  1371. X    cl\||\|adm3|3|lsi adm3:am:bs:cl=^Z:li#24:co#80
  1372. X.PP
  1373. X.B Cursor addressing
  1374. X.PP
  1375. XCursor addressing in the terminal is described by a
  1376. X\fBcm\fR string capability, with 
  1377. X.IR printf (3S)
  1378. Xlike escapes \fB%x\fR in it.
  1379. XThese substitute to encodings of the current line or column position,
  1380. Xwhile other characters are passed through unchanged.
  1381. XIf the \fBcm\fR string is thought of as being a function, then its
  1382. Xarguments are the line and then the column to which motion is desired,
  1383. Xand the \fB%\fR encodings have the following meanings:
  1384. X.PP
  1385. X.DT
  1386. X.nf
  1387. X    %d    as in \fIprintf\fR, 0 origin
  1388. X    %2    like %2d
  1389. X    %3    like %3d
  1390. X    %.    like %c
  1391. X    %+x    adds \fIx\fR to value, then %.
  1392. X    %>xy    if value > x adds y, no output.
  1393. X    %r    reverses order of line and column, no output
  1394. X    %i    increments line/column (for 1 origin)
  1395. X    %%    gives a single %
  1396. X    %n    exclusive or row and column with 0140 (DM2500)
  1397. X    %B    BCD (16*(x/10)) + (x%10), no output.
  1398. X    %D    Reverse coding (x-2*(x%16)), no output. (Delta Data).
  1399. X.fi
  1400. X.PP
  1401. XConsider the HP2645, which, to get to row 3 and column 12, needs
  1402. Xto be sent \eE&a12c03Y padded for 6 milliseconds.  Note that the order
  1403. Xof the rows and columns is inverted here, and that the row and column
  1404. Xare printed as two digits.  Thus its \fBcm\fR capability is \*(lqcm=6\eE&%r%2c%2Y\*(rq.
  1405. XThe Microterm \s-2ACT-IV\s0 needs the current row and column sent
  1406. Xpreceded by a \fB^T\fR, with the row and column simply encoded in binary,
  1407. X\*(lqcm=^T%.%.\*(rq.  Terminals which use \*(lq%.\*(rq need to be able to
  1408. Xbackspace the cursor (\fBbs\fR or \fBbc\fR),
  1409. Xand to move the cursor up one line on the screen (\fBup\fR introduced below).
  1410. XThis is necessary because it is not always safe to transmit \fB\et\fR, \fB\en\fR
  1411. X\fB^D\fR and \fB\er\fR, as the system may change or discard them.
  1412. X.PP
  1413. XA final example is the \s-2LSI ADM\s0-3a, which uses row and column
  1414. Xoffset by a blank character, thus \*(lqcm=\eE=%+ %+ \*(rq.
  1415. X.PP
  1416. X.B Cursor motions
  1417. X.PP
  1418. XIf the terminal can move the cursor one position to the right, leaving
  1419. Xthe character at the current position unchanged, then this sequence should
  1420. Xbe given as \fBnd\fR (non-destructive space).  If it can move the cursor
  1421. Xup a line
  1422. Xon the screen in the same column, this should be given as \fBup\fR.
  1423. XIf the terminal has no cursor addressing capability, but can home the cursor
  1424. X(to very upper left corner of screen) then this can be given as
  1425. X\fBho\fR; similarly a fast way of getting to the lower left hand corner
  1426. Xcan be given as \fBll\fR; this may involve going up with \fBup\fR
  1427. Xfrom the home position,
  1428. Xbut the editor will never do this itself (unless \fBll\fR does) because it
  1429. Xmakes no assumption about the effect of moving up from the home position.
  1430. X.PP
  1431. X.B Area clears
  1432. X.PP
  1433. XIf the terminal can clear from the current position to the end of the
  1434. Xline, leaving the cursor where it is, this should be given as \fBce\fR.
  1435. XIf the terminal can clear from the current position to the end of the
  1436. Xdisplay, then this should be given as \fBcd\fR.
  1437. XThe editor only uses
  1438. X\fBcd\fR from the first column of a line.
  1439. X.PP
  1440. X.B Insert/delete line
  1441. X.PP
  1442. XIf the terminal can open a new blank line before the line where the cursor
  1443. Xis, this should be given as \fBal\fR; this is done only from the first
  1444. Xposition of a line.  The cursor must then appear on the newly blank line.
  1445. XIf the terminal can delete the line which the cursor is on, then this
  1446. Xshould be given as \fBdl\fR; this is done only from the first position on
  1447. Xthe line to be deleted.
  1448. XIf the terminal can scroll the screen backwards, then this can be given as
  1449. X\fBsb\fR, but just \fBal\fR suffices.
  1450. XIf the terminal can retain display memory above then the
  1451. X\fBda\fR capability should be given; if display memory can be retained
  1452. Xbelow then \fBdb\fR should be given.  These let the editor understand
  1453. Xthat deleting a line on the screen may bring non-blank lines up from below
  1454. Xor that scrolling back with \fBsb\fR may bring down non-blank lines.
  1455. X.PP
  1456. X.B Insert/delete character
  1457. X.PP
  1458. XThere are two basic kinds of intelligent terminals with respect to
  1459. Xinsert/delete character which can be described using
  1460. X.I termcap.
  1461. XThe most common insert/delete character operations affect only the characters
  1462. Xon the current line and shift characters off the end of the line rigidly.
  1463. XOther terminals, such as the Concept 100 and the Perkin Elmer Owl, make
  1464. Xa distinction between typed and untyped blanks on the screen, shifting
  1465. Xupon an insert or delete only to an untyped blank on the screen which is
  1466. Xeither eliminated, or expanded to two untyped blanks.  You can find out
  1467. Xwhich kind of terminal you have by clearing the screen and then typing
  1468. Xtext separated by cursor motions.  Type \*(lqabc\ \ \ \ def\*(rq using local
  1469. Xcursor motions (not spaces) between the \*(lqabc\*(rq and the \*(lqdef\*(rq.
  1470. XThen position the cursor before the \*(lqabc\*(rq and put the terminal in insert
  1471. Xmode.  If typing characters causes the rest of the line to shift
  1472. Xrigidly and characters to fall off the end, then your terminal does
  1473. Xnot distinguish between blanks and untyped positions.  If the \*(lqabc\*(rq
  1474. Xshifts over to the \*(lqdef\*(rq which then move together around the end of the
  1475. Xcurrent line and onto the next as you insert, you have the second type of
  1476. Xterminal, and should give the capability \fBin\fR, which stands for
  1477. X\*(lqinsert null\*(rq.  If your terminal does something different and unusual
  1478. Xthen you may have to modify the editor to get it to use the insert
  1479. Xmode your terminal defines.  We have seen no terminals which have an insert
  1480. Xmode not not falling into one of these two classes.
  1481. X.PP
  1482. XThe editor can handle both terminals which have an insert mode, and terminals
  1483. Xwhich send a simple sequence to open a blank position on the current line.
  1484. XGive as \fBim\fR the sequence to get into insert mode, or give it an
  1485. Xempty value if your terminal uses a sequence to insert a blank position.
  1486. XGive as \fBei\fR the sequence to leave insert mode (give this, with
  1487. Xan empty value also if you gave \fBim\fR so).
  1488. XNow give as \fBic\fR any sequence needed to be sent just before sending
  1489. Xthe character to be inserted.  Most terminals with a true insert mode
  1490. Xwill not give \fBic\fR, terminals which send a sequence to open a screen
  1491. Xposition should give it here.  (Insert mode is preferable to the sequence
  1492. Xto open a position on the screen if your terminal has both.)
  1493. XIf post insert padding is needed, give this as a number of milliseconds
  1494. Xin \fBip\fR (a string option).  Any other sequence which may need to be
  1495. Xsent after an insert of a single character may also be given in \fBip\fR.
  1496. X.PP
  1497. XIt is occasionally necessary to move around while in insert mode
  1498. Xto delete characters on the same line (e.g. if there is a tab after
  1499. Xthe insertion position).  If your terminal allows motion while in
  1500. Xinsert mode you can give the capability \fBmi\fR to speed up inserting
  1501. Xin this case.  Omitting \fBmi\fR will affect only speed.   Some terminals
  1502. X(notably Datamedia's) must not have \fBmi\fR because of the way their
  1503. Xinsert mode works.
  1504. X.PP
  1505. XFinally, you can specify delete mode by giving \fBdm\fR and \fBed\fR
  1506. Xto enter and exit delete mode, and \fBdc\fR to delete a single character
  1507. Xwhile in delete mode.
  1508. X.PP
  1509. X.B "Highlighting, underlining, and visible bells"
  1510. X.PP
  1511. XIf your terminal has sequences to enter and exit standout mode these
  1512. Xcan be given as \fBso\fR and \fBse\fR respectively.
  1513. XIf there are several flavors of standout mode
  1514. X(such as inverse video, blinking, or underlining \-
  1515. Xhalf bright is not usually an acceptable \*(lqstandout\*(rq mode
  1516. Xunless the terminal is in inverse video mode constantly)
  1517. Xthe preferred mode is inverse video by itself.
  1518. XIf the code to change into or out of standout
  1519. Xmode leaves one or even two blank spaces on the screen,
  1520. Xas the TVI 912 and Teleray 1061 do,
  1521. Xthen \fBug\fR should be given to tell how many spaces are left.
  1522. X.PP
  1523. XCodes to begin underlining and end underlining can be given as \fBus\fR
  1524. Xand \fBue\fR respectively.
  1525. XIf the terminal has a code to underline the current character and move
  1526. Xthe cursor one space to the right, 
  1527. Xsuch as the Microterm Mime,
  1528. Xthis can be given as \fBuc\fR.
  1529. X(If the underline code does not move the cursor to the right,
  1530. Xgive the code followed by a nondestructive space.)
  1531. X.PP
  1532. XMany terminals, such as the HP 2621, automatically leave standout
  1533. Xmode when they move to a new line or the cursor is addressed.
  1534. XPrograms using standout mode should exit standout mode before
  1535. Xmoving the cursor or sending a newline.
  1536. X.PP
  1537. XIf the terminal has
  1538. Xa way of flashing the screen to indicate an error quietly (a bell replacement)
  1539. Xthen this can be given as \fBvb\fR; it must not move the cursor.
  1540. XIf the terminal should be placed in a different mode during
  1541. Xopen and visual modes of
  1542. X.I ex,
  1543. Xthis can be given as
  1544. X\fBvs\fR and \fBve\fR, sent at the start and end of these modes
  1545. Xrespectively.  These can be used to change, e.g., from a underline
  1546. Xto a block cursor and back.
  1547. X.PP
  1548. XIf the terminal needs to be in a special mode when running
  1549. Xa program that addresses the cursor,
  1550. Xthe codes to enter and exit this mode can be given as \fBti\fR and \fBte\fR.
  1551. XThis arises, for example, from terminals like the Concept with more than
  1552. Xone page of memory.
  1553. XIf the terminal has only memory relative cursor addressing and not screen
  1554. Xrelative cursor addressing, a one screen-sized window must be fixed into
  1555. Xthe terminal for cursor addressing to work properly.
  1556. X.PP
  1557. XIf your terminal correctly generates underlined characters
  1558. X(with no special codes needed)
  1559. Xeven though it does not overstrike,
  1560. Xthen you should give the capability \fBul\fR.
  1561. XIf overstrikes are erasable with a blank,
  1562. Xthen this should be indicated by giving \fBeo\fR.
  1563. X.PP
  1564. X.B Keypad
  1565. X.PP
  1566. XIf the terminal has a keypad that transmits codes when the keys are pressed,
  1567. Xthis information can be given. Note that it is not possible to handle
  1568. Xterminals where the keypad only works in local (this applies, for example,
  1569. Xto the unshifted HP 2621 keys).
  1570. XIf the keypad can be set to transmit or not transmit,
  1571. Xgive these codes as \fBks\fR and \fBke\fR.
  1572. XOtherwise the keypad is assumed to always transmit.
  1573. XThe codes sent by the left arrow, right arrow, up arrow, down arrow,
  1574. Xand home keys can be given as \fBkl, kr, ku, kd, \fRand\fB kh\fR respectively.
  1575. XIf there are function keys such as f0, f1, ..., f9, the codes they send
  1576. Xcan be given as \fBk0, k1, ..., k9\fR.
  1577. XIf these keys have labels other than the default f0 through f9, the labels
  1578. Xcan be given as \fBl0, l1, ..., l9\fR.
  1579. XIf there are other keys that transmit the same code as the terminal expects
  1580. Xfor the corresponding function, such as clear screen, the \fItermcap\fP
  1581. X2 letter codes can be given in the \fBko\fR capability,
  1582. Xfor example, \*(lq:ko=cl,ll,sf,sb:\*(rq, which says that the terminal has
  1583. Xclear, home down, scroll down, and scroll up keys that transmit
  1584. Xthe same thing as the cl, ll, sf, and sb entries.
  1585. X.PP
  1586. XThe
  1587. X.B ma
  1588. Xentry is also used to indicate arrow keys on terminals which have
  1589. Xsingle character arrow keys.  It is obsolete but still in use in
  1590. Xversion 2 of vi, which must be run on some minicomputers due to
  1591. Xmemory limitations.
  1592. XThis field is redundant with
  1593. X.BR "kl, kr, ku, kd, " and " kh" .
  1594. XIt consists of groups of two characters.
  1595. XIn each group, the first character is what an arrow key sends, the
  1596. Xsecond character is the corresponding vi command.
  1597. XThese commands are
  1598. X.B h
  1599. Xfor
  1600. X.BR kl ,
  1601. X.B j
  1602. Xfor
  1603. X.BR kd ,
  1604. X.B k
  1605. Xfor
  1606. X.BR ku ,
  1607. X.B l
  1608. Xfor
  1609. X.BR kr ,
  1610. Xand
  1611. X.B H
  1612. Xfor
  1613. X.BR kh .
  1614. XFor example, the mime would be
  1615. X.B ":ma=^Kj^Zk^Xl:"
  1616. Xindicating arrow keys left (^H), down (^K), up (^Z), and right (^X).
  1617. X(There is no home key on the mime.)
  1618. X.PP
  1619. X.B Miscellaneous
  1620. X.PP
  1621. XIf the terminal requires other than a null (zero) character as a pad,
  1622. Xthen this can be given as \fBpc\fR.
  1623. X.PP
  1624. XIf tabs on the terminal require padding, or if the terminal uses a
  1625. Xcharacter other than \fB^I\fR to tab, then this can be given as \fBta\fR.
  1626. X.PP
  1627. XHazeltine terminals, which don't allow `~' characters to be printed should
  1628. Xindicate \fBhz\fR.
  1629. XDatamedia terminals, which echo carriage-return linefeed for carriage return
  1630. Xand then ignore a following linefeed should indicate \fBnc\fR.
  1631. XEarly Concept terminals, which ignore a linefeed immediately after an \fBam\fR
  1632. Xwrap, should indicate \fBxn\fR.
  1633. XIf an erase-eol is required to get rid of standout
  1634. X(instead of merely writing on top of it),
  1635. X\fBxs\fP should be given.
  1636. XTeleray terminals, where tabs turn all characters moved over to blanks,
  1637. Xshould indicate \fBxt\fR.
  1638. XOther specific terminal problems may be corrected by adding more
  1639. Xcapabilities of the form \fBx\fIx\fR.
  1640. X.PP
  1641. XOther capabilities
  1642. Xinclude \fBis\fR, an initialization string for the terminal,
  1643. Xand \fBif\fR, the name of a file containing long initialization strings.
  1644. XThese strings are expected to properly clear and then set the tabs
  1645. Xon the terminal, if the terminal has settable tabs.
  1646. XIf both are given, \fBis\fR will be printed before \fBif\fR.
  1647. XThis is useful where \fBif\fR is
  1648. X.I /usr/lib/tabset/std
  1649. Xbut \fBis\fR
  1650. Xclears the tabs first.
  1651. X.PP
  1652. X.B Similar Terminals
  1653. X.PP
  1654. XIf there are two very similar terminals,
  1655. Xone can be defined as being just like the other with certain exceptions.
  1656. XThe string capability \fBtc\fR can be given
  1657. Xwith the name of the similar terminal.
  1658. XThis capability must be \fIlast\fP and the combined length of the two entries
  1659. Xmust not exceed 1024. Since
  1660. X.I termlib
  1661. Xroutines search the entry from left to right, and since the tc capability is
  1662. Xreplaced by the corresponding entry, the capabilities given at the left
  1663. Xoverride the ones in the similar terminal.
  1664. XA capability can be canceled with \fBxx@\fR where xx is the capability.
  1665. XFor example, the entry
  1666. X.PP
  1667. X    hn\||\|2621nl:ks@:ke@:tc=2621:
  1668. X.PP
  1669. Xdefines a 2621nl that does not have the \fBks\fR or \fBke\fR capabilities,
  1670. Xand hence does not turn on the function key labels when in visual mode.
  1671. XThis is useful for different modes for a terminal, or for different
  1672. Xuser preferences.
  1673. X.SH FILES
  1674. X.DT
  1675. X/etc/termcap    file containing terminal descriptions
  1676. X.SH SEE ALSO
  1677. Xex(1), curses(3X), termcap(3X), tset(1), vi(1), ul(1), more(1)
  1678. X.SH AUTHOR
  1679. XWilliam Joy
  1680. X.br
  1681. XMark Horton added underlining and keypad support
  1682. X.SH BUGS
  1683. X.I Ex
  1684. Xallows only 256 characters for string capabilities, and the routines
  1685. Xin 
  1686. X.IR termcap (3X)
  1687. Xdo not check for overflow of this buffer.
  1688. XThe total length of a single entry (excluding only escaped newlines)
  1689. Xmay not exceed 1024.
  1690. X.PP
  1691. XThe
  1692. X.BR ma ,
  1693. X.BR vs ,
  1694. Xand
  1695. X.B ve
  1696. Xentries are specific to the
  1697. X.I vi
  1698. Xprogram.
  1699. X.PP
  1700. XNot all programs support all entries.
  1701. XThere are entries that are not supported by any program.
  1702. END_OF_FILE
  1703.   if test 25213 -ne `wc -c <'abc/tc/termcap.5'`; then
  1704.     echo shar: \"'abc/tc/termcap.5'\" unpacked with wrong size!
  1705.   fi
  1706.   # end of 'abc/tc/termcap.5'
  1707. fi
  1708. echo shar: End of archive 5 \(of 25\).
  1709. cp /dev/null ark5isdone
  1710. MISSING=""
  1711. 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
  1712.     if test ! -f ark${I}isdone ; then
  1713.     MISSING="${MISSING} ${I}"
  1714.     fi
  1715. done
  1716. if test "${MISSING}" = "" ; then
  1717.     echo You have unpacked all 25 archives.
  1718.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1719. else
  1720.     echo You still must unpack the following archives:
  1721.     echo "        " ${MISSING}
  1722. fi
  1723. exit 0 # Just in case...
  1724.