[Commit] jove Makefile,1.6,1.7 ask.c,1.3,1.4 ctype.c,1.1.1.1,1.2 jove.c,1.4,1.5 jove.h,1.5,1.6 macros.c,1.2,1.3 re.c,1.3,1.4 re1.c,1.3,1.4

Keith Packard commit@keithp.com
Wed, 14 May 2003 23:00:17 -0700


Committed by: keithp

Update of /local/src/CVS/jove
In directory home.keithp.com:/tmp/cvs-serv11186

Modified Files:
	Makefile ask.c ctype.c jove.c jove.h macros.c re.c re1.c 
Log Message:
Accept utf-8 on input.  Check array bounds for char-indexed arrays

Index: Makefile
===================================================================
RCS file: /local/src/CVS/jove/Makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile	30 Jan 2002 05:57:08 -0000	1.6
+++ Makefile	15 May 2003 06:00:14 -0000	1.7
@@ -17,7 +17,7 @@
 # JOVE, RECOVER and TEACHJOVE.  MANEXT is the extension for the man pages,
 # e.g., jove.1 or jove.l or jove.m.
 
-DESTDIR = /usr/local
+DESTDIR = /local
 TMPDIR = /tmp
 RECDIR = $(TMPDIR)
 LIBDIR = $(DESTDIR)/lib/jove

Index: ask.c
===================================================================
RCS file: /local/src/CVS/jove/ask.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ask.c	15 May 2003 00:01:06 -0000	1.3
+++ ask.c	15 May 2003 06:00:14 -0000	1.4
@@ -123,7 +123,7 @@
 {
 	static int	InAsk = 0;
 	jmp_buf	savejmp;
-	int	c,
+	ucs4	c,
 		prompt_len;
 	Buffer	*saveb = curbuf;
 	int	abort = 0,

Index: ctype.c
===================================================================
RCS file: /local/src/CVS/jove/ctype.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- ctype.c	10 Mar 2001 12:23:11 -0000	1.1.1.1
+++ ctype.c	15 May 2003 06:00:14 -0000	1.2
@@ -152,7 +152,7 @@
 	return ((CharTable[curbuf->b_major])[c]&(_W));
 }
 
