From 85c8e80edc486f6fe64852a475b242ccf4c904ca Mon Sep 17 00:00:00 2001 From: nemo Date: Sun, 9 Feb 2025 15:08:16 +0100 Subject: [PATCH] init --- .gitignore | 1 + Makefile | 5 +++ main.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..924cb58 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ascii-table diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7f796fa --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: + gcc -Wall -Wextra main.c -o ascii-table + +run: all + ./ascii-table diff --git a/main.c b/main.c new file mode 100644 index 0000000..efcb10b --- /dev/null +++ b/main.c @@ -0,0 +1,91 @@ +#include +#include + +int is_char(char c) +{ + return c >= 32 && c <= 126; +} + +char* char_name(char c) +{ + c %= 128; + + static char buff[2] = {0}; + + switch (c) { + case 0: return "null"; + case 1: return "start of heading"; + case 2: return "start of text"; + case 3: return "end of text"; + case 4: return "end of transmission"; + case 5: return "enquiry"; + case 6: return "aknowledge"; + case 7: return "bell"; + case 8: return "backspace"; + case 9: return "horizontal tab"; + case 10: return "line feed"; + case 11: return "vertical tab"; + case 12: return "form feed"; + case 13: return "carriage return"; + case 14: return "shift out"; + case 15: return "shift in"; + case 16: return "data link escape"; + case 17: return "device control 1"; + case 18: return "device control 2"; + case 19: return "device control 3"; + case 20: return "device control 4"; + case 21: return "negative aknowledge"; + case 22: return "synchronious idle"; + case 23: return "end of trans. block"; + case 24: return "cancel"; + case 25: return "end of medium"; + case 26: return "substitute"; + case 27: return "escape"; + case 28: return "file seperator"; + case 29: return "group seperator"; + case 30: return "record seperator"; + case 31: return "unit seperator"; + case 127: return "del"; + default: buff[0] = c; return buff; + } + + return "wtf?"; +} + +int main() +{ + printf("Dec\tHex\tChar | "); + printf("Dec\tHex\tChar | "); + printf("Dec\tHex\tChar | "); + printf("Dec\tHex\tChar\n"); + printf("--------------------------------------+"); + printf("----------------------+"); + printf("-----------------------+"); + printf("------------------------\n"); + int nb_column = 4; + int u = 128/nb_column; + for (int i = 0; i < u; i++) { + char c; + char* s; + + c = u*0+i; + s = char_name(c); + printf("%d\t%x\t[%s] ", c, c, s); + for (size_t y = 0; y < 19 - strlen(s); y++) { + printf(" "); + } + printf("| "); + + c = u*1+i; + s = char_name(c); + printf("%d\t%x\t[%s] | ", c, c, s); + + c = u*2+i; + s = char_name(c); + printf("%d\t%x\t[%s] | ", c, c, s); + + c = u*3+i; + s = char_name(c); + printf("%d\t%x\t[%s]\n", c, c, s); + } +}