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