nix_utf8_aesthetic

Simple tool to generate aesthetic text
git clone https://0xdd.org/code/nix_utf8_aesthetic.git
Log | Files | Refs | README | LICENSE

commit 2cc7e3ddb26f33b35c747c95bc191a08183bd844
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Sun, 16 Dec 2018 19:40:57 -0500

initial commit

Diffstat:
A.gitignore | 2++
AMakefile | 12++++++++++++
Amain.c | 33+++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +text_aesthetic + diff --git a/Makefile b/Makefile @@ -0,0 +1,12 @@ +BIN = text_aesthetic + +.PHONY: all +all: $(BIN) + +$(BIN): main.c + $(CC) $(CFLAGS) $< -o $@ + +.PHONY: clean +clean: + rm -rf $(BIN) + diff --git a/main.c b/main.c @@ -0,0 +1,33 @@ +#include <unistd.h> + +int +main() { + char ch; + while (read(STDIN_FILENO, &ch, sizeof(ch)) == sizeof(ch)) { + if (ch == 0x20) { + /* write codepoint 0x3000 */ + char utf8[] = { + 0b11100000 | 0b0011, + 0b10000000 | 0b000000, + 0b10000000 | 0b000000, + }; + write(STDOUT_FILENO, utf8, sizeof(utf8)); + } + else if ((ch >= 0x21) && (ch <= 0x7E)) { + /* write codepoints 0xFF01-0xFF5E */ + char offset = ch - 0x20; + char utf8[] = { + 0b11100000 | 0b1111, + 0b10000000 | (0b1111 << 2) | (offset >> 6), + 0b10000000 | (offset & 0b111111), + }; + write(STDOUT_FILENO, utf8, sizeof(utf8)); + } + else { + write(STDOUT_FILENO, &ch, sizeof(ch)); + } + } + + return 0; +} +