v07i072: Public-domain TPUT (corrected implementation)

sources-request at mirror.UUCP sources-request at mirror.UUCP
Thu Dec 4 06:03:13 AEST 1986


Submitted by: seismo!rochester!ur-valhalla!badri (Badri Lokanathan)
Mod.sources: Volume 7, Issue 72
Archive-name: tput2

After a lot of discussion with Mark Horton, I decided to make
modifications to the format of tput so that it would be compatible with
sys V shell scripts (my previous version unfortunately was not.) I am
reposting the source so that you can either redistribute it or just
archive it.

Sorry for all the confusion.
Badri Lokanathan
------------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README
#	Makefile
#	tput.1
#	tput.h
#	tput.c
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
cat << \xxTPUTxx > 'README'
From: rochester!ur-valhalla!badri Sep 19 17:31:33 EDT 1986
To: whom it may concern
Subject: Public domain tput release 2

This revision has undergone major changes after the first one, mainly
because the first release was not compatible with SV tput.
New features are:

(1) Totally different capability naming conventions from first
    release, but equivalent to SV conventions.

(2) Error messages are properly reported.

(3) Can be used to query for properties of other terminals also.

Problems still not properly handled:
Limited features: Handles almost all termcap features, but is still
only a subset of the latest version tput because terminfo has not been used.
On the other hand if terminfo was available, most probably tput would
be too!

Thanks to Mark Horton @ cbosgd for suggestions.
Badri Lokanathan
--------------------------------------------------------------------------------
From: rochester!ur-valhalla!badri  Aug 28 10:02
To: whom it may concern
Subject: tput instructions

This program is supposed to be equivalent to the system V utility
tput, which handles screen parameters from termcap. It may take inputs
in a slightly different format (basically because I wrote this program
without actually having worked on tput.) Any suggestions/modifications
are welcome.

Your system is assumed to have termlib and associated functions (I
wrote the program on BSD 4.2, assuming that termlib was fairly
standard.) There is one include file in the program - sgtty.h which
should be present. If not, I hope an equivalent exists.
Other than that, the code should be fairly portable.

The make file is delibrately trivial. It does not do any installation
- just compilation.

make

will make tput in the current directory.

make man

will make a man page in tput.doc.


tput, written by Badri Lokanathan, is in the public domain, and may be
used by any person or organization, in any way and for any purpose.
There is no warranty of merchantability nor any warranty of fitness for
a particular purpose nor any other warranty, either express or implied,
as to the accuracy of the enclosed materials or as to their suitability
for any particular purpose.  Accordingly, the author assumes no respon-
sibility for their use by the recipient.   Further, the author assumes
no obligation to furnish any assistance of any kind whatsoever, or to
furnish any additional information or documentation.
xxTPUTxx
fi
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
cat << \xxTPUTxx > 'Makefile'
tput: tput.c tput.h
	cc -o tput tput.c -ltermlib

man: tput.1
	nroff -man tput.1 > tput.doc

dtput: tput.c tput.h
	cc -g -o dtput tput.c -ltermlib

lint:
	lint -DLINT tput.c
xxTPUTxx
fi
if test -f 'tput.1'
then
	echo shar: "will not over-write existing file 'tput.1'"
