shithub: neatroff

Download patch

ref: cefdee951aa523e79a2e3ac1f19cdfbb5080423c
parent: 966ff9d486ae39e15691941f3174ed0962616ca4
author: Ali Gholami Rudi <ali@rudi.ir>
date: Wed Dec 31 17:44:02 EST 2014

cp: allow utf-8 escaped names

This actually reverts c6e989fa: now in \x, \(xy, \nx, \n(xy, \*x, \*(xy
x and y can be unicode characters.

--- a/char.c
+++ b/char.c
@@ -114,16 +114,14 @@
 	if (!utf8next(c, next))
 		return -1;
 	if (c[0] == c_ni) {
-		c[1] = next();
-		c[2] = '\0';
+		utf8next(c + 1, next);
 		return c_ni;
 	}
 	if (c[0] == c_ec) {
-		c[1] = next();
-		c[2] = '\0';
+		utf8next(c + 1, next);
 		if (c[1] == '(') {
-			c[0] = next();
-			c[1] = next();
+			l = utf8next(c, next);
+			l += utf8next(c + l, next);
 			return '(';
 		} else if (!n_cp && c[1] == '[') {
 			l = 0;
@@ -234,11 +232,10 @@
 		return -1;
 	utf8read(s, d);
 	if (d[0] == c_ec) {
-		d[1] = *(*s)++;
-		d[2] = '\0';
+		utf8read(s, d + 1);
 		if (d[1] == '(') {
-			d[0] = *(*s)++;
-			d[1] = *(*s)++;
+			utf8read(s, d);
+			utf8read(s, d + strlen(d));
 		} else if (!n_cp && d[1] == '[') {
 			while (**s && **s != ']')
 				*r++ = *(*s)++;
--- a/cp.c
+++ b/cp.c
@@ -22,8 +22,8 @@
 	int c = cp_noninext();
 	int i = 0;
 	if (c == '(') {
-		d[i++] = cp_noninext();
-		d[i++] = cp_noninext();
+		i += utf8next(d + i, cp_noninext);
+		i += utf8next(d + i, cp_noninext);
 	} else if (!n_cp && c == '[') {
 		c = cp_noninext();
 		while (i < NMLEN - 1 && c >= 0 && c != ']') {
@@ -30,10 +30,11 @@
 			d[i++] = c;
 			c = cp_noninext();
 		}
+		d[i] = '\0';
 	} else {
-		d[i++] = c;
+		cp_back(c);
+		utf8next(d, cp_noninext);
 	}
-	d[i] = '\0';
 }
 
 static int regid(void)
--- a/hyph.c
+++ b/hyph.c
@@ -21,10 +21,10 @@
 /* read a single character from s into d; return the number of characters read */
 static int hy_cget(char *d, char *s)
 {
+	int i = 0;
 	if (s[0] != '\\')
 		return utf8read(&s, d);
 	if (s[1] == '[') {
-		int i = 0;
 		s += 2;
 		while (*s && *s != ']' && i < GNLEN - 1)
 			d[i++] = *s++;
@@ -32,13 +32,12 @@
 		return *s ? i + 3 : i + 2;
 	}
 	if (s[1] == '(') {
-		d[0] = s[2];
-		d[1] = s[3];
-		d[2] = '\0';
-		return 4;
+		s += 2;
+		i += utf8read(&s, d + i);
+		i += utf8read(&s, d + i);
+		return 2 + i;
 	}
 	if (s[1] == 'C') {
-		int i = 0;
 		int q = s[2];
 		s += 3;
 		while (*s && *s != q && i < GNLEN - 1)
@@ -46,32 +45,19 @@
 		d[i] = '\0';
 		return *s ? i + 4 : i + 3;
 	}
-	d[0] = s[0];
-	d[1] = s[1];
-	d[2] = '\0';
-	return 2;
+	*d++ = *s++;
+	return 1 + utf8read(&s, d);
 }
 
 /* append character s to d; return the number of characters written */
 static int hy_cput(char *d, char *s)
 {
-	if (!s[0] || !s[1] || utf8one(s)) {
+	if (!s[0] || !s[1] || utf8one(s))
 		strcpy(d, s);
-	} else if (s[0] == '\\' && !s[2]) {
-		s[0] = d[0];
-		s[1] = d[1];
-		s[2] = '\0';
-		return 2;
-	} else if (!s[2]) {
-		d[0] = '\\';
-		d[1] = '(';
-		d[2] = s[0];
-		d[3] = s[1];
-		d[4] = '\0';
-		return 4;
-	} else {
+	else if (s[0] == '\\')
+		strcpy(d, s);
+	else if (!s[2])
 		snprintf(d, GNLEN, "\\[%s]", s);
-	}
 	return strlen(d);
 }