1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RTFScanner.lex,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 /* compile with flex++ -8 -f -+ -Sflex.skl -ortfparser.cxx rtfparser.lex */
43 #define stricmp strcasecmp
46 writerfilter::rtftok::RTFScanner* writerfilter::rtftok::RTFScanner::createRTFScanner(class writerfilter::rtftok::RTFInputSource& inputSource, writerfilter::rtftok::RTFScannerHandler &eventHandler)
48 return new yyFlexLexer(&inputSource, eventHandler);
54 //int isatty(int fd) { return 0; }
55 int yywrap(void) { return 1; }
59 oslFileHandle yy_osl_in=NULL;
60 #define YY_INPUT(buf,result,max_size) \
63 assert(yy_osl_in!=NULL);\
65 oslFileError ret=osl_isEndOfFile( yy_osl_in, &isEOF );\
66 assert(ret==osl_File_E_None);\
73 sal_uInt64 bytesRead;\
74 ret=osl_readFile( yy_osl_in, buf, max_size, &bytesRead);\
75 assert(ret==osl_File_E_None);\
82 //extern RtfTokenizer* this;
83 void yyFlexLexer::split_ctrl(char *_yytext, char* token, char *value)
85 int i=0; // skip first '\'
86 while(_yytext[i]!=0 && (_yytext[i]=='\r' || _yytext[i]=='\n')) i++;
87 while(_yytext[i]!=0 && (_yytext[i]<'A' || (_yytext[i]>'Z' && _yytext[i]<'a') || _yytext[i]>'z')) i++;
88 while(_yytext[i]!=0 && _yytext[i]>='A') *(token++)=_yytext[i++];
90 while(_yytext[i]!=0 && _yytext[i]>' ') *(value++)=_yytext[i++];
94 void yyFlexLexer::raise_ctrl(char* _yytext)
98 split_ctrl(_yytext, token, value);
99 eventHandler.ctrl(token, value);
102 void yyFlexLexer::raise_dest(char* _yytext)
106 split_ctrl(_yytext, token, value);
107 eventHandler.dest(token, value);
110 #define _num_of_destctrls (sizeof(_destctrls)/sizeof(_destctrls[0]))
111 static const char* _destctrls[] = {
251 void yyFlexLexer::raise_destOrCtrl(char* _yytext)
255 split_ctrl(_yytext, token, value);
256 char* result=(char*)bsearch(token, _destctrls, _num_of_destctrls, 20, (int (*)(const void*, const void*))stricmp);
259 eventHandler.dest(token, value);
263 eventHandler.lbrace();
264 eventHandler.ctrl(token, value);
271 \{\\upr\{" "? { /* skip upr destination */
274 while (br>0 && (c = yyinput()) != EOF)
279 eventHandler.lbrace();
284 \\bin(("+"|"-")?[0-9]*)?" "? {
287 int len=atoi(yytext+4);
289 // pictureBytes=2*len;
293 eventHandler.addBinData((unsigned char)c);
296 eventHandler.rbrace();
299 \{[\r\n]*\\\*\\[A-Za-z]+(("+"|"-")?[0-9]*)?" "? { /* stared dest word */
303 \{[\r\n]*\\[A-Za-z]+(("+"|"-")?[0-9]*)?" "? { /* dest word */
304 raise_destOrCtrl(yytext);
306 \\[A-Za-z]+(("+"|"-")?[0-9]*)?" "? { /* ctrl word */
311 \\\'[A-Fa-f0-9][A-Fa-f0-9] { /* hex char */
312 eventHandler.addHexChar(yytext);
320 eventHandler.lbrace();
324 eventHandler.rbrace();
327 \\\| { num_chars+=yyleng;}
328 \\~ {num_chars+=yyleng; eventHandler.addCharU(0xa0);}
329 \\- {num_chars+=yyleng;}
330 \\_ {num_chars+=yyleng;}
331 \\\: {num_chars+=yyleng;}
332 \n { ++num_lines;num_chars+=yyleng;}
333 \r {num_chars+=yyleng;}
334 \t {num_chars+=yyleng;}
335 " "(" "+) { eventHandler.addSpaces(yyleng); num_chars+=yyleng;}
336 . { eventHandler.addChar(yytext[0]); num_chars+=yyleng;}