Compare commits
11 Commits
bed1c7f20d
...
robinson
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ce92848ce | ||
|
|
9b9c0fbd53 | ||
|
|
448d9c2c5d | ||
|
|
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.
|
||||||
@@ -1,163 +1,188 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
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 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) {
|
// Find the first number in a line using the given regex
|
||||||
std::smatch m;
|
bool find_first_number_in_line(const std::string& s, int& out, const std::regex& rx) {
|
||||||
if (std::regex_search(s, m, rx)) {
|
std::smatch m;
|
||||||
out = std::stoi(m.str());
|
if (std::regex_search(s, m, rx)) {
|
||||||
return true;
|
out = std::stoi(m.str());
|
||||||
}
|
return true;
|
||||||
return false;
|
}
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
// Check if a line contains exactly 24 consecutive '?'
|
|
||||||
bool has_exactly_24_A(const std::string& s) {
|
// Check if a line contains exactly 24 consecutive '<27>'
|
||||||
int count = 0;
|
bool has_exactly_24_A(const std::string& s) {
|
||||||
for (size_t i = 0; i <= s.size(); ++i) {
|
int count = 0;
|
||||||
if (i < s.size() && s[i] == (char)196) {
|
for (size_t i = 0; i <= s.size(); ++i) {
|
||||||
count++;
|
if (i < s.size() && s[i] == (char)196) {
|
||||||
}
|
count++;
|
||||||
else {
|
}
|
||||||
if (count == 24) return true; // exact match found
|
else {
|
||||||
count = 0; // reset counter
|
if (count == 24) return true; // exact match found
|
||||||
}
|
count = 0; // reset counter
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
if (argc < 3) {
|
int main(int argc, char* argv[]) {
|
||||||
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
if (argc < 3) {
|
||||||
return 1;
|
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
std::ifstream infile(argv[1]);
|
|
||||||
if (!infile) {
|
// Read entire file into memory as lines
|
||||||
std::cerr << "Error opening input file.\n";
|
std::ifstream infile(argv[1], std::ios::binary);
|
||||||
return 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";
|
std::ofstream outfile(argv[2], std::ios::binary);
|
||||||
return 1;
|
if (!outfile) {
|
||||||
}
|
std::cerr << "Error opening output file.\n";
|
||||||
|
return 1;
|
||||||
std::vector<std::string> lines;
|
}
|
||||||
std::string line;
|
|
||||||
while (std::getline(infile, line)) {
|
std::vector<std::string> lines;
|
||||||
lines.push_back(line);
|
std::string line;
|
||||||
}
|
while (std::getline(infile, line)) {
|
||||||
|
if (!infile.eof()) line += '\n'; // preserve original line endings
|
||||||
const std::string marker = "F.L.C.M. %";
|
lines.push_back(line);
|
||||||
|
}
|
||||||
// === 1) Find marker index ===
|
|
||||||
bool marker_found = false;
|
// Detect if document should be modified
|
||||||
size_t marker_index = 0;
|
bool has_bbgyro = false;
|
||||||
for (size_t i = 0; i < lines.size(); ++i) {
|
bool has_subs = false;
|
||||||
if (lines[i].find(marker) != std::string::npos) {
|
for (const auto& l : lines) {
|
||||||
marker_found = true;
|
std::string lower = l;
|
||||||
marker_index = i;
|
std::transform(lower.begin(), lower.end(), lower.begin(),
|
||||||
break;
|
[](unsigned char c) { return std::tolower(c); });
|
||||||
}
|
if (!has_bbgyro && lower.find("bbgyrs") != std::string::npos) has_bbgyro = true;
|
||||||
}
|
if (!has_subs && lower.find("subs") != std::string::npos) has_subs = true;
|
||||||
|
if (has_bbgyro || has_subs) break;
|
||||||
if (!marker_found) {
|
}
|
||||||
for (const auto& l : lines) outfile << l << '\n';
|
|
||||||
return 0;
|
// If neither BBGYRO nor SUBS appears, pass file through unmodified
|
||||||
}
|
if (!has_bbgyro && !has_subs) {
|
||||||
|
infile.clear();
|
||||||
// === 2) Extract gyros from "BBGYRO" line ===
|
infile.seekg(0, std::ios::beg);
|
||||||
int gyros = 0;
|
outfile << infile.rdbuf(); // exact byte-for-byte copy
|
||||||
bool gyros_found = false;
|
return 0;
|
||||||
size_t bbgyro_index = std::string::npos;
|
}
|
||||||
const std::string bbgyro_token = "BBGYRS";
|
|
||||||
|
const std::string marker = "F.L.C.M. %";
|
||||||
for (size_t i = 0; i < lines.size(); ++i) {
|
|
||||||
size_t pos = lines[i].find(bbgyro_token);
|
// === 1) Find marker index ===
|
||||||
if (pos != std::string::npos) {
|
bool marker_found = false;
|
||||||
bbgyro_index = i;
|
size_t marker_index = 0;
|
||||||
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
if (lines[i].find(marker) != std::string::npos) {
|
||||||
gyros_found = true;
|
marker_found = true;
|
||||||
}
|
marker_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// === 3) Extract total_subs ===
|
if (!marker_found) {
|
||||||
int total_subs = 0;
|
// Marker not found, write original file unchanged
|
||||||
|
infile.clear();
|
||||||
auto find_total_after_start_index = [&](size_t start_index) -> bool {
|
infile.seekg(0, std::ios::beg);
|
||||||
for (size_t j = start_index; j < lines.size(); ++j) {
|
outfile << infile.rdbuf();
|
||||||
if (has_exactly_24_A(lines[j])) {
|
return 0;
|
||||||
if (j + 1 < lines.size()) {
|
}
|
||||||
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
|
||||||
return true;
|
// === 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 = "BBGYRS";
|
||||||
return false;
|
|
||||||
};
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
|
size_t pos = lines[i].find(bbgyro_token);
|
||||||
if (gyros_found) {
|
if (pos != std::string::npos) {
|
||||||
find_total_after_start_index(bbgyro_index + 1);
|
bbgyro_index = i;
|
||||||
}
|
std::string tail = lines[i].substr(pos + bbgyro_token.size());
|
||||||
else {
|
if (find_first_number_in_line(tail, gyros, number_regex_full)) {
|
||||||
// Fallback: second "SUBS"
|
gyros_found = true;
|
||||||
int subs_count = 0;
|
}
|
||||||
size_t subs_index = std::string::npos;
|
break;
|
||||||
for (size_t i = 0; i < lines.size(); ++i) {
|
}
|
||||||
if (lines[i].find("SUBS") != std::string::npos) {
|
}
|
||||||
subs_count++;
|
|
||||||
if (subs_count == 2) {
|
// === 3) Extract total_subs ===
|
||||||
subs_index = i;
|
int total_subs = 0;
|
||||||
break;
|
|
||||||
}
|
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 (subs_index != std::string::npos) {
|
if (j + 1 < lines.size()) {
|
||||||
find_total_after_start_index(subs_index + 1);
|
if (find_first_number_in_line(lines[j + 1], total_subs, number_regex_1to3)) {
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// === 4) Truncate document after the marker ===
|
}
|
||||||
std::vector<std::string> truncated(lines.begin(), lines.begin() + marker_index + 1);
|
}
|
||||||
|
return false;
|
||||||
// === 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);
|
if (gyros_found) {
|
||||||
|
find_total_after_start_index(bbgyro_index + 1);
|
||||||
bool inserted = false;
|
}
|
||||||
for (const auto& l : truncated) {
|
else {
|
||||||
size_t ff_pos = l.find('\f');
|
// Fallback: second "SUBS"
|
||||||
if (!inserted && ff_pos != std::string::npos) {
|
int subs_count = 0;
|
||||||
std::string modified = l.substr(0, ff_pos) + insert_line + l.substr(ff_pos);
|
size_t subs_index = std::string::npos;
|
||||||
outfile << modified << '\n';
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
inserted = true;
|
std::string lower = lines[i];
|
||||||
}
|
std::transform(lower.begin(), lower.end(), lower.begin(),
|
||||||
else {
|
[](unsigned char c) { return std::tolower(c); });
|
||||||
outfile << l << '\n';
|
if (lower.find("subs") != std::string::npos) {
|
||||||
}
|
subs_count++;
|
||||||
}
|
if (subs_count == 2) {
|
||||||
|
subs_index = i;
|
||||||
if (!inserted) {
|
break;
|
||||||
outfile << insert_line << '\n';
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (inserted) {
|
if (subs_index != std::string::npos) {
|
||||||
// === 6) Append a form feed to the very end of the truncated document ===
|
find_total_after_start_index(subs_index + 1);
|
||||||
outfile << '\f';
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
// === 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;
|
||||||
|
}
|
||||||
BIN
ReportTruncate-Robinson.exe
Executable file
BIN
ReportTruncate-Robinson.exe
Executable file
Binary file not shown.
Reference in New Issue
Block a user