# HG changeset patch # User David A. Holland # Date 1292839278 18000 # Node ID 01c3a2088ab42030f6a36970be7b40e17c75bc2d # Parent ac45dcc57ff977e0e128c296b6dc016ac0aa30dd fix some more bugs diff -r ac45dcc57ff9 -r 01c3a2088ab4 macro.c --- 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; iparams, 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); } diff -r ac45dcc57ff9 -r 01c3a2088ab4 output.c --- 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 #include #include #include @@ -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) {