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