capconvert 8.6 KB

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