Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

#! /bin/sh

# Test recognition of Perl format strings of both kinds (printf and brace).
# This test is for the combination of both kinds.

tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15

tmpfiles="$tmpfiles f-pm-1.data"

cat <<\EOF > f-pm-1.data
# Both formats.
#, perl-format, perl-brace-format
"{foo} %c {bar} %d {baz}"
# printf format only.
#, perl-format
"%c %d"
# printf format only, because '%' is not allowed in identifier.
#, perl-format
"{foo%cbar}"
# Valid bracketed format because there is still one valid identifier.
#, perl-format, perl-brace-format
"{foo%cbar} {baz}"
# Bracketed format only, because %l is not recognized in printf format.
#, perl-brace-format
"{foo} %l {bar}"
# Neither format recognized here.

"{foo bar %l"
EOF

: ${XGETTEXT=xgettext}
n=0
while read comment; do
  read formats
  read string
  n=`expr $n + 1`
  tmpfiles="$tmpfiles f-pm-1-$n.in f-pm-1-$n.po"
  cat <<EOF > f-pm-1-$n.in
gettext(${string});
EOF
  ${XGETTEXT} -L perl --omit-header --no-location -o f-pm-1-$n.po f-pm-1-$n.in || exit 1
  test -f f-pm-1-$n.po || exit 1
  fail=
  if test -n "${formats}"; then
    # Verify that the first line contains the expected #, comment.
    if sed 1q < f-pm-1-$n.po | grep '^'"${formats}"'$' > /dev/null; then
      :
    else
      fail=yes
    fi
  else
    # Verify that there is no #, comment.
    if sed 1q < f-pm-1-$n.po | grep '^msgid' > /dev/null; then
      :
    else
      fail=yes
    fi
  fi
  if test -n "$fail"; then
    echo "Format string recognition error:" 1>&2
    cat f-pm-1-$n.in 1>&2
    echo "Got:" 1>&2
    cat f-pm-1-$n.po 1>&2
    exit 1
  fi
done < f-pm-1.data

rm -fr $tmpfiles

exit 0