else
cat << \xxTPUTxx > 'tput.1'
.TH tput 1local "UR EE GRADUATE VLSI LAB"
.SH NAME
tput \- query termcap data base
.SH SYNOPSIS
.B  tput
[
\fB-T\fRtype
]
[
\fB-e\fR
]
capname
[
.I x
.I y
]
.SH DESCRIPTION
.ad
.I tput
uses the \fItermcap(5)\fR data base to make terminal-dependent
capabilities and information available to the shell. \fITput\fR outputs
a string if the attribute (\fBcap\fRability \fBname\fR) is of type
string, or an integer if the attribute is of type integer. If the
attribute is of type Boolean, tput simply sets the exit code (0 for
TRUE, 1 for FALSE) and does no output.
.sp 1
.ta 1i
.fc #
#\fB-T\fRtype#indicates the type of terminal. Normally this flag
.br
##is unnecessary, as the default is taken from the
.br
##environment variable \fB$TERM.\fR
.br
#\fB-e\fR#suppresses the printing of error messages. In case
.br
##an error occurs, an error code is returned with or
.br
##without this flag.
.br
#Capname#indicates the attribute (mapping to an attribute
.br
##from the \f\Itermcap\f\R database.)
.sp 1
x and y are integer values for cursor movement.
.sp 1
Typical capname options are given below.
.SH REQUESTS
.in 0
.ll 8i
.ta .75i 1.5i 2.5i 
.B Option\tType\tTermcap\tExplanation
.br
am	bool	am	Terminal has automatic margins
.br
bw	bool	bw	cub1 wraps from column 0 to last column
.br
chts	bool	HC	Cursor is hard to see.
.br
da	bool	da	Display may be retained above the screen
.br
db	bool	db	Display may be retained below the screen
.br
eo	bool	eo	Can erase overstrikes with a blank
.br
eslok	bool	es	Escape can be used on the status line
.br
gn	bool	gn	Generic line type (e.g. dialup, switch).
.br
hc	bool	hc	Hardcopy terminal
.br
hs	bool	hs	Has extra "status line"
.br
hz	bool	hz	Hazeltine; can't print ~'s
.br
in	bool	in	Insert mode distinguishes nulls
.br
km	bool	km	Has a meta key (shift, sets parity bit)
.br
mc5i	bool	5i	Printer won't echo on screen.
.br
mir	bool	mi	Safe to move while in insert mode
.br
msgr	bool	ms	Safe to move in standout modes
.br
npc	bool	NP	Pad character doesn't exist.
.br
nrrmc	bool	NR	Smcup does not reverse rmcup.
.br
nxon	bool	nx	Padding won't work, xon/xoff required
.br
os	bool	os	Terminal overstrikes
.br
ul	bool	ul	underline character overstrikes
.br
xenl	bool	xn	newline ignored after 80 cols (Concept)
.br
xhp	bool	xs	Standout not erased by overwriting (hp)
.br
xon	bool	xo	Terminal uses xon/xoff handshaking
.br
xsb	bool	xb	Beehive (f1=escape, f2=ctrl C)
.br
xt	bool	xt	Tabs destructive, magic so char (t1061)
.br
cols	num	co	Number of columns in a line
.br
it	num	it	Tabs initially every \# spaces.
.br
lh	num	lh	\# rows in each label
.br
lines	num	li	Number of lines on screen or page
.br
lm	num	lm	Lines of memory if > lines.  0 => varies
.br
lw	num	lw	\# cols in each label
.br
nlab	num	Nl	\# of labels on screen (start at 1)
.br
pb	num	pb	Lowest baud rate where padding needed
.br
vt	num	vt	Virtual terminal number (CB/Unix)
.br
wsl	num	ws	\# columns in status line
.br
xmc	num	sg	Number blank chars left by smso or rmso
.br
acsc	str	ac	Graphic charset pairs aAbBcC - def=vt100
.br
bel	str	bl	Audible signal (bell)
.br
blink	str	mb	Turn on blinking
.br
bold	str	md	Turn on bold (extra bright) mode
.br
cbt	str	bt	Back tab
.br
civis	str	vi	Make cursor invisible
.br
clear	str	cl	Clear screen (*)
.br
cmdch	str	CC	Term. settable cmd char in prototype
.br
cnorm	str	ve	Make cursor appear normal (undo vs/vi)
.br
cr	str	cr	Carriage return (*)
.br
csr	str	cs	change to lines \#1 thru \#2 (vt100) (G)
.br
cub	str	LE	Move cursor left \#1 spaces (G)
.br
cub1	str	le	Move cursor left one space.
.br
cud	str	DO	Move cursor down \#1 lines. (G*)
.br
cud1	str	do	Down one line
.br
cuf	str	RI	Move cursor right \#1 spaces. (G*)
.br
cuf1	str	nd	Non-destructive space (cursor right)
.br
cup	str	cm	Cursor motion to row \#1 col \#2 (G)
.br
cuu	str	UP	Move cursor up \#1 lines. (G*)
.br
cuu1	str	up	Upline (cursor up)
.br
cvvis	str	vs	Make cursor very visible
.br
dch	str	DC	Delete \#1 chars (G*)
.br
dch1	str	dc	Delete character (*)
.br
dim	str	mh	Turn on half-bright mode
.br
dl	str	DL	Delete \#1 lines (G*)
.br
dl1	str	dl	Delete line (*)
.br
dsl	str	ds	Disable status line
.br
ech	str	ec	Erase \#1 characters (G)
.br
ed	str	cd	Clear to end of display (*)
.br
el	str	ce	Clear to end of line
.br
el1	str	cb	Clear to beginning of line, inclusive
.br
enacs	str	eA	Enable alternate char set
.br
ff	str	ff	Hardcopy terminal page eject (*)
.br
flash	str	vb	Visible bell (may not move cursor)
.br
fsl	str	fs	Return from status line
.br
hd	str	hd	Half-line down (forward 1/2 linefeed)
.br
home	str	ho	Home cursor (if no cup)
.br
hpa	str	ch	Set cursor column (G)
.br
ht	str	ta	Tab to next 8 space hardware tab stop.
.br
hts	str	st	Set a tab in all rows, current column.
.br
hu	str	hu	Half-line up (reverse 1/2 linefeed)
.br
ich	str	IC	Insert \#1 blank chars (G*)
.br
ich1	str	ic	Insert character
.br
if	str	if	Name of file containing is
.br
il	str	AL	Add \#1 new blank lines (G*)
.br
il1	str	al	Add new blank line (*)
.br
ind	str	sf	Scroll text up
.br
indn	str	SF	Scroll forward \#1 lines. (G)
.br
invis	str	mk	Turn on blank mode (chars invisible)
.br
ip	str	ip	Insert pad after character inserted (*)
.br
iprog	str	iP	Path name of program for init.
.br
is1	str	i1	Terminal initialization string
.br
is2	str	is	Terminal initialization string
.br
is3	str	i3	Terminal initialization string
.br
kBEG	str	&9	KEY_SBEG, 0572, shifted beginning key
.br
kCAN	str	&0	KEY_SCANCEL, 0573, shifted cancel key
.br
kCMD	str	*1	KEY_SCOMMAND, 0574, shifted command key
.br
kCPY	str	*2	KEY_SCOPY, 0575, shifted copy key
.br
kCRT	str	*3	KEY_SCREATE, 0576, shifted create key
.br
kDC	str	*4	KEY_SDC, 0577, shifted delete char key
.br
kDL	str	*5	KEY_SDL, 0600, shifted delete line key
.br
kEND	str	*7	KEY_SEND, 0602, shifted end key
.br
kEOL	str	*8	KEY_SEOL, 0603, shifted clear line key
.br
kEXT	str	*9	KEY_SEXIT, 0604, shifted exit key
.br
kFND	str	*0	KEY_SFIND, 0605, shifted find key
.br
kHLP	str	\#1	KEY_SHELP, 0606, shifted help key
.br
kHOM	str	\#2	KEY_SHOME, 0607, shifted home key
.br
kIC	str	\#3	KEY_SIC, 0610, shifted input key
.br
kLFT	str	\#4	KEY_SLEFT, 0611, shifted left arrow key
.br
kMOV	str	%b	KEY_SMOVE, 0613, shifted move key
.br
kMSG	str	%a	KEY_SMESSAGE, 0612, shifted message key
.br
kNXT	str	%c	KEY_SNEXT, 0614, shifted next key
.br
kOPT	str	%d	KEY_SOPTIONS, 0615, shifted options key
.br
kPRT	str	%f	KEY_SPRINT, 0617, shifted print key
.br
kPRV	str	%e	KEY_SPREVIOUS, 0616, shifted prev key
.br
kRDO	str	%g	KEY_SREDO, 0620, shifted redo key
.br
kRES	str	%j	KEY_SRSUME, 0623, shifted resume key
.br
kRIT	str	%i	KEY_SRIGHT, 0622, shifted right arrow
.br
kRPL	str	%h	KEY_SREPLACE, 0621, shifted replace key
.br
kSAV	str	!1	KEY_SSAVE, 0624, shifted save key
.br
kSPD	str	!2	KEY_SSUSPEND, 0625, shifted suspend key
.br
kUND	str	!3	KEY_SUNDO, 0626, shifted undo key
.br
ka1	str	K1	KEY_A1, 0534, Upper left of keypad
.br
ka3	str	K3	KEY_A3, 0535, Upper right of keypad
.br
kb2	str	K2	KEY_B2, 0536, Center of keypad
.br
kbeg	str	@1	KEY_BEG, 0542, beg(inning) key
.br
kbs	str	kb	KEY_BACKSPACE, 0407, Sent by backspace key
.br
kc1	str	K4	KEY_C1, 0537, Lower left of keypad
.br
kc3	str	K5	KEY_C3, 0540, Lower right of keypad
.br
kcan	str	@2	KEY_CANCEL, 0543, cancel key
.br
kcbt	str	kB	KEY_BTAB, 0541, Back tab key
.br
kclo	str	@3	KEY_CLOSE, 0544, close key
.br
kclr	str	kC	KEY_CLEAR, 0515, Sent by clear screen or erase key.
.br
kcmd	str	@4	KEY_COMMAND, 0545, cmd (command) key
.br
kcpy	str	@5	KEY_COPY, 0546, copy key
.br
kcrt	str	@6	KEY_CREATE, 0547, create key
.br
kctab	str	kt	KEY_CTAB, 0525, Sent by clear-tab key
.br
kcub1	str	kl	KEY_LEFT, 0404, Sent by terminal left arrow key
.br
kcud1	str	kd	KEY_DOWN, 0402, Sent by terminal down arrow key
.br
kcuf1	str	kr	KEY_RIGHT, 0405, Sent by terminal right arrow key
.br
kcuu1	str	ku	KEY_UP, 0403, Sent by terminal up arrow key
.br
kdch1	str	kD	KEY_DC, 0512, Sent by delete character key.
.br
kdl1	str	kL	KEY_DL, 0510, Sent by delete line key.
.br
ked	str	kS	KEY_EOS, 0516, Sent by clear-to-end-of-screen key.
.br
kel	str	kE	KEY_EOL, 0517, Sent by clear-to-end-of-line key.
.br
kend	str	@7	KEY_END, 0550, end key
.br
kent	str	@8	KEY_ENTER, 0527, Enter/send (unreliable)
.br
kext	str	@9	KEY_EXIT, 0551, exit key
.br
kf0	str	k0	KEY_F(0), 0410, function key f0.
.br
kf1	str	k1	KEY_F(1), 0411, function key f1.
.br
kf10	str	k;	KEY_F(10), 0422, function key f10.
.br
kf11	str	F1	KEY_F(11), 0423, function key f11.
.br
kf12	str	F2	KEY_F(12), 0424, function key f12.
.br
kf13	str	F3	KEY_F(13), 0425, function key f13.
.br
kf14	str	F4	KEY_F(14), 0426, function key f14.
.br
kf15	str	F5	KEY_F(15), 0427, function key f15.
.br
kf16	str	F6	KEY_F(16), 0430, function key f16.
.br
kf17	str	F7	KEY_F(17), 0431, function key f17.
.br
kf18	str	F8	KEY_F(18), 0432, function key f18.
.br
kf19	str	F9	KEY_F(19), 0433, function key f19.
.br
kf2	str	k2	KEY_F(2), 0412, function key f2.
.br
kf20	str	FA	KEY_F(20), 0434, function key f20.
.br
kf21	str	FB	KEY_F(21), 0435, function key f21.
.br
kf22	str	FC	KEY_F(22), 0436, function key f22.
.br
kf23	str	FD	KEY_F(23), 0437, function key f23.
.br
kf24	str	FE	KEY_F(24), 0440, function key f24.
.br
kf25	str	FF	KEY_F(25), 0441, function key f25.
.br
kf26	str	FG	KEY_F(26), 0442, function key f26.
.br
kf27	str	FH	KEY_F(27), 0443, function key f27.
.br
kf28	str	FI	KEY_F(28), 0444, function key f28.
.br
kf29	str	FJ	KEY_F(29), 0445, function key f29.
.br
kf3	str	k3	KEY_F(3), 0413, function key f3.
.br
kf30	str	FK	KEY_F(30), 0446, function key f30.
.br
kf31	str	FL	KEY_F(31), 0447, function key f31.
.br
kf32	str	FM	KEY_F(32), 0450, function key f32.
.br
kf33	str	FN	KEY_F(13), 0451, function key f13.
.br
kf34	str	FO	KEY_F(34), 0452, function key f34.
.br
kf35	str	FP	KEY_F(35), 0453, function key f35.
.br
kf36	str	FQ	KEY_F(36), 0454, function key f36.
.br
kf37	str	FR	KEY_F(37), 0455, function key f37.
.br
kf38	str	FS	KEY_F(38), 0456, function key f38.
.br
kf39	str	FT	KEY_F(39), 0457, function key f39.
.br
kf4	str	k4	KEY_F(4), 0414, function key f4.
.br
kf40	str	FU	KEY_F(40), 0460, function key f40.
.br
kf41	str	FV	KEY_F(41), 0461, function key f41.
.br
kf42	str	FW	KEY_F(42), 0462, function key f42.
.br
kf43	str	FX	KEY_F(43), 0463, function key f43.
.br
kf44	str	FY	KEY_F(44), 0464, function key f44.
.br
kf45	str	FZ	KEY_F(45), 0465, function key f45.
.br
kf46	str	Fa	KEY_F(46), 0466, function key f46.
.br
kf47	str	Fb	KEY_F(47), 0467, function key f47.
.br
kf48	str	Fc	KEY_F(48), 0470, function key f48.
.br
kf49	str	Fd	KEY_F(49), 0471, function key f49.
.br
kf5	str	k5	KEY_F(5), 0415, function key f5.
.br
kf50	str	Fe	KEY_F(50), 0472, function key f50.
.br
kf51	str	Ff	KEY_F(51), 0473, function key f51.
.br
kf52	str	Fg	KEY_F(52), 0474, function key f52.
.br
kf53	str	Fh	KEY_F(53), 0475, function key f53.
.br
kf54	str	Fi	KEY_F(54), 0476, function key f54.
.br
kf55	str	Fj	KEY_F(55), 0477, function key f55.
.br
kf56	str	Fk	KEY_F(56), 0500, function key f56.
.br
kf57	str	Fl	KEY_F(57), 0501, function key f57.
.br
kf58	str	Fm	KEY_F(58), 0502, function key f58.
.br
kf59	str	Fn	KEY_F(59), 0503, function key f59.
.br
kf6	str	k6	KEY_F(6), 0416, function key f6.
.br
kf60	str	Fo	KEY_F(60), 0504, function key f60.
.br
kf61	str	Fp	KEY_F(61), 0505, function key f61.
.br
kf62	str	Fq	KEY_F(62), 0506, function key f62.
.br
kf63	str	Fr	KEY_F(63), 0507, function key f63.
.br
kf7	str	k7	KEY_F(7), 0417, function key f7.
.br
kf8	str	k8	KEY_F(8), 0420, function key f8.
.br
kf9	str	k9	KEY_F(9), 0421, function key f9.
.br
kfnd	str	@0	KEY_FIND, 0552, find key
.br
khlp	str	%1	KEY_HELP, 0553, help key
.br
khome	str	kh	KEY_HOME, 0406, Sent by home key.
.br
khts	str	kT	KEY_STAB, 0524, Sent by set-tab key
.br
kich1	str	kI	KEY_IC, 0513, Sent by ins char/enter ins mode key.
.br
kil1	str	kA	KEY_IL, 0511, Sent by insert line.
.br
kind	str	kF	KEY_SF, 0520, Sent by scroll-forward/down key
.br
kll	str	kH	KEY_LL, 0533, Sent by home-down key
.br
kmov	str	%4	KEY_MOVE, 0556, move key
.br
kmrk	str	%2	KEY_MARK, 0554, mark key
.br
kmsg	str	%3	KEY_MESSAGE, 0555, message key
.br
knp	str	kN	KEY_NPAGE, 0522, Sent by next-page key
.br
knxt	str	%5	KEY_NEXT, 0557, next object key
.br
kopn	str	%6	KEY_OPEN, 0560, open key
.br
kopt	str	%7	KEY_OPTIONS, 0561, options key
.br
kpp	str	kP	KEY_PPAGE, 0523, Sent by previous-page key
.br
kprt	str	%9	KEY_PRINT, 0532, print or copy
.br
kprv	str	%8	KEY_PREVIOUS, 0562, previous object key
.br
krdo	str	%0	KEY_REDO, 0563, redo key
.br
kref	str	&1	KEY_REFERENCE, 0564, ref(erence) key
.br
kres	str	&5	KEY_RESUME, 0570, resume key
.br
krfr	str	&2	KEY_REFRESH, 0565, refresh key
.br
kri	str	kR	KEY_SR, 0521, Sent by scroll-backward/up key
.br
krmir	str	kM	KEY_EIC, 0514, Sent by rmir or smir in insert mode.
.br
krpl	str	&3	KEY_REPLACE, 0566, replace key
.br
krst	str	&4	KEY_RESTART, 0567, restart key
.br
ksav	str	&6	KEY_SAVE, 0571, save key
.br
kslt	str	*6	KEY_SELECT, 0601, select key
.br
kspd	str	&7	KEY_SUSPEND, 0627, suspend key
.br
ktbc	str	ka	KEY_CATAB, 0526, Sent by clear-all-tabs key.
.br
kund	str	&8	KEY_UNDO, 0630, undo key
.br
lf0	str	l0	Labels on function key f0 if not f0
.br
lf1	str	l1	Labels on function key f1 if not f1
.br
lf10	str	la	Labels on function key f10 if not f10
.br
lf2	str	l2	Labels on function key f2 if not f2
.br
lf3	str	l3	Labels on function key f3 if not f3
.br
lf4	str	l4	Labels on function key f4 if not f4
.br
lf5	str	l5	Labels on function key f5 if not f5
.br
lf6	str	l6	Labels on function key f6 if not f6
.br
lf7	str	l7	Labels on function key f7 if not f7
.br
lf8	str	l8	Labels on function key f8 if not f8
.br
lf9	str	l9	Labels on function key f9 if not f9
.br
ll	str	ll	Last line, first column (if no cup)
.br
mc0	str	ps	Print contents of the screen
.br
mc4	str	pf	Turn off the printer
.br
mc5	str	po	Turn on the printer
.br
mc5p	str	pO	Turn on the printer for \#1 bytes.
.br
mgc	str	MC	Clear left and right soft margins
.br
mrcup	str	CM	Memory relative cursor addressing.
.br
nel	str	nw	Newline (behaves like cr followed by lf)
.br
pad	str	pc	Pad character (rather than null)
.br
pfkey	str	pk	Prog funct key \#1 to type string \#2
.br
pfloc	str	pl	Prog funct key \#1 to execute string \#2
.br
pfx	str	px	Prog funct key \#1 to xmit string \#2
.br
pln	str	pn	Prog label \#1 to show string \#2
.br
prot	str	mp	Turn on protected mode
.br
rc	str	rc	Restore cursor to position of last sc.
.br
rep	str	rp	Repeat char \#1 \#2 times.  (G*)
.br
rev	str	mr	Turn on reverse video mode
.br
rf	str	rf	Name of file containing reset string.
.br
rfi	str	RF	send next input char (for ptys)
.br
ri	str	sr	Scroll text down
.br
rin	str	SR	Scroll backward \#1 lines. (G)
.br
rmacs	str	ae	End alternate character set
.br
rmam	str	RA	Turn off automatic margins
.br
rmcup	str	te	String to end programs that use cup
.br
rmdc	str	ed	End delete mode
.br
rmir	str	ei	End insert mode;
.br
rmkx	str	ke	Out of "keypad transmit" mode
.br
rmln	str	LF	Turn off soft labels
.br
rmm	str	mo	Turn off "meta mode"
.br
rmp	str	rP	Like ip but when in replace mode
.br
rmso	str	se	End stand out mode
.br
rmul	str	ue	End underscore mode
.br
rmxon	str	RX	Turn off xon/xoff handshaking
.br
rs1	str	r1	Reset terminal completely to sane modes.
.br
rs2	str	r2	Reset terminal completely to sane modes.
.br
rs3	str	r3	Reset terminal completely to sane modes.
.br
sc	str	sc	Save cursor position.
.br
sgr	str	sa	Define the video attributes (G9)
.br
sgr0	str	me	Turn off all attributes
.br
smacs	str	as	Start alternate character set
.br
smam	str	SA	Turn on automatic margins
.br
smcup	str	ti	String to begin programs that use cup
.br
smdc	str	dm	Delete mode (enter)
.br
smgl	str	ML	Set soft left margin
.br
smgr	str	MR	Set soft right margin
.br
smir	str	im	Insert mode (enter);
.br
smkx	str	ks	Put terminal in "keypad transmit" mode
.br
smln	str	LO	Turn on soft labels
.br
smm	str	mm	Turn on "meta mode" (8th bit)
.br
smso	str	so	Begin stand out mode
.br
smul	str	us	Start underscore mode
.br
smxon	str	SX	Turn on xon/xoff handshaking
.br
tbc	str	ct	Clear all tab stops.
.br
tsl	str	ts	Go to status line, col \#1
.br
uc	str	uc	Underscore one char and move past it
.br
vpa	str	cv	Like hpa but sets row. (G)
.br
wind	str	wi	Current window is lines \#1-\#2 cols \#3-\#4
.br
xoffc	str	XF	X-off character
.br
xonc	str	XN	X-on character
.br
.ad
.ll 6.5i
.in .5i
.SH FILES
/etc/termcap
.SH SEE ALSO
termcap(3X), termcap(5)
.SH DIAGNOSTICS
Tput prints error messages (unless suppressed using -e) and returns
the following error codes on error:
.br
#-1#Usage error.
.br
#-2#Bad terminal type.
.br
#-3#Bad capname.
.sp 1
.SH BUGS
Complex capnames with many auxiliary parameters (such as sgr) do
not work properly because curses has not been used - this program
is based entirely on termcap (and that too from BSD4.2 manuals!)
.PP
-n option does not work for most capnames, so it has not been
mentioned in this page.
xxTPUTxx
fi
if test -f 'tput.h'
then
	echo shar: "will not over-write existing file 'tput.h'"
