Skip to content

Commit

Permalink
XML2GFF: Add xml2gff tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Oct 14, 2018
1 parent 348174c commit d395d61
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Makefile.in
/src/gff2xml
/src/tlk2xml
/src/ssf2xml
/src/xml2gff
/src/xml2tlk
/src/xml2ssf
/src/convert2da
Expand All @@ -112,6 +113,7 @@ Makefile.in
/src/gff2xml.exe
/src/tlk2xml.exe
/src/ssf2xml.exe
/src/xml2gff.exe
/src/xml2tlk.exe
/src/xml2ssf.exe
/src/convert2da.exe
Expand Down
13 changes: 13 additions & 0 deletions src/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ src_tws_LDADD = \
$(LDADD) \
$(EMPTY)

bin_PROGRAMS += src/xml2gff
src_xml2gff_SOURCES = \
src/xml2gff.cpp \
src/util.cpp \
$(EMPTY)
src_xml2gff_LDADD = \
src/xml/libxml.la \
src/aurora/libaurora.la \
src/common/libcommon.la \
src/version/libversion.la \
$(LDADD) \
$(EMPTY)

# Subdirectories

include src/version/rules.mk
Expand Down
112 changes: 112 additions & 0 deletions src/xml2gff.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* xoreos-tools - Tools to help with xoreos development
*
* xoreos-tools is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos-tools is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos-tools. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Tool to convert XML files back into GFF.
*/

#include "src/version/version.h"

#include "src/common/scopedptr.h"
#include "src/common/ustring.h"
#include "src/common/util.h"
#include "src/common/strutil.h"
#include "src/common/error.h"
#include "src/common/platform.h"
#include "src/common/readfile.h"
#include "src/common/writefile.h"
#include "src/common/stdinstream.h"
#include "src/common/encoding.h"
#include "src/common/cli.h"

#include "src/aurora/types.h"

#include "src/xml/gffcreator.h"

#include "src/util.h"

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

void createGFF(const Common::UString &inFile, const Common::UString &outFile);

int main(int argc, char **argv) {
initPlatform();

try {
std::vector<Common::UString> args;
Common::Platform::getParameters(argc, argv, args);

int returnValue = 1;
Common::UString inFile, outFile;

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

createGFF(inFile, outFile);
} catch (...) {
Common::exceptionDispatcherError();
}

return 0;
}

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

using Common::CLI::NoOption;
using Common::CLI::kContinueParsing;
using Common::CLI::Parser;
using Common::CLI::ValGetter;
using Common::CLI::ValAssigner;
using Common::CLI::makeEndArgs;
using Common::CLI::makeAssigners;
std::vector<Common::UString> args;
NoOption filesOpt(false, new ValGetter<std::vector<Common::UString> &>(args,
"[input file] <output file>"));
Parser parser(argv[0], "XML to BioWare GFF converter",
"If no input file is given, the input is read from stdin.\n\n"
"The toplevel XML tag determines, if a GFF3 or GFF4 file will be written\n"
"and the type property determines which GFF id will be written. If a more\n"
"then 4 letter id is written it will be cut to 4 letters.",
returnValue,
makeEndArgs(&filesOpt));

if (!parser.process(argv))
return false;

if (args.size() == 2) {
inFile = args[0];
outFile = args[1];
} else
outFile = args[0];

return true;
}

void createGFF(const Common::UString &inFile, const Common::UString &outFile) {
Common::WriteFile gff(outFile);
Common::ScopedPtr<Common::ReadStream> xml(openFileOrStdIn(inFile));

XML::GFFCreator::create(gff, *xml, inFile);

gff.flush();
gff.close();
}

0 comments on commit d395d61

Please sign in to comment.