Add new arg to readers and writers.  Use new functions reduce_encode
and reduce_decode.
@@ -6,7 +6,7 @@ DEF_VARR (uint8_t);
static VARR (uint8_t) * orig, *buf1, *buf2;
static size_t input_length1 = 0;
-static size_t reader1 (void *start, size_t len) {
+static size_t reader1 (void *start, size_t len, void *aux_data) {
size_t n = fread (start, 1, len, stdin);
for (size_t i = 0; i < n; i++) VARR_PUSH (uint8_t, orig, ((uint8_t *) start)[i]);
@@ -15,7 +15,7 @@ static size_t reader1 (void *start, size_t len) {
}
static size_t output_length1 = 0;
-static size_t writer1 (const void *start, size_t len) {
+static size_t writer1 (const void *start, size_t len, void *aux_data) {
output_length1 += len;
for (size_t i = 0; i < len; i++) VARR_PUSH (uint8_t, buf1, ((uint8_t *) start)[i]);
return len;
@@ -24,7 +24,7 @@ static size_t writer1 (const void *start, size_t len) {
static size_t size_min (size_t a, size_t b) { return a < b ? a : b; }
static size_t input_length2 = 0;
-static size_t reader2 (void *start, size_t len) {
+static size_t reader2 (void *start, size_t len, void *aux_data) {
size_t s = size_min (len, VARR_LENGTH (uint8_t, buf1) - input_length2);
for (size_t i = 0; i < s; i++)
@@ -34,7 +34,7 @@ static size_t reader2 (void *start, size_t len) {
}
static size_t output_length2 = 0;
-static size_t writer2 (const void *start, size_t len) {
+static size_t writer2 (const void *start, size_t len, void *aux_data) {
output_length2 += len;
for (size_t i = 0; i < len; i++) VARR_PUSH (uint8_t, buf2, ((uint8_t *) start)[i]);
return len;
@@ -55,7 +55,7 @@ int main (void) {
VARR_CREATE (uint8_t, orig, 0);
VARR_CREATE (uint8_t, buf1, 0);
- if (!reduce_do (reader1, writer1)) {
+ if (!reduce_encode (reader1, writer1, NULL)) {
fprintf (stderr, "Error in reducing input file!\n");
return 1;
}
@@ -64,7 +64,7 @@ int main (void) {
(real_usec_time () - start) / 1000.0);
VARR_CREATE (uint8_t, buf2, 0);
start = real_usec_time ();
- if (!reduce_undo (reader2, writer2)) {
+ if (!reduce_decode (reader2, writer2, NULL)) {
fprintf (stderr, "Corrupted input file!\n");
return 1;
}
