static char *sccsid
="@(#)showtc.c 1.9 (Berkeley) %G%";
** -D look for duplicate names and print termcap file
** -S sort entries before display
** -T trace (-DDEBUG only)
** -U print unknown capabilities
** -f following arg is FULL PATHNAME of termcap file
** -g sort on generic names
** -s don't print two char name at the front of every line
** -x expand tc= capabilities
** [ent] display specific entry. tc= will be expanded.
** David L. Wasley, U.C.Berkeley
** Kevin Layer: modified for 4.1c and misc changes.
** Kevin Layer: added the printing of terminal capabilities
** in `human' readable form (like that in "man 5 termcap").
#define USAGE "usage: %s [-Sxdngb] [-f termcapfile] [entry] ...\n"
"AL", "Add N new blank lines",
"CC", "Command char in prototype if settable",
"DC", "Delete N characters",
"DO", "Move cursor down N lines",
"IC", "Insert N blank characters",
"LE", "Move cursor left N positions",
"RI", "Move cursor right N positions",
"UP", "Move cursor up N lines",
"ae", "End alternate character set",
"al", "Add new blank line",
"am", "Has automatic margins",
"as", "Start alternate character set",
"bc", "Backspace if not ^H",
"bl", "Audible Bell (default ^G)",
"bs", "Can backspace with ^H",
"bw", "Backspace wraps from col 0 to last col",
"cd", "Clear to end of display",
"ce", "Clear to end of line",
"ch", "Like cm, but horizontal motion only",
"co", "Number of columns in a line",
"cr", "Carriage return (default ^M)",
"cs", "Change scrolling region (vt100), like cm",
"ct", "Clear all tab stops",
"cv", "Like ch but vertical only.",
"dB", "Number of millisec of bs delay needed",
"dC", "Number of millisec of cr delay needed",
"dF", "Number of millisec of ff delay needed",
"dN", "Number of millisec of nl delay needed",
"dT", "Number of millisec of tab delay needed",
"da", "Display may be retained above",
"db", "Display may be retained below",
"dc", "Delete character",
"dm", "Start Delete mode",
"ds", "Disable status display",
"ei", "End insert mode;give \":ei=:\" if ic",
"eo", "Can erase overstrikes with a blank",
"es", "Escape seq's ok on status line",
"ff", "Hardcopy page eject (default ^L)",
"fs", "From status line sequence",
"hc", "Hardcopy terminal",
"hd", "Half-line down (forward 1/2 lf)",
"ho", "Home cursor (if no cm)",
"hu", "Half-line up (reverse 1/2 lf)",
"hz", "Hazeltine; can't print ~'s",
"i2", "Initialization string (used by sysline(1))",
"ic", "Insert character",
"if", "Name of file containing is",
"im", "Start insert mode;give \":im=:\" if ic",
"in", "Insert mode distinguishes nulls on display",
"ip", "Insert pad after character inserted",
"is", "Initialization string",
"k0", "Sent by function key 0",
"k1", "Sent by function key 1",
"k2", "Sent by function key 2",
"k3", "Sent by function key 3",
"k4", "Sent by function key 4",
"k5", "Sent by function key 5",
"k6", "Sent by function key 6",
"k7", "Sent by function key 7",
"k8", "Sent by function key 8",
"k9", "Sent by function key 9",
"kb", "Sent by backspace key",
"kd", "Sent by down arrow key",
"ke", "Out of \"keypad transmit\" mode",
"kh", "Sent by home key",
"kl", "Sent by left arrow key",
"km", "Has a \"meta\" key (shift, sets parity bit)",
"kn", "Number of \"other\" keys",
"ko", "Tc entries for other non-function keys",
"kr", "Sent by right arrow key",
"ks", "Put in \"keypad transmit\" mode",
"ku", "Sent by up arrow key",
"l0", "Label on function key 0 (if not \"0\")",
"l1", "Label on function key 1 (if not \"1\")",
"l2", "Label on function key 2 (if not \"2\")",
"l3", "Label on function key 3 (if not \"3\")",
"l4", "Label on function key 4 (if not \"4\")",
"l5", "Label on function key 5 (if not \"5\")",
"l6", "Label on function key 6 (if not \"6\")",
"l7", "Label on function key 7 (if not \"7\")",
"l8", "Label on function key 8 (if not \"8\")",
"l9", "Label on function key 9 (if not \"9\")",
"li", "Number of lines on screen or page",
"ll", "Last line, first column (if no cm)",
"ma", "Arrow key map, used by vi V2 only",
"mb", "Enter blinking mode",
"me", "Reset video attributes",
"mh", "Enter halfbright mode",
"mi", "Safe to move while in insert mode",
"mk", "Enter protected mode",
"ml", "Memory lock on above cursor.",
"mp", "Turn on protected attribute",
"mr", "Enter reverse video mode",
"ms", "Ok to move while in standout/underline mode",
"mu", "Memory unlock (turn off memory lock).",
"nc", "No working CR (DM2500,H2000)",
"nd", "Non-destructive space (cursor right)",
"nl", "Newline character (default \\n)",
"ns", "Is a CRT but doesn't scroll.",
"os", "Terminal overstrikes",
"pb", "Lowest baud where delays are required",
"pc", "Pad character (rather than null)",
"pl", "Program function key N to execute string S (terminfo only)",
"pt", "Has hardware tabs (may need to use is)",
"rc", "Restore cursor to position of last sc",
"rf", "Name of file containing reset codes",
"rs", "Reset terminal completely to sane modes",
"sc", "Save cursor position",
"se", "End stand out mode",
"sg", "Number of blank chars left by so/se",
"so", "Begin stand out mode",
"sr", "Scroll reverse (backwards)",
"st", "Set a tab in all rows, current column",
"ta", "Tab (other than ^I or with padding)",
"tc", "Entry of similar terminal - must be last",
"te", "String to end programs that use cm",
"ti", "String to begin programs that use cm",
"ts", "To status line sequence",
"uc", "Underscore one char and move past it",
"ue", "End underscore mode",
"ug", "Number of blank chars left by us or ue",
"ul", "Underlines, though no overstrike",
"up", "Upline (cursor up)",
"us", "Start underscore mode",
"vb", "Visible bell (may not move cursor)",
"ve", "Sequence to end open/visual mode",
"vs", "Sequence to start open/visual mode",
"vt", "Virtual terminal number (not supported on all systems)",
"xb", "Beehive (f1=escape, f2=ctrl C)",
"xn", "A newline is ignored after a wrap (Concept)",
"xr", "Return acts like ce \\r \\n (Delta Data)",
"xs", "Standout not erased by writing over it (HP 264?)",
"xt", "Destructive tabs, magic so char (Teleray 1061)"
#define NOCAPS (sizeof capList / sizeof *capList)
int tc_loopc
; /* loop counter */
char *tcfile
; /* termcap database pathname */
char cwd
[MAXPATHLEN
]; /* current working directory */
char tcbuf
[2048]; /* buffer for termcap description */
struct TcName
*find_name();
if ((bp
= getenv("TERMCAP")) && *bp
== '/')
if (*(av
= *++argv
) == '-')
/* use alternate termcap file */
"-f needs a filename\n");
/* only check for dup names */
/* look for duplicated names */
/* strip the two name off */
/* sort the name array */
/* sort on generic names */
/* expand entries in 'full mode' */
fprintf(stderr
, "showtc: unknown flag: -%c\n", *av
);
fprintf(stderr
, USAGE
, argv
[0]);
* insert the specified TERMCAP file into the environment
if (getwd(cwd
) == NULL
) {
fprintf(stderr
, "showtc: %s\n", cwd
);
} else if (strlen(cwd
) + strlen(tcfile
) + 2 > sizeof cwd
) {
fprintf(stderr
, "showtc: %s\n",
"Current working directory name too long");
if (cwd
[strlen(cwd
) - 1] != '/')
(void) sprintf(envbuf
, "TERMCAP=%s", tcfile
);
if (strncmp(*envp
, "TERMCAP=", 8) == 0)
*envp
= envbuf
; /* this may be dangerous */
** if user specified type(s), do only those
** look for the users specified term types
switch (n
= tgetent(tcbuf
, *argv
))
"showtc: bad entry: %s\n", *argv
);
fputs("showtc: ", stderr
);
fprintf(stderr
, "bad return from tgetent: %d\n", n
);
fprintf(stderr
, "showtc: -b flag with no entries makes no sense.\n");
** if no type was specified, do the whole file
if ((tcfp
= fopen(tcfile
, "r")) == NULL
)
** identify database, for the record
printf("File: %s, last modified: %s\n", tcfile
, ctime(&st
.st_mtime
));
** build termcap entry table
while (fgets(bp
, sizeof (tcbuf
), tcfp
) != NULL
)
while (*(bp
= lastchar(bp
)) == '\\' && fgets(bp
, (sizeof tcbuf
) - (bp
- tcbuf
), tcfp
))
for (bp
= tcbuf
; *bp
&& *bp
!= ':'; bp
++)
(void) strncpy(tn
->name_buf
, tcbuf
,
sizeof tcNames
[0].name_buf
);
** Look for duplicate names
for (tn
= tcNames
; tn
->file_pos
>= 0; tn
++)
printf("Entry #%d:\n\t%s\n\tfile_pos = %ld\n",
tn
- tcNames
, tn
->name_buf
, tn
->file_pos
);
qsort((char *)tcNames
, tn
- tcNames
,
sizeof (struct TcName
), name_cmp
);
** List termcap entry for each name in table
for (tn
= tcNames
; tn
->file_pos
>= 0; tn
++)
/*** working toward this ...
(void) fseek(tcfp
, tn
->file_pos
, 0);
while (fgets(bp
, (sizeof tcbuf
) - (bp
- tcbuf
), tcfp
)
&& *(bp
= lastchar(bp
)) == '\\')
while (*p
== '\n' || *p
== ' ')
if (gflag
) /* sort on generic names */
while (*a
&& *b
&& *a
!= '|' && *a
== *b
)
if (*a
== '|' || *a
== CNULL
)
return((*b
== '|' || *b
== CNULL
)? 0:-1);
if (*b
== '|' || *b
== CNULL
)
return(strncmp(a
, b
, 2));
while (*buf
&& !isalnum(*buf
))
* ignore duplicate cap entries
for (tp
= caps
; tp
< cp
; tp
++)
if (strncmp(buf
, *tp
, 2) == 0)
* does user want tc= expanded?
if (xflag
&& strncmp(buf
, "tc=", 3) == 0)
printf("%s: expanding %s\n",
* let tgetent do the work
*cp
= CNULL
; /* was (char *)0 */
qsort((char *) caps
, cp
- caps
, sizeof (char *), ent_cmp
);
for (cp
= caps
; *cp
; cp
++)
printf("%-45s %s\n", getdesc(*cp
), *cp
);
printf("%2.2s %-45s %s\n", name
, getdesc(*cp
), *cp
);
if ((n
= index(b
, ':') - b
+ 1) <= 0)
if (len
== 0) /* first part */
printf("%.*s\\\n\t:", n
, b
);
while (*b
&& index(" \t:\n", *b
))
return(strncmp(*a
, *b
, 2));
** Look for duplicated names
register struct TcName
*tn
;
register struct TcName
*tm
;
while (tn
->file_pos
>= 0)
if (p
!= q
&& (tm
= find_name(q
, tn
+ 1, p
- q
)))
fputs("Duplicate name: ", stdout
);
register struct TcName
*tn
;
** find name of length len in tcname structure buffers.
while (tn
->file_pos
>= 0)
while (*buf
&& *buf
!= '|')
while (*buf
&& *buf
!= '|')
if (*buf
== '|' || *buf
== '\0')
while (*buf
&& *buf
!= '|')
return((struct TcName
*)0);
for (i
= 0; i
< NOCAPS
; i
++)
if (strncmp(key
, capList
[i
].cap
, 2) == 0)
return (capList
[i
].desc
);
for (i
= 0; i
< NOCAPS
; i
++)
if (strncmp(key
, capList
[i
].cap
, 2) == 0)