From c6654fbcc88703b819c09ee5c4babeb6bcaa9084 Mon Sep 17 00:00:00 2001 From: xp986 <> Date: Wed, 8 Oct 2025 23:56:01 -0500 Subject: [PATCH 1/2] Initial commit --- FormFeedRemove1-Robinson.cpp | 54 ++++++++++++++++++++++++ FormFeedRemove_0.2-Robinson.cpp | 65 ++++++++++++++++++++++++++++ FormFeedRemove_0.3-Robinson.cpp | 75 +++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 FormFeedRemove1-Robinson.cpp create mode 100644 FormFeedRemove_0.2-Robinson.cpp create mode 100644 FormFeedRemove_0.3-Robinson.cpp diff --git a/FormFeedRemove1-Robinson.cpp b/FormFeedRemove1-Robinson.cpp new file mode 100644 index 0000000..39affcd --- /dev/null +++ b/FormFeedRemove1-Robinson.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + std::ifstream infile(argv[1], std::ios::binary); + if (!infile) { + std::cerr << "Error opening input file.\n"; + return 1; + } + + std::vector buffer((std::istreambuf_iterator(infile)), + std::istreambuf_iterator()); + infile.close(); + + // Replace ASCII 9b with ''; + + for (auto& c : buffer) { + if ((unsigned char)c == 155) { + c = (char)0; + } + } + + + // Remove form feed (ASCII 12) from the last 16 bytes only + size_t size = buffer.size(); + size_t start = (size >= 16) ? size - 16 : 0; + for (size_t i = start; i < size; ) { + if ((unsigned char)buffer[i] == 12) { + buffer.erase(buffer.begin() + i); + size--; // update size since vector shrinks + } + else { + i++; + } + } + + std::ofstream outfile(argv[2], std::ios::binary); + if (!outfile) { + std::cerr << "Error opening output file.\n"; + return 1; + } + + outfile.write(buffer.data(), buffer.size()); + outfile.close(); + + //std::cout << "Processing complete. Output written to " << argv[2] << "\n"; + return 0; +} diff --git a/FormFeedRemove_0.2-Robinson.cpp b/FormFeedRemove_0.2-Robinson.cpp new file mode 100644 index 0000000..830d188 --- /dev/null +++ b/FormFeedRemove_0.2-Robinson.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + // --- Read entire file into memory --- + std::ifstream infile(argv[1], std::ios::binary); + if (!infile) { + std::cerr << "Error opening input file.\n"; + return 1; + } + + std::vector buffer((std::istreambuf_iterator(infile)), + std::istreambuf_iterator()); + infile.close(); + + if (buffer.empty()) { + std::cerr << "Input file is empty.\n"; + return 1; + } + + // --- 1. Remove all ASCII 155 (0x9B) bytes --- + buffer.erase(std::remove(buffer.begin(), buffer.end(), (char)155), buffer.end()); + + // --- 2. Remove form feed (ASCII 12) from the last 16 bytes only --- + if (!buffer.empty()) { + size_t start = (buffer.size() > 16) ? buffer.size() - 16 : 0; + buffer.erase(std::remove(buffer.begin() + start, buffer.end(), (char)12), buffer.end()); + } + + // --- 3. Remove one space (ASCII 32) at start of final line --- + if (!buffer.empty()) { + // Find position of last newline character ('\n' or '\r') + size_t last_line_start = 0; + for (size_t i = buffer.size(); i-- > 0; ) { + if (buffer[i] == '\n') { + last_line_start = i + 1; + break; + } + } + + // If first character of last line is a space (0x20), remove one + if (last_line_start < buffer.size() && buffer[last_line_start] == ' ') { + buffer.erase(buffer.begin() + last_line_start); + } + } + + // --- Write output file --- + std::ofstream outfile(argv[2], std::ios::binary); + if (!outfile) { + std::cerr << "Error opening output file.\n"; + return 1; + } + + outfile.write(buffer.data(), buffer.size()); + outfile.close(); + + return 0; +} diff --git a/FormFeedRemove_0.3-Robinson.cpp b/FormFeedRemove_0.3-Robinson.cpp new file mode 100644 index 0000000..f79f40f --- /dev/null +++ b/FormFeedRemove_0.3-Robinson.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + // Read file into buffer + std::ifstream infile(argv[1], std::ios::binary); + if (!infile) { + std::cerr << "Error opening input file.\n"; + return 1; + } + std::vector buffer((std::istreambuf_iterator(infile)), + std::istreambuf_iterator()); + infile.close(); + + if (buffer.empty()) { + std::cerr << "Input file is empty.\n"; + return 1; + } + + // 1) Remove all ASCII 155 (0x9B) + buffer.erase(std::remove_if(buffer.begin(), buffer.end(), + [](char c){ return static_cast(c) == 155 || (c) == 62; }), + buffer.end()); + + // 2) Remove form feed (0x0C) from the last 16 bytes only + if (!buffer.empty()) { + size_t start = (buffer.size() > 16) ? buffer.size() - 16 : 0; + buffer.erase(std::remove(buffer.begin() + start, buffer.end(), (char)12), buffer.end()); + } + + // 3) Remove one space preceding every occurrence of: digit '/' space digit + // i.e. remove the single space immediately before the pattern "x/ x" (x = digit) + std::vector out; + out.reserve(buffer.size()); + + const size_t n = buffer.size(); + for (size_t i = 0; i < n; ++i) { + // If current char is a space and the next 4 characters exist and match: + // [digit] '/' ' ' [digit] starting at i+1 -> remove this current space (skip it) + if (buffer[i] == ' ' && i + 4 < n && + std::isdigit(static_cast(buffer[i + 1])) && + buffer[i + 2] == '/' && + buffer[i + 3] == ' ' && + std::isdigit(static_cast(buffer[i + 4]))) { + // skip this single space (do not push it to out) + continue; + } + + // Otherwise, keep the character + out.push_back(buffer[i]); + } + + // 4) Write output + std::ofstream outfile(argv[2], std::ios::binary); + if (!outfile) { + std::cerr << "Error opening output file.\n"; + return 1; + } + if (!out.empty()) { + outfile.write(out.data(), out.size()); + } + outfile.close(); + + return 0; +} From 5f2e186ae1ce670743159cad1d784212eed61ac6 Mon Sep 17 00:00:00 2001 From: xp986 <> Date: Thu, 9 Oct 2025 00:01:53 -0500 Subject: [PATCH 2/2] Move license and readme to master. --- LICENSE | 18 ++++++++++++++++++ README.md | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..52331d9 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a4043bb --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# FormFeedDelete-Robinson + +Deletes the form feed at the end of delivery tickets printed by the BonAppetit system. Modifications for Robinson store. \ No newline at end of file