Skip to content

Commit

Permalink
NBFS2TGA: Use CLI class
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo-ray authored and DrMcCoy committed Apr 13, 2017
1 parent e094252 commit 746016d
Showing 1 changed file with 17 additions and 60 deletions.
77 changes: 17 additions & 60 deletions src/nbfs2tga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "src/common/error.h"
#include "src/common/platform.h"
#include "src/common/readfile.h"
#include "src/common/cli.h"

#include "src/aurora/types.h"
#include "src/aurora/util.h"
Expand Down Expand Up @@ -76,66 +77,22 @@ bool parseCommandLine(const std::vector<Common::UString> &argv, int &returnValue
Common::UString &nbfsFile, Common::UString &nbfpFile,
Common::UString &outFile, uint32 &width, uint32 &height) {

std::vector<Common::UString> args;

bool optionsEnd = false;
for (size_t i = 1; i < argv.size(); i++) {
// A "--" marks an end to all options
if (argv[i] == "--") {
optionsEnd = true;
continue;
}

// We're still handling options
if (!optionsEnd) {
// Help text
if ((argv[i] == "-h") || (argv[i] == "--help")) {
printUsage(stdout, argv[0]);
returnValue = 0;

return false;
}

if (argv[i] == "--version") {
Version::printVersion();
returnValue = 0;

return false;
}

if (argv[i].beginsWith("-") || argv[i].beginsWith("--")) {
// An options, but we already checked for all known ones

printUsage(stderr, argv[0]);
returnValue = 1;

return false;
}
}

args.push_back(argv[i]);
}

if ((args.size() < 3) || (args.size() > 5)) {
printUsage(stderr, argv[0]);
returnValue = 1;

return false;
}


nbfsFile = args[0];
nbfpFile = args[1];
outFile = args[2];

width = height = 0xFFFFFFFF;

if (args.size() > 3)
width = atoi(args[3].c_str());
if (args.size() > 4)
height = atoi(args[4].c_str());

return true;
using Common::CLI::Parser;
using Common::CLI::ValGetter;
using Common::CLI::NoOption;
using Common::CLI::makeEndArgs;
using Common::CLI::kContinueParsing;
std::vector<Common::CLI::Getter *> getters;
NoOption nbfsFileOpt(false, new ValGetter<Common::UString &>(nbfsFile, "nbfs"));
NoOption nbfpFileOpt(false, new ValGetter<Common::UString &>(nbfpFile, "nbfp"));
NoOption outFileOpt(false, new ValGetter<Common::UString &>(outFile, "tga"));
NoOption widthOpt(true, new ValGetter<uint32 &>(width, "width"));
NoOption heightOpt(true, new ValGetter<uint32 &>(height, "height"));
Parser parser(argv[0], "Nintendo raw NBFS image to TGA converter\n", "",
returnValue, makeEndArgs(&nbfsFileOpt, &nbfpFileOpt,
&outFileOpt, &widthOpt, &heightOpt));

return parser.process(argv);
}

void printUsage(FILE *stream, const Common::UString &name) {
Expand Down

0 comments on commit 746016d

Please sign in to comment.