static char *sccsid
="@(#)showtc.c 1.4 (Berkeley) %G%";
** -D look for duplicate names and print termcap file
** -S sort entries before display
** -T trace (-DDEBUG only)
** -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"
"ae", "End alternate character set",
"al", "Add new blank line",
"am", "Has automatic margins",
"as", "Start alternate character set",
"bc", "Backspace if not ^H",
"bs", "Can backspace with ^H",
"bw", "Backspace wraps from col 0 to last col",
"CC", "Command char in prototype if settable",
"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",
"cv", "Like ch but vertical only.",
"da", "Display may be retained above",
"dB", "Number of millisec of bs delay needed",
"db", "Display may be retained below",
"dC", "Number of millisec of cr delay needed",
"dc", "Delete character",
"dF", "Number of millisec of ff delay needed",
"dm", "Start Delete mode",
"dN", "Number of millisec of nl delay needed",
"dT", "Number of millisec of tab delay needed",
"ei", "End insert mode;give \":ei=:\" if ic",
"eo", "Can erase overstrikes with a blank",
"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)",
"hs", "Has 25th status line",
"hu", "Half-line up (reverse 1/2 lf)",
"hz", "Hazeltine; can't print ~'s",
"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",
"i2", "Alternate initialization string",
"kb", "Sent by backspace key",
"kd", "Sent down arrow key",
"ke", "Out of \"keypad transmit\" mode",
"kh", "Sent by home key",
"kl", "Sent by left arrow key",
"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",
"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",
"mi", "Safe to move while in insert mode",
"ml", "Memory lock on above cursor.",
"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",
"pc", "Pad character (rather than null)",
"pt", "Has hardware tabs (may need to use is)",
"se", "End stand out mode",
"sg", "Number of blank chars left by so/se",
"so", "Begin stand out mode",
"sr", "Scroll reverse (backwards)",
"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",
"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)"
int tc_loopc
; /* loop counter */
char *tcfile
; /* termcap database pathname */
char tcbuf
[1024]; /* 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
(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
);