# $Header: /data/cvsroot/mail/elmme+/ConfTool/GenTerminalinfo,v 1.5 2003/09/05 19:31:30 hurtta Exp $

    if $test $new = y ; then
	   cat >bin/elm.terminalinfo <<'EOM'
# This file gives terminal specific methods for switching of chartset
#        of terminal. On file there may be following kind lines:
# 
#        term    ISO-2022        charset-name
#        term    ISO-2022        charset-definition
#        term    ISO-2022/DW        charset-name
#        term    PRIVATE         charset-name    d/d d/d d/d
#        term    PRIVATE         charset-name    [ condition ] d/d d/d d/d
# 
# 
#        where term is type of terminal (ie value of $TERM).               
#        ISO-2022 is literal, which indicates that
#        next column is character set name or character set
#        definition as on elm.mimecharsets or mime.charsets file
#        and that character set switching happends as given with
#        other-set and bank-Gx-* attributes on charcter set
#        definition. PRIVATE literal, which indicates that
#        next two columns are charatter set name and bytes given
#        on d/d format for switch character set.
# 
#        ISO-2022/DW literal indicates that terminal uses
#        same attributes than on case ISO2022 literal.
#        Additionally that says that 94x94 and 96x96 sets
#        consume two character positions on display with that
#        terminal. That literal is available only with charset
#        which have type=iso2022.
#         [ condition ] is like  [ exp = exp ] where exp can be
#        either "quoted value" or $ENV_VAR. "quoted value" allow
#        also environment variables (same way than Elm ME+ allows
#        on pathnames.)  For example that may be used on lines like
# 
#                linux   PRIVATE ISO-8859-15     [ $SYSFONTACM="iso15" ] 1/11 2/8 4/11 0/15
#                                                                     
EOM
	$echo "* Copying content of doc/terminal.info"
	cat doc/terminal.info >> bin/elm.terminalinfo

    else
	printit='$echo "* Adding terminal definations from doc/terminal.info"; printit='
	termname=''

	while read terminal type set rest ; do
	    case "$terminal" in
		\#*)
		   if $test "$termname" != ""; then 
		       echo "$terminal $type $set $rest" >> bin/elm.terminalinfo
		   fi
		   ;;
		 "")
		    termname=
		    ;;
                 *)
		    if $test "$terminal" = "$termname" ; then
			echo "$terminal	$type $set $rest" >> bin/elm.terminalinfo
		    else 
			file=bin/elm.terminalinfo
			first="$terminal"
			. ConfTool/GrepValue

			if $test "$result" = "" ; then
			    eval "$printit"
			    $echo "  Adding $terminal"
			    termname="$terminal"
			    echo "" >> bin/elm.terminalinfo
			    echo "# -- $terminal" >> bin/elm.terminalinfo
			    echo "$terminal $type $set $rest" >> bin/elm.terminalinfo
			else
			    termname=
			    case "$type" in
				"ISO-2022/DW"|ISO-2022|PRIVATE|FLAG|ISO-2022-LIKE)
				    # Does not work completely correctly
				    if $fgrep "$terminal" bin/elm.terminalinfo | \
 $fgrep "$set" > /dev/null ;
				    then
					:
				    else 
					eval "$printit"
					$echo "  Adding $set to $terminal"
					echo "# " >> bin/elm.terminalinfo
					echo "$terminal $type $set $rest" >> bin/elm.terminalinfo

				    fi					 
				;;
			    esac

			fi
		    fi
	       ;;
	    esac
	done < doc/terminal.info
    fi

