1#! /bin/sh 2 3# Test checking of C format strings. 4 5tmpfiles="" 6trap 'rm -fr $tmpfiles' 1 2 3 15 7 8tmpfiles="$tmpfiles f-c-2.data" 9cat <<\EOF > f-c-2.data 10# Valid: %% doesn't count 11msgid "abc%%def" 12msgstr "xyz" 13# Invalid: invalid msgstr 14msgid "abc%%def" 15msgstr "xyz%" 16# Valid: same arguments 17msgid "abc%s%gdef" 18msgstr "xyz%s%g" 19# Valid: same arguments, with different widths 20msgid "abc%2sdef" 21msgstr "xyz%3s" 22# Valid: same arguments but in numbered syntax 23msgid "abc%s%gdef" 24msgstr "xyz%1$s%2$g" 25# Valid: permutation 26msgid "abc%s%g%cdef" 27msgstr "xyz%3$c%2$g%1$s" 28# Invalid: too few arguments 29msgid "abc%2$udef%1$s" 30msgstr "xyz%1$s" 31# Invalid: too few arguments 32msgid "abc%sdef%u" 33msgstr "xyz%s" 34# Invalid: too many arguments 35msgid "abc%udef" 36msgstr "xyz%uvw%c" 37# Valid: same numbered arguments, with different widths 38msgid "abc%2$5s%1$4s" 39msgstr "xyz%2$4s%1$5s" 40# Invalid: missing argument 41msgid "abc%2$sdef%1$u" 42msgstr "xyz%1$u" 43# Invalid: missing argument 44msgid "abc%1$sdef%2$u" 45msgstr "xyz%2$u" 46# Invalid: added argument 47msgid "abc%1$udef" 48msgstr "xyz%1$uvw%2$c" 49# Valid: type compatibility 50msgid "abc%i" 51msgstr "xyz%d" 52# Valid: type compatibility 53msgid "abc%o" 54msgstr "xyz%u" 55# Valid: type compatibility 56msgid "abc%u" 57msgstr "xyz%x" 58# Valid: type compatibility 59msgid "abc%u" 60msgstr "xyz%X" 61# Valid: type compatibility 62msgid "abc%e" 63msgstr "xyz%E" 64# Valid: type compatibility 65msgid "abc%e" 66msgstr "xyz%f" 67# Valid: type compatibility 68msgid "abc%e" 69msgstr "xyz%F" 70# Valid: type compatibility 71msgid "abc%e" 72msgstr "xyz%g" 73# Valid: type compatibility 74msgid "abc%e" 75msgstr "xyz%G" 76# Valid: type compatibility 77msgid "abc%e" 78msgstr "xyz%a" 79# Valid: type compatibility 80msgid "abc%e" 81msgstr "xyz%A" 82# Invalid: type incompatibility 83msgid "abc%c" 84msgstr "xyz%s" 85# Invalid: type incompatibility 86msgid "abc%c" 87msgstr "xyz%i" 88# Invalid: type incompatibility 89msgid "abc%c" 90msgstr "xyz%o" 91# Invalid: type incompatibility 92msgid "abc%c" 93msgstr "xyz%e" 94# Invalid: type incompatibility 95msgid "abc%c" 96msgstr "xyz%p" 97# Invalid: type incompatibility 98msgid "abc%c" 99msgstr "xyz%n" 100# Invalid: type incompatibility 101msgid "abc%s" 102msgstr "xyz%i" 103# Invalid: type incompatibility 104msgid "abc%s" 105msgstr "xyz%o" 106# Invalid: type incompatibility 107msgid "abc%s" 108msgstr "xyz%e" 109# Invalid: type incompatibility 110msgid "abc%s" 111msgstr "xyz%p" 112# Invalid: type incompatibility 113msgid "abc%s" 114msgstr "xyz%n" 115# Invalid: type incompatibility 116msgid "abc%i" 117msgstr "xyz%o" 118# Invalid: type incompatibility 119msgid "abc%i" 120msgstr "xyz%e" 121# Invalid: type incompatibility 122msgid "abc%i" 123msgstr "xyz%p" 124# Invalid: type incompatibility 125msgid "abc%i" 126msgstr "xyz%n" 127# Invalid: type incompatibility 128msgid "abc%u" 129msgstr "xyz%e" 130# Invalid: type incompatibility 131msgid "abc%u" 132msgstr "xyz%p" 133# Invalid: type incompatibility 134msgid "abc%u" 135msgstr "xyz%n" 136# Invalid: type incompatibility 137msgid "abc%e" 138msgstr "xyz%p" 139# Invalid: type incompatibility 140msgid "abc%e" 141msgstr "xyz%n" 142# Invalid: type incompatibility 143msgid "abc%p" 144msgstr "xyz%n" 145# Invalid: type incompatibility due to size 146msgid "abc%i" 147msgstr "xyz%hhi" 148# Invalid: type incompatibility due to size 149msgid "abc%i" 150msgstr "xyz%hi" 151# Invalid: type incompatibility due to size 152msgid "abc%i" 153msgstr "xyz%li" 154# Invalid: type incompatibility due to size 155msgid "abc%i" 156msgstr "xyz%lli" 157# Invalid: type incompatibility due to size 158msgid "abc%i" 159msgstr "xyz%Li" 160# Invalid: type incompatibility due to size 161msgid "abc%i" 162msgstr "xyz%qi" 163# Invalid: type incompatibility due to size 164msgid "abc%i" 165msgstr "xyz%ji" 166# Invalid: type incompatibility due to size 167msgid "abc%i" 168msgstr "xyz%zi" 169# Invalid: type incompatibility due to size 170msgid "abc%i" 171msgstr "xyz%ti" 172# Invalid: type incompatibility due to size 173msgid "abc%hhi" 174msgstr "xyz%hi" 175# Invalid: type incompatibility due to size 176msgid "abc%hhi" 177msgstr "xyz%li" 178# Invalid: type incompatibility due to size 179msgid "abc%hhi" 180msgstr "xyz%lli" 181# Invalid: type incompatibility due to size 182msgid "abc%hhi" 183msgstr "xyz%Li" 184# Invalid: type incompatibility due to size 185msgid "abc%hhi" 186msgstr "xyz%qi" 187# Invalid: type incompatibility due to size 188msgid "abc%hhi" 189msgstr "xyz%ji" 190# Invalid: type incompatibility due to size 191msgid "abc%hhi" 192msgstr "xyz%zi" 193# Invalid: type incompatibility due to size 194msgid "abc%hhi" 195msgstr "xyz%ti" 196# Invalid: type incompatibility due to size 197msgid "abc%hi" 198msgstr "xyz%li" 199# Invalid: type incompatibility due to size 200msgid "abc%hi" 201msgstr "xyz%lli" 202# Invalid: type incompatibility due to size 203msgid "abc%hi" 204msgstr "xyz%Li" 205# Invalid: type incompatibility due to size 206msgid "abc%hi" 207msgstr "xyz%qi" 208# Invalid: type incompatibility due to size 209msgid "abc%hi" 210msgstr "xyz%ji" 211# Invalid: type incompatibility due to size 212msgid "abc%hi" 213msgstr "xyz%zi" 214# Invalid: type incompatibility due to size 215msgid "abc%hi" 216msgstr "xyz%ti" 217# Invalid: type incompatibility due to size 218msgid "abc%li" 219msgstr "xyz%lli" 220# Invalid: type incompatibility due to size 221msgid "abc%li" 222msgstr "xyz%Li" 223# Invalid: type incompatibility due to size 224msgid "abc%li" 225msgstr "xyz%qi" 226# Invalid: type incompatibility due to size 227msgid "abc%li" 228msgstr "xyz%ji" 229# Invalid: type incompatibility due to size 230msgid "abc%li" 231msgstr "xyz%zi" 232# Invalid: type incompatibility due to size 233msgid "abc%li" 234msgstr "xyz%ti" 235# Invalid: type incompatibility due to size 236msgid "abc%lli" 237msgstr "xyz%ji" 238# Invalid: type incompatibility due to size 239msgid "abc%lli" 240msgstr "xyz%zi" 241# Invalid: type incompatibility due to size 242msgid "abc%lli" 243msgstr "xyz%ti" 244# Invalid: type incompatibility due to size 245msgid "abc%Li" 246msgstr "xyz%ji" 247# Invalid: type incompatibility due to size 248msgid "abc%Li" 249msgstr "xyz%zi" 250# Invalid: type incompatibility due to size 251msgid "abc%Li" 252msgstr "xyz%ti" 253# Invalid: type incompatibility due to size 254msgid "abc%qi" 255msgstr "xyz%ji" 256# Invalid: type incompatibility due to size 257msgid "abc%qi" 258msgstr "xyz%zi" 259# Invalid: type incompatibility due to size 260msgid "abc%qi" 261msgstr "xyz%ti" 262# Invalid: type incompatibility due to size 263msgid "abc%ji" 264msgstr "xyz%zi" 265# Invalid: type incompatibility due to size 266msgid "abc%ji" 267msgstr "xyz%ti" 268# Invalid: type incompatibility due to size 269msgid "abc%zi" 270msgstr "xyz%ti" 271# Invalid: type incompatibility for width 272msgid "abc%g%*g" 273msgstr "xyz%*g%g" 274EOF 275 276: ${MSGFMT=msgfmt} 277n=0 278while read comment; do 279 read msgid_line 280 read msgstr_line 281 n=`expr $n + 1` 282 tmpfiles="$tmpfiles f-c-2-$n.po f-c-2-$n.mo" 283 cat <<EOF > f-c-2-$n.po 284#, c-format 285${msgid_line} 286${msgstr_line} 287EOF 288 fail= 289 if echo "$comment" | grep 'Valid:' > /dev/null; then 290 if ${MSGFMT} --check-format -o f-c-2-$n.mo f-c-2-$n.po; then 291 : 292 else 293 fail=yes 294 fi 295 else 296 ${MSGFMT} --check-format -o f-c-2-$n.mo f-c-2-$n.po 2> /dev/null 297 if test $? = 1; then 298 : 299 else 300 fail=yes 301 fi 302 fi 303 if test -n "$fail"; then 304 echo "Format string checking error:" 1>&2 305 cat f-c-2-$n.po 1>&2 306 exit 1 307 fi 308 rm -f f-c-2-$n.po f-c-2-$n.mo 309done < f-c-2.data 310 311rm -fr $tmpfiles 312 313exit 0 314