As part of another thread (programming with the Standard Template Library (STL) ) I wanted to show how you could use STL in SMAUG.
However the initial problem was that SMAUG is written in C, not C++.
I have converted it to C++, however it was a tedious process - to say the least.
One major problem was the use of the word "class" (being the player's class) in many places in the source, however "class" is a reserved word in C++. Also, to a lesser extent, the use of the word "new".
This meant finding and replacing each word "class", however not inside comments or quoted strings, to "mudclass".
There were also other fixups to do with stricter checking of the "const" keyword, and various other fiddly things.
To save anyone else the trouble of doing it, the chanages are in this file:
This is a gzipped file of differences (context diffs), between the C source and the C++ source, for the version:
In other words, the Unix source of version 1.4a *with* the MXP patches.
If you try to apply it to the non-MXP version it should work, except that some patch hunks will fail, particularly in comm.c.
To apply, download the patch file, unzip it, and copy it to your "src" directory. Then type:
patch < smaug1.4a_mxp.cpp_diffs.txt
You should then be able to "make clean" and then "make".
In order to keep the same file names for patching purposes the C++ source files still end in .c, however once you have patched them you may wish to rename them as .cpp files.
Why convert?
Once you have SMAUG in C++ you can use STL which makes handling lists and vectors much easier, and gives you the "string" class which lets you handle string data without having to "malloc" and "free" all the time, and worry about strings overflowing their defined lengths.
However the converted version presented here is simply exactly the same code with the minimal modifications made to make it compile as a C++ project.
However the initial problem was that SMAUG is written in C, not C++.
I have converted it to C++, however it was a tedious process - to say the least.
One major problem was the use of the word "class" (being the player's class) in many places in the source, however "class" is a reserved word in C++. Also, to a lesser extent, the use of the word "new".
This meant finding and replacing each word "class", however not inside comments or quoted strings, to "mudclass".
There were also other fixups to do with stricter checking of the "const" keyword, and various other fiddly things.
To save anyone else the trouble of doing it, the chanages are in this file:
http://www.gammon.com.au/files/smaug/smaug1.4a_mxp.cpp_diffs.txt.gz
This is a gzipped file of differences (context diffs), between the C source and the C++ source, for the version:
http://www.gammon.com.au/files/smaug/smaug1.4a_mxp.tgz
In other words, the Unix source of version 1.4a *with* the MXP patches.
If you try to apply it to the non-MXP version it should work, except that some patch hunks will fail, particularly in comm.c.
To apply, download the patch file, unzip it, and copy it to your "src" directory. Then type:
patch < smaug1.4a_mxp.cpp_diffs.txt
You should then be able to "make clean" and then "make".
In order to keep the same file names for patching purposes the C++ source files still end in .c, however once you have patched them you may wish to rename them as .cpp files.
Why convert?
Once you have SMAUG in C++ you can use STL which makes handling lists and vectors much easier, and gives you the "string" class which lets you handle string data without having to "malloc" and "free" all the time, and worry about strings overflowing their defined lengths.
However the converted version presented here is simply exactly the same code with the minimal modifications made to make it compile as a C++ project.