Refactor c code generator

It's been rewritten in a less functional style. String copies were actually
taking significant time for large parsers.
Trim trailing whitespace