1*433d6423SLionel Sambuc /* termcap - print termcap settings Author: Terrence Holm */
2*433d6423SLionel Sambuc
3*433d6423SLionel Sambuc #include <stdlib.h>
4*433d6423SLionel Sambuc #include <termcap.h>
5*433d6423SLionel Sambuc #include <stdio.h>
6*433d6423SLionel Sambuc
7*433d6423SLionel Sambuc #define TC_BUFFER 1024 /* Size of termcap(3) buffer */
8*433d6423SLionel Sambuc
9*433d6423SLionel Sambuc /****************************************************************/
10*433d6423SLionel Sambuc /* */
11*433d6423SLionel Sambuc /* termcap [ type ] */
12*433d6423SLionel Sambuc /* */
13*433d6423SLionel Sambuc /* Prints out all of the termcap capabilities as described */
14*433d6423SLionel Sambuc /* in termcap(4). If "type" is not supplied then $TERM is */
15*433d6423SLionel Sambuc /* used. */
16*433d6423SLionel Sambuc /* */
17*433d6423SLionel Sambuc /****************************************************************/
18*433d6423SLionel Sambuc
19*433d6423SLionel Sambuc int main(int argc, char **argv);
20*433d6423SLionel Sambuc void Print(char *comment, char *name);
21*433d6423SLionel Sambuc void Error(char *message, char *arg);
22*433d6423SLionel Sambuc
main(argc,argv)23*433d6423SLionel Sambuc int main(argc, argv)
24*433d6423SLionel Sambuc int argc;
25*433d6423SLionel Sambuc char *argv[];
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc {
28*433d6423SLionel Sambuc char *term;
29*433d6423SLionel Sambuc char buffer[ TC_BUFFER ];
30*433d6423SLionel Sambuc
31*433d6423SLionel Sambuc
32*433d6423SLionel Sambuc /* Check for an argument */
33*433d6423SLionel Sambuc
34*433d6423SLionel Sambuc if ( argc > 2 )
35*433d6423SLionel Sambuc Error( "Usage: %s [ type ]\n", argv[0] );
36*433d6423SLionel Sambuc
37*433d6423SLionel Sambuc if ( argc == 2 )
38*433d6423SLionel Sambuc term = argv[1];
39*433d6423SLionel Sambuc else
40*433d6423SLionel Sambuc term = getenv( "TERM" );
41*433d6423SLionel Sambuc
42*433d6423SLionel Sambuc if ( term == NULL )
43*433d6423SLionel Sambuc Error( "termcap: $TERM is not defined\n", "" );
44*433d6423SLionel Sambuc
45*433d6423SLionel Sambuc
46*433d6423SLionel Sambuc /* Read in the termcap entry */
47*433d6423SLionel Sambuc
48*433d6423SLionel Sambuc if ( tgetent( buffer, term ) != 1 )
49*433d6423SLionel Sambuc Error( "termcap: No termcap entry for %s\n", term );
50*433d6423SLionel Sambuc
51*433d6423SLionel Sambuc
52*433d6423SLionel Sambuc /* Print out the entry's contents */
53*433d6423SLionel Sambuc
54*433d6423SLionel Sambuc printf( "TERM = %s\n\n", term );
55*433d6423SLionel Sambuc
56*433d6423SLionel Sambuc if ( tgetflag( "am" ) == 1 )
57*433d6423SLionel Sambuc printf( "End of line wraps to next line (am)\n" );
58*433d6423SLionel Sambuc
59*433d6423SLionel Sambuc if ( tgetflag( "bs" ) == 1 )
60*433d6423SLionel Sambuc printf( "Ctrl/H performs a backspace (bs)\n" );
61*433d6423SLionel Sambuc
62*433d6423SLionel Sambuc printf( "Number of columns (co) = %d\n", tgetnum( "co" ) );
63*433d6423SLionel Sambuc printf( "Number of lines (li) = %d\n", tgetnum( "li" ) );
64*433d6423SLionel Sambuc
65*433d6423SLionel Sambuc Print( "Clear to end of line", "ce" );
66*433d6423SLionel Sambuc Print( "Clear to end of screen", "cd" );
67*433d6423SLionel Sambuc Print( "Clear the whole screen", "cl" );
68*433d6423SLionel Sambuc
69*433d6423SLionel Sambuc Print( "Start \"stand out\" mode", "so" );
70*433d6423SLionel Sambuc Print( "End \"stand out\" mode", "se" );
71*433d6423SLionel Sambuc Print( "Start underscore mode", "us" );
72*433d6423SLionel Sambuc Print( "End underscore mode", "ue" );
73*433d6423SLionel Sambuc Print( "Start blinking mode", "mb" );
74*433d6423SLionel Sambuc Print( "Start bold mode", "md" );
75*433d6423SLionel Sambuc Print( "Start reverse mode", "mr" );
76*433d6423SLionel Sambuc Print( "Return to normal mode", "me" );
77*433d6423SLionel Sambuc
78*433d6423SLionel Sambuc Print( "Scroll backwards", "sr" );
79*433d6423SLionel Sambuc Print( "Cursor motion", "cm" );
80*433d6423SLionel Sambuc
81*433d6423SLionel Sambuc Print( "Up one line", "up" );
82*433d6423SLionel Sambuc Print( "Down one line", "do" );
83*433d6423SLionel Sambuc Print( "Left one space", "le" );
84*433d6423SLionel Sambuc Print( "Right one space", "nd" );
85*433d6423SLionel Sambuc Print( "Move to top left corner", "ho" );
86*433d6423SLionel Sambuc
87*433d6423SLionel Sambuc Print( "Generated by \"UP\"", "ku" );
88*433d6423SLionel Sambuc Print( "Generated by \"DOWN\"", "kd" );
89*433d6423SLionel Sambuc Print( "Generated by \"LEFT\"", "kl" );
90*433d6423SLionel Sambuc Print( "Generated by \"RIGHT\"", "kr" );
91*433d6423SLionel Sambuc Print( "Generated by \"HOME\"", "kh" );
92*433d6423SLionel Sambuc Print( "Generated by \"END\"", "@7" );
93*433d6423SLionel Sambuc Print( "Generated by \"PGUP\"", "kP" );
94*433d6423SLionel Sambuc Print( "Generated by \"PGDN\"", "kN" );
95*433d6423SLionel Sambuc Print( "Generated by \"F1\" ", "k1" );
96*433d6423SLionel Sambuc Print( "Generated by numeric \"+\"", "%5" );
97*433d6423SLionel Sambuc Print( "Generated by numeric \"-\"", "%8" );
98*433d6423SLionel Sambuc Print( "Generated by numeric \"5\"", "K2" );
99*433d6423SLionel Sambuc
100*433d6423SLionel Sambuc return( 0 );
101*433d6423SLionel Sambuc }
102*433d6423SLionel Sambuc
103*433d6423SLionel Sambuc
104*433d6423SLionel Sambuc
105*433d6423SLionel Sambuc
106*433d6423SLionel Sambuc
107*433d6423SLionel Sambuc
108*433d6423SLionel Sambuc /****************************************************************/
109*433d6423SLionel Sambuc /* */
110*433d6423SLionel Sambuc /* Print( comment, name ) */
111*433d6423SLionel Sambuc /* */
112*433d6423SLionel Sambuc /* If a termcap entry exists for "name", then */
113*433d6423SLionel Sambuc /* print out "comment" and the entry. Control */
114*433d6423SLionel Sambuc /* characters are printed as ^x. */
115*433d6423SLionel Sambuc /* */
116*433d6423SLionel Sambuc /****************************************************************/
117*433d6423SLionel Sambuc
118*433d6423SLionel Sambuc
Print(comment,name)119*433d6423SLionel Sambuc void Print( comment, name )
120*433d6423SLionel Sambuc char *comment;
121*433d6423SLionel Sambuc char *name;
122*433d6423SLionel Sambuc
123*433d6423SLionel Sambuc {
124*433d6423SLionel Sambuc char entry[ 50 ];
125*433d6423SLionel Sambuc char *p = entry;
126*433d6423SLionel Sambuc
127*433d6423SLionel Sambuc if ( tgetstr( name, &p ) == NULL )
128*433d6423SLionel Sambuc return;
129*433d6423SLionel Sambuc
130*433d6423SLionel Sambuc printf( "%-32s (%s) = ", comment, name );
131*433d6423SLionel Sambuc
132*433d6423SLionel Sambuc for ( p = entry; *p != '\0'; ++p )
133*433d6423SLionel Sambuc if ( *p < ' ' )
134*433d6423SLionel Sambuc printf( "^%c", *p + '@' );
135*433d6423SLionel Sambuc else if ( *p == '\177' )
136*433d6423SLionel Sambuc printf( "^?" );
137*433d6423SLionel Sambuc else
138*433d6423SLionel Sambuc putchar( *p );
139*433d6423SLionel Sambuc
140*433d6423SLionel Sambuc putchar( '\n' );
141*433d6423SLionel Sambuc }
142*433d6423SLionel Sambuc
143*433d6423SLionel Sambuc
144*433d6423SLionel Sambuc
145*433d6423SLionel Sambuc
146*433d6423SLionel Sambuc
147*433d6423SLionel Sambuc
148*433d6423SLionel Sambuc /****************************************************************/
149*433d6423SLionel Sambuc /* */
150*433d6423SLionel Sambuc /* Error( message, arg ) */
151*433d6423SLionel Sambuc /* */
152*433d6423SLionel Sambuc /* Printf the "message" and abort. */
153*433d6423SLionel Sambuc /* */
154*433d6423SLionel Sambuc /****************************************************************/
155*433d6423SLionel Sambuc
156*433d6423SLionel Sambuc
Error(message,arg)157*433d6423SLionel Sambuc void Error( message, arg )
158*433d6423SLionel Sambuc char *message;
159*433d6423SLionel Sambuc char *arg;
160*433d6423SLionel Sambuc
161*433d6423SLionel Sambuc {
162*433d6423SLionel Sambuc fprintf( stderr, message, arg );
163*433d6423SLionel Sambuc exit( 1 );
164*433d6423SLionel Sambuc }
165