5 #include <boost/filesystem/convenience.hpp>
14 #define NO_TAGBLOCKS 11
15 const char *tagblocks
[NO_TAGBLOCKS
] = {
22 "EXPC", // C3 creature info
23 "DSEX", // DS creature info
24 "SFAM", // C3 starter family
26 "DFAM" // DS starter family
29 int main(int argc
, char **argv
) {
30 bool outputfiles
= true, notags
= false, usageerror
= false;
32 while ((ch
= getopt(argc
, argv
, "on")) != -1) {
34 case 'o': outputfiles
= false; break;
35 case 'n': notags
= true; break;
36 default: usageerror
= true; break;
41 if ((argc
!= 1) || usageerror
) {
42 cerr
<< "syntax: praydumper -o -n filename\n-o don't output non-tag blocks as files\n-n do not interpret tag blocks" << endl
;
46 fs::path inputfile
= fs::path(argv
[0], fs::native
);
47 if (!fs::exists(inputfile
)) {
48 cerr
<< "input file doesn't exist!" << endl
;
52 cout
<< "(- praydumper-generated PRAY file from '" << argv
[0] << "' -)" << endl
;
53 cout
<< endl
<< "\"en-GB\"" << endl
;
54 prayFile
file(inputfile
);
56 for (vector
<prayBlock
*>::iterator x
= file
.blocks
.begin(); x
!= file
.blocks
.end(); x
++) {
57 // TODO: s/"/\\"/ in the data (use find/replace methods of string)
62 for (unsigned int i
= 0; i
< NO_TAGBLOCKS
; i
++) {
63 if ((*x
)->type
== tagblocks
[i
]) {
65 cout
<< endl
<< "group " << (*x
)->type
<< " \"" << (*x
)->name
<< "\"" << endl
;
69 for (std::map
<std::string
, int>::iterator y
= (*x
)->integerValues
.begin(); y
!= (*x
)->integerValues
.end(); y
++) {
70 cout
<< "\"" << y
->first
<< "\" " << y
->second
<< endl
;
73 for (std::map
<std::string
, std::string
>::iterator y
= (*x
)->stringValues
.begin(); y
!= (*x
)->stringValues
.end(); y
++) {
74 std::string name
= y
->first
;
75 if ((name
.substr(0, 7) == "Script ") || (name
.substr(0, 13) == "Remove script")) {
76 name
= (*x
)->name
+ " - " + name
+ ".cos";
77 ofstream
output(name
.c_str());
78 output
.write(y
->second
.c_str(), y
->second
.size());
79 cout
<< "\"" << y
->first
<< "\" @ \"" << name
<< "\"" << endl
;
81 cout
<< "\"" << y
->first
<< "\" \"" << y
->second
<< "\"" << endl
;
88 cout
<< endl
<< "inline " << (*x
)->type
<< " \"" << (*x
)->name
<< "\" \"" << (*x
)->name
<< "\"" << endl
;
91 ofstream
output((*x
)->name
.c_str());
92 output
.write((char *)(*x
)->getBuffer(), (*x
)->getSize());