Line data Source code
1 : %{
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : /*
21 : * lexer for parsing xml-property source files (*.xml)
22 : */
23 :
24 : /* enlarge token buffer to tokenize whole strings */
25 : #undef YYLMAX
26 : #define YYLMAX 64000
27 :
28 : /* to enable debug output define LEXDEBUG */
29 : #define LEXDEBUG 1
30 : #ifdef LEXDEBUG
31 : #define OUTPUT fprintf
32 : #else
33 : #define OUTPUT(Par1,Par2);
34 : #endif
35 :
36 : /* table of possible token ids */
37 : #include "tokens.h"
38 : #include <stdlib.h>
39 : #include <stdio.h>
40 :
41 : #include "sal/main.h"
42 :
43 : #if defined __GNUC__
44 : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
45 : #pragma GCC diagnostic ignored "-Wunused-function"
46 : #pragma GCC diagnostic ignored "-Wunused-label"
47 : #endif
48 : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
49 : #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
50 : #endif
51 : #elif defined __SINPRO_CC
52 : #pragma disable_warn
53 : #elif defined _MSC_VER
54 : #pragma warning(push, 1)
55 : #endif
56 :
57 : /* external functions (C++ code, declared as extern "C" */
58 : extern "C" int WorkOnTokenSet( int, char* );
59 : extern "C" int Argument( char * );
60 : extern "C" int InitXrmExport( char * , char * );
61 : extern "C" int EndXrmExport();
62 : extern "C" int GetError();
63 : extern "C" int SetError();
64 : extern "C" char *GetOutputFile( int argc, char* argv[]);
65 : extern "C" FILE *GetXrmFile();
66 : extern "C" int isQuiet();
67 : extern "C" char* getFilename();
68 :
69 : /* forwards */
70 : void YYWarning();
71 :
72 : int bText=0;
73 : %}
74 :
75 : %option yylineno
76 : %option never-interactive
77 :
78 : %p 24000
79 : %e 1200
80 : %n 500
81 :
82 : %%
83 :
84 : "<p "[^\>]*xml:lang[^\>]*\> {
85 0 : WorkOnTokenSet( XRM_TEXT_START , yytext );
86 : }
87 0 :
88 : "</p>" {
89 0 : WorkOnTokenSet( XRM_TEXT_END, yytext );
90 : }
91 0 :
92 : "<h1 "[^\>]*xml:lang[^\>]*\> {
93 0 : WorkOnTokenSet( XRM_TEXT_START , yytext );
94 : }
95 0 :
96 : "</h1>" {
97 0 : WorkOnTokenSet( XRM_TEXT_END, yytext );
98 : }
99 0 : "<h2 "[^\>]*xml:lang[^\>]*\> {
100 0 : WorkOnTokenSet( XRM_TEXT_START , yytext );
101 : }
102 0 :
103 : "</h2>" {
104 0 : WorkOnTokenSet( XRM_TEXT_END, yytext );
105 : }
106 0 : "<h3 "[^\>]*xml:lang[^\>]*\> {
107 0 : WorkOnTokenSet( XRM_TEXT_START , yytext );
108 : }
109 0 :
110 : "</h3>" {
111 0 : WorkOnTokenSet( XRM_TEXT_END, yytext );
112 : }
113 0 : "<h4 "[^\>]*xml:lang[^\>]*\> {
114 0 : WorkOnTokenSet( XRM_TEXT_START , yytext );
115 : }
116 0 :
117 : "</h4>" {
118 0 : WorkOnTokenSet( XRM_TEXT_END, yytext );
119 : }
120 0 : "<h5 "[^\>]*xml:lang[^\>]*\> {
121 0 : WorkOnTokenSet( XRM_TEXT_START , yytext );
122 : }
123 0 :
124 : "</h5>" {
125 0 : WorkOnTokenSet( XRM_TEXT_END, yytext );
126 : }
127 0 :
128 : "<display-name>" {
129 0 : WorkOnTokenSet( DESC_DISPLAY_NAME_START , yytext );
130 : }
131 0 :
132 : "</display-name>" {
133 0 : WorkOnTokenSet( DESC_DISPLAY_NAME_END, yytext );
134 : }
135 0 :
136 : "<name "[^\>]*lang[^\>]*\> {
137 0 : WorkOnTokenSet( DESC_TEXT_START , yytext );
138 : }
139 0 :
140 : "</name>" {
141 0 : WorkOnTokenSet( DESC_TEXT_END, yytext );
142 : }
143 0 :
144 : "<extension-description>" {
145 0 : WorkOnTokenSet( DESC_EXTENSION_DESCRIPTION_START , yytext );
146 : }
147 0 :
148 : "</extension-description>" {
149 0 : WorkOnTokenSet( DESC_EXTENSION_DESCRIPTION_END , yytext );
150 : }
151 0 :
152 : "<src "[^\>]*lang[^\>]*\> {
153 0 : WorkOnTokenSet( DESC_EXTENSION_DESCRIPTION_SRC , yytext );
154 : }
155 0 :
156 :
157 :
158 : "<!--" {
159 0 : char c1 = 0, c2 = 0;
160 0 : int c3 = yyinput();
161 : char pChar[2];
162 0 : pChar[1] = 0x00;
163 0 : pChar[0] = c3;
164 :
165 0 : WorkOnTokenSet( COMMENT, yytext );
166 0 : WorkOnTokenSet( COMMENT, pChar );
167 :
168 0 : for(;;) {
169 0 : if ( c3 == EOF )
170 0 : break;
171 0 : if ( c1 == '-' && c2 == '-' && c3 == '>' )
172 0 : break;
173 0 : c1 = c2;
174 0 : c2 = c3;
175 0 : c3 = yyinput();
176 0 : pChar[0] = c3;
177 0 : WorkOnTokenSet( COMMENT, pChar );
178 : }
179 : }
180 0 :
181 : .|\n {
182 0 : if ( bText == 1 )
183 0 : WorkOnTokenSet( XML_TEXTCHAR, yytext );
184 : else
185 0 : WorkOnTokenSet( UNKNOWNCHAR, yytext );
186 : }
187 0 :
188 :
189 0 : %%
190 0 :
191 : /*****************************************************************************/
192 : int yywrap(void)
193 0 : /*****************************************************************************/
194 : {
195 : return 1;
196 0 : }
197 :
198 : /*****************************************************************************/
199 : void YYWarning( const char *s )
200 0 : /*****************************************************************************/
201 : {
202 : /* write warning to stderr */
203 : fprintf( stderr,
204 : "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
205 0 : }
206 0 :
207 : /*****************************************************************************/
208 : void yyerror ( const char *s )
209 0 : /*****************************************************************************/
210 : {
211 : /* write error to stderr */
212 : fprintf( stderr,
213 : "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
214 0 : SetError();
215 0 : }
216 0 :
217 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
218 0 : /* error level */
219 : int nRetValue = 0;
220 0 : char *pOutput;
221 : FILE *pFile;
222 :
223 : pOutput = GetOutputFile( argc, argv );
224 0 :
225 : if ( !pOutput )
226 0 : {
227 : return 1;
228 0 : }
229 : pFile = GetXrmFile();
230 0 : InitXrmExport( pOutput , getFilename() );
231 0 :
232 : if ( !pFile )
233 0 : return 1;
234 0 :
235 : yyin = pFile;
236 0 :
237 : /* create global instance of class XmlExport */
238 : //InitXrmExport( pOutput );
239 :
240 : /* start parser */
241 : yylex();
242 0 :
243 : /* get error info. and end export */
244 : nRetValue = GetError();
245 0 : EndXrmExport();
246 0 :
247 : /* return error level */
248 : return nRetValue;
249 0 : }
|