| 6 | #include <sstream> |
| 7 | |
| 8 | void buildLoader(const std::string& input, const std::string& output) |
| 9 | { |
| 10 | std::ofstream outfile(output.c_str()); |
| 11 | |
| 12 | std::string jsBuff = loadFile(input); |
| 13 | |
| 14 | json_value *root = json_parse(jsBuff.c_str(), jsBuff.size()); |
| 15 | if (root) { |
| 16 | json_value *function_root = get_object_key(root, "functions"); |
| 17 | |
| 18 | assert(function_root->type == json_array); |
| 19 | |
| 20 | for (auto& it: jsonArrayIterator(function_root)) |
| 21 | { |
| 22 | std::string comment = get_object_string_key(it, "_comment"); |
| 23 | if (!comment.empty()) { |
| 24 | outfile << "// Comment " << comment << "\n"; |
| 25 | } |
| 26 | std::string funcname = get_object_string_key(it, "functionname"); |
| 27 | std::string returntype = get_object_string_key(it, "returntype"); |
| 28 | if (!funcname.empty() && !returntype.empty()) { |
| 29 | json_value* params = get_object_key(it, "params"); |
| 30 | outfile << "#ifndef HUMBLENET_SKIP_" << funcname << "\n"; |
| 31 | std::stringstream ss; |
| 32 | ss << "LOADER_PROC("; |
| 33 | ss << returntype; |
| 34 | ss << ","; |
| 35 | ss << funcname; |
| 36 | ss << ","; |
| 37 | if (params) { |
| 38 | ss << "("; |
| 39 | std::stringstream argss; |
| 40 | for (auto& pit : jsonArrayIterator(params)) |
| 41 | { |
| 42 | std::string paramtype = get_object_string_key(pit, "paramtype"); |
| 43 | std::string paramname = get_object_string_key(pit, "paramname"); |
| 44 | ss << paramtype << " " << paramname << ","; |
| 45 | argss << paramname << ","; |
| 46 | } |
| 47 | ss.seekp(-1, std::ios_base::cur); |
| 48 | ss << "),("; |
| 49 | ss << argss.str(); |
| 50 | ss.seekp(-1, std::ios_base::cur); |
| 51 | ss << "),"; |
| 52 | } else { |
| 53 | ss << "(void),(),"; |
| 54 | } |
| 55 | if (returntype != "void") { |
| 56 | ss << "return"; |
| 57 | } |
| 58 | ss << ")\n"; |
| 59 | |
| 60 | outfile << ss.str() << "#endif\n"; |
| 61 | } |
| 62 | } |
| 63 | json_value_free(root); |
| 64 | } else { |
| 65 | die("Unable to parse JSON file"); |
no test coverage detected