#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src

# Test checking of GCC internal format strings.

cat <<\EOF > f-gi-2.data
# Valid: %% doesn't count
msgid  "abc%%def"
msgstr "xyz"
# Valid: %< doesn't count
msgid  "abc%<def"
msgstr "xyz"
# Valid: %> doesn't count
msgid  "abc%>def"
msgstr "xyz"
# Valid: %' doesn't count
msgid  "abc%'def"
msgstr "xyz"
# Invalid: %m consumes err_no
msgid  "abc%mdef"
msgstr "xyz"
# Invalid: %m consumes err_no
msgid  "abc"
msgstr "xyz%muvw"
# Invalid: invalid msgstr
msgid  "abc%%def"
msgstr "xyz%"
# Valid: same arguments
msgid  "abc%s%Hdef"
msgstr "xyz%s%H"
# Valid: same arguments, with different flags
msgid  "abc%s%Hdef"
msgstr "xyz%qs%qH"
# Valid: same arguments, with different widths
msgid  "abc%.*sdef"
msgstr "xyz%i%s"
# Valid: same arguments but in numbered syntax
msgid  "abc%s%ddef"
msgstr "xyz%1$s%2$d"
# Valid: permutation
msgid  "abc%s%d%cdef"
msgstr "xyz%3$c%2$d%1$s"
# Valid: permutation with width
msgid  "abc%c%.*sdef"
msgstr "xyz%3$.*2$s%1$c"
# Invalid: too few arguments
msgid  "abc%sdef%u"
msgstr "xyz%s"
# Invalid: too many arguments
msgid  "abc%udef"
msgstr "xyz%uvw%c"
# Valid: same numbered arguments, with different widths
msgid  "abc%2$5s%1$4s"
msgstr "xyz%2$4s%1$5s"
# Invalid: missing argument
msgid  "abc%2$sdef%1$u"
msgstr "xyz%1$u"
# Invalid: missing argument
msgid  "abc%1$sdef%2$u"
msgstr "xyz%2$u"
# Invalid: added argument
msgid  "abc%1$udef"
msgstr "xyz%1$uvw%2$c"
# Valid: type compatibility
msgid  "abc%i"
msgstr "xyz%d"
# Valid: type compatibility
msgid  "abc%o"
msgstr "xyz%u"
# Valid: type compatibility
msgid  "abc%u"
msgstr "xyz%x"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%s"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%i"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%u"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%p"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%H"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%D"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%c"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%i"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%u"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%p"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%H"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%D"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%s"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%u"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%p"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%H"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%D"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%i"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%p"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%H"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%D"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%u"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%H"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%D"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%p"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%D"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%H"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%F"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%D"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%T"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%F"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%A"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%T"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%C"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%A"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%C"
msgstr "xyz%E"
# Invalid: type incompatibility
msgid  "abc%C"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%C"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%C"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%C"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%C"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%E"
msgstr "xyz%L"
# Invalid: type incompatibility
msgid  "abc%E"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%E"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%E"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%E"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%L"
msgstr "xyz%O"
# Invalid: type incompatibility
msgid  "abc%L"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%L"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%L"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%O"
msgstr "xyz%P"
# Invalid: type incompatibility
msgid  "abc%O"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%O"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%P"
msgstr "xyz%Q"
# Invalid: type incompatibility
msgid  "abc%P"
msgstr "xyz%V"
# Invalid: type incompatibility
msgid  "abc%Q"
msgstr "xyz%V"
# Invalid: type incompatibility due to size
msgid  "abc%i"
msgstr "xyz%li"
# Invalid: type incompatibility due to size
msgid  "abc%i"
msgstr "xyz%lli"
# Invalid: type incompatibility due to size
msgid  "abc%i"
msgstr "xyz%wi"
# Invalid: type incompatibility due to size
msgid  "abc%li"
msgstr "xyz%lli"
# Invalid: type incompatibility due to size
msgid  "abc%li"
msgstr "xyz%wi"
# Invalid: type incompatibility due to size
msgid  "abc%lli"
msgstr "xyz%wi"
# Invalid: type incompatibility for width
msgid  "abc%.*s"
msgstr "xyz%u%s"
EOF

: ${MSGFMT=msgfmt}
n=0
while read comment; do
  read msgid_line
  read msgstr_line
  n=`expr $n + 1`
  cat <<EOF > f-gi-2-$n.po
#, gcc-internal-format
${msgid_line}
${msgstr_line}
EOF
  fail=
  if echo "$comment" | grep 'Valid:' > /dev/null; then
    if ${MSGFMT} --check-format -o f-gi-2-$n.mo f-gi-2-$n.po; then
      :
    else
      fail=yes
    fi
  else
    ${MSGFMT} --check-format -o f-gi-2-$n.mo f-gi-2-$n.po 2> /dev/null
    if test $? = 1; then
      :
    else
      fail=yes
    fi
  fi
  if test -n "$fail"; then
    echo "Format string checking error:" 1>&2
    cat f-gi-2-$n.po 1>&2
    Exit 1
  fi
  rm -f f-gi-2-$n.po f-gi-2-$n.mo
done < f-gi-2.data

Exit 0