else
cat << \xxTPUTxx > 'tput.h'
/*
 * Copyright (C) $Date: 86/09/19 17:01:07 $
 * by $Author: badri $
 * University of Rochester,
 * Department of Electrical Engineering.
 *
 * CoNtEnTs   This file contains various definitions for tput.
 *
 * $Locker:  $
 * $Source: /u/users/badri/usr/src/local/tput/RCS/tput.h,v $
 * $Revision: 1.2 $
 *
 * History of this release:
 * $Log:	tput.h,v $
 * Revision 1.2  86/09/19  17:01:07  badri
 * Did some rearranging of things. Also incorporated error messages.
 * 
 * Revision 1.1  86/09/18  15:48:24  badri
 * Initial revision
 * 
 */
#include <sgtty.h>
#include <stdio.h>

#ifndef XTABS
#define XTABS 0006000
#endif  XTABS

#define LARGEBUF 1024
#define SMALLBUF   64

#define SYSTEM    666
#define FAILURE     1
#define SUCCESS     0
#define BADUSE     -1
#define BADTERM    -2
#define BADCAP     -3
/*
 * To add new capabilities, increment table size and define the
 * capability in the appropriate slot in the structure. Note that 
 * the capabilities are lexicographically ordered. This ordering
 * must be maintained for the binary search to work.
 * Format for entry is 
 * {"capability", "termcap_key"},
 */
