yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
z3ed.cc
Go to the documentation of this file.
1#include "cli/z3ed.h"
2
3#include <cstring>
4#include <iostream>
5#include <memory>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10#include "cli/tui.h"
11#include "util/flag.h"
12#include "util/macro.h"
13
14DECLARE_FLAG(std::string, rom_file);
15DECLARE_FLAG(std::string, bps_file);
16DECLARE_FLAG(std::string, src_file);
17DECLARE_FLAG(std::string, modified_file);
18DECLARE_FLAG(std::string, bin_file);
19DECLARE_FLAG(std::string, address);
20DECLARE_FLAG(std::string, length);
21DECLARE_FLAG(std::string, file_size);
22DECLARE_FLAG(std::string, dest_rom);
23DECLARE_FLAG(std::string, tile32_id_list);
24
25DEFINE_FLAG(std::string, rom_file, "", "The ROM file to load.");
26DEFINE_FLAG(std::string, bps_file, "", "The BPS file to apply.");
27
28DEFINE_FLAG(std::string, src_file, "", "The source file.");
29DEFINE_FLAG(std::string, modified_file, "", "The modified file.");
30
31DEFINE_FLAG(std::string, bin_file, "", "The binary file to export to.");
32DEFINE_FLAG(std::string, address, "", "The address to convert.");
33DEFINE_FLAG(std::string, length, "", "The length of the data to read.");
34
35DEFINE_FLAG(std::string, file_size, "", "The size of the file to expand to.");
36DEFINE_FLAG(std::string, dest_rom, "", "The destination ROM file.");
37DEFINE_FLAG(std::string, tile32_id_list, "",
38 "The list of tile32 IDs to transfer.");
39
40namespace yaze {
45namespace cli {
46namespace {
47
48int RunCommandHandler(int argc, char *argv[]) {
49 std::vector<std::string> arguments;
50 for (int i = 2; i < argc; i++) { // Skip the arg mode (argv[1])
51 std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
52 arguments.emplace_back(argv[i]);
53 }
54
55 Commands commands;
56 std::string mode = argv[1];
57 if (commands.handlers.find(mode) != commands.handlers.end()) {
58 PRINT_IF_ERROR(commands.handlers[mode]->handle(arguments))
59 } else {
60 std::cerr << "Invalid mode specified: " << mode << std::endl;
61 }
62 return EXIT_SUCCESS;
63}
64
65} // namespace
66} // namespace cli
67} // namespace yaze
68
69int main(int argc, char *argv[]) {
71 RETURN_IF_EXCEPTION(flag_parser.Parse(argc, argv));
72
73 for (const auto &flag : yaze::util::global_flag_registry()->AllFlags()) {
74 // Cast the IFlag to a Flag and use Get
75 auto flags = dynamic_cast<yaze::util::Flag<std::string> *>(flag);
76 std::cout << "Flag: " << flag->name() << " = " << flags->Get() << std::endl;
77 }
78
80 return EXIT_SUCCESS;
81}
void Parse(int argc, char **argv)
Definition flag.h:121
const std::string & name() const override
Definition flag.h:39
#define DECLARE_FLAG(type, name)
Definition flag.h:105
#define DEFINE_FLAG(type, name, default_val, help_text)
Definition flag.h:108
#define PRINT_IF_ERROR(expression)
Definition macro.h:36
#define RETURN_IF_EXCEPTION(expression)
Definition macro.h:112
int RunCommandHandler(int argc, char *argv[])
Definition z3ed.cc:48
void ShowMain()
Definition tui.cc:568
FlagRegistry * global_flag_registry()
Definition flag.h:99
Main namespace for the application.
Definition controller.cc:18
Command handler for the CLI.
Definition z3ed.h:217
std::unordered_map< std::string, std::shared_ptr< CommandHandler > > handlers
Definition z3ed.h:218
int main(int argc, char *argv[])
Definition z3ed.cc:69