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 *);
43 extern
int yylex(void);
45 static void do_catgets
(int, int, char *);
46 static char *add_qstring
(char *, char *);
59 %token
<id
> SETID
, MSGID
, DIGIT
62 %type
<id
> cast_setid
, setid
, cast_msgid
, msgid
, cast_digit
, digit
63 %type
<str
> catd
, arg_list
, arg_def
, arg_func
, arg_exp
, str
,
64 cast_qstr
, paren_qstr
, qstr_list
72 genmsg_list: /* empty */
74 if
(!IsActiveMode
(ReplaceMode
)) {
75 src_err
(srcfile
, (lineno
- 1),
76 gettext
("catgets not found"));
79 | genmsg
{ is_cat_found
= TRUE
; }
82 genmsg: catgets
{ end_of_cat
= TRUE
; }
83 | genmsg catgets
{ end_of_cat
= TRUE
; }
86 catgets: CATGETS
'(' catd
',' cast_setid
',' cast_msgid
',' cast_qstr
')'
88 do_catgets
($5, $7, $9); free
($9);
93 catd: '(' CATD
')' arg_list
{ $$
= $4; }
94 |
'(' CONST CATD
')' arg_list
{ $$
= $5; }
99 | arg_list
'-' '>' arg_def
100 |
'(' arg_list
'-' '>' arg_def
')' { $$
= $2; }
108 arg_func: '(' arg_func
')' { $$
= $2; }
111 | str
'(' cast_digit
')'
112 | str
'(' cast_qstr
')' { free
($3); }
115 arg_exp: '(' arg_exp
')' { $$
= $2; }
117 | INC str
{ $$
= $2; }
120 str: '(' str
')' { $$
= $2; }
121 |
'*' str
{ $$
= $2; }
125 cast_setid: '(' INT
')' setid
{ $$
= $4; }
126 |
'(' CONST INT
')' setid
{ $$
= $5; }
130 setid: setid
'+' setid
{ $$
= $1 + $3; }
131 | setid
'-' setid
{ $$
= $1 - $3; }
132 | setid
'*' setid
{ $$
= $1 * $3; }
136 yyerror(gettext
("zero divide"));
141 |
'-' setid %prec UMINUS
{ $$
= -$2; }
142 |
'(' setid
')' { $$
= $2; }
146 cast_msgid: '(' INT
')' msgid
{ $$
= $4; }
147 |
'(' CONST INT
')' msgid
{ $$
= $5; }
151 msgid: msgid
'+' msgid
{ $$
= $1 + $3; }
152 | msgid
'-' msgid
{ $$
= $1 - $3; }
153 | msgid
'*' msgid
{ $$
= $1 * $3; }
157 yyerror(gettext
("zero devide"));
162 |
'-' msgid %prec UMINUS
{ $$
= -$2; }
163 |
'(' msgid
')' { $$
= $2; }
167 cast_digit: '(' INT
')' digit
{ $$
= $4; }
168 |
'(' CONST INT
')' digit
{ $$
= $5; }
172 digit: digit
'+' digit
{ $$
= $1 + $3; }
173 | digit
'-' digit
{ $$
= $1 - $3; }
174 | digit
'*' digit
{ $$
= $1 * $3; }
178 yyerror(gettext
("zero divide"));
183 |
'-' digit %prec UMINUS
{ $$
= -$2; }
184 |
'(' digit
')' { $$
= $2; }
188 cast_qstr: '(' CHAR
'*' ')' paren_qstr
{ $$
= $5; }
189 |
'(' CONST CHAR
'*' ')' paren_qstr
{ $$
= $6; }
193 paren_qstr: '(' qstr_list
')' { $$
= $2; }
198 | qstr_list QSTR
{ $$
= add_qstring
($1, $2); }
204 do_catgets
(int setid
, int msgid
, char *str
)
207 if
(IsActiveMode
(ReplaceMode
)) {
210 if
(setid
== 0 || setid
> NL_SETMAX
) {
211 src_err
(srcfile
, lineno
,
212 gettext
("improper set number: %d"), setid
);
215 if
(IsActiveMode
(ProjectMode
)) {
216 set_msgid
(setid
, id
);
217 add_msg
(setid
, id
, str
, srcfile
, lineno
, TRUE
);
218 } else if
(IsActiveMode
(ReverseMode
)) {
219 set_linemsgid
(msg_line
, NOMSGID
);
220 } else if
(IsActiveMode
(AutoNumMode
)) {
222 id
= get_msgid
(srcfile
, msg_line
, setid
, str
);
223 set_linemsgid
(msg_line
, id
);
226 set_msgid
(setid
, id
);
227 add_msg
(setid
, id
, str
, srcfile
, lineno
, FALSE
);
229 } else if
(id
== NOMSGID
) {
230 warning
(gettext
("improper message number: -1"));
232 add_msg
(setid
, id
, str
, srcfile
, lineno
, FALSE
);
237 add_qstring
(char *str
, char *add
)
239 int len
= strlen
(str
) + strlen
(add
) + 3;
240 /* 3 includes '\', '\n' and '\0' */
241 char *tmp
= malloc
(len
);
243 prg_err
(gettext
("fatal: out of memory"));
246 (void) snprintf
(tmp
, len
, "%s\\\n%s", str
, add
);