Make 8-bit support run-time configurable.
Now to do the same for xterm support. This means people can eventually toy around with xterm+UTF-8 without recompiling their kernel.
This commit is contained in:
parent
b03552b5e2
commit
e06d84fc49
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=197115
@ -125,6 +125,9 @@ scteken_init(scr_stat *scp, void **softc, int code)
|
||||
/* FALLTHROUGH */
|
||||
case SC_TE_WARM_INIT:
|
||||
teken_init(&ts->ts_teken, &scteken_funcs, scp);
|
||||
#ifndef TEKEN_UTF8
|
||||
teken_set_8bit(&ts->ts_teken);
|
||||
#endif /* !TEKEN_UTF8 */
|
||||
|
||||
tp.tp_row = scp->ysize;
|
||||
tp.tp_col = scp->xsize;
|
||||
|
@ -49,26 +49,17 @@ static FILE *df;
|
||||
#endif /* __FreeBSD__ && _KERNEL */
|
||||
|
||||
#include "teken.h"
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
#include "teken_wcwidth.h"
|
||||
#else /* !TEKEN_UTF8 */
|
||||
#ifdef TEKEN_XTERM
|
||||
#define teken_wcwidth(c) ((c <= 0x1B) ? -1 : 1)
|
||||
#else /* !TEKEN_XTERM */
|
||||
#define teken_wcwidth(c) (1)
|
||||
#endif /* TEKEN_XTERM */
|
||||
#endif /* TEKEN_UTF8 */
|
||||
|
||||
#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
|
||||
#ifdef TEKEN_XTERM
|
||||
#include "teken_scs.h"
|
||||
#else /* !(TEKEN_XTERM && TEKEN_UTF8) */
|
||||
#else /* !TEKEN_XTERM */
|
||||
#define teken_scs_process(t, c) (c)
|
||||
#define teken_scs_restore(t)
|
||||
#define teken_scs_save(t)
|
||||
#define teken_scs_set(t, g, ts)
|
||||
#define teken_scs_switch(t, g)
|
||||
#endif /* TEKEN_XTERM && TEKEN_UTF8 */
|
||||
#endif /* TEKEN_XTERM */
|
||||
|
||||
/* Private flags for t_stateflags. */
|
||||
#define TS_FIRSTDIGIT 0x01 /* First numeric digit in escape sequence. */
|
||||
@ -187,9 +178,7 @@ teken_init(teken_t *t, const teken_funcs_t *tf, void *softc)
|
||||
t->t_defattr.ta_bgcolor = TC_BLACK;
|
||||
teken_subr_do_reset(t);
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
t->t_utf8_left = 0;
|
||||
#endif /* TEKEN_UTF8 */
|
||||
|
||||
teken_set_winsize(t, &tp);
|
||||
}
|
||||
@ -214,14 +203,14 @@ teken_input_char(teken_t *t, teken_char_t c)
|
||||
case '\x0C':
|
||||
teken_subr_newpage(t);
|
||||
break;
|
||||
#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
|
||||
#ifdef TEKEN_XTERM
|
||||
case '\x0E':
|
||||
teken_scs_switch(t, 1);
|
||||
break;
|
||||
case '\x0F':
|
||||
teken_scs_switch(t, 0);
|
||||
break;
|
||||
#endif /* TEKEN_XTERM && TEKEN_UTF8 */
|
||||
#endif /* TEKEN_XTERM */
|
||||
case '\r':
|
||||
teken_subr_carriage_return(t);
|
||||
break;
|
||||
@ -253,11 +242,13 @@ static void
|
||||
teken_input_byte(teken_t *t, unsigned char c)
|
||||
{
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
/*
|
||||
* UTF-8 handling.
|
||||
*/
|
||||
if ((c & 0x80) == 0x00) {
|
||||
if (t->t_utf8_left == -1) {
|
||||
/* UTF-8 disabled. */
|
||||
teken_input_char(t, c);
|
||||
} else if ((c & 0x80) == 0x00) {
|
||||
/* One-byte sequence. */
|
||||
t->t_utf8_left = 0;
|
||||
teken_input_char(t, c);
|
||||
@ -283,9 +274,6 @@ teken_input_byte(teken_t *t, unsigned char c)
|
||||
teken_input_char(t, t->t_utf8_partial);
|
||||
}
|
||||
}
|
||||
#else /* !TEKEN_UTF8 */
|
||||
teken_input_char(t, c);
|
||||
#endif /* TEKEN_UTF8 */
|
||||
}
|
||||
|
||||
void
|
||||
@ -344,6 +332,13 @@ teken_set_winsize(teken_t *t, const teken_pos_t *p)
|
||||
teken_subr_do_reset(t);
|
||||
}
|
||||
|
||||
void
|
||||
teken_set_8bit(teken_t *t)
|
||||
{
|
||||
|
||||
t->t_utf8_left = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* State machine.
|
||||
*/
|
||||
|
@ -36,7 +36,6 @@
|
||||
* commands.
|
||||
*
|
||||
* Configuration switches:
|
||||
* - TEKEN_UTF8: Enable/disable UTF-8 handling.
|
||||
* - TEKEN_XTERM: Enable xterm-style emulation, instead of cons25.
|
||||
*/
|
||||
|
||||
@ -44,11 +43,7 @@
|
||||
#include "opt_teken.h"
|
||||
#endif /* __FreeBSD__ && _KERNEL */
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
typedef uint32_t teken_char_t;
|
||||
#else /* !TEKEN_UTF8 */
|
||||
typedef unsigned char teken_char_t;
|
||||
#endif /* TEKEN_UTF8 */
|
||||
typedef unsigned short teken_unit_t;
|
||||
typedef unsigned char teken_format_t;
|
||||
#define TF_BOLD 0x01
|
||||
@ -121,9 +116,9 @@ typedef struct {
|
||||
tf_respond_t *tf_respond;
|
||||
} teken_funcs_t;
|
||||
|
||||
#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
|
||||
#ifdef TEKEN_XTERM
|
||||
typedef teken_char_t teken_scs_t(teken_char_t);
|
||||
#endif /* TEKEN_XTERM && TEKEN_UTF8 */
|
||||
#endif /* TEKEN_XTERM */
|
||||
|
||||
/*
|
||||
* Terminal state.
|
||||
@ -156,16 +151,14 @@ struct __teken {
|
||||
#define T_NUMCOL 160
|
||||
unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)];
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
unsigned int t_utf8_left;
|
||||
int t_utf8_left;
|
||||
teken_char_t t_utf8_partial;
|
||||
#endif /* TEKEN_UTF8 */
|
||||
|
||||
#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
|
||||
#ifdef TEKEN_XTERM
|
||||
unsigned int t_curscs;
|
||||
teken_scs_t *t_saved_curscs;
|
||||
teken_scs_t *t_scs[2];
|
||||
#endif /* TEKEN_XTERM && TEKEN_UTF8 */
|
||||
#endif /* TEKEN_XTERM */
|
||||
};
|
||||
|
||||
/* Initialize teken structure. */
|
||||
@ -182,4 +175,7 @@ void teken_set_curattr(teken_t *, const teken_attr_t *);
|
||||
void teken_set_defattr(teken_t *, const teken_attr_t *);
|
||||
void teken_set_winsize(teken_t *, const teken_pos_t *);
|
||||
|
||||
/* Legacy features. */
|
||||
void teken_set_8bit(teken_t *);
|
||||
|
||||
#endif /* !_TEKEN_H_ */
|
||||
|
@ -95,7 +95,6 @@ printchar(const teken_pos_t *p)
|
||||
px = &buffer[p->tp_col][p->tp_row];
|
||||
|
||||
/* Convert Unicode to UTF-8. */
|
||||
#ifdef TEKEN_UTF8
|
||||
if (px->c < 0x80) {
|
||||
str[0] = px->c;
|
||||
} else if (px->c < 0x800) {
|
||||
@ -111,9 +110,6 @@ printchar(const teken_pos_t *p)
|
||||
str[2] = 0x80 | ((px->c >> 6) & 0x3f);
|
||||
str[3] = 0x80 | (px->c & 0x3f);
|
||||
}
|
||||
#else /* !TEKEN_UTF8 */
|
||||
str[0] = px->c;
|
||||
#endif /* TEKEN_UTF8 */
|
||||
|
||||
if (px->a.ta_format & TF_BOLD)
|
||||
attr |= A_BOLD;
|
||||
@ -294,9 +290,7 @@ main(int argc __unused, char *argv[] __unused)
|
||||
};
|
||||
int i, j;
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
setlocale(LC_CTYPE, "UTF-8");
|
||||
#endif /* TEKEN_UTF8 */
|
||||
|
||||
tp.tp_row = ws.ws_row = NROWS;
|
||||
tp.tp_col = ws.ws_col = NCOLS;
|
||||
@ -311,9 +305,7 @@ main(int argc __unused, char *argv[] __unused)
|
||||
#else /* !TEKEN_XTERM */
|
||||
setenv("TERM", "cons25", 1);
|
||||
#endif /* TEKEN_XTERM */
|
||||
#ifdef TEKEN_UTF8
|
||||
setenv("LC_CTYPE", "UTF-8", 0);
|
||||
#endif /* TEKEN_UTF8 */
|
||||
execlp("zsh", "-zsh", NULL);
|
||||
execlp("bash", "-bash", NULL);
|
||||
execlp("sh", "-sh", NULL);
|
||||
|
@ -786,13 +786,20 @@ static void
|
||||
teken_subr_regular_character(teken_t *t, teken_char_t c)
|
||||
{
|
||||
int width;
|
||||
|
||||
c = teken_scs_process(t, c);
|
||||
|
||||
/* XXX: Don't process zero-width characters yet. */
|
||||
width = teken_wcwidth(c);
|
||||
if (width <= 0)
|
||||
return;
|
||||
if (t->t_utf8_left == -1) {
|
||||
#ifdef TEKEN_XTERM
|
||||
if (c <= 0x1B)
|
||||
return;
|
||||
#endif /* TEKEN_XTERM */
|
||||
width = 1;
|
||||
} else {
|
||||
c = teken_scs_process(t, c);
|
||||
width = teken_wcwidth(c);
|
||||
/* XXX: Don't process zero-width characters yet. */
|
||||
if (width <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEKEN_XTERM
|
||||
if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1 &&
|
||||
|
Loading…
Reference in New Issue
Block a user