shithub: neatroff

Download patch

ref: 23c9c796ad136f6bac96e21f3add6fda8332ebb9
parent: 93fbb40f78a4b3d264c55907b9bb345bebf8d785
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Apr 20 14:48:31 EDT 2013

dev: more consistent special glyph names

--- a/dev.c
+++ b/dev.c
@@ -123,8 +123,13 @@
 
 struct glyph *dev_glyph(char *c, int fn)
 {
-	struct glyph *g = font_find(fn_font[fn], c);
+	struct glyph *g;
 	int i;
+	if (c[0] == '\\' && c[1] == '\\')
+		c++;
+	if (c[0] == '\\' && c[1] == '(')
+		c += 2;
+	g = font_find(fn_font[fn], c);
 	if (g)
 		return g;
 	for (i = 0; i < fn_n; i++)
--- a/out.c
+++ b/out.c
@@ -193,38 +193,40 @@
 void out_line(char *s)
 {
 	struct glyph *g;
-	char c[GNLEN * 2];
+	char c[GNLEN * 4];
 	char arg[ILNLEN];
 	while (*s) {
 		s = utf8get(c, s);
 		if (c[0] == '\\') {
-			s = utf8get(c, s);
-			if (c[0] == '(') {
-				s = utf8get(c, s);
+			s = utf8get(c + 1, s);
+			if (c[1] == '(') {
+				s = utf8get(c + 2, s);
 				s = utf8get(c + strlen(c), s);
-			} else if (strchr("DfhsvX", c[0])) {
-				s = escarg(s, arg, c[0]);
-				if (c[0] == 'D') {
+			} else if (c[1] == '\\') {
+				c[1] = '\0';
+			} else if (strchr("DfhsvX", c[1])) {
+				s = escarg(s, arg, c[1]);
+				if (c[1] == 'D') {
 					out_draw(arg, NULL);
 					continue;
 				}
-				if (c[0] == 'f') {
+				if (c[1] == 'f') {
 					out_ft(dev_font(arg));
 					continue;
 				}
-				if (c[0] == 'h') {
+				if (c[1] == 'h') {
 					outnn("h%d", eval(arg, 0, 'm'));
 					continue;
 				}
-				if (c[0] == 's') {
+				if (c[1] == 's') {
 					out_ps(eval(arg, o_s, '\0'));
 					continue;
 				}
-				if (c[0] == 'v') {
+				if (c[1] == 'v') {
 					outnn("v%d", eval(arg, 0, 'v'));
 					continue;
 				}
-				if (c[0] == 'X') {
+				if (c[1] == 'X') {
 					out("x X %s\n", arg);
 					continue;
 				}
@@ -232,11 +234,10 @@
 		}
 		g = dev_glyph(c, o_f);
 		if (g) {
-			if (utf8len(c[0]) == strlen(c)) {
+			if (utf8len(c[0]) == strlen(c))
 				outnn("c%s%s", c, c[1] ? "\n" : "");
-			} else {
-				out("C%s\n", c);
-			}
+			else
+				out("C%s\n", c[0] == '\\' && c[1] == '(' ? c + 2 : c);
 		}
 		outnn("h%d", charwid(g ? g->wid : dev_spacewid(), o_s));
 	}
--- a/ren.c
+++ b/ren.c
@@ -517,11 +517,11 @@
 /* read one character and place it inside adj buffer */
 static int ren_char(struct adj *adj, int (*next)(void), void (*back)(int))
 {
-	char c[GNLEN * 2];
+	char c[GNLEN * 4];
 	char arg[ILNLEN];
 	char widbuf[16];
 	struct glyph *g;
-	int esc = 0, n;
+	int n;
 	nextchar(c, next);
 	if (c[0] == ' ' || c[0] == '\n') {
 		adj_put(adj, charwid(dev_spacewid(), n_s), c);
@@ -528,21 +528,20 @@
 		return 0;
 	}
 	if (c[0] == '\\') {
-		esc = 1;
-		nextchar(c, next);
-		if (c[0] == '(') {
-			int l = nextchar(c, next);
-			l += nextchar(c + l, next);
-			c[l] = '\0';
-		} else if (strchr(" DdfhkrsuvwXx0^|{}", c[0])) {
-			if (c[0] == 'w') {
+		nextchar(c + 1, next);
+		if (c[1] == '(') {
+			int l = nextchar(c + 2, next);
+			l += nextchar(c + 2 + l, next);
+			c[2 + l] = '\0';
+		} else if (strchr(" DdfhkLlrsuvwXx0^|{}", c[1])) {
+			if (c[1] == 'w') {
 				n = ren_wid(next, back);
 				sprintf(widbuf, "%d", n);
 				in_push(widbuf, NULL);
 				return 0;
 			}
-			escarg_ren(arg, c[0]);
-			ren_cmd(adj, c[0], arg);
+			escarg_ren(arg, c[1]);
+			ren_cmd(adj, c[1], arg);
 			return 0;
 		}
 	}
@@ -555,12 +554,8 @@
 		adj_put(adj, 0, "\\f(%02d", n_f);
 		ren_f = n_f;
 	}
-	if (utf8len(c[0]) == strlen(c))
-		sprintf(arg, "%s%s", esc ? "\\" : "", c);
-	else
-		sprintf(arg, "\\(%s", c);
 	g = dev_glyph(c, n_f);
-	adj_put(adj, charwid(g ? g->wid : dev_spacewid(), n_s), arg);
+	adj_put(adj, charwid(g ? g->wid : dev_spacewid(), n_s), c);
 	return g ? g->type : 0;
 }