/* * UNG's Not GNU * * Copyright (c) 2022, Jakob Kaivo * * 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 #include #include #include #include #include #include #include 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; }