Compare commits
1 Commits
fda084cd3c
...
robinson
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b67f5565ac |
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 3) {
|
||||
std::cerr << "Usage: " << argv[0] << " <inputfile> <outputfile>\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<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) 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;
|
||||
}
|
||||
Reference in New Issue
Block a user