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