v12i090: kterm - kanji xterm, Part09/18

mleisher at NMSU.Edu mleisher at NMSU.Edu
Wed May 8 12:40:18 AEST 1991


Submitted-by: mleisher at NMSU.Edu
Posting-number: Volume 12, Issue 90
Archive-name: kterm/part09

#!/bin/sh
# this is kt412.09 (part 9 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" != 9; 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		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';
X		screen->gsets[1] = 'B';
X		screen->gsets[2] = 'B';
X		screen->gsets[3] = 'B';
#endif /* !KTERM */
X		screen->curgl = 0;
#ifdef KTERM
X		screen->curgr = 1;
#else /* !KTERM */
X		screen->curgr = 2;
#endif /* !KTERM */
X		screen->curss = 0;
X		ClearScreen(screen);
#ifdef STATUSLINE
X		EraseStatus();
#endif /* STATUSLINE */
X		screen->cursor_state = OFF;
X		if (term->flags & REVERSE_VIDEO)
X			ReverseVideo(term);
X
X		term->flags = term->initflags;
X		if(screen->c132 && (term->flags & IN132COLUMNS)) {
X		        Dimension junk;
X			XtMakeResizeRequest(
X			    (Widget) term,
X			    (Dimension) 80*FontWidth(screen)
X				+ 2 * screen->border + screen->scrollbar,
#ifdef STATUSLINE
X			    (Dimension) screen->statusheight +
#endif /* STATUSLINE */
X			    (Dimension) FontHeight(screen)
X			        * (screen->max_row + 1) + 2 * screen->border,
X			    &junk, &junk);
X			XSync(screen->display, FALSE);	/* synchronize */
X			if(QLength(screen->display) > 0)
X				xevents();
X		}
X		CursorSet(screen, 0, 0, term->flags);
X	}
X	longjmp(vtjmpbuf, 1);	/* force ground state in parser */
}
X
X
#ifdef STATUSLINE
ToStatus(col)
int col;
{
X	register TScreen *screen = &term->screen;
X
X	if (screen->cursor_state)
X		HideCursor();
X	if (col > screen->max_col)
X		col = screen->max_col;
X	if (!screen->instatus) {
X		if (!screen->statusline)
X			ShowStatus();
X		CursorSave(term, &screen->statussc);
X		screen->instatus = TRUE;
X		screen->cur_row = screen->max_row + 1;
X	}
X	screen->cur_col = col;
}
X
XFromStatus()
{
X	register TScreen *screen = &term->screen;
X
X	if (!screen->instatus)
X		return;
X	screen->instatus = FALSE;
X	CursorRestore(term, &screen->statussc);
}
X
ShowStatus()
{
X	register TScreen *screen = &term->screen;
X	register int border = 2 * screen->border;
X
X	if (screen->statusline)
X		return;
X	screen->statusline = 1;
X	screen->statusheight = FontHeight(screen) + 2;
X	ResizeScreen(term, border + screen->scrollbar, border);
}
X
HideStatus()
{
X	register TScreen *screen = &term->screen;
X	register int border = 2 * screen->border;
#ifndef KTERM
X	register int i, j;
#endif /* !KTERM */
X
X	if (!screen->statusline)
X		return;
X	if (screen->instatus)
X		FromStatus();
X	screen->statusline = 0;
X	screen->statusheight = 0;
#ifdef KTERM
X	bzero(screen->buf[screen->max_row + 1],
X		sizeof(Bchr) * (screen->max_col+1));
#else /* !KTERM */
X	bzero(screen->buf[i = 2 * (screen->max_row + 1)],
X		j = screen->max_col + 1);
X	bzero(screen->buf[i + 1], j);
#endif /* !KTERM */
X	ResizeScreen(term, border + screen->scrollbar, border);
}
X
EraseStatus()
{
X	register TScreen *screen = &term->screen;
X	register int j, pix;
#ifdef KTERM
X	int fnum = F_ISO8859_1; /* referd by normalGC and reverseGC */
#else /* !KTERM */
X	register int i;
#endif /* !KTERM */
X
X	if (!screen->statusline)
X		return;
#ifdef KTERM
X	bzero(screen->buf[screen->max_row + 1],
X		j = sizeof(Bchr) * (screen->max_col+1));
#else /* !KTERM */
X	bzero(screen->buf[i = 2 * (screen->max_row + 1)],
X		j = screen->max_col + 1);
X	bzero(screen->buf[i + 1], j) ;
#endif /* !KTERM */
X	XFillRectangle(screen->display, TextWindow(screen),
X		screen->reversestatus ? screen->normalGC : screen->reverseGC,
X		screen->border - 1 + screen->scrollbar,
X		(screen->max_row + 1) * FontHeight(screen) +
X		screen->border,
X		j * FontWidth(screen) + 2, screen->statusheight);
X	if (!screen->reversestatus)
X		StatusBox(screen);
}
X
StatusBox(screen)
register TScreen *screen;
{
#ifdef KTERM
X	int fnum = F_ISO8859_1; /* referd by normalGC */
#endif /* KTERM */
X
X	status_box[0].x = screen->scrollbar;
X	status_box[0].y = (screen->max_row + 1) * FontHeight(screen) +
X		screen->border;
X	status_box[3].x = -(status_box[1].x = (screen->max_col + 1) *
X		FontWidth(screen) + screen->border + 1);
X	status_box[4].y = -(status_box[2].y = FontHeight(screen) + 1);
X	XDrawLines(screen->display, TextWindow(screen), screen->normalGC,
X		status_box, NBOX, CoordModePrevious);
}
#endif /* STATUSLINE */
X
X
/*
X * set_character_class - takes a string of the form
X * 
X *                 low[-high]:val[,low[-high]:val[...]]
X * 
X * and sets the indicated ranges to the indicated values.
X */
X
int set_character_class (s)
X    register char *s;
{
X    register int i;			/* iterator, index into s */
X    int len;				/* length of s */
X    int acc;				/* accumulator */
X    int low, high;			/* bounds of range [0..127] */
X    int base;				/* 8, 10, 16 (octal, decimal, hex) */
X    int numbers;			/* count of numbers per range */
X    int digits;				/* count of digits in a number */
X    static char *errfmt = "%s:  %s in range string \"%s\" (position %d)\n";
X    extern char *ProgramName;
X
X    if (!s || !s[0]) return -1;
X
X    base = 10;				/* in case we ever add octal, hex */
X    low = high = -1;			/* out of range */
X
X    for (i = 0, len = strlen (s), acc = 0, numbers = digits = 0;
X	 i < len; i++) {
X	char c = s[i];
X
X	if (isspace(c)) {
X	    continue;
X	} else if (isdigit(c)) {
X	    acc = acc * base + (c - '0');
X	    digits++;
X	    continue;
X	} else if (c == '-') {
X	    low = acc;
X	    acc = 0;
X	    if (digits == 0) {
X		fprintf (stderr, errfmt, ProgramName, "missing number", s, i);
X		return (-1);
X	    }
X	    digits = 0;
X	    numbers++;
X	    continue;
X	} else if (c == ':') {
X	    if (numbers == 0)
X	      low = acc;
X	    else if (numbers == 1)
X	      high = acc;
X	    else {
X		fprintf (stderr, errfmt, ProgramName, "too many numbers",
X			 s, i);
X		return (-1);
X	    }
X	    digits = 0;
X	    numbers++;
X	    acc = 0;
X	    continue;
X	} else if (c == ',') {
X	    /*
X	     * now, process it
X	     */
X
X	    if (high < 0) {
X		high = low;
X		numbers++;
X	    }
X	    if (numbers != 2) {
X		fprintf (stderr, errfmt, ProgramName, "bad value number", 
X			 s, i);
X	    } else if (SetCharacterClassRange (low, high, acc) != 0) {
X		fprintf (stderr, errfmt, ProgramName, "bad range", s, i);
X	    }
X
X	    low = high = -1;
X	    acc = 0;
X	    digits = 0;
X	    numbers = 0;
X	    continue;
X	} else {
X	    fprintf (stderr, errfmt, ProgramName, "bad character", s, i);
X	    return (-1);
X	}				/* end if else if ... else */
X
X    }
X
X    if (low < 0 && high < 0) return (0);
X
X    /*
X     * now, process it
X     */
X
X    if (high < 0) high = low;
X    if (numbers < 1 || numbers > 2) {
X	fprintf (stderr, errfmt, ProgramName, "bad value number", s, i);
X    } else if (SetCharacterClassRange (low, high, acc) != 0) {
X	fprintf (stderr, errfmt, ProgramName, "bad range", s, i);
X    }
X
X    return (0);
}
X
/* ARGSUSED */
static void HandleKeymapChange(w, event, params, param_count)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *param_count;
{
X    static XtTranslations keymap, original;
X    static XtResource resources[] = {
X	{ XtNtranslations, XtCTranslations, XtRTranslationTable,
X	      sizeof(XtTranslations), 0, XtRTranslationTable, (caddr_t)NULL}
X    };
X    char mapName[1000];
X    char mapClass[1000];
X
X    if (*param_count != 1) return;
X
X    if (original == NULL) original = w->core.tm.translations;
X
X    if (strcmp(params[0], "None") == 0) {
X	XtOverrideTranslations(w, original);
X	return;
X    }
X    (void) sprintf( mapName, "%sKeymap", params[0] );
X    (void) strcpy( mapClass, mapName );
X    if (islower(mapClass[0])) mapClass[0] = toupper(mapClass[0]);
X    XtGetSubresources( w, &keymap, mapName, mapClass,
X		       resources, (Cardinal)1, NULL, (Cardinal)0 );
X    if (keymap != NULL)
X	XtOverrideTranslations(w, keymap);
}
X
X
/* ARGSUSED */
static void HandleBell(w, event, params, param_count)
X    Widget w;
X    XEvent *event;		/* unused */
X    String *params;		/* [0] = volume */
X    Cardinal *param_count;	/* 0 or 1 */
{
X    int percent = (*param_count) ? atoi(params[0]) : 0;
X
X    XBell( XtDisplay(w), percent );
}
X
X
/* ARGSUSED */
static void HandleIgnore(w, event, params, param_count)
X    Widget w;
X    XEvent *event;		/* unused */
X    String *params;		/* unused */
X    Cardinal *param_count;	/* unused */
{
X    /* do nothing, but check for funny escape sequences */
X    (void) SendMousePosition(w, event);
}
X
X
/* ARGSUSED */
void DoSetSelectedFont(w, client_data, selection, type, value, length, format)
X    Widget w;
X    XtPointer client_data;
X    Atom *selection, *type;
X    XtPointer value;
X    unsigned long *length;
X    int *format;
{
X    char *val = (char *)value;
X    int len;
X    if (*type != XA_STRING || *format != 8) { Bell(); return; }
X    len = strlen(value);
X    if (len > 0) {
X	if (val[len-1] == '\n') val[len-1] = '\0';
X	if (!LoadNewFont (&term->screen, val, NULL, True, 
X			  fontMenu_fontescape))
X	  Bell();
X    }
}
X
void FindFontSelection (atom_name, justprobe)
X    char *atom_name;
X    Bool justprobe;
{
X    static AtomPtr *atoms;
X    static int atomCount = 0;
X    AtomPtr *pAtom;
X    int a;
X    Atom target;
#ifdef KTERM
X    int fnum = F_ISO8859_1;
#endif /* KTERM */
X
X    if (!atom_name) atom_name = "PRIMARY";
X
X    for (pAtom = atoms, a = atomCount; a; a--, pAtom++) {
X	if (strcmp(atom_name, XmuNameOfAtom(*pAtom)) == 0) break;
X    }
X    if (!a) {
X	atoms = (AtomPtr*) XtRealloc (atoms, sizeof(AtomPtr)*(atomCount+1));
X	*(pAtom = &atoms[atomCount++]) = XmuMakeAtom(atom_name);
X    }
X
X    target = XmuInternAtom(XtDisplay(term), *pAtom);
X    if (justprobe) {
X	term->screen.menu_font_names[fontMenu_fontsel] = 
X	  XGetSelectionOwner(XtDisplay(term), target) ? _Font_Selected_ : NULL;
X    } else {
X	XtGetSelectionValue(term, target, XA_STRING,
X			    DoSetSelectedFont, NULL,
X			    XtLastTimestampProcessed(XtDisplay(term)));
X    }
X    return;
}
X
X
/* ARGSUSED */
void HandleSetFont(w, event, params, param_count)
X    Widget w;
X    XEvent *event;		/* unused */
X    String *params;		/* unused */
X    Cardinal *param_count;	/* unused */
{
X    int fontnum;
X    char *name1 = NULL, *name2 = NULL;
X
X    if (*param_count == 0) {
X	fontnum = fontMenu_fontdefault;
X    } else {
X	int maxparams = 1;		/* total number of params allowed */
X
X	switch (params[0][0]) {
X	  case 'd': case 'D': case '0':
X	    fontnum = fontMenu_fontdefault; break;
X	  case '1':
X	    fontnum = fontMenu_font1; break;
X	  case '2':
X	    fontnum = fontMenu_font2; break;
X	  case '3':
X	    fontnum = fontMenu_font3; break;
X	  case '4':
X	    fontnum = fontMenu_font4; break;
X	  case 'e': case 'E':
X	    fontnum = fontMenu_fontescape; maxparams = 3; break;
X	  case 's': case 'S':
X	    fontnum = fontMenu_fontsel; maxparams = 2; break;
X	  default:
X	    Bell();
X	    return;
X	}
X	if (*param_count > maxparams) {	 /* see if extra args given */
X	    Bell();
X	    return;
X	}
X	switch (*param_count) {		/* assign 'em */
X	  case 3:
X	    name2 = params[2];
X	    /* fall through */
X	  case 2:
X	    name1 = params[1];
X	    break;
X	}
X    }
X
X    SetVTFont (fontnum, True, name1, name2);
}
X
X
void SetVTFont (i, doresize, name1, name2)
X    int i;
X    Bool doresize;
X    char *name1, *name2;
{
X    TScreen *screen = &term->screen;
X
X    if (i < 0 || i >= NMENUFONTS) {
X	Bell();
X	return;
X    }
X    if (i == fontMenu_fontsel) {	/* go get the selection */
X	FindFontSelection (name1, False);  /* name1 = atom, name2 is ignored */
X	return;
X    }
#ifndef KTERM
X    if (!name1) name1 = screen->menu_font_names[i];
#endif /* !KTERM */
X    if (!LoadNewFont(screen, name1, name2, doresize, i)) {
X	Bell();
X    }
X    return;
}
X
X
#ifdef KTERM
static char *search_font_matching(screen, fontpattern, fonttail)
TScreen *screen;
char *fontpattern;
char *fonttail;
{
X	static char **fontnamelist;
X	char *tmptail;
X	int count, i;
X	int fonttaillen;
X
X	if (!fontpattern) return NULL;
X
X	fonttaillen = strlen(fonttail);
X	if (fontnamelist) {
X		XFreeFontNames(fontnamelist);
X	}
X	fontnamelist = XListFonts(screen->display, fontpattern, 1000, &count);
X	for (i = 0; i < count; i ++) {
X		tmptail = fontnamelist[i]+strlen(fontnamelist[i])-fonttaillen;
X		if (XmuCompareISOLatin1(fonttail, tmptail) == 0) {
X			return fontnamelist[i];
X		}
X	}
X	return NULL;
}
#endif /* KTERM */
X
#ifdef KTERM
int LoadNewFont (screen, nfontpat, bfontpat, doresize, fontnum)
X    TScreen *screen;
X    char *nfontpat, *bfontpat;
#else /* !KTERM */
int LoadNewFont (screen, nfontname, bfontname, doresize, fontnum)
X    TScreen *screen;
X    char *nfontname, *bfontname;
#endif /* !KTERM */
X    Bool doresize;
X    int fontnum;
{
X    XFontStruct *nfs = NULL, *bfs = NULL;
X    XGCValues xgcv;
X    unsigned long mask;
X    GC new_normalGC = NULL, new_normalboldGC = NULL;
X    GC new_reverseGC = NULL, new_reverseboldGC = NULL;
X    char *tmpname = NULL;
#ifdef KTERM
X    char *tmpbname = NULL;
X    XFontStruct *asciinfs = NULL;
X    int fnum;
X    char *nfontname, *bfontname;
X    static char *fonttail[FCNT] = {
X	"-iso8859-1",
X	"-jisx0201.1976-0",
#ifdef KTERM_KANJI
X	"-jisx0208.1983-0",
#endif /* KTERM_KANJI */
#ifdef KTERM_HANZI
X        "-gb2312.1980-0",
#endif /* KTERM_HANZI */
#ifdef KTERM_HANGUL
X        "-ksc5601.1987-0",
#endif /* KTERM_HANGUL */
X    };
#endif /* KTERM */
X
#ifdef KTERM
X  for (fnum = F_ISO8859_1; fnum < FCNT; fnum ++) {
X
X    nfontname = search_font_matching(screen, nfontpat, fonttail[fnum]);
X
X    if (!nfontname) {
X        switch(term->misc.lang[0]) {
#ifdef KTERM_HANZI
X          case 'c': case 'C':
X            if ((F_ISO8859_1 < fnum && fnum < F_GB2312_0) ||
X                fnum > F_GB2312_0)
X              continue;
X            break;
#endif /* KTERM_HANZI */
#ifdef KTERM_HANGUL
X          case 'k': case 'K':
X            if ((F_ISO8859_1 < fnum && fnum < F_KSC5601_0) ||
X                fnum > F_KSC5601_0)
X              continue;
X            break;
#endif /* KTERM_HANGUL */
X          default:
X            if (fnum > F_JISX0208_0)
X              continue;
X            break;
X        }
X        nfontname = screen->menu_font_names[fontnum];
X    }
X
X    if (!(nfontname && (nfs = XLoadQueryFont (screen->display, nfontname)))) {
/**
fprintf (stderr, "n%d: failed to load \"%s\"\n", fnum, nfontname);
**/
X	nfontname = search_font_matching(screen,
X			screen->menu_font_list[fontnum], fonttail[fnum]);
X	if (!(nfontname &&
X	      (nfs = XLoadQueryFont (screen->display, nfontname)))) {
/**
fprintf (stderr, "n%d: failed to load \"%s\"\n", fnum, nfontname);
**/
X		if (fnum > F_ISO8859_1) {
X		    nfs = asciinfs;
X		} else goto bad;
X	}
X    }
X    if (fnum == F_ISO8859_1) asciinfs = nfs;
/**
fprintf (stderr, "n%d: loaded \"%s\"\n", fnum, nfontname);
**/
X
X    if (nfontname && fontnum == fontMenu_fontescape &&
X	nfontname != screen->menu_font_names[fontnum]) {
X	tmpname = (char *) malloc (strlen(nfontname) + 1);
X	if (!tmpname) return 0;
X	strcpy (tmpname, nfontname);
X    }
#else /* !KTERM */
X    if (!nfontname) return 0;
X
X    if (fontnum == fontMenu_fontescape &&
X	nfontname != screen->menu_font_names[fontnum]) {
X	tmpname = (char *) malloc (strlen(nfontname) + 1);
X	if (!tmpname) return 0;
X	strcpy (tmpname, nfontname);
X    }
X
X    if (!(nfs = XLoadQueryFont (screen->display, nfontname))) goto bad;
#endif /* !KTERM */
X
#ifdef KTERM
X    bfontname = search_font_matching(screen, bfontpat, fonttail[fnum]);
X    if (!bfontname) bfontname = screen->menu_bfont_names[fontnum];
X
X    if (!(bfontname && (bfs = XLoadQueryFont (screen->display, bfontname)))) {
/**
fprintf (stderr, "b%d: failed to load \"%s\"\n", fnum, bfontname);
**/
X	bfontname = search_font_matching(screen,
X			screen->menu_bfont_list[fontnum], fonttail[fnum]);
X	if (!(bfontname &&
X	      (bfs = XLoadQueryFont (screen->display, bfontname)))) {
/**
fprintf (stderr, "b%d: failed to load \"%s\"\n", fnum, bfontname);
**/
X      		bfs = nfs;
X	}
/**
else fprintf (stderr, "b%d: loaded \"%s\"\n", fnum, bfontname);
**/
X    }
/**
else fprintf (stderr, "b%d: loaded \"%s\"\n", fnum, bfontname);
**/
X
X    if (bfontname && fontnum == fontMenu_fontescape &&
X	bfontname != screen->menu_bfont_names[fontnum]) {
X	tmpbname = (char *) malloc (strlen(bfontname) + 1);
X	if (!tmpbname) return 0;
X	strcpy (tmpbname, bfontname);
X    }
#else /* !KTERM */
X    if (!(bfontname && 
X	  (bfs = XLoadQueryFont (screen->display, bfontname))))
X      bfs = nfs;
#endif /* !KTERM */
X
X    mask = (GCFont | GCForeground | GCBackground | GCGraphicsExposures |
X	    GCFunction);
X
X    xgcv.font = nfs->fid;
X    xgcv.foreground = screen->foreground;
X    xgcv.background = term->core.background_pixel;
X    xgcv.graphics_exposures = TRUE;	/* default */
X    xgcv.function = GXcopy;
X
X    new_normalGC = XtGetGC((Widget)term, mask, &xgcv);
X    if (!new_normalGC) goto bad;
X
X    if (nfs == bfs) {			/* there is no bold font */
X	new_normalboldGC = new_normalGC;
X    } else {
X	xgcv.font = bfs->fid;
X	new_normalboldGC = XtGetGC((Widget)term, mask, &xgcv);
X	if (!new_normalboldGC) goto bad;
X    }
X
X    xgcv.font = nfs->fid;
X    xgcv.foreground = term->core.background_pixel;
X    xgcv.background = screen->foreground;
X    new_reverseGC = XtGetGC((Widget)term, mask, &xgcv);
X    if (!new_reverseGC) goto bad;
X
X    if (nfs == bfs) {			/* there is no bold font */
X	new_reverseboldGC = new_reverseGC;
X    } else {
X	xgcv.font = bfs->fid;
X	new_reverseboldGC = XtGetGC((Widget)term, mask, &xgcv);
X	if (!new_reverseboldGC) goto bad;
X    }
X
X    XtReleaseGC ((Widget) term, screen->normalGC);
X    if (screen->normalGC != screen->normalboldGC)
X      XtReleaseGC ((Widget) term, screen->normalboldGC);
X    XtReleaseGC ((Widget) term, screen->reverseGC);
X    if (screen->reverseGC != screen->reverseboldGC)
X      XtReleaseGC ((Widget) term, screen->reverseboldGC);
X    screen->normalGC = new_normalGC;
X    screen->normalboldGC = new_normalboldGC;
X    screen->reverseGC = new_reverseGC;
X    screen->reverseboldGC = new_reverseboldGC;
X    screen->fnt_norm = nfs;
X    screen->fnt_bold = bfs;
X    screen->fnt_bold = screen->fnt_norm;
X    screen->enbolden = (nfs == bfs);
X    set_menu_font (False);
X    screen->menu_font_number = fontnum;
X    set_menu_font (True);
X    if (tmpname) {			/* if setting escape or sel */
X	if (screen->menu_font_names[fontnum])
X	  free (screen->menu_font_names[fontnum]);
X	screen->menu_font_names[fontnum] = tmpname;
X	if (fontnum == fontMenu_fontescape) {
X	    set_sensitivity (term->screen.fontMenu,
X			     fontMenuEntries[fontMenu_fontescape].widget,
X			     TRUE);
X	}
X    }
#ifdef KTERM
X    set_cursor_gcs (screen, fnum);
X  }
#else /* !KTERM */
X    set_cursor_gcs (screen);
#endif /* !KTERM */
X    update_font_info (screen, doresize);
X    return 1;
X
X  bad:
X    if (tmpname) free (tmpname);
X    if (new_normalGC)
X      XtReleaseGC ((Widget) term, screen->normalGC);
X    if (new_normalGC && new_normalGC != new_normalboldGC)
X      XtReleaseGC ((Widget) term, new_normalboldGC);
X    if (new_reverseGC)
X      XtReleaseGC ((Widget) term, new_reverseGC);
X    if (new_reverseGC && new_reverseGC != new_reverseboldGC)
X      XtReleaseGC ((Widget) term, new_reverseboldGC);
X    if (nfs) XFreeFont (screen->display, nfs);
X    if (nfs && nfs != bfs) XFreeFont (screen->display, bfs);
X    return 0;
}
X
X
update_font_info (screen, doresize)
X    TScreen *screen;
X    Bool doresize;
{
X    int i, j, width, height, scrollbar_width;
#ifdef KTERM
X    int fnum;
X    int max_ascent = 0, max_descent = 0, max_width = 0;
X
X    for (fnum = F_ISO8859_1; fnum < FCNT; fnum ++) {
X	if (screen->_fnt_norm[fnum]) {
#ifdef KTERM_KANJI
X	  if (screen->_fnt_norm[fnum]->max_byte1 > 0) { /* MB font */
X	    if (max_width < screen->_fnt_norm[fnum]->max_bounds.width/2) {
X		max_width = screen->_fnt_norm[fnum]->max_bounds.width/2;
X	    }
X	  } else
#endif /* KTERM_KANJI */
X	    if (max_width < screen->_fnt_norm[fnum]->max_bounds.width) {
X		max_width = screen->_fnt_norm[fnum]->max_bounds.width;
X	    }
X	}
X    }
X    screen->fullVwin.f_width = max_width;
X    for (fnum = F_ISO8859_1; fnum < FCNT; fnum ++) {
X	if (screen->_fnt_norm[fnum]) {
X	    if (max_ascent < screen->_fnt_norm[fnum]->ascent) {
X		max_ascent = screen->_fnt_norm[fnum]->ascent;
X	    }
X	    if (max_descent < screen->_fnt_norm[fnum]->descent) {
X		max_descent = screen->_fnt_norm[fnum]->descent;
X	    }
X	}
X    }
X    screen->max_ascent = max_ascent;
X    screen->max_descent = max_descent;
X    screen->fullVwin.f_height = max_ascent + max_descent;
#else /* !KTERM */
X
X    screen->fullVwin.f_width = screen->fnt_norm->max_bounds.width;
X    screen->fullVwin.f_height = (screen->fnt_norm->ascent +
X				 screen->fnt_norm->descent);
#endif /* !KTERM */
X    scrollbar_width = (term->misc.scrollbar ? 
X		       screen->scrollWidget->core.width : 0);
X    i = 2 * screen->border + scrollbar_width;
X    j = 2 * screen->border;
#ifdef STATUSLINE
X    if (screen->statusline)
#ifdef KTERM
X	j += (screen->statusheight = FontHeight(screen) + 2);
#else /* !KTERM */
X	j += (screen->statusheight = screen->fullVwin.f_height + 2);
#endif /* !KTERM */
#endif /* STATUSLINE */
#ifdef KTERM
X    width = (screen->max_col + 1) * FontWidth(screen) + i;
X    height = (screen->max_row + 1) * FontHeight(screen) + j;
#else /* !KTERM */
X    width = (screen->max_col + 1) * screen->fullVwin.f_width + i;
X    height = (screen->max_row + 1) * screen->fullVwin.f_height + j;
#endif /* !KTERM */
X    screen->fullVwin.fullwidth = width;
X    screen->fullVwin.fullheight = height;
X    screen->fullVwin.width = width - i;
X    screen->fullVwin.height = height - j;
X
X    if (doresize) {
X	if (VWindow(screen)) {
X	    XClearWindow (screen->display, VWindow(screen));
X	}
X	DoResizeScreen (term);		/* set to the new natural size */
X	if (screen->scrollWidget)
X	  ResizeScrollBar (screen->scrollWidget, -1, -1,
X			   Height(screen) + screen->border * 2);
X	Redraw ();
X    }
X    set_vt_box (screen);
}
X
set_vt_box (screen)
X	TScreen *screen;
{
X	XPoint	*vp;
X
#ifdef KTERM
X	vp = &VTbox[1];
X	(vp++)->x = FontWidth(screen) - 1;
X	(vp++)->y = screen->fullVwin.f_height - 1;
X	(vp++)->x = -(FontWidth(screen) - 1);
X	vp->y = -(screen->fullVwin.f_height - 1);
X	screen->_box[F_ISO8859_1] = VTbox;
X	screen->_box[F_JISX0201_0] = VTbox;
# ifdef KTERM_KANJI
X	vp = &VTwbox[1];
X	(vp++)->x = FontWidth(screen) * 2 - 1;
X	(vp++)->y = screen->fullVwin.f_height - 1;
X	(vp++)->x = -(FontWidth(screen) * 2 - 1);
X	vp->y = -(screen->fullVwin.f_height - 1);
X        switch(term->misc.lang[0]) {
#ifdef KTERM_HANZI
X          case 'c': case 'C':
X            screen->_box[F_GB2312_0] = VTwbox;
X            break;
#endif /* KTERM_HANZI */
#ifdef KTERM_HANGUL
X          case 'k': case 'K':
X            screen->_box[F_KSC5601_0] = VTwbox;
X            break;
#endif /* KTERM_HANGUL */
X          default:
X            screen->_box[F_JISX0208_0] = VTwbox;
X            break;
X        }
# endif /* KTERM_KANJI */
#else /* !KTERM */
X	vp = &VTbox[1];
X	(vp++)->x = FontWidth(screen) - 1;
X	(vp++)->y = FontHeight(screen) - 1;
X	(vp++)->x = -(FontWidth(screen) - 1);
X	vp->y = -(FontHeight(screen) - 1);
X	screen->box = VTbox;
#endif /* !KTERM */
}
X
X
#ifdef KTERM
set_cursor_gcs (screen, fnum)
X    int fnum;
#else /* !KTERM */
set_cursor_gcs (screen)
#endif /* !KTERM */
X    TScreen *screen;
{
X    XGCValues xgcv;
X    unsigned long mask;
X    unsigned long cc = screen->cursorcolor;
X    unsigned long fg = screen->foreground;
X    unsigned long bg = term->core.background_pixel;
X    GC new_cursorGC = NULL, new_reversecursorGC = NULL;
X    GC new_cursoroutlineGC = NULL;
X
X    /*
X     * Let's see, there are three things that have "color":
X     *
X     *     background
X     *     text
X     *     cursorblock
X     *
X     * And, there are four situation when drawing a cursor, if we decide
X     * that we like have a solid block of cursor color with the letter
X     * that it is highlighting shown in the background color to make it
X     * stand out:
X     *
X     *     selected window, normal video - background on cursor
X     *     selected window, reverse video - foreground on cursor
X     *     unselected window, normal video - foreground on background
X     *     unselected window, reverse video - background on foreground
X     *
X     * Since the last two are really just normalGC and reverseGC, we only
X     * need two new GC's.  Under monochrome, we get the same effect as
X     * above by setting cursor color to foreground.
X     */
X
X    xgcv.font = screen->fnt_norm->fid;
X    mask = (GCForeground | GCBackground | GCFont);
X    if (cc != fg && cc != bg) {
X	/* we have a colored cursor */
X	xgcv.foreground = fg;
X	xgcv.background = cc;
X	new_cursorGC = XtGetGC ((Widget) term, mask, &xgcv);
X
X	if (screen->always_highlight) {
X	    new_reversecursorGC = (GC) 0;
X	    new_cursoroutlineGC = (GC) 0;
X	} else {
X	    xgcv.foreground = bg;
X	    xgcv.background = cc;
X	    new_reversecursorGC = XtGetGC ((Widget) term, mask, &xgcv);
X	    xgcv.foreground = cc;
X	    xgcv.background = bg;
X	    new_cursoroutlineGC = XtGetGC ((Widget) term, mask, &xgcv);
X		}
X    } else {
X	new_cursorGC = (GC) 0;
X	new_reversecursorGC = (GC) 0;
X	new_cursoroutlineGC = (GC) 0;
X    }
X    if (screen->cursorGC) XtReleaseGC (term, screen->cursorGC);
X    if (screen->reversecursorGC) XtReleaseGC (term, screen->reversecursorGC);
X    if (screen->cursoroutlineGC) XtReleaseGC (term, screen->cursoroutlineGC);
X    screen->cursorGC = new_cursorGC;
X    screen->reversecursorGC = new_reversecursorGC;
X    screen->cursoroutlineGC = new_cursoroutlineGC;
}
SHAR_EOF
echo 'File kterm-4.1.2/charproc.c is complete' &&
chmod 0664 kterm-4.1.2/charproc.c ||
echo 'restore of kterm-4.1.2/charproc.c failed'
Wc_c="`wc -c < 'kterm-4.1.2/charproc.c'`"
test 139105 -eq "$Wc_c" ||
	echo 'kterm-4.1.2/charproc.c: original size 139105, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= kterm-4.1.2/colortest ==============
