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