BitShares/bitshares_toolkit — pull request #739 by drltc (2014-09-02 15:34:25+00:00)
Title: Refactor bts_genesis_to_cpp.cpp to use template prologue and epilogue

The `genesis,json` to `genesis_json.cpp` process consists of the following:

- Convert a JSON object into a C++ string literal (or sequence of string literals if you have a buggy compiler, see #738 )
- Write that C++ string literal into a source file, along with some declaration and other code needed to make it useful

Instead of having the declaration part hard-coded in `bts_genesis_to_cpp`, this pull request moves it into two separate files, `genesis.prologue` and `genesis.epilogue` [1]. The benefits of this are as follows:

- No longer need to escape special characters
- We can now use the `bts_genesis_to_cpp` binary unmodified if we ever want to embed other JSON data in the executable. Just change the command line arguments to use different template files!

Because of the second thing, I've added another commit which renames the utility to `bts_json_to_cpp` so the name more accurately reflects the new functionality.

I also changed the CLI parameter names a little bit. I don't think it matters much because AFAIK the only user of this utility is our own build process.

To verify the functionality of this patch, try the following:

# build without this pull request, then...
mv libraries/blockchain/genesis_json.cpp genesis_json.old.cpp
# build with this patch
diff -u genesis_json.old.cpp libraries/blockchain/genesis_json.cpp

The only difference between the two files will be the name of the generating program (which is located inside a comment).

[1] I call these "template files" because I use `format_string` to do variable substitution, i.e. the `${source_file_name}` in `genesis.prologue` is expanded like you would expect.