From 795a8ecaf5656d299139e2c41fab19573bdac0c6 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sat, 7 Nov 2026 05:33:00 +0300 Subject: publish --- src/rle-dec.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/rle-dec.c (limited to 'src/rle-dec.c') diff --git a/src/rle-dec.c b/src/rle-dec.c new file mode 100644 index 0000000..02a006c --- /dev/null +++ b/src/rle-dec.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +#include "config.h" + +int +main (int argc, char *argv[]) +{ + setlocale (LC_ALL, ""); + + if (argc != 3) { + fprintf (stderr, "Usage: %s {infile} {outfile}\n", basename (argv[0])); + return EXIT_FAILURE; + } + + FILE *istream = fopen (argv[1], "r,ccs="CCS); + if (istream == NULL) { + perror (NULL); + return EXIT_FAILURE; + } + + FILE *ostream = fopen (argv[2], "w,ccs="CCS); + // FILE *ostream = stdout; + if (ostream == NULL) { + perror (NULL); + return EXIT_FAILURE; + } + + wint_t current = fgetwc (istream); + while (current != WEOF) { + wint_t next = fgetwc (istream); + if (next == current) { + size_t count; + fwscanf (istream, L"%llu", &count); + fgetwc (istream); + while (count--) + fputwc (current, ostream); + current = fgetwc (istream); + } else { + fputwc (current, ostream); + current = next; + } + } + + if (fclose (ostream) == EOF) { + perror (NULL); + return EXIT_FAILURE; + } + + if (fclose (istream) == EOF) { + perror (NULL); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} -- cgit v1.3.1