source: trunk/minix/commands/simple/termcap.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 3.9 KB
RevLine 
[9]1/* termcap - print termcap settings Author: Terrence Holm */
2
3#include <stdlib.h>
4#include <termcap.h>
5#include <stdio.h>
6
7#define TC_BUFFER 1024 /* Size of termcap(3) buffer */
8
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/****************************************************************/
18
19_PROTOTYPE(int main, (int argc, char **argv));
20_PROTOTYPE(void Print, (char *comment, char *name));
21_PROTOTYPE(void Error, (char *message, char *arg));
22
23int main(argc, argv)
24int argc;
25char *argv[];
26
27 {
28 char *term;
29 char buffer[ TC_BUFFER ];
30
31
32 /* Check for an argument */
33
34 if ( argc > 2 )
35 Error( "Usage: %s [ type ]\n", argv[0] );
36
37 if ( argc == 2 )
38 term = argv[1];
39 else
40 term = getenv( "TERM" );
41
42 if ( term == NULL )
43 Error( "termcap: $TERM is not defined\n", "" );
44
45
46 /* Read in the termcap entry */
47
48 if ( tgetent( buffer, term ) != 1 )
49 Error( "termcap: No termcap entry for %s\n", term );
50
51
52 /* Print out the entry's contents */
53
54 printf( "TERM = %s\n\n", term );
55
56 if ( tgetflag( "am" ) == 1 )
57 printf( "End of line wraps to next line (am)\n" );
58
59 if ( tgetflag( "bs" ) == 1 )
60 printf( "Ctrl/H performs a backspace (bs)\n" );
61
62 printf( "Number of columns (co) = %d\n", tgetnum( "co" ) );
63 printf( "Number of lines (li) = %d\n", tgetnum( "li" ) );
64
65 Print( "Clear to end of line", "ce" );
66 Print( "Clear to end of screen", "cd" );
67 Print( "Clear the whole screen", "cl" );
68
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" );
77
78 Print( "Scroll backwards", "sr" );
79 Print( "Cursor motion", "cm" );
80
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" );
86
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\"", "k0" );
93 Print( "Generated by \"PGUP\"", "k1" );
94 Print( "Generated by \"PGDN\"", "k2" );
95 Print( "Generated by numeric \"+\"", "k3" );
96 Print( "Generated by numeric \"-\"", "k4" );
97 Print( "Generated by numeric \"5\"", "k5" );
98
99 return( 0 );
100 }
101
102
103
104
105
106
107/****************************************************************/
108/* */
109/* Print( comment, name ) */
110/* */
111/* If a termcap entry exists for "name", then */
112/* print out "comment" and the entry. Control */
113/* characters are printed as ^x. */
114/* */
115/****************************************************************/
116
117
118void Print( comment, name )
119 char *comment;
120 char *name;
121
122 {
123 char entry[ 50 ];
124 char *p = entry;
125
126 if ( tgetstr( name, &p ) == NULL )
127 return;
128
129 printf( "%-32s (%s) = ", comment, name );
130
131 for ( p = entry; *p != '\0'; ++p )
132 if ( *p < ' ' )
133 printf( "^%c", *p + '@' );
134 else if ( *p == '\177' )
135 printf( "^?" );
136 else
137 putchar( *p );
138
139 putchar( '\n' );
140 }
141
142
143
144
145
146
147/****************************************************************/
148/* */
149/* Error( message, arg ) */
150/* */
151/* Printf the "message" and abort. */
152/* */
153/****************************************************************/
154
155
156void Error( message, arg )
157 char *message;
158 char *arg;
159
160 {
161 fprintf( stderr, message, arg );
162 exit( 1 );
163 }
Note: See TracBrowser for help on using the repository browser.