[Midnightbsd-cvs] src [9901] trunk/sys/teken: sync with freebsd 10-stable

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Thu May 24 18:40:47 EDT 2018


Revision: 9901
          http://svnweb.midnightbsd.org/src/?rev=9901
Author:   laffer1
Date:     2018-05-24 18:40:46 -0400 (Thu, 24 May 2018)
Log Message:
-----------
sync with freebsd 10-stable

Modified Paths:
--------------
    trunk/sys/teken/demo/Makefile
    trunk/sys/teken/demo/teken_demo.c
    trunk/sys/teken/gensequences
    trunk/sys/teken/libteken/Makefile
    trunk/sys/teken/libteken/Symbol.map
    trunk/sys/teken/libteken/teken.3
    trunk/sys/teken/sequences
    trunk/sys/teken/stress/Makefile
    trunk/sys/teken/stress/teken_stress.c
    trunk/sys/teken/teken.c
    trunk/sys/teken/teken.h
    trunk/sys/teken/teken_scs.h
    trunk/sys/teken/teken_subr.h
    trunk/sys/teken/teken_subr_compat.h
    trunk/sys/teken/teken_wcwidth.h

Property Changed:
----------------
    trunk/sys/teken/gensequences
    trunk/sys/teken/libteken/Symbol.map
    trunk/sys/teken/libteken/teken.3
    trunk/sys/teken/sequences

Modified: trunk/sys/teken/demo/Makefile
===================================================================
--- trunk/sys/teken/demo/Makefile	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/demo/Makefile	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,7 +1,8 @@
-# $FreeBSD$
+# $MidnightBSD$
+# $FreeBSD: stable/10/sys/teken/demo/Makefile 226341 2011-10-13 14:20:27Z ed $
 
 PROG=	teken_demo
-LDADD=	-lncurses -lteken -lutil
+LDADD=	-lncursesw -lteken -lutil
 MAN=
 
 WARNS?=	6

Modified: trunk/sys/teken/demo/teken_demo.c
===================================================================
--- trunk/sys/teken/demo/teken_demo.c	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/demo/teken_demo.c	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/demo/teken_demo.c 262861 2014-03-06 18:30:56Z jhb $
  */
 
 #include <sys/ioctl.h>
@@ -86,9 +87,10 @@
 	assert(p->tp_row < NROWS);
 	assert(p->tp_col < NCOLS);
 
-	getyx(stdscr, y, x);
-
 	px = &buffer[p->tp_col][p->tp_row];
+	/* No need to print right hand side of CJK character manually. */
+	if (px->a.ta_format & TF_CJK_RIGHT)
+		return;
 
 	/* Convert Unicode to UTF-8. */
 	if (px->c < 0x80) {
@@ -118,8 +120,8 @@
 
 	bkgdset(attr | COLOR_PAIR(teken_256to8(px->a.ta_fgcolor) +
 	      8 * teken_256to8(px->a.ta_bgcolor)));
+	getyx(stdscr, y, x);
 	mvaddstr(p->tp_row, p->tp_col, str);
-
 	move(y, x);
 }
 

