From 22669eebade0c3dc78ade4102ba2edfebe13d256 Mon Sep 17 00:00:00 2001 From: xp986 <> Date: Thu, 9 Oct 2025 00:15:18 -0500 Subject: [PATCH] Initial commit --- FormFeedRemove1-Alameda.cpp | 54 +++++++++++++++++++++++++++++++++++++ FormFeedRemove1.cpp | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 FormFeedRemove1-Alameda.cpp create mode 100644 FormFeedRemove1.cpp diff --git a/FormFeedRemove1-Alameda.cpp b/FormFeedRemove1-Alameda.cpp new file mode 100644 index 0000000..42ff2c7 --- /dev/null +++ b/FormFeedRemove1-Alameda.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(); + + // Step 1: Replace ASCII 171 with 189 + /* + for (auto& c : buffer) { + if ((unsigned char)c == 171) { + c = (char)189; + } + } + */ + + // Step 2: 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/FormFeedRemove1.cpp b/FormFeedRemove1.cpp new file mode 100644 index 0000000..39affcd --- /dev/null +++ b/FormFeedRemove1.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; +}