nstrftime, c-nstrftime tests: Avoid test failures on native Windows.
[gnulib.git] / tests / test-termcap.c
blob730b8a4c1cb359a13a727874628614f2c0f3c870
1 /* Ad-hoc testing program for <termcap.h>.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include "termcap.h"
22 #include <stdio.h>
23 /* Get getenv(). */
24 #include <stdlib.h>
25 /* Get STDOUT_FILENO. */
26 #include <unistd.h>
28 int
29 main (int argc, char *argv[])
31 const char *underline_on = NULL;
32 const char *underline_off = NULL;
33 const char *bold_on = NULL;
34 const char *invert_on = NULL;
35 const char *attributes_off = NULL;
38 const char *term = getenv ("TERM");
39 if (term != NULL && *term != '\0')
41 #if HAVE_TERMCAP
42 static char tbuf[2048];
43 if (tgetent (tbuf, term) > 0)
45 underline_on = tgetstr ("us", NULL);
46 underline_off = tgetstr ("ue", NULL);
47 bold_on = tgetstr ("md", NULL);
48 invert_on = tgetstr ("mr", NULL);
49 attributes_off = tgetstr ("me", NULL);
51 #elif HAVE_TERMINFO
52 int err = 1;
53 if (setupterm (term, STDOUT_FILENO, &err) == 0 || err == 1)
55 underline_on = tigetstr ("smul");
56 underline_off = tigetstr ("rmul");
57 bold_on = tigetstr ("bold");
58 invert_on = tigetstr ("rev");
59 attributes_off = tigetstr ("sgr0");
61 #endif
65 if (bold_on) tputs (bold_on, 1, putchar);
66 printf ("#include");
67 if (attributes_off) tputs (attributes_off, 1, putchar);
68 printf (" <stdio.h>\n");
69 if (underline_on) tputs (underline_on, 1, putchar);
70 printf ("int");
71 if (underline_off) tputs (underline_off, 1, putchar);
72 printf ("\n");
73 if (invert_on) tputs (invert_on, 1, putchar);
74 printf ("main");
75 if (attributes_off) tputs (attributes_off, 1, putchar);
76 printf (" ()\n");
77 printf ("{\n");
78 printf (" printf (\"Hello world\\n\");\n");
79 printf (" ");
80 if (bold_on) tputs (bold_on, 1, putchar);
81 printf ("return");
82 if (attributes_off) tputs (attributes_off, 1, putchar);
83 printf (" 0;\n");
84 printf ("}\n");
86 return 0;