Modified: trunk/sys/teken/gensequences
===================================================================
--- trunk/sys/teken/gensequences	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/gensequences	2018-05-24 22:40:46 UTC (rev 9901)
@@ -25,7 +25,8 @@
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
-# $FreeBSD$
+# $FreeBSD: stable/10/sys/teken/gensequences 223574 2011-06-26 18:25:10Z ed $
+# $MidnightBSD$
 
 function die(msg) {
 	print msg;


Property changes on: trunk/sys/teken/gensequences
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/teken/libteken/Makefile
===================================================================
--- trunk/sys/teken/libteken/Makefile	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/libteken/Makefile	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,4 +1,5 @@
-# $FreeBSD$
+# $MidnightBSD$
+# $FreeBSD: stable/10/sys/teken/libteken/Makefile 221698 2011-05-09 16:27:39Z ed $
 
 LIB=	teken
 SHLIB_MAJOR= 0

Modified: trunk/sys/teken/libteken/Symbol.map
===================================================================
--- trunk/sys/teken/libteken/Symbol.map	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/libteken/Symbol.map	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,6 +1,7 @@
 /*
- * $FreeBSD$
- */	
+ * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/teken/libteken/Symbol.map 226111 2011-10-07 15:05:24Z ed $
+ */
 
 FBSD_1.2 {
 	teken_256to8;


Property changes on: trunk/sys/teken/libteken/Symbol.map
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/teken/libteken/teken.3
===================================================================
--- trunk/sys/teken/libteken/teken.3	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/libteken/teken.3	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2011 Ed Schouten <ed at FreeBSD.org>
 .\" All rights reserved.
 .\"
@@ -22,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/sys/teken/libteken/teken.3 223574 2011-06-26 18:25:10Z ed $
 .\"
 .Dd May 9, 2011
 .Dt TEKEN 3


Property changes on: trunk/sys/teken/libteken/teken.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/teken/sequences
===================================================================
--- trunk/sys/teken/sequences	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/sequences	2018-05-24 22:40:46 UTC (rev 9901)
@@ -23,7 +23,8 @@
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
-# $FreeBSD$
+# $FreeBSD: stable/10/sys/teken/sequences 214817 2010-11-05 00:56:21Z ed $
+# $MidnightBSD$
 
 # File format is as follows:
 #	Abbr		Abbreviation of sequence name


Property changes on: trunk/sys/teken/sequences
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/teken/stress/Makefile
===================================================================
--- trunk/sys/teken/stress/Makefile	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/stress/Makefile	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,4 +1,5 @@
-# $FreeBSD$
+# $MidnightBSD$
+# $FreeBSD: stable/10/sys/teken/stress/Makefile 221698 2011-05-09 16:27:39Z ed $
 
 PROG=	teken_stress
 LDADD=	-lteken

Modified: trunk/sys/teken/stress/teken_stress.c
===================================================================
--- trunk/sys/teken/stress/teken_stress.c	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/stress/teken_stress.c	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/stress/teken_stress.c 226100 2011-10-07 12:42:03Z ed $
  */
 
 #include <sys/cdefs.h>
@@ -99,24 +100,14 @@
 main(int argc __unused, char *argv[] __unused)
 {
 	teken_t t;
-	int rnd;
 	unsigned int i, iteration = 0;
 	unsigned char buf[2048];
 
-	rnd = open("/dev/urandom", O_RDONLY);
-	if (rnd < 0) {
-		perror("/dev/urandom");
-		exit(1);
-	}
 
 	teken_init(&t, &tf, NULL);
 
 	for (;;) {
-		if (read(rnd, buf, sizeof buf) != sizeof buf) {
-			perror("read");
-			exit(1);
-		}
-
+		arc4random_buf(buf, sizeof buf);
 		for (i = 0; i < sizeof buf; i++) {
 			if (buf[i] >= 0x80)
 				buf[i] =

Modified: trunk/sys/teken/teken.c
===================================================================
--- trunk/sys/teken/teken.c	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/teken.c	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,12 +24,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/teken.c 287776 2015-09-14 09:12:28Z ed $
  */
 
 #include <sys/cdefs.h>
 #if defined(__FreeBSD__) && defined(_KERNEL)
 #include <sys/param.h>
+#include <sys/limits.h>
 #include <sys/lock.h>
 #include <sys/systm.h>
 #define	teken_assert(x)		MPASS(x)
@@ -35,6 +37,7 @@
 #else /* !(__FreeBSD__ && _KERNEL) */
 #include <sys/types.h>
 #include <assert.h>
+#include <limits.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
@@ -338,15 +341,40 @@
 	return (&t->t_winsize);
 }
 
+static void
+teken_trim_cursor_pos(teken_t *t, const teken_pos_t *new)
+{
+	const teken_pos_t *cur;
+
+	cur = &t->t_winsize;
+
+	if (cur->tp_row < new->tp_row || cur->tp_col < new->tp_col)
+		return;
+	if (t->t_cursor.tp_row >= new->tp_row)
+		t->t_cursor.tp_row = new->tp_row - 1;
+	if (t->t_cursor.tp_col >= new->tp_col)
+		t->t_cursor.tp_col = new->tp_col - 1;
+}
+
 void
 teken_set_winsize(teken_t *t, const teken_pos_t *p)
 {
 
+	teken_trim_cursor_pos(t, p);
 	t->t_winsize = *p;
 	teken_subr_do_reset(t);
 }
 
 void
+teken_set_winsize_noreset(teken_t *t, const teken_pos_t *p)
+{
+
+	teken_trim_cursor_pos(t, p);
+	t->t_winsize = *p;
+	teken_subr_do_resize(t);
+}
+
+void
 teken_set_8bit(teken_t *t)
 {
 
@@ -380,18 +408,24 @@
 	teken_assert(t->t_curnum < T_NUMSIZE);
 
 	if (c >= '0' && c <= '9') {
-		/*
-		 * Don't do math with the default value of 1 when a
-		 * custom number is inserted.
-		 */
 		if (t->t_stateflags & TS_FIRSTDIGIT) {
+			/* First digit. */
 			t->t_stateflags &= ~TS_FIRSTDIGIT;
-			t->t_nums[t->t_curnum] = 0;
-		} else {
-			t->t_nums[t->t_curnum] *= 10;
+			t->t_nums[t->t_curnum] = c - '0';
+		} else if (t->t_nums[t->t_curnum] < UINT_MAX / 100) {
+			/*
+			 * There is no need to continue parsing input
+			 * once the value exceeds the size of the
+			 * terminal. It would only allow for integer
+			 * overflows when performing arithmetic on the
+			 * cursor position.
+			 *
+			 * Ignore any further digits if the value is
+			 * already UINT_MAX / 100.
+			 */
+			t->t_nums[t->t_curnum] =
+			    t->t_nums[t->t_curnum] * 10 + c - '0';
 		}
-
-		t->t_nums[t->t_curnum] += c - '0';
 		return (1);
 	} else if (c == ';') {
 		if (t->t_stateflags & TS_FIRSTDIGIT)

Modified: trunk/sys/teken/teken.h
===================================================================
--- trunk/sys/teken/teken.h	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/teken.h	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/teken.h 262861 2014-03-06 18:30:56Z jhb $
  */
 
 #ifndef _TEKEN_H_
@@ -41,10 +42,11 @@
 typedef uint32_t teken_char_t;
 typedef unsigned short teken_unit_t;
 typedef unsigned char teken_format_t;
-#define	TF_BOLD		0x01
-#define	TF_UNDERLINE	0x02
-#define	TF_BLINK	0x04
-#define	TF_REVERSE	0x08
+#define	TF_BOLD		0x01	/* Bold character. */
+#define	TF_UNDERLINE	0x02	/* Underline character. */
+#define	TF_BLINK	0x04	/* Blinking character. */
+#define	TF_REVERSE	0x08	/* Reverse rendered character. */
+#define	TF_CJK_RIGHT	0x10	/* Right-hand side of CJK character. */
 typedef unsigned char teken_color_t;
 #define	TC_BLACK	0
 #define	TC_RED		1
@@ -168,6 +170,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 *);
+void	teken_set_winsize_noreset(teken_t *, const teken_pos_t *);
 
 /* Key input escape sequences. */
 #define	TKEY_UP		0x00

Modified: trunk/sys/teken/teken_scs.h
===================================================================
--- trunk/sys/teken/teken_scs.h	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/teken_scs.h	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/teken_scs.h 203659 2010-02-08 09:16:59Z ed $
  */
 
 static inline teken_char_t

Modified: trunk/sys/teken/teken_subr.h
===================================================================
--- trunk/sys/teken/teken_subr.h	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/teken_subr.h	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/teken_subr.h 287776 2015-09-14 09:12:28Z ed $
  */
 
 static void teken_subr_cursor_up(teken_t *, unsigned int);
@@ -324,13 +325,13 @@
 teken_subr_cursor_position(teken_t *t, unsigned int row, unsigned int col)
 {
 
-	t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1;
-	if (t->t_cursor.tp_row >= t->t_originreg.ts_end)
-		t->t_cursor.tp_row = t->t_originreg.ts_end - 1;
+	row = row - 1 + t->t_originreg.ts_begin;
+	t->t_cursor.tp_row = row < t->t_originreg.ts_end ?
+	    row : t->t_originreg.ts_end - 1;
 
-	t->t_cursor.tp_col = col - 1;
-	if (t->t_cursor.tp_col >= t->t_winsize.tp_col)
-		t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+	col--;
+	t->t_cursor.tp_col = col < t->t_winsize.tp_col ?
+	    col : t->t_winsize.tp_col - 1;
 
 	t->t_stateflags &= ~TS_WRAPPED;
 	teken_funcs_cursor(t);
@@ -583,9 +584,9 @@
 teken_subr_horizontal_position_absolute(teken_t *t, unsigned int col)
 {
 
-	t->t_cursor.tp_col = col - 1;
-	if (t->t_cursor.tp_col >= t->t_winsize.tp_col)
-		t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+	col--;
+	t->t_cursor.tp_col = col < t->t_winsize.tp_col ?
+	    col : t->t_winsize.tp_col - 1;
 
 	t->t_stateflags &= ~TS_WRAPPED;
 	teken_funcs_cursor(t);
@@ -791,21 +792,19 @@
 		teken_funcs_copy(t, &ctr, &ctp);
 	}
 
+	teken_funcs_putchar(t, tp, c, &t->t_curattr);
+
 	if (width == 2 && tp->tp_col + 1 < t->t_winsize.tp_col) {
 		teken_pos_t tp2;
+		teken_attr_t attr;
 
-		/*
-		 * Store a space behind double width characters before
-		 * actually printing them. This prevents artifacts when
-		 * the consumer doesn't render it using double width
-		 * glyphs.
-		 */
+		/* Print second half of CJK fullwidth character. */
 		tp2.tp_row = tp->tp_row;
 		tp2.tp_col = tp->tp_col + 1;
-		teken_funcs_putchar(t, &tp2, BLANK, &t->t_curattr);
+		attr = t->t_curattr;
+		attr.ta_format |= TF_CJK_RIGHT;
+		teken_funcs_putchar(t, &tp2, c, &attr);
 	}
-
-	teken_funcs_putchar(t, tp, c, &t->t_curattr);
 }
 
 static void
@@ -842,13 +841,18 @@
 			}
 			t->t_cursor.tp_col = 0;
 		}
-	} else if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1 &&
-	    (t->t_stateflags & (TS_WRAPPED|TS_AUTOWRAP)) ==
-	    (TS_WRAPPED|TS_AUTOWRAP)) {
+	} else if (t->t_stateflags & TS_AUTOWRAP &&
+	    ((t->t_stateflags & TS_WRAPPED &&
+	    t->t_cursor.tp_col + 1 == t->t_winsize.tp_col) ||
+	    t->t_cursor.tp_col + width > t->t_winsize.tp_col)) {
 		teken_pos_t tp;
 
-		/* Perform line wrapping. */
-
+		/*
+		 * Perform line wrapping, if:
+		 * - Autowrapping is enabled, and
+		 *   - We're in the wrapped state at the last column, or
+		 *   - The character to be printed does not fit anymore.
+		 */
 		if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) {
 			/* Perform scrolling. */
 			teken_subr_do_scroll(t, 1);
@@ -956,6 +960,15 @@
 }
 
 static void
+teken_subr_do_resize(teken_t *t)
+{
+
+	t->t_scrollreg.ts_begin = 0;
+	t->t_scrollreg.ts_end = t->t_winsize.tp_row;
+	t->t_originreg = t->t_scrollreg;
+}
+
+static void
 teken_subr_do_reset(teken_t *t)
 {
 
@@ -1285,9 +1298,9 @@
 teken_subr_vertical_position_absolute(teken_t *t, unsigned int row)
 {
 
-	t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1;
-	if (t->t_cursor.tp_row >= t->t_originreg.ts_end)
-		t->t_cursor.tp_row = t->t_originreg.ts_end - 1;
+	row = row - 1 + t->t_originreg.ts_begin;
+	t->t_cursor.tp_row = row < t->t_originreg.ts_end ?
+	    row : t->t_originreg.ts_end - 1;
 
 	t->t_stateflags &= ~TS_WRAPPED;
 	teken_funcs_cursor(t);

Modified: trunk/sys/teken/teken_subr_compat.h
===================================================================
--- trunk/sys/teken/teken_subr_compat.h	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/teken_subr_compat.h	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/teken_subr_compat.h 214817 2010-11-05 00:56:21Z ed $
  */
 
 static void

Modified: trunk/sys/teken/teken_wcwidth.h
===================================================================
--- trunk/sys/teken/teken_wcwidth.h	2018-05-24 22:37:43 UTC (rev 9900)
+++ trunk/sys/teken/teken_wcwidth.h	2018-05-24 22:40:46 UTC (rev 9901)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Markus Kuhn -- 2007-05-26 (Unicode 5.0)
  *
@@ -7,7 +8,7 @@
  *
  * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/teken/teken_wcwidth.h 186681 2009-01-01 13:26:53Z ed $
  */
 
 struct interval {



More information about the Midnightbsd-cvs mailing list