#!/bin/sh

#	rtfchkmap - check RTF map against list of standard character names
#		to find:
#		- which names aren't represented
#		- which names are in the map that shouldn't be
#		- duplicate entries

#	Script type:	Bourne shell

#	This works for charset maps.  It also works for output maps for
#	translators if they use the same format as the charset maps (standard
#	character name in first field, comments specified with # in column 1).

#	Need to implement -d, -i, -m flags.

#	08 Sep 93	Paul DuBois	dubois@primate.wisc.edu

#	08 Sep 93 Created.

dodups=y
doillegal=y
domissing=y

stdnames=/usr/pkg/lib/rtf-tools/standard-names
tmpa=/tmp/tmc$$a
tmpb=/tmp/tmc$$b
tmpc=/tmp/tmc$$c

if [ $# -ne 1 ]; then
	echo "Usage: $0 map-file" 1>&2
	exit 1
fi

mapfile=$1

if [ ! -r $stdnames ]; then
	echo "Cannot find list of standard names ($stdnames)" 1>&2
	exit 1
fi

# strip out the name lists from the standard list and the map file

sed -e '/^$/d' -e '/^#/d' -e 's/	.*//' $stdnames | sort > $tmpa
sed -e '/^$/d' -e '/^#/d' -e 's/	.*//' $mapfile | sort > $tmpb

# find duplicate entries in map

if [ "$dodups" = "y" ]; then
uniq -d $tmpb > $tmpc
if [ -s $tmpc ]; then
	echo "There are duplicate entries for the following names in $mapfile:"
	$(CAT) $tmpc
	echo ""
fi
rm -f $tmpc
fi
sort -u $tmpb -o $tmpb

# first find names in standard list that aren't represented in the map file

if [ "$doillegal" = "y" ]; then
comm -23 $tmpa $tmpb > $tmpc
if [ -s $tmpc ]; then
	echo "Entries for following names are missing from $mapfile:"
	$(CAT) $tmpc
	echo ""
fi
rm -f $tmpc
fi

# find names in map file that aren't in the standard list

if [ "$doillegal" = "y" ]; then
comm -13 $tmpa $tmpb > $tmpc
if [ -s $tmpc ]; then
	echo "$mapfile contains entries for the following nonstandard names:"
	$(CAT) $tmpc
	echo ""
fi
rm -f $tmpc
fi

rm -f $tmpa $tmpb
