Switch to alameda code, with search for BBGYRS instead of BBGYRO
This commit is contained in:
@@ -18,7 +18,7 @@ bool find_first_number_in_line(const std::string& s, int& out, const std::regex&
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if a line contains exactly 24 consecutive '?'
|
||||
// Check if a line contains exactly 24 consecutive '<EFBFBD>'
|
||||
bool has_exactly_24_A(const std::string& s) {
|
||||
int count = 0;
|
||||
for (size_t i = 0; i <= s.size(); ++i) {
|
||||
@@ -39,13 +39,14 @@ int main(int argc, char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ifstream infile(argv[1]);
|
||||
// Read entire file into memory as lines
|
||||
std::ifstream infile(argv[1], std::ios::binary);
|
||||
if (!infile) {
|
||||
std::cerr << "Error opening input file.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ofstream outfile(argv[2]);
|
||||
std::ofstream outfile(argv[2], std::ios::binary);
|
||||
if (!outfile) {
|
||||
std::cerr << "Error opening output file.\n";
|
||||
return 1;
|
||||
@@ -54,9 +55,27 @@ int main(int argc, char* argv[]) {
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
while (std::getline(infile, line)) {
|
||||
if (!infile.eof()) line += '\n'; // preserve original line endings
|
||||
lines.push_back(line);
|
||||
}
|
||||
|
||||
// Detect if document should be modified
|
||||
bool has_bbgyro = false;
|
||||
bool has_subs = false;
|
||||
for (const auto& l : lines) {
|
||||
if (!has_bbgyro && l.find("BBGYRS") != std::string::npos) has_bbgyro = true;
|
||||
if (!has_subs && l.find("SUBS") != std::string::npos) has_subs = true;
|
||||
if (has_bbgyro || has_subs) break;
|
||||
}
|
||||
|
||||
// If neither BBGYRO nor SUBS appears, pass file through unmodified
|
||||
if (!has_bbgyro && !has_subs) {
|
||||
infile.clear();
|
||||
infile.seekg(0, std::ios::beg);
|
||||
outfile << infile.rdbuf(); // exact byte-for-byte copy
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::string marker = "F.L.C.M. %";
|
||||
|
||||
// === 1) Find marker index ===
|
||||
@@ -71,7 +90,10 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
if (!marker_found) {
|
||||
for (const auto& l : lines) outfile << l << '\n';
|
||||
// Marker not found, write original file unchanged
|
||||
infile.clear();
|
||||
infile.seekg(0, std::ios::beg);
|
||||
outfile << infile.rdbuf();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -79,7 +101,7 @@ int main(int argc, char* argv[]) {
|
||||
int gyros = 0;
|
||||
bool gyros_found = false;
|
||||
size_t bbgyro_index = std::string::npos;
|
||||
const std::string bbgyro_token = "BBGYRS";
|
||||
const std::string bbgyro_token = "BBGYRO";
|
||||
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
size_t pos = lines[i].find(bbgyro_token);
|
||||
|
||||
Reference in New Issue
Block a user