1 /* Ad-hoc testing program for <termcap.h>.
2 Copyright (C) 2022-2025 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/>. */
25 /* Get STDOUT_FILENO. */
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')
43 if (setupterm (term
, STDOUT_FILENO
, &err
) == 0 || err
== 1)
45 underline_on
= tigetstr ("smul");
46 underline_off
= tigetstr ("rmul");
47 bold_on
= tigetstr ("bold");
48 invert_on
= tigetstr ("rev");
49 attributes_off
= tigetstr ("sgr0");
52 static char tbuf
[2048];
53 if (tgetent (tbuf
, term
) > 0)
55 underline_on
= tgetstr ("us", NULL
);
56 underline_off
= tgetstr ("ue", NULL
);
57 bold_on
= tgetstr ("md", NULL
);
58 invert_on
= tgetstr ("mr", NULL
);
59 attributes_off
= tgetstr ("me", NULL
);
65 if (bold_on
) tputs (bold_on
, 1, putchar
);
67 if (attributes_off
) tputs (attributes_off
, 1, putchar
);
68 printf (" <stdio.h>\n");
69 if (underline_on
) tputs (underline_on
, 1, putchar
);
71 if (underline_off
) tputs (underline_off
, 1, putchar
);
73 if (invert_on
) tputs (invert_on
, 1, putchar
);
75 if (attributes_off
) tputs (attributes_off
, 1, putchar
);
78 printf (" printf (\"Hello world\\n\");\n");
80 if (bold_on
) tputs (bold_on
, 1, putchar
);
82 if (attributes_off
) tputs (attributes_off
, 1, putchar
);