Home | History | Annotate | Download | only in util
      1 #! /bin/sh
      2 # Generate a terminfo command from a terminfo name.
      3 #
      4 # Copyright (C) 2002  Free Software Foundation, Inc.
      5 #
      6 # This file is free software; you can redistribute it and/or modify it
      7 # under the terms of the GNU General Public License as published by
      8 # the Free Software Foundation; either version 2 of the License, or
      9 # (at your option) any later version.
     10 #
     11 # This program is distributed in the hope that it will be useful, but
     12 # WITHOUT ANY WARRANTY; without even the implied warranty of
     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 # General Public License for more details.
     15 #
     16 # You should have received a copy of the GNU General Public License
     17 # along with this program; if not, write to the Free Software
     18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     19 
     20 VERSION=@VERSION@
     21 
     22 usage () {
     23     cat <<EOF
     24 Usage: grub-terminfo TERMNAME
     25 Generate a terminfo command from a terminfo name.
     26 
     27   -h, --help              print this message and exit
     28   -v, --version           print the version information and exit
     29 
     30 Report bugs to <bug-grub@gnu.org>.
     31 EOF
     32 }
     33 
     34 error () {
     35     echo "grub-terminfo: error: $1" 1>&2
     36 }
     37 
     38 termname=
     39 
     40 for option in "$@"; do
     41     case "$option" in
     42     -h | --help)
     43         usage
     44 	exit 0 ;;
     45     -v | --version)
     46 	echo "grub-terminfo (GNU GRUB ${VERSION})"
     47 	exit 0 ;;
     48     -*)
     49 	error "Unrecognized option \`$option'"
     50 	usage
     51 	exit 1 ;;
     52     *)
     53 	if test "x$termname" != x; then
     54 	    error "More than one terminfo names?"
     55 	    usage
     56 	    exit 1
     57 	fi
     58 	termname="$option" ;;
     59     esac
     60 done
     61 
     62 if test "x$termname" = x; then
     63     error "termname not specified"
     64     usage
     65     exit 1
     66 fi
     67 
     68 get_seq () {
     69     infocmp -L -1 -g $termname | sed -n -e "/$1/s/^[^=]*=\\(.*\\),\$/\\1/p"
     70 }
     71 
     72 cursor_address="`get_seq cursor_address`"
     73 if test "x$cursor_address" = x; then
     74     error "cursor_address not found"
     75     exit 1
     76 fi
     77 cursor_address="--cursor-address=$cursor_address"
     78 
     79 clear_screen="`get_seq clear_screen`"
     80 if test "x$clear_screen" != x; then
     81     clear_screen="--clear-screen=$clear_screen"
     82 fi
     83 
     84 enter_standout_mode="`get_seq enter_standout_mode`"
     85 if test "x$enter_standout_mode" != x; then
     86     enter_standout_mode="--enter-standout-mode=$enter_standout_mode"
     87 fi
     88 
     89 exit_standout_mode="`get_seq exit_standout_mode`"
     90 if test "x$exit_standout_mode" != x; then
     91     exit_standout_mode="--exit-standout-mode=$exit_standout_mode"
     92 fi
     93 
     94 echo "terminfo --name=$termname" $cursor_address $clear_screen \
     95     $enter_standout_mode $exit_standout_mode
     96