Compare commits

4 Commits

Author SHA1 Message Date
xp986
b67f5565ac Remove unneccessary files 2025-10-09 10:37:39 -05:00
xp986
292a334abe Merge remote-tracking branch 'FormFeedRemove-Robinson/master' into robinson 2025-10-09 10:00:21 -05:00
xp986
5f2e186ae1 Move license and readme to master. 2025-10-09 00:01:53 -05:00
xp986
c6654fbcc8 Initial commit 2025-10-08 23:56:01 -05:00
4 changed files with 77 additions and 110 deletions

View File

@@ -0,0 +1,75 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <iterator>
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\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<char> buffer((std::istreambuf_iterator<char>(infile)),
std::istreambuf_iterator<char>());
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<unsigned char>(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<char> 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<unsigned char>(buffer[i + 1])) &&
buffer[i + 2] == '/' &&
buffer[i + 3] == ' ' &&
std::isdigit(static_cast<unsigned char>(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;
}

View File

@@ -1,54 +0,0 @@
#include <iostream>
#include <fstream>
#include <vector>
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
return 1;
}
std::ifstream infile(argv[1], std::ios::binary);
if (!infile) {
std::cerr << "Error opening input file.\n";
return 1;
}
std::vector<char> buffer((std::istreambuf_iterator<char>(infile)),
std::istreambuf_iterator<char>());
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;
}

View File

@@ -1,54 +0,0 @@
#include <iostream>
#include <fstream>
#include <vector>
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\n";
return 1;
}
std::ifstream infile(argv[1], std::ios::binary);
if (!infile) {
std::cerr << "Error opening input file.\n";
return 1;
}
std::vector<char> buffer((std::istreambuf_iterator<char>(infile)),
std::istreambuf_iterator<char>());
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;
}

View File

@@ -1,3 +1,3 @@
# FormFeedDelete # FormFeedDelete-Robinson
Deletes the form feed at the end of delivery tickets printed by the BonAppetit system. Deletes the form feed at the end of delivery tickets printed by the BonAppetit system. Modifications for Robinson store.