home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume12 / kterm / part08 < prev    next >
Text File  |  1991-05-08  |  52KB  |  1,917 lines

  1. Path: uunet!cs.utexas.edu!convex!central!newstop!male!jethro!exodus!NMSU.Edu!mleisher
  2. From: mleisher@NMSU.Edu
  3. Newsgroups: comp.sources.x
  4. Subject: v12i089: kterm  - kanji xterm, Part08/18
  5. Message-ID: <12973@exodus.Eng.Sun.COM>
  6. Date: 8 May 91 02:39:37 GMT
  7. References: <csx-12i082:kterm@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1905
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: mleisher@NMSU.Edu
  13. Posting-number: Volume 12, Issue 89
  14. Archive-name: kterm/part08
  15.  
  16. #!/bin/sh
  17. # this is kt412.08 (part 8 of kterm-4.1.2)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file kterm-4.1.2/charproc.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 8; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping kterm-4.1.2/charproc.c'
  35. else
  36. echo 'x - continuing file kterm-4.1.2/charproc.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'kterm-4.1.2/charproc.c' &&
  38. X            break;
  39. X
  40. X         case CASE_HIDE_STATUS:
  41. X            HideStatus();
  42. X            parsestate = groundtable;
  43. X            break;
  44. X
  45. X         case CASE_ERASE_STATUS:
  46. X            EraseStatus();
  47. X            parsestate = groundtable;
  48. X            break;
  49. #endif /* STATUSLINE */
  50. X
  51. X         case CASE_XTERM_SAVE:
  52. X            savemodes(term);
  53. X            parsestate = groundtable;
  54. X            break;
  55. X
  56. X         case CASE_XTERM_RESTORE:
  57. X            restoremodes(term);
  58. X            parsestate = groundtable;
  59. X            break;
  60. #ifdef KTERM_KANJI
  61. X        }
  62. #else /* !KTERM_KANJI */
  63. X        }
  64. #endif /* !KTERM_KANJI */
  65. X    }
  66. }
  67. X
  68. finput()
  69. {
  70. X    return(doinput());
  71. }
  72. X
  73. static int select_mask;
  74. static int write_mask;
  75. X
  76. static char v_buffer[4096];
  77. static char *v_bufstr;
  78. static char *v_bufptr;
  79. static char *v_bufend;
  80. #define    ptymask()    (v_bufptr > v_bufstr ? pty_mask : 0)
  81. X
  82. v_write(f, d, l)
  83. int f;
  84. char *d;
  85. int l;
  86. {
  87. X    int r;
  88. X    int c = l;
  89. X
  90. X    if (!v_bufstr) {
  91. X        v_bufstr = v_buffer;
  92. X        v_bufptr = v_buffer;
  93. X        v_bufend = &v_buffer[4096];
  94. X    }
  95. X
  96. X
  97. X    if ((1 << f) != pty_mask)
  98. X        return(write(f, d, l));
  99. X
  100. X    if (v_bufptr > v_bufstr) {
  101. X        if (l) {
  102. X            if (v_bufend > v_bufptr + l) {
  103. X                bcopy(d, v_bufptr, l);
  104. X                v_bufptr += l;
  105. X            } else {
  106. X                if (v_bufstr != v_buffer) {
  107. X                    bcopy(v_bufstr, v_buffer,
  108. X                          v_bufptr - v_bufstr);
  109. X                    v_bufptr -= v_bufstr - v_buffer;
  110. X                    v_bufstr = v_buffer;
  111. X                }
  112. X                if (v_bufend > v_bufptr + l) {
  113. X                    bcopy(d, v_bufptr, l);
  114. X                    v_bufptr += l;
  115. X                } else if (v_bufptr < v_bufend) {
  116. X                    fprintf(stderr, "Out of buffer space\n");
  117. X                    c = v_bufend - v_bufptr;
  118. X                    bcopy(d, v_bufptr, c);
  119. X                    v_bufptr = v_bufend;
  120. X                } else {
  121. X                    fprintf(stderr, "Out of buffer space\n");
  122. X                    c = 0;
  123. X                }
  124. X            }
  125. X        }
  126. X        if (v_bufptr > v_bufstr) {
  127. X            if ((r = write(f, v_bufstr, v_bufptr - v_bufstr)) <= 0)
  128. X                return(r);
  129. X            if ((v_bufstr += r) >= v_bufptr)
  130. X                v_bufstr = v_bufptr = v_buffer;
  131. X        }
  132. X    } else if (l) {
  133. X        if ((r = write(f, d, l)) < 0) {
  134. X            if (errno == EWOULDBLOCK)
  135. X                r = 0;
  136. X            else if (errno == EINTR)
  137. X                r = 0;
  138. X            else
  139. X                return(r);
  140. X        }
  141. X        if (l - r) {
  142. X            if (l - r > v_bufend - v_buffer) {
  143. X                fprintf(stderr, "Truncating to %d\n",
  144. X                        v_bufend - v_buffer);
  145. X                l = (v_bufend - v_buffer) + r;
  146. X            }
  147. X            bcopy(d + r, v_buffer, l - r);
  148. X            v_bufstr = v_buffer;
  149. X            v_bufptr = v_buffer + (l - r);
  150. X        }
  151. X    }
  152. X    return(c);
  153. }
  154. X
  155. in_put()
  156. {
  157. X    register TScreen *screen = &term->screen;
  158. X    register int i;
  159. X    static struct timeval trackTimeOut;
  160. X
  161. X    select_mask = pty_mask;    /* force initial read */
  162. X    for( ; ; ) {
  163. #ifdef        CRAY
  164. X        trackTimeOut.tv_sec = 0;
  165. X        trackTimeOut.tv_usec = 0;
  166. X        (void) select(max_plus1, &select_mask, (int *) NULL,
  167. X            (int *)NULL, &trackTimeOut);
  168. #endif        /* CRAY */
  169. X
  170. X        if((select_mask & pty_mask) && (eventMode == NORMAL)) {
  171. X            if(screen->logging)
  172. X                FlushLog(screen);
  173. X            if((bcnt = read(screen->respond, bptr = buffer,
  174. X             BUF_SIZE)) < 0) {
  175. X                if(errno == EIO)
  176. X                    Cleanup (0);
  177. X                else if(errno != EWOULDBLOCK)
  178. X                    Panic(
  179. X                 "input: read returned unexpected error (%d)\n",
  180. X                     errno);
  181. X            } else if(bcnt == 0)
  182. X                Panic("input: read returned zero\n", 0);
  183. X            else {
  184. #ifdef KTERM_KANJI
  185. X                if (pending_byte) {
  186. X                    /*
  187. X                     * restore pending_byte to the top of
  188. X                     * the text which just read.
  189. X                     */
  190. X                    *--bptr = pending_byte;
  191. X                    bcnt++;
  192. X                    pending_byte = 0;
  193. X                }
  194. #endif /* KTERM_KANJI */
  195. X                if(screen->scrollWidget && screen->scrollttyoutput &&
  196. X                 screen->topline < 0)
  197. X                    /* Scroll to bottom */
  198. X                    WindowScroll(screen, 0);
  199. X                break;
  200. X            }
  201. X        }
  202. X        if(screen->scroll_amt)
  203. X            FlushScroll(screen);
  204. X        if(screen->cursor_set && (screen->cursor_col != screen->cur_col
  205. X         || screen->cursor_row != screen->cur_row)) {
  206. X            if(screen->cursor_state)
  207. X                HideCursor();
  208. X            ShowCursor();
  209. X        } else if(screen->cursor_set != screen->cursor_state) {
  210. X            if(screen->cursor_set)
  211. X                ShowCursor();
  212. X            else
  213. X                HideCursor();
  214. X        }
  215. X        
  216. X    if (waitingForTrackInfo) {
  217. X            trackTimeOut.tv_sec = TRACKTIMESEC;
  218. X            trackTimeOut.tv_usec = TRACKTIMEUSEC;
  219. X            select_mask = pty_mask;
  220. X            if ((i = select(max_plus1, &select_mask, (int *)NULL, (int *)NULL,
  221. X             &trackTimeOut)) < 0) {
  222. X                 if (errno != EINTR)
  223. X                    SysError(ERROR_SELECT);
  224. X                continue;
  225. X            } else if (i == 0) {
  226. X                /* emacs just isn't replying, go on */
  227. X                waitingForTrackInfo = 0;
  228. X                Bell();
  229. X                select_mask = Select_mask;
  230. X            }
  231. X        } else if (QLength(screen->display))
  232. X            select_mask = X_mask;
  233. X        else {
  234. X            write_mask = ptymask();
  235. X            XFlush(screen->display);
  236. X            select_mask = Select_mask;
  237. X            if (eventMode != NORMAL)
  238. X                select_mask = X_mask;
  239. X            if(select(max_plus1, &select_mask, &write_mask, 
  240. X                (int *)NULL, (struct timeval *) NULL) < 0){
  241. X                if (errno != EINTR)
  242. X                    SysError(ERROR_SELECT);
  243. X                continue;
  244. X            } 
  245. X        }
  246. X        if (write_mask & ptymask())
  247. X            v_write(screen->respond, 0, 0);    /* flush buffer */
  248. X        if(select_mask & X_mask) {
  249. X            if (bcnt <= 0) {
  250. X                bcnt = 0;
  251. X                bptr = buffer;
  252. X            }
  253. X            xevents();
  254. X            if (bcnt > 0)
  255. X                break;
  256. X        }
  257. X    }
  258. X    bcnt--;
  259. X    return(*bptr++);
  260. }
  261. X
  262. /*
  263. X * process a string of characters according to the character set indicated
  264. X * by charset.  worry about end of line conditions (wraparound if selected).
  265. X */
  266. dotext(screen, flags, charset, buf, ptr)
  267. register TScreen    *screen;
  268. unsigned    flags;
  269. #ifdef KTERM
  270. Char        charset;
  271. Char    *buf;
  272. Char    *ptr;
  273. #else /* !KTERM */
  274. char        charset;
  275. char    *buf;
  276. char    *ptr;
  277. #endif /* !KTERM */
  278. {
  279. #ifdef KTERM
  280. X    int    do_wrap = 0;
  281. X    register Char    *s;
  282. #else /* !KTERM */
  283. X    register char    *s;
  284. #endif /* !KTERM */
  285. X    register int    len;
  286. X    register int    n;
  287. X    register int    next_col;
  288. X
  289. #ifdef KTERM
  290. X    switch (charset) {
  291. X    case GSET_UK:        /* United Kingdom set            */
  292. X        for (s=buf; s<ptr; ++s)
  293. X            *s &= ~NEEDMAP;
  294. X            if (*s == '#') /* UK pound sign */
  295. X                *s |= NEEDMAP;
  296. X        break;
  297. X
  298. X    case GSET_KANA:        /* JIS Kana set                */
  299. X        for (s=buf; s<ptr; ++s) {
  300. X            *s |= NEEDMAP;
  301. X        }
  302. X        break;
  303. X
  304. X    case GSET_GRAPH:    /* special graphics (line drawing)    */
  305. X    case GSET_ASCII:    /* ASCII set                */
  306. X    case GSET_JISROMAN:    /* JIS Roman set            */
  307. X    case GSET_LATIN1R:    /* Right part of ISO8859-1    */
  308. X    case GSET_LATIN2R:    /* Right part of ISO8859-2    */
  309. X    case GSET_LATIN3R:    /* Right part of ISO8859-3    */
  310. X    case GSET_LATIN4R:    /* Right part of ISO8859-4    */
  311. X    case GSET_LATIN7R:    /* Right part of ISO8859-7    */
  312. X    case GSET_LATIN6R:    /* Right part of ISO8859-6    */
  313. X    case GSET_LATIN8R:    /* Right part of ISO8859-8    */
  314. X    case GSET_LATIN5R:    /* Right part of ISO8859-5    */
  315. X    case GSET_LATIN9R:    /* Right part of ISO8859-9    */
  316. X    case GSET_KANJI:    /* JISX0208 Kanji set        */
  317. X    case GSET_OLDKANJI:    /* JISX0208 Kanji set        */
  318. #ifdef KTERM_HANZI
  319. X        case GSET_HANZI:        /* GB2312 Hanzi set */
  320. #endif /* KTERM_HANZI */
  321. #ifdef KTERM_HANGUL
  322. X        case GSET_HANGUL:    /* KSC5601 Hangul set */
  323. #endif /* KTERM_HANGUL */
  324. X
  325. X                if (FontType(screen, FNUM(charset), 0) == LOW) {
  326. X                    for (s=buf; s<ptr; ++s) {
  327. X            *s &= ~NEEDMAP;
  328. X                    }
  329. X                }
  330. X                break;
  331. X
  332. X    default:    /* any character sets we don't recognize*/
  333. X        return;
  334. X    }
  335. #else /* !KTERM */
  336. X    switch (charset) {
  337. X    case 'A':    /* United Kingdom set            */
  338. X        for (s=buf; s<ptr; ++s)
  339. X            if (*s == '#')
  340. X                *s = '\036';    /* UK pound sign*/
  341. X        break;
  342. X
  343. X    case 'B':    /* ASCII set                */
  344. X        break;
  345. X
  346. X    case '0':    /* special graphics (line drawing)    */
  347. X        for (s=buf; s<ptr; ++s)
  348. X            if (*s>=0x5f && *s<=0x7e)
  349. X                *s = *s == 0x5f ? 0x7f : *s - 0x5f;
  350. X        break;
  351. X
  352. X    default:    /* any character sets we don't recognize*/
  353. X        return;
  354. X    }
  355. #endif /* !KTERM */
  356. X
  357. X    len = ptr - buf; 
  358. X    ptr = buf;
  359. X    while (len > 0) {
  360. X        n = screen->max_col-screen->cur_col+1;
  361. X        if (n <= 1) {
  362. #ifdef STATUSLINE
  363. X            if (screen->do_wrap && (flags&WRAPAROUND) &&
  364. X                !screen->instatus) {
  365. #else /* !STATUSLINE */
  366. X            if (screen->do_wrap && (flags&WRAPAROUND)) {
  367. #endif /* !STATUSLINE */
  368. X                Index(screen, 1);
  369. X                screen->cur_col = 0;
  370. X                screen->do_wrap = 0;
  371. X                n = screen->max_col+1;
  372. X            } else
  373. X                n = 1;
  374. X        }
  375. X        if (len < n)
  376. X            n = len;
  377. #ifdef KTERM_KANJI
  378. X        if (charset & MBCS) {
  379. X            if (n == 1) {
  380. X                if (flags & WRAPAROUND) {
  381. X                    n--; do_wrap = 1;
  382. X                } else
  383. X                    n++;
  384. X            } else
  385. X                if (n & 1)
  386. X                    n--;
  387. X        }
  388. #endif /* KTERM_KANJI */
  389. X        next_col = screen->cur_col + n;
  390. #ifdef KTERM
  391. X        WriteText(screen, ptr, n, flags, charset);
  392. #else /* !KTERM */
  393. X        WriteText(screen, ptr, n, flags);
  394. #endif /* !KTERM */
  395. X        /*
  396. X         * the call to WriteText updates screen->cur_col.
  397. X         * If screen->cur_col != next_col, we must have
  398. X         * hit the right margin, so set the do_wrap flag.
  399. X         */
  400. X        screen->do_wrap = (screen->cur_col < next_col);
  401. #ifdef KTERM_KANJI
  402. X        screen->do_wrap |= do_wrap;
  403. #endif /* KTERM_KANJI */
  404. X        len -= n;
  405. X        ptr += n;
  406. X    }
  407. }
  408. /*
  409. X * write a string str of length len onto the screen at
  410. X * the current cursor position.  update cursor position.
  411. X */
  412. #ifdef KTERM
  413. WriteText(screen, str, len, flags, gset)
  414. #else /* !KTERM */
  415. WriteText(screen, str, len, flags)
  416. #endif /* !KTERM */
  417. register TScreen    *screen;
  418. register char    *str;
  419. register int    len;
  420. unsigned    flags;
  421. #ifdef KTERM
  422. register Char    gset;
  423. #endif /* KTERM */
  424. {
  425. X    register int cx, cy;
  426. X    register unsigned fgs = flags;
  427. #ifdef KTERM
  428. X    register int    i, n;
  429. X    XChar2b drawbuf[256], *dbuf;
  430. X
  431. X    dbuf = (len > 256) ? (XChar2b *)XtMalloc(len * sizeof(XChar2b))
  432. X               : drawbuf;
  433. #else /* !KTERM */
  434. X    GC    currentGC;
  435. #endif /* !KTERM */
  436. #ifdef STATUSLINE
  437. X   if(screen->instatus && screen->reversestatus)
  438. X    fgs ^= INVERSE;
  439. X   if(screen->cur_row - screen->topline <= screen->max_row ||
  440. X      screen->instatus) {
  441. #else /* !STATUSLINE */
  442. X   if(screen->cur_row - screen->topline <= screen->max_row) {
  443. #endif /* !STATUSLINE */
  444. X    /*
  445. X    if(screen->cur_row == screen->cursor_row && screen->cur_col <=
  446. X     screen->cursor_col && screen->cursor_col <= screen->cur_col + len - 1)
  447. X        screen->cursor_state = OFF;
  448. X     */
  449. X    if(screen->cursor_state)
  450. X        HideCursor();
  451. X
  452. #ifndef KTERM
  453. X    /*
  454. X     *    make sure that the correct GC is current
  455. X     */
  456. X
  457. X    if (fgs & BOLD)
  458. X        if (fgs & INVERSE)
  459. X            currentGC = screen->reverseboldGC;
  460. X        else    currentGC = screen->normalboldGC;
  461. X    else  /* not bold */
  462. X        if (fgs & INVERSE)
  463. X            currentGC = screen->reverseGC;
  464. X        else    currentGC = screen->normalGC;
  465. #endif /* !KTERM */
  466. X
  467. X    if (fgs & INSERT)
  468. X        InsertChar(screen, len);
  469. X      if (!(AddToRefresh(screen))) {
  470. X        if(screen->scroll_amt)
  471. X            FlushScroll(screen);
  472. #ifdef KTERM
  473. #ifdef KTERM_KANJI
  474. X    if (gset & MBCS) {
  475. X        for (i = n = 0; i < len; n++) {
  476. X            dbuf[n].byte1 = str[i++];
  477. X            dbuf[n].byte2 = str[i++];
  478. X        }
  479. X    } else
  480. #endif /* KTERM_KANJI */
  481. X    for (n = 0; n < len; n++) {
  482. X        dbuf[n].byte1 = 0;
  483. X        dbuf[n].byte2 = MapOnFont(gset, str[n]);
  484. X    }
  485. #endif /* KTERM */
  486. X    cx = CursorX(screen, screen->cur_col);
  487. #ifdef KTERM
  488. X    cy = CursorY(screen, screen->cur_row);
  489. #ifdef STATUSLINE
  490. X    if (screen->instatus)
  491. X        cy ++;
  492. #endif /* STATUSLINE */
  493. X    BreakMBchar(screen);
  494. X    screen->cur_col += len;
  495. X    BreakMBchar(screen);
  496. X    screen->cur_col -= len;
  497. #ifdef  COLOR_TEXT /* mukawa */
  498. X    ScreenDraw(screen, cx, cy, dbuf, n, gset, fgs,
  499. #else    /* COLOR_TEXT */
  500. X    ScreenDraw(screen, cx, cy, dbuf, n, gset,
  501. #endif  /* COLOR_TEXT */
  502. X        fgs & BOLD, fgs & INVERSE, fgs & UNDERLINE, False);
  503. #else /* !KTERM */
  504. X    cy = CursorY(screen, screen->cur_row)+screen->fnt_norm->ascent;
  505. X     XDrawImageString(screen->display, TextWindow(screen), currentGC,
  506. X            cx, cy, str, len);
  507. X
  508. X    if((fgs & BOLD) && screen->enbolden) 
  509. X        if (currentGC == screen->normalGC || screen->reverseGC)
  510. X            XDrawString(screen->display, TextWindow(screen),
  511. X                      currentGC,cx + 1, cy, str, len);
  512. X
  513. X    if(fgs & UNDERLINE) 
  514. X        XDrawLine(screen->display, TextWindow(screen), currentGC,
  515. X            cx, cy+1,
  516. X            cx + len * FontWidth(screen), cy+1);
  517. #endif /* !KTERM */
  518. X    /*
  519. X     * the following statements compile data to compute the average 
  520. X     * number of characters written on each call to XText.  The data
  521. X     * may be examined via the use of a "hidden" escape sequence.
  522. X     */
  523. X    ctotal += len;
  524. X    ++ntotal;
  525. X      }
  526. X    }
  527. #ifdef KTERM
  528. X    ScreenWrite(screen, str, flags, gset, len);
  529. #else /* !KTERM */
  530. X    ScreenWrite(screen, str, flags, len);
  531. #endif /* !KTERM */
  532. X    CursorForward(screen, len);
  533. }
  534. /*
  535. X * process ANSI modes set, reset
  536. X */
  537. modes(term, func)
  538. XXtermWidget    term;
  539. int        (*func)();
  540. {
  541. X    register int    i;
  542. X
  543. X    for (i=0; i<nparam; ++i) {
  544. X        switch (param[i]) {
  545. X        case 4:            /* IRM                */
  546. X            (*func)(&term->flags, INSERT);
  547. X            break;
  548. X
  549. X        case 20:        /* LNM                */
  550. X            (*func)(&term->flags, LINEFEED);
  551. X            update_autolinefeed();
  552. X            break;
  553. X        }
  554. X    }
  555. }
  556. X
  557. /*
  558. X * process DEC private modes set, reset
  559. X */
  560. dpmodes(term, func)
  561. XXtermWidget    term;
  562. int        (*func)();
  563. {
  564. X    register TScreen    *screen    = &term->screen;
  565. X    register int    i, j;
  566. X    extern int bitset();
  567. X
  568. X    for (i=0; i<nparam; ++i) {
  569. X        switch (param[i]) {
  570. X        case 1:            /* DECCKM            */
  571. X            (*func)(&term->keyboard.flags, CURSOR_APL);
  572. X            break;
  573. X        case 2:            /* ANSI/VT52 mode        */
  574. X            if (func == bitset) {
  575. X                screen->gsets[0] =
  576. X                    screen->gsets[1] =
  577. X                    screen->gsets[2] =
  578. X                    screen->gsets[3] = 'B';
  579. X                screen->curgl = 0;
  580. X                screen->curgr = 2;
  581. X            }
  582. X            break;
  583. X        case 3:            /* DECCOLM            */
  584. X            if(screen->c132) {
  585. X                ClearScreen(screen);
  586. X                CursorSet(screen, 0, 0, term->flags);
  587. X                if((j = func == bitset ? 132 : 80) !=
  588. X                 ((term->flags & IN132COLUMNS) ? 132 : 80) ||
  589. X                 j != screen->max_col + 1) {
  590. X                        Dimension replyWidth, replyHeight;
  591. X                    XtGeometryResult status;
  592. X
  593. X                    status = XtMakeResizeRequest (
  594. X                        (Widget) term, 
  595. X                        (Dimension) FontWidth(screen) * j
  596. X                            + 2*screen->border
  597. X                        + screen->scrollbar,
  598. X                        (Dimension) FontHeight(screen)
  599. X                        * (screen->max_row + 1)
  600. X                        + 2 * screen->border,
  601. X                        &replyWidth, &replyHeight);
  602. X
  603. X                    if (status == XtGeometryYes ||
  604. X                        status == XtGeometryDone) {
  605. X                        ScreenResize (&term->screen,
  606. X                              replyWidth,
  607. X                              replyHeight,
  608. X                              &term->flags);
  609. X                    }
  610. X                }
  611. X                (*func)(&term->flags, IN132COLUMNS);
  612. X            }
  613. X            break;
  614. X        case 4:            /* DECSCLM (slow scroll)    */
  615. X            if (func == bitset) {
  616. X                screen->jumpscroll = 0;
  617. X                if (screen->scroll_amt)
  618. X                    FlushScroll(screen);
  619. X            } else
  620. X                screen->jumpscroll = 1;
  621. X            (*func)(&term->flags, SMOOTHSCROLL);
  622. X            update_jumpscroll();
  623. X            break;
  624. X        case 5:            /* DECSCNM            */
  625. X            j = term->flags;
  626. X            (*func)(&term->flags, REVERSE_VIDEO);
  627. X            if ((term->flags ^ j) & REVERSE_VIDEO)
  628. X                ReverseVideo(term);
  629. X            /* update_reversevideo done in RevVid */
  630. X            break;
  631. X
  632. X        case 6:            /* DECOM            */
  633. X            (*func)(&term->flags, ORIGIN);
  634. X            CursorSet(screen, 0, 0, term->flags);
  635. X            break;
  636. X
  637. X        case 7:            /* DECAWM            */
  638. X            (*func)(&term->flags, WRAPAROUND);
  639. X            update_autowrap();
  640. X            break;
  641. X        case 8:            /* DECARM            */
  642. X            /* ignore autorepeat */
  643. X            break;
  644. X        case 9:            /* MIT bogus sequence        */
  645. X            if(func == bitset)
  646. X                screen->send_mouse_pos = 1;
  647. X            else
  648. X                screen->send_mouse_pos = 0;
  649. X            break;
  650. X        case 38:        /* DECTEK            */
  651. X            if(func == bitset & !(screen->inhibit & I_TEK)) {
  652. X                if(screen->logging) {
  653. X                    FlushLog(screen);
  654. X                    screen->logstart = Tbuffer;
  655. X                }
  656. X                screen->TekEmu = TRUE;
  657. X            }
  658. X            break;
  659. X        case 40:        /* 132 column mode        */
  660. X            screen->c132 = (func == bitset);
  661. X            update_allow132();
  662. X            break;
  663. X        case 41:        /* curses hack            */
  664. X            screen->curses = (func == bitset);
  665. X            update_cursesemul();
  666. X            break;
  667. X        case 44:        /* margin bell            */
  668. X            screen->marginbell = (func == bitset);
  669. X            if(!screen->marginbell)
  670. X                screen->bellarmed = -1;
  671. X            update_marginbell();
  672. X            break;
  673. X        case 45:        /* reverse wraparound    */
  674. X            (*func)(&term->flags, REVERSEWRAP);
  675. X            update_reversewrap();
  676. X            break;
  677. X        case 46:        /* logging        */
  678. #ifdef ALLOWLOGFILEONOFF
  679. X            /*
  680. X             * if this feature is enabled, logging may be 
  681. X             * enabled and disabled via escape sequences.
  682. X             */
  683. X            if(func == bitset)
  684. X                StartLog(screen);
  685. X            else
  686. X                CloseLog(screen);
  687. #else
  688. X            Bell();
  689. X            Bell();
  690. #endif /* ALLOWLOGFILEONOFF */
  691. X            break;
  692. X        case 47:        /* alternate buffer        */
  693. X            if(func == bitset)
  694. X                ToAlternate(screen);
  695. X            else
  696. X                FromAlternate(screen);
  697. X            break;
  698. #ifdef STATUSLINE
  699. X        case 48:        /* reverse statusline        */
  700. X            j = screen->reversestatus;
  701. X            (*func)(&screen->reversestatus, 1);
  702. X            if (j != screen->reversestatus)
  703. X                ScrnRefresh(screen, screen->max_row + 1, 0, 1,
  704. X                    screen->max_col + 1);
  705. X            break;
  706. #endif /* STATUSLINE */
  707. X        case 1000:        /* xtem bogus sequence        */
  708. X            if(func == bitset)
  709. X                screen->send_mouse_pos = 2;
  710. X            else
  711. X                screen->send_mouse_pos = 0;
  712. X            break;
  713. X        case 1001:        /* xtem sequence w/hilite tracking */
  714. X            if(func == bitset)
  715. X                screen->send_mouse_pos = 3;
  716. X            else
  717. X                screen->send_mouse_pos = 0;
  718. X            break;
  719. X        }
  720. X    }
  721. }
  722. X
  723. /*
  724. X * process xterm private modes save
  725. X */
  726. savemodes(term)
  727. XXtermWidget term;
  728. {
  729. X    register TScreen    *screen    = &term->screen;
  730. X    register int i;
  731. X
  732. X    for (i = 0; i < nparam; i++) {
  733. X        switch (param[i]) {
  734. X        case 1:            /* DECCKM            */
  735. X            screen->save_modes[0] = term->keyboard.flags &
  736. X             CURSOR_APL;
  737. X            break;
  738. X        case 3:            /* DECCOLM            */
  739. X            if(screen->c132)
  740. X                screen->save_modes[1] = term->flags &
  741. X                 IN132COLUMNS;
  742. X            break;
  743. X        case 4:            /* DECSCLM (slow scroll)    */
  744. X            screen->save_modes[2] = term->flags & SMOOTHSCROLL;
  745. X            break;
  746. X        case 5:            /* DECSCNM            */
  747. X            screen->save_modes[3] = term->flags & REVERSE_VIDEO;
  748. X            break;
  749. X        case 6:            /* DECOM            */
  750. X            screen->save_modes[4] = term->flags & ORIGIN;
  751. X            break;
  752. X
  753. X        case 7:            /* DECAWM            */
  754. X            screen->save_modes[5] = term->flags & WRAPAROUND;
  755. X            break;
  756. X        case 8:            /* DECARM            */
  757. X            /* ignore autorepeat */
  758. X            break;
  759. X        case 9:            /* mouse bogus sequence */
  760. X            screen->save_modes[7] = screen->send_mouse_pos;
  761. X            break;
  762. X        case 40:        /* 132 column mode        */
  763. X            screen->save_modes[8] = screen->c132;
  764. X            break;
  765. X        case 41:        /* curses hack            */
  766. X            screen->save_modes[9] = screen->curses;
  767. X            break;
  768. X        case 44:        /* margin bell            */
  769. X            screen->save_modes[12] = screen->marginbell;
  770. X            break;
  771. X        case 45:        /* reverse wraparound    */
  772. X            screen->save_modes[13] = term->flags & REVERSEWRAP;
  773. X            break;
  774. X        case 46:        /* logging        */
  775. X            screen->save_modes[14] = screen->logging;
  776. X            break;
  777. X        case 47:        /* alternate buffer        */
  778. X            screen->save_modes[15] = screen->alternate;
  779. X            break;
  780. #ifdef STATUSLINE
  781. X        case 48:        /* reverse statusline        */
  782. X            screen->save_modes[16] = screen->reversestatus;
  783. X            break;
  784. #endif /* STATUSLINE */
  785. X        case 1000:        /* mouse bogus sequence        */
  786. X        case 1001:
  787. X            screen->save_modes[7] = screen->send_mouse_pos;
  788. X            break;
  789. X        }
  790. X    }
  791. }
  792. X
  793. /*
  794. X * process xterm private modes restore
  795. X */
  796. restoremodes(term)
  797. XXtermWidget term;
  798. {
  799. X    register TScreen    *screen    = &term->screen;
  800. X    register int i, j;
  801. X
  802. X    for (i = 0; i < nparam; i++) {
  803. X        switch (param[i]) {
  804. X        case 1:            /* DECCKM            */
  805. X            term->keyboard.flags &= ~CURSOR_APL;
  806. X            term->keyboard.flags |= screen->save_modes[0] &
  807. X             CURSOR_APL;
  808. X            update_appcursor();
  809. X            break;
  810. X        case 3:            /* DECCOLM            */
  811. X            if(screen->c132) {
  812. X                ClearScreen(screen);
  813. X                CursorSet(screen, 0, 0, term->flags);
  814. X                if((j = (screen->save_modes[1] & IN132COLUMNS)
  815. X                 ? 132 : 80) != ((term->flags & IN132COLUMNS)
  816. X                 ? 132 : 80) || j != screen->max_col + 1) {
  817. X                        Dimension replyWidth, replyHeight;
  818. X                    XtGeometryResult status;
  819. X                    status = XtMakeResizeRequest (
  820. X                        (Widget) term,
  821. X                        (Dimension) FontWidth(screen) * j 
  822. X                        + 2*screen->border
  823. X                        + screen->scrollbar,
  824. X                        (Dimension) FontHeight(screen)
  825. X                        * (screen->max_row + 1)
  826. X                        + 2*screen->border,
  827. X                        &replyWidth, &replyHeight);
  828. X
  829. X                    if (status == XtGeometryYes ||
  830. X                        status == XtGeometryDone) {
  831. X                        ScreenResize (&term->screen,
  832. X                              replyWidth,
  833. X                              replyHeight,
  834. X                              &term->flags);
  835. X                    }
  836. X                }
  837. X                term->flags &= ~IN132COLUMNS;
  838. X                term->flags |= screen->save_modes[1] &
  839. X                 IN132COLUMNS;
  840. X            }
  841. X            break;
  842. X        case 4:            /* DECSCLM (slow scroll)    */
  843. X            if (screen->save_modes[2] & SMOOTHSCROLL) {
  844. X                screen->jumpscroll = 0;
  845. X                if (screen->scroll_amt)
  846. X                    FlushScroll(screen);
  847. X            } else
  848. X                screen->jumpscroll = 1;
  849. X            term->flags &= ~SMOOTHSCROLL;
  850. X            term->flags |= screen->save_modes[2] & SMOOTHSCROLL;
  851. X            update_jumpscroll();
  852. X            break;
  853. X        case 5:            /* DECSCNM            */
  854. X            if((screen->save_modes[3] ^ term->flags) &
  855. X             REVERSE_VIDEO) {
  856. X                term->flags &= ~REVERSE_VIDEO;
  857. X                term->flags |= screen->save_modes[3] &
  858. X                 REVERSE_VIDEO;
  859. X                ReverseVideo(term);
  860. X                /* update_reversevideo done in RevVid */
  861. X            }
  862. X            break;
  863. X        case 6:            /* DECOM            */
  864. X            term->flags &= ~ORIGIN;
  865. X            term->flags |= screen->save_modes[4] & ORIGIN;
  866. X            CursorSet(screen, 0, 0, term->flags);
  867. X            break;
  868. X
  869. X        case 7:            /* DECAWM            */
  870. X            term->flags &= ~WRAPAROUND;
  871. X            term->flags |= screen->save_modes[5] & WRAPAROUND;
  872. X            update_autowrap();
  873. X            break;
  874. X        case 8:            /* DECARM            */
  875. X            /* ignore autorepeat */
  876. X            break;
  877. X        case 9:            /* MIT bogus sequence        */
  878. X            screen->send_mouse_pos = screen->save_modes[7];
  879. X            break;
  880. X        case 40:        /* 132 column mode        */
  881. X            screen->c132 = screen->save_modes[8];
  882. X            update_allow132();
  883. X            break;
  884. X        case 41:        /* curses hack            */
  885. X            screen->curses = screen->save_modes[9];
  886. X            update_cursesemul();
  887. X            break;
  888. X        case 44:        /* margin bell            */
  889. X            if(!(screen->marginbell = screen->save_modes[12]))
  890. X                screen->bellarmed = -1;
  891. X            update_visualbell();
  892. X            break;
  893. X        case 45:        /* reverse wraparound    */
  894. X            term->flags &= ~REVERSEWRAP;
  895. X            term->flags |= screen->save_modes[13] & REVERSEWRAP;
  896. X            update_reversewrap();
  897. X            break;
  898. X        case 46:        /* logging        */
  899. #ifdef ALLOWLOGFILEONOFF
  900. X            if(screen->save_modes[14])
  901. X                StartLog(screen);
  902. X            else
  903. X                CloseLog(screen);
  904. #endif /* ALLOWLOGFILEONOFF */
  905. X            /* update_logging done by StartLog and CloseLog */
  906. X            break;
  907. X        case 47:        /* alternate buffer        */
  908. X            if(screen->save_modes[15])
  909. X                ToAlternate(screen);
  910. X            else
  911. X                FromAlternate(screen);
  912. X            /* update_altscreen done by ToAlt and FromAlt */
  913. X            break;
  914. #ifdef STATUSLINE
  915. X        case 48:        /* reverse statusline        */
  916. X            if (screen->save_modes[16] != screen->reversestatus) {
  917. X                screen->reversestatus = screen->save_modes[16];
  918. X                ScrnRefresh(screen, screen->max_row + 1, 0, 1,
  919. X                        screen->max_col + 1);
  920. X            }
  921. X            break;
  922. #endif /* STATUSLINE */
  923. X        case 1000:        /* mouse bogus sequence        */
  924. X        case 1001:
  925. X            screen->send_mouse_pos = screen->save_modes[7];
  926. X            break;
  927. X        }
  928. X    }
  929. }
  930. X
  931. /*
  932. X * set a bit in a word given a pointer to the word and a mask.
  933. X */
  934. bitset(p, mask)
  935. int    *p;
  936. {
  937. X    *p |= mask;
  938. }
  939. X
  940. /*
  941. X * clear a bit in a word given a pointer to the word and a mask.
  942. X */
  943. bitclr(p, mask)
  944. int    *p;
  945. {
  946. X    *p &= ~mask;
  947. }
  948. X
  949. unparseseq(ap, fd)
  950. register ANSI    *ap;
  951. {
  952. X    register int    c;
  953. X    register int    i;
  954. X    register int    inters;
  955. X
  956. X    c = ap->a_type;
  957. X    if (c>=0x80 && c<=0x9F) {
  958. X        unparseputc(ESC, fd);
  959. X        c -= 0x40;
  960. X    }
  961. X    unparseputc(c, fd);
  962. X    c = ap->a_type;
  963. X    if (c==ESC || c==DCS || c==CSI || c==OSC || c==PM || c==APC) {
  964. X        if (ap->a_pintro != 0)
  965. X            unparseputc((char) ap->a_pintro, fd);
  966. X        for (i=0; i<ap->a_nparam; ++i) {
  967. X            if (i != 0)
  968. X                unparseputc(';', fd);
  969. X            unparseputn((unsigned int) ap->a_param[i], fd);
  970. X        }
  971. X        inters = ap->a_inters;
  972. X        for (i=3; i>=0; --i) {
  973. X            c = (inters >> (8*i)) & 0xff;
  974. X            if (c != 0)
  975. X                unparseputc(c, fd);
  976. X        }
  977. X        unparseputc((char) ap->a_final, fd);
  978. X    }
  979. }
  980. X
  981. unparseputn(n, fd)
  982. unsigned int    n;
  983. int fd;
  984. {
  985. X    unsigned int    q;
  986. X
  987. X    q = n/10;
  988. X    if (q != 0)
  989. X        unparseputn(q, fd);
  990. X    unparseputc((char) ('0' + (n%10)), fd);
  991. }
  992. X
  993. unparseputc(c, fd)
  994. char c;
  995. int fd;
  996. {
  997. X    char    buf[2];
  998. X    register i = 1;
  999. X    extern XtermWidget term;
  1000. X
  1001. X    if((buf[0] = c) == '\r' && (term->flags & LINEFEED)) {
  1002. X        buf[1] = '\n';
  1003. X        i++;
  1004. X    }
  1005. X    if (write(fd, buf, i) != i)
  1006. X        Panic("unparseputc: error writing character\n", 0);
  1007. }
  1008. X
  1009. unparsefputs (s, fd)
  1010. X    register char *s;
  1011. X    int fd;
  1012. {
  1013. X    if (s) {
  1014. X    while (*s) unparseputc (*s++, fd);
  1015. X    }
  1016. }
  1017. X
  1018. X
  1019. ToAlternate(screen)
  1020. register TScreen *screen;
  1021. {
  1022. X    extern ScrnBuf Allocate();
  1023. X
  1024. X    if(screen->alternate)
  1025. X        return;
  1026. X    if(!screen->altbuf)
  1027. X        screen->altbuf = Allocate(screen->max_row + 1, screen->max_col
  1028. X         + 1, &screen->abuf_address);
  1029. X    SwitchBufs(screen);
  1030. X    screen->alternate = TRUE;
  1031. X    update_altscreen();
  1032. }
  1033. X
  1034. XFromAlternate(screen)
  1035. register TScreen *screen;
  1036. {
  1037. X    if(!screen->alternate)
  1038. X        return;
  1039. X    screen->alternate = FALSE;
  1040. X    SwitchBufs(screen);
  1041. X    update_altscreen();
  1042. }
  1043. X
  1044. SwitchBufs(screen)
  1045. register TScreen *screen;
  1046. {
  1047. X    register int rows, top;
  1048. #ifdef KTERM
  1049. X    Bchr *save [MAX_ROWS];
  1050. #else /* !KTERM */
  1051. X    char *save [2 * MAX_ROWS];
  1052. #endif /* !KTERM */
  1053. X
  1054. X    if(screen->cursor_state)
  1055. X        HideCursor();
  1056. X    rows = screen->max_row + 1;
  1057. #ifdef KTERM
  1058. X    bcopy((char *)screen->buf, (char *)save, sizeof(Bchr *) * rows);
  1059. X    bcopy((char *)screen->altbuf, (char *)screen->buf, sizeof(Bchr *) *
  1060. X     rows);
  1061. X    bcopy((char *)save, (char *)screen->altbuf, sizeof(Bchr *) * rows);
  1062. #else /* !KTERM */
  1063. X    bcopy((char *)screen->buf, (char *)save, 2 * sizeof(char *) * rows);
  1064. X    bcopy((char *)screen->altbuf, (char *)screen->buf, 2 * sizeof(char *) *
  1065. X     rows);
  1066. X    bcopy((char *)save, (char *)screen->altbuf, 2 * sizeof(char *) * rows);
  1067. #endif /* !KTERM */
  1068. X
  1069. X    if((top = -screen->topline) <= screen->max_row) {
  1070. X        if(screen->scroll_amt)
  1071. X            FlushScroll(screen);
  1072. #ifdef STATUSLINE
  1073. X        if(top == 0 && !screen->statusline)
  1074. #else /* !STATUSLINE */
  1075. X        if(top == 0)
  1076. #endif /* !STATUSLINE */
  1077. X            XClearWindow(screen->display, TextWindow(screen));
  1078. X        else
  1079. X            XClearArea(
  1080. X                screen->display,
  1081. X                TextWindow(screen),
  1082. X                (int) screen->border + screen->scrollbar,
  1083. X                (int) top * FontHeight(screen) + screen->border,
  1084. X                (unsigned) Width(screen),
  1085. X                (unsigned) (screen->max_row - top + 1)
  1086. X                * FontHeight(screen),
  1087. X                FALSE);
  1088. X    }
  1089. #ifndef ENBUG /* kagotani */
  1090. X    TrackText(0, 0, 0, 0);
  1091. #endif
  1092. X    ScrnRefresh(screen, 0, 0, rows, screen->max_col + 1, False);
  1093. }
  1094. X
  1095. VTRun()
  1096. {
  1097. X    register TScreen *screen = &term->screen;
  1098. X    register int i;
  1099. X    
  1100. X    if (!screen->Vshow) {
  1101. X        XtRealizeWidget (term->core.parent);
  1102. X        set_vt_visibility (TRUE);
  1103. X    } 
  1104. X    update_vttekmode();
  1105. X    update_vtshow();
  1106. X    update_tekshow();
  1107. X    set_vthide_sensitivity();
  1108. X
  1109. X    if (screen->allbuf == NULL) VTallocbuf ();
  1110. X
  1111. X    screen->cursor_state = OFF;
  1112. X    screen->cursor_set = ON;
  1113. X
  1114. X    bcnt = 0;
  1115. X    bptr = buffer;
  1116. X    while(Tpushb > Tpushback) {
  1117. X        *bptr++ = *--Tpushb;
  1118. X        bcnt++;
  1119. X    }
  1120. X    bcnt += (i = Tbcnt);
  1121. X    for( ; i > 0 ; i--)
  1122. X        *bptr++ = *Tbptr++;
  1123. X    bptr = buffer;
  1124. X    if(!setjmp(VTend))
  1125. X        VTparse();
  1126. X    HideCursor();
  1127. X    screen->cursor_set = OFF;
  1128. }
  1129. X
  1130. /*ARGSUSED*/
  1131. static void VTExpose(w, event, region)
  1132. Widget w;
  1133. XXEvent *event;
  1134. Region region;
  1135. {
  1136. X    register TScreen *screen = &term->screen;
  1137. X
  1138. #ifdef DEBUG
  1139. X    if(debug)
  1140. X        fputs("Expose\n", stderr);
  1141. #endif    /* DEBUG */
  1142. X    if (event->type == Expose)
  1143. X        HandleExposure (screen, (XExposeEvent *)event);
  1144. }
  1145. X
  1146. static void VTGraphicsOrNoExpose (event)
  1147. XXEvent *event;
  1148. X    {
  1149. X    register TScreen *screen = &term->screen;
  1150. X    if (screen->incopy <= 0) {
  1151. X        screen->incopy = 1;
  1152. X        if (screen->scrolls > 0)
  1153. X            screen->scrolls--;
  1154. X    }
  1155. X    if (event->type == GraphicsExpose)
  1156. X      if (HandleExposure (screen, (XExposeEvent *)event))
  1157. X        screen->cursor_state = OFF;
  1158. X    if ((event->type == NoExpose) || ((XGraphicsExposeEvent *)event)->count == 0) {
  1159. X        if (screen->incopy <= 0 && screen->scrolls > 0)
  1160. X            screen->scrolls--;
  1161. X        if (screen->scrolls)
  1162. X            screen->incopy = -1;
  1163. X        else
  1164. X            screen->incopy = 0;
  1165. X    }
  1166. }
  1167. X
  1168. /*ARGSUSED*/
  1169. static void VTNonMaskableEvent (w, closure, event)
  1170. Widget w;
  1171. caddr_t closure;
  1172. XXEvent *event;
  1173. X    {
  1174. X    switch (event->type) {
  1175. X       case MappingNotify:
  1176. X      XRefreshKeyboardMapping (&event->xmapping);
  1177. X      break;
  1178. X       case GraphicsExpose:
  1179. X       case NoExpose:
  1180. X      VTGraphicsOrNoExpose (event);
  1181. X      break;
  1182. X      }
  1183. X    }
  1184. X
  1185. X
  1186. X
  1187. X
  1188. static void VTResize(w)
  1189. X    Widget w;
  1190. {
  1191. X    if (XtIsRealized(w))
  1192. X      ScreenResize (&term->screen, term->core.width, term->core.height,
  1193. X            &term->flags);
  1194. }
  1195. X
  1196. X
  1197. int VTInit ()
  1198. {
  1199. X    register TScreen *screen = &term->screen;
  1200. X
  1201. X    XtRealizeWidget (term->core.parent);
  1202. X    if (screen->allbuf == NULL) VTallocbuf ();
  1203. X    return (1);
  1204. }
  1205. X
  1206. static void VTallocbuf ()
  1207. {
  1208. X    register TScreen *screen = &term->screen;
  1209. X    int nrows = screen->max_row + 1;
  1210. X    extern ScrnBuf Allocate();
  1211. X
  1212. X    /* allocate screen buffer now, if necessary. */
  1213. X    if (screen->scrollWidget)
  1214. X      nrows += screen->savelines;
  1215. X    screen->allbuf = Allocate (nrows, screen->max_col + 1,
  1216. X     &screen->sbuf_address);
  1217. X    if (screen->scrollWidget)
  1218. #ifdef KTERM
  1219. X      screen->buf = &screen->allbuf[screen->savelines];
  1220. #else /* !KTERM */
  1221. X      screen->buf = &screen->allbuf[2 * screen->savelines];
  1222. #endif /* !KTERM */
  1223. X    else
  1224. X      screen->buf = screen->allbuf;
  1225. X    return;
  1226. }
  1227. X
  1228. static void VTInitialize (request, new)
  1229. X   XtermWidget request, new;
  1230. {
  1231. X   int i;
  1232. #ifdef KTERM
  1233. X   int fnum;
  1234. #endif /* KTERM */
  1235. X   /* Zero out the entire "screen" component of "new" widget,
  1236. X      then do field-by-field assigment of "screen" fields
  1237. X      that are named in the resource list. */
  1238. X
  1239. X   bzero ((char *) &new->screen, sizeof(new->screen));
  1240. X   new->screen.c132 = request->screen.c132;
  1241. X   new->screen.curses = request->screen.curses;
  1242. X   new->screen.foreground = request->screen.foreground;
  1243. X   new->screen.cursorcolor = request->screen.cursorcolor;
  1244. #ifdef  COLOR_TEXT /* mukawa */
  1245. X   new->screen.textcolor[0] = request->screen.textcolor[0];
  1246. X   new->screen.textcolor[1] = request->screen.textcolor[1];
  1247. X   new->screen.textcolor[2] = request->screen.textcolor[2];
  1248. X   new->screen.textcolor[3] = request->screen.textcolor[3];
  1249. X   new->screen.textcolor[4] = request->screen.textcolor[4];
  1250. X   new->screen.textcolor[5] = request->screen.textcolor[5];
  1251. X   new->screen.textcolor[6] = request->screen.textcolor[6];
  1252. X   new->screen.textcolor[7] = request->screen.textcolor[7];
  1253. #endif  /* COLOR_TEXT */
  1254. X   new->screen.border = request->screen.border;
  1255. X   new->screen.jumpscroll = request->screen.jumpscroll;
  1256. X   new->screen.logfile = request->screen.logfile;
  1257. X   new->screen.marginbell = request->screen.marginbell;
  1258. X   new->screen.mousecolor = request->screen.mousecolor;
  1259. X   new->screen.mousecolorback = request->screen.mousecolorback;
  1260. X   new->screen.multiscroll = request->screen.multiscroll;
  1261. X   new->screen.nmarginbell = request->screen.nmarginbell;
  1262. X   new->screen.savelines = request->screen.savelines;
  1263. X   new->screen.scrolllines = request->screen.scrolllines;
  1264. X   new->screen.scrollttyoutput = request->screen.scrollttyoutput;
  1265. X   new->screen.scrollkey = request->screen.scrollkey;
  1266. X   new->screen.visualbell = request->screen.visualbell;
  1267. X   new->screen.TekEmu = request->screen.TekEmu;
  1268. X   new->misc.re_verse = request->misc.re_verse;
  1269. X   new->screen.multiClickTime = request->screen.multiClickTime;
  1270. X   new->screen.charClass = request->screen.charClass;
  1271. X   new->screen.cutNewline = request->screen.cutNewline;
  1272. X   new->screen.cutToBeginningOfLine = request->screen.cutToBeginningOfLine;
  1273. X   new->screen.always_highlight = request->screen.always_highlight;
  1274. X   new->screen.pointer_cursor = request->screen.pointer_cursor;
  1275. X   new->screen.eight_bits = request->screen.eight_bits;
  1276. X   new->screen.allowSendEvents = request->screen.allowSendEvents;
  1277. X   new->misc.titeInhibit = request->misc.titeInhibit;
  1278. #ifdef KTERM
  1279. X  for (fnum = F_ISO8859_1; fnum < FCNT; fnum++) {
  1280. #endif /* KTERM */
  1281. X   for (i = 0; i < NMENUFONTS; i++) {
  1282. X       new->screen.menu_font_names[i] = request->screen.menu_font_names[i];
  1283. X   }
  1284. X   /* set default in realize proc */
  1285. X   new->screen.menu_font_names[fontMenu_fontdefault] = NULL;
  1286. X   new->screen.menu_font_names[fontMenu_fontescape] = NULL;
  1287. X   new->screen.menu_font_names[fontMenu_fontsel] = NULL;
  1288. #ifdef KTERM
  1289. X   new->screen.menu_bfont_names[fontMenu_fontdefault] = NULL;
  1290. X   new->screen.menu_bfont_names[fontMenu_fontescape] = NULL;
  1291. X   new->screen.menu_bfont_names[fontMenu_fontsel] = NULL;
  1292. X  }
  1293. X   for (i = 0; i < NMENUFONTS; i++) {
  1294. X       new->screen.menu_font_list[i] = request->screen.menu_font_list[i];
  1295. X       new->screen.menu_bfont_list[i] = request->screen.menu_bfont_list[i];
  1296. X   }
  1297. X   /* set default in realize proc */
  1298. X   new->screen.menu_font_list[fontMenu_fontdefault] = NULL;
  1299. X   new->screen.menu_font_list[fontMenu_fontescape] = NULL;
  1300. X   new->screen.menu_font_list[fontMenu_fontsel] = NULL;
  1301. X   new->screen.menu_bfont_list[fontMenu_fontdefault] = NULL;
  1302. X   new->screen.menu_bfont_list[fontMenu_fontescape] = NULL;
  1303. X   new->screen.menu_bfont_list[fontMenu_fontsel] = NULL;
  1304. #endif /* KTERM */
  1305. X   new->screen.menu_font_number = fontMenu_fontdefault;
  1306. #ifdef STATUSLINE
  1307. X   new->screen.statusline = request->screen.statusline;
  1308. X   new->screen.reversestatus = request->screen.reversestatus;
  1309. #endif /* STATUSLINE */
  1310. #ifdef KTERM
  1311. X   new->screen.linespace = request->screen.linespace;
  1312. #endif /* KTERM */
  1313. X
  1314. X    /*
  1315. X     * The definition of -rv now is that it changes the definition of 
  1316. X     * XtDefaultForeground and XtDefaultBackground.  So, we no longer
  1317. X     * need to do anything special.
  1318. X     */
  1319. X   new->keyboard.flags = 0;
  1320. X   new->screen.display = new->core.screen->display;
  1321. X   new->core.height = new->core.width = 1;
  1322. X      /* dummy values so that we don't try to Realize the parent shell 
  1323. X     with height or width of 0, which is illegal in X.  The real
  1324. X     size is computed in the xtermWidget's Realize proc,
  1325. X     but the shell's Realize proc is called first, and must see
  1326. X     a valid size. */
  1327. X
  1328. X   /* look for focus related events on the shell, because we need
  1329. X    * to care about the shell's border being part of our focus.
  1330. X    */
  1331. X   XtAddEventHandler(XtParent(new), EnterWindowMask, FALSE,
  1332. X        HandleEnterWindow, (Opaque)NULL);
  1333. X   XtAddEventHandler(XtParent(new), LeaveWindowMask, FALSE,
  1334. X        HandleLeaveWindow, (Opaque)NULL);
  1335. X   XtAddEventHandler(XtParent(new), FocusChangeMask, FALSE,
  1336. X        HandleFocusChange, (Opaque)NULL);
  1337. X   XtAddEventHandler(new, 0L, TRUE,
  1338. X        VTNonMaskableEvent, (Opaque)NULL);
  1339. X
  1340. X   set_character_class (new->screen.charClass);
  1341. X
  1342. X   /* create it, but don't realize it */
  1343. X   ScrollBarOn (new, TRUE, FALSE);
  1344. X   return;
  1345. }
  1346. X
  1347. X
  1348. static void VTDestroy (w)
  1349. Widget w;
  1350. {
  1351. X    XtFree(((XtermWidget)w)->screen.selection);
  1352. }
  1353. X
  1354. /*ARGSUSED*/
  1355. static void VTRealize (w, valuemask, values)
  1356. Widget w;
  1357. XXtValueMask *valuemask;
  1358. XXSetWindowAttributes *values;
  1359. {
  1360. X    unsigned int width, height;
  1361. X    register TScreen *screen = &term->screen;
  1362. X    int xpos, ypos, pr;
  1363. X    extern char *malloc();
  1364. X    XSizeHints        sizehints;
  1365. X    extern int        VTgcFontMask;
  1366. X    int scrollbar_width;
  1367. #ifdef KTERM
  1368. X    int fnum = F_ISO8859_1;
  1369. #endif /* KTERM */
  1370. X
  1371. X    TabReset (term->tabs);
  1372. X
  1373. #ifdef KTERM
  1374. X    screen->menu_font_list[fontMenu_fontdefault] = term->misc.fontlist;
  1375. X    screen->menu_bfont_list[fontMenu_fontdefault] = term->misc.bfontlist;
  1376. X    for (fnum = F_ISO8859_1; fnum < FCNT; fnum ++) {
  1377. X        screen->menu_font_names[fontMenu_fontdefault] = term->misc.f_n;
  1378. X        screen->menu_bfont_names[fontMenu_fontdefault] = term->misc.f_b;
  1379. X        screen->fnt_norm = screen->fnt_bold = NULL;
  1380. X    }
  1381. X    fnum = F_ISO8859_1;
  1382. X    if (!LoadNewFont(screen, NULL, NULL, False, 0)) {
  1383. X        if (term->misc.f_n == NULL
  1384. X         || XmuCompareISOLatin1(term->misc.f_n, "fixed") != 0) {
  1385. #else /* !KTERM */
  1386. X    screen->menu_font_names[fontMenu_fontdefault] = term->misc.f_n;
  1387. X    screen->fnt_norm = screen->fnt_bold = NULL;
  1388. X    if (!LoadNewFont(screen, term->misc.f_n, term->misc.f_b, False, 0)) {
  1389. X        if (XmuCompareISOLatin1(term->misc.f_n, "fixed") != 0) {
  1390. #endif /* !KTERM */
  1391. X        fprintf (stderr, 
  1392. X             "%s:  unable to open font \"%s\", trying \"fixed\"....\n",
  1393. X             xterm_name, term->misc.f_n);
  1394. #ifdef KTERM
  1395. X        screen->menu_font_names[fontMenu_fontdefault] = "fixed";
  1396. X        (void) LoadNewFont (screen, NULL, NULL, False, 0);
  1397. #else /* !KTERM */
  1398. X        (void) LoadNewFont (screen, "fixed", NULL, False, 0);
  1399. X        screen->menu_font_names[fontMenu_fontdefault] = "fixed";
  1400. #endif /* !KTERM */
  1401. X        }
  1402. X    }
  1403. X
  1404. X    /* really screwed if we couldn't open default font */
  1405. X    if (!screen->fnt_norm) {
  1406. X        fprintf (stderr, "%s:  unable to locate a suitable font\n",
  1407. X             xterm_name);
  1408. X        Exit (1);
  1409. X    }
  1410. X
  1411. X    /* making cursor */
  1412. X    if (!screen->pointer_cursor) 
  1413. X      screen->pointer_cursor = make_colored_cursor(XC_xterm, 
  1414. X                               screen->mousecolor,
  1415. X                               screen->mousecolorback);
  1416. X    else 
  1417. X      recolor_cursor (screen->pointer_cursor, 
  1418. X              screen->mousecolor, screen->mousecolorback);
  1419. X
  1420. X    scrollbar_width = (term->misc.scrollbar ?
  1421. X               screen->scrollWidget->core.width : 0);
  1422. X
  1423. X
  1424. X    /* set defaults */
  1425. X    xpos = 1; ypos = 1; width = 80; height = 24;
  1426. X    pr = XParseGeometry (term->misc.geo_metry, &xpos, &ypos,
  1427. X                 &width, &height);
  1428. X    screen->max_col = (width - 1);    /* units in character cells */
  1429. X    screen->max_row = (height - 1);    /* units in character cells */
  1430. X    update_font_info (&term->screen, False);
  1431. X
  1432. X    width = screen->fullVwin.fullwidth;
  1433. X    height = screen->fullVwin.fullheight;
  1434. X
  1435. X    if ((pr & XValue) && (XNegative&pr)) 
  1436. X      xpos += DisplayWidth(screen->display, DefaultScreen(screen->display))
  1437. X            - width - (term->core.parent->core.border_width * 2);
  1438. X    if ((pr & YValue) && (YNegative&pr))
  1439. X      ypos += DisplayHeight(screen->display,DefaultScreen(screen->display))
  1440. X            - height - (term->core.parent->core.border_width * 2);
  1441. X
  1442. X    /* set up size hints for window manager; min 1 char by 1 char */
  1443. X    sizehints.base_width = 2 * screen->border + scrollbar_width;
  1444. X    sizehints.base_height = 2 * screen->border;
  1445. X    sizehints.width_inc = FontWidth(screen);
  1446. X    sizehints.height_inc = FontHeight(screen);
  1447. X    sizehints.min_width = sizehints.base_width + sizehints.width_inc;
  1448. X    sizehints.min_height = sizehints.base_height + sizehints.height_inc;
  1449. X    sizehints.flags = (PBaseSize|PMinSize|PResizeInc);
  1450. X    sizehints.x = xpos;
  1451. X    sizehints.y = ypos;
  1452. X    if ((XValue&pr) || (YValue&pr)) {
  1453. X        sizehints.flags |= USSize|USPosition;
  1454. X        sizehints.flags |= PWinGravity;
  1455. X        switch (pr & (XNegative | YNegative)) {
  1456. X          case 0:
  1457. X        sizehints.win_gravity = NorthWestGravity;
  1458. X        break;
  1459. X          case XNegative:
  1460. X        sizehints.win_gravity = NorthEastGravity;
  1461. X        break;
  1462. X          case YNegative:
  1463. X        sizehints.win_gravity = SouthWestGravity;
  1464. X        break;
  1465. X          default:
  1466. X        sizehints.win_gravity = SouthEastGravity;
  1467. X        break;
  1468. X        }
  1469. X    } else {
  1470. X        /* set a default size, but do *not* set position */
  1471. X        sizehints.flags |= PSize;
  1472. X    }
  1473. X    sizehints.width = width;
  1474. X    sizehints.height = height;
  1475. X    if ((WidthValue&pr) || (HeightValue&pr)) 
  1476. X      sizehints.flags |= USSize;
  1477. X    else sizehints.flags |= PSize;
  1478. #ifdef STATUSLINE
  1479. X    sizehints.base_height += screen->statusheight;
  1480. X    sizehints.min_height += screen->statusheight;
  1481. #endif /* STATUSLINE */
  1482. X
  1483. X    (void) XtMakeResizeRequest((Widget) term,
  1484. X                   (Dimension)width, (Dimension)height,
  1485. X                   &term->core.width, &term->core.height);
  1486. X
  1487. X    /* XXX This is bogus.  We are parsing geometries too late.  This
  1488. X     * is information that the shell widget ought to have before we get
  1489. X     * realized, so that it can do the right thing.
  1490. X     */
  1491. X        if (sizehints.flags & USPosition)
  1492. X        XMoveWindow (XtDisplay(term), term->core.parent->core.window,
  1493. X             sizehints.x, sizehints.y);
  1494. X
  1495. X    XSetWMNormalHints (XtDisplay(term), term->core.parent->core.window,
  1496. X               &sizehints);
  1497. X
  1498. #ifdef STATUSLINE
  1499. X    values->bit_gravity = ForgetGravity;
  1500. #else /* !STATUSLINE */
  1501. X    values->bit_gravity = NorthWestGravity;
  1502. #endif /* !STATUSLINE */
  1503. X    term->screen.fullVwin.window = term->core.window =
  1504. X      XCreateWindow(XtDisplay(term), XtWindow(term->core.parent),
  1505. X        term->core.x, term->core.y,
  1506. X        term->core.width, term->core.height, term->core.border_width,
  1507. X        (int) term->core.depth,
  1508. X        InputOutput, CopyFromParent,    
  1509. X        *valuemask|CWBitGravity, values);
  1510. X
  1511. #ifdef KTERM
  1512. X    set_cursor_gcs (screen, F_ISO8859_1);
  1513. #else /* !KTERM */
  1514. X    set_cursor_gcs (screen);
  1515. #endif /* !KTERM */
  1516. X
  1517. X    /* Reset variables used by ANSI emulation. */
  1518. X
  1519. #ifdef KTERM
  1520. X    screen->gsets[0] = GSET_ASCII;
  1521. # ifdef KTERM_KANJI
  1522. X        switch(term->misc.lang[0]) {
  1523. #  ifdef KTERM_HANZI
  1524. X          case 'c': case 'C':
  1525. X            screen->gsets[1] = GSET_HANZI;
  1526. X            screen->gsets[2] = GSET_ASCII;
  1527. X            break;
  1528. #  endif /* KTERM_HANZI */
  1529. #  ifdef KTERM_HANGUL
  1530. X          case 'k': case 'K':
  1531. X            screen->gsets[1] = GSET_HANGUL;
  1532. X            screen->gsets[2] = GSET_ASCII;
  1533. X            break;
  1534. #  endif /* KTERM_HANGUL */
  1535. X          default:
  1536. X            screen->gsets[1] = (term->flags & EUC_KANJI) ? GSET_KANJI : GSET_KANA;
  1537. X            screen->gsets[2] = (term->flags & EUC_KANJI) ? GSET_KANA : GSET_ASCII;
  1538. X            break;
  1539. X        }
  1540. # else /* !KTERM_KANJI */
  1541. X    screen->gsets[1] = GSET_KANA;
  1542. X    screen->gsets[2] = GSET_ASCII;
  1543. # endif /* !KTERM_KANJI */
  1544. X    screen->gsets[3] = GSET_ASCII;
  1545. #else /* !KTERM */
  1546. X    screen->gsets[0] = 'B';            /* ASCII_G        */
  1547. X    screen->gsets[1] = 'B';
  1548. X    screen->gsets[2] = 'B';            /* DEC supplemental.    */
  1549. X    screen->gsets[3] = 'B';
  1550. #endif /* !KTERM */
  1551. X    screen->curgl = 0;            /* G0 => GL.        */
  1552. #ifdef KTERM
  1553. X    screen->curgr = 1;            /* G1 => GR.        */
  1554. #else /* !KTERM */
  1555. X    screen->curgr = 2;            /* G2 => GR.        */
  1556. #endif /* !KTERM */
  1557. X    screen->curss = 0;            /* No single shift.    */
  1558. X
  1559. X    XDefineCursor(screen->display, VShellWindow, screen->pointer_cursor);
  1560. X
  1561. X        screen->cur_col = screen->cur_row = 0;
  1562. #ifdef KTERM
  1563. X    screen->max_col = Width(screen)/FontWidth(screen) - 1;
  1564. X    screen->top_marg = 0;
  1565. X    screen->bot_marg = screen->max_row = Height(screen) /
  1566. X                FontHeight(screen) - 1;
  1567. #else /* !KTERM */
  1568. X    screen->max_col = Width(screen)/screen->fullVwin.f_width - 1;
  1569. X    screen->top_marg = 0;
  1570. X    screen->bot_marg = screen->max_row = Height(screen) /
  1571. X                screen->fullVwin.f_height - 1;
  1572. #endif /* !KTERM */
  1573. X
  1574. X    screen->sc.row = screen->sc.col = screen->sc.flags = NULL;
  1575. X
  1576. X    /* Mark screen buffer as unallocated.  We wait until the run loop so
  1577. X       that the child process does not fork and exec with all the dynamic
  1578. X       memory it will never use.  If we were to do it here, the
  1579. X       swap space for new process would be huge for huge savelines. */
  1580. X    if (!tekWidget)            /* if not called after fork */
  1581. X      screen->buf = screen->allbuf = NULL;
  1582. X
  1583. X    screen->do_wrap = NULL;
  1584. X    screen->scrolls = screen->incopy = 0;
  1585. X    set_vt_box (screen);
  1586. #ifdef STATUSLINE
  1587. X    status_box[0].x = screen->border - 1;
  1588. #endif /* STATUSLINE */
  1589. X
  1590. X    screen->savedlines = 0;
  1591. X
  1592. X    if (term->misc.scrollbar) {
  1593. X        screen->scrollbar = 0;
  1594. X        ScrollBarOn (term, FALSE, TRUE);
  1595. X    }
  1596. X    CursorSave (term, &screen->sc);
  1597. X    return;
  1598. }
  1599. X
  1600. /*
  1601. X * Shows cursor at new cursor position in screen.
  1602. X */
  1603. ShowCursor()
  1604. {
  1605. X    register TScreen *screen = &term->screen;
  1606. X    register int x, y, flags;
  1607. #ifdef KTERM
  1608. X    XChar2b c;
  1609. X    Char gset;
  1610. #else /* !KTERM */
  1611. X    Char c;
  1612. X    GC    currentGC;
  1613. #endif /* !KTERM */
  1614. X    Boolean    in_selection;
  1615. X
  1616. X    if (eventMode != NORMAL) return;
  1617. X
  1618. #ifdef STATUSLINE
  1619. X    if (!screen->instatus &&
  1620. X        screen->cur_row - screen->topline > screen->max_row)
  1621. #else /* !STATUSLINE */
  1622. X    if (screen->cur_row - screen->topline > screen->max_row)
  1623. #endif /* !STATUSLINE */
  1624. X        return;
  1625. #ifdef KTERM
  1626. X    gset = screen->buf[y = screen->cursor_row = screen->cur_row]
  1627. X                [x = screen->cursor_col = screen->cur_col].gset;
  1628. X    if (gset == MBC2) {
  1629. X        gset = screen->buf[y][x-1].gset;
  1630. X        x --;
  1631. X    }
  1632. X    if (gset & MBCS) {
  1633. X        c.byte1 = screen->buf[y][x].code;
  1634. X        c.byte2 = screen->buf[y][x+1].code;
  1635. X    } else {
  1636. X        c.byte1 = 0;
  1637. X        c.byte2 = screen->buf[y][x].code;
  1638. X        if (c.byte2 == 0) {
  1639. X            c.byte2 = ' ';
  1640. X            gset = GSET_ASCII;
  1641. X        }
  1642. X    }
  1643. X    flags = screen->buf[y][x].attr;
  1644. #else /* !KTERM */
  1645. X    c = screen->buf[y = 2 * (screen->cursor_row = screen->cur_row)]
  1646. X     [x = screen->cursor_col = screen->cur_col];
  1647. X    flags = screen->buf[y + 1][x];
  1648. X    if (c == 0)
  1649. X        c = ' ';
  1650. #endif /* !KTERM */
  1651. X
  1652. X    if (screen->cur_row > screen->endHRow ||
  1653. X        (screen->cur_row == screen->endHRow &&
  1654. X         screen->cur_col >= screen->endHCol) ||
  1655. X        screen->cur_row < screen->startHRow ||
  1656. X        (screen->cur_row == screen->startHRow &&
  1657. X         screen->cur_col < screen->startHCol))
  1658. X        in_selection = False;
  1659. X    else
  1660. X        in_selection = True;
  1661. X
  1662. #ifdef STATUSLINE
  1663. X    if (screen->instatus && screen->reversestatus)
  1664. X        flags ^= INVERSE;
  1665. #endif /* STATUSLINE */
  1666. X
  1667. #ifdef KTERM
  1668. X    x = CursorX(screen, x);
  1669. X    y = CursorY(screen, y);
  1670. #ifdef  COLOR_TEXT /* mukawa */
  1671. X    ScreenDraw(screen, x, y, &c, 1, gset, flags,
  1672. #else    /* COLOR_TEXT */
  1673. X    ScreenDraw(screen, x, y, &c, 1, gset,
  1674. #endif  /* COLOR_TEXT */
  1675. X        flags & BOLD,
  1676. X        (screen->select || screen->always_highlight)
  1677. X        ^ ((flags & INVERSE) != 0) ^ (in_selection != 0),
  1678. X        flags & UNDERLINE,
  1679. X        True);
  1680. #else /* !KTERM */
  1681. X    if(screen->select || screen->always_highlight) {
  1682. X        if (( (flags & INVERSE) && !in_selection) ||
  1683. X            (!(flags & INVERSE) &&  in_selection)){
  1684. X            /* text is reverse video */
  1685. X            if (screen->cursorGC) {
  1686. X            currentGC = screen->cursorGC;
  1687. X            } else {
  1688. X            if (flags & BOLD) {
  1689. X                currentGC = screen->normalboldGC;
  1690. X            } else {
  1691. X                currentGC = screen->normalGC;
  1692. X            }
  1693. X            }
  1694. X        } else { /* normal video */
  1695. X            if (screen->reversecursorGC) {
  1696. X            currentGC = screen->reversecursorGC;
  1697. X            } else {
  1698. X            if (flags & BOLD) {
  1699. X                currentGC = screen->reverseboldGC;
  1700. X            } else {
  1701. X                currentGC = screen->reverseGC;
  1702. X            }
  1703. X            }
  1704. X        }
  1705. X    } else { /* not selected */
  1706. X        if (( (flags & INVERSE) && !in_selection) ||
  1707. X            (!(flags & INVERSE) &&  in_selection)) {
  1708. X            /* text is reverse video */
  1709. X            currentGC = screen->reverseGC;
  1710. X        } else { /* normal video */
  1711. X            currentGC = screen->normalGC;
  1712. X        }
  1713. X        
  1714. X    }
  1715. X
  1716. X    x = CursorX (screen, screen->cur_col);
  1717. X    y = CursorY(screen, screen->cur_row) + 
  1718. X      screen->fnt_norm->ascent;
  1719. X    XDrawImageString(screen->display, TextWindow(screen), currentGC,
  1720. X        x, y, (char *) &c, 1);
  1721. X
  1722. X    if((flags & BOLD) && screen->enbolden) /* no bold font */
  1723. X        XDrawString(screen->display, TextWindow(screen), currentGC,
  1724. X            x + 1, y, (char *) &c, 1);
  1725. X    if(flags & UNDERLINE) 
  1726. X        XDrawLine(screen->display, TextWindow(screen), currentGC,
  1727. X            x, y+1, x + FontWidth(screen), y+1);
  1728. X    if (!screen->select && !screen->always_highlight) {
  1729. X        screen->box->x = x;
  1730. X        screen->box->y = y - screen->fnt_norm->ascent;
  1731. X        XDrawLines (screen->display, TextWindow(screen), 
  1732. X                screen->cursoroutlineGC ? screen->cursoroutlineGC 
  1733. X                                : currentGC,
  1734. X                screen->box, NBOX, CoordModePrevious);
  1735. X    }
  1736. #endif /* !KTERM */
  1737. X    screen->cursor_state = ON;
  1738. }
  1739. X
  1740. /*
  1741. X * hide cursor at previous cursor position in screen.
  1742. X */
  1743. HideCursor()
  1744. {
  1745. X    register TScreen *screen = &term->screen;
  1746. #ifdef KTERM
  1747. X    register int x, y, flags;
  1748. X    XChar2b c;
  1749. X    Char gset;
  1750. #else /* !KTERM */
  1751. X    GC    currentGC;
  1752. X    register int x, y, flags;
  1753. X    char c;
  1754. #endif /* !KTERM */
  1755. X    Boolean    in_selection;
  1756. X
  1757. #ifdef STATUSLINE
  1758. X    Boolean instatus;
  1759. X
  1760. X    if(!(instatus = screen->cursor_row > screen->max_row) &&
  1761. X       screen->cursor_row - screen->topline > screen->max_row)
  1762. #else /* !STATUSLINE */
  1763. X    if(screen->cursor_row - screen->topline > screen->max_row)
  1764. #endif /* !STATUSLINE */
  1765. X        return;
  1766. #ifdef KTERM
  1767. X    gset = screen->buf[y = screen->cursor_row][x = screen->cursor_col].gset;
  1768. X    if (gset == MBC2) {
  1769. X        gset = screen->buf[y][x-1].gset;
  1770. X        x --;
  1771. X    }
  1772. X    if (gset & MBCS) {
  1773. X        c.byte1 = screen->buf[y][x].code;
  1774. X        c.byte2 = screen->buf[y][x+1].code;
  1775. X    } else {
  1776. X        c.byte1 = 0;
  1777. X        c.byte2 = screen->buf[y][x].code;
  1778. X        if (c.byte2 == 0) {
  1779. X            c.byte2 = ' ';
  1780. X            gset = GSET_ASCII;
  1781. X        }
  1782. X    }
  1783. X    flags = screen->buf[y][x].attr;
  1784. #else /* !KTERM */
  1785. X    c = screen->buf[y = 2 * screen->cursor_row][x = screen->cursor_col];
  1786. X    flags = screen->buf[y + 1][x];
  1787. #endif /* !KTERM */
  1788. X
  1789. X    if (screen->cursor_row > screen->endHRow ||
  1790. X        (screen->cursor_row == screen->endHRow &&
  1791. X         screen->cursor_col >= screen->endHCol) ||
  1792. X        screen->cursor_row < screen->startHRow ||
  1793. X        (screen->cursor_row == screen->startHRow &&
  1794. X         screen->cursor_col < screen->startHCol))
  1795. X        in_selection = False;
  1796. X    else
  1797. X        in_selection = True;
  1798. X
  1799. #ifdef STATUSLINE
  1800. X    if (screen->instatus && screen->reversestatus)
  1801. X        flags ^= INVERSE;
  1802. #endif /* STATUSLINE */
  1803. X
  1804. #ifdef KTERM
  1805. X    x = CursorX(screen, x);
  1806. #else /* !KTERM */
  1807. X    if (( (flags & INVERSE) && !in_selection) ||
  1808. X        (!(flags & INVERSE) &&  in_selection)) {
  1809. X        if(flags & BOLD) {
  1810. X            currentGC = screen->reverseboldGC;
  1811. X        } else {
  1812. X            currentGC = screen->reverseGC;
  1813. X        }
  1814. X    } else {
  1815. X        if(flags & BOLD) {
  1816. X            currentGC = screen->normalboldGC;
  1817. X        } else {
  1818. X            currentGC = screen->normalGC;
  1819. X        }
  1820. X    }
  1821. X
  1822. X    if (c == 0)
  1823. X        c = ' ';
  1824. X    x = CursorX (screen, screen->cursor_col);
  1825. #endif /* !KTERM */
  1826. #ifdef STATUSLINE
  1827. X    y = (instatus ? (screen->cursor_row * FontHeight(screen) + 1) :
  1828. X         ((screen->cursor_row - screen->topline) * FontHeight(screen))) +
  1829. #else /* !STATUSLINE */
  1830. X    y = (((screen->cursor_row - screen->topline) * FontHeight(screen))) +
  1831. #endif /* !STATUSLINE */
  1832. X     screen->border;
  1833. #ifdef KTERM
  1834. #ifdef  COLOR_TEXT /* mukawa */
  1835. X    ScreenDraw(screen, x, y, &c, 1, gset, flags,
  1836. #else    /* COLOR_TEXT */
  1837. X    ScreenDraw(screen, x, y, &c, 1, gset,
  1838. #endif  /* COLOR_TEXT */
  1839. X        flags & BOLD,
  1840. X        ((flags & INVERSE) != 0) ^ (in_selection != 0),
  1841. X        flags & UNDERLINE,
  1842. X        False);
  1843. #else /* !KTERM */
  1844. X    y = y+screen->fnt_norm->ascent;
  1845. X    XDrawImageString(screen->display, TextWindow(screen), currentGC,
  1846. X        x, y, &c, 1);
  1847. X    if((flags & BOLD) && screen->enbolden)
  1848. X        XDrawString(screen->display, TextWindow(screen), currentGC,
  1849. X            x + 1, y, &c, 1);
  1850. X    if(flags & UNDERLINE) 
  1851. X        XDrawLine(screen->display, TextWindow(screen), currentGC,
  1852. X            x, y+1, x + FontWidth(screen), y+1);
  1853. #endif /* !KTERM */
  1854. X    screen->cursor_state = OFF;
  1855. }
  1856. X
  1857. VTReset(full)
  1858. int full;
  1859. {
  1860. X    register TScreen *screen = &term->screen;
  1861. X
  1862. X    /* reset scrolling region */
  1863. X    screen->top_marg = 0;
  1864. X    screen->bot_marg = screen->max_row;
  1865. X    term->flags &= ~ORIGIN;
  1866. X    if(full) {
  1867. X        TabReset (term->tabs);
  1868. X        term->keyboard.flags = NULL;
  1869. #ifdef KTERM
  1870. X        screen->gsets[0] = GSET_ASCII;
  1871. # ifdef KTERM_KANJI
  1872. X                switch(term->misc.lang[0]) {
  1873. #  ifdef KTERM_HANZI
  1874. X                  case 'c': case 'C':
  1875. X                    screen->gsets[1] = GSET_HANZI;
  1876. X                    screen->gsets[2] = GSET_ASCII;
  1877. X                    break;
  1878. #  endif /* KTERM_HANZI */
  1879. #  ifdef KTERM_HANGUL
  1880. X                  case 'k': case 'K':
  1881. X                    screen->gsets[1] = GSET_HANGUL;
  1882. X                    screen->gsets[2] = GSET_ASCII;
  1883. X                    break;
  1884. #  endif /* KTERM_HANGUL */
  1885. X                  default:
  1886. X                    screen->gsets[1] = (term->flags & EUC_KANJI)
  1887. X                      ? GSET_KANJI : GSET_KANA;
  1888. X                    screen->gsets[2] = (term->flags & EUC_KANJI)
  1889. X                      ? GSET_KANA : GSET_ASCII;
  1890. X                    break;
  1891. X                }
  1892. # else /* !KTERM_KANJI */
  1893. SHAR_EOF
  1894. true || echo 'restore of kterm-4.1.2/charproc.c failed'
  1895. fi
  1896. echo 'End of kterm-4.1.2 part 8'
  1897. echo 'File kterm-4.1.2/charproc.c is continued in part 9'
  1898. echo 9 > _shar_seq_.tmp
  1899. exit 0
  1900.  
  1901.  
  1902. -----------------------------------------------------------------------------
  1903. mleisher@nmsu.edu                      "I laughed.
  1904. Mark Leisher                                I cried.
  1905. Computing Research Lab                          I fell down.
  1906. New Mexico State University                        It changed my life."
  1907. Las Cruces, NM                     - Rich [Cowboy Feng's Space Bar and Grille]
  1908.  
  1909. --
  1910. Dan Heller
  1911. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1912. Senior Writer                President          comp-sources.x@uunet.uu.net
  1913. argv@ora.com                 argv@zipcode.com
  1914.