changeset 27:01c3a2088ab4

fix some more bugs
author David A. Holland
date Mon, 20 Dec 2010 05:01:18 -0500
parents ac45dcc57ff9
children 8a955e3dda2c
files macro.c output.c
diffstat 2 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/macro.c	Mon Dec 20 05:01:07 2010 -0500
+++ b/macro.c	Mon Dec 20 05:01:18 2010 -0500
@@ -467,7 +467,7 @@
 	num = stringarray_num(&m->params);
 	for (i=0; i<num; i++) {
 		param = stringarray_get(&m->params, i);
-		if (strlen(param) == len && !strcmp(name, param)) {
+		if (strlen(param) == len && !memcmp(name, param, len)) {
 			*num_ret = i;
 			return true;
 		}
@@ -493,7 +493,7 @@
 				if (pos > blockstart) {
 					ei = expansionitem_create_stringlen(
 						buf + blockstart,
-						pos - blockstart);
+						wordstart - blockstart);
 					expansionitemarray_add(&m->expansion,
 							       ei, NULL);
 				}
--- a/output.c	Mon Dec 20 05:01:07 2010 -0500
+++ b/output.c	Mon Dec 20 05:01:18 2010 -0500
@@ -1,3 +1,4 @@
+#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <err.h>
@@ -9,6 +10,9 @@
 
 static int outputfd = -1;
 static bool incomment = false;
+static char *linebuf;
+static size_t linebufpos, linebufmax;
+static struct place linebufplace;
 
 static
 void
@@ -42,8 +46,6 @@
 		output_open();
 	}
 
-	/* XXX this will often come by ones and twos, should buffer */
-
 	done = 0;
 	while (done < len) {
 		result = write(outputfd, buf+done, len-done);
@@ -62,8 +64,10 @@
 	}
 }
 
+
+static
 void
-output(const struct place *p, const char *buf, size_t len)
+filter_output(const struct place *p, const char *buf, size_t len)
 {
 	size_t pos, start;
 	struct place p2;
@@ -97,7 +101,6 @@
 					dowrite(buf + start, pos - start);
 				}
 				start = pos;
-				pos += 2;
 				incomment = false;
 				/* cancel out the loop's pos++ */
 				pos--;
@@ -115,6 +118,30 @@
 }
 
 void
+output(const struct place *p, const char *buf, size_t len)
+{
+	if (linebufpos + len > linebufmax) {
+		if (linebufmax == 0) {
+			linebufmax = 64;
+		}
+		while (linebufpos + len > linebufmax) {
+			linebufmax *= 2;
+		}
+		linebuf = dorealloc(linebuf, linebufmax);
+	}
+	if (linebufpos == 0) {
+		linebufplace = *p;
+	}
+	memcpy(linebuf + linebufpos, buf, len);
+	linebufpos += len;
+
+	if (len == 1 && buf[0] == '\n') {
+		filter_output(&linebufplace, linebuf, linebufpos);
+		linebufpos = 0;
+	}
+}
+
+void
 output_eof(void)
 {
 	if (mode.output_file != NULL && outputfd >= 0) {