if test -f 'kterm-4.1.2/colortest' -a X"$1" != X"-c"; then
	echo 'x - skipping kterm-4.1.2/colortest (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting kterm-4.1.2/colortest (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'kterm-4.1.2/colortest' &&
#!/bin/sh
X
for f in 0 4 1 5 2 6 3 7
do
X	echo '[3'${f}'m  $@%+%i!<%F%-%9%HBP1~$N(J [4'${f}'m kterm [3'${f}'m $@$G$9!#(J("^[[X'${f}'m")'
done
echo "[0m"
Xexit 0
SHAR_EOF
chmod 0775 kterm-4.1.2/colortest ||
echo 'restore of kterm-4.1.2/colortest failed'
Wc_c="`wc -c < 'kterm-4.1.2/colortest'`"
test 166 -eq "$Wc_c" ||
	echo 'kterm-4.1.2/colortest: original size 166, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= kterm-4.1.2/convert.c ==============
if test -f 'kterm-4.1.2/convert.c' -a X"$1" != X"-c"; then
	echo 'x - skipping kterm-4.1.2/convert.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting kterm-4.1.2/convert.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'kterm-4.1.2/convert.c' &&
/*
X *	convert.c -- code converters for kterm
X *	$Kagotani: /usr/src.yoshi/X/KTerm/4.1.0/RCS/convert.c,v 1.1 90/06/27 09:38:46 kagotani Rel $
X *
X * $Header: /usr/local/src/X11/contrib/clients/kterm-4.1.2/RCS/convert.c,v 1.5 1991/03/15 09:28:40 mleisher Exp $
X */
X
/*
X * Modified for Hanzi support:
X * Mark Leisher mleisher at nmsu.edu Fri Nov  9 09:22:33 1990
X */
X
/*
X * Copyright (c) 1989  Software Research Associates, Inc.
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Software Research Associates not be
X * used in advertising or publicity pertaining to distribution of the
X * software without specific, written prior permission.  Software Research
X * Associates makes no representations about the suitability of this software
X * for any purpose.  It is provided "as is" without express or implied
X * warranty.
X *
X * Author:  Makoto Ishisone, Software Research Associates, Inc., Japan
X */
#include <stdio.h>
#include "kterm.h"
X
#ifdef KTERM_HANZI
#include "hzutil.h"
#endif /* KTERM HANZI */
X
#ifdef KTERM_HANGUL
#include "hgutil.h"
#endif /* KTERM_HANGUL */
X
#ifdef KTERM
X
#define NULL	0
#define SS2	0x8E
#define CSI	0x9B
X
#ifdef KTERM_HANZI
X
Ichr *
convNSHzToGB(hz, from)
Ichr *hz;
int from;
{
X    Ichr *ptr;
X    int i, j, len = 0;
X    unsigned char c1, c2, oc1, oc2, gs1, gs2;
X
X    i = 0;
X    while(hz[i++].code) len++;
X    ptr = (Ichr *)XtMalloc((len + 1) * sizeof(Ichr));
X
X    i = j = 0;
X    while(i < len) {
X        gs1 = hz[i].gset;
X        c1 = hz[i].code;
X        if (gs1 != GSET_HANZI) {
X            ptr[j].gset = gs1;
X            ptr[j++].code = c1;
X        } else {
X            i++;
X            gs2 = hz[i].gset;
X            c2 = hz[i].code;
X            hzconvert(from, c1, c2, &oc1, &oc2);
X            ptr[j].gset = gs1;
X            ptr[j++].code = oc1;
X            ptr[j].gset = gs2;
X            ptr[j++].code = oc2;
X        }
X        i++;
X    }
X    ptr[j].gset = 0;
X    ptr[j].code = '\0';
X    return(ptr);
}
X
/* CS -> GUOBIAO */
static int
CStoGB(cs_p, gs_p)
Ichr		**cs_p;
unsigned char	**gs_p;
{
X	int		c1, c2;
X	Ichr		*cs = *cs_p;
X	unsigned char	*gs = *gs_p;
X
X        if (cs->gset == GSET_HANZI) {
X            c1 = cs++->code;
X            c2 = cs++->code;
X            if (gs) {
X                *gs++ = c1 | 0x80;
X                *gs++ = c2 | 0x80;
X            }
X            *gs_p = gs;
X            *cs_p = cs;
X            return(2);
X        }
X        return(0);
}
X
/* CS -> SGB */
static int
CStoSGB(cs_p, sgs_p)
Ichr		**cs_p;
unsigned char	**sgs_p;
{
X        int             c1, c2;
X	Ichr		*cs = *cs_p;
X	unsigned char	*sgs = *sgs_p;
X        unsigned char   oc1, oc2;
X
X        if (cs->gset == GSET_HANZI) {
X            c1 = cs++->code;
X            c2 = cs++->code;
X            if (sgs) {
X                hzconvert(GBtoSGB, c1, c2, &oc1, &oc2);
X                *sgs++ = oc1 | 0x80;
X                *sgs++ = oc2 | 0x80;
X            }
X            *sgs_p = sgs;
X            *cs_p = cs;
X            return(2);
X        }
X        return(0);
}
X
/* CS -> BIG5 */
static int
CStoBIG5(cs_p, bs_p)
Ichr		**cs_p;
unsigned char	**bs_p;
{
X	int		c1, c2;
X	Ichr		*cs = *cs_p;
X	unsigned char	*bs = *bs_p;
X        unsigned char	ch1, ch2, och1, och2;
X
X        if (cs->gset == GSET_HANZI) {
X            c1 = cs++->code;
X            c2 = cs++->code;
X            if (bs) {
X                ch1 = c1 | 0x80;
X                ch2 = c2 | 0x80;
X                hzconvert(GBtoBIG, ch1, ch2, &och1, &och2);
X                *bs++ = och1;
X                *bs++ = och2;
X            }
X            *bs_p = bs;
X            *cs_p = cs;
X            return(2);
X        }
X        return(0);
}
X
/* CS -> GUOBIAO using ESC-$-A */
int
convCStoGB(cs, gs)
Ichr	       *cs;
unsigned char  *gs;
{
X    return convCStoANY(cs, gs, CStoGB);
}
X
/* CS -> SGB using ESC-$-A */
int
convCStoSGB(cs, sgs)
Ichr	       *cs;
unsigned char  *sgs;
{
X    return convCStoANY(cs, sgs, CStoSGB);
}
X
/* CS -> BIG5 using ESC-$-A */
int
convCStoBIG5(cs, bs)
Ichr	       *cs;
unsigned char  *bs;
{
X    return convCStoANY(cs, bs, CStoBIG5);
}
#endif /* KTERM_HANZI */
X
#ifdef KTERM_HANGUL
/* CS -> KS */
static int
CStoKS(cs_p, ks_p)
Ichr		**cs_p;
unsigned char	**ks_p;
{
X	int		c1, c2;
X	Ichr		*cs = *cs_p;
X	unsigned char	*ks = *ks_p;
X
X        if (cs->gset == GSET_HANGUL) {
X            c1 = cs++->code;
X            c2 = cs++->code;
X            if (ks) {
X                *ks++ = c1 | 0x80;
X                *ks++ = c2 | 0x80;
X            }
X            *ks_p = ks;
X            *cs_p = cs;
X            return(2);
X        }
X        return(0);
}
X
/* CS -> KS using ESC-$-C */
int
convCStoKS(cs, ks)
Ichr		*cs;
unsigned char	*ks;
{
X    return convCStoANY(cs, ks, CStoKS);
}
#endif /* KTERM_HANGUL */
X
X
/* CS -> JIS using ESC-$-B */
int
convCStoJIS(cs, js)
Ichr		*cs;
unsigned char	*js;
{
X	return convCStoANY(cs, js, NULL);
}
X
/* CS -> EUC */
static int
CStoEUC(cs_p, es_p)
Ichr		**cs_p;
unsigned char	**es_p;
{
X	int		c1, c2;
X	Ichr		*cs = *cs_p;
X	unsigned char	*es = *es_p;
X	if (cs->gset == GSET_KANA) {
X		c1 = cs++->code;
X		if (es) {
X			*es++ = SS2;
X			*es++ = c1 | 0x80;
X		}
X		*es_p = es;
X		*cs_p = cs;
X		return 2;
X	} else if (cs->gset == GSET_KANJI
X		|| cs->gset == GSET_OLDKANJI) {
X		c1 = cs++->code;
X		c2 = cs++->code;
X		if (es) {
X			*es++ = c1 | 0x80;
X			*es++ = c2 | 0x80;
X		}
X		*es_p = es;
X		*cs_p = cs;
X		return 2;
X	}
X	return 0;
}
X
int
convCStoEUC(cs, es)
Ichr		*cs;
unsigned char	*es;
{
X	return convCStoANY(cs, es, CStoEUC);
}
X
/* CS -> SJIS */
static int
CStoSJIS(cs_p, ss_p)
Ichr		**cs_p;
unsigned char	**ss_p;
{
X	int		c1, c2;
X	Ichr		*cs = *cs_p;
X	unsigned char	*ss = *ss_p;
X	if (cs->gset == GSET_KANA) {
X		c1 = cs++->code;
X		if (ss) {
X			*ss++ = c1 | 0x80;
X		}
X		*ss_p = ss;
X		*cs_p = cs;
X		return 1;
X	} else if (cs->gset == GSET_KANJI || cs->gset == GSET_OLDKANJI) {
X		c1 = cs++->code;
X		c2 = cs++->code;
X		if (ss) {
X			*ss++ = (c1 - 0x21) / 2 + ((c1 <= 0x5e) ? 0x81 : 0xc1);
X			if (c1 & 1)	/* odd */
X			    *ss++ = c2 + ((c2 <= 0x5f) ? 0x1f : 0x20);
X			else
X			    *ss++ = c2 + 0x7e;
X		}
X		*ss_p = ss;
X		*cs_p = cs;
X		return 2;
X	}
X	return 0;
}
X
int
convCStoSJIS(cs, ss)
Ichr		*cs;
unsigned char	*ss;
{
X	return convCStoANY(cs, ss, CStoSJIS);
}
X
/* CS -> any */
int
convCStoANY(cs, as, func)
Ichr		*cs;
unsigned char	*as;
int		(*func)();
{
X	register int	c1, c2;
X	register int	gset = GSET_ASCII;
X	register int	n = 0, m;
X
X	while (c1 = cs->code) {
X		if (func && (m = (*func)(&cs, &as))) {
X			n += m;
X			continue;
X		}
X		if (gset != cs->gset) {
X			if (gset & CS96 && !(cs->gset & CS96)) {
X				if (as)
X					*as++ = '\025'; /* SI */
X				n++;
X			} else if (!(gset & CS96) && cs->gset & CS96) {
X				if (as)
X					*as++ = '\024'; /* SO */
X				n++;
X			}
X			/*
X			 *	A HACK FOR JISROMAN
X			 */
X			if (cs->gset == GSET_ASCII
X			 || cs->gset == GSET_JISROMAN) {
X				if (gset != GSET_ASCII
X				 && gset != GSET_JISROMAN) {
X					if (as) {
X						*as++ = '\033';
X						*as++ = '(';
X						*as++ = TESG(cs->gset);
X					}
X					n += 3;
X				}
X			} else if (cs->gset == GSET_KANJI
X			/*
X			 * if (cs->gset == GSET_KANJI
X			 */
X			 || cs->gset == GSET_OLDKANJI) {
X				if (as) {
X					*as++ = '\033';
X					*as++ = '$';
X					*as++ = TESG(cs->gset);
X				}
X				n += 3;
X			} else {
X				if (as) {
X					*as++ = '\033';
X					if (cs->gset & MBCS) {
X						*as++ = '$';
X					}
X					if (cs->gset & CS96) {
X						*as++ = '-';
X					} else {
X						*as++ = '(';
X					}
X					*as++ = TESG(cs->gset);
X				}
X				n += 3;
X				if (cs->gset & MBCS)
X					n ++;
X			}
X			gset = cs->gset;
X		}
X		cs++;
X		if (gset & MBCS) {
X			c2 = cs++->code;
X			if (as) {
X				*as++ = c1 & ~0x80;
X				*as++ = c2 & ~0x80;
X			}
X			n += 2;
X		} else {
X			if (as)
X				*as++ = c1 & ~0x80;
X			n++;
X		}
X	}
X	/*
X	 *	A HACK FOR JISROMAN
X	 * if (gset != GSET_ASCII) {
X	 */
X	if (gset != GSET_ASCII && gset != GSET_JISROMAN) {
X		if (as) {
X			*as++ = '\033';
X			*as++ = '(';
X			*as++ = 'B';
X		}
X		n += 3;
X	}
X	if (as)
X		*as = '\0';
X
X	return n;
}
X
/* CS -> ISO Latin-1 */
int
convCStoLatin1(cs, ls)
Ichr *cs;
unsigned char *ls;
{
X	register int	c;
X	register int	n = 0;
X
X	if (ls) {
X		while (c = cs->code) {
X			if (cs++->gset == GSET_ASCII) {
X				*ls++ = c & 0x7f;
X				n++;
X			}
X		}
X		*ls = '\0';
X	} else {
X		while (c = cs->code) {
X			if (cs++->gset == GSET_ASCII) {
X				n++;
X			}
X		}
X	}
X	return n;
}
X
/******************************************************************************
COMPOUND_TEXT Summary
X  (based on Comopund Text Encoding Version 1 -- MIT X Consortium Standard)
(1) Only G0 and G1 are used. G2 and G3 are not.
(2) G0 is invoked into GL and G1 into GR. These invocation are not changed.
X	(In other words, Locking Shift and Single Shift are not used)
(3) In initial state, ISO Latin-1 is designated into G0/G1.
(4) To designate MBCS into G0, ESC-$-F is not used but ESC-$-(-F.
(5) In C0, only HT, NL, and ESC are used.
(6) In C1, only CSI is used.
(7) Text direction can be indecated.
X	begin left-to-right string
X	begin right-to-left string
X	end of string
******************************************************************************/
X
/* convCStoCT -- Wide Character String -> COMPOUND_TEXT */
int
convCStoCT(cs, as)
register Ichr *cs;
register unsigned char *as;
/* Convert Wide Character String cs to COMPOUND_TEXT xstr, return
X * length of xstr in bytes (not including the terminating null character).
X * If xstr is NULL, no conversion is done, but return length of xstr.
X */
{
X	register int	c1, c2;
X	register int	g0 = GSET_ASCII;
X	register int	g1 = GSET_LATIN1R;
X	register int	n = 0;
X
X	while (c1 = cs->code) {
X	    if (cs->gset & CS96
X	     || cs->gset & MBCS
X	     || cs->gset == GSET_KANA) {
X		if (g1 != cs->gset) {
X			g1 = cs->gset;
X			if (as) {
X				*as++ = '\033';
X				if (g1 & MBCS) {
X					*as++ = '$';
X				}
X				if (g1 & CS96) {
X					*as++ = '-';
X				} else {
X					*as++ = ')';
X				}
X				*as++ = TESG(g1);
X			}
X			n += 3;
X			if (g1 & MBCS)
X				n ++;
X		}
X		cs++;
X		if (g1 & MBCS) {
X			c2 = cs++->code;
X			if (as) {
X				*as++ = c1 | 0x80;
X				*as++ = c2 | 0x80;
X			}
X			n += 2;
X		} else {
X			if (as)
X				*as++ = c1 | 0x80;
X			n++;
X		}
X	    } else {
X		if (g0 != cs->gset) {
X			g0 = cs->gset;
X			if (as) {
X				*as++ = '\033';
X				*as++ = '(';
X				*as++ = TESG(g0);
X			}
X			n += 3;
X		}
X		cs++;
X		if (as)
X			*as++ = c1 & ~0x80;
X		n++;
X	    }
X	}
X	if (g0 != GSET_ASCII) {
X		if (as) {
X			*as++ = '\033';
X			*as++ = '(';
X			*as++ = 'B';
X		}
X		n += 3;
X	}
X	if (as)
X		*as = '\0';
X
X	return n;
}
X
static unsigned char *
getesc(str, len)
unsigned char *str;
int len;
{
X	register int	c;
X
X	/* Find intermediate characters and final character
X	 * following the escape character in an escape sequence.
X	 */
X	/* The intermediate character is 02/00 to 02/15 */
X	while (len > 0) {
X		c = *str;
X		if (c < 0x20 || 0x2f < c)
X			break;
X		len--, str++;
X	}
X	/* The final character is 03/00 to 07/14 */
X	if (--len < 0 || (c = *str++) < 0x30 || 0x7e < c)
X		return (unsigned char *)NULL;
X
X	return str;
}
X
static unsigned char *
getcsi(str, len)
unsigned char *str;
int len;
{
X	register int	c;
X
X	/* Find parameter characters, intermediate characters
X	 * and final character following the CSI character
X	 * in a CSI sequence.
X	 */
X	/* The parameter characters is 03/00 to 03/15 */
X	while (len > 0) {
X		c = *str;
X		if (c < 0x30 || 0x3f < c)
X			break;
X		len--, str++;
X	}
X	/* The intermediate character is 02/00 to 02/15 */
X	while (len > 0) {
X		c = *str;
X		if (c < 0x20 || 0x2f < c)
X			break;
X		len--, str++;
X	}
X	/* The final character is 04/00 to 07/14 */
X	if (--len < 0 || (c = *str++) < 0x40 || 0x7e < c)
X		return (unsigned char *)NULL;
X
X	return str;
}
X
/* convCTtoCS -- COMPOUND_TEXT -> Wide Character String */
int
convCTtoCS(xstr, len, cs)
register unsigned char *xstr;
int len;
Ichr *cs;
/* Convert COMPOUND_TEXT xstr to Wide Character String cs, return
X * length of cs in characters (not including the terminating null character).
X * If cs is NULL, no conversion is done, but return length of cs.
X */
{
X	register int	c;
X	int	nskip;
X	int	n = 0;
X	int	g0, g1, gs;
X	unsigned char	*xstr1;
X
X	/*
X	 * Compound Text can include null octet. Therefore the length
X	 * of xstr is able to be specified by parameter len.
X	 * But if len is zero or negative, get length by strlen() assuming
X	 * that no null octet exists.
X	 */
X	if (len <= 0) {
X		len = strlen((char *)xstr);
X	}
X
X	/* In initial state, ISO 8859/1 is designated into G0/G1 */
X	g0 = GSET_ASCII;	/* ASCII -> G0 */
X	g1 = GSET_LATIN1R;	/* Latin/1 right hand part -> G1 */
X
X	while (len-- > 0) {
X		switch (c = *xstr++) {
X		case '\n':	/* NEWLINE */
X		case '\t':	/* TAB */
X			if (cs) {
X				cs->code = c;
X				cs->gset = g0;
X				cs++;
X			}
X			n++;
X			break;
X		case 0x9b:	/* CSI */
X			/*
X			 * CSI sequence is generally in following form:
X			 *	CSI {P} {I} F
X			 *        P : 03/00 to 03/15
X			 *        I : 02/00 to 02/15
X			 *        F : 04/00 to 07/14
X			 */
X			/*
X			 * Currently only directionality is definde
X			 * as following:
X			 *	CSI-1-]		begin left-to-right text
X			 *	CSI-2-]		begin right-to-left text
X			 *	CSI-]		end of string
X			 * But this implementation ignores them.
X			 */
X			xstr1 = getcsi(xstr, len);
X			if (xstr1 == NULL)
X				return -1;
X			len -= xstr1 - xstr;
X			xstr = xstr1;
X			break;
X		case '\033':	/* ESC */
X			/*
X			 * ESC sequence is generally in following form:
X			 *	ESC {I} F
X			 *        I : 02/00 to 02/15
X			 *        F : 03/00 to 07/14
X			 */
X			/*
X			 * Currently, following functions are defined:
X			 *   Standard character set
X			 *	ESC-(-F
X			 *	ESC-$-(-F
X			 *	ESC-)-F
X			 *	ESC---F
X			 *	ESC-$-)-F
X			 *   Non standard character set
X			 *	ESC-%-/-[0123]
X			 * Standard character set must be accepted correctly.
X			 * Non standard one is ignored but must be parsed
X			 * for skipping data.
X			 */
X			xstr1 = getesc(xstr, len);
X			if (xstr1 == NULL)
X				return -1;
X			len -= xstr1 - xstr;
X			switch (xstr1 - xstr) {
X			case 2:		/* ESC - I - F */
X				switch (*xstr++) {
X				case '(':	/* 94chars CS -> G0 */
X					g0 = GSET(*xstr);
X					break;
X				case ')':	/* 94chars CS -> G1 */
X					g1 = GSET(*xstr);
X					break;
X				case '-':	/* 96chars CS -> G1 */
X					g1 = GSET(*xstr) | CS96;
X					break;
X				default:	/* ignore */
X					break;
X				}
X				break;
X			case 3:		/* ESC - I - I - F */
X				switch (*xstr++) {
X				case '$':
X					switch (*xstr++) {
X					case '(':	/* 94chars MBCS -> G0 */
X						g0 = GSET(*xstr) | MBCS;
X						break;
X					case ')':	/* 94chars MBCS -> G1 */
X						g1 = GSET(*xstr) | MBCS;
X						break;
X					case '-':	/* 96chars MBCS -> G1 */
X						g1 = GSET(*xstr) | CS96 | MBCS;
X						break;
X					default:	/* ignore */
X						break;
X					}
X					break;
X				case '%':
X					if (*xstr++ != '/') {
X						/* unknown sequence */
X						break;
X					}
X					/*
X					 * Private encoding is ignored.
X					 * But following data must be skipped.
X					 *	ESC-%-/-F-M-L
X					 */
X					len -= 2;
X					if (len < 0)
X						return -1;
X					nskip = (*xstr1 & 0x7f) * 128 +
X					    (*(xstr1 + 1) & 0x7f);
X					if ((len -= nskip) < 0)
X						return -1;
X					xstr1 += nskip + 2;
X					break;
X				default:
X					break;
X				}
X				break;
X			default:
X				break;
X			}
X			xstr = xstr1;
X			break;
X		default:
X			if (!(c & 0x60)) {
X				/*
X				 * Non NL/TAB/ESC/CSI character in C0 or C1
X				 * is an obvious error.
X				 */
X				return -1;
X			}
X			gs = (c & 0x80) ? g1 : g0;
X			if (cs) {
X				cs->code = c & ~0x80;
X				cs->gset = gs;
X				cs++;
X			}
X			n++;
X			break;
X		}
X	}
X	if (cs) {
X		cs->code = 0;
X		cs->gset = 0;
X	}
X	return n;
}
#endif
SHAR_EOF
chmod 0664 kterm-4.1.2/convert.c ||
echo 'restore of kterm-4.1.2/convert.c failed'
Wc_c="`wc -c < 'kterm-4.1.2/convert.c'`"
test 15524 -eq "$Wc_c" ||
	echo 'kterm-4.1.2/convert.c: original size 15524, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= kterm-4.1.2/convlib.c ==============
