#! /bin/sh

map=true
script=LATIN
while	case "$1" in
	-c)	# count only
		map=false
		shift;;
	-s)	# script
		script=`echo $2 | tr 'a-z' 'A-Z'`
		shift
		shift;;
	-stat)	for script in arabic cyrillic greek hebrew latin
		do	./mnemos.determine -c -s $script lib/uwith.$script-accents |
			sort -nr > lib/uwith.$script-accents.n
		done
		exit;;
	*)	false;;
	esac
do	true
done

sed -e "s,	.*,," $* |
while read a
do
	if $map
	then
		echo --------------------------------------------------------------
		echo $a
		egrep "$script .* WITH $a;" UnicodeData.txt | wc -l

		tmp=/tmp/mnemos.$$
		egrep "$script .* WITH $a \*/" mnemos.??? > $tmp
		wc -l < $tmp
		sed -e "s,.*\(0x[0-9a-fA-F]*\).*,\1," $tmp | 
			tr 'a-f' 'A-F' | sort | uniq -d
		cat $tmp
		rm -f $tmp
	else	# count only
		echo `egrep "$script .* WITH $a;" UnicodeData.txt | wc -l`"	$a"
	fi
done
