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