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 int main(int argc, char **argv); 20 void Print(char *comment, char *name); 21 void Error(char *message, char *arg); 22 23 int main(argc, argv) 24 int argc; 25 char *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\"", "@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" ); 99 100 return( 0 ); 101 } 102 103 104 105 106 107 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 /****************************************************************/ 117 118 119 void Print( comment, name ) 120 char *comment; 121 char *name; 122 123 { 124 char entry[ 50 ]; 125 char *p = entry; 126 127 if ( tgetstr( name, &p ) == NULL ) 128 return; 129 130 printf( "%-32s (%s) = ", comment, name ); 131 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 ); 139 140 putchar( '\n' ); 141 } 142 143 144 145 146 147 148 /****************************************************************/ 149 /* */ 150 /* Error( message, arg ) */ 151 /* */ 152 /* Printf the "message" and abort. */ 153 /* */ 154 /****************************************************************/ 155 156 157 void Error( message, arg ) 158 char *message; 159 char *arg; 160 161 { 162 fprintf( stderr, message, arg ); 163 exit( 1 ); 164 } 165