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