Automatic pre-compiler for submitting tasks on Codeforces

Правка en5, от bicsi, 2020-06-29 17:26:03

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:

FILE: debug.hpp
FILE: dsu.hpp
FILE: sol.cpp

Output of /path/to/scr.py sol.cpp:

OUTPUT

Output of /path/to/scr.py sol.cpp -DDEBUG:

OUTPUT

The main idea is that it merges all your #include "bla" files (not the #include <bla> ones, though), and replaces all the #defines 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 #defines, 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.

Теги debugging, #tool, script

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский bicsi 2020-06-29 17:26:03 16 Script now shouldn't discard comments.
en4 Английский bicsi 2020-06-29 16:59:46 27 Tiny change: 'e code\n- precompile the code\' -> 'e code\n- run the GCC preprocessor on the code\'
en3 Английский bicsi 2020-06-29 16:59:04 2 Tiny change: 'e steps:\n- remove' -> 'e steps:\n\n- remove'
en2 Английский bicsi 2020-06-29 16:58:34 18 Tiny change: 'tebin.com/4icsFNWP (Python 3' -> 'tebin.com/CR0mJXbR (Python 3'
en1 Английский bicsi 2020-06-29 16:52:36 4693 Initial revision (published)