#define TABLESIZE 310
struct {char *key, *value} table[TABLESIZE] = {
	{"acsc", "ac"},
	{"am", "am"},
	{"bel", "bl"},
	{"blink", "mb"},
	{"bold", "md"},
	{"bw", "bw"},
	{"cbt", "bt"},
	{"chts", "HC"},
	{"civis", "vi"},
	{"clear", "cl"},
	{"cmdch", "CC"},
	{"cnorm", "ve"},
	{"cols", "co"},
	{"cr", "cr"},
	{"csr", "cs"},
	{"cub", "LE"},
	{"cub1", "le"},
	{"cud", "DO"},
	{"cud1", "do"},
	{"cuf", "RI"},
	{"cuf1", "nd"},
	{"cup", "cm"},
	{"cuu", "UP"},
	{"cuu1", "up"},
	{"cvvis", "vs"},
	{"da", "da"},
	{"db", "db"},
	{"dch", "DC"},
	{"dch1", "dc"},
	{"dim", "mh"},
	{"dl", "DL"},
	{"dl1", "dl"},
	{"dsl", "ds"},
	{"ech", "ec"},
	{"ed", "cd"},
	{"el", "ce"},
	{"el1", "cb"},
	{"enacs", "eA"},
	{"eo", "eo"},
	{"eslok", "es"},
	{"ff", "ff"},
	{"flash", "vb"},
	{"fsl", "fs"},
	{"gn", "gn"},
	{"hc", "hc"},
	{"hd", "hd"},
	{"home", "ho"},
	{"hpa", "ch"},
	{"hs", "hs"},
	{"ht", "ta"},
	{"hts", "st"},
	{"hu", "hu"},
	{"hz", "hz"},
	{"ich", "IC"},
	{"ich1", "ic"},
	{"if", "if"},
	{"il", "AL"},
	{"il1", "al"},
	{"in", "in"},
	{"ind", "sf"},
	{"indn", "SF"},
	{"invis", "mk"},
	{"ip", "ip"},
	{"iprog", "iP"},
	{"is1", "i1"},
	{"is2", "is"},
	{"is3", "i3"},
	{"it", "it"},
	{"kBEG", "&9"},
	{"kCAN", "&0"},
	{"kCMD", "*1"},
	{"kCPY", "*2"},
	{"kCRT", "*3"},
	{"kDC", "*4"},
	{"kDL", "*5"},
	{"kEND", "*7"},
	{"kEOL", "*8"},
	{"kEXT", "*9"},
	{"kFND", "*0"},
	{"kHLP", "#1"},
	{"kHOM", "#2"},
	{"kIC", "#3"},
	{"kLFT", "#4"},
	{"kMOV", "%b"},
	{"kMSG", "%a"},
	{"kNXT", "%c"},
	{"kOPT", "%d"},
	{"kPRT", "%f"},
	{"kPRV", "%e"},
	{"kRDO", "%g"},
	{"kRES", "%j"},
	{"kRIT", "%i"},
	{"kRPL", "%h"},
	{"kSAV", "!1"},
	{"kSPD", "!2"},
	{"kUND", "!3"},
	{"ka1", "K1"},
	{"ka3", "K3"},
	{"kb2", "K2"},
	{"kbeg", "@1"},
	{"kbs", "kb"},
	{"kc1", "K4"},
	{"kc3", "K5"},
	{"kcan", "@2"},
	{"kcbt", "kB"},
	{"kclo", "@3"},
	{"kclr", "kC"},
	{"kcmd", "@4"},
	{"kcpy", "@5"},
	{"kcrt", "@6"},
	{"kctab", "kt"},
	{"kcub1", "kl"},
	{"kcud1", "kd"},
	{"kcuf1", "kr"},
	{"kcuu1", "ku"},
	{"kdch1", "kD"},
	{"kdl1", "kL"},
	{"ked", "kS"},
	{"kel", "kE"},
	{"kend", "@7"},
	{"kent", "@8"},
	{"kext", "@9"},
	{"kf0", "k0"},
	{"kf1", "k1"},
	{"kf10", "k;"},
	{"kf11", "F1"},
	{"kf12", "F2"},
	{"kf13", "F3"},
	{"kf14", "F4"},
	{"kf15", "F5"},
	{"kf16", "F6"},
	{"kf17", "F7"},
	{"kf18", "F8"},
	{"kf19", "F9"},
	{"kf2", "k2"},
	{"kf20", "FA"},
	{"kf21", "FB"},
	{"kf22", "FC"},
	{"kf23", "FD"},
	{"kf24", "FE"},
	{"kf25", "FF"},
	{"kf26", "FG"},
	{"kf27", "FH"},
	{"kf28", "FI"},
	{"kf29", "FJ"},
	{"kf3", "k3"},
	{"kf30", "FK"},
	{"kf31", "FL"},
	{"kf32", "FM"},
	{"kf33", "FN"},
	{"kf34", "FO"},
	{"kf35", "FP"},
	{"kf36", "FQ"},
	{"kf37", "FR"},
	{"kf38", "FS"},
	{"kf39", "FT"},
	{"kf4", "k4"},
	{"kf40", "FU"},
	{"kf41", "FV"},
	{"kf42", "FW"},
	{"kf43", "FX"},
	{"kf44", "FY"},
	{"kf45", "FZ"},
	{"kf46", "Fa"},
	{"kf47", "Fb"},
	{"kf48", "Fc"},
	{"kf49", "Fd"},
	{"kf5", "k5"},
	{"kf50", "Fe"},
	{"kf51", "Ff"},
	{"kf52", "Fg"},
	{"kf53", "Fh"},
	{"kf54", "Fi"},
	{"kf55", "Fj"},
	{"kf56", "Fk"},
	{"kf57", "Fl"},
	{"kf58", "Fm"},
	{"kf59", "Fn"},
	{"kf6", "k6"},
	{"kf60", "Fo"},
	{"kf61", "Fp"},
	{"kf62", "Fq"},
	{"kf63", "Fr"},
	{"kf7", "k7"},
	{"kf8", "k8"},
	{"kf9", "k9"},
	{"kfnd", "@0"},
	{"khlp", "%1"},
	{"khome", "kh"},
	{"khts", "kT"},
	{"kich1", "kI"},
	{"kil1", "kA"},
	{"kind", "kF"},
	{"kll", "kH"},
	{"km", "km"},
	{"kmov", "%4"},
	{"kmrk", "%2"},
	{"kmsg", "%3"},
	{"knp", "kN"},
	{"knxt", "%5"},
	{"kopn", "%6"},
	{"kopt", "%7"},
	{"kpp", "kP"},
	{"kprt", "%9"},
	{"kprv", "%8"},
	{"krdo", "%0"},
	{"kref", "&1"},
	{"kres", "&5"},
	{"krfr", "&2"},
	{"kri", "kR"},
	{"krmir", "kM"},
	{"krpl", "&3"},
	{"krst", "&4"},
	{"ksav", "&6"},
	{"kslt", "*6"},
	{"kspd", "&7"},
	{"ktbc", "ka"},
	{"kund", "&8"},
	{"lf0", "l0"},
	{"lf1", "l1"},
	{"lf10", "la"},
	{"lf2", "l2"},
	{"lf3", "l3"},
	{"lf4", "l4"},
	{"lf5", "l5"},
	{"lf6", "l6"},
	{"lf7", "l7"},
	{"lf8", "l8"},
	{"lf9", "l9"},
	{"lh", "lh"},
	{"lines", "li"},
	{"ll", "ll"},
	{"lm", "lm"},
	{"lw", "lw"},
	{"mc0", "ps"},
	{"mc4", "pf"},
	{"mc5", "po"},
	{"mc5i", "5i"},
	{"mc5p", "pO"},
	{"mgc", "MC"},
	{"mir", "mi"},
	{"mrcup", "CM"},
	{"msgr", "ms"},
	{"nel", "nw"},
	{"nlab", "Nl"},
	{"npc", "NP"},
	{"nrrmc", "NR"},
	{"nxon", "nx"},
	{"os", "os"},
	{"pad", "pc"},
	{"pb", "pb"},
	{"pfkey", "pk"},
	{"pfloc", "pl"},
	{"pfx", "px"},
	{"pln", "pn"},
	{"prot", "mp"},
	{"rc", "rc"},
	{"rep", "rp"},
	{"rev", "mr"},
	{"rf", "rf"},
	{"rfi", "RF"},
	{"ri", "sr"},
	{"rin", "SR"},
	{"rmacs", "ae"},
	{"rmam", "RA"},
	{"rmcup", "te"},
	{"rmdc", "ed"},
	{"rmir", "ei"},
	{"rmkx", "ke"},
	{"rmln", "LF"},
	{"rmm", "mo"},
	{"rmp", "rP"},
	{"rmso", "se"},
	{"rmul", "ue"},
	{"rmxon", "RX"},
	{"rs1", "r1"},
	{"rs2", "r2"},
	{"rs3", "r3"},
	{"sc", "sc"},
	{"sgr", "sa"},
	{"sgr0", "me"},
	{"smacs", "as"},
	{"smam", "SA"},
	{"smcup", "ti"},
	{"smdc", "dm"},
	{"smgl", "ML"},
	{"smgr", "MR"},
	{"smir", "im"},
	{"smkx", "ks"},
	{"smln", "LO"},
	{"smm", "mm"},
	{"smso", "so"},
	{"smul", "us"},
	{"smxon", "SX"},
	{"tbc", "ct"},
	{"tsl", "ts"},
	{"uc", "uc"},
	{"ul", "ul"},
	{"vpa", "cv"},
	{"vt", "vt"},
	{"wind", "wi"},
	{"wsl", "ws"},
	{"xenl", "xn"},
	{"xhp", "xs"},
	{"xmc", "sg"},
	{"xoffc", "XF"},
	{"xon", "xo"},
	{"xonc", "XN"},
	{"xsb", "xb"},
	{"xt", "xt"}
};

