Using the C preprocessor as an HTML templating engine
11–20 of 34 posts
Re: Using the C preprocessor as an HTML templating engine
#12https://news.ycombinator.com/item?id=39863492
Re: Using the C preprocessor as an HTML templating engine
#13IIRC the earliest version of the C++ language, before a C++ compiler existed, was implemented with C and the M4 preprocessor. https://en.wikipedia.org/wiki/M4_(computer_language) https://www.gnu.org/software/m4/
Re: Using the C preprocessor as an HTML templating engine
#14Or there's the opposite choice of using PHP as a C preprocessors. Not sure which is more frightening.
Re: Using the C preprocessor as an HTML templating engine
#15Why not go all out? Use -DUSERNAME=$USERNAME on the command line to pass in data? Define macros with parameters to affect rendering in complicated ways. Call cpp for every request to generate the html. Could be fun!
Re: Using the C preprocessor as an HTML templating engine
#16Re: Using the C preprocessor as an HTML templating engine
#17IIRC the earliest version of the C++ language, before a C++ compiler existed, was implemented with C and the M4 preprocessor. https://en.wikipedia.org/wiki/M4_(computer_language) https://www.gnu.org/software/m4/
Re: Using the C preprocessor as an HTML templating engine
#18Seems like a bad idea, given that the CPP and HTML have a fair number of overlapping tokens (e.g. `#` for both URL fragments and macro beginnings). Why not use SSI[1]? It's inspired by the CPP's syntax, but is supported directly by most HTTP servers (and is more powerful, to boot). [1]: https://en.wikipedia.org/wiki/Server_Side_Includes
Because hacking is fun, and it's still fun if it's a bad idea
Re: Using the C preprocessor as an HTML templating engine
#19IIRC the earliest version of the C++ language, before a C++ compiler existed, was implemented with C and the M4 preprocessor. https://en.wikipedia.org/wiki/M4_(computer_language) https://www.gnu.org/software/m4/
[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/m...
Re: Using the C preprocessor as an HTML templating engine
#20IIRC the earliest version of the C++ language, before a C++ compiler existed, was implemented with C and the M4 preprocessor. https://en.wikipedia.org/wiki/M4_(computer_language) https://www.gnu.org/software/m4/
Thank you, I did not know this. I was about to comment and say: Why not go with m4(1)? I have used it for a personal homepage and while it certainly will try to stab you in the back like any old macro processor will, it is more full-fledged that its C counterpart and will also allow to to smugly state that your homepage is POSIX compliant [1]. There are a few guides out there from around 2000 to get you started, but…
1. built-in macro names that require arguments such as `define' are not "expanded" if you don't follow them with parentheses
2. there's an option to require a magic sigil character to invoke macros, such as % or something; this turns out to have been required in the original gpm and its bell labs clone m6. this helps enormously with complicated macros
however, the fact that the output of your macro is always immediately run as new code (as opposed to m6 and gpm, where this was optional on a per-call basis) makes m4 just ridiculously error-prone. i feel like trauma from debugging m4 macros was a major consideration in the design of the weak-ass c preprocessor