svn commit: r186681 - in head/sys: conf dev/syscons dev/syscons/teken pc98/cbus

Ed Schouten ed at FreeBSD.org
Thu Jan 1 05:26:55 PST 2009


Author: ed
Date: Thu Jan  1 13:26:53 2009
New Revision: 186681
URL: http://svn.freebsd.org/changeset/base/186681

Log:
  Replace syscons terminal renderer by a new renderer that uses libteken.
  
  Some time ago I started working on a library called libteken, which is
  terminal emulator. It does not buffer any screen contents, but only
  keeps terminal state, such as cursor position, attributes, etc. It
  should implement all escape sequences that are implemented by the
  cons25 terminal emulator, but also a fair amount of sequences that are
  present in VT100 and xterm.
  
  A lot of random notes, which could be of interest to users/developers:
  
  - Even though I'm leaving the terminal type set to `cons25', users can
    do experiments with placing `xterm-color' in /etc/ttys. Because we
    only implement a subset of features of xterm, this may cause
    artifacts. We should consider extending libteken, because in my
    opinion xterm is the way to go. Some missing features:
  
    - Keypad application mode (DECKPAM)
    - Character sets (SCS)
  
  - libteken is filled with a fair amount of assertions, but unfortunately
    we cannot go into the debugger anymore if we fail them. I've done
    development of this library almost entirely in userspace. In
    sys/dev/syscons/teken there are two applications that can be helpful
    when debugging the code:
  
    - teken_demo: a terminal emulator that can be started from a regular
      xterm that emulates a terminal using libteken. This application can
      be very useful to debug any rendering issues.
  
    - teken_stress: a stress testing application that emulates random
      terminal output. libteken has literally survived multiple terabytes
      of random input.
  
  - libteken also includes support for UTF-8, but unfortunately our input
    layer and font renderer don't support this. If users want to
    experiment with UTF-8 support, they can enable `TEKEN_UTF8' in
    teken.h. If you recompile your kernel or the teken_demo application,
    you can hold some nice experiments.
  
  - I've left PC98 the way it is right now. The PC98 platform has a custom
    syscons renderer, which supports some form of localised input. Maybe
    we should port PC98 to libteken by the time syscons supports UTF-8?
  
  - I've removed the `dumb' terminal emulator. It has been broken for
    years. It hasn't survived the `struct proc' -> `struct thread'
    conversion.
  
  - To prevent confusion among people that want to hack on libteken:
    unlike syscons, the state machines that parse the escape sequences are
    machine generated. This means that if you want to add new escape
    sequences, you have to add an entry to the `sequences' file. This will
    cause new entries to be added to `teken_state.h'.
  
  - Any rendering artifacts that didn't occur prior to this commit are by
    accident. They should be reported to me, so I can fix them.
  
  Discussed on:	current@, hackers@
  Discussed with:	philip (at 25C3)

Added:
  head/sys/dev/syscons/scterm-teken.c   (contents, props changed)
  head/sys/dev/syscons/teken/
  head/sys/dev/syscons/teken/Makefile   (contents, props changed)
  head/sys/dev/syscons/teken/gensequences   (contents, props changed)
  head/sys/dev/syscons/teken/sequences   (contents, props changed)
  head/sys/dev/syscons/teken/teken.c   (contents, props changed)
  head/sys/dev/syscons/teken/teken.h   (contents, props changed)
  head/sys/dev/syscons/teken/teken_demo.c   (contents, props changed)
  head/sys/dev/syscons/teken/teken_stress.c   (contents, props changed)
  head/sys/dev/syscons/teken/teken_subr.h   (contents, props changed)
  head/sys/dev/syscons/teken/teken_subr_compat.h   (contents, props changed)
  head/sys/dev/syscons/teken/teken_wcwidth.h   (contents, props changed)
  head/sys/pc98/cbus/sctermvar.h
     - copied unchanged from r186677, head/sys/dev/syscons/sctermvar.h
Deleted:
  head/sys/dev/syscons/scterm-dumb.c
  head/sys/dev/syscons/scterm-sc.c
  head/sys/dev/syscons/sctermvar.h
Modified:
  head/sys/conf/files
  head/sys/conf/files.amd64
  head/sys/conf/files.i386
  head/sys/conf/files.ia64
  head/sys/conf/files.powerpc
  head/sys/conf/files.sparc64
  head/sys/dev/syscons/scterm.c
  head/sys/dev/syscons/syscons.c
  head/sys/dev/syscons/syscons.h
  head/sys/pc98/cbus/scterm-sck.c

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/conf/files	Thu Jan  1 13:26:53 2009	(r186681)
@@ -75,6 +75,11 @@ pccarddevs.h			standard				   \
 	compile-with	"${AWK} -f $S/tools/pccarddevs2h.awk $S/dev/pccard/pccarddevs" \
 	no-obj no-implicit-rule before-depend				   \
 	clean		"pccarddevs.h"
+teken_state.h		optional sc					   \
+	dependency	"$S/dev/syscons/teken/gensequences $S/dev/syscons/teken/sequences" \
+	compile-with	"${AWK} -f $S/dev/syscons/teken/gensequences $S/dev/syscons/teken/sequences > teken_state.h" \
+	no-obj no-implicit-rule before-depend				   \
+	clean		"teken_state.h"
 usbdevs.h			optional usb				   \
 	dependency	"$S/tools/usbdevs2h.awk $S/dev/usb/usbdevs" \
 	compile-with	"${AWK} -f $S/tools/usbdevs2h.awk $S/dev/usb/usbdevs -h" \
@@ -1424,7 +1429,6 @@ dev/syscons/logo/logo_saver.c	optional l
 dev/syscons/rain/rain_saver.c	optional rain_saver
 dev/syscons/schistory.c		optional sc
 dev/syscons/scmouse.c		optional sc
-dev/syscons/scterm-dumb.c	optional sc
 dev/syscons/scterm.c		optional sc
 dev/syscons/scvidctl.c		optional sc
 dev/syscons/snake/snake_saver.c	optional snake_saver

Modified: head/sys/conf/files.amd64
==============================================================================
--- head/sys/conf/files.amd64	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/conf/files.amd64	Thu Jan  1 13:26:53 2009	(r186681)
@@ -196,9 +196,10 @@ dev/sio/sio_pci.c		optional	sio pci
 dev/sio/sio_puc.c		optional	sio puc
 dev/speaker/spkr.c		optional	speaker
 dev/syscons/apm/apm_saver.c	optional	apm_saver apm
-dev/syscons/scterm-sc.c		optional	sc
+dev/syscons/scterm-teken.c	optional	sc
 dev/syscons/scvgarndr.c		optional	sc vga
 dev/syscons/scvtb.c		optional	sc
+dev/syscons/teken/teken.c	optional sc
 dev/uart/uart_cpu_amd64.c	optional	uart
 dev/wpi/if_wpi.c		optional	wpi
 isa/atrtc.c			standard

Modified: head/sys/conf/files.i386
==============================================================================
--- head/sys/conf/files.i386	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/conf/files.i386	Thu Jan  1 13:26:53 2009	(r186681)
@@ -220,10 +220,11 @@ dev/sio/sio_puc.c		optional sio puc
 dev/speaker/spkr.c		optional speaker
 dev/sr/if_sr_isa.c		optional sr isa
 dev/syscons/apm/apm_saver.c	optional apm_saver apm
-dev/syscons/scterm-sc.c		optional sc
+dev/syscons/scterm-teken.c	optional sc
 dev/syscons/scvesactl.c		optional sc vga vesa
 dev/syscons/scvgarndr.c		optional sc vga
 dev/syscons/scvtb.c		optional sc
+dev/syscons/teken/teken.c	optional sc
 dev/uart/uart_cpu_i386.c	optional uart
 dev/acpica/acpi_if.m		standard
 dev/wpi/if_wpi.c		optional wpi

Modified: head/sys/conf/files.ia64
==============================================================================
--- head/sys/conf/files.ia64	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/conf/files.ia64	Thu Jan  1 13:26:53 2009	(r186681)
@@ -57,9 +57,10 @@ dev/fb/fb.c			optional	fb | vga
 dev/fb/vga.c			optional	vga
 dev/hwpmc/hwpmc_ia64.c		optional	hwpmc
 dev/kbd/kbd.c			optional	atkbd | sc | ukbd
-dev/syscons/scterm-sc.c		optional	sc
+dev/syscons/scterm-teken.c	optional	sc
 dev/syscons/scvgarndr.c		optional	sc vga
 dev/syscons/scvtb.c		optional	sc
+dev/syscons/teken/teken.c	optional sc
 dev/uart/uart_cpu_ia64.c	optional	uart
 dev/acpica/acpi_if.m		standard
 ia64/acpica/OsdEnvironment.c	optional	acpi

Modified: head/sys/conf/files.powerpc
==============================================================================
--- head/sys/conf/files.powerpc	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/conf/files.powerpc	Thu Jan  1 13:26:53 2009	(r186681)
@@ -39,8 +39,9 @@ dev/powermac_nvram/powermac_nvram.c opti
 dev/quicc/quicc_bfe_ocp.c	optional	quicc mpc85xx
 dev/scc/scc_bfe_macio.c		optional	scc powermac
 dev/syscons/scgfbrndr.c		optional	sc
-dev/syscons/scterm-sc.c		optional	sc
+dev/syscons/scterm-teken.c	optional	sc
 dev/syscons/scvtb.c		optional	sc
+dev/syscons/teken/teken.c	optional sc
 dev/tsec/if_tsec.c		optional	tsec
 dev/tsec/if_tsec_ocp.c		optional	tsec mpc85xx
 dev/uart/uart_bus_ocp.c		optional	uart mpc85xx

Modified: head/sys/conf/files.sparc64
==============================================================================
--- head/sys/conf/files.sparc64	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/conf/files.sparc64	Thu Jan  1 13:26:53 2009	(r186681)
@@ -55,8 +55,9 @@ dev/pcf/pcf_ebus.c		optional	pcf ebus
 dev/sound/sbus/cs4231.c		optional	snd_audiocs ebus | \
 						snd_audiocs sbus
 dev/syscons/scgfbrndr.c		optional	sc
-dev/syscons/scterm-sc.c		optional	sc
+dev/syscons/scterm-teken.c	optional	sc
 dev/syscons/scvtb.c		optional	sc
+dev/syscons/teken/teken.c	optional sc
 dev/uart/uart_cpu_sparc64.c	optional	uart
 dev/uart/uart_kbd_sun.c		optional	uart sc
 kern/syscalls.c			optional	ktr

Added: head/sys/dev/syscons/scterm-teken.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/syscons/scterm-teken.c	Thu Jan  1 13:26:53 2009	(r186681)
@@ -0,0 +1,504 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota at zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer as
+ *    the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/consio.h>
+
+#if defined(__sparc64__) || defined(__powerpc__)
+#include <machine/sc_machdep.h>
+#else
+#include <machine/pc/display.h>
+#endif
+
+#include <dev/syscons/syscons.h>
+
+#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);
+
+typedef struct {
+	teken_t		ts_teken;
+	int		ts_busy;
+} teken_stat;
+
+static teken_stat	reserved_teken_stat;
+
+static sc_term_sw_t sc_term_scteken = {
+	{ NULL, NULL },
+	"scteken",			/* emulator name */
+	"teken terminal",		/* description */
+	"*",				/* matching renderer */
+	sizeof(teken_stat),		/* softc size */
+	0,
+	scteken_init,
+	scteken_term,
+	scteken_puts,
+	scteken_ioctl,
+	(sc_term_reset_t *)scteken_nop,
+	scteken_default_attr,
+	scteken_clear,
+	(sc_term_notify_t *)scteken_nop,
+	scteken_input,
+};
+
+SCTERM_MODULE(scteken, sc_term_scteken);
+
+static tf_bell_t	scteken_bell;
+static tf_cursor_t	scteken_cursor;
+static tf_putchar_t	scteken_putchar;
+static tf_fill_t	scteken_fill;
+static tf_copy_t	scteken_copy;
+static tf_param_t	scteken_param;
+static tf_respond_t	scteken_respond;
+
+static const teken_funcs_t scteken_funcs = {
+	.tf_bell	= scteken_bell,
+	.tf_cursor	= scteken_cursor,
+	.tf_putchar	= scteken_putchar,
+	.tf_fill	= scteken_fill,
+	.tf_copy	= scteken_copy,
+	.tf_param	= scteken_param,
+	.tf_respond	= scteken_respond,
+};
+
+static int
+scteken_init(scr_stat *scp, void **softc, int code)
+{
+	teken_stat *ts = scp->ts;
+	teken_pos_t tp;
+
+	if (*softc == NULL) {
+		if (reserved_teken_stat.ts_busy)
+			return (EINVAL);
+		*softc = &reserved_teken_stat;
+	}
+	ts = *softc;
+
+	switch (code) {
+	case SC_TE_COLD_INIT:
+		++sc_term_scteken.te_refcount;
+		ts->ts_busy = 1;
+		/* FALLTHROUGH */
+	case SC_TE_WARM_INIT:
+		teken_init(&ts->ts_teken, &scteken_funcs, scp);
+
+		tp.tp_row = scp->ysize;
+		tp.tp_col = scp->xsize;
+		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;
+	}
+
+	return (0);
+}
+
+static int
+scteken_term(scr_stat *scp, void **softc)
+{
+
+	if (*softc == &reserved_teken_stat) {
+		*softc = NULL;
+		reserved_teken_stat.ts_busy = 0;
+	}
+	--sc_term_scteken.te_refcount;
+
+	return (0);
+}
+
+static void
+scteken_puts(scr_stat *scp, u_char *buf, int len)
+{
+	teken_stat *ts = scp->ts;
+
+	scp->sc->write_in_progress++;
+	teken_input(&ts->ts_teken, buf, len);
+	scp->sc->write_in_progress--;
+}
+
+static int
+scteken_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
+	     struct thread *td)
+{
+	vid_info_t *vi;
+
+	switch (cmd) {
+	case GIO_ATTR:      	/* get current attributes */
+		*(int*)data = SC_NORM_ATTR;
+		return (0);
+	case CONS_GETINFO:  	/* get current (virtual) console info */
+		/* XXX: INCORRECT! */
+		vi = (vid_info_t *)data;
+		if (vi->size != sizeof(struct vid_info))
+			return EINVAL;
+		vi->mv_norm.fore = SC_NORM_ATTR & 0x0f;
+		vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f;
+		vi->mv_rev.fore = SC_NORM_ATTR & 0x0f;
+		vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f;
+		/*
+		 * The other fields are filled by the upper routine. XXX
+		 */
+		return (ENOIOCTL);
+	}
+
+	return (ENOIOCTL);
+}
+
+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)
+{
+
+	sc_move_cursor(scp, 0, 0);
+	sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
+	mark_all(scp);
+}
+
+static int
+scteken_input(scr_stat *scp, int c, struct tty *tp)
+{
+
+	return FALSE;
+}
+
+static void
+scteken_nop(void)
+{
+
+}
+
+/*
+ * libteken routines.
+ */
+
+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[TC_NCOLORS] = {
+	FG_DARKGREY,  FG_LIGHTRED,     FG_LIGHTGREEN, FG_YELLOW,
+	FG_LIGHTBLUE, FG_LIGHTMAGENTA, FG_LIGHTCYAN,  FG_WHITE,
+};
+
+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)
+{
+	unsigned int attr = 0;
+
+	if (a->ta_format & TF_BOLD)
+		attr |= fgcolors_bold[a->ta_fgcolor];
+	else
+		attr |= fgcolors_normal[a->ta_fgcolor];
+	attr |= bgcolors[a->ta_bgcolor];
+
+#ifdef FG_UNDERLINE
+	if (a->ta_format & TF_UNDERLINE)
+		attr |= FG_UNDERLINE;
+#endif /* FG_UNDERLINE */
+#ifdef FG_BLINK
+	if (a->ta_format & TF_BLINK)
+		attr |= FG_BLINK;
+#endif /* FG_BLINK */
+
+	return (attr << 8);
+}
+
+static void
+scteken_bell(void *arg)
+{
+	scr_stat *scp = arg;
+
+	sc_bell(scp, scp->bell_pitch, scp->bell_duration);
+}
+
+static void
+scteken_cursor(void *arg, const teken_pos_t *p)
+{
+	scr_stat *scp = arg;
+
+	sc_move_cursor(scp, p->tp_col, p->tp_row);
+}
+
+static void
+scteken_putchar(void *arg, const teken_pos_t *tp, teken_char_t c,
+    const teken_attr_t *a)
+{
+	scr_stat *scp = arg;
+	u_char *map;
+	u_char ch;
+	vm_offset_t p;
+	int cursor, attr;
+
+#ifdef TEKEN_UTF8
+	if (c >= 0x80) {
+		/* XXX: Don't display UTF-8 yet. */
+		attr = (FG_YELLOW|BG_RED) << 8;
+		ch = '?';
+	} else
+#endif /* TEKEN_UTF8 */
+	{
+		attr = scteken_attr(a);
+		ch = c;
+	}
+
+	map = scp->sc->scr_map;
+
+	cursor = tp->tp_row * scp->xsize + tp->tp_col;
+	p = sc_vtb_pointer(&scp->vtb, cursor);
+	sc_vtb_putchar(&scp->vtb, p, map[ch], attr);
+
+	mark_for_update(scp, cursor);
+	/*
+	 * XXX: Why do we need this? Only marking `cursor' should be
+	 * enough. Without this line, we get artifacts.
+	 */
+	mark_for_update(scp, imin(cursor + 1, scp->xsize * scp->ysize - 1));
+}
+
+static void
+scteken_fill(void *arg, const teken_rect_t *r, teken_char_t c,
+    const teken_attr_t *a)
+{
+	scr_stat *scp = arg;
+	u_char *map;
+	u_char ch;
+	unsigned int width;
+	int attr, row;
+
+#ifdef TEKEN_UTF8
+	if (c >= 0x80) {
+		/* XXX: Don't display UTF-8 yet. */
+		attr = (FG_YELLOW|BG_RED) << 8;
+		ch = '?';
+	} else
+#endif /* TEKEN_UTF8 */
+	{
+		attr = scteken_attr(a);
+		ch = c;
+	}
+
+	map = scp->sc->scr_map;
+
+	if (r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize) {
+		/* Single contiguous region to fill. */
+		sc_vtb_erase(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
+		    (r->tr_end.tp_row - r->tr_begin.tp_row) * scp->xsize,
+		    map[ch], attr);
+	} else {
+		/* Fill display line by line. */
+		width = r->tr_end.tp_col - r->tr_begin.tp_col;
+
+		for (row = r->tr_begin.tp_row; row < r->tr_end.tp_row; row++) {
+			sc_vtb_erase(&scp->vtb, r->tr_begin.tp_row *
+			    scp->xsize + r->tr_begin.tp_col,
+			    width, map[ch], attr);
+		}
+	}
+
+	/* Mark begin and end positions to be refreshed. */
+	mark_for_update(scp,
+	    r->tr_begin.tp_row * scp->xsize + r->tr_begin.tp_col);
+	mark_for_update(scp,
+	    (r->tr_end.tp_row - 1) * scp->xsize + (r->tr_end.tp_col - 1));
+	sc_remove_cutmarking(scp);
+}
+
+static void
+scteken_copy(void *arg, const teken_rect_t *r, const teken_pos_t *p)
+{
+	scr_stat *scp = arg;
+	unsigned int width;
+	int src, dst, end;
+
+#ifndef SC_NO_HISTORY
+	/*
+	 * We count a line of input as history if we perform a copy of
+	 * one whole line upward. In other words: if a line of text gets
+	 * overwritten by a rectangle that's right below it.
+	 */
+	if (scp->history != NULL &&
+	    r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize &&
+	    r->tr_begin.tp_row == p->tp_row + 1) {
+		sc_hist_save_one_line(scp, p->tp_row);
+	}
+#endif
+
+	if (r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize) {
+		/* Single contiguous region to copy. */
+		sc_vtb_move(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
+		    p->tp_row * scp->xsize,
+		    (r->tr_end.tp_row - r->tr_begin.tp_row) * scp->xsize);
+	} else {
+		/* Copy line by line. */
+		width = r->tr_end.tp_col - r->tr_begin.tp_col;
+
+		if (p->tp_row < r->tr_begin.tp_row) {
+			/* Copy from top to bottom. */
+			src = r->tr_begin.tp_row * scp->xsize +
+			    r->tr_begin.tp_col;
+			end = r->tr_end.tp_row * scp->xsize +
+			    r->tr_end.tp_col;
+			dst = p->tp_row * scp->xsize + p->tp_col;
+
+			while (src < end) {
+				sc_vtb_move(&scp->vtb, src, dst, width);
+			
+				src += scp->xsize;
+				dst += scp->xsize;
+			}
+		} else {
+			/* Copy from bottom to top. */
+			src = (r->tr_end.tp_row - 1) * scp->xsize +
+			    r->tr_begin.tp_col;
+			end = r->tr_begin.tp_row * scp->xsize +
+			    r->tr_begin.tp_col;
+			dst = (p->tp_row + r->tr_end.tp_row -
+			    r->tr_begin.tp_row - 1) * scp->xsize + p->tp_col;
+
+			while (src >= end) {
+				sc_vtb_move(&scp->vtb, src, dst, width);
+			
+				src -= scp->xsize;
+				dst -= scp->xsize;
+			}
+		}
+	}
+
+	/* Mark begin and end positions to be refreshed. */
+	mark_for_update(scp,
+	    p->tp_row * scp->xsize + p->tp_col);
+	mark_for_update(scp,
+	    (p->tp_row + r->tr_end.tp_row - r->tr_begin.tp_row - 1) *
+	    scp->xsize +
+	    (p->tp_col + r->tr_end.tp_col - r->tr_begin.tp_col - 1));
+	sc_remove_cutmarking(scp);
+}
+
+static void
+scteken_param(void *arg, int cmd, int value)
+{
+	scr_stat *scp = arg;
+
+	switch (cmd) {
+	case TP_SHOWCURSOR:
+		if (value) {
+			sc_change_cursor_shape(scp,
+			    CONS_RESET_CURSOR|CONS_LOCAL_CURSOR, -1, -1);
+		} else {
+			sc_change_cursor_shape(scp,
+			    CONS_HIDDEN_CURSOR|CONS_LOCAL_CURSOR, -1, -1);
+		}
+		break;
+	case TP_SWITCHVT:
+		sc_switch_scr(scp->sc, value);
+		break;
+	}
+}
+
+static void
+scteken_respond(void *arg, const void *buf, size_t len)
+{
+	scr_stat *scp = arg;
+
+	sc_respond(scp, buf, len);
+}

