summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-14 09:35:33 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-14 09:35:33 -0400
commitd5db77157de38c653463a828c6f39d43997986a4 (patch)
tree79b58cfa794637959ad52a2800c6e30d8df1d822
first draft
-rw-r--r--Makefile30
-rw-r--r--untic.c149
2 files changed, 179 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..095d0d1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,30 @@
+.POSIX:
+
+# This Makefile was generated by maje
+# See https://gitlab.com/jkaivo/maje/ for more information
+# Do not edit this Makefile by hand
+
+CC=c99
+LD=$(CC)
+CFLAGS=-Wall -Wextra -Wpedantic -Werror -g
+LDFLAGS=
+LDLIBS=-lcurses
+SRCDIR=.
+OBJDIR=.
+BINDIR=$(OBJDIR)
+DESTDIR=/usr/local
+
+all: $(BINDIR)/untic
+
+clean:
+ rm -f $(BINDIR)/untic $(OBJDIR)/*.o
+
+install: $(BINDIR)/untic
+ cp $(BINDIR)/untic $(DESTDIR)/bin
+
+$(BINDIR)/untic: $(OBJDIR)/untic.o
+$(OBJDIR)/untic.o: $(SRCDIR)/untic.c
+ $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/untic.c
+
+$(BINDIR)/untic:
+ $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/*.o $(LDLIBS)
diff --git a/untic.c b/untic.c
new file mode 100644
index 0000000..274af7a
--- /dev/null
+++ b/untic.c
@@ -0,0 +1,149 @@
+/*
+ * UNG's Not GNU
+ *
+ * Copyright (c) 2022, Jakob Kaivo <jkk@ung.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define _XOPEN_SOURCE 700
+#define _XOPEN_CURSES 700
+#include <curses.h>
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <term.h>
+#include <unctrl.h>
+#include <unistd.h>
+
+static const char *ti_flags[] = {
+ "bw", "am", "bce", "ccc", "xhp", "xhpa", "cpix", "crxm",
+ "xt", "xenl", "eo", "gn", "hc", "chts", "km", "daisy",
+ "hs", "hls", "in", "lpix", "da", "db", "mir", "msgr",
+ "nxon", "xsb", "npc", "ndscr", "nrrmc", "os",
+ "mc5i", "xvpa", "sam", "eslok", "hz", "ul", "xon",
+};
+static const size_t n_flags = sizeof(ti_flags) / sizeof(ti_flags[0]);
+
+static const char *ti_numbers[] = {
+ "bitwin", "bitype", "bufsz", "btns", "cols",
+ "spinh", "spinv", "it", "lh", "lw", "lines",
+ "lm", "ma", "xmc", "colors", "maddr", "mjump",
+ "pairs", "wnum", "mcs", "mls", "nvc", "nlab", "npins",
+ "orc", "orl", "orhi", "orvi", "pb", "cps", "vt", "widcs",
+ "wsl",
+};
+static const size_t n_numbers = sizeof(ti_numbers) / sizeof(ti_numbers[0]);
+
+static const char *ti_strings[] = {
+ "acsc", "scesa", "cbt", "bel", "bicr", "binel",
+ "birep", "cr", "cpi", "lpi", "chr", "cvr", "csr",
+ "rmp", "csnm", "tbc", "mgc", "clear", "el1", "el",
+ "ed", "csin", "colornm", "hpa", "cmdch", "cwin",
+ "cup", "cud1", "home", "civis", "cub1", "mrcup",
+ "cnorm", "cuf1", "ll", "cuu1", "cvvis", "defbi",
+ "defc", "dch1", "dl1", "devt", "dial", "dsl", "dclk", "dispc",
+ "hd", "enacs", "endbi", "smacs", "smam",
+ "blink", "bold", "smcup", "smdc", "dim", "swidm",
+ "sdrfq", "ehhlm", "smir", "sitm", "ehlm", "slm",
+ "elohlm", "smicm", "snlq", "snrmq", "smpch",
+ "prot", "rev", "erhlm", "smsc", "invis", "sshm",
+ "smso", "ssubm", "ssupm", "ethlm", "smul",
+ "sum", "evhlm", "smxon", "ech", "rmacs",
+ "rmam", "sgr0", "rmcup", "rmdc", "rwidm", "rmir",
+ "ritm", "rlm", "rmicm", "rmpch", "rmsc", "rshm",
+ "rmso", "rsubm", "rsupm", "rmul", "rum", "rmxon",
+ "pause", "hook", "flash", "ff", "fsl", "getm",
+ "wingo", "hup", "is1", "is2", "is3", "if", "iprog",
+ "initc", "initp", "ich1", "il1", "ip",
+};
+static const size_t n_strings = sizeof(ti_strings) / sizeof(ti_strings[0]);
+
+int main(int argc, char *argv[])
+{
+ setlocale(LC_ALL, "");
+ char *file = NULL;
+ char *term = NULL;
+
+ int c;
+ while ((c = getopt(argc, argv, "f:")) != -1) {
+ switch(c) {
+ case 'f': /** Read terminfo from file **/
+ file = optarg;
+ break;
+
+ default:
+ return 1;
+ }
+ }
+
+ term = argv[optind];
+
+ if (file != NULL && term != NULL) {
+ fprintf(stderr, "untic: too many operands\n");
+ return 1;
+ }
+
+ if (term != NULL && argc > optind + 1) {
+ fprintf(stderr, "untic: too many operands\n");
+ return 1;
+ }
+
+ /* TODO: handle file != NULL */
+
+ int err = 0;
+ if (setupterm(term, STDIN_FILENO, &err) == ERR) {
+ fprintf(stderr, "untic: couldn't find ");
+ if (err == 0) {
+ fprintf(stderr, "terminal entry in ");
+ }
+ fprintf(stderr, "terminfo database\n");
+ return 1;
+ }
+
+ printf("%s | %s\n", termname(), longname());
+
+ for (size_t i = 0; i < n_flags; i++) {
+ if (tigetflag(ti_flags[i]) > 0) {
+ printf("\t%s,\n", ti_flags[i]);
+ }
+ }
+
+ for (size_t i = 0; i < n_numbers; i++) {
+ int n = tigetnum(ti_numbers[i]);
+ if (n > -1) {
+ printf("\t%s#%d,\n", ti_numbers[i], n);
+ }
+ }
+
+ for (size_t i = 0; i < n_strings; i++) {
+ char *s = tigetstr(ti_strings[i]);
+ if (s && s != (char*)-1) {
+ printf("\t%s=", ti_strings[i]);
+ while (*s) {
+ printf("%s", unctrl(*s));
+ s++;
+ }
+ printf(",\n");
+ }
+ }
+
+ return 0;
+}