xref: /freebsd/contrib/ncurses/progs/capconvert (revision 87c1627502a5dde91e5284118eec8682b60f27a2)
1#!/bin/sh
2##############################################################################
3# Copyright (c) 1998,2006 Free Software Foundation, Inc.                     #
4#                                                                            #
5# Permission is hereby granted, free of charge, to any person obtaining a    #
6# copy of this software and associated documentation files (the "Software"), #
7# to deal in the Software without restriction, including without limitation  #
8# the rights to use, copy, modify, merge, publish, distribute, distribute    #
9# with modifications, sublicense, and/or sell copies of the Software, and to #
10# permit persons to whom the Software is furnished to do so, subject to the  #
11# following conditions:                                                      #
12#                                                                            #
13# The above copyright notice and this permission notice shall be included in #
14# all copies or substantial portions of the Software.                        #
15#                                                                            #
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22# DEALINGS IN THE SOFTWARE.                                                  #
23#                                                                            #
24# Except as contained in this notice, the name(s) of the above copyright     #
25# holders shall not be used in advertising or otherwise to promote the sale, #
26# use or other dealings in this Software without prior written               #
27# authorization.                                                             #
28##############################################################################
29# $Id: capconvert,v 1.4 2006/04/22 21:46:17 tom Exp $
30#
31# capconvert -- automated conversion from termcap to terminfo
32#
33
34echo "This script tries to automatically set you up so that your applications"
35echo "that now use termcap can use terminfo and the ncurses library."
36echo ""
37
38# Note, except for telling if we're running under xterm we don't use TERM at
39# all.  This is because BSD users not infrequently have multiple termtypes
40# selected by conditionals in tset -- unless they're xterm users, in which
41# case they're on a workstation and probably don't.
42
43# Check to make sure TERMINFO is not already defined
44if test -n "$TERMINFO"
45then
46	echo "TERMINFO is already defined in your environment.  This means"
47	echo "you already have a local terminfo tree, so you do not need any"
48	echo "conversion."
49	if test ! -d $TERMINFO ; then
50		echo "Caution: TERMINFO does not point to a directory!"
51	fi
52	exit;
53fi
54
55# Check to see if terminfo is present in one of the standard locations.
56terminfo=no
57for p in $TERMINFO \
58	/usr/lib/terminfo \
59	/usr/share/lib/terminfo \
60	/usr/share/terminfo \
61	/usr/local/lib/terminfo \
62	/usr/local/share/terminfo
63do
64	if test -d $p ; then
65		terminfo=yes
66		break
67	fi
68done
69
70if test $terminfo = yes
71then
72	echo "Your system already has a system-wide terminfo tree."
73	echo ""
74	if test -z "$TERMCAP"
75	then
76		echo "You have no TERMCAP variable set, so we are done."
77		# Assumes the terminfo master covers all canned terminal types
78		exit;
79	fi
80	if test "$TERM" = "xterm"
81	then
82		echo "You are running xterm, which usually sets TERMCAP itself."
83		echo "We can ignore this, because terminfo knows about xterm."
84		echo "So you will just use the system-wide terminfo tree."
85		exit;
86	else
87		echo "We will have to make a local one for you anyway, to capture the effect"
88		echo "of your TERMCAP variable."
89	fi
90else
91	echo "No system-wide terminfo tree.  We will make you a local one."
92fi
93echo "";
94
95# Check if test -x works (it's not portable, but useful)
96OPT="-x"
97TMP=test$$; touch $TMP && chmod 755 $TMP
98if test $OPT $TMP ; then
99	chmod 644 $TMP
100	test $OPT $TMP && OPT="-f"
101else
102	OPT="-f"
103fi
104rm -f $TMP
105
106# First step -- go find tic
107TIC=
108IFS="${IFS= 	}"; save_ifs="$IFS"; IFS="${IFS}:"
109for x in $PATH .
110do
111	if test $OPT $x/tic
112	then
113		TIC=$x/tic
114		break
115	fi
116done
117IFS="$ac_save_ifs"
118
119if test -n "$TIC"
120then
121	echo "I see tic at $TIC."
122	case $TIC in # (vi
123	./tic)
124		if test $OPT ../misc/shlib ; then
125			TIC="../misc/shlib $TIC"
126		fi
127		;;
128	esac
129else
130	echo "You do not have tic installed anywhere I can see, please fix that."
131	exit;
132fi
133echo "";
134
135# We have tic.  Either there's no system terminfo tree or there is one but
136# the user has a TERMCAP variable that may modify a stock description.
137#
138
139# Make the user a terminfo directory
140if test -d $HOME/.terminfo
141then
142	echo "It appears you already have a private terminfo directory"
143	echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
144	echo "is not defined.  I am not going to second-guess this -- if you"
145	echo "really want me to try auto-configuring for you, remove or"
146	echo "rename $HOME/terminfo and run me again."
147	exit;
148else
149	echo "I am creating your private terminfo directory at $HOME/.terminfo"
150	mkdir $HOME/.terminfo
151	# Ensure that that's where tic's compilation results.
152	# This isn't strictly necessary with a 1.9.7 or later tic.
153	TERMINFO="$HOME/.terminfo"; export TERMINFO
154fi
155echo "";
156
157# Find a terminfo source to work from
158if test -f ../misc/terminfo.src
159then
160	echo "I see the terminfo master source is handy; I will use that."
161	master=../misc/terminfo.src
162else
163	# Ooops...looks like we're running from somewhere other than the
164	# progs directory of an ncurses source tree.
165	master=`find $HOME -name "*terminfo.src" -print`
166	mcount=`echo $master | wc -l`
167	case $mcount in
168	0)
169		echo "I can not find a terminfo source file anywhere under your home directory."
170		echo "There should be a file called terminfo.src somewhere in your"
171		echo "ncurses distribution; please put it in your home directotry"
172		echo "and run me again (it does not have to live there permanently)."
173		exit;
174	;;
175	1)
176		echo "I see a file called $master."
177		echo "I am going to assume this is the terminfo source included with"
178		echo "the ncurses distribution.  If this assumption is wrong, please"
179		echo "interrupt me now!  OK to continue?"
180		read ans;
181	;;
182	2)
183		echo "I see more than one possible terminfo source.  Here they are:"
184		echo $master | sed "/^/s//	/";
185		while :
186		do
187			echo "Please tell me which one to use:"
188			read master;
189			if test -f $master
190			then
191				break
192			else
193				echo "That file does not exist. Try again?";
194			fi
195		done
196	;;
197	esac
198fi
199echo "";
200
201# Now that we have a master, compile it into the local tree
202echo "OK, now I will make your private terminfo tree.  This may take a bit..."
203#
204# Kluge alert: we compile terminfo.src in two pieces because a lot of machines
205# with < 16MB RAM choke on tic's core-hog habits.
206trap "rm -f tsplit$$.*" 0 1 2 5 15
207sed -n $master \
208	-e '1,/SPLIT HERE/w 'tsplit$$.01 \
209	-e '/SPLIT HERE/,$w 'tsplit$$.02 \
210	2>/dev/null
211for x in tsplit$$.*; do eval $TIC $x; done
212rm tsplit$$.*
213trap 0 1 2 5 15
214#
215echo "You now have a private tree under $HOME/.terminfo;"
216echo "the ncurses library will automatically read from it,"
217echo "and ncurses tic will automatically compile entries to it."
218
219# We're done unless user has a .termcap file or equivalent named by TERMCAP
220if test -z "$TERMCAP"
221then
222	echo "You have no TERMCAP set, so we are done."
223fi
224
225# OK, here comes the nasty case...user has a TERMCAP.  Instead of
226# trying to follow all the convolutions of the relationship between
227# TERM and TERMCAP (partly because it's too painful, and partly because
228# we don't actually know what TERM will be nor even if it always has
229# the same value for this user) we do the following three steps...
230
231if test -f $HOME/.termcap
232then
233	echo 'I see you have a $HOME/.termcap file.  I will compile that.'
234	eval $TIC $HOME/.termcap
235	echo "Done."
236	echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
237elif test -f "$TERMCAP"
238then
239	echo "Your TERMCAP names the file $TERMCAP.  I will compile that."
240	eval $TIC $TERMCAP
241	echo "Done."
242	echo "Note that editing $TERMCAP will no longer change the data curses sees."
243else
244	echo "Your TERMCAP value appears to be an entry in termcap format."
245	echo "I will compile it."
246	echo $TERMCAP >myterm$$
247	eval $TIC myterm$$
248	rm myterm$$
249	echo "Done."
250	echo "Note that editing TERMCAP will no longer change the data curses sees."
251fi
252echo "To do that, decompile the terminal decription you want with infocmp(1),"
253echo "edit to taste, and recompile using tic(1)."
254
255# capconvert ends here
256
257