>From ada3702813d792fa9225c9812f7066f5a905d540 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jan 2022 17:01:07 +0100 Subject: [PATCH 2/2] terminfo: Add tests. * tests/test-terminfo.c: New file. * modules/terminfo-tests: New file. --- ChangeLog | 4 ++ modules/terminfo-tests | 13 +++++++ tests/test-terminfo.c | 87 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 modules/terminfo-tests create mode 100644 tests/test-terminfo.c diff --git a/ChangeLog b/ChangeLog index 16e2955418..4c9a1e7989 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2022-01-30 Bruno Haible + terminfo: Add tests. + * tests/test-terminfo.c: New file. + * modules/terminfo-tests: New file. + terminfo, terminfo-h: New modules. * lib/terminfo.h: New file, from GNU gettext. * m4/terminfo.m4: New file, from GNU gettext. diff --git a/modules/terminfo-tests b/modules/terminfo-tests new file mode 100644 index 0000000000..50d7a45d74 --- /dev/null +++ b/modules/terminfo-tests @@ -0,0 +1,13 @@ +Files: +tests/test-terminfo.c + +Depends-on: +terminfo-h +unistd + +configure.ac: + +Makefile.am: +TESTS += test-terminfo +check_PROGRAMS += test-terminfo +test_terminfo_LDADD = $(LDADD) @LIBTERMINFO@ diff --git a/tests/test-terminfo.c b/tests/test-terminfo.c new file mode 100644 index 0000000000..85c3e0bcfb --- /dev/null +++ b/tests/test-terminfo.c @@ -0,0 +1,87 @@ +/* Ad-hoc testing program for . + Copyright (C) 2022 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "terminfo.h" + +#include +/* Get getenv(). */ +#include +/* Get STDOUT_FILENO. */ +#include + +int +main (int argc, char *argv[]) +{ + const char *underline_on = NULL; + const char *underline_off = NULL; + const char *bold_on = NULL; + const char *invert_on = NULL; + const char *attributes_off = NULL; + + { + const char *term = getenv ("TERM"); + if (term != NULL && *term != '\0') + { + #if HAVE_TERMINFO + int err = 1; + if (setupterm (term, STDOUT_FILENO, &err) || err == 1) + { + underline_on = tigetstr ("smul"); + underline_off = tigetstr ("rmul"); + bold_on = tigetstr ("bold"); + invert_on = tigetstr ("rev"); + attributes_off = tigetstr ("sgr0"); + } + #elif HAVE_TERMCAP + static char tbuf[2048]; + if (tgetent (tbuf, term) > 0) + { + underline_on = tgetstr ("us", NULL); + underline_off = tgetstr ("ue", NULL); + bold_on = tgetstr ("md", NULL); + invert_on = tgetstr ("mr", NULL); + attributes_off = tgetstr ("me", NULL); + } + #endif + } + } + + if (bold_on) tputs (bold_on, 1, putchar); + printf ("#include"); + if (attributes_off) tputs (attributes_off, 1, putchar); + printf (" \n"); + if (underline_on) tputs (underline_on, 1, putchar); + printf ("int"); + if (underline_off) tputs (underline_off, 1, putchar); + printf ("\n"); + if (invert_on) tputs (invert_on, 1, putchar); + printf ("main"); + if (attributes_off) tputs (attributes_off, 1, putchar); + printf (" ()\n"); + printf ("{\n"); + printf (" printf (\"Hello world\\n\");\n"); + printf (" "); + if (bold_on) tputs (bold_on, 1, putchar); + printf ("return"); + if (attributes_off) tputs (attributes_off, 1, putchar); + printf (" 0;\n"); + printf ("}\n"); + + return 0; +} -- 2.25.1