]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/capconvert
ncurses 5.7 - patch 20091121
[ncurses.git] / progs / capconvert
index 0a3ea5d560b252ced54a57862f075b8220dc26c5..8199bbf09b7efc2292e9f78ffe8f1d81eb06c08b 100755 (executable)
@@ -1,4 +1,32 @@
-#! /bin/sh
+#!/bin/sh
+##############################################################################
+# Copyright (c) 1998,2006 Free Software Foundation, Inc.                     #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation  #
+# the rights to use, copy, modify, merge, publish, distribute, distribute    #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the  #
+# following conditions:                                                      #
+#                                                                            #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software.                        #
+#                                                                            #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
+# DEALINGS IN THE SOFTWARE.                                                  #
+#                                                                            #
+# Except as contained in this notice, the name(s) of the above copyright     #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written               #
+# authorization.                                                             #
+##############################################################################
+# $Id: capconvert,v 1.4 2006/04/22 21:46:17 tom Exp $
 #
 # capconvert -- automated conversion from termcap to terminfo
 #
 #
 # capconvert -- automated conversion from termcap to terminfo
 #
@@ -13,57 +41,93 @@ echo ""
 # case they're on a workstation and probably don't.
 
 # Check to make sure TERMINFO is not already defined
 # case they're on a workstation and probably don't.
 
 # Check to make sure TERMINFO is not already defined
-if [ "$TERMINFO" ]
+if test -n "$TERMINFO"
 then
        echo "TERMINFO is already defined in your environment.  This means"
        echo "you already have a local terminfo tree, so you do not need any"
        echo "conversion."
 then
        echo "TERMINFO is already defined in your environment.  This means"
        echo "you already have a local terminfo tree, so you do not need any"
        echo "conversion."
+       if test ! -d $TERMINFO ; then
+               echo "Caution: TERMINFO does not point to a directory!"
+       fi
        exit;
 fi
 
        exit;
 fi
 
-# Check to see if terminfo is present.
-if [ -d /usr/lib/terminfo -o -d /usr/local/lib/terminfo ]
+# Check to see if terminfo is present in one of the standard locations.
+terminfo=no
+for p in $TERMINFO \
+       /usr/lib/terminfo \
+       /usr/share/lib/terminfo \
+       /usr/share/terminfo \
+       /usr/local/lib/terminfo \
+       /usr/local/share/terminfo
+do
+       if test -d $p ; then
+               terminfo=yes
+               break
+       fi
+done
+
+if test $terminfo = yes
 then
        echo "Your system already has a system-wide terminfo tree."
 then
        echo "Your system already has a system-wide terminfo tree."
-       terminfo=yes
        echo ""
        echo ""
-       if [ "$TERMCAP" = "" ]
+       if test -z "$TERMCAP"
        then
        then
-               echo "You have no TERMCAP variable set, so we're done."
+               echo "You have no TERMCAP variable set, so we are done."
                # Assumes the terminfo master covers all canned terminal types
                exit;
        fi
                # Assumes the terminfo master covers all canned terminal types
                exit;
        fi
-       if [ "$TERM" = "xterm" ]
+       if test "$TERM" = "xterm"
        then
        then
-               echo "You're running xterm, which rudely sets TERMCAP itself."
+               echo "You are running xterm, which usually sets TERMCAP itself."
                echo "We can ignore this, because terminfo knows about xterm."
                echo "We can ignore this, because terminfo knows about xterm."
-               echo "So you'll just use the system-wide terminfo tree."
+               echo "So you will just use the system-wide terminfo tree."
                exit;
        else
                exit;
        else
-               echo "We'll have to make a local one for you anyway, in order"
-               echo "to capture the effect of your TERMCAP variable."
+               echo "We will have to make a local one for you anyway, to capture the effect"
+               echo "of your TERMCAP variable."
        fi
 else
        fi
 else
-       echo "No system-wide terminfo tree.  We'll make you a local one."
-       terminfo=no
+       echo "No system-wide terminfo tree.  We will make you a local one."
 fi
 echo "";
 
 fi
 echo "";
 
+# Check if test -x works (it's not portable, but useful)
+OPT="-x"
+TMP=test$$; touch $TMP && chmod 755 $TMP
+if test $OPT $TMP ; then
+       chmod 644 $TMP
+       test $OPT $TMP && OPT="-f"
+else
+       OPT="-f"
+fi
+rm -f $TMP
 
 # First step -- go find tic
 
 # First step -- go find tic
