1 1.1 christos #! /bin/sh 2 1.1 christos 3 1.1 christos # Test checking of Shell format strings. 4 1.1 christos 5 1.1 christos tmpfiles="" 6 1.1 christos trap 'rm -fr $tmpfiles' 1 2 3 15 7 1.1 christos 8 1.1 christos tmpfiles="$tmpfiles f-sh-2.data" 9 1.1 christos cat <<\EOF > f-sh-2.data 10 1.1 christos # Invalid: invalid msgstr 11 1.1 christos msgid "abc$file" 12 1.1 christos msgstr "xyz$file$" 13 1.1 christos # Valid: same arguments, permutation 14 1.1 christos msgid "abc$file in $dir" 15 1.1 christos msgstr "xyz$dir o $file" 16 1.1 christos # Invalid: missing argument 17 1.1 christos msgid "abc$dir/$file" 18 1.1 christos msgstr "xyz$file" 19 1.1 christos # Invalid: added argument 20 1.1 christos msgid "abc$file" 21 1.1 christos msgstr "xyz$file in $dir" 22 1.1 christos # Valid: braces or not, doesn't matter 23 1.1 christos msgid "abc$file" 24 1.1 christos msgstr "xyz${file}" 25 1.1 christos # Invalid: different default value 26 1.1 christos msgid "abc$file" 27 1.1 christos msgstr "xyz${file-/tmpdir}" 28 1.1 christos EOF 29 1.1 christos 30 1.1 christos : ${MSGFMT=msgfmt} 31 1.1 christos n=0 32 1.1 christos while read comment; do 33 1.1 christos read msgid_line 34 1.1 christos read msgstr_line 35 1.1 christos n=`expr $n + 1` 36 1.1 christos tmpfiles="$tmpfiles f-sh-2-$n.po f-sh-2-$n.mo" 37 1.1 christos cat <<EOF > f-sh-2-$n.po 38 1.1 christos #, sh-format 39 1.1 christos ${msgid_line} 40 1.1 christos ${msgstr_line} 41 1.1 christos EOF 42 1.1 christos fail= 43 1.1 christos if echo "$comment" | grep 'Valid:' > /dev/null; then 44 1.1 christos if ${MSGFMT} --check-format -o f-sh-2-$n.mo f-sh-2-$n.po; then 45 1.1 christos : 46 1.1 christos else 47 1.1 christos fail=yes 48 1.1 christos fi 49 1.1 christos else 50 1.1 christos ${MSGFMT} --check-format -o f-sh-2-$n.mo f-sh-2-$n.po 2> /dev/null 51 1.1 christos if test $? = 1; then 52 1.1 christos : 53 1.1 christos else 54 1.1 christos fail=yes 55 1.1 christos fi 56 1.1 christos fi 57 1.1 christos if test -n "$fail"; then 58 1.1 christos echo "Format string checking error:" 1>&2 59 1.1 christos cat f-sh-2-$n.po 1>&2 60 1.1 christos exit 1 61 1.1 christos fi 62 1.1 christos rm -f f-sh-2-$n.po f-sh-2-$n.mo 63 1.1 christos done < f-sh-2.data 64 1.1 christos 65 1.1 christos rm -fr $tmpfiles 66 1.1 christos 67 1.1 christos exit 0 68