int errno;
unsigned short errsup = 0;
xxTPUTxx
fi
if test -f 'tput.c'
then
	echo shar: "will not over-write existing file 'tput.c'"
else
cat << \xxTPUTxx > 'tput.c'
#ifndef LINT
static char rcsid[] = "$Header: tput.c,v 1.6 86/09/19 17:01:00 badri Exp $" ;
#endif LINT
/*
 * Copyright (C) $Date: 86/09/19 17:01:00 $
 * by $Author: badri $
 * University of Rochester,
 * Department of Electrical Engineering.
 *
 * CoNtEnTs   This file contains a program to emulate the system V
 * CoNtEnTs   version of tput.
 *
 * $Locker:  $
 * $Source: /u/users/badri/usr/src/local/tput/RCS/tput.c,v $
 * $Revision: 1.6 $
 *
 * History of this release:
 * $Log:	tput.c,v $
 * Revision 1.6  86/09/19  17:01:00  badri
 * Updated to incorporate -e flag etc.
 * 
 * Revision 1.5  86/09/18  20:58:09  badri
 * Rewrote match, which had a bug in it!
 * 
 * Revision 1.4  86/09/18  15:43:34  badri
 * Updated to incorporate all flags of the old SV tput plus cursor movement
 * plus -n flag to affect number of lines (if permitted.)
 * 
 * Revision 1.3  86/09/18  15:34:51  badri
 * This is an interim version to make tput more compatible with SV.
 * Mods suggested by mark at cbosgd (Mark Horton)
 * 
 * Revision 1.2  86/08/22  13:39:27  badri
 * 1. Corrected a bug that would cause %d to fail after %%.
 * 2. Included XTABS handling.
 * 3. General cleanup of code.
 * 1. Corrected a bug that would cause %d to fail after %%.
 * 2. Included XTABS handling.
 * 3. General cleanup of code.
 * 
 * Revision 1.1  86/08/21  19:23:33  badri
 * Initial revision
 * 
 */
