summaryrefslogtreecommitdiff
path: root/support/dktools/test-rld.ctr
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
committerNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
commit1f457376b478257b88d4a857f5ec1b6155442dd7 (patch)
tree2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/test-rld.ctr
parentac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff)
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/test-rld.ctr')
-rw-r--r--support/dktools/test-rld.ctr112
1 files changed, 0 insertions, 112 deletions
diff --git a/support/dktools/test-rld.ctr b/support/dktools/test-rld.ctr
deleted file mode 100644
index 2bd2984ceb..0000000000
--- a/support/dktools/test-rld.ctr
+++ /dev/null
@@ -1,112 +0,0 @@
-
-#include <stdio.h>
-#include "dk4rld.h"
-#include "dk4edstm.h"
-
-/*
- Example file for run-length decoding.
- The program reads data from standard input, applies
- run-length decoding and writes result data to standard
- output.
-
- For better understanding we only do minimal diagnostics
- here (set exit status code).
- In real world programs one would issue more diagnostics
- on problems.
-*/
-
-
-int main(int argc, char *argv[])
-{
- dk4_rl_dec_t dec; /* Decoder */
- const unsigned char *ucptr; /* Address of output buffer */
- size_t sz; /* Number of output characters */
- size_t i; /* Current output char index */
-#if DK4_ON_WINDOWS
- int oldimode; /* Old file mode for stdin */
- int oldomode; /* Old file mode for stdout */
-#endif
- int ic; /* Current input char from stdin */
- int stopped = 0; /* Flag: EOD found */
- int exval = 0; /* Exit status code */
-
- /* On Windows we must set stdin and stdout to binary mode explicitly.
- */
-#if DK4_ON_WINDOWS
- oldimode = _setmode(_fileno(stdin), _O_BINARY);
- oldomode = _setmode(_fileno(stdout), _O_BINARY);
-#endif
-
- /* Initialize decoder
- */
- dk4rld_init(&dec, NULL);
-
- /* Process standard input.
- */
- while (EOF != (ic = fgetc(stdin))) {
- if (1 == stopped) {
- stopped = 2;
- /* Error: Addtional bytes after EOD marker */
- }
- switch (dk4rld_add(&dec, (unsigned char)ic, NULL)) {
- case DK4_EDSTM_FINISHED : {
- ucptr = NULL; sz = 0;
- if (0 != dk4rld_output(&ucptr, &sz, &dec, NULL)) {
- if ((NULL != ucptr) && (0 < sz)) {
- for (i = 0; i < sz; i++) {
- if (EOF == fputc((int)(ucptr[i]), stdout)) {
- exval = 1;
- /* Error: Failed to write to standard output */
- }
- }
- }
- }
- } break;
- case DK4_EDSTM_STOP : {
- if (0 == stopped) { stopped = 1; }
- } break;
- case DK4_EDSTM_ERROR : {
- exval = 1;
- /* Error: Not properly run-length encoded data */
- } break;
- }
- }
-
- /* If successful so far, process final data from decoder
- and check for syntax error.
- */
- if (0 == exval) {
- switch (dk4rld_finish(&dec, NULL)) {
- case DK4_EDSTM_FINISHED : {
- ucptr = NULL; sz = 0;
- if (0 != dk4rld_output(&ucptr, &sz, &dec, NULL)) {
- if ((NULL != ucptr) && (0 < sz)) {
- for (i = 0; i < sz; i++) {
- if (EOF == fputc((int)(ucptr[i]), stdout)) {
- exval = 1;
- /* Error: Failed to write to standard output */
- }
- }
- }
- }
- } break;
- case DK4_EDSTM_ERROR : {
- exval = 1;
- /* Error: Not properly run-length encoded data */
- } break;
- }
- }
-
- /* Restore previous file mode for stdin and stdout on Windows.
- */
-#if DK4_ON_WINDOWS
- fflush(stdout);
- _setmode(_fileno(stdout), oldomode);
- _setmode(_fileno(stdin), oldimode);
-#endif
-
- /* Exit, indicate success or error.
- */
- exit(exval); return exval;
-}
-