PERFORCE change 154718 for review
Ed Schouten
ed at FreeBSD.org
Mon Dec 15 11:49:39 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=154718
Change 154718 by ed at ed_flippo on 2008/12/15 19:49:15
Small improvements:
- Add support for per-terminal default attributes.
- Print kernel messages in a different color again.
- Add new keyword to sequences file to mark commands whose
arguments should be set to 1 whose value is 0.
Affected files ...
.. //depot/projects/mpsafetty/sys/dev/syscons/scterm-teken.c#18 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/gensequences#2 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/sequences#5 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/teken.c#7 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/teken.h#10 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/teken_subr.h#12 edit
Differences ...
==== //depot/projects/mpsafetty/sys/dev/syscons/scterm-teken.c#18 (text+ko) ====
@@ -48,10 +48,13 @@
#include <dev/syscons/teken/teken.h>
+static void scteken_revattr(unsigned char, teken_attr_t *);
+
static sc_term_init_t scteken_init;
static sc_term_term_t scteken_term;
static sc_term_puts_t scteken_puts;
static sc_term_ioctl_t scteken_ioctl;
+static sc_term_default_attr_t scteken_default_attr;
static sc_term_clear_t scteken_clear;
static sc_term_input_t scteken_input;
static void scteken_nop(void);
@@ -75,7 +78,7 @@
scteken_puts,
scteken_ioctl,
(sc_term_reset_t *)scteken_nop,
- (sc_term_default_attr_t *)scteken_nop,
+ scteken_default_attr,
scteken_clear,
(sc_term_notify_t *)scteken_nop,
scteken_input,
@@ -120,9 +123,15 @@
ts->ts_busy = 1;
teken_init(&ts->ts_teken, &scteken_funcs, scp);
+
tp.tp_row = scp->ysize;
tp.tp_col = scp->xsize;
- teken_winsize(&ts->ts_teken, &tp);
+ teken_set_winsize(&ts->ts_teken, &tp);
+
+ tp.tp_row = scp->cursor_pos / scp->xsize;
+ tp.tp_col = scp->cursor_pos % scp->xsize;
+ teken_set_cursor(&ts->ts_teken, &tp);
+
break;
case SC_TE_WARM_INIT:
/* XXX */
@@ -184,6 +193,16 @@
}
static void
+scteken_default_attr(scr_stat *scp, int color, int rev_color)
+{
+ teken_stat *ts = scp->ts;
+ teken_attr_t ta;
+
+ scteken_revattr(color, &ta);
+ teken_set_defattr(&ts->ts_teken, &ta);
+}
+
+static void
scteken_clear(scr_stat *scp)
{
@@ -209,21 +228,61 @@
* libteken routines.
*/
-static const unsigned char fgcolors_normal[8] = {
+static const unsigned char fgcolors_normal[TC_NCOLORS] = {
FG_BLACK, FG_RED, FG_GREEN, FG_BROWN,
FG_BLUE, FG_MAGENTA, FG_CYAN, FG_LIGHTGREY,
};
-static const unsigned char fgcolors_bold[8] = {
+static const unsigned char fgcolors_bold[TC_NCOLORS] = {
FG_DARKGREY, FG_LIGHTRED, FG_LIGHTGREEN, FG_YELLOW,
FG_LIGHTBLUE, FG_LIGHTMAGENTA, FG_LIGHTCYAN, FG_WHITE,
};
-static const unsigned char bgcolors[8] = {
+static const unsigned char bgcolors[TC_NCOLORS] = {
BG_BLACK, BG_RED, BG_GREEN, BG_BROWN,
BG_BLUE, BG_MAGENTA, BG_CYAN, BG_LIGHTGREY,
};
+static void
+scteken_revattr(unsigned char color, teken_attr_t *a)
+{
+ teken_color_t fg, bg;
+
+ /*
+ * XXX: Reverse conversion of syscons to teken attributes. Not
+ * realiable. Maybe we should turn it into a 1:1 mapping one of
+ * these days?
+ */
+
+ a->ta_format = 0;
+ a->ta_fgcolor = TC_WHITE;
+ a->ta_bgcolor = TC_BLACK;
+
+#ifdef FG_BLINK
+ if (color & FG_BLINK) {
+ a->ta_format |= TF_BLINK;
+ color &= ~FG_BLINK;
+ }
+#endif /* FG_BLINK */
+
+ for (fg = 0; fg < TC_NCOLORS; fg++) {
+ for (bg = 0; bg < TC_NCOLORS; bg++) {
+ if ((fgcolors_normal[fg] | bgcolors[bg]) == color) {
+ a->ta_fgcolor = fg;
+ a->ta_bgcolor = bg;
+ return;
+ }
+
+ if ((fgcolors_bold[fg] | bgcolors[bg]) == color) {
+ a->ta_fgcolor = fg;
+ a->ta_bgcolor = bg;
+ a->ta_format |= TF_BOLD;
+ return;
+ }
+ }
+ }
+}
+
static inline unsigned int
scteken_attr(const teken_attr_t *a)
{
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/gensequences#2 (text+ko) ====
@@ -115,8 +115,12 @@
} else {
printf "\t\t%s(t", l_cmd_c_name[c];
split(l_cmd_args[c], args, " ");
- for (a = 1; args[a] != ""; a++)
- printf ", t->t_curnum < %d ? %d : t->t_nums[%d]", a, args[a], (a - 1);
+ for (a = 1; args[a] != ""; a++) {
+ if (args[a] == "n")
+ printf ", (t->t_curnum < %d || t->t_nums[%d] == 0) ? 1 : t->t_nums[%d]", a, (a - 1), (a - 1);
+ else
+ printf ", t->t_curnum < %d ? %d : t->t_nums[%d]", a, args[a], (a - 1);
+ }
print ");";
}
print "\t\tbreak;";
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/sequences#5 (text+ko) ====
@@ -23,23 +23,31 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
-# Abbr Name Sequence Default args
-CBT Cursor Backward Tabulation ^[ [ Z 1
-CHT Cursor Forward Tabulation ^[ [ I 1
-CNL Cursor Next Line ^[ [ E 1
-CPL Cursor Previous Line ^[ [ F 1
+# File format is as follows:
+# Abbr Abbreviation of sequence name
+# Name Sequence name (will be converted to C function name)
+# Sequence Bytes that form the sequence
+# Arguments Standard value of arguments passed to this sequence
+# - `variable' means a variable number of arguments
+# - `n' converts 0 to 1
+
+# Abbr Name Sequence Arguments
+CBT Cursor Backward Tabulation ^[ [ Z n
+CHT Cursor Forward Tabulation ^[ [ I n
+CNL Cursor Next Line ^[ [ E n
+CPL Cursor Previous Line ^[ [ F n
CPR Cursor Position Report ^[ [ n 0
-CUB Cursor Backward ^[ [ D 1
-CUD Cursor Down ^[ [ B 1
-CUD Cursor Down ^[ [ e 1
-CUF Cursor Forward ^[ [ C 1
-CUF Cursor Forward ^[ [ a 1
+CUB Cursor Backward ^[ [ D n
+CUD Cursor Down ^[ [ B n
+CUD Cursor Down ^[ [ e n
+CUF Cursor Forward ^[ [ C n
+CUF Cursor Forward ^[ [ a n
CUP Cursor Position ^[ [ H 1 1
CUP Cursor Position ^[ [ f 1 1
-CUU Cursor Up ^[ [ A 1
+CUU Cursor Up ^[ [ A n
DA1 Primary Device Attributes ^[ [ c 0
DA2 Secondary Device Attributes ^[ [ > c 0
-DC Delete character ^[ [ P 1
+DC Delete character ^[ [ P n
DCS Device Control String ^[ P
DECALN Alignment test ^[ # 8
DECDHL Double Height Double Width Line Top ^[ # 3
@@ -55,16 +63,16 @@
DECSM Set DEC mode ^[ [ ? h 0
DECSTBM Set top and bottom margins ^[ [ r 0 0
DECSWL Single Height Single Width Line ^[ # 5
-DL Delete line ^[ [ M 1
+DL Delete line ^[ [ M n
DSR Device Status Report ^[ [ ? n 0
-ECH Erase character ^[ [ X 1
+ECH Erase character ^[ [ X n
ED Erase display ^[ [ J 0
EL Erase line ^[ [ K 0
HPA Horizontal Position Absolute ^[ [ G 1
HPA Horizontal Position Absolute ^[ [ ` 1
HTS Horizontal Tab Set ^[ H
-ICH Insert character ^[ [ @ 1
-IL Insert line ^[ [ L 1
+ICH Insert character ^[ [ @ n
+IL Insert line ^[ [ L n
IND Index ^[ D
NEL Next line ^[ E
RI Reverse index ^[ M
@@ -80,11 +88,11 @@
SCS SCS ^[ ) 2
SCS SCS ^[ ) A
SCS SCS ^[ ) B
-SD Pan Up ^[ [ T 1
+SD Pan Up ^[ [ T n
SGR Set Graphic Rendition ^[ [ m variable
SM Set Mode ^[ [ h 0
ST String Terminator ^[ \\
-SU Pan Down ^[ [ S 1
+SU Pan Down ^[ [ S n
TBC Tab Clear ^[ [ g 0
VPA Vertical Position Absolute ^[ [ d 1
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/teken.c#7 (text+ko) ====
@@ -74,12 +74,6 @@
static teken_state_t teken_state_init;
-static const teken_attr_t teken_defattr = {
- .ta_format = 0,
- .ta_fgcolor = TC_WHITE,
- .ta_bgcolor = TC_BLACK,
-};
-
/*
* Wrappers for hooks.
*/
@@ -194,13 +188,16 @@
t->t_nextstate = teken_state_init;
+ t->t_defattr.ta_format = 0;
+ t->t_defattr.ta_fgcolor = TC_WHITE;
+ t->t_defattr.ta_bgcolor = TC_BLACK;
teken_subr_do_reset(t);
#ifdef TEKEN_UTF8
t->t_utf8_left = 0;
#endif /* TEKEN_UTF8 */
- teken_winsize(t, &tp);
+ teken_set_winsize(t, &tp);
}
static void
@@ -241,8 +238,11 @@
teken_assert(t->t_saved_cursor.tp_col < t->t_winsize.tp_col);
teken_assert(t->t_scrollreg.ts_end <= t->t_winsize.tp_row);
teken_assert(t->t_scrollreg.ts_begin < t->t_scrollreg.ts_end);
- teken_assert(t->t_originreg.ts_end <= t->t_winsize.tp_row);
- teken_assert(t->t_originreg.ts_begin < t->t_originreg.ts_end);
+ /* Origin region has to be window size or the same as scrollreg. */
+ teken_assert((t->t_originreg.ts_begin == t->t_scrollreg.ts_begin &&
+ t->t_originreg.ts_end == t->t_scrollreg.ts_end) ||
+ (t->t_originreg.ts_begin == 0 &&
+ t->t_originreg.ts_end == t->t_winsize.tp_row));
}
static void
@@ -294,23 +294,34 @@
}
void
-teken_winsize(teken_t *t, const teken_pos_t *p)
+teken_set_cursor(teken_t *t, const teken_pos_t *p)
+{
+
+ /* XXX: bounds checking with originreg! */
+ teken_assert(p->tp_row < t->t_winsize.tp_row);
+ teken_assert(p->tp_col < t->t_winsize.tp_col);
+
+ t->t_cursor = *p;
+}
+
+void
+teken_set_defattr(teken_t *t, const teken_attr_t *a)
+{
+
+ t->t_curattr = t->t_saved_curattr = t->t_defattr = *a;
+}
+
+void
+teken_set_winsize(teken_t *t, const teken_pos_t *p)
{
- teken_rect_t tr;
teken_assert(p->tp_col <= T_NUMCOL);
t->t_winsize = *p;
- /* XXX: discards active scroll region. */
+ /* XXX: bounds checking with cursor/etc! */
t->t_scrollreg.ts_begin = 0;
t->t_scrollreg.ts_end = t->t_winsize.tp_row;
t->t_originreg = t->t_scrollreg;
-
- /* Blank screen. */
- tr.tr_begin.tp_row = 0;
- tr.tr_begin.tp_col = 0;
- tr.tr_end = t->t_winsize;
- teken_funcs_fill(t, &tr, BLANK, &teken_defattr);
}
/*
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/teken.h#10 (text+ko) ====
@@ -61,6 +61,7 @@
#define TC_MAGENTA 5
#define TC_CYAN 6
#define TC_WHITE 7
+#define TC_NCOLORS 8
typedef struct {
teken_unit_t tp_row;
@@ -117,6 +118,7 @@
/*
* Terminal state.
*/
+
struct __teken {
const teken_funcs_t *t_funcs;
void *t_softc;
@@ -133,6 +135,7 @@
teken_pos_t t_saved_cursor;
teken_attr_t t_saved_curattr;
+ teken_attr_t t_defattr;
teken_pos_t t_winsize;
/* For DECSTBM. */
@@ -149,8 +152,15 @@
#endif /* TEKEN_UTF8 */
};
+/* Initialize teken structure. */
void teken_init(teken_t *, const teken_funcs_t *, void *);
+
+/* Deliver character input. */
void teken_input(teken_t *, const void *, size_t);
-void teken_winsize(teken_t *, const teken_pos_t *);
+
+/* Set teken attributes. */
+void teken_set_cursor(teken_t *, const teken_pos_t *);
+void teken_set_defattr(teken_t *, const teken_attr_t *);
+void teken_set_winsize(teken_t *, const teken_pos_t *);
#endif /* !_TEKEN_H_ */
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/teken_subr.h#12 (text+ko) ====
@@ -183,7 +183,7 @@
tr.tr_begin.tp_row = 0;
tr.tr_begin.tp_col = 0;
tr.tr_end = t->t_winsize;
- teken_funcs_fill(t, &tr, 'E', &teken_defattr);
+ teken_funcs_fill(t, &tr, 'E', &t->t_defattr);
}
static void
@@ -219,8 +219,6 @@
teken_subr_cursor_backward(teken_t *t, unsigned int ncols)
{
- if (ncols == 0)
- ncols = 1;
if (ncols > t->t_cursor.tp_col)
t->t_cursor.tp_col = 0;
else
@@ -233,9 +231,6 @@
teken_subr_cursor_backward_tabulation(teken_t *t, unsigned int ntabs)
{
- if (ntabs == 0)
- ntabs = 1;
-
do {
/* Stop when we've reached the beginning of the line. */
if (t->t_cursor.tp_col == 0)
@@ -253,9 +248,6 @@
teken_subr_cursor_down(teken_t *t, unsigned int nrows)
{
- if (nrows == 0)
- nrows = 1;
-
teken_assert(t->t_cursor.tp_row < t->t_scrollreg.ts_end);
if (nrows >= t->t_scrollreg.ts_end - t->t_cursor.tp_row)
t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1;
@@ -269,8 +261,6 @@
teken_subr_cursor_forward(teken_t *t, unsigned int ncols)
{
- if (ncols == 0)
- ncols = 1;
if (ncols >= t->t_winsize.tp_col - t->t_cursor.tp_col)
t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
else
@@ -283,9 +273,6 @@
teken_subr_cursor_forward_tabulation(teken_t *t, unsigned int ntabs)
{
- if (ntabs == 0)
- ntabs = 1;
-
do {
/* Stop when we've reached the end of the line. */
if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1)
@@ -343,9 +330,6 @@
teken_subr_cursor_up(teken_t *t, unsigned int nrows)
{
- if (nrows == 0)
- nrows = 1;
-
if (nrows > ((int)t->t_cursor.tp_row - t->t_scrollreg.ts_begin))
t->t_cursor.tp_row = t->t_scrollreg.ts_begin;
else
@@ -359,9 +343,6 @@
{
teken_rect_t tr;
- if (ncols == 0)
- ncols = 1;
-
tr.tr_begin.tp_row = t->t_cursor.tp_row;
tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
tr.tr_end.tp_col = t->t_winsize.tp_col;
@@ -385,9 +366,6 @@
{
teken_rect_t tr;
- if (nrows == 0)
- nrows = 1;
-
tr.tr_begin.tp_col = 0;
tr.tr_end.tp_row = t->t_scrollreg.ts_end;
tr.tr_end.tp_col = t->t_winsize.tp_col;
@@ -445,9 +423,6 @@
{
teken_rect_t tr;
- if (ncols == 0)
- ncols = 1;
-
tr.tr_begin = t->t_cursor;
tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
@@ -572,9 +547,6 @@
{
teken_rect_t tr;
- if (ncols == 0)
- ncols = 1;
-
tr.tr_begin = t->t_cursor;
tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
@@ -601,9 +573,6 @@
{
teken_rect_t tr;
- if (nrows == 0)
- nrows = 1;
-
tr.tr_begin.tp_row = t->t_cursor.tp_row;
tr.tr_begin.tp_col = 0;
tr.tr_end.tp_col = t->t_winsize.tp_col;
@@ -672,10 +641,6 @@
teken_subr_pan_down(teken_t *t, unsigned int nrows)
{
- if (nrows == 0)
- nrows = 1;
-
-
teken_subr_do_scroll(t, (int)nrows);
}
@@ -683,9 +648,6 @@
teken_subr_pan_up(teken_t *t, unsigned int nrows)
{
- if (nrows == 0)
- nrows = 1;
-
teken_subr_do_scroll(t, -(int)nrows);
}
@@ -837,7 +799,7 @@
teken_subr_do_reset(teken_t *t)
{
- t->t_curattr = t->t_saved_curattr = teken_defattr;
+ t->t_curattr = t->t_saved_curattr = t->t_defattr;
t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
t->t_saved_cursor = t->t_cursor;
t->t_stateflags = TS_AUTOWRAP;
@@ -975,7 +937,7 @@
/* No attributes means reset. */
if (ncmds == 0) {
- t->t_curattr = teken_defattr;
+ t->t_curattr = t->t_defattr;
return;
}
@@ -984,7 +946,7 @@
switch (n) {
case 0: /* Reset. */
- t->t_curattr = teken_defattr;
+ t->t_curattr = t->t_defattr;
break;
case 1: /* Bold. */
t->t_curattr.ta_format |= TF_BOLD;
@@ -1021,7 +983,7 @@
t->t_curattr.ta_fgcolor = n - 30;
break;
case 39: /* Set default foreground color. */
- t->t_curattr.ta_fgcolor = teken_defattr.ta_fgcolor;
+ t->t_curattr.ta_fgcolor = t->t_defattr.ta_fgcolor;
break;
case 40: /* Set background color: black */
case 41: /* Set background color: red */
@@ -1034,7 +996,7 @@
t->t_curattr.ta_bgcolor = n - 40;
break;
case 49: /* Set default background color. */
- t->t_curattr.ta_bgcolor = teken_defattr.ta_bgcolor;
+ t->t_curattr.ta_bgcolor = t->t_defattr.ta_bgcolor;
break;
default:
teken_printf("unsupported attribute %u\n", n);
More information about the p4-projects
mailing list