8 const char* hexes
= "0123456789abcdef";
10 std::string
quote_c_string(const std::string
& raw
)
12 std::ostringstream out
;
22 else if(ch
< 32 || ch
== 127)
23 out
<< "\\x" << hexes
[ch
/ 16] << hexes
[ch
% 16];
31 void process_command_inverse(JSON::node
& n
, std::string name
, std::ostream
& imp
)
33 if(name
== "__mod" || n
.index_count() < 4)
35 auto& inv
= n
.index(3);
36 for(auto i
= inv
.begin(); i
!= inv
.end(); i
++) {
37 std::string args
= i
.key8();
38 std::string desc
= i
->as_string8();
40 imp
<< "\t" << quote_c_string(name
+ " " + args
) << ", " << quote_c_string(desc
) << ","
43 imp
<< "\t" << quote_c_string(name
) << ", " << quote_c_string(desc
) << "," << std::endl
;
47 bool is_crap_filename(const std::string
& arg
)
49 if(arg
.length() >= 4 && arg
.substr(arg
.length() - 4) == ".exe") return true;
50 if(arg
.length() >= 9 && arg
.substr(arg
.length() - 9) == "/mkstubsi") return true;
51 if(arg
== "mkstubsi") return true;
55 int main(int argc
, char** argv
)
57 std::ofstream
impl("inverselist.cpp");
58 impl
<< "#include \"cmdhelp/inverselist.hpp\"" << std::endl
;
59 impl
<< "namespace STUBS" << std::endl
;
60 impl
<< "{" << std::endl
;
61 impl
<< "const char* inverse_cmd_list[] = {" << std::endl
;
63 for(int i
= 1; i
< argc
; i
++) {
65 if(argv
[i
][0] == 0 || is_crap_filename(argv
[i
]))
67 std::ifstream
infile(argv
[i
]);
71 std::getline(infile
, tmp
);
72 in_json
= in_json
+ tmp
+ "\n";
74 JSON::node
n(in_json
);
75 for(auto j
= n
.begin(); j
!= n
.end(); j
++)
76 process_command_inverse(*j
, j
.key8(), impl
);
79 impl
<< "\t0\n};" << std::endl
;
80 impl
<< "}" << std::endl
;