home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / newinfo < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  2.1 KB  |  84 lines

  1. #!/bin/ksh
  2. # @(#) newinfo.ksh 1.0 93/04/06
  3. # 93/04/06 john h. dubois iii (john@armory.com)
  4. # newinfo: create a new terminfo description and run a program using it
  5.  
  6. name=${0##*/}
  7. usage="Usage: $name [-h] [-t<term>] capdef[,capdef...] [program [arg ...]]"
  8. help="$usage
  9. capdef is a string of one or more terminfo capability definitions, given
  10. as they would appear in a terminfo source file, e.g.:  'lines#24,kf0=\E[V,am'
  11. (the single quotes protect the backslash from stripping by the shell).
  12. If program is not given, the new terminfo source is left in
  13. \$HOME/.newinfo/source and the compiled source can be used by setting the
  14. TERMINFO environment variable to \$HOME/.newinfo.  If program is given,
  15. it is run using the new description; after the program exits, the terminfo
  16. data is removed.
  17. Options:
  18. -h: Print this help.
  19. -t<term>: Start with and modify the terminfo description of <term>.
  20.     The default is to start with and modify the value of the terminfo
  21.     descrption for \$TERM."
  22.  
  23. while getopts :ht: opt; do
  24.     case $opt in
  25.     h)  echo "$help"
  26.     exit 0;;
  27.     t) TERM=$OPTARG;;
  28.     +?) echo "$name: options should not be preceded by a '+'."; exit 1;;
  29.     :) 
  30.     print -r -u2 -- \
  31.     "$name: Option '$OPTARG' requires a value.  Use -h for help."
  32.     exit 1
  33.     ;;
  34.     ?) echo "$name: $OPTARG: bad option.  Use -h for help."; exit 1;;
  35.     esac
  36. done
  37.  
  38. # remove args that were options
  39. let OPTIND=OPTIND-1
  40. shift $OPTIND
  41.  
  42. if [ $# -lt 1 ]; then
  43.     echo "$usage"
  44.     exit
  45. fi
  46.  
  47. alias istrue="test 0 -ne"
  48. alias isfalse="test 0 -eq"
  49.  
  50. typeset -L1 termletter=$TERM
  51. TERMINFO=${TERMINFO:-/usr/lib/terminfo}
  52. tmpdir=$HOME/.newinfo
  53.  
  54. typeset -i dexisted=0 texisted=0
  55.  
  56. tmpfile=$tmpdir/source
  57. if [ -d $tmpdir ]; then
  58.     dexisted=1
  59. else
  60.     mkdir $tmpdir
  61.     [ ! -d $tmpdir/$termletter ] && mkdir $tmpdir/$termletter
  62. fi
  63. sourceterm=$tmpdir/$termletter/${TERM}_orig
  64. if [ -f $sourceterm ]; then
  65.     texisted=1
  66. else
  67.     cp $TERMINFO/$termletter/$TERM $sourceterm
  68. fi
  69.  
  70. echo -n "$TERM, $1, use=${TERM}_orig," > $tmpfile
  71. shift
  72.  
  73. export TERMINFO=$tmpdir
  74. tic $tmpfile
  75.  
  76. if [ $# -gt 0 ]; then
  77.     "$@"
  78.     if isfalse dexisted; then
  79.     rm -rf $tmpdir
  80.     else
  81.     isfalse texisted && rm $sourceterm
  82.     fi
  83. fi
  84.