remove DECLARE_FLAG macro and add mode parsing
This commit is contained in:
@@ -11,17 +11,6 @@
|
|||||||
#include "util/flag.h"
|
#include "util/flag.h"
|
||||||
#include "util/macro.h"
|
#include "util/macro.h"
|
||||||
|
|
||||||
DECLARE_FLAG(std::string, rom_file);
|
|
||||||
DECLARE_FLAG(std::string, bps_file);
|
|
||||||
DECLARE_FLAG(std::string, src_file);
|
|
||||||
DECLARE_FLAG(std::string, modified_file);
|
|
||||||
DECLARE_FLAG(std::string, bin_file);
|
|
||||||
DECLARE_FLAG(std::string, address);
|
|
||||||
DECLARE_FLAG(std::string, length);
|
|
||||||
DECLARE_FLAG(std::string, file_size);
|
|
||||||
DECLARE_FLAG(std::string, dest_rom);
|
|
||||||
DECLARE_FLAG(std::string, tile32_id_list);
|
|
||||||
|
|
||||||
DEFINE_FLAG(std::string, rom_file, "", "The ROM file to load.");
|
DEFINE_FLAG(std::string, rom_file, "", "The ROM file to load.");
|
||||||
DEFINE_FLAG(std::string, bps_file, "", "The BPS file to apply.");
|
DEFINE_FLAG(std::string, bps_file, "", "The BPS file to apply.");
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#include "flag.h"
|
#include "flag.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "yaze_config.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
@@ -39,6 +43,28 @@ void FlagParser::Parse(std::vector<std::string>* tokens) {
|
|||||||
|
|
||||||
// Set the parsed value on the matching flag.
|
// Set the parsed value on the matching flag.
|
||||||
flag_ptr->ParseValue(value_string);
|
flag_ptr->ParseValue(value_string);
|
||||||
|
} else if (token.rfind("-", 0) == 0) {
|
||||||
|
if (token == "-v" || token == "-version") {
|
||||||
|
std::cout << "Version: " << YAZE_VERSION_MAJOR << "."
|
||||||
|
<< YAZE_VERSION_MINOR << "." << YAZE_VERSION_PATCH << "\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for -h or -help
|
||||||
|
if (token == "-h" || token == "-help") {
|
||||||
|
std::cout << "Available flags:\n";
|
||||||
|
for (const auto& flag :
|
||||||
|
yaze::util::global_flag_registry()->AllFlags()) {
|
||||||
|
std::cout << flag->name() << ": " << flag->help() << "\n";
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string flag_name;
|
||||||
|
if (!ExtractFlag(token, &flag_name)) {
|
||||||
|
throw std::runtime_error("Unrecognized flag: " + token);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
leftover.push_back(token);
|
leftover.push_back(token);
|
||||||
}
|
}
|
||||||
@@ -46,5 +72,25 @@ void FlagParser::Parse(std::vector<std::string>* tokens) {
|
|||||||
*tokens = leftover;
|
*tokens = leftover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FlagParser::ExtractFlagAndValue(const std::string& token,
|
||||||
|
std::string* flag_name,
|
||||||
|
std::string* value_string) {
|
||||||
|
const size_t eq_pos = token.find('=');
|
||||||
|
if (eq_pos == std::string::npos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*flag_name = token.substr(0, eq_pos);
|
||||||
|
*value_string = token.substr(eq_pos + 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlagParser::ExtractFlag(const std::string& token, std::string* flag_name) {
|
||||||
|
if (token.rfind("-", 0) == 0) {
|
||||||
|
*flag_name = token;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
@@ -102,8 +102,6 @@ inline FlagRegistry* global_flag_registry() {
|
|||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DECLARE_FLAG(type, name) extern yaze::util::Flag<type>* FLAGS_##name
|
|
||||||
|
|
||||||
// Defines a global Flag<type>* FLAGS_<name> and registers it.
|
// Defines a global Flag<type>* FLAGS_<name> and registers it.
|
||||||
#define DEFINE_FLAG(type, name, default_val, help_text) \
|
#define DEFINE_FLAG(type, name, default_val, help_text) \
|
||||||
yaze::util::Flag<type>* FLAGS_##name = \
|
yaze::util::Flag<type>* FLAGS_##name = \
|
||||||
@@ -138,15 +136,10 @@ class FlagParser {
|
|||||||
// value. e.g. "--count=42" -> flag_name = "--count", value_string = "42"
|
// value. e.g. "--count=42" -> flag_name = "--count", value_string = "42"
|
||||||
// returns true if '=' was found
|
// returns true if '=' was found
|
||||||
bool ExtractFlagAndValue(const std::string& token, std::string* flag_name,
|
bool ExtractFlagAndValue(const std::string& token, std::string* flag_name,
|
||||||
std::string* value_string) {
|
std::string* value_string);
|
||||||
const size_t eq_pos = token.find('=');
|
|
||||||
if (eq_pos == std::string::npos) {
|
// Mode flag '-'
|
||||||
return false;
|
bool ExtractFlag(const std::string& token, std::string* flag_name);
|
||||||
}
|
|
||||||
*flag_name = token.substr(0, eq_pos);
|
|
||||||
*value_string = token.substr(eq_pos + 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|||||||
Reference in New Issue
Block a user