#include "tput.h"

main(argc,argv)
int argc;
char *argv[];
{
	char bp[LARGEBUF], *getenv(), *tgetstr(), *tgoto(),
	     buf[SMALLBUF], *id, *area, *ptr;
	int outc();
	struct sgttyb ttyprm;
	unsigned short ttyflg, arg, start, pos, end;
	long affcnt, val;

	if (argc < 2) quit(BADUSE,"fubar");

	arg = 1;
	affcnt = 1;
	val = -1;	/* This is used for examining if type of
			 * terminal is explicitly specified.
			 */

	while (argv[arg][0] == '-')
	{
		switch (argv[arg][1])
		{
			case 'T':	/* Terminal type */
			if (argv[arg][2] == '\0' || argc < 3)
				quit(BADUSE,"fubar");

			if (tgetent(bp,&argv[arg][2]) < 1)
				quit(BADTERM,&argv[arg][2]);
			val = 0;
			break;

			case 'e':	/* Suppress printing of error message */
			errsup = 1;
			break;

			case 'n':	/* No. of affected lines */
			affcnt = atoi(&argv[arg][2]); 
			break;

			default:
				quit(BADUSE,"fubar");
		}
		arg++;
	}
	if (val < 0)
		if (tgetent(bp,getenv("TERM")) < 1)
			quit(BADTERM,"in environment variable TERM");

	/* Begin a binary search for capability in table */ 
	for (start = 0, end = TABLESIZE - 1, pos = (end - start) >> 1;
	     end - start > 1; pos = start + ((end - start) >> 1))
	{
		switch (match(argv[arg],table[pos].key))
		{
			case -1:    /* Lexicographically less than pos */
			end = pos;
			continue;

			case  0:	/* A hit! */
			id = table[pos].value;
			goto WORK;

			case  1:    /* Lexicographically greater than pos. */
			start = pos;
			continue;
		}			
	}

	/* Examine the current start and end positions of table for match */
	if (!match(argv[arg],table[start].key)) id = table[start].value;
	else if (!match(argv[arg],table[end].key)) id = table[end].value;
	else quit(BADCAP,argv[arg]);  /* Could not find capability in table */

	WORK:
	/* At this point we know that the capability exists in our
	 * table, but we do not know if it is of type boolean, string
	 * or has a numeric value (or does not exist.)
	 */
	if ((val = tgetnum(id)) != -1)
	{
		/* It has a numeric value. Print it and quit. */
		fprintf(stdout, "%d\n",val);
		quit(SUCCESS,"tput");
	}

	/* It is of type string (or boolean) */
	area = buf;
	if (!tgetstr(id,&area))
	{
		/* Boolean */
	 	if (tgetflag(id)) quit(SUCCESS,"tput");
		else quit(FAILURE,"tput");
	}
	/*
	 * It is of type string.
	 * Examine if cursor movement specified. This is done
	 * by looking for % followed by any but %. Since %%
	 * is a single %, we have to make sure that %% followed
	 * by any but % is not interpreted as a format.
	 * If cursor movement is specified then tgoto needs
	 * to be invoked. Else put as is.
	 */
	ptr = buf;
	while (*ptr != '\0')
	{
		if (*(ptr++) != '%') continue;
		if (*ptr != '\0' && *(ptr++) != '%')
		{
			/* This string is a cm string. Increment arg to
			 * position it over the numeric argument (if specified!)
			 */
			if (argc - ++arg < 2) quit(BADUSE,"fubar");

			if (*(ptr=tgoto(buf,atoi(argv[arg+1]),atoi(argv[arg])))
				== 'O' && *(ptr+1) == 'O' &&
			    *(ptr+2) == 'P' && *(ptr+3) == 'S')
				quit(BADUSE,"fubar");

			/* Turn off XTABS, but save old flags first. */
			if (gtty(fileno(stdout),&ttyprm) < 0)
				quit(SYSTEM,"fubar");
			ttyflg = ttyprm.sg_flags;

			ttyprm.sg_flags &= ~XTABS;
			if (stty(fileno(stdout),&ttyprm) < 0)
				quit(SYSTEM,"fubar");

			tputs(ptr,affcnt,outc);

			/* Restore old flags. */
			ttyprm.sg_flags = ttyflg;
			if (stty(fileno(stdout),&ttyprm) < 0)
				quit(SYSTEM,"fubar");
			quit(SUCCESS,"tput");
		}
	quit(BADUSE,"fubar");
	}
	tputs(buf,affcnt,outc);
	quit(SUCCESS,"tput");
}

outc(c)
char c;
{
	if (write(fileno(stdout),&c,sizeof(char)) < 0)
		quit(SYSTEM,"fubar");
	return(SUCCESS);
}

match(s1,s2)
char *s1, *s2;
{
	while (*s1 == *s2)
	{
		if (*s1 == '\0') return(0);
		s1++, s2++;
	}
	return(*s1 > *s2 ? 1:-1);
}

quit(i,s)
int i;
char *s;
{
	if (errsup)
	{
		if (i < SYSTEM) exit(i);
		else exit(errno);
	}
	switch(i)
	{
		case SUCCESS:
		case FAILURE:
		exit(i);

		case BADUSE:
		fprintf(stderr,
		"Usage: tput [ -Ttype ] [ -e ] [ -nlines ] capname [ x y ]\n");
		exit(i);
	
		case BADTERM:
		fprintf(stderr, "Bad terminal type: %s\n",s);
		exit(i);

		case BADCAP:
		fprintf(stderr, "Bad capability: %s\n",s);
		exit(i);

		case SYSTEM:
		fprintf(stderr, "Terminal I/O error - examine exit status\n");
		exit(errno);
	}
}
xxTPUTxx
fi
exit 0
#	End of shell archive



More information about the Mod.sources mailing list