1 #! /bin/sh 2 3 # Test checking of awk format strings. 4 5 tmpfiles="" 6 trap 'rm -fr $tmpfiles' 1 2 3 15 7 8 tmpfiles="$tmpfiles f-a-2.data" 9 cat <<\EOF > f-a-2.data 10 # Valid: %% doesn't count 11 msgid "abc%%def" 12 msgstr "xyz" 13 # Invalid: invalid msgstr 14 msgid "abc%%def" 15 msgstr "xyz%" 16 # Valid: same arguments 17 msgid "abc%s%gdef" 18 msgstr "xyz%s%g" 19 # Valid: same arguments, with different widths 20 msgid "abc%2sdef" 21 msgstr "xyz%3s" 22 # Valid: same arguments but in numbered syntax 23 msgid "abc%s%gdef" 24 msgstr "xyz%1$s%2$g" 25 # Valid: permutation 26 msgid "abc%s%g%cdef" 27 msgstr "xyz%3$c%2$g%1$s" 28 # Invalid: too few arguments 29 msgid "abc%2$udef%1$s" 30 msgstr "xyz%1$s" 31 # Invalid: too few arguments 32 msgid "abc%sdef%u" 33 msgstr "xyz%s" 34 # Invalid: too many arguments 35 msgid "abc%udef" 36 msgstr "xyz%uvw%c" 37 # Valid: same numbered arguments, with different widths 38 msgid "abc%2$5s%1$4s" 39 msgstr "xyz%2$4s%1$5s" 40 # Invalid: missing argument 41 msgid "abc%2$sdef%1$u" 42 msgstr "xyz%1$u" 43 # Invalid: missing argument 44 msgid "abc%1$sdef%2$u" 45 msgstr "xyz%2$u" 46 # Invalid: added argument 47 msgid "abc%1$udef" 48 msgstr "xyz%1$uvw%2$c" 49 # Valid: type compatibility 50 msgid "abc%i" 51 msgstr "xyz%d" 52 # Valid: type compatibility 53 msgid "abc%o" 54 msgstr "xyz%u" 55 # Valid: type compatibility 56 msgid "abc%u" 57 msgstr "xyz%x" 58 # Valid: type compatibility 59 msgid "abc%u" 60 msgstr "xyz%X" 61 # Valid: type compatibility 62 msgid "abc%e" 63 msgstr "xyz%E" 64 # Valid: type compatibility 65 msgid "abc%e" 66 msgstr "xyz%f" 67 # Valid: type compatibility 68 msgid "abc%e" 69 msgstr "xyz%g" 70 # Valid: type compatibility 71 msgid "abc%e" 72 msgstr "xyz%G" 73 # Invalid: type incompatibility 74 msgid "abc%c" 75 msgstr "xyz%s" 76 # Invalid: type incompatibility 77 msgid "abc%c" 78 msgstr "xyz%i" 79 # Invalid: type incompatibility 80 msgid "abc%c" 81 msgstr "xyz%o" 82 # Invalid: type incompatibility 83 msgid "abc%c" 84 msgstr "xyz%e" 85 # Invalid: type incompatibility 86 msgid "abc%s" 87 msgstr "xyz%i" 88 # Invalid: type incompatibility 89 msgid "abc%s" 90 msgstr "xyz%o" 91 # Invalid: type incompatibility 92 msgid "abc%s" 93 msgstr "xyz%e" 94 # Invalid: type incompatibility 95 msgid "abc%i" 96 msgstr "xyz%o" 97 # Invalid: type incompatibility 98 msgid "abc%i" 99 msgstr "xyz%e" 100 # Invalid: type incompatibility 101 msgid "abc%u" 102 msgstr "xyz%e" 103 # Invalid: type incompatibility for width 104 msgid "abc%g%*g" 105 msgstr "xyz%*g%g" 106 EOF 107 108 : ${MSGFMT=msgfmt} 109 n=0 110 while read comment; do 111 read msgid_line 112 read msgstr_line 113 n=`expr $n + 1` 114 tmpfiles="$tmpfiles f-a-2-$n.po f-a-2-$n.mo" 115 cat <<EOF > f-a-2-$n.po 116 #, awk-format 117 ${msgid_line} 118 ${msgstr_line} 119 EOF 120 fail= 121 if echo "$comment" | grep 'Valid:' > /dev/null; then 122 if ${MSGFMT} --check-format -o f-a-2-$n.mo f-a-2-$n.po; then 123 : 124 else 125 fail=yes 126 fi 127 else 128 ${MSGFMT} --check-format -o f-a-2-$n.mo f-a-2-$n.po 2> /dev/null 129 if test $? = 1; then 130 : 131 else 132 fail=yes 133 fi 134 fi 135 if test -n "$fail"; then 136 echo "Format string checking error:" 1>&2 137 cat f-a-2-$n.po 1>&2 138 exit 1 139 fi 140 rm -f f-a-2-$n.po f-a-2-$n.mo 141 done < f-a-2.data 142 143 rm -fr $tmpfiles 144 145 exit 0 146