diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-12-15 19:34:12 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-12-15 19:34:12 +1300 |
commit | 031d3c673a70bc322ce0b7c67b97431607446f42 (patch) | |
tree | 8daa8e9bb7fa36d61ecb55325cfee6350e720801 | |
download | wtf8-031d3c673a70bc322ce0b7c67b97431607446f42.tar.gz wtf8-031d3c673a70bc322ce0b7c67b97431607446f42.zip |
First commit wtf8(1), tiny UTF-8 inspector
Just committing this first as I know it works, will make it a bit nicer
now.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | wtf8.c | 26 |
3 files changed, 36 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e7524a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/wtf8 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d72eba5 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: all clean + +CC = clang +CFLAGS = -std=c99 -Weverything -Wno-padded + +all : wtf8 + +clean : + rm -f wtf8 @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + char *p; + int c; + + if (argc != 2) + exit(EXIT_FAILURE); + + for (p = argv[1]; *p; p++) + printf("%02x ", (unsigned char) *p); + putchar('\n'); + + for (p = argv[1]; *p; ) { + for (c = 1; p[c] && (p[c] & 0xC0) == 0x80; c++) + printf(" "); + putchar(' '); + for (; c > 0; c--) + putchar(*p++); + putchar(' '); + } + putchar('\n'); + + exit(EXIT_SUCCESS); +} |