| 1 | #!/bin/sh
|
|---|
| 2 | # $Id: capconvert,v 1.3 1997/08/02 21:52:06 tom Exp $
|
|---|
| 3 | #
|
|---|
| 4 | # capconvert -- automated conversion from termcap to terminfo
|
|---|
| 5 | #
|
|---|
| 6 |
|
|---|
| 7 | echo "This script tries to automatically set you up so that your applications"
|
|---|
| 8 | echo "that now use termcap can use terminfo and the ncurses library."
|
|---|
| 9 | echo ""
|
|---|
| 10 |
|
|---|
| 11 | # Note, except for telling if we're running under xterm we don't use TERM at
|
|---|
| 12 | # all. This is because BSD users not infrequently have multiple termtypes
|
|---|
| 13 | # selected by conditionals in tset -- unless they're xterm users, in which
|
|---|
| 14 | # case they're on a workstation and probably don't.
|
|---|
| 15 |
|
|---|
| 16 | # Check to make sure TERMINFO is not already defined
|
|---|
| 17 | if test -n "$TERMINFO"
|
|---|
| 18 | then
|
|---|
| 19 | echo "TERMINFO is already defined in your environment. This means"
|
|---|
| 20 | echo "you already have a local terminfo tree, so you do not need any"
|
|---|
| 21 | echo "conversion."
|
|---|
| 22 | if test ! -d $TERMINFO ; then
|
|---|
| 23 | echo "Caution: TERMINFO does not point to a directory!"
|
|---|
| 24 | fi
|
|---|
| 25 | exit;
|
|---|
| 26 | fi
|
|---|
| 27 |
|
|---|
| 28 | # Check to see if terminfo is present in one of the standard locations.
|
|---|
| 29 | terminfo=no
|
|---|
| 30 | for p in $TERMINFO \
|
|---|
| 31 | /usr/lib/terminfo \
|
|---|
| 32 | /usr/share/lib/terminfo \
|
|---|
| 33 | /usr/share/terminfo \
|
|---|
| 34 | /usr/local/lib/terminfo \
|
|---|
| 35 | /usr/local/share/terminfo
|
|---|
| 36 | do
|
|---|
| 37 | if test -d $p ; then
|
|---|
| 38 | terminfo=yes
|
|---|
| 39 | break
|
|---|
| 40 | fi
|
|---|
| 41 | done
|
|---|
| 42 |
|
|---|
| 43 | if test $terminfo = yes
|
|---|
| 44 | then
|
|---|
| 45 | echo "Your system already has a system-wide terminfo tree."
|
|---|
| 46 | echo ""
|
|---|
| 47 | if test -z "$TERMCAP"
|
|---|
| 48 | then
|
|---|
| 49 | echo "You have no TERMCAP variable set, so we are done."
|
|---|
| 50 | # Assumes the terminfo master covers all canned terminal types
|
|---|
| 51 | exit;
|
|---|
| 52 | fi
|
|---|
| 53 | if test "$TERM" = "xterm"
|
|---|
| 54 | then
|
|---|
| 55 | echo "You are running xterm, which usually sets TERMCAP itself."
|
|---|
| 56 | echo "We can ignore this, because terminfo knows about xterm."
|
|---|
| 57 | echo "So you will just use the system-wide terminfo tree."
|
|---|
| 58 | exit;
|
|---|
| 59 | else
|
|---|
| 60 | echo "We will have to make a local one for you anyway, to capture the effect"
|
|---|
| 61 | echo "of your TERMCAP variable."
|
|---|
| 62 | fi
|
|---|
| 63 | else
|
|---|
| 64 | echo "No system-wide terminfo tree. We will make you a local one."
|
|---|
| 65 | fi
|
|---|
| 66 | echo "";
|
|---|
| 67 |
|
|---|
| 68 | # Check if test -x works (it's not portable, but useful)
|
|---|
| 69 | OPT="-x"
|
|---|
| 70 | TMP=test$$; touch $TMP && chmod 755 $TMP
|
|---|
| 71 | if test $OPT $TMP ; then
|
|---|
| 72 | chmod 644 $TMP
|
|---|
| 73 | test $OPT $TMP && OPT="-f"
|
|---|
| 74 | else
|
|---|
| 75 | OPT="-f"
|
|---|
| 76 | fi
|
|---|
| 77 | rm -f $TMP
|
|---|
| 78 |
|
|---|
| 79 | # First step -- go find tic
|
|---|
| 80 | TIC=
|
|---|
| 81 | IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
|
|---|
| 82 | for x in $PATH .
|
|---|
| 83 | do
|
|---|
| 84 | if test $OPT $x/tic
|
|---|
| 85 | then
|
|---|
| 86 | TIC=$x/tic
|
|---|
| 87 | break
|
|---|
| 88 | fi
|
|---|
| 89 | done
|
|---|
| 90 | IFS="$ac_save_ifs"
|
|---|
| 91 |
|
|---|
| 92 | if test -n "$TIC"
|
|---|
| 93 | then
|
|---|
| 94 | echo "I see tic at $TIC."
|
|---|
| 95 | case $TIC in # (vi
|
|---|
| 96 | ./tic)
|
|---|
| 97 | if test $OPT ../misc/shlib ; then
|
|---|
| 98 | TIC="../misc/shlib $TIC"
|
|---|
| 99 | fi
|
|---|
| 100 | ;;
|
|---|
| 101 | esac
|
|---|
| 102 | else
|
|---|
| 103 | echo "You do not have tic installed anywhere I can see, please fix that."
|
|---|
| 104 | exit;
|
|---|
| 105 | fi
|
|---|
| 106 | echo "";
|
|---|
| 107 |
|
|---|
| 108 | # We have tic. Either there's no system terminfo tree or there is one but
|
|---|
| 109 | # the user has a TERMCAP variable that may modify a stock description.
|
|---|
| 110 | #
|
|---|
| 111 |
|
|---|
| 112 | # Make the user a terminfo directory
|
|---|
| 113 | if test -d $HOME/.terminfo
|
|---|
| 114 | then
|
|---|
| 115 | echo "It appears you already have a private terminfo directory"
|
|---|
| 116 | echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
|
|---|
| 117 | echo "is not defined. I am not going to second-guess this -- if you"
|
|---|
| 118 | echo "really want me to try auto-configuring for you, remove or"
|
|---|
| 119 | echo "rename $HOME/terminfo and run me again."
|
|---|
| 120 | exit;
|
|---|
| 121 | else
|
|---|
| 122 | echo "I am creating your private terminfo directory at $HOME/.terminfo"
|
|---|
| 123 | mkdir $HOME/.terminfo
|
|---|
| 124 | # Ensure that that's where tic's compilation results.
|
|---|
| 125 | # This isn't strictly necessary with a 1.9.7 or later tic.
|
|---|
| 126 | TERMINFO="$HOME/.terminfo"; export TERMINFO
|
|---|
| 127 | fi
|
|---|
| 128 | echo "";
|
|---|
| 129 |
|
|---|
| 130 | # Find a terminfo source to work from
|
|---|
| 131 | if test -f ../misc/terminfo.src
|
|---|
| 132 | then
|
|---|
| 133 | echo "I see the terminfo master source is handy; I will use that."
|
|---|
| 134 | master=../misc/terminfo.src
|
|---|
| 135 | else
|
|---|
| 136 | # Ooops...looks like we're running from somewhere other than the
|
|---|
| 137 | # progs directory of an ncurses source tree.
|
|---|
| 138 | master=`find $HOME -name "*terminfo.src" -print`
|
|---|
| 139 | mcount=`echo $master | wc -l`
|
|---|
| 140 | case $mcount in
|
|---|
| 141 | 0)
|
|---|
| 142 | echo "I can not find a terminfo source file anywhere under your home directory."
|
|---|
| 143 | echo "There should be a file called terminfo.src somewhere in your"
|
|---|
| 144 | echo "ncurses distribution; please put it in your home directotry"
|
|---|
| 145 | echo "and run me again (it does not have to live there permanently)."
|
|---|
| 146 | exit;
|
|---|
| 147 | ;;
|
|---|
| 148 | 1)
|
|---|
| 149 | echo "I see a file called $master."
|
|---|
| 150 | echo "I am going to assume this is the terminfo source included with"
|
|---|
| 151 | echo "the ncurses distribution. If this assumption is wrong, please"
|
|---|
| 152 | echo "interrupt me now! OK to continue?"
|
|---|
| 153 | read ans;
|
|---|
| 154 | ;;
|
|---|
| 155 | 2)
|
|---|
| 156 | echo "I see more than one possible terminfo source. Here they are:"
|
|---|
| 157 | echo $master | sed "/^/s// /";
|
|---|
| 158 | while :
|
|---|
| 159 | do
|
|---|
| 160 | echo "Please tell me which one to use:"
|
|---|
| 161 | read master;
|
|---|
| 162 | if test -f $master
|
|---|
| 163 | then
|
|---|
| 164 | break
|
|---|
| 165 | else
|
|---|
| 166 | echo "That file does not exist. Try again?";
|
|---|
| 167 | fi
|
|---|
| 168 | done
|
|---|
| 169 | ;;
|
|---|
| 170 | esac
|
|---|
| 171 | fi
|
|---|
| 172 | echo "";
|
|---|
| 173 |
|
|---|
| 174 | # Now that we have a master, compile it into the local tree
|
|---|
| 175 | echo "OK, now I will make your private terminfo tree. This may take a bit..."
|
|---|
| 176 | #
|
|---|
| 177 | # Kluge alert: we compile terminfo.src in two pieces because a lot of machines
|
|---|
| 178 | # with < 16MB RAM choke on tic's core-hog habits.
|
|---|
| 179 | trap "rm -f tsplit$$.*" 0 1 2 5 15
|
|---|
| 180 | sed -n $master \
|
|---|
| 181 | -e '1,/SPLIT HERE/w 'tsplit$$.01 \
|
|---|
| 182 | -e '/SPLIT HERE/,$w 'tsplit$$.02 \
|
|---|
| 183 | 2>/dev/null
|
|---|
| 184 | for x in tsplit$$.*; do eval $TIC $x; done
|
|---|
| 185 | rm tsplit$$.*
|
|---|
| 186 | trap 0 1 2 5 15
|
|---|
| 187 | #
|
|---|
| 188 | echo "You now have a private tree under $HOME/.terminfo;"
|
|---|
| 189 | echo "the ncurses library will automatically read from it,"
|
|---|
| 190 | echo "and ncurses tic will automatically compile entries to it."
|
|---|
| 191 |
|
|---|
| 192 | # We're done unless user has a .termcap file or equivalent named by TERMCAP
|
|---|
| 193 | if test -z "$TERMCAP"
|
|---|
| 194 | then
|
|---|
| 195 | echo "You have no TERMCAP set, so we are done."
|
|---|
| 196 | fi
|
|---|
| 197 |
|
|---|
| 198 | # OK, here comes the nasty case...user has a TERMCAP. Instead of
|
|---|
| 199 | # trying to follow all the convolutions of the relationship between
|
|---|
| 200 | # TERM and TERMCAP (partly because it's too painful, and partly because
|
|---|
| 201 | # we don't actually know what TERM will be nor even if it always has
|
|---|
| 202 | # the same value for this user) we do the following three steps...
|
|---|
| 203 |
|
|---|
| 204 | if test -f $HOME/.termcap
|
|---|
| 205 | then
|
|---|
| 206 | echo 'I see you have a $HOME/.termcap file. I will compile that.'
|
|---|
| 207 | eval $TIC $HOME/.termcap
|
|---|
| 208 | echo "Done."
|
|---|
| 209 | echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
|
|---|
| 210 | elif test -f "$TERMCAP"
|
|---|
| 211 | then
|
|---|
| 212 | echo "Your TERMCAP names the file $TERMCAP. I will compile that."
|
|---|
| 213 | eval $TIC $TERMCAP
|
|---|
| 214 | echo "Done."
|
|---|
| 215 | echo "Note that editing $TERMCAP will no longer change the data curses sees."
|
|---|
| 216 | else
|
|---|
| 217 | echo "Your TERMCAP value appears to be an entry in termcap format."
|
|---|
| 218 | echo "I will compile it."
|
|---|
| 219 | echo $TERMCAP >myterm$$
|
|---|
| 220 | eval $TIC myterm$$
|
|---|
| 221 | rm myterm$$
|
|---|
| 222 | echo "Done."
|
|---|
| 223 | echo "Note that editing TERMCAP will no longer change the data curses sees."
|
|---|
| 224 | fi
|
|---|
| 225 | echo "To do that, decompile the terminal decription you want with infocmp(1),"
|
|---|
| 226 | echo "edit to taste, and recompile using tic(1)."
|
|---|
| 227 |
|
|---|
| 228 | # capconvert ends here
|
|---|
| 229 |
|
|---|