ncursesw-morphos/progs/capconvert

260 lines
8.7 KiB
Plaintext
Raw Normal View History

1998-03-01 12:21:12 +08:00
#!/bin/sh
2006-12-18 12:32:42 +08:00
##############################################################################
# Copyright 2019,2020 Thomas E. Dickey #
# Copyright 1998-2011,2017 Free Software Foundation, Inc. #
2006-12-18 12:32:42 +08:00
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, distribute #
# with modifications, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the #
# following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
# Except as contained in this notice, the name(s) of the above copyright #
# holders shall not be used in advertising or otherwise to promote the sale, #
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
# $Id: capconvert,v 1.9 2020/02/02 23:34:34 tom Exp $
1997-05-15 12:00:00 +08:00
#
# capconvert -- automated conversion from termcap to terminfo
#
echo "This script tries to automatically set you up so that your applications"
echo "that now use termcap can use terminfo and the ncurses library."
echo ""
# Note, except for telling if we're running under xterm we don't use TERM at
# all. This is because BSD users not infrequently have multiple termtypes
# selected by conditionals in tset -- unless they're xterm users, in which
# case they're on a workstation and probably don't.
# Check to make sure TERMINFO is not already defined
1998-03-01 12:21:12 +08:00
if test -n "$TERMINFO"
1997-05-15 12:00:00 +08:00
then
echo "TERMINFO is already defined in your environment. This means"
echo "you already have a local terminfo tree, so you do not need any"
echo "conversion."
1998-03-01 12:21:12 +08:00
if test ! -d $TERMINFO ; then
echo "Caution: TERMINFO does not point to a directory!"
fi
1997-05-15 12:00:00 +08:00
exit;
fi
1998-03-01 12:21:12 +08:00
# Check to see if terminfo is present in one of the standard locations.
terminfo=no
for p in $TERMINFO \
/usr/lib/terminfo \
/usr/share/lib/terminfo \
/usr/share/terminfo \
/usr/local/lib/terminfo \
/usr/local/share/terminfo
do
if test -d $p ; then
terminfo=yes
break
fi
done
if test $terminfo = yes
1997-05-15 12:00:00 +08:00
then
echo "Your system already has a system-wide terminfo tree."
echo ""
1998-03-01 12:21:12 +08:00
if test -z "$TERMCAP"
1997-05-15 12:00:00 +08:00
then
1998-03-01 12:21:12 +08:00
echo "You have no TERMCAP variable set, so we are done."
1997-05-15 12:00:00 +08:00
# Assumes the terminfo master covers all canned terminal types
exit;
fi
case $TERM in
xterm | xterm-*)
1998-03-01 12:21:12 +08:00
echo "You are running xterm, which usually sets TERMCAP itself."
1997-05-15 12:00:00 +08:00
echo "We can ignore this, because terminfo knows about xterm."
1998-03-01 12:21:12 +08:00
echo "So you will just use the system-wide terminfo tree."
exit
;;
*)
1998-03-01 12:21:12 +08:00
echo "We will have to make a local one for you anyway, to capture the effect"
echo "of your TERMCAP variable."
;;
esac
1997-05-15 12:00:00 +08:00
else
1998-03-01 12:21:12 +08:00
echo "No system-wide terminfo tree. We will make you a local one."
1997-05-15 12:00:00 +08:00
fi
echo "";
1998-03-01 12:21:12 +08:00
# Check if test -x works (it's not portable, but useful)
OPT="-x"
TMP=test$$; touch $TMP && chmod 755 $TMP
if test $OPT $TMP ; then
chmod 644 $TMP
test $OPT $TMP && OPT="-f"
else
OPT="-f"
fi
rm -f $TMP
1997-05-15 12:00:00 +08:00
# First step -- go find tic
1998-03-01 12:21:12 +08:00
TIC=
IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
for x in $PATH .
1997-05-15 12:00:00 +08:00
do
1998-03-01 12:21:12 +08:00
if test $OPT $x/tic
then
1998-03-01 12:21:12 +08:00
TIC=$x/tic
break
fi
1997-05-15 12:00:00 +08:00
done
1998-03-01 12:21:12 +08:00
IFS="$ac_save_ifs"
if test -n "$TIC"
1997-05-15 12:00:00 +08:00
then
1998-03-01 12:21:12 +08:00
echo "I see tic at $TIC."
case $TIC in # (vi
./tic)
if test $OPT ../misc/shlib ; then
TIC="../misc/shlib $TIC"
fi
;;
esac
1997-05-15 12:00:00 +08:00
else
1998-03-01 12:21:12 +08:00
echo "You do not have tic installed anywhere I can see, please fix that."
1997-05-15 12:00:00 +08:00
exit;
fi
echo "";
# We have tic. Either there's no system terminfo tree or there is one but
# the user has a TERMCAP variable that may modify a stock description.
#
# Make the user a terminfo directory
1998-03-01 12:21:12 +08:00
if test -d $HOME/.terminfo
1997-05-15 12:00:00 +08:00
then
echo "It appears you already have a private terminfo directory"
echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
echo "is not defined. I am not going to second-guess this -- if you"
1997-05-15 12:00:00 +08:00
echo "really want me to try auto-configuring for you, remove or"
echo "rename $HOME/terminfo and run me again."
exit;
else
1998-03-01 12:21:12 +08:00
echo "I am creating your private terminfo directory at $HOME/.terminfo"
1997-05-15 12:00:00 +08:00
mkdir $HOME/.terminfo
# Ensure that that's where tic's compilation results.
# This isn't strictly necessary with a 1.9.7 or later tic.
TERMINFO="$HOME/.terminfo"; export TERMINFO
fi
echo "";
# Find a terminfo source to work from
1998-03-01 12:21:12 +08:00
if test -f ../misc/terminfo.src
1997-05-15 12:00:00 +08:00
then
1998-03-01 12:21:12 +08:00
echo "I see the terminfo master source is handy; I will use that."
1997-05-15 12:00:00 +08:00
master=../misc/terminfo.src
else
# Ooops...looks like we're running from somewhere other than the
# progs directory of an ncurses source tree.
master=`find $HOME -name "*terminfo.src" -print`
mcount=`echo $master | wc -l`
case $mcount in
0)
1998-03-01 12:21:12 +08:00
echo "I can not find a terminfo source file anywhere under your home directory."
1997-05-15 12:00:00 +08:00
echo "There should be a file called terminfo.src somewhere in your"
echo "ncurses distribution; please put it in your home directotry"
1998-03-01 12:21:12 +08:00
echo "and run me again (it does not have to live there permanently)."
1997-05-15 12:00:00 +08:00
exit;
;;
1)
echo "I see a file called $master."
1998-03-01 12:21:12 +08:00
echo "I am going to assume this is the terminfo source included with"
1997-05-15 12:00:00 +08:00
echo "the ncurses distribution. If this assumption is wrong, please"
echo "interrupt me now! OK to continue?"
read answer;
1997-05-15 12:00:00 +08:00
;;
2)
echo "I see more than one possible terminfo source. Here they are:"
echo $master | sed "/^/s// /";
while :
do
echo "Please tell me which one to use:"
read master;
1998-03-01 12:21:12 +08:00
if test -f $master
1997-05-15 12:00:00 +08:00
then
break
else
1998-03-01 12:21:12 +08:00
echo "That file does not exist. Try again?";
1997-05-15 12:00:00 +08:00
fi
done
;;
esac
fi
echo "";
# Now that we have a master, compile it into the local tree
1998-03-01 12:21:12 +08:00
echo "OK, now I will make your private terminfo tree. This may take a bit..."
1997-05-15 12:00:00 +08:00
#
# Kluge alert: we compile terminfo.src in two pieces because a lot of machines
# with < 16MB RAM choke on tic's core-hog habits.
trap "rm -f tsplit$$.*" EXIT INT QUIT TERM HUP
1997-05-15 12:00:00 +08:00
sed -n $master \
1998-03-01 12:21:12 +08:00
-e '1,/SPLIT HERE/w 'tsplit$$.01 \
-e '/SPLIT HERE/,$w 'tsplit$$.02 \
1997-05-15 12:00:00 +08:00
2>/dev/null
1998-03-01 12:21:12 +08:00
for x in tsplit$$.*; do eval $TIC $x; done
1997-05-15 12:00:00 +08:00
rm tsplit$$.*
trap EXIT INT QUIT TERM HUP
1997-05-15 12:00:00 +08:00
#
echo "You now have a private tree under $HOME/.terminfo;"
echo "the ncurses library will automatically read from it,"
echo "and ncurses tic will automatically compile entries to it."
1997-05-15 12:00:00 +08:00
# We're done unless user has a .termcap file or equivalent named by TERMCAP
1998-03-01 12:21:12 +08:00
if test -z "$TERMCAP"
1997-05-15 12:00:00 +08:00
then
1998-03-01 12:21:12 +08:00
echo "You have no TERMCAP set, so we are done."
1997-05-15 12:00:00 +08:00
fi
# OK, here comes the nasty case...user has a TERMCAP. Instead of
# trying to follow all the convolutions of the relationship between
# TERM and TERMCAP (partly because it's too painful, and partly because
# we don't actually know what TERM will be nor even if it always has
# the same value for this user) we do the following three steps...
1998-03-01 12:21:12 +08:00
if test -f $HOME/.termcap
1997-05-15 12:00:00 +08:00
then
1998-03-01 12:21:12 +08:00
echo 'I see you have a $HOME/.termcap file. I will compile that.'
eval $TIC $HOME/.termcap
1997-05-15 12:00:00 +08:00
echo "Done."
echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
1998-03-01 12:21:12 +08:00
elif test -f "$TERMCAP"
then
1998-03-01 12:21:12 +08:00
echo "Your TERMCAP names the file $TERMCAP. I will compile that."
eval $TIC $TERMCAP
1997-05-15 12:00:00 +08:00
echo "Done."
echo "Note that editing $TERMCAP will no longer change the data curses sees."
else
echo "Your TERMCAP value appears to be an entry in termcap format."
1998-03-01 12:21:12 +08:00
echo "I will compile it."
1997-05-15 12:00:00 +08:00
echo $TERMCAP >myterm$$
1998-03-01 12:21:12 +08:00
eval $TIC myterm$$
1997-05-15 12:00:00 +08:00
rm myterm$$
echo "Done."
echo "Note that editing TERMCAP will no longer change the data curses sees."
1998-03-01 12:21:12 +08:00
fi
echo "To do that, decompile the terminal description you want with infocmp(1),"
1997-05-15 12:00:00 +08:00
echo "edit to taste, and recompile using tic(1)."
# capconvert ends here