-set -- `echo $PATH | tr ':' '\n' | sort | uniq`
-for x in $*
+TIC=
+IFS="${IFS=    }"; save_ifs="$IFS"; IFS="${IFS}:"
+for x in $PATH .
 do
 do
-       if [ -x $x/tic ]
+       if test $OPT $x/tic
        then 
        then 
-               tic=$x/tic
-       fi;
+               TIC=$x/tic
+               break
+       fi
 done
 done
-if [ "$tic" ]
+IFS="$ac_save_ifs"
+
+if test -n "$TIC"
 then
 then
-       echo "I see tic at $tic."
+       echo "I see tic at $TIC."
+       case $TIC in # (vi
+       ./tic)
+               if test $OPT ../misc/shlib ; then
+                       TIC="../misc/shlib $TIC"
+               fi
+               ;;
+       esac
 else
 else
-       echo "You don't have tic installed anywhere I can see, please fix that."
+       echo "You do not have tic installed anywhere I can see, please fix that."
        exit;
 fi
 echo "";
        exit;
 fi
 echo "";
@@ -73,16 +137,16 @@ echo "";
 #
 
 # Make the user a terminfo directory
 #
 
 # Make the user a terminfo directory
-if [ -d $HOME/.terminfo ]
+if test -d $HOME/.terminfo
 then
        echo "It appears you already have a private terminfo directory"
        echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
 then
        echo "It appears you already have a private terminfo directory"
        echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
-       echo "is not defined.  I'm not going to second-guess this -- if you" 
+       echo "is not defined.  I am not going to second-guess this -- if you" 
        echo "really want me to try auto-configuring for you, remove or"
        echo "rename $HOME/terminfo and run me again."
        exit;
 else
        echo "really want me to try auto-configuring for you, remove or"
        echo "rename $HOME/terminfo and run me again."
        exit;
 else
-       echo "I'm creating your private terminfo directory at $HOME/.terminfo"
+       echo "I am creating your private terminfo directory at $HOME/.terminfo"
        mkdir $HOME/.terminfo
        # Ensure that that's where tic's compilation results.
        # This isn't strictly necessary with a 1.9.7 or later tic.
        mkdir $HOME/.terminfo
        # Ensure that that's where tic's compilation results.
        # This isn't strictly necessary with a 1.9.7 or later tic.
@@ -91,9 +155,9 @@ fi
 echo "";
 
 # Find a terminfo source to work from
 echo "";
 
 # Find a terminfo source to work from
-if [ -f ../misc/terminfo.src ]
+if test -f ../misc/terminfo.src
 then
 then
-       echo "I see the terminfo master source is handy; I'll use that."
+       echo "I see the terminfo master source is handy; I will use that."
        master=../misc/terminfo.src
 else
        # Ooops...looks like we're running from somewhere other than the
        master=../misc/terminfo.src
 else
        # Ooops...looks like we're running from somewhere other than the
@@ -102,15 +166,15 @@ else
        mcount=`echo $master | wc -l`
        case $mcount in
        0)
        mcount=`echo $master | wc -l`
        case $mcount in
        0)
-               echo "I can't find a terminfo source file anywhere under your home directory."
+               echo "I can not find a terminfo source file anywhere under your home directory."
                echo "There should be a file called terminfo.src somewhere in your"
                echo "ncurses distribution; please put it in your home directotry"
                echo "There should be a file called terminfo.src somewhere in your"
                echo "ncurses distribution; please put it in your home directotry"
-               echo "and run me again (it doesn't have to live there permanently)."
+               echo "and run me again (it does not have to live there permanently)."
                exit;
        ;;
        1)
                echo "I see a file called $master."
                exit;
        ;;
        1)
                echo "I see a file called $master."
-               echo "I'm going to assume this is the terminfo source included with"
+               echo "I am going to assume this is the terminfo source included with"
                echo "the ncurses distribution.  If this assumption is wrong, please"
                echo "interrupt me now!  OK to continue?"
                read ans;
                echo "the ncurses distribution.  If this assumption is wrong, please"
                echo "interrupt me now!  OK to continue?"
                read ans;
@@ -122,11 +186,11 @@ else
                do
                        echo "Please tell me which one to use:"
                        read master;
                do
                        echo "Please tell me which one to use:"
                        read master;
-                       if [ -f $master ]
+                       if test -f $master
                        then
                                break
                        else
                        then
                                break
                        else
