Compare commits
8 Commits
bed1c7f20d
...
b93cf0bc1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b93cf0bc1b | ||
|
|
70c9e35ae4 | ||
|
|
55ac790b43 | ||
|
|
2647432b04 | ||
|
|
28f6c6d46c | ||
| ee5368cf19 | |||
|
|
c966d048b6 | ||
| f8aeb47a77 |
18
LICENSE
Normal file
18
LICENSE
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 xp986
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||||
|
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
||||||
|
following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||||
|
portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||||
|
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
||||||
|
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# ReportTruncate-Robinson
|
||||||
|
|
||||||
|
Truncates the daily report from the BonAppetit system. Modifications for the Robinson store.
|
||||||
@@ -18,7 +18,7 @@ bool find_first_number_in_line(const std::string& s, int& out, const std::regex&
|
|||||||
return false;
|
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) {
|
bool has_exactly_24_A(const std::string& s) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (size_t i = 0; i <= s.size(); ++i) {
|
for (size_t i = 0; i <= s.size(); ++i) {
|
||||||
@@ -39,13 +39,14 @@ int main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream infile(argv[1]);
|
// Read entire file into memory as lines
|
||||||
|
std::ifstream infile(argv[1], std::ios::binary);
|
||||||
if (!infile) {
|
if (!infile) {
|
||||||
std::cerr << "Error opening input file.\n";
|
std::cerr << "Error opening input file.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream outfile(argv[2]);
|
std::ofstream outfile(argv[2], std::ios::binary);
|
||||||
if (!outfile) {
|
if (!outfile) {
|
||||||
std::cerr << "Error opening output file.\n";
|
std::cerr << "Error opening output file.\n";
|
||||||
return 1;
|
return 1;
|
||||||
@@ -54,9 +55,27 @@ int main(int argc, char* argv[]) {
|
|||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(infile, line)) {
|
while (std::getline(infile, line)) {
|
||||||
|
if (!infile.eof()) line += '\n'; // preserve original line endings
|
||||||
lines.push_back(line);
|
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. %";
|
const std::string marker = "F.L.C.M. %";
|
||||||
|
|
||||||
// === 1) Find marker index ===
|
// === 1) Find marker index ===
|
||||||
@@ -71,7 +90,10 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!marker_found) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,18 +164,14 @@ int main(int argc, char* argv[]) {
|
|||||||
size_t ff_pos = l.find('\f');
|
size_t ff_pos = l.find('\f');
|
||||||
if (!inserted && ff_pos != std::string::npos) {
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
outfile << modified << '\n';
|
outfile << modified;
|
||||||
inserted = true;
|
inserted = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
outfile << l << '\n';
|
outfile << l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inserted) {
|
|
||||||
outfile << insert_line << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inserted) {
|
if (inserted) {
|
||||||
// === 6) Append a form feed to the very end of the truncated document ===
|
// === 6) Append a form feed to the very end of the truncated document ===
|
||||||
outfile << '\f';
|
outfile << '\f';
|
||||||
|
|||||||
148
ReportTruncate_0.1.cpp
Normal file
148
ReportTruncate_0.1.cpp
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <regex>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const std::regex number_regex_full(R"(\d+)");
|
||||||
|
static const std::regex number_regex_1to3(R"(\b\d{1,3}\b)");
|
||||||
|
|
||||||
|
// Helper: find first number in 's', put into out, return true if found
|
||||||
|
bool find_first_number_in_line(const std::string &s, int &out, const std::regex &rx) {
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(s, m, rx)) {
|
||||||
|
out = std::stoi(m.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile(argv[1]);
|
||||||
|
if (!infile) {
|
||||||
|
std::cerr << "Error opening input file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile(argv[2]);
|
||||||
|
if (!outfile) {
|
||||||
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read entire file into memory
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(infile, line)) {
|
||||||
|
lines.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string marker = "F.L.C.M. %";
|
||||||
|
|
||||||
|
// === 1) Find marker index (for truncation) ===
|
||||||
|
bool marker_found = false;
|
||||||
|
size_t marker_index = 0;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
|
marker_found = true;
|
||||||
|
marker_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!marker_found) {
|
||||||
|
for (const auto &l : lines) outfile << l << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 2) Extract gyros (first number on SAME line as "BBGYRO") ===
|
||||||
|
int gyros = 0;
|
||||||
|
bool gyros_found = false;
|
||||||
|
size_t bbgyro_index = std::string::npos;
|
||||||
|
const std::string bbgyro_token = "BBGYRO";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
bbgyro_index = i;
|
||||||
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
|
gyros_found = true;
|
||||||
|
}
|
||||||
|
break; // only first occurrence matters
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 3) Extract total_subs (1–3 digit number after 'Ä' line) ===
|
||||||
|
int total_subs = 0;
|
||||||
|
bool total_found = false;
|
||||||
|
|
||||||
|
auto find_total_after_start_index = [&](size_t start_index)->bool {
|
||||||
|
for (size_t j = start_index; j < lines.size(); ++j) {
|
||||||
|
size_t countA = 0;
|
||||||
|
for (u_char c : lines[j]) if (c == u'Ä') ++countA;
|
||||||
|
if (countA >= 10) {
|
||||||
|
// look in the next line and up to 3 lines after if needed
|
||||||
|
for (size_t k = j + 1; k < lines.size(); ++k) {
|
||||||
|
if (find_first_number_in_line(lines[k], total_subs, number_regex_1to3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (gyros_found) {
|
||||||
|
total_found = find_total_after_start_index(bbgyro_index + 1);
|
||||||
|
} else {
|
||||||
|
// BBGYRO not found -> find 2nd occurrence of "SUBS" then start from there
|
||||||
|
int subs_count = 0;
|
||||||
|
size_t subs_index = std::string::npos;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find("SUBS") != std::string::npos) {
|
||||||
|
subs_count++;
|
||||||
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subs_index != std::string::npos) {
|
||||||
|
total_found = find_total_after_start_index(subs_index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 4) Truncate to include up to and including the marker line ===
|
||||||
|
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
||||||
|
|
||||||
|
// === 5) Insert "TOTAL SUBS --- <diff>" immediately before first form feed ===
|
||||||
|
int diff = total_subs - gyros;
|
||||||
|
const std::string insert_line = "\n\n TOTAL SUBS --- " + std::to_string(diff);
|
||||||
|
|
||||||
|
bool inserted = false;
|
||||||
|
for (const auto &l : truncated) {
|
||||||
|
size_t ff_pos = l.find('\f');
|
||||||
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
|
// insert directly before first form feed
|
||||||
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
|
outfile << modified << '\n';
|
||||||
|
inserted = true;
|
||||||
|
} else {
|
||||||
|
outfile << l << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!inserted) {
|
||||||
|
outfile << insert_line << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
143
ReportTruncate_0.2.cpp
Normal file
143
ReportTruncate_0.2.cpp
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <regex>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const std::regex number_regex_full(R"(\d+)");
|
||||||
|
static const std::regex number_regex_1to3(R"(\b\d{1,3}\b)");
|
||||||
|
static const std::regex exact_24_A(R"((?<!Ä)Ä{24}(?!Ä))");
|
||||||
|
|
||||||
|
bool find_first_number_in_line(const std::string &s, int &out, const std::regex &rx) {
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(s, m, rx)) {
|
||||||
|
out = std::stoi(m.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile(argv[1]);
|
||||||
|
if (!infile) {
|
||||||
|
std::cerr << "Error opening input file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile(argv[2]);
|
||||||
|
if (!outfile) {
|
||||||
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(infile, line)) {
|
||||||
|
lines.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string marker = "F.L.C.M. %";
|
||||||
|
|
||||||
|
// === 1) Find marker index ===
|
||||||
|
bool marker_found = false;
|
||||||
|
size_t marker_index = 0;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
|
marker_found = true;
|
||||||
|
marker_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!marker_found) {
|
||||||
|
for (const auto &l : lines) outfile << l << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 2) Extract gyros from "BBGYRO" line ===
|
||||||
|
int gyros = 0;
|
||||||
|
bool gyros_found = false;
|
||||||
|
size_t bbgyro_index = std::string::npos;
|
||||||
|
const std::string bbgyro_token = "BBGYRO";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
bbgyro_index = i;
|
||||||
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
|
gyros_found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 3) Extract total_subs ===
|
||||||
|
int total_subs = 0;
|
||||||
|
bool total_found = false;
|
||||||
|
|
||||||
|
auto find_total_after_start_index = [&](size_t start_index)->bool {
|
||||||
|
for (size_t j = start_index; j < lines.size(); ++j) {
|
||||||
|
if (std::regex_search(lines[j], exact_24_A)) {
|
||||||
|
if (j + 1 < lines.size()) {
|
||||||
|
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (gyros_found) {
|
||||||
|
total_found = find_total_after_start_index(bbgyro_index + 1);
|
||||||
|
} else {
|
||||||
|
// Fallback: second "SUBS"
|
||||||
|
int subs_count = 0;
|
||||||
|
size_t subs_index = std::string::npos;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find("SUBS") != std::string::npos) {
|
||||||
|
subs_count++;
|
||||||
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subs_index != std::string::npos) {
|
||||||
|
total_found = find_total_after_start_index(subs_index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 4) Truncate document after the marker ===
|
||||||
|
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
||||||
|
|
||||||
|
// === 5) Insert TOTAL SUBS --- diff before first form feed ===
|
||||||
|
int diff = total_subs - gyros;
|
||||||
|
const std::string insert_line = "\n\n TOTAL SUBS --- " + std::to_string(diff);
|
||||||
|
|
||||||
|
bool inserted = false;
|
||||||
|
for (const auto &l : truncated) {
|
||||||
|
size_t ff_pos = l.find('\f');
|
||||||
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
|
outfile << modified << '\n';
|
||||||
|
inserted = true;
|
||||||
|
} else {
|
||||||
|
outfile << l << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inserted) {
|
||||||
|
outfile << insert_line << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
157
ReportTruncate_0.3.cpp
Normal file
157
ReportTruncate_0.3.cpp
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <regex>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const std::regex number_regex_full(R"(\d+)");
|
||||||
|
static const std::regex number_regex_1to3(R"(\b\d{1,3}\b)");
|
||||||
|
|
||||||
|
// Find the first number in a line using the given regex
|
||||||
|
bool find_first_number_in_line(const std::string &s, int &out, const std::regex &rx) {
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(s, m, rx)) {
|
||||||
|
out = std::stoi(m.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a line contains exactly 24 consecutive 'Ä'
|
||||||
|
bool has_exactly_24_A(const std::string &s) {
|
||||||
|
int count = 0;
|
||||||
|
for (size_t i = 0; i <= s.size(); ++i) {
|
||||||
|
if (i < s.size() && s[i] == (char)196) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
if (count == 24) return true; // exact match found
|
||||||
|
count = 0; // reset counter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile(argv[1]);
|
||||||
|
if (!infile) {
|
||||||
|
std::cerr << "Error opening input file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile(argv[2]);
|
||||||
|
if (!outfile) {
|
||||||
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(infile, line)) {
|
||||||
|
lines.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string marker = "F.L.C.M. %";
|
||||||
|
|
||||||
|
// === 1) Find marker index ===
|
||||||
|
bool marker_found = false;
|
||||||
|
size_t marker_index = 0;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
|
marker_found = true;
|
||||||
|
marker_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!marker_found) {
|
||||||
|
for (const auto &l : lines) outfile << l << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 2) Extract gyros from "BBGYRO" line ===
|
||||||
|
int gyros = 0;
|
||||||
|
bool gyros_found = false;
|
||||||
|
size_t bbgyro_index = std::string::npos;
|
||||||
|
const std::string bbgyro_token = "BBGYRO";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
bbgyro_index = i;
|
||||||
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
|
gyros_found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 3) Extract total_subs ===
|
||||||
|
int total_subs = 0;
|
||||||
|
bool total_found = false;
|
||||||
|
|
||||||
|
auto find_total_after_start_index = [&](size_t start_index) -> bool {
|
||||||
|
for (size_t j = start_index; j < lines.size(); ++j) {
|
||||||
|
if (has_exactly_24_A(lines[j])) {
|
||||||
|
if (j + 1 < lines.size()) {
|
||||||
|
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (gyros_found) {
|
||||||
|
total_found = find_total_after_start_index(bbgyro_index + 1);
|
||||||
|
} else {
|
||||||
|
// Fallback: second "SUBS"
|
||||||
|
int subs_count = 0;
|
||||||
|
size_t subs_index = std::string::npos;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find("SUBS") != std::string::npos) {
|
||||||
|
subs_count++;
|
||||||
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subs_index != std::string::npos) {
|
||||||
|
total_found = find_total_after_start_index(subs_index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 4) Truncate document after the marker ===
|
||||||
|
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
||||||
|
|
||||||
|
// === 5) Insert TOTAL SUBS --- diff before first form feed ===
|
||||||
|
int diff = total_subs - gyros;
|
||||||
|
const std::string insert_line = "\n\n TOTAL ROLLS (Total - Gyros) --- " + std::to_string(diff);
|
||||||
|
|
||||||
|
bool inserted = false;
|
||||||
|
for (const auto &l : truncated) {
|
||||||
|
size_t ff_pos = l.find('\f');
|
||||||
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
|
outfile << modified << '\n';
|
||||||
|
inserted = true;
|
||||||
|
} else {
|
||||||
|
outfile << l << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inserted) {
|
||||||
|
outfile << insert_line << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
159
ReportTruncate_0.4.cpp
Normal file
159
ReportTruncate_0.4.cpp
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <regex>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const std::regex number_regex_full(R"(\d+)");
|
||||||
|
static const std::regex number_regex_1to3(R"(\b\d{1,3}\b)");
|
||||||
|
|
||||||
|
// Find the first number in a line using the given regex
|
||||||
|
bool find_first_number_in_line(const std::string &s, int &out, const std::regex &rx) {
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(s, m, rx)) {
|
||||||
|
out = std::stoi(m.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a line contains exactly 24 consecutive 'Ä'
|
||||||
|
bool has_exactly_24_A(const std::string &s) {
|
||||||
|
int count = 0;
|
||||||
|
for (size_t i = 0; i <= s.size(); ++i) {
|
||||||
|
if (i < s.size() && s[i] == (char)196) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
if (count == 24) return true; // exact match found
|
||||||
|
count = 0; // reset counter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile(argv[1]);
|
||||||
|
if (!infile) {
|
||||||
|
std::cerr << "Error opening input file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile(argv[2]);
|
||||||
|
if (!outfile) {
|
||||||
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(infile, line)) {
|
||||||
|
lines.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string marker = "F.L.C.M. %";
|
||||||
|
|
||||||
|
// === 1) Find marker index ===
|
||||||
|
bool marker_found = false;
|
||||||
|
size_t marker_index = 0;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
|
marker_found = true;
|
||||||
|
marker_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!marker_found) {
|
||||||
|
for (const auto &l : lines) outfile << l << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 2) Extract gyros from "BBGYRO" line ===
|
||||||
|
int gyros = 0;
|
||||||
|
bool gyros_found = false;
|
||||||
|
size_t bbgyro_index = std::string::npos;
|
||||||
|
const std::string bbgyro_token = "BBGYRO";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
bbgyro_index = i;
|
||||||
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
|
gyros_found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 3) Extract total_subs ===
|
||||||
|
int total_subs = 0;
|
||||||
|
|
||||||
|
auto find_total_after_start_index = [&](size_t start_index) -> bool {
|
||||||
|
for (size_t j = start_index; j < lines.size(); ++j) {
|
||||||
|
if (has_exactly_24_A(lines[j])) {
|
||||||
|
if (j + 1 < lines.size()) {
|
||||||
|
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (gyros_found) {
|
||||||
|
find_total_after_start_index(bbgyro_index + 1);
|
||||||
|
} else {
|
||||||
|
// Fallback: second "SUBS"
|
||||||
|
int subs_count = 0;
|
||||||
|
size_t subs_index = std::string::npos;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find("SUBS") != std::string::npos) {
|
||||||
|
subs_count++;
|
||||||
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subs_index != std::string::npos) {
|
||||||
|
find_total_after_start_index(subs_index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 4) Truncate document after the marker ===
|
||||||
|
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
||||||
|
|
||||||
|
// === 5) Insert TOTAL SUBS --- diff before first form feed ===
|
||||||
|
int diff = total_subs - gyros;
|
||||||
|
const std::string insert_line = "\n\n ROLLS USED --- " + std::to_string(diff);
|
||||||
|
|
||||||
|
bool inserted = false;
|
||||||
|
for (const auto &l : truncated) {
|
||||||
|
size_t ff_pos = l.find('\f');
|
||||||
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
|
outfile << modified << '\n';
|
||||||
|
inserted = true;
|
||||||
|
} else {
|
||||||
|
outfile << l << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inserted) {
|
||||||
|
outfile << insert_line << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 6) Append a form feed to the very end of the truncated document ===
|
||||||
|
outfile << '\f';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
163
ReportTruncate_0.5.cpp
Normal file
163
ReportTruncate_0.5.cpp
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <regex>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const std::regex number_regex_full(R"(\d+)");
|
||||||
|
static const std::regex number_regex_1to3(R"(\b\d{1,3}\b)");
|
||||||
|
|
||||||
|
// Find the first number in a line using the given regex
|
||||||
|
bool find_first_number_in_line(const std::string &s, int &out, const std::regex &rx) {
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(s, m, rx)) {
|
||||||
|
out = std::stoi(m.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a line contains exactly 24 consecutive '<27>'
|
||||||
|
bool has_exactly_24_A(const std::string &s) {
|
||||||
|
int count = 0;
|
||||||
|
for (size_t i = 0; i <= s.size(); ++i) {
|
||||||
|
if (i < s.size() && s[i] == (char)196) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
if (count == 24) return true; // exact match found
|
||||||
|
count = 0; // reset counter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile(argv[1]);
|
||||||
|
if (!infile) {
|
||||||
|
std::cerr << "Error opening input file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile(argv[2]);
|
||||||
|
if (!outfile) {
|
||||||
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(infile, line)) {
|
||||||
|
lines.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string marker = "F.L.C.M. %";
|
||||||
|
|
||||||
|
// === 1) Find marker index ===
|
||||||
|
bool marker_found = false;
|
||||||
|
size_t marker_index = 0;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
|
marker_found = true;
|
||||||
|
marker_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!marker_found) {
|
||||||
|
for (const auto &l : lines) outfile << l << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 2) Extract gyros from "BBGYRO" line ===
|
||||||
|
int gyros = 0;
|
||||||
|
bool gyros_found = false;
|
||||||
|
size_t bbgyro_index = std::string::npos;
|
||||||
|
const std::string bbgyro_token = "BBGYRO";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
bbgyro_index = i;
|
||||||
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
|
gyros_found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 3) Extract total_subs ===
|
||||||
|
int total_subs = 0;
|
||||||
|
|
||||||
|
auto find_total_after_start_index = [&](size_t start_index) -> bool {
|
||||||
|
for (size_t j = start_index; j < lines.size(); ++j) {
|
||||||
|
if (has_exactly_24_A(lines[j])) {
|
||||||
|
if (j + 1 < lines.size()) {
|
||||||
|
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (gyros_found) {
|
||||||
|
find_total_after_start_index(bbgyro_index + 1);
|
||||||
|
} else {
|
||||||
|
// Fallback: second "SUBS"
|
||||||
|
int subs_count = 0;
|
||||||
|
size_t subs_index = std::string::npos;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find("SUBS") != std::string::npos) {
|
||||||
|
subs_count++;
|
||||||
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subs_index != std::string::npos) {
|
||||||
|
find_total_after_start_index(subs_index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 4) Truncate document after the marker ===
|
||||||
|
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
||||||
|
|
||||||
|
// === 5) Insert TOTAL SUBS --- diff before first form feed ===
|
||||||
|
int diff = total_subs - gyros;
|
||||||
|
const std::string insert_line = "\n\n ROLLS USED --- " + std::to_string(diff);
|
||||||
|
|
||||||
|
bool inserted = false;
|
||||||
|
for (const auto &l : truncated) {
|
||||||
|
size_t ff_pos = l.find('\f');
|
||||||
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
|
outfile << modified << '\n';
|
||||||
|
inserted = true;
|
||||||
|
} else {
|
||||||
|
outfile << l << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (!inserted) {
|
||||||
|
outfile << insert_line << '\n';
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (inserted) {
|
||||||
|
// === 6) Append a form feed to the very end of the truncated document ===
|
||||||
|
outfile << '\f';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
181
ReportTruncate_0.6.cpp
Normal file
181
ReportTruncate_0.6.cpp
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <regex>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const std::regex number_regex_full(R"(\d+)");
|
||||||
|
static const std::regex number_regex_1to3(R"(\b\d{1,3}\b)");
|
||||||
|
|
||||||
|
// Find the first number in a line using the given regex
|
||||||
|
bool find_first_number_in_line(const std::string& s, int& out, const std::regex& rx) {
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(s, m, rx)) {
|
||||||
|
out = std::stoi(m.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a line contains exactly 24 consecutive '<27>'
|
||||||
|
bool has_exactly_24_A(const std::string& s) {
|
||||||
|
int count = 0;
|
||||||
|
for (size_t i = 0; i <= s.size(); ++i) {
|
||||||
|
if (i < s.size() && s[i] == (char)196) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (count == 24) return true; // exact match found
|
||||||
|
count = 0; // reset counter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
|
return 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::ios::binary);
|
||||||
|
if (!outfile) {
|
||||||
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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("BBGYRO") != 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 ===
|
||||||
|
bool marker_found = false;
|
||||||
|
size_t marker_index = 0;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
|
marker_found = true;
|
||||||
|
marker_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!marker_found) {
|
||||||
|
// Marker not found, write original file unchanged
|
||||||
|
infile.clear();
|
||||||
|
infile.seekg(0, std::ios::beg);
|
||||||
|
outfile << infile.rdbuf();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 2) Extract gyros from "BBGYRO" line ===
|
||||||
|
int gyros = 0;
|
||||||
|
bool gyros_found = false;
|
||||||
|
size_t bbgyro_index = std::string::npos;
|
||||||
|
const std::string bbgyro_token = "BBGYRO";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
bbgyro_index = i;
|
||||||
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
|
gyros_found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 3) Extract total_subs ===
|
||||||
|
int total_subs = 0;
|
||||||
|
|
||||||
|
auto find_total_after_start_index = [&](size_t start_index) -> bool {
|
||||||
|
for (size_t j = start_index; j < lines.size(); ++j) {
|
||||||
|
if (has_exactly_24_A(lines[j])) {
|
||||||
|
if (j + 1 < lines.size()) {
|
||||||
|
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (gyros_found) {
|
||||||
|
find_total_after_start_index(bbgyro_index + 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Fallback: second "SUBS"
|
||||||
|
int subs_count = 0;
|
||||||
|
size_t subs_index = std::string::npos;
|
||||||
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
if (lines[i].find("SUBS") != std::string::npos) {
|
||||||
|
subs_count++;
|
||||||
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subs_index != std::string::npos) {
|
||||||
|
find_total_after_start_index(subs_index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 4) Truncate document after the marker ===
|
||||||
|
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
||||||
|
|
||||||
|
// === 5) Insert TOTAL SUBS --- diff before first form feed ===
|
||||||
|
int diff = total_subs - gyros;
|
||||||
|
const std::string insert_line = "\n\n\r ROLLS USED --- " + std::to_string(diff);
|
||||||
|
|
||||||
|
bool inserted = false;
|
||||||
|
for (const auto& l : truncated) {
|
||||||
|
size_t ff_pos = l.find('\f');
|
||||||
|
if (!inserted && ff_pos != std::string::npos) {
|
||||||
|
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
||||||
|
outfile << modified;
|
||||||
|
inserted = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outfile << l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inserted) {
|
||||||
|
// === 6) Append a form feed to the very end of the truncated document ===
|
||||||
|
outfile << '\f';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user