Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SohamG opened this issue Feb 12, 2022 · 2 comments
Open

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

SohamG opened this issue Feb 12, 2022 · 2 comments

Comments

@SohamG
Copy link

SohamG commented Feb 12, 2022

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?

@bakkeby
Copy link
Owner

bakkeby commented Feb 12, 2022

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
Copy link
Owner

bakkeby commented Feb 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants