Hello!
After seeing the recent hype towards debugging utils and code snippets usage and what not, and due to the fact that I had 30 minutes of free time to spend this afternoon, I decided to write a small Python script that pre-compiles multiple files into one big file for Codeforces submission.
The tool is here: https://pastebin.com/c4dS4Pik (Python 3 required)
Basically the tool does these steps:
- remove the
#include <bla>
lines from the code - run the GCC preprocessor on the code
- add the
#include <bla>
lines back - run some cleanup routine (optional)
In order to use this script, copy it somewhere (preferably in your PATH directory), and run it using: /path/to/scr.py file.cpp [ARGS]
The ARGS
are similar to the ones you would give to your g++
command.
For example, let's say we have three files:
Output of /path/to/scr.py sol.cpp
:
Output of /path/to/scr.py sol.cpp -DDEBUG
:
The main idea is that it merges all your #include "bla"
files (not the #include <bla>
ones, though), and replaces all the #define
s and other preprocessor instructions.
Let me know what you think! The tool should work fine in UNIX-based systems (Mac OS X, Linux). I would be happy if someone could test/port this tool for Windows. I think one cool thing about this tool is that it pre-compiles all the #define
s, so that most of the output code would look more standardized (C++-ish).
I would personally probably not use this tool too much, as my general approach is to copy-paste implementations and tweak them to the specific problem, but I know a lot of people prefer to use them as black boxes, so this might be useful.