Skip to content

Instantly share code, notes, and snippets.

@alexjurkiewicz
Created February 6, 2019 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexjurkiewicz/401e66fca7f3c232e3ddd90a2bfea505 to your computer and use it in GitHub Desktop.
Save alexjurkiewicz/401e66fca7f3c232e3ddd90a2bfea505 to your computer and use it in GitHub Desktop.
$ nice make -j8 debug
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C rltiles all ARCH=x86_64-apple-darwin18.2.0 NO_PKGCONFIG=Yes TILES=
* If you experience any problems building Crawl, please take a second look
* at INSTALL.txt: the solution to your problem just might be in there!
LINK crawl
Undefined symbols for architecture x86_64:
"branch_data_json()", referenced from:
parse_args(int, char**, bool) in initfile.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [crawl] Error 1
diff --git a/crawl-ref/source/branch-data-json.cc b/crawl-ref/source/branch-data-json.cc
new file mode 100644
index 0000000000..af23f708e1
--- /dev/null
+++ b/crawl-ref/source/branch-data-json.cc
@@ -0,0 +1,32 @@
+/**
+ * @file
+ * @brief Provide branch data as JSON
+ */
+
+#include "AppHdr.h"
+
+#include "branch-data-json.h"
+
+#include "json.h"
+#include "json-wrapper.h"
+
+#include "branch.h"
+#include "stringutil.h" // to_string on Cygwin
+
+static JsonNode *_branch_info_array()
+{
+ JsonNode *branches(json_mkarray());
+ for (branch_iterator it; it; ++it)
+ {
+ JsonNode *branch_info(json.mkobject());
+ json_append_member(branch_info, "name", json_mkstring(branch->shortname));
+ }
+ return branches;
+}
+
+string branch_data_json()
+{
+ JsonWrapper json(json_mkobject());
+ json_append_member(json.node, "branches", _branch_info_array());
+ return json.to_string();
+}
diff --git a/crawl-ref/source/branch-data-json.h b/crawl-ref/source/branch-data-json.h
new file mode 100644
index 0000000000..6211d766ad
--- /dev/null
+++ b/crawl-ref/source/branch-data-json.h
@@ -0,0 +1,3 @@
+#pragma once
+
+string branch_data_json();
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index a2e70c7f3a..73546266e5 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -22,6 +22,7 @@
#include <set>
#include <string>
+#include "branch-data-json.h"
#include "chardump.h"
#include "clua.h"
#include "colour.h"
@@ -3828,6 +3829,7 @@ enum commandline_option_type
CLO_THROTTLE,
CLO_NO_THROTTLE,
CLO_PLAYABLE_JSON, // JSON metadata for species, jobs, combos.
+ CLO_BRANCH_DATA_JSON, // JSON metadata for branches.
CLO_EDIT_BONES,
#ifdef USE_TILE_WEB
CLO_WEBTILES_SOCKET,
@@ -3846,7 +3848,7 @@ static const char *cmd_ops[] =
"builddb", "help", "version", "seed", "save-version", "sprint",
"extra-opt-first", "extra-opt-last", "sprint-map", "edit-save",
"print-charset", "tutorial", "wizard", "explore", "no-save", "gdb",
- "no-gdb", "nogdb", "throttle", "no-throttle", "playable-json",
+ "no-gdb", "nogdb", "throttle", "no-throttle", "playable-json", "branch-data-json",
"bones",
#ifdef USE_TILE_WEB
"webtiles-socket", "await-connection", "print-webtiles-options",
@@ -4759,6 +4761,10 @@ bool parse_args(int argc, char **argv, bool rc_only)
fprintf(stdout, "%s", playable_metadata_json().c_str());
end(0);
+ case CLO_BRANCH_DATA_JSON:
+ fprintf(stdout, "%s", branch_data_json().c_str());
+ end(0);
+
case CLO_TEST:
crawl_state.test = true;
if (next_is_param)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment