add debug feature
This commit is contained in:
parent
6fab84f077
commit
8b791f04bc
22
src/main.cc
22
src/main.cc
|
@ -11,13 +11,21 @@ struct Entry {
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (argc != 2) {
|
if (argc < 2) {
|
||||||
std::cerr << "Usage: " << argv[0] << " <search_string>" << std::endl;
|
std::cerr << "Usage: " << argv[0] << " <search_string> [--debug]" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* filename = "dict.bin";
|
const char* filename = "dict.bin";
|
||||||
std::string search_string = argv[1];
|
std::string search_string = argv[1];
|
||||||
|
bool debug_mode = false; // Debug mode flag
|
||||||
|
|
||||||
|
// Check if --debug is passed
|
||||||
|
if (argc == 3 && std::string(argv[2]) == "--debug") {
|
||||||
|
debug_mode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string raw_output; // To store raw output
|
||||||
|
|
||||||
// The trie dictionary type from the four types
|
// The trie dictionary type from the four types
|
||||||
using trie_type = xcdat::trie_15_type;
|
using trie_type = xcdat::trie_15_type;
|
||||||
|
@ -54,11 +62,17 @@ int main(int argc, char* argv[]) {
|
||||||
substrings.push_back(substring);
|
substrings.push_back(substring);
|
||||||
}
|
}
|
||||||
std::cout << search_string << " - " << smallest_prefix << " = ";
|
std::cout << search_string << " - " << smallest_prefix << " = ";
|
||||||
|
if (debug_mode) {
|
||||||
|
raw_output += search_string + " - " + smallest_prefix.data() + " = "; // Accumulate raw output
|
||||||
|
}
|
||||||
size_t pos = search_string.find(smallest_prefix);
|
size_t pos = search_string.find(smallest_prefix);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
search_string.erase(0, pos + smallest_prefix.length());
|
search_string.erase(0, pos + smallest_prefix.length());
|
||||||
}
|
}
|
||||||
std::cout << search_string << std::endl;
|
std::cout << search_string << std::endl;
|
||||||
|
if (debug_mode) {
|
||||||
|
raw_output += search_string + '\n'; // Add the result to raw output
|
||||||
|
}
|
||||||
// Remove leading whitespace, if any
|
// Remove leading whitespace, if any
|
||||||
while (!search_string.empty() && std::isspace(search_string.front())) {
|
while (!search_string.empty() && std::isspace(search_string.front())) {
|
||||||
search_string.erase(0, 1);
|
search_string.erase(0, 1);
|
||||||
|
@ -69,6 +83,10 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print the stored raw output if debug mode is active
|
||||||
|
if (debug_mode) {
|
||||||
|
std::cout << "Stored raw output:" << std::endl << raw_output << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& sub : substrings) {
|
for (const auto& sub : substrings) {
|
||||||
std::cout << sub << std::endl;
|
std::cout << sub << std::endl;
|
||||||
|
|
Loading…
Reference in a new issue