shithub: neatroff

Download patch

ref: 93fbb40f78a4b3d264c55907b9bb345bebf8d785
parent: 4f0e4f183e5c02c517c5bc7ff5df87a782b0239f
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Apr 20 14:47:12 EDT 2013

eval: add eval_up() to update the passed char **

--- a/eval.c
+++ b/eval.c
@@ -95,7 +95,8 @@
 		evaljmp(s, ')');
 		return ret;
 	}
-	if (!evaljmp(s, '\\') && !evaljmp(s, 'w')) {
+	if ((*s)[0] == '\\' && (*s)[1] == 'w') {
+		*s += 2;
 		wid_s = s;
 		ret = ren_wid(wid_next, wid_back);
 		readunit(**s && strchr(SCHAR, **s) ? *(*s)++ : defunit, ret);
@@ -134,13 +135,14 @@
 	return ret;
 }
 
-int eval(char *s, int orig, int unit)
+/* evaluate *s and update s to point to the last character read */
+int eval_up(char **s, int orig, int unit)
 {
 	int n;
 	int rel = 0;		/* n should be added to orig */
-	if (*s == '+' || *s == '-') {
-		rel = *s == '+' ? 1 : -1;
-		s++;
+	if (**s == '+' || **s == '-') {
+		rel = **s == '+' ? 1 : -1;
+		(*s)++;
 	}
 	defunit = unit;
 	if (unit == 'v')
@@ -147,8 +149,14 @@
 		abspos = -n_d;
 	if (unit == 'm')
 		abspos = n_lb - f_hpos();
-	n = evalexpr(&s);
+	n = evalexpr(s);
 	if (rel)
 		return rel > 0 ? orig + n : orig - n;
 	return n;
+}
+
+/* evaluate s */
+int eval(char *s, int orig, int unit)
+{
+	return eval_up(&s, orig, unit);
 }
--- a/xroff.h
+++ b/xroff.h
@@ -33,6 +33,7 @@
 char *num_str(int id);
 int *nreg(int id);
 int eval(char *s, int orig, int unit);
+int eval_up(char **s, int orig, int unit);
 
 /* string registers */
 void str_set(int id, char *s);