clean up code a bit more

This commit is contained in:
Lily Tsuru 2023-08-22 19:43:17 -04:00
parent 9d02d7280e
commit e8cdc4e41a
1 changed files with 12 additions and 4 deletions

View File

@ -25,6 +25,8 @@ namespace swbf {
std::uint32_t codeHash; std::uint32_t codeHash;
bool done = false; bool done = false;
/// The matched codes for this thread.
/// All threads need to be summed up to get the whole list.
std::vector<std::string> matches; std::vector<std::string> matches;
void DisplayProgress() { void DisplayProgress() {
@ -96,10 +98,9 @@ namespace swbf {
while(true) { while(true) {
hash = swbf::SwsfScramble(test_buffer); hash = swbf::SwsfScramble(test_buffer);
// There was a match! // found a match
if(hash == options.targetHash) if(hash == options.targetHash)
DisplayData().matches.push_back(test_buffer); DisplayData().matches.push_back(test_buffer);
//swbf::fprint(stderr, "match: {} ({:08x})\n", test_buffer, hash);
CopyDisplayData(); CopyDisplayData();
@ -138,10 +139,15 @@ namespace swbf {
pool.join(); // just in case! pool.join(); // just in case!
// build the matches file fprint(stdout, "\nDone, writing matches file...\n");
fprint(stdout, "Writing matches file...");
std::ofstream ofs("matches.txt"); std::ofstream ofs("matches.txt");
if(!ofs) {
fprint(stderr, "Could not open matches file for writing. Unfortunately, there's not much I can do about that.\n");
std::exit(1);
}
// write the matches file
if(options.exact) if(options.exact)
fprint(ofs, "Matches for hash {:8x} for length {}:\n", options.targetHash, options.startLength, options.endLength); fprint(ofs, "Matches for hash {:8x} for length {}:\n", options.targetHash, options.startLength, options.endLength);
else else
@ -154,6 +160,8 @@ namespace swbf {
td.matches.clear(); td.matches.clear();
} }
infoData.clear();
} }
} // namespace swbf } // namespace swbf