15f4613f2SJohn Marino#!/bin/sh 25f4613f2SJohn Marino############################################################################## 3*32bb5217SDaniel Fojt# Copyright 2019,2020 Thomas E. Dickey # 4*32bb5217SDaniel Fojt# Copyright 1998-2011,2017 Free Software Foundation, Inc. # 55f4613f2SJohn Marino# # 65f4613f2SJohn Marino# Permission is hereby granted, free of charge, to any person obtaining a # 75f4613f2SJohn Marino# copy of this software and associated documentation files (the "Software"), # 85f4613f2SJohn Marino# to deal in the Software without restriction, including without limitation # 95f4613f2SJohn Marino# the rights to use, copy, modify, merge, publish, distribute, distribute # 105f4613f2SJohn Marino# with modifications, sublicense, and/or sell copies of the Software, and to # 115f4613f2SJohn Marino# permit persons to whom the Software is furnished to do so, subject to the # 125f4613f2SJohn Marino# following conditions: # 135f4613f2SJohn Marino# # 145f4613f2SJohn Marino# The above copyright notice and this permission notice shall be included in # 155f4613f2SJohn Marino# all copies or substantial portions of the Software. # 165f4613f2SJohn Marino# # 175f4613f2SJohn Marino# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 185f4613f2SJohn Marino# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 195f4613f2SJohn Marino# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 205f4613f2SJohn Marino# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 215f4613f2SJohn Marino# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 225f4613f2SJohn Marino# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 235f4613f2SJohn Marino# DEALINGS IN THE SOFTWARE. # 245f4613f2SJohn Marino# # 255f4613f2SJohn Marino# Except as contained in this notice, the name(s) of the above copyright # 265f4613f2SJohn Marino# holders shall not be used in advertising or otherwise to promote the sale, # 275f4613f2SJohn Marino# use or other dealings in this Software without prior written # 285f4613f2SJohn Marino# authorization. # 295f4613f2SJohn Marino############################################################################## 30*32bb5217SDaniel Fojt# $Id: capconvert,v 1.9 2020/02/02 23:34:34 tom Exp $ 315f4613f2SJohn Marino# 325f4613f2SJohn Marino# capconvert -- automated conversion from termcap to terminfo 335f4613f2SJohn Marino# 345f4613f2SJohn Marino 355f4613f2SJohn Marinoecho "This script tries to automatically set you up so that your applications" 365f4613f2SJohn Marinoecho "that now use termcap can use terminfo and the ncurses library." 375f4613f2SJohn Marinoecho "" 385f4613f2SJohn Marino 395f4613f2SJohn Marino# Note, except for telling if we're running under xterm we don't use TERM at 405f4613f2SJohn Marino# all. This is because BSD users not infrequently have multiple termtypes 415f4613f2SJohn Marino# selected by conditionals in tset -- unless they're xterm users, in which 425f4613f2SJohn Marino# case they're on a workstation and probably don't. 435f4613f2SJohn Marino 445f4613f2SJohn Marino# Check to make sure TERMINFO is not already defined 455f4613f2SJohn Marinoif test -n "$TERMINFO" 465f4613f2SJohn Marinothen 475f4613f2SJohn Marino echo "TERMINFO is already defined in your environment. This means" 485f4613f2SJohn Marino echo "you already have a local terminfo tree, so you do not need any" 495f4613f2SJohn Marino echo "conversion." 505f4613f2SJohn Marino if test ! -d $TERMINFO ; then 515f4613f2SJohn Marino echo "Caution: TERMINFO does not point to a directory!" 525f4613f2SJohn Marino fi 535f4613f2SJohn Marino exit; 545f4613f2SJohn Marinofi 555f4613f2SJohn Marino 565f4613f2SJohn Marino# Check to see if terminfo is present in one of the standard locations. 575f4613f2SJohn Marinoterminfo=no 585f4613f2SJohn Marinofor p in $TERMINFO \ 595f4613f2SJohn Marino /usr/lib/terminfo \ 605f4613f2SJohn Marino /usr/share/lib/terminfo \ 615f4613f2SJohn Marino /usr/share/terminfo \ 625f4613f2SJohn Marino /usr/local/lib/terminfo \ 635f4613f2SJohn Marino /usr/local/share/terminfo 645f4613f2SJohn Marinodo 655f4613f2SJohn Marino if test -d $p ; then 665f4613f2SJohn Marino terminfo=yes 675f4613f2SJohn Marino break 685f4613f2SJohn Marino fi 695f4613f2SJohn Marinodone 705f4613f2SJohn Marino 715f4613f2SJohn Marinoif test $terminfo = yes 725f4613f2SJohn Marinothen 735f4613f2SJohn Marino echo "Your system already has a system-wide terminfo tree." 745f4613f2SJohn Marino echo "" 755f4613f2SJohn Marino if test -z "$TERMCAP" 765f4613f2SJohn Marino then 775f4613f2SJohn Marino echo "You have no TERMCAP variable set, so we are done." 785f4613f2SJohn Marino # Assumes the terminfo master covers all canned terminal types 795f4613f2SJohn Marino exit; 805f4613f2SJohn Marino fi 813468e90cSJohn Marino case $TERM in 823468e90cSJohn Marino xterm | xterm-*) 835f4613f2SJohn Marino echo "You are running xterm, which usually sets TERMCAP itself." 845f4613f2SJohn Marino echo "We can ignore this, because terminfo knows about xterm." 855f4613f2SJohn Marino echo "So you will just use the system-wide terminfo tree." 863468e90cSJohn Marino exit 873468e90cSJohn Marino ;; 883468e90cSJohn Marino *) 895f4613f2SJohn Marino echo "We will have to make a local one for you anyway, to capture the effect" 905f4613f2SJohn Marino echo "of your TERMCAP variable." 913468e90cSJohn Marino ;; 923468e90cSJohn Marino esac 935f4613f2SJohn Marinoelse 945f4613f2SJohn Marino echo "No system-wide terminfo tree. We will make you a local one." 955f4613f2SJohn Marinofi 965f4613f2SJohn Marinoecho ""; 975f4613f2SJohn Marino 985f4613f2SJohn Marino# Check if test -x works (it's not portable, but useful) 995f4613f2SJohn MarinoOPT="-x" 1005f4613f2SJohn MarinoTMP=test$$; touch $TMP && chmod 755 $TMP 1015f4613f2SJohn Marinoif test $OPT $TMP ; then 1025f4613f2SJohn Marino chmod 644 $TMP 1035f4613f2SJohn Marino test $OPT $TMP && OPT="-f" 1045f4613f2SJohn Marinoelse 1055f4613f2SJohn Marino OPT="-f" 1065f4613f2SJohn Marinofi 1075f4613f2SJohn Marinorm -f $TMP 1085f4613f2SJohn Marino 1095f4613f2SJohn Marino# First step -- go find tic 1105f4613f2SJohn MarinoTIC= 1115f4613f2SJohn MarinoIFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:" 1125f4613f2SJohn Marinofor x in $PATH . 1135f4613f2SJohn Marinodo 1145f4613f2SJohn Marino if test $OPT $x/tic 1155f4613f2SJohn Marino then 1165f4613f2SJohn Marino TIC=$x/tic 1175f4613f2SJohn Marino break 1185f4613f2SJohn Marino fi 1195f4613f2SJohn Marinodone 1205f4613f2SJohn MarinoIFS="$ac_save_ifs" 1215f4613f2SJohn Marino 1225f4613f2SJohn Marinoif test -n "$TIC" 1235f4613f2SJohn Marinothen 1245f4613f2SJohn Marino echo "I see tic at $TIC." 1255f4613f2SJohn Marino case $TIC in # (vi 1265f4613f2SJohn Marino ./tic) 1275f4613f2SJohn Marino if test $OPT ../misc/shlib ; then 1285f4613f2SJohn Marino TIC="../misc/shlib $TIC" 1295f4613f2SJohn Marino fi 1305f4613f2SJohn Marino ;; 1315f4613f2SJohn Marino esac 1325f4613f2SJohn Marinoelse 1335f4613f2SJohn Marino echo "You do not have tic installed anywhere I can see, please fix that." 1345f4613f2SJohn Marino exit; 1355f4613f2SJohn Marinofi 1365f4613f2SJohn Marinoecho ""; 1375f4613f2SJohn Marino 1385f4613f2SJohn Marino# We have tic. Either there's no system terminfo tree or there is one but 1395f4613f2SJohn Marino# the user has a TERMCAP variable that may modify a stock description. 1405f4613f2SJohn Marino# 1415f4613f2SJohn Marino 1425f4613f2SJohn Marino# Make the user a terminfo directory 1435f4613f2SJohn Marinoif test -d $HOME/.terminfo 1445f4613f2SJohn Marinothen 1455f4613f2SJohn Marino echo "It appears you already have a private terminfo directory" 1465f4613f2SJohn Marino echo "at $HOME/.terminfo; this seems odd, because TERMINFO" 1475f4613f2SJohn Marino echo "is not defined. I am not going to second-guess this -- if you" 1485f4613f2SJohn Marino echo "really want me to try auto-configuring for you, remove or" 1495f4613f2SJohn Marino echo "rename $HOME/terminfo and run me again." 1505f4613f2SJohn Marino exit; 1515f4613f2SJohn Marinoelse 1525f4613f2SJohn Marino echo "I am creating your private terminfo directory at $HOME/.terminfo" 1535f4613f2SJohn Marino mkdir $HOME/.terminfo 1545f4613f2SJohn Marino # Ensure that that's where tic's compilation results. 1555f4613f2SJohn Marino # This isn't strictly necessary with a 1.9.7 or later tic. 1565f4613f2SJohn Marino TERMINFO="$HOME/.terminfo"; export TERMINFO 1575f4613f2SJohn Marinofi 1585f4613f2SJohn Marinoecho ""; 1595f4613f2SJohn Marino 1605f4613f2SJohn Marino# Find a terminfo source to work from 1615f4613f2SJohn Marinoif test -f ../misc/terminfo.src 1625f4613f2SJohn Marinothen 1635f4613f2SJohn Marino echo "I see the terminfo master source is handy; I will use that." 1645f4613f2SJohn Marino master=../misc/terminfo.src 1655f4613f2SJohn Marinoelse 1665f4613f2SJohn Marino # Ooops...looks like we're running from somewhere other than the 1675f4613f2SJohn Marino # progs directory of an ncurses source tree. 1685f4613f2SJohn Marino master=`find $HOME -name "*terminfo.src" -print` 1695f4613f2SJohn Marino mcount=`echo $master | wc -l` 1705f4613f2SJohn Marino case $mcount in 1715f4613f2SJohn Marino 0) 1725f4613f2SJohn Marino echo "I can not find a terminfo source file anywhere under your home directory." 1735f4613f2SJohn Marino echo "There should be a file called terminfo.src somewhere in your" 1745f4613f2SJohn Marino echo "ncurses distribution; please put it in your home directotry" 1755f4613f2SJohn Marino echo "and run me again (it does not have to live there permanently)." 1765f4613f2SJohn Marino exit; 1775f4613f2SJohn Marino ;; 1785f4613f2SJohn Marino 1) 1795f4613f2SJohn Marino echo "I see a file called $master." 1805f4613f2SJohn Marino echo "I am going to assume this is the terminfo source included with" 1815f4613f2SJohn Marino echo "the ncurses distribution. If this assumption is wrong, please" 1825f4613f2SJohn Marino echo "interrupt me now! OK to continue?" 183*32bb5217SDaniel Fojt read answer; 1845f4613f2SJohn Marino ;; 1855f4613f2SJohn Marino 2) 1865f4613f2SJohn Marino echo "I see more than one possible terminfo source. Here they are:" 1875f4613f2SJohn Marino echo $master | sed "/^/s// /"; 1885f4613f2SJohn Marino while : 1895f4613f2SJohn Marino do 1905f4613f2SJohn Marino echo "Please tell me which one to use:" 1915f4613f2SJohn Marino read master; 1925f4613f2SJohn Marino if test -f $master 1935f4613f2SJohn Marino then 1945f4613f2SJohn Marino break 1955f4613f2SJohn Marino else 1965f4613f2SJohn Marino echo "That file does not exist. Try again?"; 1975f4613f2SJohn Marino fi 1985f4613f2SJohn Marino done 1995f4613f2SJohn Marino ;; 2005f4613f2SJohn Marino esac 2015f4613f2SJohn Marinofi 2025f4613f2SJohn Marinoecho ""; 2035f4613f2SJohn Marino 2045f4613f2SJohn Marino# Now that we have a master, compile it into the local tree 2055f4613f2SJohn Marinoecho "OK, now I will make your private terminfo tree. This may take a bit..." 2065f4613f2SJohn Marino# 2075f4613f2SJohn Marino# Kluge alert: we compile terminfo.src in two pieces because a lot of machines 2085f4613f2SJohn Marino# with < 16MB RAM choke on tic's core-hog habits. 209*32bb5217SDaniel Fojttrap "rm -f tsplit$$.*" EXIT INT QUIT TERM HUP 2105f4613f2SJohn Marinosed -n $master \ 2115f4613f2SJohn Marino -e '1,/SPLIT HERE/w 'tsplit$$.01 \ 2125f4613f2SJohn Marino -e '/SPLIT HERE/,$w 'tsplit$$.02 \ 2135f4613f2SJohn Marino 2>/dev/null 2145f4613f2SJohn Marinofor x in tsplit$$.*; do eval $TIC $x; done 2155f4613f2SJohn Marinorm tsplit$$.* 216*32bb5217SDaniel Fojttrap EXIT INT QUIT TERM HUP 2175f4613f2SJohn Marino# 2185f4613f2SJohn Marinoecho "You now have a private tree under $HOME/.terminfo;" 2195f4613f2SJohn Marinoecho "the ncurses library will automatically read from it," 2205f4613f2SJohn Marinoecho "and ncurses tic will automatically compile entries to it." 2215f4613f2SJohn Marino 2225f4613f2SJohn Marino# We're done unless user has a .termcap file or equivalent named by TERMCAP 2235f4613f2SJohn Marinoif test -z "$TERMCAP" 2245f4613f2SJohn Marinothen 2255f4613f2SJohn Marino echo "You have no TERMCAP set, so we are done." 2265f4613f2SJohn Marinofi 2275f4613f2SJohn Marino 2285f4613f2SJohn Marino# OK, here comes the nasty case...user has a TERMCAP. Instead of 2295f4613f2SJohn Marino# trying to follow all the convolutions of the relationship between 2305f4613f2SJohn Marino# TERM and TERMCAP (partly because it's too painful, and partly because 2315f4613f2SJohn Marino# we don't actually know what TERM will be nor even if it always has 2325f4613f2SJohn Marino# the same value for this user) we do the following three steps... 2335f4613f2SJohn Marino 2345f4613f2SJohn Marinoif test -f $HOME/.termcap 2355f4613f2SJohn Marinothen 2365f4613f2SJohn Marino echo 'I see you have a $HOME/.termcap file. I will compile that.' 2375f4613f2SJohn Marino eval $TIC $HOME/.termcap 2385f4613f2SJohn Marino echo "Done." 2395f4613f2SJohn Marino echo "Note that editing $HOME/.termcap will no longer change the data curses sees." 2405f4613f2SJohn Marinoelif test -f "$TERMCAP" 2415f4613f2SJohn Marinothen 2425f4613f2SJohn Marino echo "Your TERMCAP names the file $TERMCAP. I will compile that." 2435f4613f2SJohn Marino eval $TIC $TERMCAP 2445f4613f2SJohn Marino echo "Done." 2455f4613f2SJohn Marino echo "Note that editing $TERMCAP will no longer change the data curses sees." 2465f4613f2SJohn Marinoelse 2475f4613f2SJohn Marino echo "Your TERMCAP value appears to be an entry in termcap format." 2485f4613f2SJohn Marino echo "I will compile it." 2495f4613f2SJohn Marino echo $TERMCAP >myterm$$ 2505f4613f2SJohn Marino eval $TIC myterm$$ 2515f4613f2SJohn Marino rm myterm$$ 2525f4613f2SJohn Marino echo "Done." 2535f4613f2SJohn Marino echo "Note that editing TERMCAP will no longer change the data curses sees." 2545f4613f2SJohn Marinofi 255*32bb5217SDaniel Fojtecho "To do that, decompile the terminal description you want with infocmp(1)," 2565f4613f2SJohn Marinoecho "edit to taste, and recompile using tic(1)." 2575f4613f2SJohn Marino 2585f4613f2SJohn Marino# capconvert ends here 2595f4613f2SJohn Marino 260