#!/bin/sh
#
#	@(#)r.ttmapsdir 1.0 94/04/01 SMI;
#
# Copyright (c) 1994 by Sun Microsystems, Inc.
#

cat > /tmp/$$ttmaps.dir.delete  << EOF
gbk-0
Adobe-GB1-2
Adobe-GB1-4
gb18030.2000-0
gb18030.2000-1
EOF


while read dest
do

    for file in `cat /tmp/$$ttmaps.dir.delete`
    do

        if [ -f $dest ] ; then
             cat $dest | sed -e '1d' > /tmp/$$ttmaps.dir

        # get the line number correspond to ttmapfile ame
cat > /tmp/$$sed.scr << EOF
        /FROM-ENCODING $file/ {
                =
                }
EOF

        ttmap_line_s=`sed -n -f /tmp/$$sed.scr /tmp/$$ttmaps.dir`
        ttmap_line_e=`expr $ttmap_line_s + 2`
        #
        # Now delete the 3 lines starting from ttmap_line
        #

        echo "sed -e '$ttmap_line_s,$ttmap_line_e d' /tmp/$$ttmaps.dir > /tmp/$$ttmaps.dir.new" > /tmp/$$sed.scr.1

        sh /tmp/$$sed.scr.1
        #
        # count the remaining files left
        #
        count=`grep '^FILENAME' /tmp/$$ttmaps.dir.new | wc -l`
        if [ $count -eq 0 ]; then
             rm $dest
        else
             echo $count > $dest
             cat /tmp/$$ttmaps.dir.new >>  $dest
        fi

        fi
    done

        rm /tmp/$$ttmaps.dir /tmp/$$ttmaps.dir.delete /tmp/$$ttmaps.dir.new \
           /tmp/$$sed.scr.1  /tmp/$$sed.scr
done


exit 0
