From 22886c4a146a9c9b048994be99db816e878e6478 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Tue, 9 Jun 2015 22:04:43 +0200 Subject: [PATCH] Add varrec, a little tool to convert files with variable records to byte streams. --- tools/varrec.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tools/varrec.c diff --git a/tools/varrec.c b/tools/varrec.c new file mode 100644 index 0000000..390f889 --- /dev/null +++ b/tools/varrec.c @@ -0,0 +1,34 @@ +/* + * A little tool to convert files with variable records to byte streams. + * + * Each record consist of 2 bytes of length (little endian) followed by + * that number of data bytes. + * + * If the length is odd, there is a padding byte. This byte does not have + * to be 0. + */ +#include + +int main(int argc, char **argv) +{ + while (!feof(stdin)) { + int count, savecount; + unsigned char ch; + + ch = getchar(); + count = ch; + ch = getchar(); + count += ch << 8; + + savecount = count; + + while (count-- > 0) { + ch = getchar(); + putchar(ch); + } + + if (savecount & 1) { + getchar(); + } + } +}