Skip to content

Commit

Permalink
FIXNWN2XML: Convert input stream to output stream
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshae authored and DrMcCoy committed Oct 28, 2018
1 parent b0e1358 commit 0756b5b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/fixnwn2xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@
#include "src/common/writefile.h"
#include "src/common/filepath.h"
#include "src/common/memreadstream.h"
#include "src/common/stdoutstream.h"

#include "src/aurora/xmlfixer.h"

bool parseCommandLine(const std::vector<Common::UString> &argv, int &returnValue,
Common::UString &inFile, Common::UString &outFile);

void convert(Common::UString &inFile, Common::UString &outFile);


int main(int argc, char **argv) {
initPlatform();
Expand All @@ -60,6 +63,8 @@ int main(int argc, char **argv) {

if (!parseCommandLine(args, returnValue, inFile, outFile))
return returnValue;

convert(inFile, outFile);
} catch (...) {
Common::exceptionDispatcherError();
}
Expand All @@ -80,3 +85,22 @@ bool parseCommandLine(const std::vector<Common::UString> &argv, int &returnValue
makeEndArgs(&inFileOpt, &outFileOpt));
return parser.process(argv);
}

/*
* Read in the input file, apply XML format corrections, then write to output file.
*/
void convert(Common::UString &inFile, Common::UString &outFile) {
// Read the input file into memory
Common::ScopedPtr<Common::SeekableReadStream> in(Common::ReadFile::readIntoMemory(inFile));
Common::ScopedPtr<Common::WriteStream> out(openFileOrStdOut(outFile));

// Filter the input
Common::ReadStream *fixed = Aurora::XMLFixer::fixXMLStream(*in);

// Write to output
out->writeStream(*fixed);
out->flush();

if (!outFile.empty())
status("Converted \"%s\" to \"%s\"", inFile.c_str(), outFile.c_str());
}

0 comments on commit 0756b5b

Please sign in to comment.