Modified: head/sys/dev/syscons/scterm.c
==============================================================================
--- head/sys/dev/syscons/scterm.c	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/dev/syscons/scterm.c	Thu Jan  1 13:26:53 2009	(r186681)
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/consio.h>
 
 #include <dev/syscons/syscons.h>
-#include <dev/syscons/sctermvar.h>
 
 SET_DECLARE(scterm_set, sc_term_sw_t);
 

Modified: head/sys/dev/syscons/syscons.c
==============================================================================
--- head/sys/dev/syscons/syscons.c	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/dev/syscons/syscons.c	Thu Jan  1 13:26:53 2009	(r186681)
@@ -2741,6 +2741,16 @@ scinit(int unit, int flags)
 	    init_scp(sc, sc->first_vty, scp);
 	    sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
 			(void *)sc_buffer, FALSE);
+
+	    /* move cursors to the initial positions */
+	    if (col >= scp->xsize)
+		col = 0;
+	    if (row >= scp->ysize)
+		row = scp->ysize - 1;
+	    scp->xpos = col;
+	    scp->ypos = row;
+	    scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
+
 	    if (sc_init_emulator(scp, SC_DFLT_TERM))
 		sc_init_emulator(scp, "*");
 	    (*scp->tsw->te_default_attr)(scp,
@@ -2764,15 +2774,6 @@ scinit(int unit, int flags)
 	    sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
 #endif
 
-	/* move cursors to the initial positions */
-	if (col >= scp->xsize)
-	    col = 0;
-	if (row >= scp->ysize)
-	    row = scp->ysize - 1;
-	scp->xpos = col;
-	scp->ypos = row;
-	scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
-
 	if (bios_value.cursor_end < scp->font_size)
 	    sc->dflt_curs_attr.base = scp->font_size - 
 					  bios_value.cursor_end - 1;
@@ -3569,7 +3570,7 @@ sc_show_font(scr_stat *scp, int page)
 #endif /* !SC_NO_FONT_LOADING */
 
 void
-sc_paste(scr_stat *scp, u_char *p, int count) 
+sc_paste(scr_stat *scp, const u_char *p, int count) 
 {
     struct tty *tp;
     u_char *rmap;
@@ -3584,6 +3585,22 @@ sc_paste(scr_stat *scp, u_char *p, int c
 }
 
 void
+sc_respond(scr_stat *scp, const u_char *p, int count) 
+{
+    struct tty *tp;
+
+    tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
+    if (!tty_opened(tp))
+	return;
+    for (; count > 0; --count)
+	ttydisc_rint(tp, *p++, 0);
+#if 0
+    /* XXX: we can't call ttydisc_rint_done() here! */
+    ttydisc_rint_done(tp);
+#endif
+}
+
+void
 sc_bell(scr_stat *scp, int pitch, int duration)
 {
     if (cold || shutdown_in_progress || !enable_bell)

Modified: head/sys/dev/syscons/syscons.h
==============================================================================
--- head/sys/dev/syscons/syscons.h	Thu Jan  1 12:14:39 2009	(r186680)
+++ head/sys/dev/syscons/syscons.h	Thu Jan  1 13:26:53 2009	(r186681)
@@ -563,7 +563,8 @@ int		sc_clean_up(scr_stat *scp);
 int		sc_switch_scr(sc_softc_t *sc, u_int next_scr);
 void		sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
 int		sc_init_emulator(scr_stat *scp, char *name);
-void		sc_paste(scr_stat *scp, u_char *p, int count);
+void		sc_paste(scr_stat *scp, const u_char *p, int count);
+void		sc_respond(scr_stat *scp, const u_char *p, int count);
 void		sc_bell(scr_stat *scp, int pitch, int duration);
 
 /* schistory.c */

Added: head/sys/dev/syscons/teken/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/syscons/teken/Makefile	Thu Jan  1 13:26:53 2009	(r186681)
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+PROG=		teken_demo
+SRCS=		teken_demo.c teken.c teken_state.h
+CLEANFILES=	teken_state.h teken.log
+LDADD=		-lncurses -lutil
+NO_MAN=
+WARNS?=		6
+
+teken_state.h: gensequences sequences
+	awk -f gensequences sequences > ${.TARGET}
+
+.include <bsd.prog.mk>

Added: head/sys/dev/syscons/teken/gensequences
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/syscons/teken/gensequences	Thu Jan  1 13:26:53 2009	(r186681)
@@ -0,0 +1,157 @@
+#!/usr/bin/awk -f
+
+#-
+# Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
+# All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+function die(msg) {
+	print msg;
+	exit 1;
+}
+
+function cchar(str) {
+	if (str == "^[")
+		return "\\x1B";
+
+	return str;
+}
+
+BEGIN {
+FS = "\t+"
+
+while (getline > 0) {
+	if (NF == 0 || $1 ~ /^#/)
+		continue;
+
+	if (NF != 3 && NF != 4)
+		die("Invalid line layout: " NF " columns");
+
+	split($3, sequence, " +");
+	nsequences = 0;
+	for (s in sequence)
+		nsequences++;
+
+	prefix = "";
+	l_prefix_name[""] = "teken_state_init";
+	for (i = 1; i < nsequences; i++) {
+		n = prefix sequence[i];
+		l_prefix_parent[n] = prefix;
+		l_prefix_suffix[n] = sequence[i];
+		if (!l_prefix_name[n])
+			l_prefix_name[n] = "teken_state_" ++npr;
+		prefix = n;
+	}
+
+	suffix = sequence[nsequences];
+	cmd = prefix suffix;
+
+	# Fill lists
+	if (l_cmd_name[cmd] != "")
+		die(cmd " already exists");
+	l_cmd_prefix[cmd] = prefix;
+	l_cmd_suffix[cmd] = suffix;
+	l_cmd_args[cmd] = $4;
+	l_cmd_abbr[cmd] = $1;
+	l_cmd_name[cmd] = $2;
+	l_cmd_c_name[cmd] = "teken_subr_" tolower($2);
+	gsub(" ", "_", l_cmd_c_name[cmd]);
+
+	if ($4 != "")
+		l_prefix_numbercmds[prefix]++;
+}
+
+print "/* Generated file. Do not edit. */";
+print "";
+
+for (p in l_prefix_name) {
+	if (l_prefix_name[p] != "teken_state_init")
+		print "static teken_state_t	" l_prefix_name[p] ";";
+}
+
+for (p in l_prefix_name) {
+	print "";
+	print "/* '" p "' */";
+	print "static void";
+	print l_prefix_name[p] "(teken_t *t, teken_char_t c)";
+	print "{";
+
+	if (l_prefix_numbercmds[p] > 0) {
+		print "";
+		print "\tif (teken_state_numbers(t, c))";
+		print "\t\treturn;";
+	}
+
+	print "";
+	print "\tswitch (c) {";
+	for (c in l_cmd_prefix) {
+		if (l_cmd_prefix[c] != p)
+			continue;
+
+		print "\tcase '" cchar(l_cmd_suffix[c]) "': /* " l_cmd_abbr[c] ": " l_cmd_name[c] " */";
+
+		if (l_cmd_args[c] == "v") {
+			print "\t\t" l_cmd_c_name[c] "(t, t->t_curnum, t->t_nums);";
+		} else {
+			printf "\t\t%s(t", l_cmd_c_name[c];
+			split(l_cmd_args[c], args, " ");
+			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 if (args[a] == "r")
+					printf ", t->t_curnum < %d ? 0 : t->t_nums[%d]", a, (a - 1);
+				else
+					die("Invalid argument type: " args[a]);
+			}
+			print ");";
+		}
+		print "\t\tbreak;";
+	}
+	for (pc in l_prefix_parent) {
+		if (l_prefix_parent[pc] != p)
+			continue;
+		print "\tcase '" cchar(l_prefix_suffix[pc]) "':";
+		print "\t\tteken_state_switch(t, " l_prefix_name[pc] ");";
+		print "\t\treturn;";
+	}
+
+	print "\tdefault:";
+	if (l_prefix_name[p] == "teken_state_init") {
+		print "\t\tteken_subr_regular_character(t, c);";
+	} else {
+		print "\t\tteken_printf(\"Unsupported sequence in " l_prefix_name[p] ": %u\\n\", (unsigned int)c);";
+	}
+	print "\t\tbreak;";
+
+	print "\t}";
+
+	if (l_prefix_name[p] != "teken_state_init") {
+		print "";
+		print "\tteken_state_switch(t, teken_state_init);";
+	}
+	print "}";
+}
+
+}

Added: head/sys/dev/syscons/teken/sequences
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/syscons/teken/sequences	Thu Jan  1 13:26:53 2009	(r186681)
@@ -0,0 +1,107 @@
+#-
+# Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+# 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
+#			- `n' non-zero number (0 gets converted to 1)
+#			- `r' regular numeric argument
+#			- `v' means a variable number of arguments
+
+# 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		r
+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		n n
+CUP	Cursor Position				^[ [ f		n n
+CUU	Cursor Up				^[ [ A		n
+DA1	Primary Device Attributes		^[ [ c		r
+DA2	Secondary Device Attributes		^[ [ > c	r
+DC	Delete character			^[ [ P		n
+DCS	Device Control String			^[ P
+DECALN	Alignment test				^[ # 8
+DECDHL	Double Height Double Width Line Top	^[ # 3
+DECDHL	Double Height Double Width Line Bottom	^[ # 4
+DECDWL	Single Height Double Width Line		^[ # 6
+DECKPAM	Keypad application mode			^[ =
+DECKPNM	Keypad numeric mode			^[ >
+DECRC	Restore cursor				^[ 8
+DECRC	Restore cursor				^[ [ u
+DECRM	Reset DEC mode				^[ [ ? l	r
+DECSC	Save cursor				^[ 7
+DECSC	Save cursor				^[ [ s
+DECSM	Set DEC mode				^[ [ ? h	r
+DECSTBM	Set top and bottom margins		^[ [ r		r r
+DECSWL	Single Height Single Width Line		^[ # 5
+DL	Delete line				^[ [ M		n
+DSR	Device Status Report			^[ [ ? n	r
+ECH	Erase character				^[ [ X		n
+ED	Erase display				^[ [ J		r
+EL	Erase line				^[ [ K		r
+HPA	Horizontal Position Absolute		^[ [ G		n
+HPA	Horizontal Position Absolute		^[ [ `		n
+HTS	Horizontal Tab Set			^[ H
+ICH	Insert character			^[ [ @		n
+IL	Insert line				^[ [ L		n
+IND	Index					^[ D
+NEL	Next line				^[ E
+RI	Reverse index				^[ M
+RIS	Reset to Initial State			^[ c
+RM	Reset Mode				^[ [ l		r
+SCS	SCS					^[ ( 0
+SCS	SCS					^[ ( 1
+SCS	SCS					^[ ( 2
+SCS	SCS					^[ ( A
+SCS	SCS					^[ ( B
+SCS	SCS					^[ ) 0
+SCS	SCS					^[ ) 1
+SCS	SCS					^[ ) 2
+SCS	SCS					^[ ) A
+SCS	SCS					^[ ) B
+SD	Pan Up					^[ [ T		n
+SGR	Set Graphic Rendition			^[ [ m		v
+SM	Set Mode				^[ [ h		r
+ST	String Terminator			^[ \\
+SU	Pan Down				^[ [ S		n
+TBC	Tab Clear				^[ [ g		r
+VPA	Vertical Position Absolute		^[ [ d		n
+
+# Cons25 compatibility sequences
+C25CURS	Cons25 set cursor type			^[ [ = S	r
+C25VTSW	Cons25 switch virtual terminal		^[ [ z		r
+
+# VT52 compatibility
+#DECID	VT52 DECID				^[ Z

Added: head/sys/dev/syscons/teken/teken.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/syscons/teken/teken.c	Thu Jan  1 13:26:53 2009	(r186681)
@@ -0,0 +1,386 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list