diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/test-a85d.c |
Initial commit
Diffstat (limited to 'support/dktools/test-a85d.c')
-rw-r--r-- | support/dktools/test-a85d.c | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/support/dktools/test-a85d.c b/support/dktools/test-a85d.c new file mode 100644 index 0000000000..2c8d8410f2 --- /dev/null +++ b/support/dktools/test-a85d.c @@ -0,0 +1,148 @@ +/* + 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-a85d.ctr +*/ + + +#line 1 "test-a85d.ctr" +/** @file test-dk4a85d.c Decoding ASCII-85 encoded data. + The program converts ASCII-85 encoded text read from stdin + and writes binary data to stdout. + + This file is an example how to use the dk4_a85_dec_t type. +*/ + +#include "dk4conf.h" + +#include <stdio.h> +#if DK4_ON_WINDOWS +#include <io.h> +#endif + +#include "dk4a85d.h" +#include "dk4edstm.h" + + + + + +#line 21 "test-a85d.ctr" + + + +int main(int argc, char *argv[]) +{ + dk4_a85_dec_t a85d; /* Decoder */ + const unsigned char *uptr; /* Pointer to decoders output buffer */ + size_t sz; /* Decoder output buffer size */ + size_t i; /* Current output buffer index */ + int c; /* Input character from stdin */ + int cc = 1; /* Flag: Can continue */ + int exval = 0; /* Exit status code */ +#if DK4_ON_WINDOWS + int oldmode; /* Previous file mode for stdout */ +#endif + + + +#line 38 "test-a85d.ctr" + + +#line 39 "test-a85d.ctr" + + /* Initialize decoder. + */ + dk4a85_dec_init(&a85d, NULL); + + /* Change file mode for stdout to binary on Windows. + */ +#if DK4_ON_WINDOWS + oldmode = _setmode(_fileno(stdout), _O_BINARY); +#endif + + /* Process standard input contents. + */ + while (1 == cc) { + c = fgetc(stdin); + if (EOF != c) { + switch (dk4a85_dec_add(&a85d, c, NULL)) { + case DK4_EDSTM_FINISHED : { + /* Decoder indicates that output is available. + */ + uptr = NULL; sz = 0; + if (1 == dk4a85_dec_output(&uptr, &sz, &a85d, NULL)) { + if ((NULL != uptr) && (0 < sz)) { + /* Output really found, write to stdout. + */ + for (i = 0; i < sz; i++) { + if (EOF == fputc(uptr[i], stdout)) { + exval = 1; + /* ERROR: Failed to write output */ + } + } + } + } + } break; + case DK4_EDSTM_STOP : { + /* EOD marker found, stop processing. + */ + cc = 0; + } break; + case DK4_EDSTM_ERROR : { + /* ERROR: Decoding error occured. */ + exval = 1; + cc = -1; + } break; + } + } else { + cc = 0; + } + } + + /* Check for incomplete final sequence in decoder. + */ + if (0 == cc) { + switch (dk4a85_dec_finish(&a85d, NULL)) { + case DK4_EDSTM_FINISHED : { + /* Decoder indicates that output is available. + */ + uptr = NULL; sz = 0; + if (1 == dk4a85_dec_output(&uptr, &sz, &a85d, NULL)) { + if ((NULL != uptr) && (0 < sz)) { + /* Output really found, write to stdout. + */ + for (i = 0; i < sz; i++) { + if (EOF == fputc(uptr[i], stdout)) { + exval = 1; + /* ERROR: Failed to write output */ + } + } + } + } + } break; + case DK4_EDSTM_ERROR : { + exval = 1; + /* ERROR: Decoding error occured */ + } break; + } + } + + /* Restore previous file mode on Windows. + */ + fflush(stdout); +#if DK4_ON_WINDOWS + _setmode(_fileno(stdout), oldmode); +#endif + + + +#line 125 "test-a85d.ctr" + + +#line 126 "test-a85d.ctr" + + exit(exval); return exval; +} + |