summaryrefslogtreecommitdiff
path: root/util/dump2cuddlekeys
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-19 01:54:39 +0100
committerLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-19 02:11:32 +0100
commit6d263c7d4e0f4b1d34694b5d3d159ccb20b3db02 (patch)
tree41578268cf68b2d9ea1737687a0f98af979948d8 /util/dump2cuddlekeys
parent5881b4d5c1040c762599f90e091e4cc4c3abe6b1 (diff)
downloadcuddles-6d263c7d4e0f4b1d34694b5d3d159ccb20b3db02.tar.xz
keyboard driver and threads
* PS/2 keyboard driver * interactive shell * move away from \0 terminated strings to sized slices * coroutine threads and IRQ queues
Diffstat (limited to 'util/dump2cuddlekeys')
-rw-r--r--util/dump2cuddlekeys/.gitignore1
-rw-r--r--util/dump2cuddlekeys/Makefile8
-rw-r--r--util/dump2cuddlekeys/main.c89
3 files changed, 98 insertions, 0 deletions
diff --git a/util/dump2cuddlekeys/.gitignore b/util/dump2cuddlekeys/.gitignore
new file mode 100644
index 0000000..ba69a71
--- /dev/null
+++ b/util/dump2cuddlekeys/.gitignore
@@ -0,0 +1 @@
+dump2cuddlekeys
diff --git a/util/dump2cuddlekeys/Makefile b/util/dump2cuddlekeys/Makefile
new file mode 100644
index 0000000..07b7bb2
--- /dev/null
+++ b/util/dump2cuddlekeys/Makefile
@@ -0,0 +1,8 @@
+dump2cuddlekeys: main.c
+ gcc -Wall -Wextra main.c -o dump2cuddlekeys
+
+dumpkeys:
+ dumpkeys -C/dev/tty1 | grep '^keycode' | less
+
+preview: map2cuddlekeys
+ dumpkeys -C/dev/tty1 | ./dump2cuddlekeys | hexdump -C
diff --git a/util/dump2cuddlekeys/main.c b/util/dump2cuddlekeys/main.c
new file mode 100644
index 0000000..ec0039e
--- /dev/null
+++ b/util/dump2cuddlekeys/main.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int main()
+{
+ char keymap[256] = { '\0' };
+
+ char *line = NULL;
+ size_t cap = 0;
+ ssize_t len;
+ while ((len = getline(&line, &cap, stdin)) != -1) {
+ int code;
+ char key[len+1];
+
+ if (sscanf(line, "keycode %d = %s", &code, key) != 2)
+ continue;
+
+ char c = '\0';
+
+ struct {
+ char c;
+ const char *name;
+ } defs[] = {
+ { '\n', "Return" },
+ { ' ', "space" },
+ { '\b', "Delete" },
+ { '!', "exclam" },
+ { '&', "ampersand" },
+ { '%', "percent" },
+ { '$', "dollar" },
+ { '\'', "apostrophe" },
+ { '(', "parenleft" },
+ { ')', "parenright" },
+ { '*', "asterisk" },
+ { '+', "plus" },
+ { ',', "comma" },
+ { '-', "minus" },
+ { '.', "period" },
+ { '/', "slash" },
+ { '0', "zero" },
+ { '1', "one" },
+ { '2', "two" },
+ { '3', "three" },
+ { '4', "four" },
+ { '5', "five" },
+ { '6', "six" },
+ { '7', "seven" },
+ { '8', "eight" },
+ { '9', "nine" },
+ { ':', "colon" },
+ { ';', "semicolon" },
+ { '<', "less" },
+ { '=', "equal" },
+ { '>', "greater" },
+ { '?', "question" },
+ { '\n', "linefeed" },
+ { '\\', "backslash" },
+ { '\t', "Tab" },
+ { '@', "at" },
+ { '[', "bracketleft" },
+ { ']', "bracketright" },
+ { '(', "{" },
+ { ')', "}" },
+ { '#', "numbersign" },
+ { '^', "asciicircum" },
+ };
+
+ if (strlen(key) == 1)
+ c = key[0];
+ else if (strlen(key) == 2 && key[0] == '+')
+ c = key[1];
+ else for (size_t i = 0; i < sizeof defs / sizeof *defs; i++)
+ if (strcmp(defs[i].name, key) == 0) {
+ c = defs[i].c;
+ break;
+ }
+
+ if (c != '\0')
+ keymap[(unsigned char) code] = (char) c;
+ else if (strcmp(key, "nul") != 0)
+ {} // fprintf(stderr, "unhandled: %s\n", key);
+ }
+
+ if (line != NULL)
+ free(line);
+
+ fwrite(keymap, 1, 256, stdout);
+}