You will find a script written in Python called CppMunge.py (it needs v2.3 or later of
Python installed). While use of it is optional, it does make your life a good deal easier and TnFOX itself uses it. It provides the following features:
- Extraction and allocation of error code macros
Now you no longer need to concern yourself with allocating constants to error code macros. Simply write in your macro name and include the header file "ErrCodes.h" at the top of each of your exception using source files and CppMunge.py takes care of allocating your exception a unique number it will maintain for the rest of its life. #include "FXException.h"
#include "ErrCodes.h"
...
FXERRH(file.exists(), tr("File does not exist"), MYCLASS_FILENOTFOUND, 0);
TnFOX's own error codes list is in FXErrCodes.h
. Note that once allocated, a constant remains forever so you need to remove them manually from FXErrCodes.h
if you need to. Bear in mind the number will then be reused, so you may wish to call it RESERVEDx or something to avoid breaking binary compatibility.
- Implementation of TnFOX's nested exception handling support
More about this can be found at the documentation page of FX::FXException. Basically it wraps all your destructors (unless marked with throw()
or FXERRH_NODESTRUCTORMOD
) with the run-time support code necessary for nested exception handling.
- Extraction of text literals delimited by
tr()
You will certainly want to run all your source through the utility and have it generate a skeleton translation file for you to translate rather than do it yourself. CppMunge is intelligent and can add in and demarcate for translation newly added text literals by the programmer in all supported languages. To add a new language, simply add to the language id list at the top of the file and CppMunge will add in "!TODO!" literals where you need to add them. - Warning:
- You should keep a backup of the translation file as typing mistakes in your source can cause CppMunge to remove translations on you.
Installation:
CppMunge was designed to modify in-place C++ source without making its changes too noticeable. A previous solution generated a separate output file which had the problem of debugging referring to the wrong source file plus I myself kept altering the munged copy to fix bugs rather than its original. This new solution is much more convenient.
However it can slow things down a bit as the translation & error codes file needs to be loaded, decoded, modified and written out for each and every source file compiled. To avoid this I wrote another python script called UpdateMunged.py
which simply scans the source directory and if any munged files are newer than a time stamp file, it calls CppMunge.py
on them as a child process. To permit UpdateMunged to distinguish between mungeable files and normal ones, munged files use a
.cxx extension rather than
.cpp. Further optimisations include CppMunge not writing out anything unless it has changed.
You can disable features in either utility via commmand line options - try running CppMunge.py with -help
to see what options it supports.
- Note:
- The C++ parser used by CppMunge is extremely simple and likely to get confused by anything complicated so do not modify the lines it changes AT ALL. You might also want to keep method definitions well spaced and on separate lines like I naturally tend to write my C++!