17c478bd9Sstevel@tonic-gate#! /bin/sh
27c478bd9Sstevel@tonic-gate# Generate a terminfo command from a terminfo name.
37c478bd9Sstevel@tonic-gate#
47c478bd9Sstevel@tonic-gate# Copyright (C) 2002  Free Software Foundation, Inc.
57c478bd9Sstevel@tonic-gate#
67c478bd9Sstevel@tonic-gate# This file is free software; you can redistribute it and/or modify it
77c478bd9Sstevel@tonic-gate# under the terms of the GNU General Public License as published by
87c478bd9Sstevel@tonic-gate# the Free Software Foundation; either version 2 of the License, or
97c478bd9Sstevel@tonic-gate# (at your option) any later version.
107c478bd9Sstevel@tonic-gate#
117c478bd9Sstevel@tonic-gate# This program is distributed in the hope that it will be useful, but
127c478bd9Sstevel@tonic-gate# WITHOUT ANY WARRANTY; without even the implied warranty of
137c478bd9Sstevel@tonic-gate# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147c478bd9Sstevel@tonic-gate# General Public License for more details.
157c478bd9Sstevel@tonic-gate#
167c478bd9Sstevel@tonic-gate# You should have received a copy of the GNU General Public License
177c478bd9Sstevel@tonic-gate# along with this program; if not, write to the Free Software
187c478bd9Sstevel@tonic-gate# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
197c478bd9Sstevel@tonic-gate
207c478bd9Sstevel@tonic-gateVERSION=@VERSION@
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gateusage () {
237c478bd9Sstevel@tonic-gate    cat <<EOF
247c478bd9Sstevel@tonic-gateUsage: grub-terminfo TERMNAME
257c478bd9Sstevel@tonic-gateGenerate a terminfo command from a terminfo name.
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate  -h, --help              print this message and exit
287c478bd9Sstevel@tonic-gate  -v, --version           print the version information and exit
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gateReport bugs to <bug-grub@gnu.org>.
317c478bd9Sstevel@tonic-gateEOF
327c478bd9Sstevel@tonic-gate}
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gateerror () {
357c478bd9Sstevel@tonic-gate    echo "grub-terminfo: error: $1" 1>&2
367c478bd9Sstevel@tonic-gate}
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gatetermname=
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gatefor option in "$@"; do
417c478bd9Sstevel@tonic-gate    case "$option" in
427c478bd9Sstevel@tonic-gate    -h | --help)
437c478bd9Sstevel@tonic-gate        usage
447c478bd9Sstevel@tonic-gate	exit 0 ;;
457c478bd9Sstevel@tonic-gate    -v | --version)
467c478bd9Sstevel@tonic-gate	echo "grub-terminfo (GNU GRUB ${VERSION})"
477c478bd9Sstevel@tonic-gate	exit 0 ;;
487c478bd9Sstevel@tonic-gate    -*)
497c478bd9Sstevel@tonic-gate	error "Unrecognized option \`$option'"
507c478bd9Sstevel@tonic-gate	usage
517c478bd9Sstevel@tonic-gate	exit 1 ;;
527c478bd9Sstevel@tonic-gate    *)
537c478bd9Sstevel@tonic-gate	if test "x$termname" != x; then
547c478bd9Sstevel@tonic-gate	    error "More than one terminfo names?"
557c478bd9Sstevel@tonic-gate	    usage
567c478bd9Sstevel@tonic-gate	    exit 1
577c478bd9Sstevel@tonic-gate	fi
587c478bd9Sstevel@tonic-gate	termname="$option" ;;
597c478bd9Sstevel@tonic-gate    esac
607c478bd9Sstevel@tonic-gatedone
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gateif test "x$termname" = x; then
637c478bd9Sstevel@tonic-gate    error "termname not specified"
647c478bd9Sstevel@tonic-gate    usage
657c478bd9Sstevel@tonic-gate    exit 1
667c478bd9Sstevel@tonic-gatefi
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gateget_seq () {
697c478bd9Sstevel@tonic-gate    infocmp -L -1 -g $termname | sed -n -e "/$1/s/^[^=]*=\\(.*\\),\$/\\1/p"
707c478bd9Sstevel@tonic-gate}
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gatecursor_address="`get_seq cursor_address`"
737c478bd9Sstevel@tonic-gateif test "x$cursor_address" = x; then
747c478bd9Sstevel@tonic-gate    error "cursor_address not found"
757c478bd9Sstevel@tonic-gate    exit 1
767c478bd9Sstevel@tonic-gatefi
777c478bd9Sstevel@tonic-gatecursor_address="--cursor-address=$cursor_address"
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gateclear_screen="`get_seq clear_screen`"
807c478bd9Sstevel@tonic-gateif test "x$clear_screen" != x; then
817c478bd9Sstevel@tonic-gate    clear_screen="--clear-screen=$clear_screen"
827c478bd9Sstevel@tonic-gatefi
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gateenter_standout_mode="`get_seq enter_standout_mode`"
857c478bd9Sstevel@tonic-gateif test "x$enter_standout_mode" != x; then
867c478bd9Sstevel@tonic-gate    enter_standout_mode="--enter-standout-mode=$enter_standout_mode"
877c478bd9Sstevel@tonic-gatefi
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gateexit_standout_mode="`get_seq exit_standout_mode`"
907c478bd9Sstevel@tonic-gateif test "x$exit_standout_mode" != x; then
917c478bd9Sstevel@tonic-gate    exit_standout_mode="--exit-standout-mode=$exit_standout_mode"
927c478bd9Sstevel@tonic-gatefi
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gateecho "terminfo --name=$termname" $cursor_address $clear_screen \
957c478bd9Sstevel@tonic-gate    $enter_standout_mode $exit_standout_mode
96