8 const char* hexes
= "0123456789abcdef";
10 std::string
quote_c_string(const std::string
& raw
, bool hiraw
= false);
12 std::string
quote_c_string(const std::string
& raw
, bool hiraw
)
14 std::ostringstream out
;
24 else if(ch
< 32 || ch
== 127 || (ch
> 127 && !hiraw
))
25 out
<< "\\x" << hexes
[ch
/ 16] << hexes
[ch
% 16];
33 void process_command_inverse(JSON::node
& n
, std::ostream
& imp
)
35 if(!n
.field_exists("__inverse"))
37 auto& inv
= n
["__inverse"];
38 auto name
= n
["__name"].as_string8();
39 for(auto i
= inv
.begin(); i
!= inv
.end(); i
++) {
40 std::string args
= i
.key8();
41 std::string desc
= i
->as_string8();
43 imp
<< "\t" << quote_c_string(name
+ " " + args
) << ", " << quote_c_string(desc
, true) << ","
46 imp
<< "\t" << quote_c_string(name
) << ", " << quote_c_string(desc
, true) << "," << std::endl
;
50 int main(int argc
, char** argv
)
52 std::ofstream
impl("inverselist.cpp");
53 impl
<< "#include \"cmdhelp/inverselist.hpp\"" << std::endl
;
54 impl
<< "namespace STUBS" << std::endl
;
55 impl
<< "{" << std::endl
;
56 impl
<< "const char* inverse_cmd_list[] = {" << std::endl
;
58 for(int i
= 1; i
< argc
; i
++) {
60 if(argv
[i
][0] == 0 || argv
[i
][strlen(argv
[i
])-1] == 'e')
62 std::ifstream
infile(argv
[i
]);
66 std::getline(infile
, tmp
);
67 in_json
= in_json
+ tmp
+ "\n";
69 JSON::node
n(in_json
);
70 for(auto j
= n
.begin(); j
!= n
.end(); j
++)
71 process_command_inverse(*j
, impl
);
74 impl
<< "\t0\n};" << std::endl
;
75 impl
<< "}" << std::endl
;