if test -f 'kterm-4.1.2/convlib.c' -a X"$1" != X"-c"; then
	echo 'x - skipping kterm-4.1.2/convlib.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting kterm-4.1.2/convlib.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'kterm-4.1.2/convlib.c' &&
/*
X *	convlib.c -- conversion input library for X11 Toolkit (Xt)
X *	$Header: /usr/src.yoshi/X/KTerm/4.1.0/RCS/convlib.c,v 1.1 90/06/27 09:38:48 kagotani Rel $
X *
X *		ishisone at sra.co.jp
X */
X
/*
X * Modified for Hanzi support:
X * Mark Leisher mleisher at nmsu.edu Fri Nov  9 09:22:33 1990
X */
X
/*
X * Copyright (C) 1988 by Software Research Associates, Inc.
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Software Research Associates not be
X * used in advertising or publicity pertaining to distribution of the
X * software without specific, written prior permission.  Software Research
X * Associates makes no representations about the suitability of this software
X * for any purpose.  It is provided "as is" without express or implied
X * warranty.
X *
X * Author:  Makoto Ishisone, Software Research Associates, Inc., Japan
X *		ishisone at sra.co.jp
X */
X
/*
X * This library is for languages that need complex input method
X * (such as Japanese or Chinese).
X * It communicates with the conversion server using the standard X11
X * inter-client communication mechanism (selection/property/clientmessage),
X * so that you can easily input these languages (if you have the conversion
X * server).
X */
X
X
/*
X * see protocol document for the protocol used between client and 
X * conversion server.
X */
X
/*
X * How to use this library:
X *
X *	1. add the following entry to the widget's action table.
X *
X *		{"begin-conversion",	beginConversion},
X *
X *	2. add the following entry to the translation table.
X *
X *		[trigger-event]: begin-conversion(<language>_CONVERSION)
X *
X *	where:
X *		[trigger-event]	- an trigger event of starting conversion
X *		<language> - the language you want to input
X *	ex)
X *		Ctrl<Key>Kanji: begin-conversion(JAPANESE_CONVERSION)
X *
X *	3. write a function beginConversion().
X *	Since function beginConversion is called by the translation manager,
X *	the arguments passed are Widget, XEvent*, and parameter strings.
X *	This function should call _beginConversion() defined in this library.
X *	_beginConversion()'s interface is:
X *
X *	void _beginConversion(Widget w, Atom catom, Atom tatom,
X *			      void (*inputproc)(), caddr_t client_data);
X *	where:
X *		catom - Selection Atom (JAPANESE_CONVERSION for Japanese)
X *				       (CHINESE_CONVERSION for Chinese)
X *		tatom - Property type of the conversion text
X *				(e.g. COMPOUND_TEXT)
X *		inputproc - conversion text callback function (see below)
X *		client_data - client_data passed to inputproc
X *
X *	this callback function interface is:
X *
X *		textInput(Widget w, Atom selection,
X *				Atom proptype, int propformat,
X *				unsigned long propsize,
X *				unsigned char *propvalue,
X *				caddr_t client_data);
X *
X *	the callback function should free propvalue data area by calling
X *	XtFree().
X *
X *	So, the simplest beginConversion() will be like this:
X *
X *	/-* ARGSUSED *-/
X *	void beginConversion(w, event, params, nparams)
X *	Widget	w;
X *	XEvent	*event;
X *	String	*params;
X *	Cardinal	*nparams;
X *	{
X *		void	textInput();
X *		Atom	catom, tatom;
X *
X *		if (*nparams != 1) {
X *			/-* Error *-/
X *		}
X *		catom = XInternAtom(XtDisplay(w), *params, False);
X *		tatom = XInternAtom(XtDisplay(w), "COMPOUND_TEXT", False);
X *		_beginConversion(w, catom, tatom, textInput, NULL);
X *	}
X */
X
#include "kterm.h"
X
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Xutil.h>
X
#ifndef lint
static char	*rcsid = "$Id: convlib.c,v 1.1 90/06/27 09:38:48 kagotani Rel $";
#endif
X
/*
X * Atoms:
X *	reqAtom ("CONVERSION_REQUEST")
X *		message_type in ClientMessage event that is sent
X *		when requesting conversion service to conversion server.
X *	notifyAtom ("CONVERSION_NOTIFY")
X *		message_type in ClientMessage event that is sent
X *		from conversion server.
X *	endAtom ("CONVERSION_END")
X *		message_type in ClientMessage event that is sent
X *		from conversion server when conversion ends.
X *	endReqAtom ("CONVERSION_END_REQUEST")
X *		message_type in ClientMessage event that is sent
X *		from clients for stopping conversion.
X */
X
typedef struct {
X	Display	*display;
X	Atom	reqAtom;	/* "CONVERSION_REQUEST" */
X	Atom	notifyAtom;	/* "CONVERSION_NOTIFY" */
X	Atom	endAtom;	/* "CONVERSION_END" */
X	Atom	endReqAtom;	/* "CONVERSION_END_REQUEST" */
} ConversionAtoms;
X
typedef struct {
X	Atom	convatom;
X	Window	convowner;
X	Atom	property;
X	void	(*inputproc)();
X	caddr_t	closure;
} ConversionContext;
X
static XContext	convertPrivContext;
X
#if __STDC__ == 1
/* function prototype */
static ConversionAtoms *getAtoms(Widget);
static ConversionContext *getConversionContext(Widget);
static void recvConvAck(Widget, caddr_t, XEvent *);
static void getConv(Widget, caddr_t, XEvent *);
#else
static ConversionAtoms *getAtoms();
static ConversionContext *getConversionContext();
static void recvConvAck();
static void getConv();
#endif
X
static ConversionAtoms *
getAtoms(w)
Widget	w;
/* make atoms used for communicating with conversion server
X * and a context for holding the property name
X */
{
X	int			i;
X	Display			*disp = XtDisplay(w);
X	ConversionAtoms		*cap;
X	static ConversionAtoms	*convatomp;
X	static Cardinal		ndisp = 0;
#define nalloc	2
X
X	/*
X	 * Atoms should be made for each display
X	 */
X
X	/* check if the atoms are already made */
X	cap = convatomp;
X	for (i = 0; i < ndisp; i++, cap++) {
X		if (cap->display == disp)
X			return cap;
X	}
X
X	/* not made yet, so create them */
X	if (ndisp == 0) {
X		/* it's a first time, so a context should also be made */
X		convertPrivContext = XUniqueContext();
X		convatomp = (ConversionAtoms *)
X		    XtMalloc(sizeof(ConversionAtoms) * nalloc);
X		cap = convatomp;
X	} else if (ndisp % nalloc == 0) {
X		/* increase size */
X		convatomp = (ConversionAtoms *)
X		    XtRealloc(convatomp, sizeof(ConversionAtoms) * (ndisp +nalloc));
X		cap = convatomp + ndisp;
X	} else {
X		cap = convatomp + ndisp;
SHAR_EOF
true || echo 'restore of kterm-4.1.2/convlib.c failed'
fi
echo 'End of kterm-4.1.2 part 9'
echo 'File kterm-4.1.2/convlib.c is continued in part 10'
echo 10 > _shar_seq_.tmp
exit 0


-----------------------------------------------------------------------------
mleisher at 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 at uunet.uu.net
argv at ora.com                 argv at zipcode.com



More information about the Comp.sources.x mailing list