home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume12
/
kterm
/
part08
< prev
next >
Wrap
Text File
|
1991-05-08
|
52KB
|
1,917 lines
Path: uunet!cs.utexas.edu!convex!central!newstop!male!jethro!exodus!NMSU.Edu!mleisher
From: mleisher@NMSU.Edu
Newsgroups: comp.sources.x
Subject: v12i089: kterm - kanji xterm, Part08/18
Message-ID: <12973@exodus.Eng.Sun.COM>
Date: 8 May 91 02:39:37 GMT
References: <csx-12i082:kterm@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 1905
Approved: argv@sun.com
Submitted-by: mleisher@NMSU.Edu
Posting-number: Volume 12, Issue 89
Archive-name: kterm/part08
#!/bin/sh
# this is kt412.08 (part 8 of kterm-4.1.2)
# do not concatenate these parts, unpack them in order with /bin/sh
# file kterm-4.1.2/charproc.c continued
#
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 8; then
echo Please unpack part "$Scheck" next!
exit 1
else
exit 0
fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
echo 'x - still skipping kterm-4.1.2/charproc.c'
else
echo 'x - continuing file kterm-4.1.2/charproc.c'
sed 's/^X//' << 'SHAR_EOF' >> 'kterm-4.1.2/charproc.c' &&
X break;
X
X case CASE_HIDE_STATUS:
X HideStatus();
X parsestate = groundtable;
X break;
X
X case CASE_ERASE_STATUS:
X EraseStatus();
X parsestate = groundtable;
X break;
#endif /* STATUSLINE */
X
X case CASE_XTERM_SAVE:
X savemodes(term);
X parsestate = groundtable;
X break;
X
X case CASE_XTERM_RESTORE:
X restoremodes(term);
X parsestate = groundtable;
X break;
#ifdef KTERM_KANJI
X }
#else /* !KTERM_KANJI */
X }
#endif /* !KTERM_KANJI */
X }
}
X
finput()
{
X return(doinput());
}
X
static int select_mask;
static int write_mask;
X
static char v_buffer[4096];
static char *v_bufstr;
static char *v_bufptr;
static char *v_bufend;
#define ptymask() (v_bufptr > v_bufstr ? pty_mask : 0)
X
v_write(f, d, l)
int f;
char *d;
int l;
{
X int r;
X int c = l;
X
X if (!v_bufstr) {
X v_bufstr = v_buffer;
X v_bufptr = v_buffer;
X v_bufend = &v_buffer[4096];
X }
X
X
X if ((1 << f) != pty_mask)
X return(write(f, d, l));
X
X if (v_bufptr > v_bufstr) {
X if (l) {
X if (v_bufend > v_bufptr + l) {
X bcopy(d, v_bufptr, l);
X v_bufptr += l;
X } else {
X if (v_bufstr != v_buffer) {
X bcopy(v_bufstr, v_buffer,
X v_bufptr - v_bufstr);
X v_bufptr -= v_bufstr - v_buffer;
X v_bufstr = v_buffer;
X }
X if (v_bufend > v_bufptr + l) {
X bcopy(d, v_bufptr, l);
X v_bufptr += l;
X } else if (v_bufptr < v_bufend) {
X fprintf(stderr, "Out of buffer space\n");
X c = v_bufend - v_bufptr;
X bcopy(d, v_bufptr, c);
X v_bufptr = v_bufend;
X } else {
X fprintf(stderr, "Out of buffer space\n");
X c = 0;
X }
X }
X }
X if (v_bufptr > v_bufstr) {
X if ((r = write(f, v_bufstr, v_bufptr - v_bufstr)) <= 0)
X return(r);
X if ((v_bufstr += r) >= v_bufptr)
X v_bufstr = v_bufptr = v_buffer;
X }
X } else if (l) {
X if ((r = write(f, d, l)) < 0) {
X if (errno == EWOULDBLOCK)
X r = 0;
X else if (errno == EINTR)
X r = 0;
X else
X return(r);
X }
X if (l - r) {
X if (l - r > v_bufend - v_buffer) {
X fprintf(stderr, "Truncating to %d\n",
X v_bufend - v_buffer);
X l = (v_bufend - v_buffer) + r;
X }
X bcopy(d + r, v_buffer, l - r);
X v_bufstr = v_buffer;
X v_bufptr = v_buffer + (l - r);
X }
X }
X return(c);
}
X
in_put()
{
X register TScreen *screen = &term->screen;
X register int i;
X static struct timeval trackTimeOut;
X
X select_mask = pty_mask; /* force initial read */
X for( ; ; ) {
#ifdef CRAY
X trackTimeOut.tv_sec = 0;
X trackTimeOut.tv_usec = 0;
X (void) select(max_plus1, &select_mask, (int *) NULL,
X (int *)NULL, &trackTimeOut);
#endif /* CRAY */
X
X if((select_mask & pty_mask) && (eventMode == NORMAL)) {
X if(screen->logging)
X FlushLog(screen);
X if((bcnt = read(screen->respond, bptr = buffer,
X BUF_SIZE)) < 0) {
X if(errno == EIO)
X Cleanup (0);
X else if(errno != EWOULDBLOCK)
X Panic(
X "input: read returned unexpected error (%d)\n",
X errno);
X } else if(bcnt == 0)
X Panic("input: read returned zero\n", 0);
X else {
#ifdef KTERM_KANJI
X if (pending_byte) {
X /*
X * restore pending_byte to the top of
X * the text which just read.
X */
X *--bptr = pending_byte;
X bcnt++;
X pending_byte = 0;
X }
#endif /* KTERM_KANJI */
X if(screen->scrollWidget && screen->scrollttyoutput &&
X screen->topline < 0)
X /* Scroll to bottom */
X WindowScroll(screen, 0);
X break;
X }
X }
X if(screen->scroll_amt)
X FlushScroll(screen);
X if(screen->cursor_set && (screen->cursor_col != screen->cur_col
X || screen->cursor_row != screen->cur_row)) {
X if(screen->cursor_state)
X HideCursor();
X ShowCursor();
X } else if(screen->cursor_set != screen->cursor_state) {
X if(screen->cursor_set)
X ShowCursor();
X else
X HideCursor();
X }
X
X if (waitingForTrackInfo) {
X trackTimeOut.tv_sec = TRACKTIMESEC;
X trackTimeOut.tv_usec = TRACKTIMEUSEC;
X select_mask = pty_mask;
X if ((i = select(max_plus1, &select_mask, (int *)NULL, (int *)NULL,
X &trackTimeOut)) < 0) {
X if (errno != EINTR)
X SysError(ERROR_SELECT);
X continue;
X } else if (i == 0) {
X /* emacs just isn't replying, go on */
X waitingForTrackInfo = 0;
X Bell();
X select_mask = Select_mask;
X }
X } else if (QLength(screen->display))
X select_mask = X_mask;
X else {
X write_mask = ptymask();
X XFlush(screen->display);
X select_mask = Select_mask;
X if (eventMode != NORMAL)
X select_mask = X_mask;
X if(select(max_plus1, &select_mask, &write_mask,
X (int *)NULL, (struct timeval *) NULL) < 0){
X if (errno != EINTR)
X SysError(ERROR_SELECT);
X continue;
X }
X }
X if (write_mask & ptymask())
X v_write(screen->respond, 0, 0); /* flush buffer */
X if(select_mask & X_mask) {
X if (bcnt <= 0) {
X bcnt = 0;
X bptr = buffer;
X }
X xevents();
X if (bcnt > 0)
X break;
X }
X }
X bcnt--;
X return(*bptr++);
}
X
/*
X * process a string of characters according to the character set indicated
X * by charset. worry about end of line conditions (wraparound if selected).
X */
dotext(screen, flags, charset, buf, ptr)
register TScreen *screen;
unsigned flags;
#ifdef KTERM
Char charset;
Char *buf;
Char *ptr;
#else /* !KTERM */
char charset;
char *buf;
char *ptr;
#endif /* !KTERM */
{
#ifdef KTERM
X int do_wrap = 0;
X register Char *s;
#else /* !KTERM */
X register char *s;
#endif /* !KTERM */
X register int len;
X register int n;
X register int next_col;
X
#ifdef KTERM
X switch (charset) {
X case GSET_UK: /* United Kingdom set */
X for (s=buf; s<ptr; ++s)
X *s &= ~NEEDMAP;
X if (*s == '#') /* UK pound sign */
X *s |= NEEDMAP;
X break;
X
X case GSET_KANA: /* JIS Kana set */
X for (s=buf; s<ptr; ++s) {
X *s |= NEEDMAP;
X }
X break;
X
X case GSET_GRAPH: /* special graphics (line drawing) */
X case GSET_ASCII: /* ASCII set */
X case GSET_JISROMAN: /* JIS Roman set */
X case GSET_LATIN1R: /* Right part of ISO8859-1 */
X case GSET_LATIN2R: /* Right part of ISO8859-2 */
X case GSET_LATIN3R: /* Right part of ISO8859-3 */
X case GSET_LATIN4R: /* Right part of ISO8859-4 */
X case GSET_LATIN7R: /* Right part of ISO8859-7 */
X case GSET_LATIN6R: /* Right part of ISO8859-6 */
X case GSET_LATIN8R: /* Right part of ISO8859-8 */
X case GSET_LATIN5R: /* Right part of ISO8859-5 */
X case GSET_LATIN9R: /* Right part of ISO8859-9 */
X case GSET_KANJI: /* JISX0208 Kanji set */
X case GSET_OLDKANJI: /* JISX0208 Kanji set */
#ifdef KTERM_HANZI
X case GSET_HANZI: /* GB2312 Hanzi set */
#endif /* KTERM_HANZI */
#ifdef KTERM_HANGUL
X case GSET_HANGUL: /* KSC5601 Hangul set */
#endif /* KTERM_HANGUL */
X
X if (FontType(screen, FNUM(charset), 0) == LOW) {
X for (s=buf; s<ptr; ++s) {
X *s &= ~NEEDMAP;
X }
X }
X break;
X
X default: /* any character sets we don't recognize*/
X return;
X }
#else /* !KTERM */
X switch (charset) {
X case 'A': /* United Kingdom set */
X for (s=buf; s<ptr; ++s)
X if (*s == '#')
X *s = '\036'; /* UK pound sign*/
X break;
X
X case 'B': /* ASCII set */
X break;
X
X case '0': /* special graphics (line drawing) */
X for (s=buf; s<ptr; ++s)
X if (*s>=0x5f && *s<=0x7e)
X *s = *s == 0x5f ? 0x7f : *s - 0x5f;
X break;
X
X default: /* any character sets we don't recognize*/
X return;
X }
#endif /* !KTERM */
X
X len = ptr - buf;
X ptr = buf;
X while (len > 0) {
X n = screen->max_col-screen->cur_col+1;
X if (n <= 1) {
#ifdef STATUSLINE
X if (screen->do_wrap && (flags&WRAPAROUND) &&
X !screen->instatus) {
#else /* !STATUSLINE */
X if (screen->do_wrap && (flags&WRAPAROUND)) {
#endif /* !STATUSLINE */
X Index(screen, 1);
X screen->cur_col = 0;
X screen->do_wrap = 0;
X n = screen->max_col+1;
X } else
X n = 1;
X }
X if (len < n)
X n = len;
#ifdef KTERM_KANJI
X if (charset & MBCS) {
X if (n == 1) {
X if (flags & WRAPAROUND) {
X n--; do_wrap = 1;
X } else
X n++;
X } else
X if (n & 1)
X n--;
X }
#endif /* KTERM_KANJI */
X next_col = screen->cur_col + n;
#ifdef KTERM
X WriteText(screen, ptr, n, flags, charset);
#else /* !KTERM */
X WriteText(screen, ptr, n, flags);
#endif /* !KTERM */
X /*
X * the call to WriteText updates screen->cur_col.
X * If screen->cur_col != next_col, we must have
X * hit the right margin, so set the do_wrap flag.
X */
X screen->do_wrap = (screen->cur_col < next_col);
#ifdef KTERM_KANJI
X screen->do_wrap |= do_wrap;
#endif /* KTERM_KANJI */
X len -= n;
X ptr += n;
X }
}
X
/*
X * write a string str of length len onto the screen at
X * the current cursor position. update cursor position.
X */
#ifdef KTERM
WriteText(screen, str, len, flags, gset)
#else /* !KTERM */
WriteText(screen, str, len, flags)
#endif /* !KTERM */
register TScreen *screen;
register char *str;
register int len;
unsigned flags;
#ifdef KTERM
register Char gset;
#endif /* KTERM */
{
X register int cx, cy;
X register unsigned fgs = flags;
#ifdef KTERM
X register int i, n;
X XChar2b drawbuf[256], *dbuf;
X
X dbuf = (len > 256) ? (XChar2b *)XtMalloc(len * sizeof(XChar2b))
X : drawbuf;
#else /* !KTERM */
X GC currentGC;
#endif /* !KTERM */
X
#ifdef STATUSLINE
X if(screen->instatus && screen->reversestatus)
X fgs ^= INVERSE;
X if(screen->cur_row - screen->topline <= screen->max_row ||
X screen->instatus) {
#else /* !STATUSLINE */
X if(screen->cur_row - screen->topline <= screen->max_row) {
#endif /* !STATUSLINE */
X /*
X if(screen->cur_row == screen->cursor_row && screen->cur_col <=
X screen->cursor_col && screen->cursor_col <= screen->cur_col + len - 1)
X screen->cursor_state = OFF;
X */
X if(screen->cursor_state)
X HideCursor();
X
#ifndef KTERM
X /*
X * make sure that the correct GC is current
X */
X
X if (fgs & BOLD)
X if (fgs & INVERSE)
X currentGC = screen->reverseboldGC;
X else currentGC = screen->normalboldGC;
X else /* not bold */
X if (fgs & INVERSE)
X currentGC = screen->reverseGC;
X else currentGC = screen->normalGC;
#endif /* !KTERM */
X
X if (fgs & INSERT)
X InsertChar(screen, len);
X if (!(AddToRefresh(screen))) {
X if(screen->scroll_amt)
X FlushScroll(screen);
#ifdef KTERM
#ifdef KTERM_KANJI
X if (gset & MBCS) {
X for (i = n = 0; i < len; n++) {
X dbuf[n].byte1 = str[i++];
X dbuf[n].byte2 = str[i++];
X }
X } else
#endif /* KTERM_KANJI */
X for (n = 0; n < len; n++) {
X dbuf[n].byte1 = 0;
X dbuf[n].byte2 = MapOnFont(gset, str[n]);
X }
#endif /* KTERM */
X cx = CursorX(screen, screen->cur_col);
#ifdef KTERM
X cy = CursorY(screen, screen->cur_row);
#ifdef STATUSLINE
X if (screen->instatus)
X cy ++;
#endif /* STATUSLINE */
X BreakMBchar(screen);
X screen->cur_col += len;
X BreakMBchar(screen);
X screen->cur_col -= len;
#ifdef COLOR_TEXT /* mukawa */
X ScreenDraw(screen, cx, cy, dbuf, n, gset, fgs,
#else /* COLOR_TEXT */
X ScreenDraw(screen, cx, cy, dbuf, n, gset,
#endif /* COLOR_TEXT */
X fgs & BOLD, fgs & INVERSE, fgs & UNDERLINE, False);
#else /* !KTERM */
X cy = CursorY(screen, screen->cur_row)+screen->fnt_norm->ascent;
X XDrawImageString(screen->display, TextWindow(screen), currentGC,
X cx, cy, str, len);
X
X if((fgs & BOLD) && screen->enbolden)
X if (currentGC == screen->normalGC || screen->reverseGC)
X XDrawString(screen->display, TextWindow(screen),
X currentGC,cx + 1, cy, str, len);
X
X if(fgs & UNDERLINE)
X XDrawLine(screen->display, TextWindow(screen), currentGC,
X cx, cy+1,
X cx + len * FontWidth(screen), cy+1);
#endif /* !KTERM */
X /*
X * the following statements compile data to compute the average
X * number of characters written on each call to XText. The data
X * may be examined via the use of a "hidden" escape sequence.
X */
X ctotal += len;
X ++ntotal;
X }
X }
#ifdef KTERM
X ScreenWrite(screen, str, flags, gset, len);
#else /* !KTERM */
X ScreenWrite(screen, str, flags, len);
#endif /* !KTERM */
X CursorForward(screen, len);
}
X
/*
X * process ANSI modes set, reset
X */
modes(term, func)
XXtermWidget term;
int (*func)();
{
X register int i;
X
X for (i=0; i<nparam; ++i) {
X switch (param[i]) {
X case 4: /* IRM */
X (*func)(&term->flags, INSERT);
X break;
X
X case 20: /* LNM */
X (*func)(&term->flags, LINEFEED);
X update_autolinefeed();
X break;
X }
X }
}
X
/*
X * process DEC private modes set, reset
X */
dpmodes(term, func)
XXtermWidget term;
int (*func)();
{
X register TScreen *screen = &term->screen;
X register int i, j;
X extern int bitset();
X
X for (i=0; i<nparam; ++i) {
X switch (param[i]) {
X case 1: /* DECCKM */
X (*func)(&term->keyboard.flags, CURSOR_APL);
X break;
X case 2: /* ANSI/VT52 mode */
X if (func == bitset) {
X screen->gsets[0] =
X screen->gsets[1] =
X screen->gsets[2] =
X screen->gsets[3] = 'B';
X screen->curgl = 0;
X screen->curgr = 2;
X }
X break;
X case 3: /* DECCOLM */
X if(screen->c132) {
X ClearScreen(screen);
X CursorSet(screen, 0, 0, term->flags);
X if((j = func == bitset ? 132 : 80) !=
X ((term->flags & IN132COLUMNS) ? 132 : 80) ||
X j != screen->max_col + 1) {
X Dimension replyWidth, replyHeight;
X XtGeometryResult status;
X
X status = XtMakeResizeRequest (
X (Widget) term,
X (Dimension) FontWidth(screen) * j
X + 2*screen->border
X + screen->scrollbar,
X (Dimension) FontHeight(screen)
X * (screen->max_row + 1)
X + 2 * screen->border,
X &replyWidth, &replyHeight);
X
X if (status == XtGeometryYes ||
X status == XtGeometryDone) {
X ScreenResize (&term->screen,
X replyWidth,
X replyHeight,
X &term->flags);
X }
X }
X (*func)(&term->flags, IN132COLUMNS);
X }
X break;
X case 4: /* DECSCLM (slow scroll) */
X if (func == bitset) {
X screen->jumpscroll = 0;
X if (screen->scroll_amt)
X FlushScroll(screen);
X } else
X screen->jumpscroll = 1;
X (*func)(&term->flags, SMOOTHSCROLL);
X update_jumpscroll();
X break;
X case 5: /* DECSCNM */
X j = term->flags;
X (*func)(&term->flags, REVERSE_VIDEO);
X if ((term->flags ^ j) & REVERSE_VIDEO)
X ReverseVideo(term);
X /* update_reversevideo done in RevVid */
X break;
X
X case 6: /* DECOM */
X (*func)(&term->flags, ORIGIN);
X CursorSet(screen, 0, 0, term->flags);
X break;
X
X case 7: /* DECAWM */
X (*func)(&term->flags, WRAPAROUND);
X update_autowrap();
X break;
X case 8: /* DECARM */
X /* ignore autorepeat */
X break;
X case 9: /* MIT bogus sequence */
X if(func == bitset)
X screen->send_mouse_pos = 1;
X else
X screen->send_mouse_pos = 0;
X break;
X case 38: /* DECTEK */
X if(func == bitset & !(screen->inhibit & I_TEK)) {
X if(screen->logging) {
X FlushLog(screen);
X screen->logstart = Tbuffer;
X }
X screen->TekEmu = TRUE;
X }
X break;
X case 40: /* 132 column mode */
X screen->c132 = (func == bitset);
X update_allow132();
X break;
X case 41: /* curses hack */
X screen->curses = (func == bitset);
X update_cursesemul();
X break;
X case 44: /* margin bell */
X screen->marginbell = (func == bitset);
X if(!screen->marginbell)
X screen->bellarmed = -1;
X update_marginbell();
X break;
X case 45: /* reverse wraparound */
X (*func)(&term->flags, REVERSEWRAP);
X update_reversewrap();
X break;
X case 46: /* logging */
#ifdef ALLOWLOGFILEONOFF
X /*
X * if this feature is enabled, logging may be
X * enabled and disabled via escape sequences.
X */
X if(func == bitset)
X StartLog(screen);
X else
X CloseLog(screen);
#else
X Bell();
X Bell();
#endif /* ALLOWLOGFILEONOFF */
X break;
X case 47: /* alternate buffer */
X if(func == bitset)
X ToAlternate(screen);
X else
X FromAlternate(screen);
X break;
#ifdef STATUSLINE
X case 48: /* reverse statusline */
X j = screen->reversestatus;
X (*func)(&screen->reversestatus, 1);
X if (j != screen->reversestatus)
X ScrnRefresh(screen, screen->max_row + 1, 0, 1,
X screen->max_col + 1);
X break;
#endif /* STATUSLINE */
X case 1000: /* xtem bogus sequence */
X if(func == bitset)
X screen->send_mouse_pos = 2;
X else
X screen->send_mouse_pos = 0;
X break;
X case 1001: /* xtem sequence w/hilite tracking */
X if(func == bitset)
X screen->send_mouse_pos = 3;
X else
X screen->send_mouse_pos = 0;
X break;
X }
X }
}
X
/*
X * process xterm private modes save
X */
savemodes(term)
XXtermWidget term;
{
X register TScreen *screen = &term->screen;
X register int i;
X
X for (i = 0; i < nparam; i++) {
X switch (param[i]) {
X case 1: /* DECCKM */
X screen->save_modes[0] = term->keyboard.flags &
X CURSOR_APL;
X break;
X case 3: /* DECCOLM */
X if(screen->c132)
X screen->save_modes[1] = term->flags &
X IN132COLUMNS;
X break;
X case 4: /* DECSCLM (slow scroll) */
X screen->save_modes[2] = term->flags & SMOOTHSCROLL;
X break;
X case 5: /* DECSCNM */
X screen->save_modes[3] = term->flags & REVERSE_VIDEO;
X break;
X case 6: /* DECOM */
X screen->save_modes[4] = term->flags & ORIGIN;
X break;
X
X case 7: /* DECAWM */
X screen->save_modes[5] = term->flags & WRAPAROUND;
X break;
X case 8: /* DECARM */
X /* ignore autorepeat */
X break;
X case 9: /* mouse bogus sequence */
X screen->save_modes[7] = screen->send_mouse_pos;
X break;
X case 40: /* 132 column mode */
X screen->save_modes[8] = screen->c132;
X break;
X case 41: /* curses hack */
X screen->save_modes[9] = screen->curses;
X break;
X case 44: /* margin bell */
X screen->save_modes[12] = screen->marginbell;
X break;
X case 45: /* reverse wraparound */
X screen->save_modes[13] = term->flags & REVERSEWRAP;
X break;
X case 46: /* logging */
X screen->save_modes[14] = screen->logging;
X break;
X case 47: /* alternate buffer */
X screen->save_modes[15] = screen->alternate;
X break;
#ifdef STATUSLINE
X case 48: /* reverse statusline */
X screen->save_modes[16] = screen->reversestatus;
X break;
#endif /* STATUSLINE */
X case 1000: /* mouse bogus sequence */
X case 1001:
X screen->save_modes[7] = screen->send_mouse_pos;
X break;
X }
X }
}
X
/*
X * process xterm private modes restore
X */
restoremodes(term)
XXtermWidget term;
{
X register TScreen *screen = &term->screen;
X register int i, j;
X
X for (i = 0; i < nparam; i++) {
X switch (param[i]) {
X case 1: /* DECCKM */
X term->keyboard.flags &= ~CURSOR_APL;
X term->keyboard.flags |= screen->save_modes[0] &
X CURSOR_APL;
X update_appcursor();
X break;
X case 3: /* DECCOLM */
X if(screen->c132) {
X ClearScreen(screen);
X CursorSet(screen, 0, 0, term->flags);
X if((j = (screen->save_modes[1] & IN132COLUMNS)
X ? 132 : 80) != ((term->flags & IN132COLUMNS)
X ? 132 : 80) || j != screen->max_col + 1) {
X Dimension replyWidth, replyHeight;
X XtGeometryResult status;
X status = XtMakeResizeRequest (
X (Widget) term,
X (Dimension) FontWidth(screen) * j
X + 2*screen->border
X + screen->scrollbar,
X (Dimension) FontHeight(screen)
X * (screen->max_row + 1)
X + 2*screen->border,
X &replyWidth, &replyHeight);
X
X if (status == XtGeometryYes ||
X status == XtGeometryDone) {
X ScreenResize (&term->screen,
X replyWidth,
X replyHeight,
X &term->flags);
X }
X }
X term->flags &= ~IN132COLUMNS;
X term->flags |= screen->save_modes[1] &
X IN132COLUMNS;
X }
X break;
X case 4: /* DECSCLM (slow scroll) */
X if (screen->save_modes[2] & SMOOTHSCROLL) {
X screen->jumpscroll = 0;
X if (screen->scroll_amt)
X FlushScroll(screen);
X } else
X screen->jumpscroll = 1;
X term->flags &= ~SMOOTHSCROLL;
X term->flags |= screen->save_modes[2] & SMOOTHSCROLL;
X update_jumpscroll();
X break;
X case 5: /* DECSCNM */
X if((screen->save_modes[3] ^ term->flags) &
X REVERSE_VIDEO) {
X term->flags &= ~REVERSE_VIDEO;
X term->flags |= screen->save_modes[3] &
X REVERSE_VIDEO;
X ReverseVideo(term);
X /* update_reversevideo done in RevVid */
X }
X break;
X case 6: /* DECOM */
X term->flags &= ~ORIGIN;
X term->flags |= screen->save_modes[4] & ORIGIN;
X CursorSet(screen, 0, 0, term->flags);
X break;
X
X case 7: /* DECAWM */
X term->flags &= ~WRAPAROUND;
X term->flags |= screen->save_modes[5] & WRAPAROUND;
X update_autowrap();
X break;
X case 8: /* DECARM */
X /* ignore autorepeat */
X break;
X case 9: /* MIT bogus sequence */
X screen->send_mouse_pos = screen->save_modes[7];
X break;
X case 40: /* 132 column mode */
X screen->c132 = screen->save_modes[8];
X update_allow132();
X break;
X case 41: /* curses hack */
X screen->curses = screen->save_modes[9];
X update_cursesemul();
X break;
X case 44: /* margin bell */
X if(!(screen->marginbell = screen->save_modes[12]))
X screen->bellarmed = -1;
X update_visualbell();
X break;
X case 45: /* reverse wraparound */
X term->flags &= ~REVERSEWRAP;
X term->flags |= screen->save_modes[13] & REVERSEWRAP;
X update_reversewrap();
X break;
X case 46: /* logging */
#ifdef ALLOWLOGFILEONOFF
X if(screen->save_modes[14])
X StartLog(screen);
X else
X CloseLog(screen);
#endif /* ALLOWLOGFILEONOFF */
X /* update_logging done by StartLog and CloseLog */
X break;
X case 47: /* alternate buffer */
X if(screen->save_modes[15])
X ToAlternate(screen);
X else
X FromAlternate(screen);
X /* update_altscreen done by ToAlt and FromAlt */
X break;
#ifdef STATUSLINE
X case 48: /* reverse statusline */
X if (screen->save_modes[16] != screen->reversestatus) {
X screen->reversestatus = screen->save_modes[16];
X ScrnRefresh(screen, screen->max_row + 1, 0, 1,
X screen->max_col + 1);
X }
X break;
#endif /* STATUSLINE */
X case 1000: /* mouse bogus sequence */
X case 1001:
X screen->send_mouse_pos = screen->save_modes[7];
X break;
X }
X }
}
X
/*
X * set a bit in a word given a pointer to the word and a mask.
X */
bitset(p, mask)
int *p;
{
X *p |= mask;
}
X
/*
X * clear a bit in a word given a pointer to the word and a mask.
X */
bitclr(p, mask)
int *p;
{
X *p &= ~mask;
}
X
unparseseq(ap, fd)
register ANSI *ap;
{
X register int c;
X register int i;
X register int inters;
X
X c = ap->a_type;
X if (c>=0x80 && c<=0x9F) {
X unparseputc(ESC, fd);
X c -= 0x40;
X }
X unparseputc(c, fd);
X c = ap->a_type;
X if (c==ESC || c==DCS || c==CSI || c==OSC || c==PM || c==APC) {
X if (ap->a_pintro != 0)
X unparseputc((char) ap->a_pintro, fd);
X for (i=0; i<ap->a_nparam; ++i) {
X if (i != 0)
X unparseputc(';', fd);
X unparseputn((unsigned int) ap->a_param[i], fd);
X }
X inters = ap->a_inters;
X for (i=3; i>=0; --i) {
X c = (inters >> (8*i)) & 0xff;
X if (c != 0)
X unparseputc(c, fd);
X }
X unparseputc((char) ap->a_final, fd);
X }
}
X
unparseputn(n, fd)
unsigned int n;
int fd;
{
X unsigned int q;
X
X q = n/10;
X if (q != 0)
X unparseputn(q, fd);
X unparseputc((char) ('0' + (n%10)), fd);
}
X
unparseputc(c, fd)
char c;
int fd;
{
X char buf[2];
X register i = 1;
X extern XtermWidget term;
X
X if((buf[0] = c) == '\r' && (term->flags & LINEFEED)) {
X buf[1] = '\n';
X i++;
X }
X if (write(fd, buf, i) != i)
X Panic("unparseputc: error writing character\n", 0);
}
X
unparsefputs (s, fd)
X register char *s;
X int fd;
{
X if (s) {
X while (*s) unparseputc (*s++, fd);
X }
}
X
X
ToAlternate(screen)
register TScreen *screen;
{
X extern ScrnBuf Allocate();
X
X if(screen->alternate)
X return;
X if(!screen->altbuf)
X screen->altbuf = Allocate(screen->max_row + 1, screen->max_col
X + 1, &screen->abuf_address);
X SwitchBufs(screen);
X screen->alternate = TRUE;
X update_altscreen();
}
X
XFromAlternate(screen)
register TScreen *screen;
{
X if(!screen->alternate)
X return;
X screen->alternate = FALSE;
X SwitchBufs(screen);
X update_altscreen();
}
X
SwitchBufs(screen)
register TScreen *screen;
{
X register int rows, top;
#ifdef KTERM
X Bchr *save [MAX_ROWS];
#else /* !KTERM */
X char *save [2 * MAX_ROWS];
#endif /* !KTERM */
X
X if(screen->cursor_state)
X HideCursor();
X rows = screen->max_row + 1;
#ifdef KTERM
X bcopy((char *)screen->buf, (char *)save, sizeof(Bchr *) * rows);
X bcopy((char *)screen->altbuf, (char *)screen->buf, sizeof(Bchr *) *
X rows);
X bcopy((char *)save, (char *)screen->altbuf, sizeof(Bchr *) * rows);
#else /* !KTERM */
X bcopy((char *)screen->buf, (char *)save, 2 * sizeof(char *) * rows);
X bcopy((char *)screen->altbuf, (char *)screen->buf, 2 * sizeof(char *) *
X rows);
X bcopy((char *)save, (char *)screen->altbuf, 2 * sizeof(char *) * rows);
#endif /* !KTERM */
X
X if((top = -screen->topline) <= screen->max_row) {
X if(screen->scroll_amt)
X FlushScroll(screen);
#ifdef STATUSLINE
X if(top == 0 && !screen->statusline)
#else /* !STATUSLINE */
X if(top == 0)
#endif /* !STATUSLINE */
X XClearWindow(screen->display, TextWindow(screen));
X else
X XClearArea(
X screen->display,
X TextWindow(screen),
X (int) screen->border + screen->scrollbar,
X (int) top * FontHeight(screen) + screen->border,
X (unsigned) Width(screen),
X (unsigned) (screen->max_row - top + 1)
X * FontHeight(screen),
X FALSE);
X }
#ifndef ENBUG /* kagotani */
X TrackText(0, 0, 0, 0);
#endif
X ScrnRefresh(screen, 0, 0, rows, screen->max_col + 1, False);
}
X
VTRun()
{
X register TScreen *screen = &term->screen;
X register int i;
X
X if (!screen->Vshow) {
X XtRealizeWidget (term->core.parent);
X set_vt_visibility (TRUE);
X }
X update_vttekmode();
X update_vtshow();
X update_tekshow();
X set_vthide_sensitivity();
X
X if (screen->allbuf == NULL) VTallocbuf ();
X
X screen->cursor_state = OFF;
X screen->cursor_set = ON;
X
X bcnt = 0;
X bptr = buffer;
X while(Tpushb > Tpushback) {
X *bptr++ = *--Tpushb;
X bcnt++;
X }
X bcnt += (i = Tbcnt);
X for( ; i > 0 ; i--)
X *bptr++ = *Tbptr++;
X bptr = buffer;
X if(!setjmp(VTend))
X VTparse();
X HideCursor();
X screen->cursor_set = OFF;
}
X
/*ARGSUSED*/
static void VTExpose(w, event, region)
Widget w;
XXEvent *event;
Region region;
{
X register TScreen *screen = &term->screen;
X
#ifdef DEBUG
X if(debug)
X fputs("Expose\n", stderr);
#endif /* DEBUG */
X if (event->type == Expose)
X HandleExposure (screen, (XExposeEvent *)event);
}
X
static void VTGraphicsOrNoExpose (event)
XXEvent *event;
X {
X register TScreen *screen = &term->screen;
X if (screen->incopy <= 0) {
X screen->incopy = 1;
X if (screen->scrolls > 0)
X screen->scrolls--;
X }
X if (event->type == GraphicsExpose)
X if (HandleExposure (screen, (XExposeEvent *)event))
X screen->cursor_state = OFF;
X if ((event->type == NoExpose) || ((XGraphicsExposeEvent *)event)->count == 0) {
X if (screen->incopy <= 0 && screen->scrolls > 0)
X screen->scrolls--;
X if (screen->scrolls)
X screen->incopy = -1;
X else
X screen->incopy = 0;
X }
}
X
/*ARGSUSED*/
static void VTNonMaskableEvent (w, closure, event)
Widget w;
caddr_t closure;
XXEvent *event;
X {
X switch (event->type) {
X case MappingNotify:
X XRefreshKeyboardMapping (&event->xmapping);
X break;
X case GraphicsExpose:
X case NoExpose:
X VTGraphicsOrNoExpose (event);
X break;
X }
X }
X
X
X
X
static void VTResize(w)
X Widget w;
{
X if (XtIsRealized(w))
X ScreenResize (&term->screen, term->core.width, term->core.height,
X &term->flags);
}
X
X
int VTInit ()
{
X register TScreen *screen = &term->screen;
X
X XtRealizeWidget (term->core.parent);
X if (screen->allbuf == NULL) VTallocbuf ();
X return (1);
}
X
static void VTallocbuf ()
{
X register TScreen *screen = &term->screen;
X int nrows = screen->max_row + 1;
X extern ScrnBuf Allocate();
X
X /* allocate screen buffer now, if necessary. */
X if (screen->scrollWidget)
X nrows += screen->savelines;
X screen->allbuf = Allocate (nrows, screen->max_col + 1,
X &screen->sbuf_address);
X if (screen->scrollWidget)
#ifdef KTERM
X screen->buf = &screen->allbuf[screen->savelines];
#else /* !KTERM */
X screen->buf = &screen->allbuf[2 * screen->savelines];
#endif /* !KTERM */
X else
X screen->buf = screen->allbuf;
X return;
}
X
static void VTInitialize (request, new)
X XtermWidget request, new;
{
X int i;
#ifdef KTERM
X int fnum;
#endif /* KTERM */
X /* Zero out the entire "screen" component of "new" widget,
X then do field-by-field assigment of "screen" fields
X that are named in the resource list. */
X
X bzero ((char *) &new->screen, sizeof(new->screen));
X new->screen.c132 = request->screen.c132;
X new->screen.curses = request->screen.curses;
X new->screen.foreground = request->screen.foreground;
X new->screen.cursorcolor = request->screen.cursorcolor;
#ifdef COLOR_TEXT /* mukawa */
X new->screen.textcolor[0] = request->screen.textcolor[0];
X new->screen.textcolor[1] = request->screen.textcolor[1];
X new->screen.textcolor[2] = request->screen.textcolor[2];
X new->screen.textcolor[3] = request->screen.textcolor[3];
X new->screen.textcolor[4] = request->screen.textcolor[4];
X new->screen.textcolor[5] = request->screen.textcolor[5];
X new->screen.textcolor[6] = request->screen.textcolor[6];
X new->screen.textcolor[7] = request->screen.textcolor[7];
#endif /* COLOR_TEXT */
X new->screen.border = request->screen.border;
X new->screen.jumpscroll = request->screen.jumpscroll;
X new->screen.logfile = request->screen.logfile;
X new->screen.marginbell = request->screen.marginbell;
X new->screen.mousecolor = request->screen.mousecolor;
X new->screen.mousecolorback = request->screen.mousecolorback;
X new->screen.multiscroll = request->screen.multiscroll;
X new->screen.nmarginbell = request->screen.nmarginbell;
X new->screen.savelines = request->screen.savelines;
X new->screen.scrolllines = request->screen.scrolllines;
X new->screen.scrollttyoutput = request->screen.scrollttyoutput;
X new->screen.scrollkey = request->screen.scrollkey;
X new->screen.visualbell = request->screen.visualbell;
X new->screen.TekEmu = request->screen.TekEmu;
X new->misc.re_verse = request->misc.re_verse;
X new->screen.multiClickTime = request->screen.multiClickTime;
X new->screen.charClass = request->screen.charClass;
X new->screen.cutNewline = request->screen.cutNewline;
X new->screen.cutToBeginningOfLine = request->screen.cutToBeginningOfLine;
X new->screen.always_highlight = request->screen.always_highlight;
X new->screen.pointer_cursor = request->screen.pointer_cursor;
X new->screen.eight_bits = request->screen.eight_bits;
X new->screen.allowSendEvents = request->screen.allowSendEvents;
X new->misc.titeInhibit = request->misc.titeInhibit;
#ifdef KTERM
X for (fnum = F_ISO8859_1; fnum < FCNT; fnum++) {
#endif /* KTERM */
X for (i = 0; i < NMENUFONTS; i++) {
X new->screen.menu_font_names[i] = request->screen.menu_font_names[i];
X }
X /* set default in realize proc */
X new->screen.menu_font_names[fontMenu_fontdefault] = NULL;
X new->screen.menu_font_names[fontMenu_fontescape] = NULL;
X new->screen.menu_font_names[fontMenu_fontsel] = NULL;
#ifdef KTERM
X new->screen.menu_bfont_names[fontMenu_fontdefault] = NULL;
X new->screen.menu_bfont_names[fontMenu_fontescape] = NULL;
X new->screen.menu_bfont_names[fontMenu_fontsel] = NULL;
X }
X for (i = 0; i < NMENUFONTS; i++) {
X new->screen.menu_font_list[i] = request->screen.menu_font_list[i];
X new->screen.menu_bfont_list[i] = request->screen.menu_bfont_list[i];
X }
X /* set default in realize proc */
X new->screen.menu_font_list[fontMenu_fontdefault] = NULL;
X new->screen.menu_font_list[fontMenu_fontescape] = NULL;
X new->screen.menu_font_list[fontMenu_fontsel] = NULL;
X new->screen.menu_bfont_list[fontMenu_fontdefault] = NULL;
X new->screen.menu_bfont_list[fontMenu_fontescape] = NULL;
X new->screen.menu_bfont_list[fontMenu_fontsel] = NULL;
#endif /* KTERM */
X new->screen.menu_font_number = fontMenu_fontdefault;
#ifdef STATUSLINE
X new->screen.statusline = request->screen.statusline;
X new->screen.reversestatus = request->screen.reversestatus;
#endif /* STATUSLINE */
#ifdef KTERM
X new->screen.linespace = request->screen.linespace;
#endif /* KTERM */
X
X /*
X * The definition of -rv now is that it changes the definition of
X * XtDefaultForeground and XtDefaultBackground. So, we no longer
X * need to do anything special.
X */
X new->keyboard.flags = 0;
X new->screen.display = new->core.screen->display;
X new->core.height = new->core.width = 1;
X /* dummy values so that we don't try to Realize the parent shell
X with height or width of 0, which is illegal in X. The real
X size is computed in the xtermWidget's Realize proc,
X but the shell's Realize proc is called first, and must see
X a valid size. */
X
X /* look for focus related events on the shell, because we need
X * to care about the shell's border being part of our focus.
X */
X XtAddEventHandler(XtParent(new), EnterWindowMask, FALSE,
X HandleEnterWindow, (Opaque)NULL);
X XtAddEventHandler(XtParent(new), LeaveWindowMask, FALSE,
X HandleLeaveWindow, (Opaque)NULL);
X XtAddEventHandler(XtParent(new), FocusChangeMask, FALSE,
X HandleFocusChange, (Opaque)NULL);
X XtAddEventHandler(new, 0L, TRUE,
X VTNonMaskableEvent, (Opaque)NULL);
X
X set_character_class (new->screen.charClass);
X
X /* create it, but don't realize it */
X ScrollBarOn (new, TRUE, FALSE);
X return;
}
X
X
static void VTDestroy (w)
Widget w;
{
X XtFree(((XtermWidget)w)->screen.selection);
}
X
/*ARGSUSED*/
static void VTRealize (w, valuemask, values)
Widget w;
XXtValueMask *valuemask;
XXSetWindowAttributes *values;
{
X unsigned int width, height;
X register TScreen *screen = &term->screen;
X int xpos, ypos, pr;
X extern char *malloc();
X XSizeHints sizehints;
X extern int VTgcFontMask;
X int scrollbar_width;
#ifdef KTERM
X int fnum = F_ISO8859_1;
#endif /* KTERM */
X
X TabReset (term->tabs);
X
#ifdef KTERM
X screen->menu_font_list[fontMenu_fontdefault] = term->misc.fontlist;
X screen->menu_bfont_list[fontMenu_fontdefault] = term->misc.bfontlist;
X for (fnum = F_ISO8859_1; fnum < FCNT; fnum ++) {
X screen->menu_font_names[fontMenu_fontdefault] = term->misc.f_n;
X screen->menu_bfont_names[fontMenu_fontdefault] = term->misc.f_b;
X screen->fnt_norm = screen->fnt_bold = NULL;
X }
X fnum = F_ISO8859_1;
X if (!LoadNewFont(screen, NULL, NULL, False, 0)) {
X if (term->misc.f_n == NULL
X || XmuCompareISOLatin1(term->misc.f_n, "fixed") != 0) {
#else /* !KTERM */
X screen->menu_font_names[fontMenu_fontdefault] = term->misc.f_n;
X screen->fnt_norm = screen->fnt_bold = NULL;
X if (!LoadNewFont(screen, term->misc.f_n, term->misc.f_b, False, 0)) {
X if (XmuCompareISOLatin1(term->misc.f_n, "fixed") != 0) {
#endif /* !KTERM */
X fprintf (stderr,
X "%s: unable to open font \"%s\", trying \"fixed\"....\n",
X xterm_name, term->misc.f_n);
#ifdef KTERM
X screen->menu_font_names[fontMenu_fontdefault] = "fixed";
X (void) LoadNewFont (screen, NULL, NULL, False, 0);
#else /* !KTERM */
X (void) LoadNewFont (screen, "fixed", NULL, False, 0);
X screen->menu_font_names[fontMenu_fontdefault] = "fixed";
#endif /* !KTERM */
X }
X }
X
X /* really screwed if we couldn't open default font */
X if (!screen->fnt_norm) {
X fprintf (stderr, "%s: unable to locate a suitable font\n",
X xterm_name);
X Exit (1);
X }
X
X /* making cursor */
X if (!screen->pointer_cursor)
X screen->pointer_cursor = make_colored_cursor(XC_xterm,
X screen->mousecolor,
X screen->mousecolorback);
X else
X recolor_cursor (screen->pointer_cursor,
X screen->mousecolor, screen->mousecolorback);
X
X scrollbar_width = (term->misc.scrollbar ?
X screen->scrollWidget->core.width : 0);
X
X
X /* set defaults */
X xpos = 1; ypos = 1; width = 80; height = 24;
X pr = XParseGeometry (term->misc.geo_metry, &xpos, &ypos,
X &width, &height);
X screen->max_col = (width - 1); /* units in character cells */
X screen->max_row = (height - 1); /* units in character cells */
X update_font_info (&term->screen, False);
X
X width = screen->fullVwin.fullwidth;
X height = screen->fullVwin.fullheight;
X
X if ((pr & XValue) && (XNegative&pr))
X xpos += DisplayWidth(screen->display, DefaultScreen(screen->display))
X - width - (term->core.parent->core.border_width * 2);
X if ((pr & YValue) && (YNegative&pr))
X ypos += DisplayHeight(screen->display,DefaultScreen(screen->display))
X - height - (term->core.parent->core.border_width * 2);
X
X /* set up size hints for window manager; min 1 char by 1 char */
X sizehints.base_width = 2 * screen->border + scrollbar_width;
X sizehints.base_height = 2 * screen->border;
X sizehints.width_inc = FontWidth(screen);
X sizehints.height_inc = FontHeight(screen);
X sizehints.min_width = sizehints.base_width + sizehints.width_inc;
X sizehints.min_height = sizehints.base_height + sizehints.height_inc;
X sizehints.flags = (PBaseSize|PMinSize|PResizeInc);
X sizehints.x = xpos;
X sizehints.y = ypos;
X if ((XValue&pr) || (YValue&pr)) {
X sizehints.flags |= USSize|USPosition;
X sizehints.flags |= PWinGravity;
X switch (pr & (XNegative | YNegative)) {
X case 0:
X sizehints.win_gravity = NorthWestGravity;
X break;
X case XNegative:
X sizehints.win_gravity = NorthEastGravity;
X break;
X case YNegative:
X sizehints.win_gravity = SouthWestGravity;
X break;
X default:
X sizehints.win_gravity = SouthEastGravity;
X break;
X }
X } else {
X /* set a default size, but do *not* set position */
X sizehints.flags |= PSize;
X }
X sizehints.width = width;
X sizehints.height = height;
X if ((WidthValue&pr) || (HeightValue&pr))
X sizehints.flags |= USSize;
X else sizehints.flags |= PSize;
#ifdef STATUSLINE
X sizehints.base_height += screen->statusheight;
X sizehints.min_height += screen->statusheight;
#endif /* STATUSLINE */
X
X (void) XtMakeResizeRequest((Widget) term,
X (Dimension)width, (Dimension)height,
X &term->core.width, &term->core.height);
X
X /* XXX This is bogus. We are parsing geometries too late. This
X * is information that the shell widget ought to have before we get
X * realized, so that it can do the right thing.
X */
X if (sizehints.flags & USPosition)
X XMoveWindow (XtDisplay(term), term->core.parent->core.window,
X sizehints.x, sizehints.y);
X
X XSetWMNormalHints (XtDisplay(term), term->core.parent->core.window,
X &sizehints);
X
#ifdef STATUSLINE
X values->bit_gravity = ForgetGravity;
#else /* !STATUSLINE */
X values->bit_gravity = NorthWestGravity;
#endif /* !STATUSLINE */
X term->screen.fullVwin.window = term->core.window =
X XCreateWindow(XtDisplay(term), XtWindow(term->core.parent),
X term->core.x, term->core.y,
X term->core.width, term->core.height, term->core.border_width,
X (int) term->core.depth,
X InputOutput, CopyFromParent,
X *valuemask|CWBitGravity, values);
X
#ifdef KTERM
X set_cursor_gcs (screen, F_ISO8859_1);
#else /* !KTERM */
X set_cursor_gcs (screen);
#endif /* !KTERM */
X
X /* Reset variables used by ANSI emulation. */
X
#ifdef KTERM
X screen->gsets[0] = GSET_ASCII;
# ifdef KTERM_KANJI
X switch(term->misc.lang[0]) {
# ifdef KTERM_HANZI
X case 'c': case 'C':
X screen->gsets[1] = GSET_HANZI;
X screen->gsets[2] = GSET_ASCII;
X break;
# endif /* KTERM_HANZI */
# ifdef KTERM_HANGUL
X case 'k': case 'K':
X screen->gsets[1] = GSET_HANGUL;
X screen->gsets[2] = GSET_ASCII;
X break;
# endif /* KTERM_HANGUL */
X default:
X screen->gsets[1] = (term->flags & EUC_KANJI) ? GSET_KANJI : GSET_KANA;
X screen->gsets[2] = (term->flags & EUC_KANJI) ? GSET_KANA : GSET_ASCII;
X break;
X }
# else /* !KTERM_KANJI */
X screen->gsets[1] = GSET_KANA;
X screen->gsets[2] = GSET_ASCII;
# endif /* !KTERM_KANJI */
X screen->gsets[3] = GSET_ASCII;
#else /* !KTERM */
X screen->gsets[0] = 'B'; /* ASCII_G */
X screen->gsets[1] = 'B';
X screen->gsets[2] = 'B'; /* DEC supplemental. */
X screen->gsets[3] = 'B';
#endif /* !KTERM */
X screen->curgl = 0; /* G0 => GL. */
#ifdef KTERM
X screen->curgr = 1; /* G1 => GR. */
#else /* !KTERM */
X screen->curgr = 2; /* G2 => GR. */
#endif /* !KTERM */
X screen->curss = 0; /* No single shift. */
X
X XDefineCursor(screen->display, VShellWindow, screen->pointer_cursor);
X
X screen->cur_col = screen->cur_row = 0;
#ifdef KTERM
X screen->max_col = Width(screen)/FontWidth(screen) - 1;
X screen->top_marg = 0;
X screen->bot_marg = screen->max_row = Height(screen) /
X FontHeight(screen) - 1;
#else /* !KTERM */
X screen->max_col = Width(screen)/screen->fullVwin.f_width - 1;
X screen->top_marg = 0;
X screen->bot_marg = screen->max_row = Height(screen) /
X screen->fullVwin.f_height - 1;
#endif /* !KTERM */
X
X screen->sc.row = screen->sc.col = screen->sc.flags = NULL;
X
X /* Mark screen buffer as unallocated. We wait until the run loop so
X that the child process does not fork and exec with all the dynamic
X memory it will never use. If we were to do it here, the
X swap space for new process would be huge for huge savelines. */
X if (!tekWidget) /* if not called after fork */
X screen->buf = screen->allbuf = NULL;
X
X screen->do_wrap = NULL;
X screen->scrolls = screen->incopy = 0;
X set_vt_box (screen);
#ifdef STATUSLINE
X status_box[0].x = screen->border - 1;
#endif /* STATUSLINE */
X
X screen->savedlines = 0;
X
X if (term->misc.scrollbar) {
X screen->scrollbar = 0;
X ScrollBarOn (term, FALSE, TRUE);
X }
X CursorSave (term, &screen->sc);
X return;
}
X
/*
X * Shows cursor at new cursor position in screen.
X */
ShowCursor()
{
X register TScreen *screen = &term->screen;
X register int x, y, flags;
#ifdef KTERM
X XChar2b c;
X Char gset;
#else /* !KTERM */
X Char c;
X GC currentGC;
#endif /* !KTERM */
X Boolean in_selection;
X
X if (eventMode != NORMAL) return;
X
#ifdef STATUSLINE
X if (!screen->instatus &&
X screen->cur_row - screen->topline > screen->max_row)
#else /* !STATUSLINE */
X if (screen->cur_row - screen->topline > screen->max_row)
#endif /* !STATUSLINE */
X return;
#ifdef KTERM
X gset = screen->buf[y = screen->cursor_row = screen->cur_row]
X [x = screen->cursor_col = screen->cur_col].gset;
X if (gset == MBC2) {
X gset = screen->buf[y][x-1].gset;
X x --;
X }
X if (gset & MBCS) {
X c.byte1 = screen->buf[y][x].code;
X c.byte2 = screen->buf[y][x+1].code;
X } else {
X c.byte1 = 0;
X c.byte2 = screen->buf[y][x].code;
X if (c.byte2 == 0) {
X c.byte2 = ' ';
X gset = GSET_ASCII;
X }
X }
X flags = screen->buf[y][x].attr;
#else /* !KTERM */
X c = screen->buf[y = 2 * (screen->cursor_row = screen->cur_row)]
X [x = screen->cursor_col = screen->cur_col];
X flags = screen->buf[y + 1][x];
X if (c == 0)
X c = ' ';
#endif /* !KTERM */
X
X if (screen->cur_row > screen->endHRow ||
X (screen->cur_row == screen->endHRow &&
X screen->cur_col >= screen->endHCol) ||
X screen->cur_row < screen->startHRow ||
X (screen->cur_row == screen->startHRow &&
X screen->cur_col < screen->startHCol))
X in_selection = False;
X else
X in_selection = True;
X
#ifdef STATUSLINE
X if (screen->instatus && screen->reversestatus)
X flags ^= INVERSE;
#endif /* STATUSLINE */
X
#ifdef KTERM
X x = CursorX(screen, x);
X y = CursorY(screen, y);
#ifdef COLOR_TEXT /* mukawa */
X ScreenDraw(screen, x, y, &c, 1, gset, flags,
#else /* COLOR_TEXT */
X ScreenDraw(screen, x, y, &c, 1, gset,
#endif /* COLOR_TEXT */
X flags & BOLD,
X (screen->select || screen->always_highlight)
X ^ ((flags & INVERSE) != 0) ^ (in_selection != 0),
X flags & UNDERLINE,
X True);
#else /* !KTERM */
X if(screen->select || screen->always_highlight) {
X if (( (flags & INVERSE) && !in_selection) ||
X (!(flags & INVERSE) && in_selection)){
X /* text is reverse video */
X if (screen->cursorGC) {
X currentGC = screen->cursorGC;
X } else {
X if (flags & BOLD) {
X currentGC = screen->normalboldGC;
X } else {
X currentGC = screen->normalGC;
X }
X }
X } else { /* normal video */
X if (screen->reversecursorGC) {
X currentGC = screen->reversecursorGC;
X } else {
X if (flags & BOLD) {
X currentGC = screen->reverseboldGC;
X } else {
X currentGC = screen->reverseGC;
X }
X }
X }
X } else { /* not selected */
X if (( (flags & INVERSE) && !in_selection) ||
X (!(flags & INVERSE) && in_selection)) {
X /* text is reverse video */
X currentGC = screen->reverseGC;
X } else { /* normal video */
X currentGC = screen->normalGC;
X }
X
X }
X
X x = CursorX (screen, screen->cur_col);
X y = CursorY(screen, screen->cur_row) +
X screen->fnt_norm->ascent;
X XDrawImageString(screen->display, TextWindow(screen), currentGC,
X x, y, (char *) &c, 1);
X
X if((flags & BOLD) && screen->enbolden) /* no bold font */
X XDrawString(screen->display, TextWindow(screen), currentGC,
X x + 1, y, (char *) &c, 1);
X if(flags & UNDERLINE)
X XDrawLine(screen->display, TextWindow(screen), currentGC,
X x, y+1, x + FontWidth(screen), y+1);
X if (!screen->select && !screen->always_highlight) {
X screen->box->x = x;
X screen->box->y = y - screen->fnt_norm->ascent;
X XDrawLines (screen->display, TextWindow(screen),
X screen->cursoroutlineGC ? screen->cursoroutlineGC
X : currentGC,
X screen->box, NBOX, CoordModePrevious);
X }
#endif /* !KTERM */
X screen->cursor_state = ON;
}
X
/*
X * hide cursor at previous cursor position in screen.
X */
HideCursor()
{
X register TScreen *screen = &term->screen;
#ifdef KTERM
X register int x, y, flags;
X XChar2b c;
X Char gset;
#else /* !KTERM */
X GC currentGC;
X register int x, y, flags;
X char c;
#endif /* !KTERM */
X Boolean in_selection;
X
#ifdef STATUSLINE
X Boolean instatus;
X
X if(!(instatus = screen->cursor_row > screen->max_row) &&
X screen->cursor_row - screen->topline > screen->max_row)
#else /* !STATUSLINE */
X if(screen->cursor_row - screen->topline > screen->max_row)
#endif /* !STATUSLINE */
X return;
#ifdef KTERM
X gset = screen->buf[y = screen->cursor_row][x = screen->cursor_col].gset;
X if (gset == MBC2) {
X gset = screen->buf[y][x-1].gset;
X x --;
X }
X if (gset & MBCS) {
X c.byte1 = screen->buf[y][x].code;
X c.byte2 = screen->buf[y][x+1].code;
X } else {
X c.byte1 = 0;
X c.byte2 = screen->buf[y][x].code;
X if (c.byte2 == 0) {
X c.byte2 = ' ';
X gset = GSET_ASCII;
X }
X }
X flags = screen->buf[y][x].attr;
#else /* !KTERM */
X c = screen->buf[y = 2 * screen->cursor_row][x = screen->cursor_col];
X flags = screen->buf[y + 1][x];
#endif /* !KTERM */
X
X if (screen->cursor_row > screen->endHRow ||
X (screen->cursor_row == screen->endHRow &&
X screen->cursor_col >= screen->endHCol) ||
X screen->cursor_row < screen->startHRow ||
X (screen->cursor_row == screen->startHRow &&
X screen->cursor_col < screen->startHCol))
X in_selection = False;
X else
X in_selection = True;
X
#ifdef STATUSLINE
X if (screen->instatus && screen->reversestatus)
X flags ^= INVERSE;
#endif /* STATUSLINE */
X
#ifdef KTERM
X x = CursorX(screen, x);
#else /* !KTERM */
X if (( (flags & INVERSE) && !in_selection) ||
X (!(flags & INVERSE) && in_selection)) {
X if(flags & BOLD) {
X currentGC = screen->reverseboldGC;
X } else {
X currentGC = screen->reverseGC;
X }
X } else {
X if(flags & BOLD) {
X currentGC = screen->normalboldGC;
X } else {
X currentGC = screen->normalGC;
X }
X }
X
X if (c == 0)
X c = ' ';
X x = CursorX (screen, screen->cursor_col);
#endif /* !KTERM */
#ifdef STATUSLINE
X y = (instatus ? (screen->cursor_row * FontHeight(screen) + 1) :
X ((screen->cursor_row - screen->topline) * FontHeight(screen))) +
#else /* !STATUSLINE */
X y = (((screen->cursor_row - screen->topline) * FontHeight(screen))) +
#endif /* !STATUSLINE */
X screen->border;
#ifdef KTERM
#ifdef COLOR_TEXT /* mukawa */
X ScreenDraw(screen, x, y, &c, 1, gset, flags,
#else /* COLOR_TEXT */
X ScreenDraw(screen, x, y, &c, 1, gset,
#endif /* COLOR_TEXT */
X flags & BOLD,
X ((flags & INVERSE) != 0) ^ (in_selection != 0),
X flags & UNDERLINE,
X False);
#else /* !KTERM */
X y = y+screen->fnt_norm->ascent;
X XDrawImageString(screen->display, TextWindow(screen), currentGC,
X x, y, &c, 1);
X if((flags & BOLD) && screen->enbolden)
X XDrawString(screen->display, TextWindow(screen), currentGC,
X x + 1, y, &c, 1);
X if(flags & UNDERLINE)
X XDrawLine(screen->display, TextWindow(screen), currentGC,
X x, y+1, x + FontWidth(screen), y+1);
#endif /* !KTERM */
X screen->cursor_state = OFF;
}
X
VTReset(full)
int full;
{
X register TScreen *screen = &term->screen;
X
X /* reset scrolling region */
X screen->top_marg = 0;
X screen->bot_marg = screen->max_row;
X term->flags &= ~ORIGIN;
X if(full) {
X TabReset (term->tabs);
X term->keyboard.flags = NULL;
#ifdef KTERM
X screen->gsets[0] = GSET_ASCII;
# ifdef KTERM_KANJI
X switch(term->misc.lang[0]) {
# ifdef KTERM_HANZI
X case 'c': case 'C':
X screen->gsets[1] = GSET_HANZI;
X screen->gsets[2] = GSET_ASCII;
X break;
# endif /* KTERM_HANZI */
# ifdef KTERM_HANGUL
X case 'k': case 'K':
X screen->gsets[1] = GSET_HANGUL;
X screen->gsets[2] = GSET_ASCII;
X break;
# endif /* KTERM_HANGUL */
X default:
X screen->gsets[1] = (term->flags & EUC_KANJI)
X ? GSET_KANJI : GSET_KANA;
X screen->gsets[2] = (term->flags & EUC_KANJI)
X ? GSET_KANA : GSET_ASCII;
X break;
X }
# else /* !KTERM_KANJI */
SHAR_EOF
true || echo 'restore of kterm-4.1.2/charproc.c failed'
fi
echo 'End of kterm-4.1.2 part 8'
echo 'File kterm-4.1.2/charproc.c is continued in part 9'
echo 9 > _shar_seq_.tmp
exit 0
-----------------------------------------------------------------------------
mleisher@nmsu.edu "I laughed.
Mark Leisher I cried.
Computing Research Lab I fell down.
New Mexico State University It changed my life."
Las Cruces, NM - Rich [Cowboy Feng's Space Bar and Grille]
--
Dan Heller
O'Reilly && Associates Z-Code Software Comp-sources-x:
Senior Writer President comp-sources.x@uunet.uu.net
argv@ora.com argv@zipcode.com