xref: /aoo41x/main/l10ntools/source/cfglex.l (revision 45ef6fe1)
1 %{
2 /**************************************************************
3  *
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  *
21  *************************************************************/
22 /*
23  * lexer for parsing cfg source files
24  *
25  */
26 
27 
28 /* enlarge token buffer to tokenize whole strings */
29 #undef YYLMAX
30 #define YYLMAX 64000
31 
32 /* to enable debug output define LEXDEBUG */
33 #define LEXDEBUG		1
34 #ifdef LEXDEBUG
35 #define OUTPUT	fprintf
36 #else
37 #define OUTPUT(Par1,Par2);
38 #endif
39 
40 /* table of possible token ids */
41 #include "tokens.h"
42 #include <stdlib.h>
43 #include <stdio.h>
44 
45 #if defined __GNUC__
46 #pragma GCC system_header
47 #elif defined __SINPRO_CC
48 #pragma disable_warn
49 #elif defined _MSC_VER
50 #pragma warning(push, 1)
51 #endif
52 
53 /* external functions (C++ code, declared as extren "C" */
54 extern int WorkOnTokenSet( int, char* );
55 extern int InitCfgExport( char * , char *);
56 extern int EndCfgExport();
57 extern int GetError();
58 extern int SetError();
59 extern char *GetOutputFile( int argc, char* argv[]);
60 extern FILE *GetCfgFile();
61 extern int isQuiet();
62 extern void removeTempFile();
63 extern char* getFilename();
64 /* forwards */
65 void YYWarning();
66 
67 int bText=0;
68 %}
69 
70 %p 24000
71 %e 1200
72 %n 500
73 
74 %%
75 
76 \<[^\>]*"xml:lang="\""x-no-translate"\"[^\<]*\/\>	{
77 	bText = 0;
78 	WorkOnTokenSet( CFG_TOKEN_NO_TRANSLATE, yytext );
79 }
80 
81 \<.*\/\> {
82 	bText = 0;
83 	WorkOnTokenSet( ANYTOKEN, yytext );
84 }
85 
86 \<[^\>]*"xml:lang="\".*\"[^\<]*\>	{
87 	bText = 1;
88 	WorkOnTokenSet( CFG_TEXT_START, yytext );
89 }
90 
91 
92 \<[^\/\!][^\>]*\>	{
93 	bText = 0;
94 	WorkOnTokenSet( CFG_TAG, yytext );
95 }
96 
97 "<!"DOCTYPE[^\>]*\>	{
98 	bText = 0;
99 	WorkOnTokenSet( CFG_TAG, yytext );
100 }
101 
102 
103 \<\!\-\-	{
104 	char c1 = 0, c2 = 0, c3 = input();
105 	char pChar[2];
106 	pChar[1] = 0x00;
107 	pChar[0] = c3;
108 
109 	WorkOnTokenSet( COMMEND, yytext );
110 	WorkOnTokenSet( COMMEND, pChar );
111 
112 	for(;;) {
113 		if ( c3 == EOF )
114 			break;
115 		if ( c1 == '-' && c2 == '-' && c3 == '>' )
116 			break;
117 		c1 = c2;
118 		c2 = c3;
119 		c3 = input();
120 		pChar[0] = c3;
121 		WorkOnTokenSet( COMMEND, pChar );
122 	}
123 }
124 
125 \<\/[^\>]*\> {
126 	bText = 0;
127 	WorkOnTokenSet( CFG_CLOSETAG, yytext );
128 }
129 
130 \<[^\>\!]*\> {
131 	bText = 0;
132 	if ( yytext[ 1 ] == '!' && yytext[ 2 ] == '-' && yytext[ 3 ] == '-' )
133 		WorkOnTokenSet( COMMEND, yytext );
134 	else
135 		WorkOnTokenSet( CFG_UNKNOWNTAG, yytext );
136 }
137 
138 .|\n {
139 	if ( bText == 1 )
140 		WorkOnTokenSet( CFG_TEXTCHAR, yytext );
141 	else
142 		WorkOnTokenSet( UNKNOWNCHAR, yytext );
143 }
144 
145 
146 %%
147 
148 /*****************************************************************************/
149 int	yywrap(void)
150 /*****************************************************************************/
151 {
152 	return 1;
153 }
154 
155 /*****************************************************************************/
156 void YYWarning( char *s )
157 /*****************************************************************************/
158 {
159 	/* write warning to stderr */
160 	fprintf( stderr,
161 		"Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
162 }
163 
164 /*****************************************************************************/
165 #ifdef GCC
166 void yyerror ( char *s, ... )
167 #else
168 void yyerror ( char *s )
169 #endif
170 /*****************************************************************************/
171 {
172 	/* write error to stderr */
173 	fprintf( stderr,
174 		"Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
175 	SetError();
176 }
177 
178 /*****************************************************************************/
179 int
180 #ifdef WNT
181 _cdecl
182 #endif
183 main( int argc, char* argv[])
184 /*****************************************************************************/
185 {
186 	/* error level */
187 	int nRetValue = 0;
188 	char *pOutput;
189 	FILE *pFile;
190 
191 	pOutput = GetOutputFile( argc, argv );
192 
193     if ( !pOutput ) {
194 		fprintf( stdout, "Syntax: CFGEX[-p Prj][-r PrjRoot]-i FileIn [-o FileOut][-m DataBase][-e][-b][-u][-f][-d DoneFile][-g[:dtd] ][-L l1,l2,...]\n" );
195 		fprintf( stdout, " Prj:      Project\n" );
196 		fprintf( stdout, " PrjRoot:  Path to project root (..\\.. etc.)\n" );
197 		fprintf( stdout, " FileIn:   Source files (*.src)\n" );
198 		fprintf( stdout, " FileOut:  Destination file (*.*)\n" );
199 		fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
200         fprintf( stdout, " -e: Disable writing errorlog\n" );
201 		fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" );
202 		fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" );
203 		fprintf( stdout, " -f: force extraction and merge even if only one language is existent\n" );
204 		fprintf( stdout, " -g[:dtd]: enables generation of properties (dtds if :dtd is set) - in this case FileOut is the output path\n" );
205 		fprintf( stdout, " -d: enables generation of *.don if work is done\n" );
206 		fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
207 		fprintf( stdout, "     A fallback language can be defined like this: l1=f1.\n" );
208 		fprintf( stdout, "     f1, f2,... are also elements of (de,en-US...)\n" );
209 		fprintf( stdout, "     Example: -L de,es=en-US\n" );
210 		fprintf( stdout, "              Restriction to de and es, en-US will be fallback for es\n" );
211 		return 1;
212 	}
213 
214 	pFile = GetCfgFile();
215 	InitCfgExport( pOutput , getFilename() );
216 	if ( !pFile )
217 		return 1;
218 
219    	yyin = pFile;
220 
221 	/* create global instance of class CfgExport */
222 	//InitCfgExport( pOutput );
223 
224 	/* start parser */
225    	yylex();
226 
227 	/* get error info. and end export */
228 	nRetValue = GetError();
229 	EndCfgExport();
230 
231 
232     removeTempFile();
233 /* return error level */
234 	return nRetValue;
235 }
236 
237 
238