5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 extern
int is_cat_found
; /* from main.c */
34 extern
int lineno
; /* genmsg.l */
35 extern
int msg_line
; /* genmsg.l */
36 extern
int end_of_cat
; /* from genmsg.l */
37 extern
void set_linemsgid
(int, int); /* from genmsg.l */
38 extern
void add_msg
(int, int, char *, char *, int, int); /* from util.c */
39 extern
void set_msgid
(int, int);
40 extern
int get_msgid
(char *, int, int, char *);
41 extern
void warning
(char *);
42 extern
void yyerror(char *);
44 static void do_catgets
(int, int, char *);
45 static char *add_qstring
(char *, char *);
58 %token
<id
> SETID
, MSGID
, DIGIT
61 %type
<id
> cast_setid
, setid
, cast_msgid
, msgid
, cast_digit
, digit
62 %type
<str
> catd
, arg_list
, arg_def
, arg_func
, arg_exp
, str
,
63 cast_qstr
, paren_qstr
, qstr_list
71 genmsg_list: /* empty */
73 if
(!IsActiveMode
(ReplaceMode
)) {
74 src_err
(srcfile
, (lineno
- 1),
75 gettext
("catgets not found"));
78 | genmsg
{ is_cat_found
= TRUE
; }
81 genmsg: catgets
{ end_of_cat
= TRUE
; }
82 | genmsg catgets
{ end_of_cat
= TRUE
; }
85 catgets: CATGETS
'(' catd
',' cast_setid
',' cast_msgid
',' cast_qstr
')'
87 do_catgets
($5, $7, $9); free
($9);
92 catd: '(' CATD
')' arg_list
{ $$
= $4; }
93 |
'(' CONST CATD
')' arg_list
{ $$
= $5; }
98 | arg_list
'-' '>' arg_def
99 |
'(' arg_list
'-' '>' arg_def
')' { $$
= $2; }
107 arg_func: '(' arg_func
')' { $$
= $2; }
110 | str
'(' cast_digit
')'
111 | str
'(' cast_qstr
')' { free
($3); }
114 arg_exp: '(' arg_exp
')' { $$
= $2; }
116 | INC str
{ $$
= $2; }
119 str: '(' str
')' { $$
= $2; }
120 |
'*' str
{ $$
= $2; }
124 cast_setid: '(' INT
')' setid
{ $$
= $4; }
125 |
'(' CONST INT
')' setid
{ $$
= $5; }
129 setid: setid
'+' setid
{ $$
= $1 + $3; }
130 | setid
'-' setid
{ $$
= $1 - $3; }
131 | setid
'*' setid
{ $$
= $1 * $3; }
135 yyerror(gettext
("zero divide"));
140 |
'-' setid %prec UMINUS
{ $$
= -$2; }
141 |
'(' setid
')' { $$
= $2; }
145 cast_msgid: '(' INT
')' msgid
{ $$
= $4; }
146 |
'(' CONST INT
')' msgid
{ $$
= $5; }
150 msgid: msgid
'+' msgid
{ $$
= $1 + $3; }
151 | msgid
'-' msgid
{ $$
= $1 - $3; }
152 | msgid
'*' msgid
{ $$
= $1 * $3; }
156 yyerror(gettext
("zero devide"));
161 |
'-' msgid %prec UMINUS
{ $$
= -$2; }
162 |
'(' msgid
')' { $$
= $2; }
166 cast_digit: '(' INT
')' digit
{ $$
= $4; }
167 |
'(' CONST INT
')' digit
{ $$
= $5; }
171 digit: digit
'+' digit
{ $$
= $1 + $3; }
172 | digit
'-' digit
{ $$
= $1 - $3; }
173 | digit
'*' digit
{ $$
= $1 * $3; }
177 yyerror(gettext
("zero divide"));
182 |
'-' digit %prec UMINUS
{ $$
= -$2; }
183 |
'(' digit
')' { $$
= $2; }
187 cast_qstr: '(' CHAR
'*' ')' paren_qstr
{ $$
= $5; }
188 |
'(' CONST CHAR
'*' ')' paren_qstr
{ $$
= $6; }
192 paren_qstr: '(' qstr_list
')' { $$
= $2; }
197 | qstr_list QSTR
{ $$
= add_qstring
($1, $2); }
203 do_catgets
(int setid
, int msgid
, char *str
)
206 if
(IsActiveMode
(ReplaceMode
)) {
209 if
(setid
== 0 || setid
> NL_SETMAX
) {
210 src_err
(srcfile
, lineno
,
211 gettext
("improper set number: %d"), setid
);
214 if
(IsActiveMode
(ProjectMode
)) {
215 set_msgid
(setid
, id
);
216 add_msg
(setid
, id
, str
, srcfile
, lineno
, TRUE
);
217 } else if
(IsActiveMode
(ReverseMode
)) {
218 set_linemsgid
(msg_line
, NOMSGID
);
219 } else if
(IsActiveMode
(AutoNumMode
)) {
221 id
= get_msgid
(srcfile
, msg_line
, setid
, str
);
222 set_linemsgid
(msg_line
, id
);
225 set_msgid
(setid
, id
);
226 add_msg
(setid
, id
, str
, srcfile
, lineno
, FALSE
);
228 } else if
(id
== NOMSGID
) {
229 warning
(gettext
("improper message number: -1"));
231 add_msg
(setid
, id
, str
, srcfile
, lineno
, FALSE
);
236 add_qstring
(char *str
, char *add
)
238 int len
= strlen
(str
) + strlen
(add
) + 3;
239 /* 3 includes '\', '\n' and '\0' */
240 char *tmp
= malloc
(len
);
242 prg_err
(gettext
("fatal: out of memory"));
245 (void) snprintf
(tmp
, len
, "%s\\\n%s", str
, add
);