/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: test-a85e.ctr */ #line 1 "test-a85e.ctr" /** @file test-a85e.c Convert binary input from stdin to ASCII-85 encoded text on stdout. This is an example how to used the dk4_a85_enc_t type. */ #include "dk4conf.h" #include #if DK4_ON_WINDOWS #include #endif #include "dk4a85e.h" #include "dk4edstm.h" #line 20 "test-a85e.ctr" int main(int argc, char *argv[]) { dk4_a85_enc_t a85e; /* Encoder */ const char *dptr; /* Pointer to encoder output buffer */ size_t sz; /* Size of encoder output buffer */ size_t i; /* Current output buffer index to process */ int c; /* Input character */ int linepos = 0; /* Position within output text line */ #if DK4_ON_WINDOWS int oldmode; /* Previous file mode for stdin */ #endif #line 36 "test-a85e.ctr" #line 37 "test-a85e.ctr" /* Set file mode for standard input to binary on Windows. */ #if DK4_ON_WINDOWS oldmode = _setmode(0, _O_BINARY); #endif /* Initialize encoder. */ dk4a85_enc_init(&a85e, 1, NULL); /* Process contents from stdin. */ while (EOF != (c = fgetc(stdin))) { switch (dk4a85_enc_add(&a85e, (unsigned char)c, NULL)) { case DK4_EDSTM_FINISHED: { /* Encoder indicates that output is available. */ dptr = NULL; sz = 0; if (0 != dk4a85_enc_output(&dptr, &sz, &a85e, NULL)) { if ((NULL != dptr) && (0 < sz)) { /* Output really found, write to stdout. */ for (i = 0; i < sz; i++) { fputc(dptr[i], stdout); if (++linepos >= 75) { fputc('\n', stdout); linepos = 0; } } } } } break; } } /* Restore previous file mode for stdin on Windows */ #if DK4_ON_WINDOWS _setmode(0, oldmode); #endif /* Check for final unprocessed sequence in encoder. */ switch (dk4a85_enc_finish(&a85e, NULL)) { case DK4_EDSTM_FINISHED: { /* Encoder indicates that output is available. */ dptr = NULL; sz = 0; if (0 != dk4a85_enc_output(&dptr, &sz, &a85e, NULL)) { if ((NULL != dptr) && (0 < sz)) { /* Output really found, write to stdout. */ for (i = 0; i < sz; i++) { fputc(dptr[i], stdout); if (++linepos >= 75) { fputc('\n', stdout); linepos = 0; } } } } } break; } /* Write EOD marker to output. */ if (74 <= linepos) { fputc('\n', stdout); } fputs("~>\n", stdout); #line 110 "test-a85e.ctr" #line 111 "test-a85e.ctr" exit(0); return 0; }