nix_utf8_aesthetic

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

main.c (831B)


      1 /*
      2 2018 David DiPaola
      3 licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/)
      4 */
      5 
      6 #include <unistd.h>
      7 
      8 int
      9 main() {
     10 	char ch;
     11 	while (read(STDIN_FILENO, &ch, sizeof(ch)) == sizeof(ch)) {
     12 		if (ch == 0x20) {
     13 			/* write codepoint 0x3000 */
     14 			char utf8[] = {
     15 				0b11100000 |   0b0011,
     16 				0b10000000 | 0b000000,
     17 				0b10000000 | 0b000000,
     18 			};
     19 			write(STDOUT_FILENO, utf8, sizeof(utf8));
     20 		}
     21 		else if ((ch >= 0x21) && (ch <= 0x7E)) {
     22 			/* write codepoints 0xFF01-0xFF5E */
     23 			char offset = ch - 0x20;
     24 			char utf8[] = {
     25 				0b11100000 |                        0b1111,
     26 				0b10000000 | (0b1111 << 2) | (offset >> 6),
     27 				0b10000000 |           (offset & 0b111111),
     28 			};
     29 			write(STDOUT_FILENO, utf8, sizeof(utf8));
     30 		}
     31 		else {
     32 			write(STDOUT_FILENO, &ch, sizeof(ch));
     33 		}
     34 	}
     35 
     36 	return 0;
     37 }
     38