1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-07-04 12:03:41 +02:00

src/main.cpp: refactor cmd_search to take strlist_t and int parameters and do all parsing outside.

This commit is contained in:
Henrik Hautakoski 2020-02-05 15:59:24 +01:00
parent d636cf7756
commit 67df405309

View file

@ -39,40 +39,30 @@ bool option_l33t = false;
int option_num_threads = std::thread::hardware_concurrency(); int option_num_threads = std::thread::hardware_concurrency();
#endif /* HAVE_THREADS */ #endif /* HAVE_THREADS */
void cmd_search(int argc, char **argv) { void cmd_search(const strlist_t& words, int count) {
int n = 10;
std::string input(argv[0]);
KeySearch ks; KeySearch ks;
if (option_l33t) { if (option_l33t) {
strlist_t tmp = strsplitwords(input); for(std::size_t i = 0; i < words.size(); i++) {
for(std::size_t i = 0; i < tmp.size(); i++) { ks.addList(l33twords(words[i]));
ks.addList(l33twords(tmp[i]));
} }
} else { } else {
ks.addList(strsplitwords(input)); ks.addList(words);
}
if (argc > 1) {
n = atoi(argv[1]);
if (n < 1) {
n = 1;
}
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
ks.setThreadCount(option_num_threads); ks.setThreadCount(option_num_threads);
#endif /* HAVE_THREADS */ #endif /* HAVE_THREADS */
std::cout << "Searching for " << n std::cout << "Searching for " << count
<< " keys containing: " << strjoin(ks.getList(), ",") << " keys containing: " << strjoin(ks.getList(), ",")
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
<< ", Using: " << option_num_threads << " threads" << ", Using: " << option_num_threads << " threads"
#endif /* HAVE_THREADS */ #endif /* HAVE_THREADS */
<< std::endl; << std::endl;
ks.find(n); ks.find(count);
} }
void usage(const char *name) { void usage(const char *name) {
@ -182,10 +172,19 @@ int main(int argc, char **argv) {
std::cerr << "You must specify a word list." << std::endl; std::cerr << "You must specify a word list." << std::endl;
usage(argv[0]); usage(argv[0]);
return 1; return 1;
} else {
int count = 10;
strlist_t words = strsplitwords(std::string(argv[p]));
if (p + 1 < argc) {
count = atoi(argv[p+1]);
if (count < 1) {
count = 1;
}
} }
// Pass the rest of argv, argc cmd_search(words, count);
cmd_search(argc - p, &argv[p]); }
} }
// Benchmark // Benchmark
else if (!strcmp(argv[p], "benchmark")) { else if (!strcmp(argv[p], "benchmark")) {