#include "decode.h" #include #include int decode_main(int argc, char* argv[]) { bool decoding = true; FILE *input_file = fopen(argv[2], "rb"); if (input_file == NULL) { fprintf(stderr, "Error opening input file: %s\n", argv[2]); return 1; } FILE *output_file = fopen(argv[3], "wb"); if (output_file == NULL) { fprintf(stderr, "Error opening output file: %s\n", argv[3]); fclose(input_file); return 1; } while (decoding) { // Read data unsigned char data[1024]; unsigned char buffer_High[sizeof(data)/2]; unsigned char buffer_Low[sizeof(data)/2]; size_t bytes_read = fread(&data, 1, sizeof(data), input_file); for (size_t i = 0; i < bytes_read; i++) { buffer_High[i] = data[i + (sizeof(data)/2)]; buffer_Low[i] = data[i]; } if (bytes_read == 0) { if (feof(input_file)) { decoding = false; // eof reached } else { fprintf(stderr, "Error reading from input file\n"); fclose(input_file); fclose(output_file); return 1; } } // Decode data unsigned char decoded_data[sizeof(data)]; decoded_data[sizeof(data)] = decode_combine_nibbles(*buffer_High, *buffer_Low); // Write data fwrite(decoded_data, 1, bytes_read, output_file); } return 0; }