2 ##############################################################################
3 # Copyright (c) 1998-2011,2017 Free Software Foundation, Inc. #
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: #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
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. #
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 #
28 ##############################################################################
29 # $Id: capconvert,v 1.6 2017/08/12 12:22:06 tom Exp $
31 # capconvert -- automated conversion from termcap to terminfo
34 echo "This script tries to automatically set you up so that your applications"
35 echo "that now use termcap can use terminfo and the ncurses library."
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.
43 # Check to make sure TERMINFO is not already defined
44 if test -n "$TERMINFO"
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"
49 if test ! -d $TERMINFO ; then
50 echo "Caution: TERMINFO does not point to a directory!"
55 # Check to see if terminfo is present in one of the standard locations.
59 /usr/share/lib/terminfo \
61 /usr/local/lib/terminfo \
62 /usr/local/share/terminfo
70 if test $terminfo = yes
72 echo "Your system already has a system-wide terminfo tree."
76 echo "You have no TERMCAP variable set, so we are done."
77 # Assumes the terminfo master covers all canned terminal types
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."
88 echo "We will have to make a local one for you anyway, to capture the effect"
89 echo "of your TERMCAP variable."
93 echo "No system-wide terminfo tree. We will make you a local one."
97 # Check if test -x works (it's not portable, but useful)
99 TMP=test$$; touch $TMP && chmod 755 $TMP
100 if test $OPT $TMP ; then
102 test $OPT $TMP && OPT="-f"
108 # First step -- go find tic
110 IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
123 echo "I see tic at $TIC."
126 if test $OPT ../misc/shlib ; then
127 TIC="../misc/shlib $TIC"
132 echo "You do not have tic installed anywhere I can see, please fix that."
137 # We have tic. Either there's no system terminfo tree or there is one but
138 # the user has a TERMCAP variable that may modify a stock description.
141 # Make the user a terminfo directory
142 if test -d $HOME/.terminfo
144 echo "It appears you already have a private terminfo directory"
145 echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
146 echo "is not defined. I am not going to second-guess this -- if you"
147 echo "really want me to try auto-configuring for you, remove or"
148 echo "rename $HOME/terminfo and run me again."
151 echo "I am creating your private terminfo directory at $HOME/.terminfo"
152 mkdir $HOME/.terminfo
153 # Ensure that that's where tic's compilation results.
154 # This isn't strictly necessary with a 1.9.7 or later tic.
155 TERMINFO="$HOME/.terminfo"; export TERMINFO
159 # Find a terminfo source to work from
160 if test -f ../misc/terminfo.src
162 echo "I see the terminfo master source is handy; I will use that."
163 master=../misc/terminfo.src
165 # Ooops...looks like we're running from somewhere other than the
166 # progs directory of an ncurses source tree.
167 master=`find $HOME -name "*terminfo.src" -print`
168 mcount=`echo $master | wc -l`
171 echo "I can not find a terminfo source file anywhere under your home directory."
172 echo "There should be a file called terminfo.src somewhere in your"
173 echo "ncurses distribution; please put it in your home directotry"
174 echo "and run me again (it does not have to live there permanently)."
178 echo "I see a file called $master."
179 echo "I am going to assume this is the terminfo source included with"
180 echo "the ncurses distribution. If this assumption is wrong, please"
181 echo "interrupt me now! OK to continue?"
185 echo "I see more than one possible terminfo source. Here they are:"
186 echo $master | sed "/^/s// /";
189 echo "Please tell me which one to use:"
195 echo "That file does not exist. Try again?";
203 # Now that we have a master, compile it into the local tree
204 echo "OK, now I will make your private terminfo tree. This may take a bit..."
206 # Kluge alert: we compile terminfo.src in two pieces because a lot of machines
207 # with < 16MB RAM choke on tic's core-hog habits.
208 trap "rm -f tsplit$$.*" 0 1 2 3 15
210 -e '1,/SPLIT HERE/w 'tsplit$$.01 \
211 -e '/SPLIT HERE/,$w 'tsplit$$.02 \
213 for x in tsplit$$.*; do eval $TIC $x; done
217 echo "You now have a private tree under $HOME/.terminfo;"
218 echo "the ncurses library will automatically read from it,"
219 echo "and ncurses tic will automatically compile entries to it."
221 # We're done unless user has a .termcap file or equivalent named by TERMCAP
222 if test -z "$TERMCAP"
224 echo "You have no TERMCAP set, so we are done."
227 # OK, here comes the nasty case...user has a TERMCAP. Instead of
228 # trying to follow all the convolutions of the relationship between
229 # TERM and TERMCAP (partly because it's too painful, and partly because
230 # we don't actually know what TERM will be nor even if it always has
231 # the same value for this user) we do the following three steps...
233 if test -f $HOME/.termcap
235 echo 'I see you have a $HOME/.termcap file. I will compile that.'
236 eval $TIC $HOME/.termcap
238 echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
239 elif test -f "$TERMCAP"
241 echo "Your TERMCAP names the file $TERMCAP. I will compile that."
244 echo "Note that editing $TERMCAP will no longer change the data curses sees."
246 echo "Your TERMCAP value appears to be an entry in termcap format."
247 echo "I will compile it."
248 echo $TERMCAP >myterm$$
252 echo "Note that editing TERMCAP will no longer change the data curses sees."
254 echo "To do that, decompile the terminal decription you want with infocmp(1),"
255 echo "edit to taste, and recompile using tic(1)."
257 # capconvert ends here