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