fancy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /* $NetBSD: fancy.c,v 1.12 2004/04/23 02:58:27 simonb Exp $ */
  2. /*
  3. * Copyright (c) 1980, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. #if 0
  33. static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: fancy.c,v 1.12 2004/04/23 02:58:27 simonb Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "back.h"
  39. extern char PC; /* padding character */
  40. extern char *BC; /* backspace sequence */
  41. char *CD; /* clear to end of screen sequence */
  42. char *CE; /* clear to end of line sequence */
  43. char *CL; /* clear screen sequence */
  44. char *CM; /* cursor movement instructions */
  45. char *HO; /* home cursor sequence */
  46. char *MC; /* column cursor movement map */
  47. char *ML; /* row cursor movement map */
  48. char *ND; /* forward cursor sequence */
  49. extern char *UP; /* up cursor sequence */
  50. int lHO; /* length of HO */
  51. int lBC; /* length of BC */
  52. int lND; /* length of ND */
  53. int lUP; /* length of UP */
  54. int CO; /* number of columns */
  55. int LI; /* number of lines */
  56. int *linect; /* array of lengths of lines on screen (the
  57. * actual screen is not stored) */
  58. /* two letter codes */
  59. char tcap[] = "bccdceclcmhomcmlndup";
  60. /* corresponding strings */
  61. char **tstr[] = {&BC, &CD, &CE, &CL, &CM, &HO, &MC, &ML, &ND, &UP};
  62. extern int buffnum; /* pointer to output buffer */
  63. char tbuf[1024]; /* buffer for decoded termcap entries */
  64. int oldb[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  65. int oldr;
  66. int oldw;
  67. /* "real" cursor positions, so it knows when to reposition. These are -1 if
  68. * curr and curc are accurate */
  69. int realr;
  70. int realc;
  71. void
  72. fboard()
  73. {
  74. int i, j, l;
  75. curmove(0, 0); /* do top line */
  76. for (i = 0; i < 53; i++)
  77. fancyc('_');
  78. curmove(15, 0); /* do botttom line */
  79. for (i = 0; i < 53; i++)
  80. fancyc('_');
  81. l = 1; /* do vertical lines */
  82. for (i = 52; i > -1; i -= 28) {
  83. curmove((l == 1 ? 1 : 15), i);
  84. fancyc('|');
  85. for (j = 0; j < 14; j++) {
  86. curmove(curr + l, curc - 1);
  87. fancyc('|');
  88. }
  89. if (i == 24)
  90. i += 32;
  91. l = -l; /* alternate directions */
  92. }
  93. curmove(2, 1); /* label positions 13-18 */
  94. for (i = 13; i < 18; i++) {
  95. fancyc('1');
  96. fancyc((i % 10) + '0');
  97. curmove(curr, curc + 2);
  98. }
  99. fancyc('1');
  100. fancyc('8');
  101. curmove(2, 29); /* label positions 19-24 */
  102. fancyc('1');
  103. fancyc('9');
  104. for (i = 20; i < 25; i++) {
  105. curmove(curr, curc + 2);
  106. fancyc('2');
  107. fancyc((i % 10) + '0');
  108. }
  109. curmove(14, 1); /* label positions 12-7 */
  110. fancyc('1');
  111. fancyc('2');
  112. for (i = 11; i > 6; i--) {
  113. curmove(curr, curc + 2);
  114. fancyc(i > 9 ? '1' : ' ');
  115. fancyc((i % 10) + '0');
  116. }
  117. curmove(14, 30); /* label positions 6-1 */
  118. fancyc('6');
  119. for (i = 5; i > 0; i--) {
  120. curmove(curr, curc + 3);
  121. fancyc(i + '0');
  122. }
  123. for (i = 12; i > 6; i--)/* print positions 12-7 */
  124. if (board[i])
  125. bsect(board[i], 13, 1 + 4 * (12 - i), -1);
  126. if (board[0]) /* print red men on bar */
  127. bsect(board[0], 13, 25, -1);
  128. for (i = 6; i > 0; i--) /* print positions 6-1 */
  129. if (board[i])
  130. bsect(board[i], 13, 29 + 4 * (6 - i), -1);
  131. l = (off[1] < 0 ? off[1] + 15 : off[1]); /* print white's home */
  132. bsect(l, 3, 54, 1);
  133. curmove(8, 25); /* print the word BAR */
  134. fancyc('B');
  135. fancyc('A');
  136. fancyc('R');
  137. for (i = 13; i < 19; i++) /* print positions 13-18 */
  138. if (board[i])
  139. bsect(board[i], 3, 1 + 4 * (i - 13), 1);
  140. if (board[25]) /* print white's men on bar */
  141. bsect(board[25], 3, 25, 1);
  142. for (i = 19; i < 25; i++) /* print positions 19-24 */
  143. if (board[i])
  144. bsect(board[i], 3, 29 + 4 * (i - 19), 1);
  145. l = (off[0] < 0 ? off[0] + 15 : off[0]); /* print red's home */
  146. bsect(-l, 13, 54, -1);
  147. for (i = 0; i < 26; i++)/* save board position for refresh later */
  148. oldb[i] = board[i];
  149. oldr = (off[1] < 0 ? off[1] + 15 : off[1]);
  150. oldw = -(off[0] < 0 ? off[0] + 15 : off[0]);
  151. }
  152. /*
  153. * bsect (b,rpos,cpos,cnext)
  154. * Print the contents of a board position. "b" has the value of the
  155. * position, "rpos" is the row to start printing, "cpos" is the column to
  156. * start printing, and "cnext" is positive if the position starts at the top
  157. * and negative if it starts at the bottom. The value of "cpos" is checked
  158. * to see if the position is a player's home, since those are printed
  159. * differently.
  160. */
  161. void
  162. bsect(b, rpos, cpos, cnext)
  163. int b; /* contents of position */
  164. int rpos; /* row of position */
  165. int cpos; /* column of position */
  166. int cnext; /* direction of position */
  167. {
  168. int j; /* index */
  169. int n; /* number of men on position */
  170. int bct; /* counter */
  171. int k; /* index */
  172. char pc; /* color of men on position */
  173. bct = 0;
  174. n = abs(b); /* initialize n and pc */
  175. pc = (b > 0 ? 'r' : 'w');
  176. if (n < 6 && cpos < 54) /* position cursor at start */
  177. curmove(rpos, cpos + 1);
  178. else
  179. curmove(rpos, cpos);
  180. for (j = 0; j < 5; j++) { /* print position row by row */
  181. for (k = 0; k < 15; k += 5) /* print men */
  182. if (n > j + k)
  183. fancyc(pc);
  184. if (j < 4) { /* figure how far to back up for next row */
  185. if (n < 6) { /* stop if none left */
  186. if (j + 1 == n)
  187. break;
  188. bct = 1; /* single column */
  189. } else {
  190. if (n < 11) { /* two columns */
  191. if (cpos == 54) { /* home pos */
  192. if (j + 5 >= n)
  193. bct = 1;
  194. else
  195. bct = 2;
  196. }
  197. if (cpos < 54) { /* not home */
  198. if (j + 6 >= n)
  199. bct = 1;
  200. else
  201. bct = 2;
  202. }
  203. } else { /* three columns */
  204. if (j + 10 >= n)
  205. bct = 2;
  206. else
  207. bct = 3;
  208. }
  209. }
  210. curmove(curr + cnext, curc - bct); /* reposition cursor */
  211. }
  212. }
  213. }
  214. void
  215. refresh()
  216. {
  217. int i, r, c;
  218. r = curr; /* save current position */
  219. c = curc;
  220. for (i = 12; i > 6; i--)/* fix positions 12-7 */
  221. if (board[i] != oldb[i]) {
  222. fixpos(oldb[i], board[i], 13, 1 + (12 - i) * 4, -1);
  223. oldb[i] = board[i];
  224. }
  225. if (board[0] != oldb[0]) { /* fix red men on bar */
  226. fixpos(oldb[0], board[0], 13, 25, -1);
  227. oldb[0] = board[0];
  228. }
  229. for (i = 6; i > 0; i--) /* fix positions 6-1 */
  230. if (board[i] != oldb[i]) {
  231. fixpos(oldb[i], board[i], 13, 29 + (6 - i) * 4, -1);
  232. oldb[i] = board[i];
  233. }
  234. i = -(off[0] < 0 ? off[0] + 15 : off[0]); /* fix white's home */
  235. if (oldw != i) {
  236. fixpos(oldw, i, 13, 54, -1);
  237. oldw = i;
  238. }
  239. for (i = 13; i < 19; i++) /* fix positions 13-18 */
  240. if (board[i] != oldb[i]) {
  241. fixpos(oldb[i], board[i], 3, 1 + (i - 13) * 4, 1);
  242. oldb[i] = board[i];
  243. }
  244. if (board[25] != oldb[25]) { /* fix white men on bar */
  245. fixpos(oldb[25], board[25], 3, 25, 1);
  246. oldb[25] = board[25];
  247. }
  248. for (i = 19; i < 25; i++) /* fix positions 19-24 */
  249. if (board[i] != oldb[i]) {
  250. fixpos(oldb[i], board[i], 3, 29 + (i - 19) * 4, 1);
  251. oldb[i] = board[i];
  252. }
  253. i = (off[1] < 0 ? off[1] + 15 : off[1]); /* fix red's home */
  254. if (oldr != i) {
  255. fixpos(oldr, i, 3, 54, 1);
  256. oldr = i;
  257. }
  258. curmove(r, c); /* return to saved position */
  259. newpos();
  260. buflush();
  261. }
  262. void
  263. fixpos(old, new, r, c, inc)
  264. int old, new, r, c, inc;
  265. {
  266. int o, n, nv;
  267. int ov, nc;
  268. char col;
  269. nc = 0;
  270. if (old * new >= 0) {
  271. ov = abs(old);
  272. nv = abs(new);
  273. col = (old + new > 0 ? 'r' : 'w');
  274. o = (ov - 1) / 5;
  275. n = (nv - 1) / 5;
  276. if (o == n) {
  277. if (o == 2)
  278. nc = c + 2;
  279. if (o == 1)
  280. nc = c < 54 ? c : c + 1;
  281. if (o == 0)
  282. nc = c < 54 ? c + 1 : c;
  283. if (ov > nv)
  284. fixcol(r + inc * (nv - n * 5), nc, abs(ov - nv), ' ', inc);
  285. else
  286. fixcol(r + inc * (ov - o * 5), nc, abs(ov - nv), col, inc);
  287. return;
  288. } else {
  289. if (c < 54) {
  290. if (o + n == 1) {
  291. if (n) {
  292. fixcol(r, c, abs(nv - 5), col, inc);
  293. if (ov != 5)
  294. fixcol(r + inc * ov, c + 1,
  295. abs(ov - 5), col, inc);
  296. } else {
  297. fixcol(r, c, abs(ov - 5), ' ', inc);
  298. if (nv != 5)
  299. fixcol(r + inc * nv, c + 1,
  300. abs(nv - 5), ' ', inc);
  301. }
  302. return;
  303. }
  304. if (n == 2) {
  305. if (ov != 10)
  306. fixcol(r + inc * (ov - 5), c,
  307. abs(ov - 10), col, inc);
  308. fixcol(r, c + 2, abs(nv - 10), col, inc);
  309. } else {
  310. if (nv != 10)
  311. fixcol(r + inc * (nv - 5), c,
  312. abs(nv - 10), ' ', inc);
  313. fixcol(r, c + 2, abs(ov - 10), ' ', inc);
  314. }
  315. return;
  316. }
  317. if (n > o) {
  318. fixcol(r + inc * (ov % 5), c + o, abs(5 * n - ov), col, inc);
  319. if (nv != 5 * n)
  320. fixcol(r, c + n, abs(5 * n - nv), col, inc);
  321. } else {
  322. fixcol(r + inc * (nv % 5), c + n, abs(5 * n - nv), ' ', inc);
  323. if (ov != 5 * o)
  324. fixcol(r, c + o, abs(5 * o - ov), ' ', inc);
  325. }
  326. return;
  327. }
  328. }
  329. nv = abs(new);
  330. fixcol(r, c + 1, nv, new > 0 ? 'r' : 'w', inc);
  331. if (abs(old) <= abs(new))
  332. return;
  333. fixcol(r + inc * new, c + 1, abs(old + new), ' ', inc);
  334. }
  335. void
  336. fixcol(r, c, l, ch, inc)
  337. int l, ch, r, c, inc;
  338. {
  339. int i;
  340. curmove(r, c);
  341. fancyc(ch);
  342. for (i = 1; i < l; i++) {
  343. curmove(curr + inc, curc - 1);
  344. fancyc(ch);
  345. }
  346. }
  347. void
  348. curmove(r, c)
  349. int r, c;
  350. {
  351. if (curr == r && curc == c)
  352. return;
  353. if (realr == -1) {
  354. realr = curr;
  355. realc = curc;
  356. }
  357. curr = r;
  358. curc = c;
  359. }
  360. void
  361. newpos()
  362. {
  363. int r; /* destination row */
  364. int c; /* destination column */
  365. int mode = -1; /* mode of movement */
  366. int count = 1000; /* character count */
  367. int i; /* index */
  368. int n; /* temporary variable */
  369. char *m; /* string containing CM movement */
  370. m = NULL;
  371. if (realr == -1) /* see if already there */
  372. return;
  373. r = curr; /* set current and dest. positions */
  374. c = curc;
  375. curr = realr;
  376. curc = realc;
  377. /* double check position */
  378. if (curr == r && curc == c) {
  379. realr = realc = -1;
  380. return;
  381. }
  382. if (CM) { /* try CM to get there */
  383. mode = 0;
  384. m = (char *) tgoto(CM, c, r);
  385. count = strlen(m);
  386. }
  387. /* try HO and local movement */
  388. if (HO && (n = r + c * lND + lHO) < count) {
  389. mode = 1;
  390. count = n;
  391. }
  392. /* try various LF combinations */
  393. if (r >= curr) {
  394. /* CR, LF, and ND */
  395. if ((n = (r - curr) + c * lND + 1) < count) {
  396. mode = 2;
  397. count = n;
  398. }
  399. /* LF, ND */
  400. if (c >= curc && (n = (r - curr) + (c - curc) * lND) < count) {
  401. mode = 3;
  402. count = n;
  403. }
  404. /* LF, BS */
  405. if (c < curc && (n = (r - curr) + (curc - c) * lBC) < count) {
  406. mode = 4;
  407. count = n;
  408. }
  409. }
  410. /* try corresponding UP combinations */
  411. if (r < curr) {
  412. /* CR, UP, and ND */
  413. if ((n = (curr - r) * lUP + c * lND + 1) < count) {
  414. mode = 5;
  415. count = n;
  416. }
  417. /* UP and ND */
  418. if (c >= curc && (n = (curr - r) * lUP + (c - curc) * lND) < count) {
  419. mode = 6;
  420. count = n;
  421. }
  422. /* UP and BS */
  423. if (c < curc && (n = (curr - r) * lUP + (curc - c) * lBC) < count) {
  424. mode = 7;
  425. count = n;
  426. }
  427. }
  428. /* space over */
  429. if (curr == r && c > curc && linect[r] < curc && c - curc < count)
  430. mode = 8;
  431. switch (mode) {
  432. case -1: /* error! */
  433. write(2, "\r\nInternal cursor error.\r\n", 26);
  434. getout(0);
  435. /* direct cursor motion */
  436. case 0:
  437. tputs(m, abs(curr - r), addbuf);
  438. break;
  439. /* relative to "home" */
  440. case 1:
  441. tputs(HO, r, addbuf);
  442. for (i = 0; i < r; i++)
  443. addbuf('\012');
  444. for (i = 0; i < c; i++)
  445. tputs(ND, 1, addbuf);
  446. break;
  447. /* CR and down and over */
  448. case 2:
  449. addbuf('\015');
  450. for (i = 0; i < r - curr; i++)
  451. addbuf('\012');
  452. for (i = 0; i < c; i++)
  453. tputs(ND, 1, addbuf);
  454. break;
  455. /* down and over */
  456. case 3:
  457. for (i = 0; i < r - curr; i++)
  458. addbuf('\012');
  459. for (i = 0; i < c - curc; i++)
  460. tputs(ND, 1, addbuf);
  461. break;
  462. /* down and back */
  463. case 4:
  464. for (i = 0; i < r - curr; i++)
  465. addbuf('\012');
  466. for (i = 0; i < curc - c; i++)
  467. addbuf('\010');
  468. break;
  469. /* CR and up and over */
  470. case 5:
  471. addbuf('\015');
  472. for (i = 0; i < curr - r; i++)
  473. tputs(UP, 1, addbuf);
  474. for (i = 0; i < c; i++)
  475. tputs(ND, 1, addbuf);
  476. break;
  477. /* up and over */
  478. case 6:
  479. for (i = 0; i < curr - r; i++)
  480. tputs(UP, 1, addbuf);
  481. for (i = 0; i < c - curc; i++)
  482. tputs(ND, 1, addbuf);
  483. break;
  484. /* up and back */
  485. case 7:
  486. for (i = 0; i < curr - r; i++)
  487. tputs(UP, 1, addbuf);
  488. for (i = 0; i < curc - c; i++) {
  489. if (BC)
  490. tputs(BC, 1, addbuf);
  491. else
  492. addbuf('\010');
  493. }
  494. break;
  495. /* safe space */
  496. case 8:
  497. for (i = 0; i < c - curc; i++)
  498. addbuf(' ');
  499. }
  500. /* fix positions */
  501. curr = r;
  502. curc = c;
  503. realr = -1;
  504. realc = -1;
  505. }
  506. void
  507. clear()
  508. {
  509. int i;
  510. /* double space if can't clear */
  511. if (CL == 0) {
  512. writel("\n\n");
  513. return;
  514. }
  515. curr = curc = 0; /* fix position markers */
  516. realr = realc = -1;
  517. for (i = 0; i < 24; i++)/* clear line counts */
  518. linect[i] = -1;
  519. buffnum = -1; /* ignore leftover buffer contents */
  520. tputs(CL, CO, addbuf); /* put CL in buffer */
  521. }
  522. void
  523. fancyc(c)
  524. char c; /* character to output */
  525. {
  526. int sp; /* counts spaces in a tab */
  527. if (c == '\007') { /* bells go in blindly */
  528. addbuf(c);
  529. return;
  530. }
  531. /* process tabs, use spaces if the tab should be erasing things,
  532. * otherwise use cursor movement routines. Note this does not use
  533. * hardware tabs at all. */
  534. if (c == '\t') {
  535. sp = (curc + 8) & (~7); /* compute spaces */
  536. /* check line length */
  537. if (linect[curr] >= curc || sp < 4) {
  538. for (; sp > curc; sp--)
  539. addbuf(' ');
  540. curc = sp; /* fix curc */
  541. } else
  542. curmove(curr, sp);
  543. return;
  544. }
  545. /* do newline be calling newline */
  546. if (c == '\n') {
  547. newline();
  548. return;
  549. }
  550. /* ignore any other control chars */
  551. if (c < ' ')
  552. return;
  553. /* if an erasing space or non-space, just add it to buffer. Otherwise
  554. * use cursor movement routine, so that multiple spaces will be
  555. * grouped together */
  556. if (c > ' ' || linect[curr] >= curc) {
  557. newpos(); /* make sure position correct */
  558. addbuf(c); /* add character to buffer */
  559. /* fix line length */
  560. if (c == ' ' && linect[curr] == curc)
  561. linect[curr]--;
  562. else
  563. if (linect[curr] < curc)
  564. linect[curr] = curc;
  565. curc++; /* fix curc */
  566. } else
  567. /* use cursor movement routine */
  568. curmove(curr, curc + 1);
  569. }
  570. void
  571. clend()
  572. {
  573. int i;
  574. if (CD) {
  575. tputs(CD, CO - curr, addbuf);
  576. for (i = curr; i < LI; i++)
  577. linect[i] = -1;
  578. return;
  579. }
  580. curmove(i = curr, 0);
  581. cline();
  582. while (curr < LI - 1) {
  583. curmove(curr + 1, 0);
  584. if (linect[curr] > -1)
  585. cline();
  586. }
  587. curmove(i, 0);
  588. }
  589. void
  590. cline()
  591. {
  592. int c;
  593. if (curc > linect[curr])
  594. return;
  595. newpos();
  596. if (CE) {
  597. tputs(CE, 1, addbuf);
  598. linect[curr] = curc - 1;
  599. } else {
  600. c = curc - 1;
  601. while (linect[curr] > c) {
  602. addbuf(' ');
  603. curc++;
  604. linect[curr]--;
  605. }
  606. curmove(curr, c + 1);
  607. }
  608. }
  609. void
  610. newline()
  611. {
  612. cline();
  613. if (curr == LI - 1)
  614. curmove(begscr, 0);
  615. else
  616. curmove(curr + 1, 0);
  617. }
  618. int
  619. getcaps(s)
  620. const char *s;
  621. {
  622. char *code; /* two letter code */
  623. char ***cap; /* pointer to cap string */
  624. char *bufp; /* pointer to cap buffer */
  625. char tentry[1024]; /* temporary uncoded caps buffer */
  626. tgetent(tentry, s); /* get uncoded termcap entry */
  627. LI = tgetnum("li"); /* get number of lines */
  628. if (LI == -1)
  629. LI = 12;
  630. CO = tgetnum("co"); /* get number of columns */
  631. if (CO == -1)
  632. CO = 65;
  633. bufp = tbuf; /* get padding character */
  634. tgetstr("pc", &bufp);
  635. if (bufp != tbuf)
  636. PC = *tbuf;
  637. else
  638. PC = 0;
  639. bufp = tbuf; /* get string entries */
  640. cap = tstr;
  641. for (code = tcap; *code; code += 2)
  642. **cap++ = (char *) tgetstr(code, &bufp);
  643. /* get pertinent lengths */
  644. if (HO)
  645. lHO = strlen(HO);
  646. if (BC)
  647. lBC = strlen(BC);
  648. else
  649. lBC = 1;
  650. if (UP)
  651. lUP = strlen(UP);
  652. if (ND)
  653. lND = strlen(ND);
  654. if (LI < 24 || CO < 72 || !(CL && UP && ND))
  655. return (0);
  656. linect = (int *) calloc(LI + 1, sizeof(int));
  657. if (linect == NULL) {
  658. write(2, "\r\nOut of memory!\r\n", 18);
  659. getout(0);
  660. }
  661. return (1);
  662. }