5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2001 by Sun Microsystems, Inc.
24 * All rights reserved.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include "gnu_msgfmt.h"
31 static int plural_index
;
44 %token
<num
> MSGID_PLURAL
51 %type
<msg
> message_string plural_messages plural_message
74 body
: MSGID message_string MSGSTR message_string
76 struct entry och1
, och2
;
90 handle_message
(&och1
, &och2
);
93 | MSGID message_string MSGID_PLURAL
94 message_string
{plural_index
= 0;} plural_messages
97 struct entry och1
, och2
;
101 len
= $2.len
+ $4.len
;
102 id_str
= (char *)Xmalloc
(len
);
103 (void) memcpy
(id_str
, $2.str
, $2.len
);
104 (void) memcpy
(id_str
+ $2.len
, $4.str
, $4.len
);
108 pos1
= (struct loc
*)Xmalloc
(2 * sizeof
(struct loc
));
110 pos1
[0].len
= $2.len
;
112 pos1
[1].off
= $2.len
;
113 pos1
[1].len
= $4.len
;
122 handle_message
(&och1
, &och2
);
125 | MSGID message_string
127 error(gettext
(ERR_NO_MSGSTR
), $1, cur_po
);
130 | MSGID message_string MSGID_PLURAL message_string
132 error(gettext
(ERR_NO_MSGSTRS
), $1, cur_po
);
135 | MSGID message_string plural_messages
137 error(gettext
(ERR_NO_MSGID_PLURAL
), $1, cur_po
);
145 $$.len
= strlen
($1) + 1;
149 size_t len
, len1
, len2
;
152 /* $1.len includes null-termination */
156 /* len doesn't include null-termination */
159 str
= (char *)Xmalloc
(len
+ 1);
160 (void) memcpy
(str
, $1.str
, len1
);
161 (void) memcpy
(str
+ len1
, $2, len2
+ 1);
169 plural_messages
: plural_message
173 | plural_messages plural_message
181 tmp
= (struct loc
*)Xrealloc
($1.pos
,
182 no
* sizeof
(struct loc
));
183 tmp
[no
- 1].off
= $1.len
;
184 tmp
[no
- 1].len
= $2.len
;
185 tmp
[no
- 1].num
= $2.num
;
188 len
= $1.len
+ $2.len
;
189 plural_str
= (char *)Xmalloc
(len
);
190 (void) memcpy
(plural_str
, $1.str
, $1.len
);
191 (void) memcpy
(plural_str
+ $1.len
, $2.str
, $2.len
);
203 plural_message
: MSGSTR
'[' NUM
']' message_string
206 if
($3 != plural_index
) {
207 error(gettext
(ERR_INVALID_PLURALS
), $1, cur_po
);
211 pos
= (struct loc
*)Xmalloc
(sizeof
(struct loc
));
224 yyerror(const char *err
)
226 (void) fprintf
(stderr
,
227 gettext
(ERR_LOCATION
), cur_line
, cur_po
);
228 (void) fprintf
(stderr
, "%s\n", err
);