shithub: neatroff

Download patch

ref: 9b5448d2cc4b03f27285fd047b0fed9a596fac29
parent: e4cf02eeb714391259ef92b9660b37634440e13d
author: Ali Gholami Rudi <[email protected]>
date: Tue May 31 13:40:58 EDT 2016

draw: extend polygons to include arcs or splines

--- a/draw.c
+++ b/draw.c
@@ -134,16 +134,21 @@
 
 static int tok_num(char **s, int scale)
 {
-	char tok[ILNLEN];
-	char *d = tok;
-	while (isspace(**s))
+	while (**s == ' ' || **s == '\t')
 		(*s)++;
-	while (**s && !isspace(**s))
-		*d++ = *(*s)++;
-	*d = '\0';
-	return eval(tok, scale);
+	return eval_up(s, scale);
 }
 
+static int tok_numpt(char **s, int scale, int *i)
+{
+	char *o;
+	while (**s == ' ' || **s == '\t')
+		(*s)++;
+	o = *s;
+	*i = eval_up(s, scale);
+	return o == *s ? 1 : 0;
+}
+
 void ren_dcmd(struct wb *wb, char *s)
 {
 	int h1, h2, v1, v2;
@@ -174,9 +179,16 @@
 	case 'p':
 		wb_drawxbeg(wb, c);
 		while (*s) {
-			h1 = tok_num(&s, 'm');
-			v1 = tok_num(&s, 'v');
-			wb_drawxdot(wb, h1, v1);
+			if (tok_numpt(&s, 'm', &h1) || tok_numpt(&s, 'v', &v1)) {
+				char tok[64];
+				int i = 0;
+				while (i < sizeof(tok) - 1 && *s && *s != ' ')
+					tok[i++] = *s++;
+				tok[i] = '\0';
+				wb_drawxcmd(wb, tok);
+			} else {
+				wb_drawxdot(wb, h1, v1);
+			}
 		}
 		wb_drawxend(wb);
 		break;
--- a/out.c
+++ b/out.c
@@ -65,16 +65,21 @@
 
 static int tok_num(char **s, int scale)
 {
-	char tok[ILNLEN];
-	char *d = tok;
-	while (isspace(**s))
+	while (**s == ' ' || **s == '\t')
 		(*s)++;
-	while (**s && !isspace(**s))
-		*d++ = *(*s)++;
-	*d = '\0';
-	return eval(tok, scale);
+	return eval_up(s, scale);
 }
 
+static int tok_numpt(char **s, int scale, int *i)
+{
+	char *o;
+	while (**s == ' ' || **s == '\t')
+		(*s)++;
+	o = *s;
+	*i = eval_up(s, scale);
+	return o == *s ? 1 : 0;
+}
+
 static void out_draw(char *s)
 {
 	int c = *s++;
@@ -100,11 +105,16 @@
 		break;
 	case '~':
 	case 'p':
-		outnn(" %d", tok_num(&s, 'm'));
-		outnn(" %d", tok_num(&s, 'v'));
 		while (*s) {
-			outnn(" %d", tok_num(&s, 'm'));
-			outnn(" %d", tok_num(&s, 'v'));
+			int h, v;
+			if (tok_numpt(&s, 'm', &h) || tok_numpt(&s, 'v', &v)) {
+				outnn(" ");
+				while (*s && *s != ' ')
+					outnn("%c", *s++);
+			} else {
+				outnn(" %d", h);
+				outnn(" %d", v);
+			}
 		}
 		break;
 	}
--- a/roff.h
+++ b/roff.h
@@ -254,6 +254,7 @@
 void wb_drawa(struct wb *wb, int c, int h1, int v1, int h2, int v2);
 void wb_drawxbeg(struct wb *wb, int c);
 void wb_drawxdot(struct wb *wb, int h, int v);
+void wb_drawxcmd(struct wb *wb, char *cmd);
 void wb_drawxend(struct wb *wb);
 void wb_italiccorrection(struct wb *wb);
 void wb_italiccorrectionleft(struct wb *wb);
--- a/wb.c
+++ b/wb.c
@@ -347,6 +347,11 @@
 	wb_stsb(wb);
 }
 
+void wb_drawxcmd(struct wb *wb, char *cmd)
+{
+	sbuf_printf(&wb->sbuf, " %s", cmd);
+}
+
 void wb_drawxend(struct wb *wb)
 {
 	sbuf_printf(&wb->sbuf, "'");