File: terminfo.c

package info (click to toggle)
nettoe 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 804 kB
  • sloc: sh: 3,960; ansic: 2,254; makefile: 87
file content (145 lines) | stat: -rw-r--r-- 4,247 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* netToe Version 1.5.1
 *
 * Copyright  2011, 2012, 2013, 2014 Mats Erik Andersson
 *            <meand@users.sourceforge.net>
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>

#if defined USE_TERMINFO || defined USE_TERMCAP
# if (defined HAVE_NCURSES_H || defined HAVE_NCURSES_NCURSES_H) \
	&& (defined USE_TINFO || defined USE_NCURSES)
#  if defined HAVE_NCURSES_NCURSES_H
#   include <ncurses/ncurses.h>
#  else
#   include <ncurses.h>
#  endif
# endif
# if defined HAVE_CURSES_H && defined USE_CURSES
#  include <curses.h>
# endif
# if defined HAVE_NCURSES_TERM_H && USE_NCURSES
#  include <ncurses/term.h>
# elif defined HAVE_TERM_H && !USE_TERMCAP
#  include <term.h>
# elif defined HAVE_TERMCAP_H && USE_TERMCAP
#  include <termcap.h>
# endif

# if !HAVE_PUTP
#  define putp(x)	tputs((x), 1, putchar)
# endif

const char *clear_str = NULL;
const char *bell_str = NULL;
const char *bold_str = NULL;
const char *rmso_str = NULL;
const char *smso_str = NULL;
const char *sgr0_str = NULL;
const char *setab_str = NULL;
const char *setaf_str = NULL;
#endif /* Use terminal capabilities */

int main(void)
{
#if defined USE_TERMINFO || defined USE_TERMCAP
   char *sp;
# if HAVE_SETUPTERM || HAVE_TGETENT
   int err;
# endif /* HAVE_SETUPTERM || HAVE_TGETENT */
# if HAVE_TGETENT
   static char buf[1024];
   char *p = buf;
# endif /* HAVE_TGETENT */

   if ((sp = getenv("TERM")) == NULL) {
      sp = "dumb";
      printf("No environment value set for TERM!\n"
	     "Using \"%s\" instead.\n", sp);
   }

# if HAVE_SETUPTERM
   if (setupterm(sp, fileno(stdout), &err) == ERR) {
      switch (err) {
	case 1: puts("Hardcopy terminal!");
		return EXIT_SUCCESS;
		break;
	case 0: printf("Terminal \"%s\" not found.\n", sp);
		return EXIT_SUCCESS;
		break;
	default: puts("No terminfo database accessible.");
		 return EXIT_SUCCESS;
		 break;
      }
   }
# elif HAVE_TGETENT
   err = tgetent(buf, sp);
   switch (err) {
     case 1: /* Success */
	     break;
     case 0: printf("Terminal \"%s\" not found.\n", sp);
	     return EXIT_SUCCESS;
	     break;
     default: puts("No terminfo database accessible.");
	      return EXIT_SUCCESS;
	      break;
   }
# endif /* !HAVE_SETUPTERM && HAVE_TGETENT */

   printf("Terminal: TERM = %s.\n", sp);

# if HAVE_SETUPTERM
   clear_str = tigetstr("clear");
   bell_str = tigetstr("bel");
   bold_str = tigetstr("bold");
   rmso_str = tigetstr("rmso");
   smso_str = tigetstr("smso");
   sgr0_str = tigetstr("sgr0");
   setab_str = tigetstr("setab");
   setaf_str = tigetstr("setaf");
# elif HAVE_TGETENT
   clear_str = tgetstr("cl", &p);
   bell_str  = tgetstr("bl", &p);
   bold_str  = tgetstr("md", &p);
   rmso_str  = tgetstr("se", &p);
   smso_str  = tgetstr("so", &p);
   sgr0_str  = tgetstr("me", &p);
   setab_str = tgetstr("AB", &p);
   setaf_str = tgetstr("AF", &p);
# endif /* HAVE_TGETENT */
   printf("clear: %s\n", clear_str ? "yes" : "no, using ANSI");
   printf("bell:  %s\n", bell_str ? "yes" : "no, using ANSI");
   printf("bold:  %s\n", bold_str ? "yes" : "no, using ANSI");
   printf("rmso:  %s\n", rmso_str ? "yes" : "no, using ANSI");
   printf("smso:  %s\n", smso_str ? "yes" : "no, using ANSI");
   printf("sgr0:  %s\n", sgr0_str ? "yes" : "no, using ANSI");
   printf("setab: %s\n", setab_str ? "yes" : "no, using ANSI");
   printf("setaf: %s\n", setaf_str ? "yes" : "no, using ANSI");

   return 0;
#else /* No terminal capabilities. */
   printf("No terminal capabilities are in use.\n");

   return 0;
#endif
}