summaryrefslogtreecommitdiff
path: root/unctrl/unctrl.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-13 19:51:54 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-13 19:51:54 -0400
commitfa799768c4f6d97c5f60a37829ad1b457b7c0096 (patch)
treeed28b64735a6a79b10ecf1a87296f36e88745f4e /unctrl/unctrl.c
separate from libc
Diffstat (limited to 'unctrl/unctrl.c')
-rw-r--r--unctrl/unctrl.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/unctrl/unctrl.c b/unctrl/unctrl.c
new file mode 100644
index 0000000..fc77e6b
--- /dev/null
+++ b/unctrl/unctrl.c
@@ -0,0 +1,29 @@
+#include <unctrl.h>
+#include <curses.h>
+#include <ctype.h>
+#include <stddef.h>
+
+char * unctrl(chtype c)
+{
+ static char buf[3];
+ char * ret = NULL;
+ int ch = c & A_CHARTEXT;
+
+ if (iscntrl(ch)) {
+ buf[0] = '^';
+ buf[1] = ch + 'A';
+ buf[2] = '\0';
+ ret = buf;
+ } else if (isprint(ch)) {
+ buf[0] = ch;
+ buf[1] = '\0';
+ ret = buf;
+ }
+
+ return ret;
+}
+
+/*
+XOPEN(4)
+LINK(curses)
+*/