1 2 %{ 3 /* 4 * lexer for parsing ressource source files (*.src) 5 * 6 */ 7 8 9 /* enlarge token buffer to tokenize whole strings */ 10 #undef YYLMAX 11 #define YYLMAX 64000 12 13 /* to enable debug output define LEXDEBUG */ 14 #define LEXDEBUG 1 15 #ifdef LEXDEBUG 16 #define OUTPUT fprintf 17 #else 18 #define OUTPUT(Par1,Par2); 19 #endif 20 21 /* table of possible token ids */ 22 #include "tokens.h" 23 #include <stdlib.h> 24 #include <stdio.h> 25 26 #if defined __GNUC__ 27 #pragma GCC system_header 28 #elif defined __SINPRO_CC 29 #pragma disable_warn 30 #elif defined _MSC_VER 31 #pragma warning(push, 1) 32 #endif 33 34 /* external functions (C++ code, declared as extren "C" */ 35 extern int WorkOnTokenSet( int, char* ); 36 extern int InitExport( char * , char * ); 37 extern int Parse( int nTyp, char *pTokenText ); 38 extern int EndExport(); 39 extern int SetError(); 40 extern int GetError(); 41 extern char *GetOutputFile( int argc, char* argv[]); 42 extern FILE *GetNextFile(); 43 extern int isQuiet(); 44 extern void Close(); 45 extern char* getFilename(); 46 47 /* forwards */ 48 void YYWarning(); 49 %} 50 51 %p 24000 52 %e 1200 53 %n 500 54 55 %% 56 57 ^[\t ]*"#pragma".* { 58 WorkOnTokenSet( PRAGMA, yytext ); 59 } 60 61 ^[ \t]*\n { 62 WorkOnTokenSet( EMPTYLINE, yytext ); 63 } 64 65 [\t ]+ | 66 ^[\t ]*"#include".* | 67 ^[\t ]*"#undef".* | 68 "//".* | 69 ";" | 70 "<" | 71 ">" | 72 \n { 73 WorkOnTokenSet( IGNOREDTOKENS, yytext ); 74 } 75 "/*" { 76 char c1 = 0, c2 = input(); 77 char pChar[2]; 78 pChar[1] = 0x00; 79 pChar[0] = c2; 80 81 WorkOnTokenSet( COMMEND, yytext ); 82 WorkOnTokenSet( COMMEND, pChar ); 83 for(;;) { 84 if ( c2 == EOF ) 85 break; 86 if ( c1 == '*' && c2 == '/' ) 87 break; 88 c1 = c2; 89 c2 = input(); 90 pChar[0] = c2; 91 WorkOnTokenSet( COMMEND, pChar ); 92 } 93 } 94 95 ^[\t ]*"#ifndef".+$ | 96 ^[\t ]*"#ifdef".+$ | 97 ^[\t ]*"#if".+$ | 98 ^[\t ]*"#elif".*$ | 99 ^[\t ]*"#else".*$ | 100 ^[\t ]*"#endif".*$ { 101 WorkOnTokenSet( CONDITION, yytext ); 102 } 103 104 [a-zA-Z]+[\t ]+[^={\n]+[\t ] { 105 /* defined Res */ 106 WorkOnTokenSet( DEFINEDRES, yytext ); 107 } 108 109 [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{" | 110 [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{" { 111 /* RESSOURCE // String TTT_XX ... */ 112 WorkOnTokenSet( RESSOURCE, yytext ); 113 } 114 115 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? { 116 /* SMALRESSOURCE // String ... */ 117 WorkOnTokenSet( SMALRESSOURCE, yytext ); 118 } 119 120 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? { 121 /* TEXTLINE // TextTyp = "A Text" */ 122 WorkOnTokenSet( TEXTLINE, yytext ); 123 } 124 125 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?(\n[ \t]*)?=([ \t]*\n)?(([a-zA-Z0-9_]+)|(\".*\")|([ \t\n]*))*\".*\"(([a-zA-Z0-9_]+)|(\".*\")|([ \t\n]*))*; { 126 /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */ 127 WorkOnTokenSet( LONGTEXTLINE, yytext ); 128 } 129 130 \".*\" { 131 /* TEXT // "A Text" */ 132 WorkOnTokenSet( TEXT, yytext ); 133 } 134 135 "{"[ \t]*\\? { 136 /* LEVELUP */ 137 WorkOnTokenSet( LEVELUP, yytext ); 138 } 139 140 "}"[ \t]*;([ \t]*\\)? { 141 /* LEVELDOWN */ 142 WorkOnTokenSet( LEVELDOWN, yytext ); 143 } 144 145 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* { 146 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */ 147 WorkOnTokenSet( APPFONTMAPPING, yytext ); 148 } 149 150 [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? { 151 /* TEXTREFID // TextTyp = 12345 */ 152 WorkOnTokenSet( TEXTREFID, yytext ); 153 } 154 155 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* | 156 [a-zA-Z0-9_]+[ \t]*"=".* { 157 /* ASSIGNMENT Typ = ... */ 158 WorkOnTokenSet( ASSIGNMENT, yytext ); 159 } 160 161 162 163 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" { 164 /* LISTASSIGNMENT Typ [ ... ] = ... */ 165 WorkOnTokenSet( LISTASSIGNMENT, yytext ); 166 } 167 168 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* { 169 /* LISTASSIGNMENT Typ [ ... ] = ... */ 170 WorkOnTokenSet( LISTASSIGNMENT, yytext ); 171 } 172 173 "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{" { 174 /* UIENTRIES */ 175 WorkOnTokenSet( UIENTRIES, yytext ); 176 } 177 178 "<"?[ \t]*L?\".*\".*">" { 179 /* LISTTEXT */ 180 WorkOnTokenSet( LISTTEXT, yytext ); 181 } 182 183 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" { 184 /* RSCDEFINE #define ... */ 185 WorkOnTokenSet( RSCDEFINE, yytext ); 186 } 187 188 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ { 189 /* #define ... */ 190 WorkOnTokenSet( NORMDEFINE, yytext ); 191 } 192 193 "\\" { 194 /* RSCDEFINELEND */ 195 WorkOnTokenSet( RSCDEFINELEND, yytext ); 196 } 197 198 [a-zA-Z0-9_]+[ \t]*; { 199 /* allowed other tokens like "49 ;" or "SFX_... ;" */ 200 WorkOnTokenSet( ANYTOKEN, yytext ); 201 } 202 203 . { 204 WorkOnTokenSet( UNKNOWNCHAR, yytext ); 205 /* YYWarning( "Unknown Char" ); */ 206 } 207 208 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" { 209 /* _LISTTEXT */ 210 WorkOnTokenSet( _LISTTEXT, yytext ); 211 } 212 213 %% 214 215 /*****************************************************************************/ 216 int yywrap(void) 217 /*****************************************************************************/ 218 { 219 FILE *pFile; 220 pFile = GetNextFile(); 221 if ( pFile ) { 222 yyin = pFile; 223 yylineno = 0; 224 return 0; 225 } 226 227 /* end of input reached */ 228 return 1; 229 } 230 231 /*****************************************************************************/ 232 void YYWarning( char *s ) 233 /*****************************************************************************/ 234 { 235 /* write warning to stderr */ 236 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext ); 237 } 238 239 /*****************************************************************************/ 240 void yyerror( char *s ) 241 /*****************************************************************************/ 242 { 243 /* write error to stderr */ 244 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext ); 245 SetError(); 246 } 247 248 /*****************************************************************************/ 249 int 250 #ifdef WNT 251 _cdecl 252 #endif 253 main( int argc, char* argv[]) 254 /*****************************************************************************/ 255 { 256 /* error level */ 257 int nRetValue = 0; 258 char *pOutput; 259 FILE *pFile; 260 261 pOutput = GetOutputFile( argc, argv ); 262 263 if ( !pOutput ) { 264 fprintf( stdout, "Syntax:TRANSEX[-p Prj][-r PrjRoot]-i FileIn...[-o FileOut][-m DataBase][-e][-b][-u][-L l1,l2,...]\n" ); 265 fprintf( stdout, " Prj: Project\n" ); 266 fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" ); 267 fprintf( stdout, " FileIn: Source files (*.src)\n" ); 268 fprintf( stdout, " FileOut: Destination file (*.*)\n" ); 269 fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" ); 270 fprintf( stdout, " -QQ: quiet output\n" ); 271 fprintf( stdout, " -e: Disable writing errorlog\n" ); 272 fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" ); 273 fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" ); 274 fprintf( stdout, " -NOUTF8: disable UTF8 as language independent encoding\n" ); 275 fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" ); 276 fprintf( stdout, " A fallback language can be defined like this: l1=f1.\n" ); 277 fprintf( stdout, " f1, f2,... are also elements of (de,en-US...)\n" ); 278 fprintf( stdout, " Example: -L de,es=en-US\n" ); 279 fprintf( stdout, " Restriction to de and es, en-US will be fallback for es\n" ); 280 return 1; 281 } 282 283 InitExport( pOutput , getFilename() ); 284 pFile = GetNextFile(); 285 if ( !pFile ) 286 return 1; 287 288 yyin = pFile; 289 290 /* create global instance of class Export */ 291 292 /* start parser */ 293 yylex(); 294 Close(); 295 296 /* get error info. and end export */ 297 nRetValue = GetError(); 298 EndExport(); 299 300 /* return error level */ 301 return nRetValue; 302 } 303