xref: /titanic_41/usr/src/cmd/msgfmt/xgettext.lx.l (revision c037192b037119c9fd354732fc29b38ce097d356)
1 %{
2 /*
3  * CDDL HEADER START
4  *
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
8  * with the License.
9  *
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.
14  *
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]
20  *
21  * CDDL HEADER END
22  *
23  * Copyright (c) 1991, 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <stdio.h>
29 #include <string.h>
30 
31 #define	TRUE	1
32 #define	FALSE	0
33 
34 extern int	stdin_only;
35 extern char	curr_file[];	/* Name of file currently being read. */
36 extern int	curr_linenum;	/* line number in the current input file */
37 extern int	warn_linenum;	/* line number of current warning message */
38 extern int	optind;
39 extern int	gargc;
40 extern char	**gargv;
41 
42 extern void	handle_macro_line(void);
43 extern void	handle_cplus_comment_line(void);
44 extern void	handle_open_comment(void);
45 extern void	handle_close_comment(void);
46 extern void	handle_gettext(void);
47 extern void	handle_dgettext(void);
48 extern void	handle_dcgettext(void);
49 extern void	handle_textdomain(void);
50 extern void	handle_character(void);
51 extern void	handle_open_paren(void);
52 extern void	handle_close_paren(void);
53 extern void	handle_esc_newline(void);
54 extern void	handle_comma(void);
55 extern void	handle_newline(void);
56 extern void	handle_quote(void);
57 extern void	handle_spaces(void);
58 extern void	handle_spaces(void);
59 extern void	handle_character(void);
60 
61 /*
62  * The following lex rule basically wants to recognize tokens
63  * that can change the current state of scanning source code.
64  * Evertime such tokens are recognized, the specific handler will be
65  * executed. All other tokens are treated as regular characters and
66  * they are all handled the same way.
67  * The tricky part was not to miss any specification in ANSI-C code
68  * that looks like a meaningful token but not a meaningful one and
69  * should be treated as regular characters.
70  * For example,
71  *	c= '"';d='"'; printf("\"" "\(\)\\\"");
72  *	c = ABgettext("Not a gettext");
73  *	c = gettextXY("Not a gettext");
74  *	c = ABgettextXY("Not a gettext");
75  */
76 %}
77 
78 IDCHARS		[a-zA-Z0-9_]
79 
80 %%
81 ^#(.*\\\n)**.*\n	{ handle_macro_line(); }
82 
83 \/\/		{ handle_cplus_comment_line(); }
84 
85 \/\* 		{ handle_open_comment(); }
86 
87 \*\/ 		{ handle_close_comment(); }
88 
89 dcgettext	{ handle_dcgettext(); }
90 
91 dgettext	{ handle_dgettext(); }
92 
93 gettext		{ handle_gettext(); }
94 
95 textdomain	{ handle_textdomain(); }
96 
97 {IDCHARS}+	|
98 \'\"\'		|
99 \'\\\"\'	|
100 \\\\		|
101 \\\"		|
102 \\\(		|
103 \\\)		{ handle_character(); }
104 
105 \(		{ handle_open_paren(); }
106 
107 \)		{ handle_close_paren(); }
108 
109 \\\n		{ handle_esc_newline(); }
110 
111 \,		{ handle_comma(); }
112 
113 \n		{ handle_newline(); }
114 
115 \"		{ handle_quote(); }
116 
117 " "		{ handle_spaces(); }
118 
119 "\t"		{ handle_spaces(); }
120 
121 .		{ handle_character(); }
122 
123 %%
124 
125 /*
126  * Since multiple files can be processed, yywrap() should keep feeding
127  * all input files specified.
128  */
129 int
130 yywrap(void)
131 {
132 	FILE	*fp;
133 
134 	if ((optind >= gargc) || (stdin_only == TRUE)) {
135 		return (1);
136 	} else {
137 		/*
138 		 * gargv still contains not-processed input files.
139 		 */
140 		(void) freopen(gargv[optind], "r", stdin);
141 		if ((fp = freopen(gargv[optind], "r", stdin)) == NULL) {
142 			(void) fprintf(stderr, "ERROR, can't open input file: %s\n",
143 					gargv[optind]);
144 		}
145 #ifdef DEBUG
146 		(void) printf("In yywrap(), opening file  %d, <%s>\n",
147 				optind, gargv[optind]);
148 #endif
149 		/*
150 		 * Reset global file name and line number for the new file.
151 		 */
152 		(void) strcpy(curr_file, gargv[optind]);
153 		curr_linenum = 0;
154 		warn_linenum = 0;
155 
156 		optind++;
157 
158 		return (0);
159 	}
160 
161 } /* yywrap */
162