4 * lexer for parsing ressource source files (*.src)
9 /* enlarge token buffer to tokenize whole strings */
13 /* to enable debug output define LEXDEBUG */
16 #define OUTPUT fprintf
18 #define OUTPUT(Par1,Par2);
21 /* table of possible token ids */
27 #pragma GCC system_header
28 #elif defined __SINPRO_CC
30 #elif defined _MSC_VER
31 #pragma warning(push, 1)
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();
45 extern char* getFilename();
58 WorkOnTokenSet( PRAGMA, yytext );
62 WorkOnTokenSet( EMPTYLINE, yytext );
73 WorkOnTokenSet( IGNOREDTOKENS, yytext );
76 char c1 = 0, c2 = input();
81 WorkOnTokenSet( COMMEND, yytext );
82 WorkOnTokenSet( COMMEND, pChar );
86 if ( c1 == '*' && c2 == '/' )
91 WorkOnTokenSet( COMMEND, pChar );
101 WorkOnTokenSet( CONDITION, yytext );
104 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
106 WorkOnTokenSet( DEFINEDRES, yytext );
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 );
115 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
116 /* SMALRESSOURCE // String ... */
117 WorkOnTokenSet( SMALRESSOURCE, yytext );
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 );
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 );
131 /* TEXT // "A Text" */
132 WorkOnTokenSet( TEXT, yytext );
137 WorkOnTokenSet( LEVELUP, yytext );
140 "}"[ \t]*;([ \t]*\\)? {
142 WorkOnTokenSet( LEVELDOWN, yytext );
145 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
146 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
147 WorkOnTokenSet( APPFONTMAPPING, yytext );
150 [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
151 /* TEXTREFID // TextTyp = 12345 */
152 WorkOnTokenSet( TEXTREFID, yytext );
155 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
156 [a-zA-Z0-9_]+[ \t]*"=".* {
157 /* ASSIGNMENT Typ = ... */
158 WorkOnTokenSet( ASSIGNMENT, yytext );
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 );
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 );
173 "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{" {
175 WorkOnTokenSet( UIENTRIES, yytext );
178 "<"?[ \t]*L?\".*\".*">" {
180 WorkOnTokenSet( LISTTEXT, yytext );
183 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
184 /* RSCDEFINE #define ... */
185 WorkOnTokenSet( RSCDEFINE, yytext );
188 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
190 WorkOnTokenSet( NORMDEFINE, yytext );
195 WorkOnTokenSet( RSCDEFINELEND, yytext );
198 [a-zA-Z0-9_]+[ \t]*; {
199 /* allowed other tokens like "49 ;" or "SFX_... ;" */
200 WorkOnTokenSet( ANYTOKEN, yytext );
204 WorkOnTokenSet( UNKNOWNCHAR, yytext );
205 /* YYWarning( "Unknown Char" ); */
208 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
210 WorkOnTokenSet( _LISTTEXT, yytext );
215 /*****************************************************************************/
217 /*****************************************************************************/
220 pFile = GetNextFile();
227 /* end of input reached */
231 /*****************************************************************************/
232 void YYWarning( char *s )
233 /*****************************************************************************/
235 /* write warning to stderr */
236 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
239 /*****************************************************************************/
240 void yyerror( char *s )
241 /*****************************************************************************/
243 /* write error to stderr */
244 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
248 /*****************************************************************************/
253 main( int argc, char* argv[])
254 /*****************************************************************************/
261 pOutput = GetOutputFile( argc, argv );
263 fprintf( stdout, "\nTransEx 3.1 Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.\n" );
264 fprintf( stdout, "========================================================================\n" );
268 fprintf( stdout, "Syntax:TRANSEX[-p Prj][-r PrjRoot]-i FileIn...[-o FileOut][-m DataBase][-e][-b][-u][-L l1,l2,...]\n" );
269 fprintf( stdout, " Prj: Project\n" );
270 fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
271 fprintf( stdout, " FileIn: Source files (*.src)\n" );
272 fprintf( stdout, " FileOut: Destination file (*.*)\n" );
273 fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
274 fprintf( stdout, " -QQ: quiet output\n" );
275 fprintf( stdout, " -e: Disable writing errorlog\n" );
276 fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" );
277 fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" );
278 fprintf( stdout, " -NOUTF8: disable UTF8 as language independent encoding\n" );
279 fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
280 fprintf( stdout, " A fallback language can be defined like this: l1=f1.\n" );
281 fprintf( stdout, " f1, f2,... are also elements of (de,en-US...)\n" );
282 fprintf( stdout, " Example: -L de,es=en-US\n" );
283 fprintf( stdout, " Restriction to de and es, en-US will be fallback for es\n" );
287 InitExport( pOutput , getFilename() );
288 pFile = GetNextFile();
294 /* create global instance of class Export */
300 /* get error info. and end export */
301 nRetValue = GetError();
304 if( !isQuiet() ) fprintf( stdout, "\n===================================\n\n" );
306 /* return error level */