-char CaseEquiv[256] = {
+char _CaseEquiv[256] = {
 	'\000',	'\001',	'\002',	'\003',	'\004',	'\005',	'\006',	'\007',
 	'\010',	'\011',	'\012',	'\013',	'\014',	'\015',	'\016',	'\017',
 	'\020',	'\021',	'\022',	'\023',	'\024',	'\025',	'\026',	'\027',

Index: jove.c
===================================================================
RCS file: /local/src/CVS/jove/jove.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- jove.c	15 May 2003 00:01:06 -0000	1.4
+++ jove.c	15 May 2003 06:00:14 -0000	1.5
@@ -118,7 +118,7 @@
 		*bp = smbuf;
 private int	nchars = 0;
 
-private char	peekbuf[10],
+private char	peekbuf[30],
 		*peekp = peekbuf;
 
 #ifdef SYSV
@@ -699,18 +699,20 @@
 int	this_cmd,
 	last_cmd;
 
-dispatch(c)
-register int	c;
+dispatch(ucs4 c)
 {
 	data_obj	*cp;
 
-	if ((c & 0200) && MetaKey)
+	if ((c & 0200) && MetaKey && !Utf8Out)
 	{
 		Ungetc (c & 0177);
 		c = 033;
 	}
 	this_cmd = 0;
-	cp = mainmap[c & 0177];
+	if (c < 0x100)
+		cp = mainmap[c & 0177];
+	else
+		cp = mainmap['a'];
 
 	if (cp == 0) {
 		rbell();
@@ -724,9 +726,9 @@
 int	LastKeyStruck,
 	MetaKey = 0;
 
-terminch()
+static int terminbyte()
 {
-	register int	c,
+	ucs4		c,
 			peekc;
 #ifdef IPROCS
 	extern int	NumProcs;
@@ -736,7 +738,7 @@
 
 	if (Inputp) {
 		if ((c = *Inputp++) != 0)
-			return LastKeyStruck = c;
+			return c;
 		Inputp = 0;
 	}
 
@@ -787,7 +789,36 @@
 	}
 	if (peekc == -1)	/* Don't add_stroke peekc's */
 		add_stroke(c);
-	return LastKeyStruck = c;
+	return c;
+}
+
+ucs4
+terminch (void)
+{
+    ucs4    result;
+
+    result = terminbyte ();
+    if (Utf8Out && (result & 0xc0) == 0xc0)
+    {
+	    ucs4    mask = 0x20;
+	    int	    extra = 1;
+
+	    while ((result & mask) != 0)
+	    {
+		    extra++;
+		    mask >>= 1;
+	    }
+	    result &= (mask - 1);
+	    while (extra-- > 0)
+	    {
+		    ucs4 c = terminbyte ();
+
+		    if (!(c & 0x80))
+			    break;
+		    result = (result << 6) | (c & 0x3f);
+	    }
+    }
+    return LastKeyStruck = result;
 }
 
 dorecover()

Index: jove.h
===================================================================
RCS file: /local/src/CVS/jove/jove.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- jove.h	15 May 2003 00:01:06 -0000	1.5
+++ jove.h	15 May 2003 06:00:14 -0000	1.6
@@ -131,7 +131,7 @@
 #define lastp(line)	(line == curbuf->b_last)
 #define makedirty(line)	line->l_dline |= DIRTY
 #define one_windp()	(fwind->w_next == fwind)
-#define CharUpcase(c)	(CaseEquiv[c])
+#define CharUpcase(c)	(CaseEquiv(c))
 #define WinText(w)	(((w)->w_flags & W_NUMLINES ? 8 : 0) + ((w)->w_flags & W_HIGHCUR ? 1 : 0))
 
 typedef unsigned int	ucs4;
@@ -193,7 +193,8 @@
 #define SetMajor(x)	((curbuf->b_major = x), UpdModLine++)
 
 extern char	CharTable[NMAJORS][256];
-extern char	CaseEquiv[256];
+extern char	_CaseEquiv[256];
+static inline ucs4 CaseEquiv(ucs4 c) { return (c < 0x100) ? _CaseEquiv[c] : c; }
 
 /* setjmp/longjmp args for DoKeys() mainjmp */
 #define FIRSTCALL	0

Index: macros.c
===================================================================
RCS file: /local/src/CVS/jove/macros.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- macros.c	11 Jul 2001 06:42:26 -0000	1.2
+++ macros.c	15 May 2003 06:00:14 -0000	1.3
@@ -321,12 +321,12 @@
 static
 PrefChar(c)
 {
-	return IsPrefix(mainmap[c]) != 0;
+	return c <= 0x100 && IsPrefix(mainmap[c]) != 0;
 }
 
 IsInsertChar(c)
 {
-	return (int) ((mainmap[c]->Type & FUNCINS) == FUNCINS);
+	return (int) (c <= 0x100 && (mainmap[c]->Type & FUNCINS) == FUNCINS);
 }
 
 Forget()

Index: re.c
===================================================================
RCS file: /local/src/CVS/jove/re.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- re.c	22 Aug 2001 18:58:50 -0000	1.3
+++ re.c	15 May 2003 06:00:14 -0000	1.4
@@ -31,7 +31,7 @@
 	WrapScan = 1,
 	UseRE = 1;
 
-#define cind_cmp(a, b)	(CaseEquiv[a] == CaseEquiv[b])
+#define cind_cmp(a, b)	(CaseEquiv(a) == CaseEquiv(b))
 
 private int	REpeekc;
 private char	*REptr;
@@ -539,7 +539,7 @@
 	if (isquick) {
 		firstc = expr[2];
 		if (expr[0] == CINDC)
-			firstc = CaseEquiv[firstc];
+			firstc = CaseEquiv(firstc);
 	}
 	locs = REbolp + offset;
 
@@ -553,7 +553,7 @@
 					;
 			else
 				while (((c = *locs++) != 0) &&
-					(CaseEquiv[c] != firstc))
+					(CaseEquiv(c) != firstc))
 					;
 			if (*--locs == 0)
 				break;
@@ -579,9 +579,9 @@
 				if (*++locs != firstc)
 					break;
 			} else {
-				while (locs >= REbolp && CaseEquiv[*locs--] != firstc)
+				while (locs >= REbolp && CaseEquiv(*locs--) != firstc)
 					;
-				if (CaseEquiv[*++locs] != firstc)
+				if (CaseEquiv(*++locs) != firstc)
 					break;
 			}
 		}

Index: re1.c
===================================================================
RCS file: /local/src/CVS/jove/re1.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- re1.c	15 May 2003 00:01:06 -0000	1.3
+++ re1.c	15 May 2003 06:00:14 -0000	1.4
@@ -1,5 +1,5 @@
 /************************************************************************
- * This program is Copyright (C) 1986 by Jonathan Payne.  JOVE is       *
+ * This program is Copyright © 1986 by Jonathan Payne.  JOVE is       *
  * provided to you without charge, and with no warranty.  You may give  *
  * away copies of JOVE, including sources, provided that this notice is *
  * included in all the files.                                           *
@@ -997,12 +997,12 @@
 		case CTL('Q'):
 		case CTL('^'):
 			add_mess("");
-			c = terminch() | 0400;
+			c = terminch() | 0x80000000;
 			/* Fall into ... */
 
 		default:
-			if (c & 0400)
-				c &= 0377;
+			if (c & 0x80000000)
+				c &= 0x7fffffff;
 			else {
 				if (!IsInsertChar(c)) {
 					Ungetc(c);