Using GNU CPP with SPIN
jazzed
Posts: 11,803
GNU cpp is a powerful variant of the C pre-processor. The cpp program can be used with SPIN to generate custom SPIN files that can be compiled with any tool such as Propeller Tool, Propellent, Homespun, and BST/BSTC. Homespun and BST/BSTC have built-in pre-processor ability and should be considered by those who are not held hostage by some notion of maintaining Parallax purity.
Today Homespun supports common pre-processor items such as #define, #define SYMBOL VALUE, #ifdef (but not #ifndef), #ifdef, #elseifdef (but not #elseif), #endif, and #include.
BST/BSTC supports common pre-processor items such as simple #define, #ifdef, #ifndef, #ifdef, #elseifdef (but not #elseif), and #endif. The #include tag is not supported.
Propeller Tool and Propellent does not support any pre-processor syntax at all. Using cpp can help this. There was also another tool that provides some independent pre-processor support, but I can't find it and as I remember, it did not have a good feature set.
Getting CPP
The easiest way to get GNU cpp (and the iconv utility for converting Parallax font spin files to utf8 text) is to install cygwin on your system. Installing MinGW is another option. Generally, one should not install cygwin and MinGW on the same computer.
Cygwin is a unix like environment for Windows computers. Many useful dev tools are available with Cygwin. Go to www.cygwin.com and read about this option.
MinGW is a windows environment that includes GNU tools. It will take as much effort to install MinGW as Cygwin. Go to www.mingw.com to read about this option. MinGW software is downloaded from sourceforge.net/projects/mingw via the mingw-get-inst package.
I don't have time to give detailed instructions for all of this.
Using CPP
Once you have the tools (or patience to get this far), use cpp with SPIN by the command:
cpp -p --traditional-cpp spinfile.spin
If your spinfile has Parallax font, use iconv to make spinfile.spin usable with the command:
iconv -futf16 -tutf8 spinfile.spin > utf8_spinfile.spin
The documentation for GNU CPP is found here: http://gcc.gnu.org/onlinedocs/cpp
GNU CPP is powerful because of support for many options. The most common items mentioned above for Homespun and BST/BSTC are supported by GNU CPP, but there is so much more. It's best to focus on using the common items if possible.
Searching for simpler solutions?
Catalina has a cpp.exe, but it does not provide a way to suppress "#line" messages.
Catalina install is much faster than Cygwin or MinGW.
The source for a version of cpp used in Catalina is here: https://github.com/drh/lcc/tree/master/cpp
The adventurous could probably make a stand-alone windows application with this to save lots of pain. I would do it, but don't have time just now.
Linux offers the simplest solution of all. Just install the program
Today Homespun supports common pre-processor items such as #define, #define SYMBOL VALUE, #ifdef (but not #ifndef), #ifdef, #elseifdef (but not #elseif), #endif, and #include.
BST/BSTC supports common pre-processor items such as simple #define, #ifdef, #ifndef, #ifdef, #elseifdef (but not #elseif), and #endif. The #include tag is not supported.
Propeller Tool and Propellent does not support any pre-processor syntax at all. Using cpp can help this. There was also another tool that provides some independent pre-processor support, but I can't find it and as I remember, it did not have a good feature set.
Getting CPP
The easiest way to get GNU cpp (and the iconv utility for converting Parallax font spin files to utf8 text) is to install cygwin on your system. Installing MinGW is another option. Generally, one should not install cygwin and MinGW on the same computer.
Cygwin is a unix like environment for Windows computers. Many useful dev tools are available with Cygwin. Go to www.cygwin.com and read about this option.
MinGW is a windows environment that includes GNU tools. It will take as much effort to install MinGW as Cygwin. Go to www.mingw.com to read about this option. MinGW software is downloaded from sourceforge.net/projects/mingw via the mingw-get-inst package.
I don't have time to give detailed instructions for all of this.
Using CPP
Once you have the tools (or patience to get this far), use cpp with SPIN by the command:
cpp -p --traditional-cpp spinfile.spin
If your spinfile has Parallax font, use iconv to make spinfile.spin usable with the command:
iconv -futf16 -tutf8 spinfile.spin > utf8_spinfile.spin
The documentation for GNU CPP is found here: http://gcc.gnu.org/onlinedocs/cpp
GNU CPP is powerful because of support for many options. The most common items mentioned above for Homespun and BST/BSTC are supported by GNU CPP, but there is so much more. It's best to focus on using the common items if possible.
Searching for simpler solutions?
Catalina has a cpp.exe, but it does not provide a way to suppress "#line" messages.
Catalina install is much faster than Cygwin or MinGW.
The source for a version of cpp used in Catalina is here: https://github.com/drh/lcc/tree/master/cpp
The adventurous could probably make a stand-alone windows application with this to save lots of pain. I would do it, but don't have time just now.
Linux offers the simplest solution of all. Just install the program
Comments
[...]
Wherever possible, you should use a preprocessor geared to the language you are writing in.
[...]
If all else fails, try a true general text processor, such as GNU M4.
http://gcc.gnu.org/onlinedocs/cpp/Overview.html#Overview
I'm very happy with cpp using the "-p --traditional" flags. You can't please everyone though. Of course some folks don't really want to be pleased in the first place. It's easy to come up with excuses, solutions take effort. Since we have the source to cpp ala lcc, there is no risk in making that fit our needs if it can be built.
Cluso99, #define SYMBOL with cpp is a macro for string replacement. In the case of #define SYMBOL, the string is nothing. "#define PMOV(d,s) mov d, s" should of course look familiar.
I'm sure m4 can do more.
Leon you should provide some interesting m4 examples for us since you are keen on the solution.