feat: support multi-input.

This commit is contained in:
2025-01-21 21:03:11 +08:00
parent b00b77a3d3
commit 5a2577c3c6
3 changed files with 28 additions and 21 deletions

View File

@@ -2,32 +2,37 @@
namespace format::input {
SymbolListFile SymbolListFile::load(std::string_view path) {
std::ifstream ifs(path.data());
if (!ifs) {
throw std::runtime_error("Failed to open symlist file.");
}
SymbolListFile SymbolListFile::load(std::string_view path) { return load(std::vector<std::string>{path.data()}); }
SymbolListFile SymbolListFile::load(const std::vector<std::string>& paths) {
SymbolListFile result;
std::string line;
while (std::getline(ifs, line)) {
if (line.empty()) continue;
auto separator_pos = line.find(", ");
if (separator_pos == std::string::npos) {
throw std::runtime_error(
"Symbol data is not included declType, please re-generate symlist file with -record-decl-name."
);
for (const auto& path : paths) {
std::ifstream ifs(path.data());
if (!ifs) {
throw std::runtime_error("Failed to open symlist file.");
}
auto declType_s = line.substr(0, separator_pos);
auto symbol = line.substr(separator_pos + 2);
std::string line;
while (std::getline(ifs, line)) {
if (line.empty()) continue;
result.m_data.emplace(symbol, DeclType(declType_s));
auto separator_pos = line.find(", ");
if (separator_pos == std::string::npos) {
throw std::runtime_error(
"Symbol data is not included declType, please re-generate symlist file with -record-decl-name."
);
}
auto declType_s = line.substr(0, separator_pos);
auto symbol = line.substr(separator_pos + 2);
result.m_data.emplace(symbol, DeclType(declType_s));
}
std::println("Read {} symbols from dumped symlist.", result.m_data.size());
}
std::println("Read {} symbols from dumped symlist.", result.m_data.size());
return result;
}

View File

@@ -7,6 +7,7 @@ namespace format::input {
class SymbolListFile {
public:
[[nodiscard]] static SymbolListFile load(std::string_view path);
[[nodiscard]] static SymbolListFile load(const std::vector<std::string>& path);
void for_each(const std::function<void(Symbol)>& callback);

View File

@@ -15,9 +15,9 @@ constexpr auto VERSION = "1.0.0";
argparse::ArgumentParser program("askrva", VERSION);
struct {
OutputFormat m_output_format;
std::string m_input_path;
std::string m_output_path;
OutputFormat m_output_format;
std::vector<std::string> m_input_path;
std::string m_output_path;
std::optional<std::string> m_output_failed_path;
} args;
@@ -29,6 +29,7 @@ constexpr auto VERSION = "1.0.0";
program.add_argument("path")
.help("Path to the symbol list file.")
.store_into(args.m_input_path)
.nargs(argparse::nargs_pattern::at_least_one)
.required();
program.add_argument("--output", "-o")