home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume28 / screen32 / part02 < prev    next >
Encoding:
Text File  |  1992-02-08  |  55.0 KB  |  2,468 lines

  1. Newsgroups: comp.sources.misc
  2. From: jnweiger@immd4.informatik.uni-erlangen.de (Juergen Weigert)
  3. Subject:  v28i019:  screen-3.2 - multiple windows on an ASCII terminal, v3.2, Part02/11
  4. Message-ID: <1992Feb9.223428.6445@sparky.imd.sterling.com>
  5. X-Md4-Signature: 5e2152902254e1043a419a4454675f32
  6. Date: Sun, 9 Feb 1992 22:34:28 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jnweiger@immd4.informatik.uni-erlangen.de (Juergen Weigert)
  10. Posting-number: Volume 28, Issue 19
  11. Archive-name: screen-3.2/part02
  12. Environment: UNIX
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file screen3.2/ansi.c continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 2; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping screen3.2/ansi.c'
  32. else
  33. echo 'x - continuing file screen3.2/ansi.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'screen3.2/ansi.c' &&
  35. X    x--;
  36. X  while (x > 0 && !curr->tabs[x])
  37. X    x--;
  38. X  GotoPos(x, curr->y);
  39. X  curr->x = x;
  40. }
  41. X
  42. static void ClearScreen()
  43. {
  44. X  register int i;
  45. X  register char **ppi = curr->image, **ppa = curr->attr, **ppf = curr->font;
  46. X
  47. X  for (i = 0; i < rows; ++i)
  48. X    {
  49. X      AddLineToHist(curr, ppi, ppa, ppf);
  50. X      bclear(*ppi++, cols);
  51. X      bzero(*ppa++, cols);
  52. X      bzero(*ppf++, cols);
  53. X    }
  54. X  if (display)
  55. X    {
  56. X      PutStr(CL);
  57. X      screenx = screeny = 0;
  58. X      lp_missing = 0;
  59. X    }
  60. }
  61. X
  62. static void ClearFromBOS()
  63. {
  64. X  register int n, y = curr->y, x = curr->x;
  65. X
  66. X  for (n = 0; n < y; ++n)
  67. X    ClearInLine(1, n, 0, cols - 1);
  68. X  ClearInLine(1, y, 0, x);
  69. X  GotoPos(x, y);
  70. X  RestoreAttr();
  71. }
  72. X
  73. static void ClearToEOS()
  74. {
  75. X  register int n, y = curr->y, x = curr->x;
  76. X
  77. X  if (!y && !x)
  78. X    {
  79. X      ClearScreen();
  80. X      return;
  81. X    }
  82. X  if (display && CD)
  83. X    {
  84. X      PutStr(CD);
  85. X      lp_missing = 0;
  86. X    }
  87. X  ClearInLine(!CD, y, x, cols - 1);
  88. X  for (n = y + 1; n < rows; n++)
  89. X    ClearInLine(!CD, n, 0, cols - 1);
  90. X  GotoPos(x, y);
  91. X  RestoreAttr();
  92. }
  93. X
  94. static void ClearLine()
  95. {
  96. X  register int y = curr->y, x = curr->x;
  97. X
  98. X  ClearInLine(1, y, 0, cols - 1);
  99. X  GotoPos(x, y);
  100. X  RestoreAttr();
  101. }
  102. X
  103. static void ClearToEOL()
  104. {
  105. X  register int y = curr->y, x = curr->x;
  106. X
  107. X  ClearInLine(1, y, x, cols - 1);
  108. X  GotoPos(x, y);
  109. X  RestoreAttr();
  110. }
  111. X
  112. static void ClearFromBOL()
  113. {
  114. X  register int y = curr->y, x = curr->x;
  115. X
  116. X  ClearInLine(1, y, 0, x);
  117. X  GotoPos(x, y);
  118. X  RestoreAttr();
  119. }
  120. X
  121. static void ClearInLine(displ, y, x1, x2)
  122. int displ, y, x1, x2;
  123. {
  124. X  register int n;
  125. X
  126. X  if (x1 == cols)
  127. X    x1--;
  128. X  if (x2 == cols)
  129. X    x2--;
  130. X  if ((n = x2 - x1 + 1) != 0)
  131. X    {
  132. X      if (displ && display)
  133. X    {
  134. X      if (x2 == cols - 1 && CE)
  135. X        {
  136. X          GotoPos(x1, y);
  137. X          PutStr(CE);
  138. X          if (y == screenbot)
  139. X        lp_missing = 0;
  140. X        }
  141. X      else
  142. X        DisplayLine(curr->image[y], curr->attr[y], curr->font[y],
  143. X            blank, null, null, y, x1, x2);
  144. X    }
  145. X      if (curr)
  146. X    {
  147. X          bclear(curr->image[y] + x1, n);
  148. X          bzero(curr->attr[y] + x1, n);
  149. X          bzero(curr->font[y] + x1, n);
  150. X    }
  151. X    }
  152. }
  153. X
  154. static void CursorRight(n)
  155. register int n;
  156. {
  157. X  register int x = curr->x;
  158. X
  159. X  if (x == cols)
  160. X    {
  161. X      LineFeed(2);
  162. X      x = 0;
  163. X    }
  164. X  if ((curr->x += n) >= cols)
  165. X    curr->x = cols - 1;
  166. X  GotoPos(curr->x, curr->y);
  167. }
  168. X
  169. static void CursorUp(n)
  170. register int n;
  171. {
  172. X  if (curr->y < curr->top)        /* if above scrolling rgn, */
  173. X    {
  174. X      if ((curr->y -= n) < 0)        /* ignore its limits      */
  175. X         curr->y = 0;
  176. X    }
  177. X  else
  178. X    if ((curr->y -= n) < curr->top)
  179. X      curr->y = curr->top;
  180. X  GotoPos(curr->x, curr->y);
  181. }
  182. X
  183. static void CursorDown(n)
  184. register int n;
  185. {
  186. X  if (curr->y > curr->bot)        /* if below scrolling rgn, */
  187. X    {
  188. X      if ((curr->y += n) > rows - 1)    /* ignore its limits      */
  189. X        curr->y = rows - 1;
  190. X    }
  191. X  else
  192. X    if ((curr->y += n) > curr->bot)
  193. X      curr->y = curr->bot;
  194. X  GotoPos(curr->x, curr->y);
  195. }
  196. X
  197. static void CursorLeft(n)
  198. register int n;
  199. {
  200. X  if ((curr->x -= n) < 0)
  201. X    curr->x = 0;
  202. X  GotoPos(curr->x, curr->y);
  203. }
  204. X
  205. static void ASetMode(on)
  206. int on;
  207. {
  208. X  register int i;
  209. X
  210. X  for (i = 0; i < curr->NumArgs; ++i)
  211. X    {
  212. X      switch (curr->args[i])
  213. X    {
  214. X    case 4:
  215. X      curr->insert = on;
  216. X      InsertMode(on);
  217. X      break;
  218. X    }
  219. X    }
  220. }
  221. X
  222. static void SelectRendition()
  223. {
  224. X  register int i = 0, a = curr->LocalAttr;
  225. X
  226. X  do
  227. X    {
  228. X      switch (curr->args[i])
  229. X    {
  230. X    case 0:
  231. X      a = 0;
  232. X      break;
  233. X    case 1:
  234. X      a |= A_BD;
  235. X      break;
  236. X    case 2:
  237. X      a |= A_DI;
  238. X      break;
  239. X    case 3:
  240. X      a |= A_SO;
  241. X      break;
  242. X    case 4:
  243. X      a |= A_US;
  244. X      break;
  245. X    case 5:
  246. X      a |= A_BL;
  247. X      break;
  248. X    case 7:
  249. X      a |= A_RV;
  250. X      break;
  251. X    case 22:
  252. X      a &= ~(A_BD | A_SO | A_DI);
  253. X      break;
  254. X    case 23:
  255. X      a &= ~A_SO;
  256. X      break;
  257. X    case 24:
  258. X      a &= ~A_US;
  259. X      break;
  260. X    case 25:
  261. X      a &= ~A_BL;
  262. X      break;
  263. X    case 27:
  264. X      a &= ~A_RV;
  265. X      break;
  266. X    }
  267. X    } while (++i < curr->NumArgs);
  268. X  NewRendition(curr->LocalAttr = a);
  269. }
  270. X
  271. void
  272. NewRendition(new)
  273. register int new;
  274. {
  275. X  register int i, old = GlobalAttr;
  276. X
  277. X  if (!display || old == new)
  278. X    return;
  279. X  GlobalAttr = new;
  280. X  for (i = 1; i <= A_MAX; i <<= 1)
  281. X    {
  282. X      if ((old & i) && !(new & i))
  283. X    {
  284. X      PutStr(UE);
  285. X      PutStr(SE);
  286. X      PutStr(ME);
  287. X      if (new & A_DI)
  288. X        PutStr(attrtab[ATTR_DI]);
  289. X      if (new & A_US)
  290. X        PutStr(attrtab[ATTR_US]);
  291. X      if (new & A_BD)
  292. X        PutStr(attrtab[ATTR_BD]);
  293. X      if (new & A_RV)
  294. X        PutStr(attrtab[ATTR_RV]);
  295. X      if (new & A_SO)
  296. X        PutStr(attrtab[ATTR_SO]);
  297. X      if (new & A_BL)
  298. X        PutStr(attrtab[ATTR_BL]);
  299. X      return;
  300. X    }
  301. X    }
  302. X  if ((new & A_DI) && !(old & A_DI))
  303. X    PutStr(attrtab[ATTR_DI]);
  304. X  if ((new & A_US) && !(old & A_US))
  305. X    PutStr(attrtab[ATTR_US]);
  306. X  if ((new & A_BD) && !(old & A_BD))
  307. X    PutStr(attrtab[ATTR_BD]);
  308. X  if ((new & A_RV) && !(old & A_RV))
  309. X    PutStr(attrtab[ATTR_RV]);
  310. X  if ((new & A_SO) && !(old & A_SO))
  311. X    PutStr(attrtab[ATTR_SO]);
  312. X  if ((new & A_BL) && !(old & A_BL))
  313. X    PutStr(attrtab[ATTR_BL]);
  314. }
  315. X
  316. void
  317. SaveSetAttr(newattr, newcharset)
  318. int newattr, newcharset;
  319. {
  320. X  NewRendition(newattr);
  321. X  NewCharset(newcharset);
  322. }
  323. X
  324. void
  325. RestoreAttr()
  326. {
  327. X  NewRendition(curr->LocalAttr);
  328. X  NewCharset(curr->charsets[curr->LocalCharset]);
  329. }
  330. X
  331. static void FillWithEs()
  332. {
  333. X  register int i;
  334. X  register char *p, *ep;
  335. X
  336. X  curr->y = curr->x = 0;
  337. X  for (i = 0; i < rows; ++i)
  338. X    {
  339. X      bzero(curr->attr[i], cols);
  340. X      bzero(curr->font[i], cols);
  341. X      p = curr->image[i];
  342. X      ep = p + cols;
  343. X      while (p < ep)
  344. X    *p++ = 'E';
  345. X    }
  346. X  if (display)
  347. X    Redisplay(0);
  348. }
  349. X
  350. /*
  351. X * if cur_only, we only redisplay current line, as a full refresh is
  352. X * too expensive.
  353. X */
  354. void Redisplay(cur_only)
  355. int cur_only;
  356. {
  357. X  register int i, stop;
  358. X
  359. X  PutStr(CL);
  360. X  screenx = screeny = 0;
  361. X  lp_missing = 0;
  362. X  stop = rows; i = 0;
  363. X  if (cur_only)
  364. X    {
  365. X      i = stop = curr->y;
  366. X      stop++;
  367. X    }
  368. X  for (; i < stop; ++i)
  369. X    {
  370. X      if (in_ovl)
  371. X    (*ovl_RedisplayLine)(i, 0, cols - 1, 1);
  372. X      else
  373. X        DisplayLine(blank, null, null, curr->image[i], curr->attr[i],
  374. X            curr->font[i], i, 0, cols - 1);
  375. X    }
  376. X  if (!in_ovl)
  377. X    {
  378. X      GotoPos(curr->x, curr->y);
  379. X      NewRendition(curr->LocalAttr);
  380. X      NewCharset(curr->charsets[curr->LocalCharset]);
  381. X    }
  382. }
  383. X
  384. void
  385. DisplayLine(os, oa, of, s, as, fs, y, from, to)
  386. int from, to, y;
  387. register char *os, *oa, *of, *s, *as, *fs;
  388. {
  389. X  register int x;
  390. X  int last2flag = 0, delete_lp = 0;
  391. X
  392. X  if (!LP && y == screenbot && to == cols - 1)
  393. X    if (lp_missing
  394. X    || s[to] != os[to] || as[to] != oa[to] || of[to] != fs[to])
  395. X      {
  396. X    if ((IC || IM) && (from < to || !in_ovl))
  397. X      {
  398. X        if ((to -= 2) < from - 1)
  399. X          from--;
  400. X        last2flag = 1;
  401. X        lp_missing = 0;
  402. X      }
  403. X    else
  404. X      {
  405. X        to--;
  406. X        delete_lp = (CE || DC || CDC);
  407. X        lp_missing = (s[to] != ' ' || as[to] || fs[to]);
  408. X      }
  409. X      }
  410. X    else
  411. X      to--;
  412. X  for (x = from; x <= to; ++x)
  413. X    {
  414. X      if (s[x] == os[x] && as[x] == oa[x] && of[x] == fs[x])
  415. X    continue;
  416. X      GotoPos(x, y);
  417. X      NewRendition(as[x]);
  418. X      NewCharset(fs[x]);
  419. X      PUTCHAR(s[x]);
  420. X    }
  421. X  if (last2flag)
  422. X    {
  423. X      GotoPos(x, y);
  424. X      NewRendition(as[x + 1]);
  425. X      NewCharset(fs[x + 1]);
  426. X      PUTCHAR(s[x + 1]);
  427. X      GotoPos(x, y);
  428. X      NewRendition(as[x]);
  429. X      NewCharset(fs[x]);
  430. X      INSERTCHAR(s[x]);
  431. X    }
  432. X  else if (delete_lp)
  433. X    {
  434. X      if (DC)
  435. X    PutStr(DC);
  436. X      else if (CDC)
  437. X    CPutStr(CDC, 1);
  438. X      else if (CE)
  439. X    PutStr(CE);
  440. X    }
  441. }
  442. X
  443. void
  444. RefreshLine(y, from, to)
  445. int y, from, to;
  446. {
  447. X  char *oi = null;
  448. X
  449. X  if (CE && to == screenwidth-1)
  450. X    {
  451. X      GotoPos(from, y);
  452. X      PutStr(CE);
  453. X      oi = blank;
  454. X    }
  455. X  if (in_ovl)
  456. X    (*ovl_RedisplayLine)(y, from, to, (oi == blank));
  457. X  else
  458. X    DisplayLine(oi, null, null, curr->image[y], curr->attr[y],
  459. X                curr->font[y], y, from, to);
  460. }
  461. X
  462. static void RedisplayLine(os, oa, of, y, from, to)
  463. int from, to, y;
  464. char *os, *oa, *of;
  465. {
  466. X  DisplayLine(os, oa, of, curr->image[y], curr->attr[y],
  467. X          curr->font[y], y, from, to);
  468. X  NewRendition(curr->LocalAttr);
  469. X  NewCharset(curr->charsets[curr->LocalCharset]);
  470. }
  471. X
  472. void
  473. FixLP(x2, y2)
  474. register int x2, y2;
  475. {
  476. X  register struct win *p = curr;
  477. X
  478. X  GotoPos(x2, y2);
  479. X  SaveSetAttr(p->attr[y2][x2], p->font[y2][x2]);
  480. X  PUTCHAR(p->image[y2][x2]);
  481. X  RestoreAttr();
  482. X  lp_missing = 0;
  483. }
  484. X
  485. void
  486. CheckLP(n_ch)
  487. char n_ch;
  488. {
  489. X  register int y = screenbot, x = cols - 1;
  490. X  register char n_at, n_fo, o_ch, o_at, o_fo;
  491. X
  492. X  o_ch = curr->image[y][x];
  493. X  o_at = curr->attr[y][x];
  494. X  o_fo = curr->font[y][x];
  495. X
  496. X  n_at = curr->LocalAttr;
  497. X  n_fo = curr->charsets[curr->LocalCharset];
  498. X
  499. X  lp_missing = 0;
  500. X  if (n_ch == o_ch && n_at == o_at && n_fo == o_fo)
  501. X    {
  502. X      return;
  503. X    }
  504. X  if (n_ch != ' ' || n_at || n_fo)
  505. X    lp_missing = 1;
  506. X  if (o_ch != ' ' || o_at || o_fo)
  507. X    {
  508. X      if (DC)
  509. X    PutStr(DC);
  510. X      else if (CDC)
  511. X    CPutStr(CDC, 1);
  512. X      else if (CE)
  513. X    PutStr(CE);
  514. X      else
  515. X    lp_missing = 1;
  516. X    }
  517. }
  518. X
  519. static void FindAKA()
  520. {
  521. X  register char *cp, *line, ch;
  522. X  register struct win *wp = curr;
  523. X  register int len = strlen(wp->cmd);
  524. X  int y;
  525. X
  526. X  y = (wp->autoaka > 0 && wp->autoaka <= wp->height) ? wp->autoaka - 1 : wp->y;
  527. X  cols = wp->width;
  528. X try_line:
  529. X  cp = line = wp->image[y];
  530. X  if (wp->autoaka > 0 && (ch = *wp->cmd) != '\0')
  531. X    {
  532. X      for (;;)
  533. X    {
  534. X      if ((cp = index(cp, ch)) != NULL
  535. X          && !strncmp(cp, wp->cmd, len))
  536. X        break;
  537. X      if (!cp || ++cp - line >= cols - len)
  538. X        {
  539. X          if (++y == wp->autoaka && y < rows)
  540. X        goto try_line;
  541. X          return;
  542. X        }
  543. X    }
  544. X      cp += len;
  545. X    }
  546. X  for (len = cols - (cp - line); len && *cp == ' '; len--, cp++)
  547. X    ;
  548. X  if (len)
  549. X    {
  550. X      if (wp->autoaka > 0 && (*cp == '!' || *cp == '%' || *cp == '^'))
  551. X    wp->autoaka = -1;
  552. X      else
  553. X    wp->autoaka = 0;
  554. X      line = wp->cmd + wp->akapos;
  555. X      while (len && *cp != ' ')
  556. X    {
  557. X      if ((*line++ = *cp++) == '/')
  558. X        line = wp->cmd + wp->akapos;
  559. X      len--;
  560. X    }
  561. X      *line = '\0';
  562. X    }
  563. X  else
  564. X    wp->autoaka = 0;
  565. }
  566. X
  567. X
  568. /* We dont use HS status line with Input.
  569. X * If we would use it, then we should check e_tgetflag("es") if
  570. X * we are allowed to use esc sequences there.
  571. X * For now, we hope that Goto(,,STATLINE,0) brings us in the bottom
  572. X * line. jw.
  573. X */
  574. X
  575. static char inpbuf[101];
  576. static int inplen;
  577. static int inpmaxlen;
  578. static char *inpstring;
  579. static int inpstringlen;
  580. static void (*inpfinfunc)();
  581. X
  582. void
  583. Input(istr, len, finfunc)
  584. char *istr;
  585. int len;
  586. void (*finfunc)();
  587. {
  588. X  int maxlen;
  589. X
  590. X  inpstring = istr;
  591. X  inpstringlen = strlen(istr);
  592. X  if (len > 100)
  593. X    len = 100;
  594. X  maxlen = screenwidth - inpstringlen;
  595. X  if (!LP && STATLINE == screenbot)
  596. X    maxlen--;
  597. X  if (len > maxlen)
  598. X    len = maxlen;
  599. X  if (len < 2)
  600. X    {
  601. X      Msg(0, "Width too small");
  602. X      return;
  603. X    }
  604. X  inpmaxlen = len;
  605. X  inpfinfunc = finfunc;
  606. X  InitOverlayPage(process_inp_input, inpRedisplayLine, (int (*)())0, 1);
  607. X  inplen = 0;
  608. X  GotoPos(0, STATLINE);
  609. X  if (CE)
  610. X    PutStr(CE);
  611. X  else
  612. X    {
  613. X      DisplayLine(curr->image[screeny], curr->attr[screeny],
  614. X          curr->font[screeny],
  615. X          blank, null, null, screeny, 0, cols - 1);
  616. X    }
  617. X  inpRedisplayLine(STATLINE, 0, inpstringlen - 1, 0);
  618. X  GotoPos(inpstringlen, STATLINE);
  619. }
  620. X
  621. static void
  622. process_inp_input(ppbuf, plen)
  623. char **ppbuf;
  624. int *plen;
  625. {
  626. X  int len, x;
  627. X  char *pbuf;
  628. X  char ch;
  629. X
  630. X  if (ppbuf == 0)
  631. X    {
  632. X      AbortInp();
  633. X      return;
  634. X    }
  635. X  x = inpstringlen+inplen;
  636. X  len = *plen;
  637. X  pbuf = *ppbuf;
  638. X  while (len)
  639. X    {
  640. X      ch = *pbuf++;
  641. X      len--;
  642. X      if (ch >= ' ' && ch <= '~' && inplen < inpmaxlen)
  643. X    {
  644. X      inpbuf[inplen++] = ch;
  645. X        GotoPos(x, STATLINE);
  646. X      SaveSetAttr(A_SO, ASCII);
  647. X      PUTCHAR(ch);
  648. X      x++;
  649. X    }
  650. X      else if ((ch == '\b' || ch == 0177) && inplen > 0)
  651. X    {
  652. X      inplen--;
  653. X      x--;
  654. X        GotoPos(x, STATLINE);
  655. X      SaveSetAttr(0, ASCII);
  656. X      PUTCHAR(' ');
  657. X        GotoPos(x, STATLINE);
  658. X    }
  659. X      else if (ch == '\004' || ch == '\003' || ch == '\000' || ch == '\n' || ch == '\r')
  660. X    {
  661. X          if (ch != '\n' && ch != '\r')
  662. X        inplen = 0;
  663. X      inpbuf[inplen] = 0;
  664. X          AbortInp(); /* redisplays... */
  665. X          (*inpfinfunc)(inpbuf, inplen);
  666. X      break;
  667. X    }
  668. X    }
  669. X  *ppbuf = pbuf;
  670. X  *plen = len;
  671. }
  672. X
  673. static void
  674. AbortInp()
  675. {
  676. X  in_ovl = 0;    /* So we can use RefreshLine() */
  677. X  RefreshLine(STATLINE, 0, screenwidth-1);
  678. X  ExitOverlayPage();
  679. }
  680. X
  681. static void
  682. inpRedisplayLine(y, xs, xe, isblank)
  683. int y, xs, xe, isblank;
  684. {
  685. X  int q, r, s, l, v;
  686. X
  687. X  if (y != STATLINE)
  688. X    return;
  689. X  inpbuf[inplen] = 0;
  690. X  GotoPos(xs,y);
  691. X  q = xs;
  692. X  v = xe - xs + 1;
  693. X  s = 0;
  694. X  r = inpstringlen;
  695. X  if (v > 0 && q < r)
  696. X    {
  697. X      SaveSetAttr(A_SO, ASCII);
  698. X      l = v;
  699. X      if (l > r-q)
  700. X    l = r-q;
  701. X      printf("%-*.*s", l, l, inpstring + q - s);
  702. X      q += l;
  703. X      v -= l;
  704. X    }
  705. X  s = r;
  706. X  r += inplen;
  707. X  if (v > 0 && q < r)
  708. X    {
  709. X      SaveSetAttr(A_SO, ASCII);
  710. X      l = v;
  711. X      if (l > r-q)
  712. X    l = r-q;
  713. X      printf("%-*.*s", l, l, inpbuf + q - s);
  714. X      q += l;
  715. X      v -= l;
  716. X    }
  717. X  s = r;
  718. X  r = screenwidth;
  719. X  if (!isblank && v > 0 && q < r)
  720. X    {
  721. X      SaveSetAttr(0, ASCII);
  722. X      l = v;
  723. X      if (l > r-q)
  724. X    l = r-q;
  725. X      printf("%-*.*s", l, l, "");
  726. X      q += l;
  727. X    }
  728. X  SetLastPos(q, y);
  729. }
  730. X
  731. static void
  732. AKAfin(buf, len)
  733. char *buf;
  734. int len;
  735. {
  736. X  if (len)
  737. X    {
  738. X      strcpy(curr->cmd + curr->akapos, buf);
  739. X    }
  740. }
  741. X
  742. void
  743. InputAKA()
  744. {
  745. X  void Input(), AKAfin();
  746. X
  747. X  Input("Set window's a.k.a. to: ", 20, AKAfin);
  748. }
  749. X
  750. static void
  751. Colonfin(buf, len)
  752. char *buf;
  753. int len;
  754. {
  755. X  if (len)
  756. X    RcLine(buf);
  757. }
  758. X
  759. void
  760. InputColon()
  761. {
  762. X  void Input(), Colonfin();
  763. X
  764. X  Input(":", 100, Colonfin);
  765. }
  766. X
  767. void
  768. MakeBlankLine(p, n)
  769. register char *p;
  770. register int n;
  771. {
  772. X  while (n--)
  773. X    *p++ = ' ';
  774. }
  775. X
  776. void
  777. MakeStatus(msg)
  778. char *msg;
  779. {
  780. X  register char *s, *t;
  781. X  register int max, ti;
  782. X
  783. X  SetCurr(fore);
  784. X  display = 1;
  785. X  if (!(max = HS))
  786. X    {
  787. X      max = !LP ? cols - 1 : cols;
  788. X    }
  789. X  if (status)
  790. X    {
  791. X      if (!BellDisplayed)
  792. X    {
  793. X      ti = time((time_t *) 0) - TimeDisplayed;
  794. X      if (ti < MsgMinWait)
  795. X        sleep(MsgMinWait - ti);
  796. X    }
  797. X      RemoveStatus();
  798. X    }
  799. X  for (s = t = msg; *s && t - msg < max; ++s)
  800. X    if (*s == BELL)
  801. X      PutStr(BL);
  802. X    else if (*s >= ' ' && *s <= '~')
  803. X      *t++ = *s;
  804. X  *t = '\0';
  805. X  if (t > msg)
  806. X    {
  807. X      strncpy(LastMsg, msg, maxwidth);
  808. X      status = 1;
  809. X      status_lastx = screenx;
  810. X      status_lasty = screeny;
  811. X      StatLen = t - msg;
  812. X      if (!HS)
  813. X    {
  814. X      GotoPos(0, STATLINE);
  815. X          SaveSetAttr(A_SO, ASCII);
  816. X      InsertMode(0);
  817. X      printf("%s", msg);
  818. X          screenx = -1;
  819. X    }
  820. X      else
  821. X    {
  822. X      debug("HS:");
  823. X          SaveSetAttr(0, ASCII);
  824. X      InsertMode(0);
  825. X      CPutStr(TS, 0);
  826. X      printf("%s", msg);
  827. X      PutStr(FS);
  828. X    }
  829. X      (void) fflush(stdout);
  830. X      (void) time(&TimeDisplayed);
  831. X    }
  832. }
  833. X
  834. void
  835. RemoveStatus()
  836. {
  837. X  if (!status)
  838. X    return;
  839. X  status = 0;
  840. X  BellDisplayed = 0;
  841. X  SetCurr(fore);
  842. X  display = 1;
  843. X  if (!HS)
  844. X    {
  845. X      GotoPos(0, STATLINE);
  846. X      if (in_ovl)
  847. X    (*ovl_RedisplayLine)(STATLINE, 0, StatLen - 1, 0);
  848. X      else
  849. X    RedisplayLine(null, null, null, STATLINE, 0, StatLen - 1);
  850. X      GotoPos(status_lastx, status_lasty);
  851. X    }
  852. X  else
  853. X    {
  854. X      SaveSetAttr(0, ASCII);
  855. X      PutStr(DS);
  856. X    }
  857. }
  858. X
  859. void
  860. ClearDisplay()
  861. {
  862. X  PutStr(CL);
  863. X  screeny = screenx = 0;
  864. X  fflush(stdout);
  865. }
  866. X
  867. static void SetCurr(wp)
  868. struct win *wp;
  869. {
  870. X  curr = wp;
  871. X  cols = curr->width;
  872. X  rows = curr->height;
  873. X  display = curr->active;
  874. }
  875. X
  876. void
  877. InitOverlayPage(pro, red, rewrite, blockfore)
  878. void (*pro)();
  879. void (*red)();
  880. int (*rewrite)();
  881. int blockfore;
  882. {
  883. X  RemoveStatus();
  884. X  SetOvlCurr();
  885. X  ChangeScrollRegion(0, screenheight - 1);
  886. X  SetFlow(1);
  887. X  ovl_process = pro;
  888. X  ovl_RedisplayLine = red;
  889. X  ovl_Rewrite = rewrite;
  890. X  ovl_blockfore = blockfore;
  891. X  curr->active = 0;
  892. X  in_ovl = 1;
  893. }
  894. X
  895. void
  896. ExitOverlayPage()
  897. {
  898. X  ChangeScrollRegion(curr->top, curr->bot);
  899. X  GotoPos(curr->x, curr->y);
  900. X  RestoreAttr();
  901. X  SetFlow(curr->flow & FLOW_NOW);
  902. X  curr->active = 1;
  903. X  in_ovl = 0;
  904. }
  905. X
  906. void
  907. SetOvlCurr()
  908. {
  909. X  SetCurr(fore);
  910. X  SaveSetAttr(0, ASCII);
  911. X  InsertMode(0);
  912. X  display = 1;
  913. }
  914. X
  915. void
  916. SetLastPos(x,y)
  917. int x,y;
  918. {
  919. X  screenx = x;
  920. X  screeny = y;
  921. }
  922. X
  923. void
  924. WSresize(width, height)
  925. int width, height;
  926. {
  927. X  debug2("(display=%d:WSresize says:'%s'\n", display, tgoto(WS, width, height));
  928. X  PutStr(tgoto(WS, width, height));
  929. }
  930. X
  931. void
  932. ChangeScrollRegion(top, bot)
  933. int top, bot;
  934. {
  935. X  if (display == 0)
  936. X    return;
  937. X  if (CS == 0)
  938. X    {
  939. X      screentop = 0;
  940. X      screenbot = screenheight - 1;
  941. X      return;
  942. X    }
  943. X  if (top == screentop && bot == screenbot)
  944. X    return;
  945. X  debug2("ChangeScrollRegion: (%d - %d)\n", top, bot);
  946. X  PutStr(tgoto(CS, bot, top));
  947. X  screentop = top;
  948. X  screenbot = bot;
  949. X  screeny = screenx = -1;        /* Just in case... */
  950. }
  951. X
  952. X
  953. void AddLineToHist(wp, pi, pa, pf)
  954. struct win *wp;
  955. char **pi, **pa, **pf;
  956. {
  957. X  register char *q;
  958. X
  959. X  if (wp->histheight == 0)
  960. X    return;
  961. X  q = *pi; *pi = wp->ihist[wp->histidx]; wp->ihist[wp->histidx] = q;
  962. X  q = *pa; *pa = wp->ahist[wp->histidx]; wp->ahist[wp->histidx] = q;
  963. X  q = *pf; *pf = wp->fhist[wp->histidx]; wp->fhist[wp->histidx] = q;
  964. X  if (++wp->histidx >= wp->histheight)
  965. X    wp->histidx = 0;
  966. }
  967. X
  968. X
  969. /*
  970. X *
  971. X *  Termcap routines that use our extra_incap
  972. X *
  973. X */
  974. X
  975. /* findcap:
  976. X *   cap = capability we are looking for
  977. X *   tepp = pointer to bufferpointer
  978. X *   n = size of buffer (0 = infinity)
  979. X */
  980. X
  981. char *
  982. findcap(cap, tepp, n)
  983. char *cap;
  984. char **tepp;
  985. int n;
  986. {
  987. X  char *tep;
  988. X  char c, *p, *cp;
  989. X  int mode;    /* mode: 0=LIT  1=^  2=\x  3,4,5=\nnn */
  990. X  int num = 0, capl;
  991. X
  992. X  if (!extra_incap)
  993. X    return (0);
  994. X  tep = *tepp;
  995. X  capl = strlen(cap);
  996. X  cp = 0;
  997. X  mode = 0;
  998. X  for (p = extra_incap; *p; )
  999. X    {
  1000. X      if (strncmp(p, cap, capl) == 0)
  1001. X    {
  1002. X      p+=capl;
  1003. X      c = *p;
  1004. X      if (c && c != ':' && c != '@')
  1005. X        p++;
  1006. X      if (c == 0 || c == '@' || c == '=' || c == ':' || c == '#')
  1007. X        cp = tep;
  1008. X    }
  1009. X      while (c = *p)
  1010. X    {
  1011. X      p++;
  1012. X      if (mode == 0)
  1013. X        {
  1014. X          if (c == ':')
  1015. X            break;
  1016. X          if (c == '^')
  1017. X        mode = 1;
  1018. X          if (c == '\\')
  1019. X        mode = 2;
  1020. X        }
  1021. X      else if (mode == 1)
  1022. X        {
  1023. X          c = c & 0x1f;
  1024. X          mode = 0;
  1025. X        }
  1026. X      else if (mode == 2)
  1027. X        {
  1028. X          switch(c)
  1029. X        {
  1030. X        case '0':
  1031. X        case '1':
  1032. X        case '2':
  1033. X        case '3':
  1034. X        case '4':
  1035. X        case '5':
  1036. X        case '6':
  1037. X        case '7':
  1038. X        case '8':
  1039. X        case '9':
  1040. X          mode = 3;
  1041. X          num = 0;
  1042. X          break;
  1043. X        case 'E':
  1044. X          c = 27;
  1045. X          break;
  1046. X        case 'n':
  1047. X          c = '\n';
  1048. X          break;
  1049. X        case 'r':
  1050. X          c = '\r';
  1051. X          break;
  1052. X        case 't':
  1053. X          c = '\t';
  1054. X          break;
  1055. X        case 'b':
  1056. X          c = '\b';
  1057. X          break;
  1058. X        case 'f':
  1059. X          c = '\f';
  1060. X          break;
  1061. X        }
  1062. X          if (mode == 2)
  1063. X        mode = 0;
  1064. X        }
  1065. X      if (mode > 2)
  1066. X        {
  1067. X          num = num * 8 + (c - '0');
  1068. X          if (mode++ == 5 || (*p < '0' || *p > '9'))
  1069. X        {
  1070. X          c = num;
  1071. X          mode = 0;
  1072. X        }
  1073. X        }
  1074. X      if (mode)
  1075. X        continue;
  1076. X
  1077. X      if (cp && n != 1)
  1078. X        {
  1079. X          *cp++ = c;
  1080. X          n--;
  1081. X        }
  1082. X    }
  1083. X      if (cp)
  1084. X    {
  1085. X      *cp++ = 0;
  1086. X      *tepp = cp;
  1087. X      debug2("'%s' found in extra_incap -> %s\n", cap, tep);
  1088. X      return(tep);
  1089. X    }
  1090. X    }
  1091. X  return(0);
  1092. }
  1093. X
  1094. static char *
  1095. e_tgetstr(cap, tepp)
  1096. char *cap;
  1097. char **tepp;
  1098. {
  1099. X  char *tep;
  1100. X  if (tep = findcap(cap, tepp, 0))
  1101. X    return((*tep == '@') ? 0 : tep);
  1102. X  return (tgetstr(cap, tepp));
  1103. }
  1104. X
  1105. static int
  1106. e_tgetflag(cap)
  1107. char *cap;
  1108. {
  1109. X  char buf[2], *bufp;
  1110. X  char *tep;
  1111. X  bufp = buf;
  1112. X  if (tep = findcap(cap, &bufp, 2))
  1113. X    return((*tep == '@') ? 0 : 1);
  1114. X  return (tgetflag(cap));
  1115. }
  1116. X
  1117. static int
  1118. e_tgetnum(cap)
  1119. char *cap;
  1120. {
  1121. X  char buf[20], *bufp;
  1122. X  char *tep, c;
  1123. X  int res, base = 10;
  1124. X
  1125. X  bufp = buf;
  1126. X  if (tep = findcap(cap, &bufp, 20))
  1127. X    {
  1128. X      c = *tep;
  1129. X      if (c == '@')
  1130. X    return(-1);
  1131. X      if (c == '0')
  1132. X    base = 8;
  1133. X      res = 0;
  1134. X      while ((c = *tep++) >= '0' && c <= '9')
  1135. X    res = res * base + (c - '0');
  1136. X      return(res);
  1137. X    }
  1138. X  return (tgetnum(cap));
  1139. }
  1140. SHAR_EOF
  1141. echo 'File screen3.2/ansi.c is complete' &&
  1142. chmod 0444 screen3.2/ansi.c ||
  1143. echo 'restore of screen3.2/ansi.c failed'
  1144. Wc_c="`wc -c < 'screen3.2/ansi.c'`"
  1145. test 68724 -eq "$Wc_c" ||
  1146.     echo 'screen3.2/ansi.c: original size 68724, current size' "$Wc_c"
  1147. rm -f _shar_wnt_.tmp
  1148. fi
  1149. # ============= screen3.2/ansi.h ==============
  1150. if test -f 'screen3.2/ansi.h' -a X"$1" != X"-c"; then
  1151.     echo 'x - skipping screen3.2/ansi.h (File already exists)'
  1152.     rm -f _shar_wnt_.tmp
  1153. else
  1154. > _shar_wnt_.tmp
  1155. echo 'x - extracting screen3.2/ansi.h (Text)'
  1156. sed 's/^X//' << 'SHAR_EOF' > 'screen3.2/ansi.h' &&
  1157. /* Copyright (c) 1991
  1158. X *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
  1159. X *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
  1160. X * Copyright (c) 1987 Oliver Laumann
  1161. X *
  1162. X * This program is free software; you can redistribute it and/or modify
  1163. X * it under the terms of the GNU General Public License as published by
  1164. X * the Free Software Foundation; either version 1, or (at your option)
  1165. X * any later version.
  1166. X *
  1167. X * This program is distributed in the hope that it will be useful,
  1168. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1169. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1170. X * GNU General Public License for more details.
  1171. X *
  1172. X * You should have received a copy of the GNU General Public License
  1173. X * along with this program (see the file COPYING); if not, write to the
  1174. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1175. X *
  1176. X * Noteworthy contributors to screen's design and implementation:
  1177. X *    Wayne Davison (davison@borland.com)
  1178. X *    Patrick Wolfe (pat@kai.com, kailand!pat)
  1179. X *    Bart Schaefer (schaefer@cse.ogi.edu)
  1180. X *    Nathan Glasser (nathan@brokaw.lcs.mit.edu)
  1181. X *    Larry W. Virden (lwv27%cas.BITNET@CUNYVM.CUNY.Edu)
  1182. X *    Howard Chu (hyc@hanauma.jpl.nasa.gov)
  1183. X *    Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
  1184. X *    Markku Jarvinen (mta@{cc,cs,ee}.tut.fi)
  1185. X *    Marc Boucher (marc@CAM.ORG)
  1186. X *
  1187. X ****************************************************************
  1188. X * $Id: ansi.h,v 1.2 92/02/03 02:27:39 jnweiger Exp $ FAU
  1189. X */
  1190. X
  1191. #define NATTR        6
  1192. X
  1193. #define ATTR_DI        0    /* Dim mode */
  1194. #define ATTR_US        1    /* Underscore mode */
  1195. #define ATTR_BD        2    /* Bold mode */
  1196. #define ATTR_RV        3    /* Reverse mode */
  1197. #define ATTR_SO        4    /* Standout mode */
  1198. #define ATTR_BL        5    /* Blinking */
  1199. X
  1200. #define A_DI    (1<<ATTR_DI)
  1201. #define A_US    (1<<ATTR_US)
  1202. #define A_BD    (1<<ATTR_BD)
  1203. #define A_RV    (1<<ATTR_RV)
  1204. #define A_SO    (1<<ATTR_SO)
  1205. #define A_BL    (1<<ATTR_BL)
  1206. #define A_MAX    (1<<(NATTR-1))
  1207. X
  1208. /* Types of movement used by GotoPos() */
  1209. enum move_t {
  1210. X    M_NONE,
  1211. X    M_UP,
  1212. X    M_CUP,
  1213. X    M_DO,
  1214. X    M_CDO,
  1215. X    M_LE,
  1216. X    M_CLE,
  1217. X    M_RI,
  1218. X    M_CRI,
  1219. X    M_RW,
  1220. X    M_CR    /* CR and rewrite */
  1221. };
  1222. X
  1223. #define EXPENSIVE     1000
  1224. X
  1225. #define G0             0
  1226. #define G1             1
  1227. #define G2             2
  1228. #define G3             3
  1229. X
  1230. #define ASCII         0
  1231. X
  1232. #ifdef TOPSTAT
  1233. #define STATLINE     (0)
  1234. #else
  1235. #define STATLINE     (screenheight-1)
  1236. #endif
  1237. X
  1238. SHAR_EOF
  1239. chmod 0444 screen3.2/ansi.h ||
  1240. echo 'restore of screen3.2/ansi.h failed'
  1241. Wc_c="`wc -c < 'screen3.2/ansi.h'`"
  1242. test 2276 -eq "$Wc_c" ||
  1243.     echo 'screen3.2/ansi.h: original size 2276, current size' "$Wc_c"
  1244. rm -f _shar_wnt_.tmp
  1245. fi
  1246. # ============= screen3.2/extern.h ==============
  1247. if test -f 'screen3.2/extern.h' -a X"$1" != X"-c"; then
  1248.     echo 'x - skipping screen3.2/extern.h (File already exists)'
  1249.     rm -f _shar_wnt_.tmp
  1250. else
  1251. > _shar_wnt_.tmp
  1252. echo 'x - extracting screen3.2/extern.h (Text)'
  1253. sed 's/^X//' << 'SHAR_EOF' > 'screen3.2/extern.h' &&
  1254. /* Copyright (c) 1991
  1255. X *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
  1256. X *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
  1257. X * Copyright (c) 1987 Oliver Laumann
  1258. X *
  1259. X * This program is free software; you can redistribute it and/or modify
  1260. X * it under the terms of the GNU General Public License as published by
  1261. X * the Free Software Foundation; either version 1, or (at your option)
  1262. X * any later version.
  1263. X *
  1264. X * This program is distributed in the hope that it will be useful,
  1265. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1266. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1267. X * GNU General Public License for more details.
  1268. X *
  1269. X * You should have received a copy of the GNU General Public License
  1270. X * along with this program (see the file COPYING); if not, write to the
  1271. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1272. X *
  1273. X * Noteworthy contributors to screen's design and implementation:
  1274. X *    Wayne Davison (davison@borland.com)
  1275. X *    Patrick Wolfe (pat@kai.com, kailand!pat)
  1276. X *    Bart Schaefer (schaefer@cse.ogi.edu)
  1277. X *    Nathan Glasser (nathan@brokaw.lcs.mit.edu)
  1278. X *    Larry W. Virden (lwv27%cas.BITNET@CUNYVM.CUNY.Edu)
  1279. X *    Howard Chu (hyc@hanauma.jpl.nasa.gov)
  1280. X *    Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
  1281. X *    Markku Jarvinen (mta@{cc,cs,ee}.tut.fi)
  1282. X *    Marc Boucher (marc@CAM.ORG)
  1283. X *
  1284. X ****************************************************************
  1285. X * $Id: extern.h,v 1.2 92/02/03 02:27:40 jnweiger Exp $ FAU
  1286. X */
  1287. X
  1288. /****************************************************************
  1289. X * Thanks to Christos S. Zoulas (christos@ee.cornell.edu) who 
  1290. X * mangled the screen source through 'gcc -Wall'.
  1291. X *
  1292. X * this is his extern.h
  1293. X ****************************************************************
  1294. X */
  1295. X
  1296. #ifndef MEMFUNCS_DECLARED /* bsd386 */
  1297. # ifndef SYSV
  1298. extern void bzero __P((char *, int));
  1299. # endif
  1300. # ifdef sun
  1301. extern char *memset __P((char *, int, size_t));
  1302. # endif
  1303. # ifndef bcopy
  1304. extern void bcopy __P((char *, char *, int));
  1305. # endif /* bcopy */
  1306. #endif /* MEMFUNCS_DECLARED */
  1307. struct rusage;
  1308. #ifndef WAITSTUFF_DECLARED
  1309. # ifdef BSDWAIT
  1310. union wait;
  1311. extern int wait3 __P((union wait *, int, struct rusage *));
  1312. # else
  1313. extern pid_t wait3 __P((int *, int, struct rusage *));
  1314. # endif
  1315. #endif /* WAITSTUFF_DECLARED */
  1316. extern int getdtablesize __P((void));
  1317. #ifndef REUID_DECLARED
  1318. # if !defined(NOREUID)
  1319. #  ifdef hpux
  1320. extern int setresuid __P((uid_t, uid_t, uid_t));
  1321. extern int setresgid __P((gid_t, gid_t, gid_t));
  1322. #  else
  1323. extern int setreuid __P((uid_t, uid_t));
  1324. extern int setregid __P((gid_t, gid_t));
  1325. #  endif
  1326. # endif
  1327. #endif /* REUID_DECLARED */
  1328. #ifndef CRYPT_DECLARED
  1329. extern char *crypt __P((char *, char *));
  1330. #endif /* CRYPT_DECLARED */
  1331. #ifdef sun
  1332. extern int getpgrp __P((int));
  1333. #endif
  1334. #ifndef MKNOD_DECLARED
  1335. # ifdef POSIX
  1336. extern int mknod __P((const char *, mode_t, dev_t));
  1337. # else
  1338. extern int mknod __P((char *, int, int));
  1339. # endif
  1340. #endif /* MKNOD_DECLARED */
  1341. #ifndef PUTENV_DECLARED
  1342. extern int putenv __P((char *));
  1343. #endif /* PUTENV_DECLARED */
  1344. #ifndef KILLSTUFF_DECLARED
  1345. extern int kill __P((pid_t, int));
  1346. # ifndef SYSV
  1347. extern int killpg __P((pid_t, int));
  1348. # endif
  1349. #endif /* KILLSTUFF_DECLARED */
  1350. extern int tgetent __P((char *, char *));
  1351. extern int tgetnum __P((char *));
  1352. extern int tgetflag __P((char *));
  1353. extern void tputs __P((char *, int, void (*)(int)));
  1354. #ifdef notdef
  1355. extern unsigned char     *_flsbuf __P((unsigned char, FILE *));
  1356. #endif
  1357. #ifndef NeXT
  1358. extern int _flsbuf __P((unsigned char, FILE *));
  1359. #endif
  1360. # ifdef POSIX
  1361. extern pid_t setsid __P((void));
  1362. #  ifndef SETPGID_DECLARED
  1363. extern int setpgid __P((pid_t, int));
  1364. #  endif /* SETPGID_DECLARED */
  1365. extern int tcsetpgrp __P((int, pid_t));
  1366. # endif /* POSIX */
  1367. extern pid_t getpid __P((void));
  1368. extern uid_t getuid __P((void)); 
  1369. extern uid_t geteuid __P((void));
  1370. extern gid_t getgid __P((void)); 
  1371. extern gid_t getegid __P((void));
  1372. extern int isatty __P((int)); 
  1373. #ifdef notdef
  1374. extern int chown __P((const char *, uid_t, gid_t)); 
  1375. #endif
  1376. #ifndef GETHOSTNAME_DECLARED
  1377. extern int gethostname __P((char *, size_t));
  1378. #endif /* GETHOSTNAME_DECLARED */
  1379. extern off_t lseek __P((int, off_t, int));
  1380. #if defined(sun) && !defined(__GNUC__)        /* sun's exit returns ??? */
  1381. extern int exit __P((int));
  1382. #else
  1383. extern void exit __P((int));
  1384. #endif
  1385. extern char *getwd __P((char *));
  1386. extern char *getenv __P((const char *));
  1387. extern time_t time __P((time_t *));
  1388. X
  1389. extern char *getlogin(), *getpass(), *ttyname();
  1390. extern int fflush(); 
  1391. #if !defined(__STDC__) || !defined(POSIX)
  1392. extern char *malloc(), *realloc();
  1393. #endif
  1394. X
  1395. extern char *Filename __P((char *));
  1396. extern char *MakeTermcap __P((int));
  1397. extern char *ProcessInput __P((char *, int *, char *, int *, int));
  1398. extern char *SaveStr __P((char *));
  1399. extern char *findcap __P((char *, char **, int));
  1400. extern char *strdup __P((const char *));
  1401. extern int ChangeScrollback __P((struct win *, int, int));
  1402. extern int ChangeWindowSize __P((struct win *, int, int));
  1403. extern int CompileKeys __P((char *, char *));
  1404. extern int CountUsers __P((void));
  1405. extern int FindSocket __P((int, int *));
  1406. extern int GetAvenrun __P((void));
  1407. extern int MakeClientSocket __P((int, char *));
  1408. extern int MakeServerSocket __P((void));
  1409. extern int MakeWindow __P((char *, char **, int, int, int, char *, int, int, char *));
  1410. extern int MarkRoutine __P((int));
  1411. extern int ParseEscape __P((char *));
  1412. extern void RcLine __P((char *));
  1413. extern int RecoverSocket __P((void));
  1414. extern int RemoveUtmp __P((struct win *));
  1415. extern int SetUtmp __P((struct win *, int));
  1416. extern int UserContext __P((void));
  1417. extern int UserStatus __P((void));
  1418. extern int display_help __P((void));
  1419. extern void display_copyright __P((void));
  1420. #ifdef DEBUG
  1421. extern sig_t FEChld __P(SIGPROTOARG);
  1422. #endif
  1423. extern sig_t SigHup __P(SIGPROTOARG);
  1424. extern void Activate __P((int));
  1425. extern void ChangeScreenSize __P((int, int, int));
  1426. extern void ChangeScrollRegion __P((int, int));
  1427. extern void CheckLP __P((int));
  1428. extern void CheckScreenSize __P((int));
  1429. extern void ClearDisplay __P((void));
  1430. extern void Detach __P((int));
  1431. extern void DisplayLine __P((char *, char *, char *, char *, char *, char *, int, int, int));
  1432. extern void DoScreen __P((char *, char **));
  1433. extern void DoSet __P((char **));
  1434. extern void ExitOverlayPage __P((void));
  1435. extern void FinishRc __P((char *));
  1436. extern void FinitTerm __P((void));
  1437. extern void FixLP __P((int, int));
  1438. extern void GetTTY __P((int, struct mode *));
  1439. extern void GotoPos __P((int, int));
  1440. extern void InitKmem __P((void));
  1441. extern void InitOverlayPage __P((void (*)(), void (*)(), int (*)(), int));
  1442. extern void InitTerm __P((int));
  1443. extern void InitTermcap __P((void));
  1444. extern void InitUtmp __P((void));
  1445. extern void InputAKA __P((void));
  1446. extern void InputColon __P((void));
  1447. extern void InsertMode __P((int));
  1448. extern void Kill __P((int, int));
  1449. extern void KillBuffers __P((void));
  1450. extern void MakeBlankLine __P((char *, int));
  1451. extern void MakeStatus __P((char *));
  1452. #ifdef USEVARARGS
  1453. extern void Msg __P((int, char *, ...));
  1454. #else
  1455. extern void Msg __P(());
  1456. #endif
  1457. extern void NewAutoFlow __P((struct win *, int));
  1458. extern void NewCharset __P((int));
  1459. extern void NewRendition __P(());
  1460. extern void PUTCHAR __P((int));
  1461. extern void INSERTCHAR __P((int));
  1462. extern void PutChar __P((int));
  1463. extern void PutStr __P((char *));
  1464. extern void ReInitUtmp __P((void));
  1465. extern void ReadFile __P((void));
  1466. extern void ReceiveMsg __P((int));
  1467. extern void Redisplay __P((int));
  1468. extern void RefreshLine __P((int, int, int));
  1469. #ifdef SVR4
  1470. struct utmpx;
  1471. extern void RemoveLoginSlot __P((slot_t, struct utmpx *));
  1472. #else
  1473. struct utmp;
  1474. extern void RemoveLoginSlot __P((slot_t, struct utmp *));
  1475. #endif
  1476. extern void RemoveStatus __P((void));
  1477. extern void Report __P((struct win *, char *, int, int));
  1478. extern void ResetScreen __P((struct win *));
  1479. extern void ResizeScreen __P((struct win *));
  1480. extern void RestoreAttr __P((void));
  1481. extern void RestoreLoginSlot __P((void));
  1482. extern void SaveSetAttr __P((int, int));
  1483. extern void ScrollRegion __P((int, int, int));
  1484. extern void SendCreateMsg __P((int, int, char **, int, int, int, int, char *));
  1485. #ifdef USEVARARGS
  1486. extern void SendErrorMsg __P((char *, ...));
  1487. #else
  1488. extern void SendErrorMsg __P(());
  1489. #endif
  1490. extern void SetFlow __P((int));
  1491. extern void SetLastPos __P((int, int));
  1492. extern void SetMode __P((struct mode *, struct mode *));
  1493. extern void SetOvlCurr __P((void));
  1494. extern void SetTTY __P((int, struct mode *));
  1495. extern void SlotToggle __P((int));
  1496. extern void StartRc __P((char *));
  1497. extern void SwitchWindow __P((int));
  1498. extern void UserReturn __P((int));
  1499. extern void WSresize __P((int, int));
  1500. extern void WriteFile __P((int));
  1501. extern void WriteString __P((struct win *, char *, int));
  1502. extern void bclear __P((char *, int));
  1503. #if !defined(MEMFUNCS_DECLARED) && !defined(bcopy)
  1504. extern void bcopy __P((char *, char *, int));
  1505. #endif /* !MEMFUNCS_DECLARED && !bcopy */
  1506. extern void eexit __P((int));
  1507. extern void exit_with_usage __P((char *));
  1508. extern void main __P((int, char **));
  1509. extern void screen_builtin_lck __P((void));
  1510. extern void KillWindow __P((int));
  1511. extern char *xrealloc __P((char *, int));
  1512. extern void AddLineToHist __P((struct win *, char **, char **, char **));
  1513. extern FILE *secfopen __P((char *, char *));
  1514. extern char *stripdev __P((char *));
  1515. extern int secopen __P((char *, int, int));
  1516. SHAR_EOF
  1517. chmod 0444 screen3.2/extern.h ||
  1518. echo 'restore of screen3.2/extern.h failed'
  1519. Wc_c="`wc -c < 'screen3.2/extern.h'`"
  1520. test 9213 -eq "$Wc_c" ||
  1521.     echo 'screen3.2/extern.h: original size 9213, current size' "$Wc_c"
  1522. rm -f _shar_wnt_.tmp
  1523. fi
  1524. # ============= screen3.2/fileio.c ==============
  1525. if test -f 'screen3.2/fileio.c' -a X"$1" != X"-c"; then
  1526.     echo 'x - skipping screen3.2/fileio.c (File already exists)'
  1527.     rm -f _shar_wnt_.tmp
  1528. else
  1529. > _shar_wnt_.tmp
  1530. echo 'x - extracting screen3.2/fileio.c (Text)'
  1531. sed 's/^X//' << 'SHAR_EOF' > 'screen3.2/fileio.c' &&
  1532. /* Copyright (c) 1991
  1533. X *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
  1534. X *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
  1535. X * Copyright (c) 1987 Oliver Laumann
  1536. X *
  1537. X * This program is free software; you can redistribute it and/or modify
  1538. X * it under the terms of the GNU General Public License as published by
  1539. X * the Free Software Foundation; either version 1, or (at your option)
  1540. X * any later version.
  1541. X *
  1542. X * This program is distributed in the hope that it will be useful,
  1543. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1544. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1545. X * GNU General Public License for more details.
  1546. X *
  1547. X * You should have received a copy of the GNU General Public License
  1548. X * along with this program (see the file COPYING); if not, write to the
  1549. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1550. X *
  1551. X * Noteworthy contributors to screen's design and implementation:
  1552. X *    Wayne Davison (davison@borland.com)
  1553. X *    Patrick Wolfe (pat@kai.com, kailand!pat)
  1554. X *    Bart Schaefer (schaefer@cse.ogi.edu)
  1555. X *    Nathan Glasser (nathan@brokaw.lcs.mit.edu)
  1556. X *    Larry W. Virden (lwv27%cas.BITNET@CUNYVM.CUNY.Edu)
  1557. X *    Howard Chu (hyc@hanauma.jpl.nasa.gov)
  1558. X *    Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
  1559. X *    Markku Jarvinen (mta@{cc,cs,ee}.tut.fi)
  1560. X *    Marc Boucher (marc@CAM.ORG)
  1561. X *
  1562. X ****************************************************************
  1563. X */
  1564. X
  1565. #ifndef lint
  1566. X  static char rcs_id[] = "$Id: fileio.c,v 1.2 92/02/03 02:27:42 jnweiger Exp $ FAU";
  1567. #endif
  1568. X
  1569. #if defined(pyr) || defined(MIPS) || defined(GOULD_NP1) || defined(B43)
  1570. extern int errno;
  1571. #endif
  1572. #include <sys/types.h>
  1573. #ifndef sgi
  1574. # include <sys/file.h>
  1575. #endif /* sgi */
  1576. #include <sys/stat.h>
  1577. #include <fcntl.h>
  1578. X
  1579. #ifdef BSDI
  1580. # include <sys/signal.h>
  1581. #endif /* BSDI */
  1582. X
  1583. #include "config.h"
  1584. #include "screen.h"
  1585. #include "extern.h"
  1586. X
  1587. #ifdef _SEQUENT_
  1588. # define UTHOST        /* _SEQUENT_ has got ut_find_host() */
  1589. #endif
  1590. X
  1591. #ifndef GETUTENT
  1592. # ifdef GETTTYENT
  1593. #  include <ttyent.h>
  1594. # else
  1595. struct ttyent
  1596. {
  1597. X  char *ty_name;
  1598. };
  1599. static char *tt, *ttnext;
  1600. static char ttys[] = "/etc/ttys";
  1601. # endif
  1602. #endif
  1603. X
  1604. #ifdef LOADAV
  1605. # ifndef NeXT
  1606. #  include <nlist.h>
  1607. X
  1608. static char KmemName[] = "/dev/kmem";
  1609. #  if defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi)
  1610. static char UnixName[] = "/unix";
  1611. #  else
  1612. #   ifdef sequent
  1613. static char UnixName[] = "/dynix";
  1614. #   else
  1615. #    ifdef hpux
  1616. static char UnixName[] = "/hp-ux";
  1617. #    else
  1618. #     ifdef xelos
  1619. static char UnixName[] = "/xelos";
  1620. #     else
  1621. static char UnixName[] = "/vmunix";
  1622. #     endif /* xelos */
  1623. #    endif /* hpux */
  1624. #   endif /* sequent */
  1625. #  endif /* _SEQUENT_ ... */
  1626. X
  1627. #  ifdef alliant
  1628. static char AvenrunSym[] = "_Loadavg";
  1629. #  else
  1630. #   if defined(hpux) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi)
  1631. static char AvenrunSym[] = "avenrun";
  1632. #   else
  1633. static char AvenrunSym[] = "_avenrun";
  1634. #   endif
  1635. #  endif /* alliant */
  1636. static struct nlist nl[2];
  1637. int avenrun;
  1638. static kmemf;
  1639. #  ifdef LOADAV_3LONGS
  1640. long loadav[3];
  1641. #  else
  1642. #   ifdef LOADAV_4LONGS
  1643. long loadav[4];
  1644. #   else
  1645. double loadav[3];
  1646. #   endif
  1647. #  endif
  1648. # else /* NeXT */
  1649. #  include <mach.h>
  1650. kern_return_t error;
  1651. host_t host;
  1652. unsigned int info_count;
  1653. struct processor_set_basic_info info;
  1654. processor_set_t default_set;
  1655. float loadav;
  1656. int avenrun;
  1657. # endif /* NeXT */
  1658. #endif /* LOADAV */
  1659. X
  1660. #if defined(UTMPOK) && defined(GETUTENT) && !defined(SVR4)
  1661. # if defined(hpux) /* cruel hpux release 8.0 */
  1662. #  define pututline _pututline
  1663. # endif /* hpux */
  1664. extern struct utmp *getutline(), *pututline();
  1665. # if defined(_SEQUENT_)
  1666. extern struct utmp *ut_add_user(), *ut_delete_user();
  1667. extern char *ut_find_host();
  1668. # endif
  1669. #endif
  1670. #ifdef NETHACK
  1671. extern nethackflag;
  1672. #endif
  1673. int hardcopy_append = 0;
  1674. int all_norefresh = 0;
  1675. X
  1676. extern char *RcFileName, *home, *extra_incap, *extra_outcap;
  1677. extern char *BellString, *ActivityString, *ShellProg, *ShellArgs[];
  1678. extern char *BufferFile, *PowDetachString, *VisualBellString;
  1679. extern int VBellWait, MsgWait, MsgMinWait;
  1680. extern struct key ktab[];
  1681. extern char Esc, MetaEsc;
  1682. extern char *shellaka, SockPath[], *SockNamePtr, *LoginName;
  1683. extern int loginflag, allflag, TtyMode, auto_detach;
  1684. extern int iflag, rflag, dflag;
  1685. extern int default_flow, wrap;
  1686. extern HS, termcapHS, use_hardstatus, visual_bell, default_monitor;
  1687. extern int default_histheight;
  1688. extern int default_startup;
  1689. extern int slowpaste;
  1690. extern DeadlyMsg, HasWindow;
  1691. extern ForeNum, screenwidth, screenheight;
  1692. extern char display_tty[];
  1693. extern struct win *fore;
  1694. extern char screenterm[];
  1695. extern int join_with_cr;
  1696. extern struct mode OldMode, NewMode;
  1697. extern int HasWindow;
  1698. extern char mark_key_tab[];
  1699. extern int real_uid, eff_uid;
  1700. extern int real_gid, eff_gid;
  1701. X
  1702. #ifdef PASSWORD
  1703. int CheckPassword;
  1704. char Password[20];
  1705. #endif
  1706. X
  1707. #ifdef COPY_PASTE
  1708. extern char *copybuffer;
  1709. extern copylen;
  1710. #endif
  1711. X
  1712. static char *CatExtra __P((char *, char *));
  1713. static char **SaveArgs __P((int, char **));
  1714. static int Parse __P((char *, char *[]));
  1715. static char *ParseChar __P((char *, char *));
  1716. static void ParseNum __P((int, char *[], int*));
  1717. static void ParseOnOff __P((int, char *[], int*));
  1718. static void ParseSaveStr __P((int, char *[], char **, char *));
  1719. static int IsNum __P((char *, int));
  1720. static int IsNumColon __P((char *, int, char *, int));
  1721. static slot_t TtyNameSlot __P((char *));
  1722. X
  1723. #if !defined(GETTTYENT) && !defined(GETUTENT)
  1724. static void setttyent __P((void));
  1725. static struct ttyent *getttyent __P((void));
  1726. #endif
  1727. X
  1728. /*
  1729. X * XXX: system
  1730. X */
  1731. extern time_t time __P((time_t *));
  1732. #if !defined(BSDI) && !defined(SVR4)
  1733. extern char *getpass __P((char *));
  1734. #endif /* !BSDI && !SVR4 */
  1735. #if defined(LOADAV) && !defined(NeXT) && !defined(NLIST_DECLARED)
  1736. extern int nlist __P((char *, struct nlist *));
  1737. #endif
  1738. X
  1739. char *KeyNames[] = 
  1740. {
  1741. X  "screen",
  1742. X  "select0", "select1", "select2", "select3", "select4",
  1743. X  "select5", "select6", "select7", "select8", "select9",
  1744. X  "aka", "clear", "colon", "copy", "detach", "flow",
  1745. X  "hardcopy", "help", "histnext", "history", "info", "kill", "lastmsg",
  1746. X  "license",
  1747. X  "lockscreen", "log", "login", "monitor", "next", "other", "paste",
  1748. X  "pow_detach", "prev", "quit", "readbuf", "redisplay", "removebuf",
  1749. X  "reset", "set", "shell", "suspend", "termcap", "time", "vbell",
  1750. X  "version", "width", "windows", "wrap", "writebuf", "xoff", "xon",
  1751. X  0,
  1752. };
  1753. X
  1754. X
  1755. /* Must be in alpha order !!! */
  1756. X
  1757. char *RCNames[] =
  1758. {
  1759. X  "activity", "all", "autodetach", "bell", "bind", "bufferfile", "chdir",
  1760. X  "crlf", "echo", "escape", "flow", "hardcopy_append", "hardstatus", "login", 
  1761. X  "markkeys", "mode", "monitor", "msgminwait", "msgwait", "nethack", "password",
  1762. X  "pow_detach_msg", "redraw", "refresh", "screen", "scrollback", "shell", 
  1763. X  "shellaka", "sleep", "slowpaste", "startup_message", "term", "termcap",
  1764. X  "terminfo", "vbell", "vbell_msg", "vbellwait", "visualbell",
  1765. X  "visualbell_msg", "wrap",
  1766. };
  1767. X
  1768. enum RCcases
  1769. {
  1770. X  RC_ACTIVITY,
  1771. X  RC_ALL,
  1772. X  RC_AUTODETACH,
  1773. X  RC_BELL,
  1774. X  RC_BIND,
  1775. X  RC_BUFFERFILE,
  1776. X  RC_CHDIR,
  1777. X  RC_CRLF,
  1778. X  RC_ECHO,
  1779. X  RC_ESCAPE,
  1780. X  RC_FLOW,
  1781. X  RC_HARDCOPY_APP,
  1782. X  RC_HARDSTATUS,
  1783. X  RC_LOGIN,
  1784. X  RC_MARKKEYS,
  1785. X  RC_MODE,
  1786. X  RC_MONITOR,
  1787. X  RC_MSGMINWAIT,
  1788. X  RC_MSGWAIT,
  1789. X  RC_NETHACK,
  1790. X  RC_PASSWORD,
  1791. X  RC_POW_DETACH_MSG,
  1792. X  RC_REDRAW,
  1793. X  RC_REFRESH,
  1794. X  RC_SCREEN,
  1795. X  RC_SCROLLBACK,
  1796. X  RC_SHELL,
  1797. X  RC_SHELLAKA,
  1798. X  RC_SLEEP,
  1799. X  RC_SLOWPASTE,
  1800. X  RC_STARTUP_MESSAGE,
  1801. X  RC_TERM,
  1802. X  RC_TERMCAP,
  1803. X  RC_TERMINFO,
  1804. X  RC_VBELL,
  1805. X  RC_VBELL_MSG,
  1806. X  RC_VBELLWAIT,
  1807. X  RC_VISUALBELL,
  1808. X  RC_VISUALBELL_MSG,
  1809. X  RC_WRAP,
  1810. X  RC_RCEND
  1811. };
  1812. X
  1813. #ifdef UTMPOK
  1814. static utmp, utmpf;
  1815. static char UtmpName[] = UTMPFILE;
  1816. # ifdef MIPS
  1817. X  static utmpfappend;
  1818. # endif
  1819. #endif
  1820. X
  1821. static FILE *fp = NULL;
  1822. static char *rc_name;
  1823. X
  1824. char *SaveStr(str)
  1825. register char *str;
  1826. {
  1827. X  register char *cp;
  1828. X
  1829. X  if ((cp = malloc(strlen(str) + 1)) == NULL)
  1830. X    Msg_nomem;
  1831. X  else
  1832. X    strcpy(cp, str);
  1833. X  return cp;
  1834. }
  1835. X
  1836. static char *CatExtra(str1, str2)
  1837. register char *str1, *str2;
  1838. {
  1839. X  register char *cp;
  1840. X  register int len1, len2, add_colon;
  1841. X
  1842. X  len1 = strlen(str1);
  1843. X  if (len1 == 0)
  1844. X    return(str2);
  1845. X  add_colon = (str1[len1 - 1] != ':');
  1846. X  if (str2)
  1847. X    {
  1848. X      len2 = strlen(str2);
  1849. X      if ((cp = realloc(str2, (unsigned) len1 + len2 + add_colon + 1)) == NULL)
  1850. X    Msg_nomem;
  1851. X      bcopy(cp, cp + len1 + add_colon, len2 + 1);
  1852. X    }
  1853. X  else
  1854. X    {
  1855. X      if (len1 == 0)
  1856. X    return 0;
  1857. X      if ((cp = malloc((unsigned) len1 + add_colon + 1)) == NULL)
  1858. X    Msg_nomem;
  1859. X      cp[len1 + add_colon] = '\0'; 
  1860. X    }
  1861. X  bcopy(str1, cp, len1);
  1862. X  if (add_colon)
  1863. X    cp[len1] = ':';
  1864. X
  1865. X  return cp;
  1866. }
  1867. X
  1868. static char *findrcfile(rcfile)
  1869. char *rcfile;
  1870. {
  1871. X  static char buf[256];
  1872. X  char *rc, *p;
  1873. X
  1874. X  if (rcfile)
  1875. X    {
  1876. X      rc = SaveStr(rcfile);
  1877. X      debug1("findrcfile: you specified '%s'\n", rcfile);
  1878. X    }
  1879. X  else
  1880. X    {
  1881. X      debug("findrcfile: you specified nothing...\n");
  1882. X      if ((p = getenv("ISCREENRC")) != NULL && *p != '\0')
  1883. X    {
  1884. X      debug1("  ... but $ISCREENRC has: '%s'\n", p);
  1885. X      rc = SaveStr(p);
  1886. X    }
  1887. X      else if ((p = getenv("SCREENRC")) != NULL && *p != '\0')
  1888. X    {
  1889. X      debug1("  ... but $SCREENRC has: '%s'\n", p);
  1890. X      rc = SaveStr(p);
  1891. X    }
  1892. X      else
  1893. X    {
  1894. X      debug("  ...nothing in $SCREENRC, defaulting $HOME/.screenrc\n");
  1895. X      if (strlen(home) > 244)
  1896. X        Msg(0, "Rc: home too large");
  1897. X      sprintf(buf, "%s/.iscreenrc", home);
  1898. X          if (access(buf, R_OK))
  1899. X        sprintf(buf, "%s/.screenrc", home);
  1900. X      rc = SaveStr(buf);
  1901. X    }
  1902. X    }
  1903. X  return rc;
  1904. }
  1905. X
  1906. /*
  1907. X * this will be called twice:
  1908. X * 1) rcfilename = "/etc/screenrc"
  1909. X * 2) rcfilename = RcFileName
  1910. X */
  1911. void
  1912. StartRc(rcfilename)
  1913. char *rcfilename;
  1914. {
  1915. X  register int argc, len;
  1916. X  register char *p, *cp;
  1917. X  char buf[256];
  1918. X  char *args[MAXARGS], *t;
  1919. X
  1920. X  rc_name = findrcfile(rcfilename);
  1921. X
  1922. X  if ((fp = secfopen(rc_name, "r")) == NULL)
  1923. X    {
  1924. X      if (RcFileName && strcmp(RcFileName, rc_name) == 0)
  1925. X    {
  1926. X          /*
  1927. X           * User explicitly gave us that name,
  1928. X           * this is the only case, where we get angry, if we can't read
  1929. X           * the file.
  1930. X           */
  1931. X      debug3("StartRc: '%s','%s', '%s'\n", RcFileName, rc_name, rcfilename);
  1932. X          Msg(0, "Unable to open \"%s\".", rc_name);
  1933. X      /* NOTREACHED */
  1934. X    }
  1935. X      debug1("StartRc: '%s' no good. ignored\n", rc_name);
  1936. X      Free(rc_name);
  1937. X      rc_name = "";
  1938. X      return;
  1939. X    }
  1940. X  if ((t = getenv("TERM")) == NULL)
  1941. X    Msg(0, "No TERM in environment.");
  1942. X  debug1("startrc got termcp:%s\n", t);
  1943. X  while (fgets(buf, sizeof buf, fp) != NULL)
  1944. X    {
  1945. X      if ((p = rindex(buf, '\n')) != NULL)
  1946. X    *p = '\0';
  1947. X      if ((argc = Parse(buf, args)) == 0)
  1948. X    continue;
  1949. X      if (strcmp(args[0], "echo") == 0)
  1950. X    {
  1951. X      if (argc < 2 || (argc == 3 && strcmp(args[1], "-n")) || argc > 3)
  1952. X        {
  1953. X          DeadlyMsg = 0;
  1954. X          Msg(0, "%s: 'echo [-n] \"string\"' expected.", rc_name);
  1955. X        }
  1956. X      else
  1957. X        {
  1958. X          printf((argc == 3) ? "%s" : "%s\r\n", args[argc - 1]);
  1959. X        }
  1960. X    }
  1961. X      else if (strcmp(args[0], "sleep") == 0)
  1962. X    {
  1963. X      if (argc != 2)
  1964. X        {
  1965. X          DeadlyMsg = 0;
  1966. X          Msg(0, "%s: sleep: one numeric argument expected.", rc_name);
  1967. X        }
  1968. X      else
  1969. X        sleep(atoi(args[1]));
  1970. X    }
  1971. #ifdef TERMINFO
  1972. X      else if (strcmp(args[0], "terminfo") == 0)
  1973. #else
  1974. X      else if (strcmp(args[0], "termcap") == 0)
  1975. #endif
  1976. X    {
  1977. X      if (argc < 3 || argc > 4)
  1978. X        Msg(0, "%s: %s: incorrect number of arguments.", rc_name, args[0]);
  1979. X      for (p = args[1]; p && *p; p = cp)
  1980. X        {
  1981. X          if ((cp = index(p, '|')) != 0)
  1982. X        *cp++ = '\0';
  1983. X          len = strlen(p);
  1984. X          if (p[len - 1] == '*')
  1985. X        {
  1986. X          if (!(len - 1) || !strncmp(p, t, len - 1))
  1987. X            break;
  1988. X        }
  1989. X          else if (!strcmp(p, t))
  1990. X        break;
  1991. X        }
  1992. X      if (!(p && *p))
  1993. X        continue;
  1994. X      extra_incap = CatExtra(args[2], extra_incap);
  1995. X      if (argc == 4)
  1996. X        extra_outcap = CatExtra(args[3], extra_outcap);
  1997. X    }
  1998. X    }
  1999. X  fclose(fp);
  2000. X  Free(rc_name);
  2001. X  rc_name = "";
  2002. }
  2003. X
  2004. static char *
  2005. ParseChar(p, cp)
  2006. char *p, *cp;
  2007. {
  2008. X  if (*p == '^')
  2009. X    {
  2010. X      if (*++p == '?')
  2011. X        *cp = '\177';
  2012. X      else if (*p >= '@')
  2013. X        *cp = Ctrl(*p);
  2014. X      else
  2015. X        return 0;
  2016. X      ++p;
  2017. X    }
  2018. X  else if (*p == '\\' && *++p <= '7' && *p >= '0')
  2019. X    {
  2020. X      *cp = 0;
  2021. X      do
  2022. X        *cp = *cp * 8 + *p - '0';
  2023. X      while (*++p <= '7' && *p >= '0');
  2024. X    }
  2025. X  else
  2026. X    *cp = *p++;
  2027. X  return p;
  2028. }
  2029. X
  2030. /*
  2031. X * CompileKeys must be called before Markroutine is first used.
  2032. X * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
  2033. X *
  2034. X * s is an ascii string in a termcap-like syntax. It looks like
  2035. X *   "j=u:k=d:l=r:h=l: =.:" and so on...
  2036. X * this example rebinds the cursormovement to the keys u (up), d (down),
  2037. X * l (left), r (right). placing a mark will now be done with ".".
  2038. X */
  2039. int CompileKeys(s, array)
  2040. char *s, *array;
  2041. {
  2042. X  int i;
  2043. X  unsigned char key, value;
  2044. X
  2045. X  if (!s || !*s)
  2046. X    {
  2047. X      for (i = 0; i < 256; i++)
  2048. X        array[i] = i;
  2049. X      return 0;
  2050. X    }
  2051. X  while (*s)
  2052. X    {
  2053. X      s = ParseChar(s, (char *) &key);
  2054. X      if (*s != '=')
  2055. X    return -1;
  2056. X      do 
  2057. X    {
  2058. X          s = ParseChar(++s, (char *) &value);
  2059. X      array[value] = key;
  2060. X    }
  2061. X      while (*s == '=');
  2062. X      if (!*s) 
  2063. X    break;
  2064. X      if (*s++ != ':')
  2065. X    return -1;
  2066. X    }
  2067. X  return 0;
  2068. }
  2069. X
  2070. static char **SaveArgs(argc, argv)
  2071. register int argc;
  2072. register char **argv;
  2073. {
  2074. X  register char **ap, **pp;
  2075. X
  2076. X  if ((pp = ap = (char **) malloc((unsigned) (argc + 1) * sizeof(char **))) == 0)
  2077. X    Msg_nomem;
  2078. #ifdef notdef
  2079. X  debug("saveargs:\n"); 
  2080. #endif
  2081. X  while (argc--)
  2082. X    {
  2083. X      debug1(" '%s'", *argv);
  2084. X      *pp++ = SaveStr(*argv++);
  2085. X    }
  2086. X  debug("\n");
  2087. X  *pp = 0;
  2088. X  return ap;
  2089. }
  2090. X
  2091. void
  2092. FinishRc(rcfilename)
  2093. char *rcfilename;
  2094. {
  2095. X  /* in FinishRc screen is not yet open, thus Msg() is deadly here.
  2096. X   */
  2097. X  char buf[256];
  2098. X
  2099. X  rc_name = findrcfile(rcfilename);
  2100. X
  2101. X  if ((fp = secfopen(rc_name, "r")) == NULL)
  2102. X    {
  2103. X      if (RcFileName && strcmp(RcFileName, rc_name) == 0)
  2104. X    {
  2105. X          /*
  2106. X        * User explicitly gave us that name, 
  2107. X       * this is the only case, where we get angry, if we can't read
  2108. X       * the file.
  2109. X       */
  2110. X        debug3("FinishRc:'%s','%s','%s'\n", RcFileName, rc_name, rcfilename);
  2111. X          Msg(0, "Unable to open \"%s\".", rc_name);
  2112. X      /* NOTREACHED */
  2113. X    }
  2114. X      debug1("FinishRc: '%s' no good. ignored\n", rc_name);
  2115. X      Free(rc_name);
  2116. X      rc_name = "";
  2117. X      return;
  2118. X    }
  2119. X
  2120. X  debug("finishrc is going...\n");
  2121. X  while (fgets(buf, sizeof buf, fp) != NULL)
  2122. X    {
  2123. X      RcLine(buf);
  2124. X    }
  2125. X  (void) fclose(fp);
  2126. X  Free(rc_name);
  2127. X  rc_name = "";
  2128. }
  2129. X
  2130. /*
  2131. X * this is a KEY_SET pressed
  2132. X */
  2133. void
  2134. DoSet(argv)
  2135. char **argv;
  2136. {
  2137. X  char *p;
  2138. X  static char buf[256];
  2139. X
  2140. X  p = buf;
  2141. X  debug("DoSet\n");
  2142. X  if (!argv || !*argv || !**argv)
  2143. X    {
  2144. X      debug("empty DoSet\n");
  2145. X      sprintf(buf, "set ");
  2146. X      RcLine(buf);
  2147. X      return;
  2148. X    }
  2149. X  sprintf(p, "set"); p+=3;
  2150. X  while(*argv && (strlen(buf) + strlen(*argv) < 255))
  2151. X    {
  2152. X      sprintf(p, " %s", *argv++);
  2153. X      p += strlen(p);
  2154. X    }
  2155. X  RcLine(buf);
  2156. }
  2157. X
  2158. /*
  2159. X *    "$HOST blafoo"       -> "localhost blafoo"
  2160. X *    "${HOST}blafoo"          -> "localhostblafoo"
  2161. X *    "\$HOST blafoo"     -> "$HOST blafoo"
  2162. X *    "\\$HOST blafoo"    -> "\localhost blafoo"
  2163. X *    "'$HOST ${HOST}'"    -> "'$HOST ${HOST}'" 
  2164. X *    "'\$HOST'"           -> "'\$HOST'"
  2165. X *    "\'$HOST' $HOST"       -> "'localhost' $HOST"
  2166. X */
  2167. static char *expand_env_vars(ss)
  2168. char *ss;
  2169. {
  2170. X  static char ebuf[2048];
  2171. X  register int esize = 2047, quofl = 0;
  2172. X  register char *e = ebuf;
  2173. X  register char *s = ss;
  2174. X  register char *v;
  2175. X
  2176. X  while (*s && *s != '\n' && esize > 0)
  2177. X    {
  2178. X      if (*s == '\'')
  2179. X    quofl ^= 1;
  2180. X      if (*s == '$' && !quofl)
  2181. X    {
  2182. X      char *p, c;
  2183. X
  2184. X      p = ++s;
  2185. X      if (*s == '{')
  2186. X        {
  2187. X          p = ++s;
  2188. X          while (*p != '}')
  2189. X            if (*p++ == '\0')
  2190. X              return ss;
  2191. X        }
  2192. X      else
  2193. X        {
  2194. X          while (*p != ' ' && *p != '\0' && *p != '\n')
  2195. X        p++;
  2196. X        }
  2197. X      c = *p;
  2198. X      debug1("exp: c='%c'\n", c);
  2199. X      *p = '\0';
  2200. X      if (v = getenv(s)) 
  2201. X        {
  2202. X          debug2("exp: $'%s'='%s'\n", s, v);
  2203. X          while (*v && esize-- > 0)
  2204. X            *e++ = *v++;
  2205. X        }
  2206. X      else 
  2207. X        debug1("exp: '%s' not env\n", s);
  2208. X      if ((*p = c) == '}')
  2209. X        p++;
  2210. X      s = p;
  2211. X    }
  2212. X      else
  2213. X    {
  2214. X      if (s[0] == '\\' && !quofl)
  2215. X        if (s[1] == '$' || (s[1] == '\\' && s[2] == '$') ||
  2216. X            s[1] == '\'' || (s[1] == '\\' && s[2] == '\''))
  2217. X          s++;
  2218. X      *e++ = *s++;
  2219. X      esize--;
  2220. X    }
  2221. X    }
  2222. X  if (esize <= 0)
  2223. X    Msg(0, "expand_env_vars: buffer overflow\n");
  2224. X  *e = '\0';
  2225. X  return ebuf;
  2226. }
  2227. X
  2228. void
  2229. RcLine(ubuf)
  2230. char *ubuf;
  2231. {
  2232. X  char *args[MAXARGS];
  2233. X  register char *buf, *p, **pp, **ap;
  2234. X  register int argc, setflag;
  2235. X  int q, qq;
  2236. X  char key;
  2237. X  int low, high, mid, x;
  2238. X
  2239. X  buf = expand_env_vars(ubuf); 
  2240. X
  2241. X  ap = args;
  2242. X
  2243. X  if ((p = rindex(buf, '\n')) != NULL)
  2244. X    *p = '\0';
  2245. X  if (strncmp("set ", buf, 4) == 0)
  2246. X    {
  2247. X      buf += 4;
  2248. X      setflag = 1;
  2249. X      debug1("RcLine: '%s' is a set command\n", buf);
  2250. X    }
  2251. X  else if (strncmp("se ", buf, 3) == 0)
  2252. X    {
  2253. X      buf += 3;
  2254. X      setflag = 1;
  2255. X      debug1("RcLine: '%s' is a se command\n", buf);
  2256. X    }
  2257. X  else
  2258. X    {
  2259. X      setflag = 0;
  2260. X      debug1("RcLine: '%s'\n", buf);
  2261. X    }
  2262. X  if ((argc = Parse(buf, ap)) == 0)
  2263. X    {
  2264. X      if (setflag)
  2265. X    {
  2266. X      DeadlyMsg = 0;
  2267. X      Msg(0, "%s: set what?\n", rc_name);
  2268. X    }
  2269. X      return;
  2270. X    }
  2271. X
  2272. X  low = 0;
  2273. X  high = (int)RC_RCEND - 1;
  2274. X  while (low <= high)
  2275. X    {
  2276. X      mid = (low + high) / 2;
  2277. X      x = strcmp(ap[0], RCNames[mid]);
  2278. X      if (x < 0)
  2279. X        high = mid - 1;
  2280. X      else if (x > 0)
  2281. X        low = mid + 1;
  2282. X      else
  2283. X        break;
  2284. X    }
  2285. X  if (low > high)
  2286. X    mid = (int)RC_RCEND;
  2287. X  switch ((enum RCcases) mid)
  2288. X    {
  2289. X    case RC_ESCAPE:
  2290. X      if (argc != 2 || !ParseEscape(ap[1]))
  2291. X    {
  2292. X      DeadlyMsg = 0; 
  2293. X      Msg(0, "%s: two characters required after escape.", rc_name);
  2294. X      return;
  2295. X    }
  2296. X      if (Esc != MetaEsc)
  2297. X    ktab[Esc].type = KEY_OTHER;
  2298. X      else
  2299. X    ktab[Esc].type = KEY_IGNORE;
  2300. X      return;
  2301. X    case RC_CHDIR:
  2302. X      if (setflag)
  2303. X    break;
  2304. X      p = argc < 2 ? home : ap[1];
  2305. X      if (chdir(p) == -1)
  2306. X    {
  2307. X      DeadlyMsg = 0; 
  2308. X      Msg(errno, "%s", p);
  2309. X    }
  2310. X      return;
  2311. X    case RC_SHELL:
  2312. X      ParseSaveStr(argc, ap, &ShellProg, "shell");
  2313. X      ShellArgs[0] = ShellProg;
  2314. X      return;
  2315. X    case RC_SHELLAKA:
  2316. X      ParseSaveStr(argc, ap, &shellaka, "shellaka");
  2317. X      return;
  2318. X    case RC_SCREEN:
  2319. X      if (setflag)
  2320. X    break;
  2321. X      DoScreen(rc_name, ap + 1);
  2322. X      return;
  2323. X    case RC_SLEEP:
  2324. X    case RC_TERMCAP:
  2325. X    case RC_TERMINFO:
  2326. X      return;            /* Already handled */
  2327. X    case RC_TERM:
  2328. X      {
  2329. X        char *tmp = NULL;
  2330. X
  2331. X        ParseSaveStr(argc, ap, &tmp, "term");
  2332. X        if (!tmp)
  2333. X          return;
  2334. X    if (strlen(tmp) >= 20)
  2335. X      {
  2336. X        DeadlyMsg = 0;
  2337. X            Msg(0,"%s: term: argument too long ( < 20)", rc_name);
  2338. X            Free(tmp);
  2339. X        return;
  2340. X          }
  2341. X        strcpy(screenterm, args[1]);
  2342. X    Free(tmp);
  2343. X        debug1("screenterm set to %s\n", screenterm);
  2344. X        MakeTermcap(0);
  2345. X        return;    
  2346. X      }
  2347. X    case RC_ECHO:
  2348. X      if (HasWindow && *rc_name == '\0')
  2349. X    {
  2350. X      /*
  2351. X       * user typed ^A:echo... well, echo isn't FinishRc's job,
  2352. X       * but as he wanted to test us, we show good will
  2353. X       */
  2354. X      DeadlyMsg = 0;
  2355. X      if (argc == 2 || (argc == 3 && !strcmp(ap[1], "-n")))
  2356. X        Msg(0, "%s", ap[argc - 1]);
  2357. X      else
  2358. X         Msg(0, "%s: 'echo [-n] \"string\"' expected.", rc_name);
  2359. X    }
  2360. X      return;
  2361. X    case RC_BELL:
  2362. X      ParseSaveStr(argc, ap, &BellString, "bell");
  2363. X      return;
  2364. X    case RC_BUFFERFILE:
  2365. X      ParseSaveStr(argc, ap, &BufferFile, "bufferfile");
  2366. X      return;
  2367. X    case RC_ACTIVITY:
  2368. X      ParseSaveStr(argc, ap, &ActivityString, "activity");
  2369. X      return;
  2370. X    case RC_POW_DETACH_MSG:
  2371. X      ParseSaveStr(argc, ap, &PowDetachString, "pow_detach");
  2372. X      return;
  2373. X    case RC_LOGIN:
  2374. #ifdef UTMPOK
  2375. X      q = loginflag;
  2376. X      ParseOnOff(argc, ap, &loginflag);
  2377. X      if (fore && setflag)
  2378. X    {
  2379. X      SlotToggle(loginflag?(1):(-1));
  2380. X      loginflag = q;
  2381. X    }
  2382. #endif
  2383. X      return;
  2384. X    case RC_FLOW:
  2385. X      if (argc == 3 && ap[2][0] == 'i')
  2386. X    {
  2387. X      iflag = 1;
  2388. X      argc--;
  2389. X    }
  2390. X      if (argc == 2 && ap[1][0] == 'a')
  2391. X    default_flow = FLOW_AUTOFLAG;
  2392. X      else
  2393. X    ParseOnOff(argc, ap, &default_flow);
  2394. X      return;
  2395. X    case RC_WRAP:
  2396. X      ParseOnOff(argc, ap, &wrap);
  2397. X      return;
  2398. X    case RC_HARDSTATUS:
  2399. X      ParseOnOff(argc, ap, &use_hardstatus);
  2400. X      if (use_hardstatus)
  2401. X    HS = termcapHS;
  2402. X      else
  2403. X    HS = 0;
  2404. X      return;
  2405. X    case RC_MONITOR:
  2406. X    {
  2407. X      int f; 
  2408. X
  2409. X      ParseOnOff(argc, ap, &f);
  2410. X      if (fore && setflag)
  2411. X        fore->monitor = (f == 0) ? MON_OFF : MON_ON;
  2412. X      else
  2413. X        default_monitor = (f == 0) ? MON_OFF : MON_ON;
  2414. X    }
  2415. X      return;
  2416. X    case RC_REDRAW:
  2417. X    case RC_REFRESH:
  2418. X    {
  2419. X      int r;
  2420. X
  2421. X      ParseOnOff(argc, ap, &r);
  2422. X      if (fore && setflag)
  2423. X        fore->norefresh = (r) ? 0 : 1;
  2424. X      else
  2425. X        {
  2426. X          all_norefresh = (r) ? 0 : 1;
  2427. X          if (all_norefresh)
  2428. X            Msg(0, "No refresh on window change!\n");
  2429. X          else
  2430. X            Msg(0, "Window specific refresh\n");
  2431. X        }
  2432. X    }
  2433. X      return;
  2434. X    case RC_VBELL:
  2435. X    case RC_VISUALBELL:
  2436. X      ParseOnOff(argc, ap, &visual_bell);
  2437. X      return;
  2438. X    case RC_VBELLWAIT:
  2439. X      ParseNum(argc, ap, &VBellWait);
  2440. X      if (fore && rc_name[0] == '\0')
  2441. X        Msg(0, "vbellwait set to %d seconds", VBellWait);
  2442. X      return;
  2443. X    case RC_MSGWAIT:
  2444. X      ParseNum(argc, ap, &MsgWait);
  2445. X      if (fore && rc_name[0] == '\0')
  2446. X        Msg(0, "msgwait set to %d seconds", MsgWait);
  2447. X      return;
  2448. X    case RC_MSGMINWAIT:
  2449. X      ParseNum(argc, ap, &MsgMinWait);
  2450. X      if (fore && rc_name[0] == '\0')
  2451. X        Msg(0, "msgminwait set to %d seconds", MsgMinWait);
  2452. X      return;
  2453. X    case RC_SCROLLBACK:
  2454. X      if (fore && setflag)
  2455. X    {
  2456. X      int i;
  2457. X
  2458. X      ParseNum(argc, ap, &i);
  2459. X      ChangeScrollback(fore, i, fore->width);
  2460. SHAR_EOF
  2461. true || echo 'restore of screen3.2/fileio.c failed'
  2462. fi
  2463. echo 'End of  part 2'
  2464. echo 'File screen3.2/fileio.c is continued in part 3'
  2465. echo 3 > _shar_seq_.tmp
  2466. exit 0
  2467. exit 0 # Just in case...
  2468.