1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test checking of GFC internal format strings.
5
6cat <<\EOF > f-gf-2.data
7# Valid: %% doesn't count
8msgid  "abc%%def"
9msgstr "xyz"
10# Invalid: %C consumes currentloc
11msgid  "abc%Cdef"
12msgstr "xyz"
13# Invalid: %C consumes currentloc
14msgid  "abc"
15msgstr "xyz%Cuvw"
16# Invalid: invalid msgstr
17msgid  "abc%%def"
18msgstr "xyz%"
19# Valid: same arguments
20msgid  "abc%s%udef"
21msgstr "xyz%s%u"
22# Valid: same arguments but in numbered syntax
23msgid  "abc%s%ddef"
24msgstr "xyz%1$s%2$d"
25# Valid: permutation
26msgid  "abc%s%d%cdef"
27msgstr "xyz%3$c%2$d%1$s"
28# Invalid: too few arguments
29msgid  "abc%sdef%u"
30msgstr "xyz%s"
31# Invalid: too many arguments
32msgid  "abc%udef"
33msgstr "xyz%uvw%c"
34# Invalid: missing argument
35msgid  "abc%2$sdef%1$u"
36msgstr "xyz%1$u"
37# Invalid: missing argument
38msgid  "abc%1$sdef%2$u"
39msgstr "xyz%2$u"
40# Invalid: added argument
41msgid  "abc%1$udef"
42msgstr "xyz%1$uvw%2$c"
43# Valid: type compatibility
44msgid  "abc%i"
45msgstr "xyz%d"
46# Invalid: type incompatibility
47msgid  "abc%c"
48msgstr "xyz%s"
49# Invalid: type incompatibility
50msgid  "abc%c"
51msgstr "xyz%i"
52# Invalid: type incompatibility
53msgid  "abc%c"
54msgstr "xyz%u"
55# Invalid: type incompatibility
56msgid  "abc%c"
57msgstr "xyz%li"
58# Invalid: type incompatibility
59msgid  "abc%c"
60msgstr "xyz%lu"
61# Invalid: type incompatibility
62msgid  "abc%c"
63msgstr "xyz%L"
64# Invalid: type incompatibility
65msgid  "abc%c"
66msgstr "xyz%C"
67# Invalid: type incompatibility
68msgid  "abc%s"
69msgstr "xyz%i"
70# Invalid: type incompatibility
71msgid  "abc%s"
72msgstr "xyz%u"
73# Invalid: type incompatibility
74msgid  "abc%s"
75msgstr "xyz%li"
76# Invalid: type incompatibility
77msgid  "abc%s"
78msgstr "xyz%lu"
79# Invalid: type incompatibility
80msgid  "abc%s"
81msgstr "xyz%L"
82# Invalid: type incompatibility
83msgid  "abc%s"
84msgstr "xyz%C"
85# Invalid: type incompatibility
86msgid  "abc%i"
87msgstr "xyz%u"
88# Invalid: type incompatibility
89msgid  "abc%i"
90msgstr "xyz%li"
91# Invalid: type incompatibility
92msgid  "abc%i"
93msgstr "xyz%lu"
94# Invalid: type incompatibility
95msgid  "abc%i"
96msgstr "xyz%L"
97# Invalid: type incompatibility
98msgid  "abc%i"
99msgstr "xyz%C"
100# Invalid: type incompatibility
101msgid  "abc%u"
102msgstr "xyz%li"
103# Invalid: type incompatibility
104msgid  "abc%u"
105msgstr "xyz%lu"
106# Invalid: type incompatibility
107msgid  "abc%u"
108msgstr "xyz%L"
109# Invalid: type incompatibility
110msgid  "abc%u"
111msgstr "xyz%C"
112# Invalid: type incompatibility
113msgid  "abc%li"
114msgstr "xyz%lu"
115# Invalid: type incompatibility
116msgid  "abc%li"
117msgstr "xyz%L"
118# Invalid: type incompatibility
119msgid  "abc%li"
120msgstr "xyz%C"
121# Invalid: type incompatibility
122msgid  "abc%lu"
123msgstr "xyz%L"
124# Invalid: type incompatibility
125msgid  "abc%lu"
126msgstr "xyz%C"
127# Invalid: type incompatibility
128msgid  "abc%L"
129msgstr "xyz%C"
130# Invalid: permutation
131msgid "abc%sdef%c"
132msgstr "abc%cdef%s"
133# Valid: currentloc reference position does not matter
134msgid "abc%sdef%C"
135msgstr "abc%Cdef%s"
136# Valid: currentloc reference may be repeated
137msgid "abc%sdef%C"
138msgstr "abc%sdef%Cghi%C"
139# Valid: currentloc reference may be repeated and permuted
140msgid "abc%Cdef%Cghi%s"
141msgstr "abc%sdef%C"
142EOF
143
144: ${MSGFMT=msgfmt}
145n=0
146while read comment; do
147  read msgid_line
148  read msgstr_line
149  n=`expr $n + 1`
150  cat <<EOF > f-gf-2-$n.po
151#, gfc-internal-format
152${msgid_line}
153${msgstr_line}
154EOF
155  fail=
156  if echo "$comment" | grep 'Valid:' > /dev/null; then
157    if ${MSGFMT} --check-format -o f-gf-2-$n.mo f-gf-2-$n.po; then
158      :
159    else
160      fail=yes
161    fi
162  else
163    ${MSGFMT} --check-format -o f-gf-2-$n.mo f-gf-2-$n.po 2> /dev/null
164    if test $? = 1; then
165      :
166    else
167      fail=yes
168    fi
169  fi
170  if test -n "$fail"; then
171    echo "Format string checking error:" 1>&2
172    cat f-gf-2-$n.po 1>&2
173    Exit 1
174  fi
175  rm -f f-gf-2-$n.po f-gf-2-$n.mo
176done < f-gf-2.data
177
178Exit 0
179