# HG changeset patch # User David A. Holland # Date 1434091084 14400 # Node ID ffdb0b73856fbbc85dc64bcd082eea2704e232c0 # Parent 09cfad6772de0c334a6fc955e2fa2e7ceb970d5f Suppress blank lines later. Fixes the rest of the bizarre spacing behavior described in changeset 82cc6fa54b01. Expand t39 to cover more cases, too. diff -r 09cfad6772de -r ffdb0b73856f directive.c --- a/directive.c Fri Jun 12 02:21:28 2015 -0400 +++ b/directive.c Fri Jun 12 02:38:04 2015 -0400 @@ -638,7 +638,7 @@ } /* check if we have a directive line (# exactly in column 0) */ - if (line[0] == '#') { + if (len > 0 && line[0] == '#') { skip = 1 + strspn(line + 1, ws); assert(skip <= len); lp->current.column += skip; diff -r 09cfad6772de -r ffdb0b73856f files.c --- a/files.c Fri Jun 12 02:21:28 2015 -0400 +++ b/files.c Fri Jun 12 02:38:04 2015 -0400 @@ -274,11 +274,8 @@ /* count how many commented-out newlines we swallowed */ places.nextline.line += countnls(buf, linestart, lineend); - /* if the line isn't empty, process it */ - if (lineend > linestart) { - directive_gotline(&places, - buf+linestart, lineend-linestart); - } + /* process the line (even if it's empty) */ + directive_gotline(&places, buf+linestart, lineend-linestart); linestart = nextlinestart; lineend = findeol(buf, linestart, bufend); diff -r 09cfad6772de -r ffdb0b73856f macro.c --- a/macro.c Fri Jun 12 02:21:28 2015 -0400 +++ b/macro.c Fri Jun 12 02:38:04 2015 -0400 @@ -1246,11 +1246,22 @@ doexpand(&mainstate, p, buf, len); switch (mainstate.state) { case ES_NORMAL: - output(p, "\n", 1); + /* + * If we were sent a blank line, don't emit a newline + * for it. This matches the prior behavior of tradcpp. + */ + if (len > 0) { + output(p, "\n", 1); + } break; case ES_WANTLPAREN: case ES_NOARG: case ES_HAVEARG: + /* + * Apparently to match gcc's -traditional behavior we + * need to emit a space for each newline that appears + * while processing macro args. + */ expand_got_ws(&mainstate, p, " ", 1); break; } diff -r 09cfad6772de -r ffdb0b73856f tests/t39.c --- a/tests/t39.c Fri Jun 12 02:21:28 2015 -0400 +++ b/tests/t39.c Fri Jun 12 02:38:04 2015 -0400 @@ -1,3 +1,21 @@ #define m(a,b) a::b =m(123, 456) + ------ +=m +(123, 456) + ------ +=m( +123, 456) + ------ +=m( +123, +456 +) + ------ +=m(123, + +456) + ------ +=m(123, + 456) diff -r 09cfad6772de -r ffdb0b73856f tests/t39.good --- a/tests/t39.good Fri Jun 12 02:21:28 2015 -0400 +++ b/tests/t39.good Fri Jun 12 02:38:04 2015 -0400 @@ -1,1 +1,11 @@ =123:: 456 + ------ +=123:: 456 + ------ += 123:: 456 + ------ += 123:: 456 + ------ +=123:: 456 + ------ +=123:: 456