-                               echo "That file doesn't exist. Try again?";
+                               echo "That file does not exist. Try again?";
                        fi
                done
        ;;
                        fi
                done
        ;;
@@ -135,25 +199,27 @@ fi
 echo "";
 
 # Now that we have a master, compile it into the local tree
 echo "";
 
 # Now that we have a master, compile it into the local tree
-echo "OK, now I'll make your private terminfo tree.  This may take a bit..."
+echo "OK, now I will make your private terminfo tree.  This may take a bit..."
 #
 # Kluge alert: we compile terminfo.src in two pieces because a lot of machines
 # with < 16MB RAM choke on tic's core-hog habits.
 #
 # Kluge alert: we compile terminfo.src in two pieces because a lot of machines
 # with < 16MB RAM choke on tic's core-hog habits.
+trap "rm -f tsplit$$.*" 0 1 2 5 15
 sed -n $master \
 sed -n $master \
-       -e '1,/SPLIT HERE/w tsplit$$.01' \
-       -e '/SPLIT HERE/,$w tsplit$$.02' \
+       -e '1,/SPLIT HERE/w 'tsplit$$.01 \
+       -e '/SPLIT HERE/,$w 'tsplit$$.02 \
        2>/dev/null
        2>/dev/null
-for x in tsplit$$.*; do $tic -v $x; done
+for x in tsplit$$.*; do eval $TIC $x; done
 rm tsplit$$.*
 rm tsplit$$.*
+trap 0 1 2 5 15
 #
 echo "You now have a private tree under $HOME/.terminfo;"
 echo "the ncurses library will automatically read from it,"
 echo "and ncurses tic will automatically compile entries to it." 
 
 # We're done unless user has a .termcap file or equivalent named by TERMCAP
 #
 echo "You now have a private tree under $HOME/.terminfo;"
 echo "the ncurses library will automatically read from it,"
 echo "and ncurses tic will automatically compile entries to it." 
 
 # We're done unless user has a .termcap file or equivalent named by TERMCAP
-if [ "$TERMCAP" = "" ]
+if test -z "$TERMCAP"
 then
 then
-       echo "You have no TERMCAP set, so we're done."
+       echo "You have no TERMCAP set, so we are done."
 fi
 
 # OK, here comes the nasty case...user has a TERMCAP.  Instead of
 fi
 
 # OK, here comes the nasty case...user has a TERMCAP.  Instead of
@@ -162,27 +228,27 @@ fi
 # we don't actually know what TERM will be nor even if it always has
 # the same value for this user) we do the following three steps...
 
 # we don't actually know what TERM will be nor even if it always has
 # the same value for this user) we do the following three steps...
 
-if [ -f $HOME/.termcap ]
+if test -f $HOME/.termcap
 then
 then
-       echo 'I see you have a $HOME/.termcap file.  I'll compile that.'
-       $tic $HOME/.termcap
+       echo 'I see you have a $HOME/.termcap file.  I will compile that.'
+       eval $TIC $HOME/.termcap
        echo "Done."
        echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
        echo "Done."
        echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
-else if `expr $TERMCAP : "/"` = '1'
+elif test -f "$TERMCAP"
 then 
 then 
-       echo "Your TERMCAP names the file $TERMCAP.  I'll compile that."
-       $tic $TERMCAP
+       echo "Your TERMCAP names the file $TERMCAP.  I will compile that."
+       eval $TIC $TERMCAP
        echo "Done."
        echo "Note that editing $TERMCAP will no longer change the data curses sees."
 else
        echo "Your TERMCAP value appears to be an entry in termcap format."
        echo "Done."
        echo "Note that editing $TERMCAP will no longer change the data curses sees."
 else
        echo "Your TERMCAP value appears to be an entry in termcap format."
-       echo "I'll compile it."
+       echo "I will compile it."
        echo $TERMCAP >myterm$$
        echo $TERMCAP >myterm$$
-       $tic myterm$$
+       eval $TIC myterm$$
        rm myterm$$
        echo "Done."
        echo "Note that editing TERMCAP will no longer change the data curses sees."
        rm myterm$$
        echo "Done."
        echo "Note that editing TERMCAP will no longer change the data curses sees."
-fi fi
+fi
 echo "To do that, decompile the terminal decription you want with infocmp(1),"
 echo "edit to taste, and recompile using tic(1)."
 
 echo "To do that, decompile the terminal decription you want with infocmp(1),"
 echo "edit to taste, and recompile using tic(1)."