1#!/bin/sh 2# Complete check of a stateless encoding. 3# Usage: check-stateless SRCDIR CHARSET 4srcdir="$1" 5charset="$2" 6set -e 7 8# charset, modified for use in filenames. 9charsetf=`echo "$charset" | sed -e 's,:,-,g'` 10 11# iconv in one direction. 12./table-from "$charset" > tmp-"$charsetf".TXT 13 14# iconv in the other direction. 15./table-to "$charset" | sort > tmp-"$charsetf".INVERSE.TXT 16 17# Check 1: charmap and iconv forward should be identical. 18cmp "${srcdir}"/"$charsetf".TXT tmp-"$charsetf".TXT 2> /dev/null 19 20# Check 2: the difference between the charmap and iconv backward. 21sed -e '/ .* 0x/d' < "${srcdir}"/"$charsetf".TXT > tmp-noprecomposed-"$charsetf".TXT 22if test -f "${srcdir}"/"$charsetf".IRREVERSIBLE.TXT; then 23 cat tmp-noprecomposed-"$charsetf".TXT "${srcdir}"/"$charsetf".IRREVERSIBLE.TXT | sort | uniq -u > tmp-orig-"$charsetf".INVERSE.TXT 24else 25 cp tmp-noprecomposed-"$charsetf".TXT tmp-orig-"$charsetf".INVERSE.TXT 26fi 27cmp tmp-orig-"$charsetf".INVERSE.TXT tmp-"$charsetf".INVERSE.TXT 2> /dev/null 28 29rm -f tmp-"$charsetf".TXT tmp-"$charsetf".INVERSE.TXT tmp-noprecomposed-"$charsetf".TXT tmp-orig-"$charsetf".INVERSE.TXT 30exit 0 31# For a new encoding: 32# You can create the "$charsetf".TXT like this: 33# ./table-from "$charset" > "$charsetf".TXT 34# You can create the "$charsetf".IRREVERSIBLE.TXT like this: 35# ./table-to "$charset" | sort > "$charsetf".INVERSE.TXT 36# diff "$charsetf".TXT "$charsetf".INVERSE.TXT | grep '^[<>]' | sed -e 's,^. ,,' > "$charsetf".IRREVERSIBLE.TXT 37