shithub: neatroff

Download patch

ref: aa79ff4da0a2b1ff7e0330fe8bab3d6f14515391
parent: c0f38dd3d09c73be6e4393424f2026afe7590499
author: Ali Gholami Rudi <ali@rudi.ir>
date: Wed Jul 16 14:38:46 EDT 2014

ren: \Z'xyz' restores current position after printing xyz

--- a/draw.c
+++ b/draw.c
@@ -237,3 +237,19 @@
 	wb_done(&wb3);
 	wb_done(&wb2);
 }
+
+void ren_zcmd(struct wb *wb, char *arg)
+{
+	int h, v;
+	int c;
+	h = wb_hpos(wb);
+	v = wb_vpos(wb);
+	sstr_push(arg);
+	while ((c = sstr_next()) >= 0) {
+		sstr_back(c);
+		ren_char(wb, sstr_next, sstr_back);
+	}
+	sstr_pop();
+	wb_hmov(wb, h - wb_hpos(wb));
+	wb_vmov(wb, v - wb_vpos(wb));
+}
--- a/ren.c
+++ b/ren.c
@@ -665,6 +665,9 @@
 	case 'x':
 		wb_els(wb, eval(arg, 'v'));
 		break;
+	case 'Z':
+		ren_zcmd(wb, arg);
+		break;
 	case '0':
 		wb_hmov(wb, zwid());
 		break;
@@ -730,7 +733,7 @@
 			}
 			return;
 		}
-		if (strchr(" bCcDdefHhkLlmNoprSsuvXxz0^|{}&/,", c[1])) {
+		if (strchr(" bCcDdefHhkLlmNoprSsuvXxZz0^|{}&/,", c[1])) {
 			argnext(arg, c[1], next, back);
 			if (c[1] == 'e') {
 				snprintf(c, GNLEN, "%c%c", c_ec, c_ec);
--- a/roff.h
+++ b/roff.h
@@ -59,7 +59,7 @@
 #define SC_EM		(n_s * SC_IN / 72)
 
 /* escape sequences */
-#define ESC_Q	"bCDhHlLNoRSvwxX?"	/* \X'ccc' quoted escape sequences */
+#define ESC_Q	"bCDhHlLNoRSvwxXZ?"	/* \X'ccc' quoted escape sequences */
 #define ESC_P	"*fgkmns"		/* \Xc \X(cc \X[ccc] escape sequences */
 
 #define MIN(a, b)	((a) < (b) ? (a) : (b))
@@ -296,6 +296,8 @@
 int wb_hyphmark(char *word, int *hyidx, int *hyins);
 int wb_hyph(char *word, int *hyidx, int flg);
 int wb_wid(struct wb *wb);
+int wb_hpos(struct wb *wb);
+int wb_vpos(struct wb *wb);
 int wb_dashwid(struct wb *wb);
 int wb_empty(struct wb *wb);
 int wb_eos(struct wb *wb);
@@ -358,6 +360,7 @@
 void ren_bcmd(struct wb *wb, char *arg);	/* \b */
 void ren_ocmd(struct wb *wb, char *arg);	/* \o */
 void ren_dcmd(struct wb *wb, char *arg);	/* \D */
+void ren_zcmd(struct wb *wb, char *arg);	/* \Z */
 
 /* out.c */
 void out_line(char *s);				/* output rendered line */
--- a/wb.c
+++ b/wb.c
@@ -384,6 +384,16 @@
 	return wb->h;
 }
 
+int wb_hpos(struct wb *wb)
+{
+	return wb->h;
+}
+
+int wb_vpos(struct wb *wb)
+{
+	return wb->v;
+}
+
 int wb_empty(struct wb *wb)
 {
 	return sbuf_empty(&wb->sbuf);