xref: /AOO41X/main/l10ntools/source/cfglex.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 cfg source files
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 InitCfgExport( char * , char *);
56cdf0e10cSrcweir extern int EndCfgExport();
57cdf0e10cSrcweir extern int GetError();
58cdf0e10cSrcweir extern int SetError();
59cdf0e10cSrcweir extern char *GetOutputFile( int argc, char* argv[]);
60cdf0e10cSrcweir extern FILE *GetCfgFile();
61cdf0e10cSrcweir extern int isQuiet();
62cdf0e10cSrcweir extern void removeTempFile();
63cdf0e10cSrcweir extern char* getFilename();
64cdf0e10cSrcweir /* forwards */
65cdf0e10cSrcweir void YYWarning();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir int bText=0;
68cdf0e10cSrcweir %}
69cdf0e10cSrcweir 
70cdf0e10cSrcweir %p 24000
71cdf0e10cSrcweir %e 1200
72cdf0e10cSrcweir %n 500
73cdf0e10cSrcweir 
74cdf0e10cSrcweir %%
75cdf0e10cSrcweir 
76cdf0e10cSrcweir \<[^\>]*"xml:lang="\""x-no-translate"\"[^\<]*\/\>	{
77cdf0e10cSrcweir 	bText = 0;
78cdf0e10cSrcweir 	WorkOnTokenSet( CFG_TOKEN_NO_TRANSLATE, yytext );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir \<.*\/\> {
82cdf0e10cSrcweir 	bText = 0;
83cdf0e10cSrcweir 	WorkOnTokenSet( ANYTOKEN, yytext );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir \<[^\>]*"xml:lang="\".*\"[^\<]*\>	{
87cdf0e10cSrcweir 	bText = 1;
88cdf0e10cSrcweir 	WorkOnTokenSet( CFG_TEXT_START, yytext );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir \<[^\/\!][^\>]*\>	{
93cdf0e10cSrcweir 	bText = 0;
94cdf0e10cSrcweir 	WorkOnTokenSet( CFG_TAG, yytext );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir "<!"DOCTYPE[^\>]*\>	{
98cdf0e10cSrcweir 	bText = 0;
99cdf0e10cSrcweir 	WorkOnTokenSet( CFG_TAG, yytext );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir \<\!\-\-	{
104cdf0e10cSrcweir 	char c1 = 0, c2 = 0, c3 = input();
105cdf0e10cSrcweir 	char pChar[2];
106cdf0e10cSrcweir 	pChar[1] = 0x00;
107cdf0e10cSrcweir 	pChar[0] = c3;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	WorkOnTokenSet( COMMEND, yytext );
110cdf0e10cSrcweir 	WorkOnTokenSet( COMMEND, pChar );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	for(;;) {
113cdf0e10cSrcweir 		if ( c3 == EOF )
114cdf0e10cSrcweir 			break;
115cdf0e10cSrcweir 		if ( c1 == '-' && c2 == '-' && c3 == '>' )
116cdf0e10cSrcweir 			break;
117cdf0e10cSrcweir 		c1 = c2;
118cdf0e10cSrcweir 		c2 = c3;
119cdf0e10cSrcweir 		c3 = input();
120cdf0e10cSrcweir 		pChar[0] = c3;
121cdf0e10cSrcweir 		WorkOnTokenSet( COMMEND, pChar );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir \<\/[^\>]*\> {
126cdf0e10cSrcweir 	bText = 0;
127cdf0e10cSrcweir 	WorkOnTokenSet( CFG_CLOSETAG, yytext );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir \<[^\>\!]*\> {
131cdf0e10cSrcweir 	bText = 0;
132cdf0e10cSrcweir 	if ( yytext[ 1 ] == '!' && yytext[ 2 ] == '-' && yytext[ 3 ] == '-' )
133cdf0e10cSrcweir 		WorkOnTokenSet( COMMEND, yytext );
134cdf0e10cSrcweir 	else
135cdf0e10cSrcweir 		WorkOnTokenSet( CFG_UNKNOWNTAG, yytext );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir .|\n {
139cdf0e10cSrcweir 	if ( bText == 1 )
140cdf0e10cSrcweir 		WorkOnTokenSet( CFG_TEXTCHAR, yytext );
141cdf0e10cSrcweir 	else
142cdf0e10cSrcweir 		WorkOnTokenSet( UNKNOWNCHAR, yytext );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir %%
147cdf0e10cSrcweir 
148cdf0e10cSrcweir /*****************************************************************************/
149cdf0e10cSrcweir int	yywrap(void)
150cdf0e10cSrcweir /*****************************************************************************/
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	return 1;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir /*****************************************************************************/
156cdf0e10cSrcweir void YYWarning( char *s )
157cdf0e10cSrcweir /*****************************************************************************/
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	/* write warning to stderr */
160cdf0e10cSrcweir 	fprintf( stderr,
161cdf0e10cSrcweir 		"Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir /*****************************************************************************/
165cdf0e10cSrcweir #ifdef GCC
166cdf0e10cSrcweir void yyerror ( char *s, ... )
167cdf0e10cSrcweir #else
168cdf0e10cSrcweir void yyerror ( char *s )
169cdf0e10cSrcweir #endif
170cdf0e10cSrcweir /*****************************************************************************/
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	/* write error to stderr */
173cdf0e10cSrcweir 	fprintf( stderr,
174cdf0e10cSrcweir 		"Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
175cdf0e10cSrcweir 	SetError();
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir /*****************************************************************************/
179cdf0e10cSrcweir int
180cdf0e10cSrcweir #ifdef WNT
181cdf0e10cSrcweir _cdecl
182cdf0e10cSrcweir #endif
183cdf0e10cSrcweir main( int argc, char* argv[])
184cdf0e10cSrcweir /*****************************************************************************/
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	/* error level */
187cdf0e10cSrcweir 	int nRetValue = 0;
188cdf0e10cSrcweir 	char *pOutput;
189cdf0e10cSrcweir 	FILE *pFile;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	pOutput = GetOutputFile( argc, argv );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     if ( !pOutput ) {
194cdf0e10cSrcweir 		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" );
195cdf0e10cSrcweir 		fprintf( stdout, " Prj:      Project\n" );
196cdf0e10cSrcweir 		fprintf( stdout, " PrjRoot:  Path to project root (..\\.. etc.)\n" );
197cdf0e10cSrcweir 		fprintf( stdout, " FileIn:   Source files (*.src)\n" );
198cdf0e10cSrcweir 		fprintf( stdout, " FileOut:  Destination file (*.*)\n" );
199cdf0e10cSrcweir 		fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
200cdf0e10cSrcweir         fprintf( stdout, " -e: Disable writing errorlog\n" );
201cdf0e10cSrcweir 		fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" );
202cdf0e10cSrcweir 		fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" );
203cdf0e10cSrcweir 		fprintf( stdout, " -f: force extraction and merge even if only one language is existent\n" );
204cdf0e10cSrcweir 		fprintf( stdout, " -g[:dtd]: enables generation of properties (dtds if :dtd is set) - in this case FileOut is the output path\n" );
205cdf0e10cSrcweir 		fprintf( stdout, " -d: enables generation of *.don if work is done\n" );
206cdf0e10cSrcweir 		fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
207cdf0e10cSrcweir 		fprintf( stdout, "     A fallback language can be defined like this: l1=f1.\n" );
208cdf0e10cSrcweir 		fprintf( stdout, "     f1, f2,... are also elements of (de,en-US...)\n" );
209cdf0e10cSrcweir 		fprintf( stdout, "     Example: -L de,es=en-US\n" );
210cdf0e10cSrcweir 		fprintf( stdout, "              Restriction to de and es, en-US will be fallback for es\n" );
211cdf0e10cSrcweir 		return 1;
212cdf0e10cSrcweir 	}
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	pFile = GetCfgFile();
215cdf0e10cSrcweir 	InitCfgExport( pOutput , getFilename() );
216cdf0e10cSrcweir 	if ( !pFile )
217cdf0e10cSrcweir 		return 1;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir    	yyin = pFile;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	/* create global instance of class CfgExport */
222cdf0e10cSrcweir 	//InitCfgExport( pOutput );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	/* start parser */
225cdf0e10cSrcweir    	yylex();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	/* get error info. and end export */
228cdf0e10cSrcweir 	nRetValue = GetError();
229cdf0e10cSrcweir 	EndCfgExport();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     removeTempFile();
233cdf0e10cSrcweir /* return error level */
234cdf0e10cSrcweir 	return nRetValue;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 
238