1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #include "gnu_msgfmt.h"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #define OPT_L 0x01
30*7c478bd9Sstevel@tonic-gate #define OPT_l 0x02
31*7c478bd9Sstevel@tonic-gate #define OPT_ll 0x04
32*7c478bd9Sstevel@tonic-gate #define OPT_w 0x08
33*7c478bd9Sstevel@tonic-gate #define OPT_h 0x10
34*7c478bd9Sstevel@tonic-gate #define OPT_hh 0x20
35*7c478bd9Sstevel@tonic-gate #define OPT_j 0x40
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate static int
extract_format(char * norm,const char * sfmt,size_t sz)38*7c478bd9Sstevel@tonic-gate extract_format(char *norm, const char *sfmt, size_t sz)
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate const unsigned char *fmt = (const unsigned char *)sfmt;
41*7c478bd9Sstevel@tonic-gate unsigned char c;
42*7c478bd9Sstevel@tonic-gate int t, arg, ap;
43*7c478bd9Sstevel@tonic-gate int dotseen;
44*7c478bd9Sstevel@tonic-gate char flag, conv;
45*7c478bd9Sstevel@tonic-gate int lastarg = -1;
46*7c478bd9Sstevel@tonic-gate int prevarg;
47*7c478bd9Sstevel@tonic-gate int max = 0;
48*7c478bd9Sstevel@tonic-gate int lflag;
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate for (; *fmt; fmt++) {
51*7c478bd9Sstevel@tonic-gate if (*fmt == '%') {
52*7c478bd9Sstevel@tonic-gate if (*++fmt == '%')
53*7c478bd9Sstevel@tonic-gate continue;
54*7c478bd9Sstevel@tonic-gate if (!*fmt)
55*7c478bd9Sstevel@tonic-gate break;
56*7c478bd9Sstevel@tonic-gate prevarg = lastarg;
57*7c478bd9Sstevel@tonic-gate arg = ++lastarg;
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate t = 0;
60*7c478bd9Sstevel@tonic-gate while (*fmt && isdigit(*fmt))
61*7c478bd9Sstevel@tonic-gate t = t * 10 + *fmt++ - '0';
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate if (*fmt == '$') {
64*7c478bd9Sstevel@tonic-gate lastarg = arg = t - 1;
65*7c478bd9Sstevel@tonic-gate fmt++;
66*7c478bd9Sstevel@tonic-gate }
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate if (!*fmt)
69*7c478bd9Sstevel@tonic-gate goto end;
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate dotseen = 0;
72*7c478bd9Sstevel@tonic-gate flag = 0;
73*7c478bd9Sstevel@tonic-gate lflag = 0;
74*7c478bd9Sstevel@tonic-gate again:
75*7c478bd9Sstevel@tonic-gate /* Skip flags */
76*7c478bd9Sstevel@tonic-gate while ((c = *fmt) != '\0') {
77*7c478bd9Sstevel@tonic-gate if (c == '\'' || c == '+' || c == '-' ||
78*7c478bd9Sstevel@tonic-gate c == ' ' || c == '#' || c == '0') {
79*7c478bd9Sstevel@tonic-gate fmt++;
80*7c478bd9Sstevel@tonic-gate continue;
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate break;
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate while (*fmt && isdigit(*fmt))
86*7c478bd9Sstevel@tonic-gate fmt++;
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate if (*fmt == '*') {
89*7c478bd9Sstevel@tonic-gate if (isdigit(*(fmt + 1))) {
90*7c478bd9Sstevel@tonic-gate fmt++;
91*7c478bd9Sstevel@tonic-gate t = 0;
92*7c478bd9Sstevel@tonic-gate while (*fmt && isdigit(*fmt))
93*7c478bd9Sstevel@tonic-gate t = t * 10 + *fmt++ - '0';
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate if (*fmt == '$') {
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate * %*4$
98*7c478bd9Sstevel@tonic-gate */
99*7c478bd9Sstevel@tonic-gate ap = t - 1;
100*7c478bd9Sstevel@tonic-gate if ((ap * 2 + 1 >= sz) ||
101*7c478bd9Sstevel@tonic-gate (norm[ap * 2] &&
102*7c478bd9Sstevel@tonic-gate norm[ap * 2] != '*')) {
103*7c478bd9Sstevel@tonic-gate /* error in format */
104*7c478bd9Sstevel@tonic-gate return (-1);
105*7c478bd9Sstevel@tonic-gate } else {
106*7c478bd9Sstevel@tonic-gate if (ap >= max)
107*7c478bd9Sstevel@tonic-gate max = ap + 1;
108*7c478bd9Sstevel@tonic-gate norm[ap * 2] = '*';
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate /*
112*7c478bd9Sstevel@tonic-gate * If digits follow a '*', it is
113*7c478bd9Sstevel@tonic-gate * not loaded as an argument, the
114*7c478bd9Sstevel@tonic-gate * digits are used instead.
115*7c478bd9Sstevel@tonic-gate */
116*7c478bd9Sstevel@tonic-gate } else {
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate * %*
119*7c478bd9Sstevel@tonic-gate */
120*7c478bd9Sstevel@tonic-gate if (*(fmt + 1) == '$') {
121*7c478bd9Sstevel@tonic-gate fmt++;
122*7c478bd9Sstevel@tonic-gate } else {
123*7c478bd9Sstevel@tonic-gate ap = arg;
124*7c478bd9Sstevel@tonic-gate prevarg = arg;
125*7c478bd9Sstevel@tonic-gate lastarg = ++arg;
126*7c478bd9Sstevel@tonic-gate if ((ap * 2 + 1 >= sz) ||
127*7c478bd9Sstevel@tonic-gate (norm[ap * 2] &&
128*7c478bd9Sstevel@tonic-gate norm[ap * 2] != '*')) {
129*7c478bd9Sstevel@tonic-gate /* error in format */
130*7c478bd9Sstevel@tonic-gate return (-1);
131*7c478bd9Sstevel@tonic-gate } else {
132*7c478bd9Sstevel@tonic-gate if (ap >= max)
133*7c478bd9Sstevel@tonic-gate max = ap + 1;
134*7c478bd9Sstevel@tonic-gate norm[ap * 2] = '*';
135*7c478bd9Sstevel@tonic-gate }
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate fmt++;
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate if ((*fmt == '.') || (*fmt == '*')) {
142*7c478bd9Sstevel@tonic-gate if (dotseen)
143*7c478bd9Sstevel@tonic-gate return (-1);
144*7c478bd9Sstevel@tonic-gate dotseen = 1;
145*7c478bd9Sstevel@tonic-gate fmt++;
146*7c478bd9Sstevel@tonic-gate goto again;
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate if (!*fmt)
150*7c478bd9Sstevel@tonic-gate goto end;
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate while (*fmt) {
153*7c478bd9Sstevel@tonic-gate switch (*fmt) {
154*7c478bd9Sstevel@tonic-gate case 'l':
155*7c478bd9Sstevel@tonic-gate if (!(flag & OPT_ll)) {
156*7c478bd9Sstevel@tonic-gate if (lflag) {
157*7c478bd9Sstevel@tonic-gate flag &= ~OPT_l;
158*7c478bd9Sstevel@tonic-gate flag |= OPT_ll;
159*7c478bd9Sstevel@tonic-gate } else {
160*7c478bd9Sstevel@tonic-gate flag |= OPT_l;
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate lflag++;
164*7c478bd9Sstevel@tonic-gate break;
165*7c478bd9Sstevel@tonic-gate case 'L':
166*7c478bd9Sstevel@tonic-gate flag |= OPT_L;
167*7c478bd9Sstevel@tonic-gate break;
168*7c478bd9Sstevel@tonic-gate case 'w':
169*7c478bd9Sstevel@tonic-gate flag |= OPT_w;
170*7c478bd9Sstevel@tonic-gate break;
171*7c478bd9Sstevel@tonic-gate case 'h':
172*7c478bd9Sstevel@tonic-gate if (flag & (OPT_h|OPT_hh))
173*7c478bd9Sstevel@tonic-gate flag |= OPT_hh;
174*7c478bd9Sstevel@tonic-gate else
175*7c478bd9Sstevel@tonic-gate flag |= OPT_h;
176*7c478bd9Sstevel@tonic-gate break;
177*7c478bd9Sstevel@tonic-gate case 'j':
178*7c478bd9Sstevel@tonic-gate flag |= OPT_j;
179*7c478bd9Sstevel@tonic-gate break;
180*7c478bd9Sstevel@tonic-gate case 'z':
181*7c478bd9Sstevel@tonic-gate case 't':
182*7c478bd9Sstevel@tonic-gate if (!(flag & OPT_ll)) {
183*7c478bd9Sstevel@tonic-gate flag |= OPT_l;
184*7c478bd9Sstevel@tonic-gate }
185*7c478bd9Sstevel@tonic-gate break;
186*7c478bd9Sstevel@tonic-gate case '\'':
187*7c478bd9Sstevel@tonic-gate case '+':
188*7c478bd9Sstevel@tonic-gate case '-':
189*7c478bd9Sstevel@tonic-gate case ' ':
190*7c478bd9Sstevel@tonic-gate case '#':
191*7c478bd9Sstevel@tonic-gate case '.':
192*7c478bd9Sstevel@tonic-gate case '*':
193*7c478bd9Sstevel@tonic-gate goto again;
194*7c478bd9Sstevel@tonic-gate default:
195*7c478bd9Sstevel@tonic-gate if (isdigit(*fmt))
196*7c478bd9Sstevel@tonic-gate goto again;
197*7c478bd9Sstevel@tonic-gate else
198*7c478bd9Sstevel@tonic-gate goto done;
199*7c478bd9Sstevel@tonic-gate }
200*7c478bd9Sstevel@tonic-gate fmt++;
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate done:
203*7c478bd9Sstevel@tonic-gate if (!*fmt)
204*7c478bd9Sstevel@tonic-gate goto end;
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate if ((c = *fmt) == 'C') {
207*7c478bd9Sstevel@tonic-gate flag |= OPT_l;
208*7c478bd9Sstevel@tonic-gate conv = 'c';
209*7c478bd9Sstevel@tonic-gate } else if (c == 'd') {
210*7c478bd9Sstevel@tonic-gate conv = 'd';
211*7c478bd9Sstevel@tonic-gate } else if (c == 'S') {
212*7c478bd9Sstevel@tonic-gate flag |= OPT_l;
213*7c478bd9Sstevel@tonic-gate conv = 's';
214*7c478bd9Sstevel@tonic-gate } else if (c == 's') {
215*7c478bd9Sstevel@tonic-gate conv = 's';
216*7c478bd9Sstevel@tonic-gate } else if (c == 'i') {
217*7c478bd9Sstevel@tonic-gate conv = 'i';
218*7c478bd9Sstevel@tonic-gate } else if (c == 'o') {
219*7c478bd9Sstevel@tonic-gate conv = 'o';
220*7c478bd9Sstevel@tonic-gate } else if (c == 'u') {
221*7c478bd9Sstevel@tonic-gate conv = 'u';
222*7c478bd9Sstevel@tonic-gate } else if (c == 'c') {
223*7c478bd9Sstevel@tonic-gate conv = 'c';
224*7c478bd9Sstevel@tonic-gate } else if (c == 'x') {
225*7c478bd9Sstevel@tonic-gate conv = 'x';
226*7c478bd9Sstevel@tonic-gate } else if (c == 'X') {
227*7c478bd9Sstevel@tonic-gate conv = 'X';
228*7c478bd9Sstevel@tonic-gate } else if (c == 'e') {
229*7c478bd9Sstevel@tonic-gate conv = 'e';
230*7c478bd9Sstevel@tonic-gate } else if (c == 'E') {
231*7c478bd9Sstevel@tonic-gate conv = 'E';
232*7c478bd9Sstevel@tonic-gate } else if (c == 'f') {
233*7c478bd9Sstevel@tonic-gate conv = 'f';
234*7c478bd9Sstevel@tonic-gate } else if (c == 'F') {
235*7c478bd9Sstevel@tonic-gate conv = 'F';
236*7c478bd9Sstevel@tonic-gate } else if (c == 'a') {
237*7c478bd9Sstevel@tonic-gate conv = 'a';
238*7c478bd9Sstevel@tonic-gate } else if (c == 'A') {
239*7c478bd9Sstevel@tonic-gate conv = 'A';
240*7c478bd9Sstevel@tonic-gate } else if (c == 'g') {
241*7c478bd9Sstevel@tonic-gate conv = 'g';
242*7c478bd9Sstevel@tonic-gate } else if (c == 'G') {
243*7c478bd9Sstevel@tonic-gate conv = 'G';
244*7c478bd9Sstevel@tonic-gate } else if (c == 'p') {
245*7c478bd9Sstevel@tonic-gate conv = 'p';
246*7c478bd9Sstevel@tonic-gate } else if (c == 'n') {
247*7c478bd9Sstevel@tonic-gate conv = 'n';
248*7c478bd9Sstevel@tonic-gate } else {
249*7c478bd9Sstevel@tonic-gate lastarg = prevarg;
250*7c478bd9Sstevel@tonic-gate continue;
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate
253*7c478bd9Sstevel@tonic-gate if ((arg * 2 + 1 >= sz) ||
254*7c478bd9Sstevel@tonic-gate (norm[arg * 2] &&
255*7c478bd9Sstevel@tonic-gate (norm[arg * 2] != conv))) {
256*7c478bd9Sstevel@tonic-gate return (-1);
257*7c478bd9Sstevel@tonic-gate } else {
258*7c478bd9Sstevel@tonic-gate if (arg >= max)
259*7c478bd9Sstevel@tonic-gate max = arg + 1;
260*7c478bd9Sstevel@tonic-gate norm[arg * 2] = conv;
261*7c478bd9Sstevel@tonic-gate }
262*7c478bd9Sstevel@tonic-gate norm[arg * 2 + 1] = flag;
263*7c478bd9Sstevel@tonic-gate }
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate
266*7c478bd9Sstevel@tonic-gate end:
267*7c478bd9Sstevel@tonic-gate for (arg = 0; arg < max; arg++) {
268*7c478bd9Sstevel@tonic-gate if (norm[arg * 2] == '\0')
269*7c478bd9Sstevel@tonic-gate return (-1);
270*7c478bd9Sstevel@tonic-gate }
271*7c478bd9Sstevel@tonic-gate
272*7c478bd9Sstevel@tonic-gate return (max);
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate
275*7c478bd9Sstevel@tonic-gate
276*7c478bd9Sstevel@tonic-gate void
check_format(struct entry * id,struct entry * str,int is_c_format)277*7c478bd9Sstevel@tonic-gate check_format(struct entry *id, struct entry *str, int is_c_format)
278*7c478bd9Sstevel@tonic-gate {
279*7c478bd9Sstevel@tonic-gate int i, n;
280*7c478bd9Sstevel@tonic-gate int id_b_newline, id_e_newline;
281*7c478bd9Sstevel@tonic-gate int plural_b_newline, plural_e_newline;
282*7c478bd9Sstevel@tonic-gate int str_b_newline, str_e_newline;
283*7c478bd9Sstevel@tonic-gate int id_fmt, plural_fmt, str_fmt;
284*7c478bd9Sstevel@tonic-gate int *pstr_fmt;
285*7c478bd9Sstevel@tonic-gate char *msgid, *plural, *msgstr;
286*7c478bd9Sstevel@tonic-gate char *id_norm, *plural_norm, *str_norm;
287*7c478bd9Sstevel@tonic-gate char **pstr_norm;
288*7c478bd9Sstevel@tonic-gate size_t id_len, id_num;
289*7c478bd9Sstevel@tonic-gate size_t plural_off, plural_len, plural_num;
290*7c478bd9Sstevel@tonic-gate size_t str_len, str_num;
291*7c478bd9Sstevel@tonic-gate size_t osz, nsz;
292*7c478bd9Sstevel@tonic-gate struct loc *p;
293*7c478bd9Sstevel@tonic-gate
294*7c478bd9Sstevel@tonic-gate if (id->len == 1) {
295*7c478bd9Sstevel@tonic-gate /*
296*7c478bd9Sstevel@tonic-gate * null string: header entry
297*7c478bd9Sstevel@tonic-gate * no check is performed
298*7c478bd9Sstevel@tonic-gate */
299*7c478bd9Sstevel@tonic-gate return;
300*7c478bd9Sstevel@tonic-gate }
301*7c478bd9Sstevel@tonic-gate
302*7c478bd9Sstevel@tonic-gate msgid = id->str;
303*7c478bd9Sstevel@tonic-gate id_num = id->num;
304*7c478bd9Sstevel@tonic-gate msgstr = str->str;
305*7c478bd9Sstevel@tonic-gate if (id->no > 1) {
306*7c478bd9Sstevel@tonic-gate /* plural */
307*7c478bd9Sstevel@tonic-gate id_len = id->pos[0].len;
308*7c478bd9Sstevel@tonic-gate plural_off = id->pos[1].off;
309*7c478bd9Sstevel@tonic-gate plural_len = id->pos[1].len;
310*7c478bd9Sstevel@tonic-gate plural_num = id->pos[1].num;
311*7c478bd9Sstevel@tonic-gate plural = msgid + plural_off;
312*7c478bd9Sstevel@tonic-gate } else {
313*7c478bd9Sstevel@tonic-gate /* no plural form */
314*7c478bd9Sstevel@tonic-gate id_len = id->len;
315*7c478bd9Sstevel@tonic-gate str_len = str->len;
316*7c478bd9Sstevel@tonic-gate str_num = str->num;
317*7c478bd9Sstevel@tonic-gate plural = NULL;
318*7c478bd9Sstevel@tonic-gate }
319*7c478bd9Sstevel@tonic-gate
320*7c478bd9Sstevel@tonic-gate /*
321*7c478bd9Sstevel@tonic-gate * First checking the newline
322*7c478bd9Sstevel@tonic-gate */
323*7c478bd9Sstevel@tonic-gate
324*7c478bd9Sstevel@tonic-gate if (!plural) {
325*7c478bd9Sstevel@tonic-gate /* no plural form */
326*7c478bd9Sstevel@tonic-gate id_b_newline = (msgid[0] == '\n');
327*7c478bd9Sstevel@tonic-gate id_e_newline = (msgid[id_len - 1 - 1] == '\n');
328*7c478bd9Sstevel@tonic-gate
329*7c478bd9Sstevel@tonic-gate str_b_newline = (msgstr[0] == '\n');
330*7c478bd9Sstevel@tonic-gate str_e_newline = (msgstr[str_len - 1 - 1] == '\n');
331*7c478bd9Sstevel@tonic-gate if (id_b_newline && !str_b_newline) {
332*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_BEGIN_NEWLINE_1),
333*7c478bd9Sstevel@tonic-gate id_num, str_num, cur_po);
334*7c478bd9Sstevel@tonic-gate po_error++;
335*7c478bd9Sstevel@tonic-gate } else if (!id_b_newline && str_b_newline) {
336*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_BEGIN_NEWLINE_2),
337*7c478bd9Sstevel@tonic-gate id_num, str_num, cur_po);
338*7c478bd9Sstevel@tonic-gate po_error++;
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate if (id_e_newline && !str_e_newline) {
341*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_END_NEWLINE_1),
342*7c478bd9Sstevel@tonic-gate id_num, str_num, cur_po);
343*7c478bd9Sstevel@tonic-gate po_error++;
344*7c478bd9Sstevel@tonic-gate } else if (!id_e_newline && str_e_newline) {
345*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_END_NEWLINE_2),
346*7c478bd9Sstevel@tonic-gate id_num, str_num, cur_po);
347*7c478bd9Sstevel@tonic-gate po_error++;
348*7c478bd9Sstevel@tonic-gate }
349*7c478bd9Sstevel@tonic-gate } else {
350*7c478bd9Sstevel@tonic-gate /* plural form */
351*7c478bd9Sstevel@tonic-gate id_b_newline = (msgid[0] == '\n');
352*7c478bd9Sstevel@tonic-gate id_e_newline = (msgid[id_len - 1 - 1] == '\n');
353*7c478bd9Sstevel@tonic-gate
354*7c478bd9Sstevel@tonic-gate plural_b_newline = (plural[0] == '\n');
355*7c478bd9Sstevel@tonic-gate plural_e_newline = (plural[plural_len - 1 -1 ] == '\n');
356*7c478bd9Sstevel@tonic-gate
357*7c478bd9Sstevel@tonic-gate /* between msgid and msgid_plural */
358*7c478bd9Sstevel@tonic-gate if (id_b_newline && !plural_b_newline) {
359*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_BEGIN_NEWLINE_3),
360*7c478bd9Sstevel@tonic-gate id_num, plural_num, cur_po);
361*7c478bd9Sstevel@tonic-gate po_error++;
362*7c478bd9Sstevel@tonic-gate } else if (!id_b_newline && plural_b_newline) {
363*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_BEGIN_NEWLINE_4),
364*7c478bd9Sstevel@tonic-gate id_num, plural_num, cur_po);
365*7c478bd9Sstevel@tonic-gate po_error++;
366*7c478bd9Sstevel@tonic-gate }
367*7c478bd9Sstevel@tonic-gate if (id_e_newline && !plural_e_newline) {
368*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_END_NEWLINE_3),
369*7c478bd9Sstevel@tonic-gate id_num, plural_num, cur_po);
370*7c478bd9Sstevel@tonic-gate po_error++;
371*7c478bd9Sstevel@tonic-gate } else if (!id_e_newline && plural_e_newline) {
372*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_END_NEWLINE_4),
373*7c478bd9Sstevel@tonic-gate id_num, plural_num, cur_po);
374*7c478bd9Sstevel@tonic-gate po_error++;
375*7c478bd9Sstevel@tonic-gate }
376*7c478bd9Sstevel@tonic-gate
377*7c478bd9Sstevel@tonic-gate for (i = 0; i < str->no; i++) {
378*7c478bd9Sstevel@tonic-gate p = str->pos + i;
379*7c478bd9Sstevel@tonic-gate str_b_newline = (msgstr[p->off] == '\n');
380*7c478bd9Sstevel@tonic-gate str_e_newline =
381*7c478bd9Sstevel@tonic-gate (msgstr[p->off + p->len - 1 - 1] == '\n');
382*7c478bd9Sstevel@tonic-gate
383*7c478bd9Sstevel@tonic-gate if (id_b_newline && !str_b_newline) {
384*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_BEGIN_NEWLINE_5),
385*7c478bd9Sstevel@tonic-gate id_num, p->num, cur_po, i);
386*7c478bd9Sstevel@tonic-gate po_error++;
387*7c478bd9Sstevel@tonic-gate } else if (!id_b_newline && str_b_newline) {
388*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_BEGIN_NEWLINE_6),
389*7c478bd9Sstevel@tonic-gate id_num, p->num, cur_po, i);
390*7c478bd9Sstevel@tonic-gate po_error++;
391*7c478bd9Sstevel@tonic-gate }
392*7c478bd9Sstevel@tonic-gate
393*7c478bd9Sstevel@tonic-gate if (id_e_newline && !str_e_newline) {
394*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_END_NEWLINE_5),
395*7c478bd9Sstevel@tonic-gate id_num, p->num, cur_po, i);
396*7c478bd9Sstevel@tonic-gate po_error++;
397*7c478bd9Sstevel@tonic-gate } else if (!id_e_newline && str_e_newline) {
398*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_END_NEWLINE_6),
399*7c478bd9Sstevel@tonic-gate id_num, p->num, cur_po, i);
400*7c478bd9Sstevel@tonic-gate po_error++;
401*7c478bd9Sstevel@tonic-gate }
402*7c478bd9Sstevel@tonic-gate }
403*7c478bd9Sstevel@tonic-gate }
404*7c478bd9Sstevel@tonic-gate
405*7c478bd9Sstevel@tonic-gate /*
406*7c478bd9Sstevel@tonic-gate * if c-format is not specified, no printf-format check
407*7c478bd9Sstevel@tonic-gate * is performed.
408*7c478bd9Sstevel@tonic-gate */
409*7c478bd9Sstevel@tonic-gate if (!is_c_format) {
410*7c478bd9Sstevel@tonic-gate return;
411*7c478bd9Sstevel@tonic-gate }
412*7c478bd9Sstevel@tonic-gate
413*7c478bd9Sstevel@tonic-gate osz = id_len * 2;
414*7c478bd9Sstevel@tonic-gate id_norm = (char *)Xcalloc(1, osz);
415*7c478bd9Sstevel@tonic-gate id_fmt = extract_format(id_norm, msgid, osz);
416*7c478bd9Sstevel@tonic-gate if (id_fmt == -1) {
417*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INVALID_FMT), id_num, cur_po);
418*7c478bd9Sstevel@tonic-gate po_error++;
419*7c478bd9Sstevel@tonic-gate }
420*7c478bd9Sstevel@tonic-gate
421*7c478bd9Sstevel@tonic-gate if (!plural) {
422*7c478bd9Sstevel@tonic-gate /* no plural */
423*7c478bd9Sstevel@tonic-gate
424*7c478bd9Sstevel@tonic-gate nsz = str_len * 2;
425*7c478bd9Sstevel@tonic-gate str_norm = (char *)Xcalloc(1, nsz);
426*7c478bd9Sstevel@tonic-gate str_fmt = extract_format(str_norm, msgstr, nsz);
427*7c478bd9Sstevel@tonic-gate if (str_fmt == -1) {
428*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INVALID_FMT), str_num, cur_po);
429*7c478bd9Sstevel@tonic-gate po_error++;
430*7c478bd9Sstevel@tonic-gate }
431*7c478bd9Sstevel@tonic-gate
432*7c478bd9Sstevel@tonic-gate if (id_fmt != str_fmt) {
433*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT),
434*7c478bd9Sstevel@tonic-gate id_num, str_num, cur_po);
435*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT_DIFF_1),
436*7c478bd9Sstevel@tonic-gate id_fmt, str_fmt);
437*7c478bd9Sstevel@tonic-gate po_error++;
438*7c478bd9Sstevel@tonic-gate } else {
439*7c478bd9Sstevel@tonic-gate for (n = 0; n < id_fmt; n++) {
440*7c478bd9Sstevel@tonic-gate if ((id_norm[n * 2] !=
441*7c478bd9Sstevel@tonic-gate str_norm[n * 2]) ||
442*7c478bd9Sstevel@tonic-gate (id_norm[n * 2 + 1] !=
443*7c478bd9Sstevel@tonic-gate str_norm[n * 2 + 1])) {
444*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT),
445*7c478bd9Sstevel@tonic-gate id_num, str_num, cur_po);
446*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT_DIFF_2),
447*7c478bd9Sstevel@tonic-gate n + 1);
448*7c478bd9Sstevel@tonic-gate po_error++;
449*7c478bd9Sstevel@tonic-gate }
450*7c478bd9Sstevel@tonic-gate }
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate free(str_norm);
453*7c478bd9Sstevel@tonic-gate free(id_norm);
454*7c478bd9Sstevel@tonic-gate
455*7c478bd9Sstevel@tonic-gate return;
456*7c478bd9Sstevel@tonic-gate }
457*7c478bd9Sstevel@tonic-gate
458*7c478bd9Sstevel@tonic-gate /* plural */
459*7c478bd9Sstevel@tonic-gate nsz = plural_len * 2;
460*7c478bd9Sstevel@tonic-gate plural_norm = (char *)Xcalloc(1, nsz);
461*7c478bd9Sstevel@tonic-gate plural_fmt = extract_format(plural_norm, plural, nsz);
462*7c478bd9Sstevel@tonic-gate if (plural_fmt == -1) {
463*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INVALID_FMT), plural_num, cur_po);
464*7c478bd9Sstevel@tonic-gate po_error++;
465*7c478bd9Sstevel@tonic-gate }
466*7c478bd9Sstevel@tonic-gate
467*7c478bd9Sstevel@tonic-gate pstr_norm = (char **)Xcalloc(str->no, sizeof (char *));
468*7c478bd9Sstevel@tonic-gate pstr_fmt = (int *)Xcalloc(str->no, sizeof (int));
469*7c478bd9Sstevel@tonic-gate for (i = 0; i < str->no; i++) {
470*7c478bd9Sstevel@tonic-gate p = str->pos + i;
471*7c478bd9Sstevel@tonic-gate nsz = p->len * 2;
472*7c478bd9Sstevel@tonic-gate pstr_norm[i] = (char *)Xcalloc(1, nsz);
473*7c478bd9Sstevel@tonic-gate pstr_fmt[i] = extract_format(pstr_norm[i],
474*7c478bd9Sstevel@tonic-gate msgstr + p->off, nsz);
475*7c478bd9Sstevel@tonic-gate if (pstr_fmt[i] == -1) {
476*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INVALID_FMT),
477*7c478bd9Sstevel@tonic-gate p->num, cur_po);
478*7c478bd9Sstevel@tonic-gate po_error++;
479*7c478bd9Sstevel@tonic-gate }
480*7c478bd9Sstevel@tonic-gate }
481*7c478bd9Sstevel@tonic-gate
482*7c478bd9Sstevel@tonic-gate /* between msgid and msgid_plural */
483*7c478bd9Sstevel@tonic-gate if (id_fmt != plural_fmt) {
484*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT),
485*7c478bd9Sstevel@tonic-gate id_num, plural_num, cur_po);
486*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT_DIFF_1),
487*7c478bd9Sstevel@tonic-gate id_fmt, plural_fmt);
488*7c478bd9Sstevel@tonic-gate po_error++;
489*7c478bd9Sstevel@tonic-gate } else {
490*7c478bd9Sstevel@tonic-gate for (n = 0; n < id_fmt; n++) {
491*7c478bd9Sstevel@tonic-gate if ((id_norm[n * 2] !=
492*7c478bd9Sstevel@tonic-gate plural_norm[n * 2]) ||
493*7c478bd9Sstevel@tonic-gate (id_norm[n * 2 + 1] !=
494*7c478bd9Sstevel@tonic-gate plural_norm[n * 2 + 1])) {
495*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT),
496*7c478bd9Sstevel@tonic-gate id_num, plural_num, cur_po);
497*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT_DIFF_2),
498*7c478bd9Sstevel@tonic-gate n + 1);
499*7c478bd9Sstevel@tonic-gate po_error++;
500*7c478bd9Sstevel@tonic-gate }
501*7c478bd9Sstevel@tonic-gate }
502*7c478bd9Sstevel@tonic-gate }
503*7c478bd9Sstevel@tonic-gate free(plural_norm);
504*7c478bd9Sstevel@tonic-gate
505*7c478bd9Sstevel@tonic-gate /* between msgid and msgstr */
506*7c478bd9Sstevel@tonic-gate for (i = 0; i < str->no; i++) {
507*7c478bd9Sstevel@tonic-gate p = str->pos + i;
508*7c478bd9Sstevel@tonic-gate if (id_fmt != pstr_fmt[i]) {
509*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT),
510*7c478bd9Sstevel@tonic-gate id_num, p->num, cur_po);
511*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT_DIFF_1),
512*7c478bd9Sstevel@tonic-gate id_fmt, pstr_fmt[i]);
513*7c478bd9Sstevel@tonic-gate po_error++;
514*7c478bd9Sstevel@tonic-gate } else {
515*7c478bd9Sstevel@tonic-gate for (n = 0; n < id_fmt; n++) {
516*7c478bd9Sstevel@tonic-gate if ((id_norm[n * 2] !=
517*7c478bd9Sstevel@tonic-gate pstr_norm[i][n * 2]) ||
518*7c478bd9Sstevel@tonic-gate (id_norm[n * 2 + 1] !=
519*7c478bd9Sstevel@tonic-gate pstr_norm[i][n * 2 + 1])) {
520*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT),
521*7c478bd9Sstevel@tonic-gate id_num, p->num, cur_po);
522*7c478bd9Sstevel@tonic-gate diag(gettext(ERR_INCMP_FMT_DIFF_2),
523*7c478bd9Sstevel@tonic-gate n + 1);
524*7c478bd9Sstevel@tonic-gate po_error++;
525*7c478bd9Sstevel@tonic-gate }
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate }
528*7c478bd9Sstevel@tonic-gate free(pstr_norm[i]);
529*7c478bd9Sstevel@tonic-gate }
530*7c478bd9Sstevel@tonic-gate free(pstr_norm);
531*7c478bd9Sstevel@tonic-gate free(pstr_fmt);
532*7c478bd9Sstevel@tonic-gate free(id_norm);
533*7c478bd9Sstevel@tonic-gate }
534