shithub: neatroff

Download patch

ref: 87294120003bbc48e7ffb50566c46c9b22285cf3
parent: 5c479143296d316505df08fbe35218f19cc0876d
author: Ali Gholami Rudi <ali@rudi.ir>
date: Tue May 28 13:26:00 EDT 2013

tr: skip tabs after if condition

--- a/tr.c
+++ b/tr.c
@@ -191,7 +191,7 @@
 	return 0;
 }
 
-/* read into sbuf until stop */
+/* read into sbuf until stop; if stop is NULL, stop at whitespace */
 static int read_until(struct sbuf *sbuf, char *stop)
 {
 	int c;
@@ -199,8 +199,10 @@
 		cp_back(c);
 		if (c == '\n')
 			return 1;
-		if (!schar_jump(stop, cp_next, cp_back))
+		if (!stop && (c == ' ' || c == '\t'))
 			return 0;
+		if (stop && !schar_jump(stop, cp_next, cp_back))
+			return 0;
 		sbuf_add(sbuf, cp_next());
 	}
 	return 1;
@@ -245,7 +247,7 @@
 	struct sbuf sbuf;
 	int ret;
 	sbuf_init(&sbuf);
-	if (!read_until(&sbuf, " "))
+	if (!read_until(&sbuf, NULL))
 		cp_back(' ');
 	ret = eval(sbuf_buf(&sbuf), '\0') > 0;
 	sbuf_done(&sbuf);