flexipatch-finalizer icon indicating copy to clipboard operation
flexipatch-finalizer copied to clipboard

[Suggestion] Use the `cpp` command (C Pre Processor)

Open SohamG opened this issue 3 years ago • 2 comments

I recently wanted to get rid of the cruft from my config.h removing all the conditional lines. I instinctively used cpp feeding it patches.h for the macros and telling it to retain comments to get the desired result.

I ran something like this:

cpp config.h.old -imacros patches.h -C -o config.h

I then realized I couldve used this script and out of curiosity I checked the implementation.

IDK if this project is actively developed, but perhaps the ginormous awk program can be shortened with cpp?

SohamG avatar Feb 12 '22 18:02 SohamG

Thanks for the suggestion, and the tip. Yes I think the whole script can be simplified with this so I shall have a closer look at my earliest convenience.

I was actually looking for something like this back when I wrote the finalizer but didn't come across cpp in my searches, hence the rather complicated awk script.

At first glance I don't foresee any complications using cpp for the bulk work.

bakkeby avatar Feb 12 '22 20:02 bakkeby

I have had a closer look and using cpp is not that straightforward as I first thought.

The key is that we will want to preprocess only the directives that are present in patches.h and leave everything else as-is. Using cpp I end up with a dwm.c that has more than 24K lines including everything from /usr/include/X11/Xft/Xft.h and all related libraries.

From the man page:

The cpp command expects two file names as arguments, infile and outfile. The preprocessor reads infile together with any other file s it specifies with #include. All the output generated by the combined input files is written in outfile.

I didn't see any way around this based on the command line options. Possibly it might be possible with another preprocessor tool. I tried m4 but that is not designed for this.

bakkeby avatar Feb 22 '22 09:02 bakkeby