auto
  #   ˆl–Ü4ý(ÔÔD¨ JWÀLZ7ÿÀ„,´×ÄÃ 4     #!/usr/bin/sh

font_map=/usr/share/libwmf/fonts/fontmap
font_dir=

echo_help=no

while test $# -gt 0; do
	case "$1" in
	-*=*) optarg=$(echo "$1" | sed 's/[-_a-zA-Z0-9]*=//') ;;
	*)    optarg= ;;
	esac

	case $1 in
	--help)  echo_help=yes ;;
	--map=*)
		font_map=$optarg
	;;
	*)
		if test "x$font_dir" = "x"; then
			font_dir=$1
		else
			font_dir="$font_dir $1"
		fi
	;;
	esac

	shift
done

if test "x$font_map" = "x"; then
	echo_help=yes
fi

if test "x$font_dir" = "x"; then
	font_dir="/usr/share/libwmf/fonts"
else
	font_dir="$font_dir /usr/share/libwmf/fonts"
fi

if test $echo_help = yes; then
	cat <<EOF
Usage: libwmf-fontmap --map=<fontmap> dir1 [dir2 [dir3 ...]]
EOF
	exit "$1"
fi

echo font map = $font_map

font_pwd=$(pwd)

if test -w $font_map; then
	rm -f $font_map
fi

cat > $font_map <<EOF
<?xml version="1.0"?>
<fontmap>
EOF

for i in $font_dir; do
	if test -d "$i"; then
		cd "$i" || continue
		font_cwd=$(pwd)
		echo scanning "$i"

		for j in *.afm; do
			[ -e "$j" ] || continue
			font_root=$(echo "$j" | sed s/.afm//)
			font_metrics=$font_cwd/$font_root.afm
			font_glyphs=
			if test -r "$font_cwd/$font_root.pfa"; then
				font_glyphs="$font_cwd/$font_root.pfa"
			elif test -r "$font_cwd/$font_root.pfb"; then
				font_glyphs="$font_cwd/$font_root.pfb"
			elif test -r "$font_cwd/$font_root.t1"; then
				font_glyphs="$font_cwd/$font_root.t1"
			fi
			if test "x$font_glyphs" != "x"; then
				echo font: "$font_root"
				FontName=$(grep "FontName " "$font_metrics" | sed "s/FontName //")
				FullName=$(grep "FullName " "$font_metrics" | sed "s/FullName //")
				FamilyName=$(grep "FamilyName " "$font_metrics" | sed "s/FamilyName //")
				Weight=$(grep "Weight " "$font_metrics" | sed "s/Weight //")
				cd "$font_pwd" || continue
				echo '<font format="type1" metrics="'"$font_metrics"'" glyphs="'"$font_glyphs"'" name="'"$FontName"'" fullname="'"$FullName"'" familyname="'"$FamilyName"'" weight="'"$Weight"'" version="0.1" alias="'"$FontName"'"/>' >> $font_map
				cd "$font_cwd" || continue
			fi
		done

		for j in *.ttf; do
			[ -e "$j" ] || continue
			font_root=$(echo "$j" | sed s/.ttf//)
			font_recognized=yes
			font_glyphs=$font_cwd/$font_root.ttf
			case "$font_root" in
				antquab)
				FontName="BookAntiqua-Bold"
				FullName="Book Antiqua Bold"
				FamilyName="Book Antiqua"
				Weight="Bold"
				;;
				antquabi)
				FontName="BookAntiqua-BoldItalic"
				FullName="Book Antiqua Bold Italic"
				FamilyName="Book Antiqua"
				Weight="Bold Italic"
				;;
				antquai)
				FontName="BookAntiqua-Italic"
				FullName="Book Antiqua Italic"
				FamilyName="Book Antiqua"
				Weight="Italic"
				;;
				arbli___)
				FontName="Arial-BlackItalic"
				FullName="Arial Black Italic"
				FamilyName="Arial Black"
				Weight="Italic"
				;;
				arial)
				FontName="ArialMT"
				FullName="Arial"
				FamilyName="Arial"
				Weight="Regular"
				;;
				arialbd)
				FontName="Arial-BoldMT"
				FullName="Arial Bold"
				FamilyName="Arial"
				Weight="Bold"
				;;
				arialbi)
				FontName="Arial-BoldItalicMT"
				FullName="Arial Bold Italic"
				FamilyName="Arial"
				Weight="Bold Italic"
				;;
				ariali)
				FontName="Arial-ItalicMT"
				FullName="Arial Italic"
				FamilyName="Arial"
				Weight="Italic"
				;;
				arialn)
				FontName="ArialNarrow"
				FullName="Arial Narrow"
				FamilyName="Arial Narrow"
				Weight="Regular"
				;;
				arialnb)
				FontName="ArialNarrow-Bold"
				FullName="Arial Narrow Bold"
				FamilyName="Arial Narrow"
				Weight="Bold"
				;;
				arialnbi)
				FontName="ArialNarrow-BoldItalic"
				FullName="Arial Narrow Bold Italic"
				FamilyName="Arial Narrow"
				Weight="Bold Italic"
				;;
				arialni)
				FontName="ArialNarrow-Italic"
				FullName="Arial Narrow Italic"
				FamilyName="Arial Narrow"
				Weight="Italic"
				;;
				arialuni)
				FontName="ArialUnicodeMS"
				FullName="Arial Unicode MS"
				FamilyName="Arial Unicode MS"
				Weight="Regular"
				;;
				ariblk)
				FontName="Arial-Black"
				FullName="Arial Black"
				FamilyName="Arial Black"
				We