shithub: neatroff

Download patch

ref: 71b97b8325ac5a3f4aa2762d90e860bfe00f816b
parent: 9449dc43d41f2539965d9f46e50f5794196a635f
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Apr 19 14:28:52 EDT 2013

in: make the signature of in_pushnl() like in_push()

--- a/in.c
+++ b/in.c
@@ -11,6 +11,7 @@
 	int pos;
 	int len;
 	int backed;
+	int nl;			/* read \n, if the previous char was not */
 	struct inbuf *prev;
 };
 
@@ -42,10 +43,10 @@
 	buf->args = args ? args_init(args) : NULL;
 }
 
-void in_pushnl(void)
+void in_pushnl(char *s, char **args)
 {
-	if (buf && buf->backed < 0 && in_last != '\n')
-		cp_back('\n');
+	in_push(s, args);
+	buf->nl = 1;
 }
 
 void in_source(char *path)
@@ -88,6 +89,8 @@
 {
 	int c;
 	while (buf || !in_nextfile()) {
+		if (buf->nl-- > 0 && in_last != '\n')
+			return '\n';
 		if (buf->buf && buf->pos < buf->len)
 			break;
 		if (!buf->buf && (c = getc(buf->fin)) >= 0)
--- a/ren.c
+++ b/ren.c
@@ -146,7 +146,7 @@
 {
 	char buf[32];
 	sprintf(buf, "%s.ne %du\n", dobr ? ".br\n" : "", n_p);
-	in_push(buf, NULL);
+	in_pushnl(buf, NULL);
 }
 
 static void trap_exec(int reg)
@@ -154,8 +154,7 @@
 	if (bp_force)
 		push_ne(0);
 	if (str_get(reg))
-		in_push(str_get(reg), NULL);
-	in_pushnl();
+		in_pushnl(str_get(reg), NULL);
 }
 
 /* return 1 if executed a trap */
@@ -255,7 +254,7 @@
 void tr_sp(char **args)
 {
 	if (args[0][0] == '.')
-		ren_br(1);
+		 ren_br(1);
 	if (!n_ns)
 		down(args[1] ? eval(args[1], 0, 'v') : n_v);
 }
--- a/xroff.h
+++ b/xroff.h
@@ -99,11 +99,11 @@
 int cp_next(void);		/* copy-mode layer */
 int tr_next(void);		/* troff layer */
 void in_push(char *s, char **args);
+void in_pushnl(char *s, char **args);
 void in_source(char *path);	/* .so request */
 void in_queue(char *path);	/* next input file */
 char *in_arg(int i);		/* look up argument */
 void in_back(int c);		/* push back input character */
-void in_pushnl(void);		/* push a \n, if the last char was not */
 char *in_filename(void);	/* current filename */
 void cp_back(int c);		/* push back copy-mode character */
 void cp_blk(int skip);		/* skip or read the next line or block */