update dev300-m58
[ooovba.git] / soltools / HIDCompiler / hidclex.l
blobdf36c708f2a838db7f96b3715eb61126beac3b07
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  * 
5  * Copyright 2008 by Sun Microsystems, Inc.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * $RCSfile: hidclex.l,v $
10  * $Revision: 1.9 $
11  *
12  * This file is part of OpenOffice.org.
13  *
14  * OpenOffice.org is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License version 3
16  * only, as published by the Free Software Foundation.
17  *
18  * OpenOffice.org is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU Lesser General Public License version 3 for more details
22  * (a copy is included in the LICENSE file that accompanied this code).
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * version 3 along with OpenOffice.org.  If not, see
26  * <http://www.openoffice.org/license.html>
27  * for a copy of the LGPLv3 License.
28  *
29  ************************************************************************/
31 // Suppress any warnings from generated code:
32 #if defined __GNUC__
33 #pragma GCC system_header
34 #elif defined __SUNPRO_CC
35 #pragma disable_warn
36 #elif defined _MSC_VER
37 #pragma warning(push, 1)
38 #endif
40 static char const Revision[]     = "$Revision: 1.9 $" ;
44 XX  XX     XXXX   XXXXXX
45 XX  XX      XX     XX  XX
46 XX  XX      XX     XX  XX
47 XXXXXX      XX     XX  XX
48 XX  XX      XX     XX  XX
49 XX  XX      XX     XX  XX
50 XX  XX     XXXX   XXXXXX
53   XXXX                                 XX      XXX
54  XX  XX                                         XX
55 XX         XXXX   XXX XX   XX XXX     XXX       XX     XXXXX   XX XXX
56 XX        XX  XX  XX X XX   XX  XX     XX       XX    XX    X   XXX XX
57 XX    X   XX  XX  XX X XX   XX  XX     XX       XX    XXXXXXX   XX
58  XX  XX   XX  XX  XX   XX   XXXXX      XX       XX    XX        XX
59   XXXX     XXXX   XXX  XXX  XX        XXXX     XXXX    XXXXX   XXXX
60                            XXXX
65 /* length of buffer for reading with lex */
66 /**/
67 /* enlarge token buffer to tokenize whole strings */
68 #undef YYLMAX
69 #define YYLMAX 64000
71 int exclude_bracelevel=0; /* count braces in that start state */
72 static YY_BUFFER_STATE InputFiles[127];         // for recursive parse
73 static int nInputFileDepth = 0;
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <string.h>
80 #include <ctype.h>
82 int alloc_cnt = 0;
83 void freestring( char const * ); //forward
85 char* dot2underline( char* str )
87         size_t len=strlen(str);
88         for( size_t i=0; i<len; i++ )
89                 if( str[i]=='.' ) str[i]='_';
90         return str;
93 void dotappend( char*& base, char const * suffix )
95         // append like "str.suffix" if suffix else "str"
97         if( suffix == NULL )
98                 return ;
100         size_t siz;
101         if( (siz=strlen(suffix)) == 0 )
102                 return ;
104         size_t siz2 = base==NULL ? 0 : strlen(base);
106         char* newstr;
108         {//do never forget to increment/decrement alloc_cnt
109         newstr = (char*) malloc( (siz2+siz+1) +1 /*for "." */ );
110         alloc_cnt++;
111         }
113         if( newstr == NULL )
114                 fprintf( stderr,"error: dotappend() could not malloc() \n"), exit(1);
116         if( base ) {
117                 strcpy( newstr, base );
118                 freestring( base );
119         }
120         else
121                 newstr[0] = '\0';
123         strcat( newstr, "." );
124         strcat( newstr, suffix );
125         base = newstr;
128 void dotsubtract( char*& base, char const * suffix )
130         // remove dotted suffix from base.suffix --> base
132         if( base == NULL || suffix == NULL )
133                 return;
134         if( strlen(suffix) == 0 )
135                 return;
136         if( (strlen(suffix)+1) > strlen(base) )
137                 return;
138         char * pos=strstr( base, suffix);
139         if( pos && (pos-1 >= base) && ( *(pos-1) == '.') )
140                 if( *(pos+strlen(suffix)) == '\0' ) //only if at end of base
141                         *(pos-1)= '\0';
142         return;
145 int level = 0;
146 char levelbuffer[512];
148 void adjust_levelbuffer()
150         int i;
151         for(i=0; i<level;i++) {
152                 levelbuffer[i] = '\t';
153         }
154         levelbuffer[i] = '\0';
157 void freestring( char const * ptr )
159          alloc_cnt--;
160          adjust_levelbuffer();
161          //fprintf(stderr,"%sinfo: freestring line %d\n",levelbuffer, __LINE__);
162          free(const_cast< char * >(ptr)), ptr = NULL;
165 void makestring(char** newstr, char* oldstr)
167         alloc_cnt++;
168         adjust_levelbuffer();
169         /*
170         fprintf(stderr,"%sinfo: makestring on line %d\n",levelbuffer,__LINE__);
171         */
172         strcpy( (*newstr=(char*)malloc(strlen(oldstr)+1)), oldstr);
173         if( *newstr==NULL ) {
174                 fprintf( stderr,
175                 "error: cannot malloc for makestring() alloc_cnt==%d \n", alloc_cnt);
176                 exit(1);
177         }
180 #ifndef WNT
181 int strcmpi(char const * stra, char const * strb)
183         // like strcmp() but case insensitive
184         size_t i;
185         char a,b;
186         for(i=0; ;i++){
187                 a = (char) tolower(stra[i]);
188                 b = (char) tolower(strb[i]);
189                 if( a < b )
190                         return -1;
191                 if( a > b )
192                         return 1;
193                 if( a == '\0' && b == '\0' )
194                         return 0;
195         }
197 #endif
199 /* variables for listfile ( with project + pathname of src file ) */
200 char* listfilename;
201 #define MAXSRCFILES 2048
202 char* filename_tab[MAXSRCFILES];
203 char* project_tab[MAXSRCFILES];
204 int tab_entries = 0;
205 //int fileno = 0; /* currently used filenumber */
207 /* globale variablen */
208 FILE* outfile;
209 char const *filename = ""; //incl. path
210 //char *basename = "";
211 char const *project = "";
212 char const *subpath = "";       //from project name downwards like source\ui\xxx.src
214 int firstprint = 1;
216 int in_define = 0;
218 class ident_ring
220         #define MAXRING 2
221         //nicht aendern wg externer Abfrage ->size() == 2
223         char*  ring[MAXRING];
224         int     ringpos;
225         int     last;
226         int     broken;
227 public:
228                 ident_ring()  {
229                                                         last = ringpos = -1;
230                                                         for(int i=0; i<MAXRING;i++)
231                                                                 ring[i]=NULL;
232                                                         broken = 0;
233                                                   }
235         void    set_zero()    {
236                                                         last = ringpos = -1;
237                                                         for(int i=0; i<MAXRING;i++) {
238                                                                 if( ring[i] != NULL )
239                                                                         freestring( ring[i] );
240                                                                 ring[i]=NULL;
241                                                         }
242                                                         broken = 0;
243                                                   }
244         void    set_broken()  { broken = 1; }
245         int     size()        {
246                                                         if( ringpos == -1 )
247                                                                 return 0;
249                                                         if( broken) {
250                                                                 if( ringpos==0 )
251                                                                         return 0;
252                                                                 else
253                                                                         return 1;
254                                                         } else {
255                                                                 if( ringpos==0 )
256                                                                         return 1;
257                                                                 else
258                                                                         return 2;
259                                                         }
260                                                   }
262         char*   extract_last(){
263                                                         if( last == -1 )  {
264                                                                 return NULL;
265                                                         } else {
266                                                                 char* ttt=ring[last];
267                                                                 ring[last]=NULL;
268                                                                 return ttt;
269                                                         }
270                                               }
272         char*   extract_actual()  {
273                                                         if(ringpos == -1) {
274                                                                 return NULL;
275                                                         } else {
276                                                                 char *ttt=ring[ringpos];
277                                                                 ring[ringpos]=NULL;
278                                                                 return ttt;
279                                                         }
280                                                   }
282         void    set(char* id) {
283                                                         ringpos= (++ringpos) % MAXRING;
284                                                         if( ring[ringpos] != NULL )
285                                                                 freestring( ring[ringpos] ); /*otherwise: memory lost*/
286                                                         ring[ ringpos ] = id;
287                                                         //fprintf(stderr,
288                                                         //      "info: ring[%d] == %s broken==%d \n"
289                                                         //      ,ringpos,ring[ringpos],broken
290                                                         // );
292                                                         if( !(ringpos==0 && last==-1) )
293                                                                 last = (++last) % MAXRING;
294                                                   }
298 /* Notnagel: die letzten identifier/number merken, fuer klasse & globalID */
299 ident_ring *ring;
302 typedef int token;
304 #define TOK_SEMICOLON   ';'
305 #define TOK_EQUAL               '='
306 #define TOK_OPENBRACKET '['
307 #define TOK_CLOSEBRACKET ']'
308 #define TOK_OPENBRACE   '{'
309 #define TOK_CLOSEBRACE  '}'
310 #define TOK_KOMMA               ','
311 #define TOK_LESS                '<'
312 #define TOK_GREATER             '>'
313 #define TOK_OPENPAREN   '('
314 #define TOK_CLOSEPAREN  ')'
315 #define TOK_PLUS                '+'
316 #define TOK_MINUS               '-'
317 #define TOK_STAR                '*'
318 #define TOK_SLASH               '/'
320 #define TOK_POSorSIZE   146
321 #define TOK_POSSIZE             147
322 #define TOK_TEXTTAG             148
323 #define TOK_IDNUM               149
325 #define TOK_EXTRADATA   151
326 #define TOK_TEXT                152
327 #define TOK_MESSAGE             153
328 #define TOK_HELPTEXT    154
329 #define TOK_TRUE                155
330 #define TOK_FALSE               156
332 #define TOK_RESID       180
334 #define TOK_STRING              190
336 #define TOK_INVALID     (-1)
338 token  lasttoken = TOK_INVALID;
343 #define UNDEF (-1)
345 char *globalID = const_cast< char * >("");
346 char const *globalKLASSE = NULL;
348 void reset_globalID() {
349         //
350         if( globalID && (strlen(globalID) > 0 ) ) {
351                 freestring( globalID );
352                 globalID = const_cast< char * >("");
353         }
357 //--------------------------------------------------------------------
358 class resource
360 private:
361         resource ( const resource& );  //copy-ctor soll keiner benutzen
362         void operator=( const resource& ); // zuweisung auch nicht
363 public:
364         resource();
365         ~resource();
366 public:
367         int      lineno;
368         token  lasttoken; //before opening {
369         char const *klasse ;
370         char *localID;
371         char *helpID;
372         int  residfound;
375 resource *ares ; /* aktuell bearbeitete resource */
377 resource::~resource()
379         if( klasse != NULL )   freestring(klasse);
380         if( localID != NULL )  freestring(localID);
381         if( helpID != NULL )   freestring(helpID);
385 resource::resource()
387         lineno =   UNDEF;
388         lasttoken= TOK_INVALID;
389         klasse =    NULL ;
390         localID =  NULL ;
391         helpID =   NULL ;
392         residfound= 0;
395 int residfound = 0; // "Identifier = " auf momentanem level gefunden
397 #define   MAXSTACK 32
398 resource* stack[MAXSTACK]; /* resource stack */
399 #define   EMPTYSTACK (-1)
400 int       stackptr = EMPTYSTACK;
402 void push_resource( resource* r )
404         stackptr++;
405         if( stackptr >= MAXSTACK ) {
406                 fprintf( stderr, "error: resource stack is full %d \n", stackptr);
407                 exit(1);
408         }
409         stack[ stackptr ] = r;
412 resource* pop_resource()
414         if( stackptr < 0 ) {
415                 fprintf( stderr, "error: pop resource from empty stack \n");
416                 exit(1);
417         }
418         return stack[ stackptr-- ];
421 /* forward */
422 int eat_comment();
423 int eat_cpp_comment();
425 /*===================================================*/
427 // '+' im identifier wg basic\source\classes\sb.src
429 // '<' im identifier wg sc subtdlg.src
431 // '&' im identifier wg scerror.src so2..nocode.src svxerr.src scwarngs.src
434 //string                (\"[^"]*\") alter einfacher string ohne "
438 /* 89012 */
439 %option never-interactive
442 simple          ([^\n\"]*)
443 %p 7000
444 string          \"{simple}((((\\\\)*(\\\"))?){simple})*\"
446 %x MACRO_STATE
448 %x EXCLUDE_STATE
449 resfilelist         ([Ff][Ii][Ll][Ee][Ll][Ii][Ss][Tt])
450 resstringlist   ([Ss][Tt][Rr][Ii][Nn][Gg][Ll][Ii][Ss][Tt])
451 resstring       ([Ss][Tt][Rr][Ii][Nn][Gg])
453 identifier ([a-z_A-Z]+[a-z_A-Z<+&0-9]*)
454 number          (([0-9]+)|(0x[0-9a-fA-F]+))
455 residentifier ([Ii][Dd][Ee][Nn][Tt][Ii][Ff][Ii][Ee][Rr])
456 w                       ([ \t\n]*)
457 wspecial        ([\\ \t\n]*)
458 texttag         (([Tt][Ii][Tt][Ll][Ee])|([Tt][Ee][Xx][Tt])|([Mm][Ee][Ss][Ss][Aa][Gg][Ee]))
459 qhelptag        (([Qq][Uu][Ii][Cc][Kk])?([Hh][Ee][Ll][Pp][Tt][Ee][Xx][Tt]))
460 langtag         ([a-zA-Z_]+)
461 helptag         ([Hh][Ee][Ll][Pp][Ii][Dd])
462 helpid          ([a-zA-Z_0-9]+)
463 num2tag         (([Pp][Oo][Ss])|([Ss][Ii][Zz][Ee]))
464 num4tag         (([Pp][Oo][Ss][Ss][Ii][Zz][Ee]))
467 [ \t]           {
468                                 /* forget whitespace */;
469                         }
471 ^[ \t]*#include.*\.src[">].*    {
472                                 char NewFile[255];              //long names???
473                                 int i, j, GetIt;
475                                 GetIt = 0;
476                                 j = 0;
477                                 nInputFileDepth++;
478 //      nicht schoen aber geht...
479                                 for (i = 0; yytext[i+1] != 0; i++)
480                                 {
481                                         if ( GetIt == 1 )
482                                         {
483                                                 if ( yytext[i] == '"' || yytext[i] == '>' )
484                                                         GetIt = 0;
485                                                 else
486                                                         NewFile[j++] = yytext[i];
487                                         }
488                                         if ( yytext[i] == '"' || yytext[i] == '<' )
489                                                 GetIt = 1;
490                                 }
491                                 NewFile[j] = '\0';
492                                 FILE* pFile = NULL;
493                                 pFile = fopen( NewFile, "r" );
494                                 if( pFile == NULL ) {
495                                         fprintf( stderr, "warning: could not open inputfile %s \n", NewFile );
496                                         // try the new *_tmpl.src version instead
497                                         // this hack was introduced to allow localisation of included src files
498                                         const char* sStrTmpl = "_tmpl";
499                                         j -= 4;
500                                         for ( i = 0 ; i <5 ; i++,j++ )
501                                         {
502                                             NewFile[j+5] = NewFile[j];
503                                             NewFile[j] = sStrTmpl[i];
504                                         }
505                                 NewFile[j+4] = '\0';
506                                         fprintf( stderr, "trying inputfile %s \n", NewFile );
507                                 pFile = fopen( NewFile, "r" );
508                                     if( pFile == NULL ) {
509                                             fprintf( stderr, "error: could not open inputfile %s \n", NewFile );
510                                             exit(1);
511                             }
512                                 }
513                                 InputFiles[ nInputFileDepth ] = yy_create_buffer( pFile, YY_BUF_SIZE );
514                 yy_switch_to_buffer( InputFiles[ nInputFileDepth ] );
516                                 printf( "%s //ATTENTION!! %s gets included here\n", yytext, NewFile );
517                                 fprintf( outfile, "// %s //ATTENTION!! %s gets included here\n\n", yytext, NewFile );
518                         }
520 ^[ \t]*#include.*       {
521                                 fprintf( outfile, "%s\n\n", yytext );
522                         }
524 ^[ \t]*#(if|ifdef|ifndef|elif).*                {
525                                 ;
526                         }
528 ^[ \t]*#else    {
529                                 ;
530                         }
531 ^[ \t]*#endif   {
532                                 ;
533                         }
535 ^[ \t]*#(undef|error|pragma).*  {
536                                 ;
537                         }
539 ^[ \t]*#define  {
540                                 fprintf( outfile, "%s", yytext );
541                                 BEGIN MACRO_STATE;
542                         }
544 <INITIAL,MACRO_STATE>"/*"               {
545                                 eat_comment();
546                         }
548 <INITIAL,MACRO_STATE>"//"               {
549                                 eat_cpp_comment();
550                         }
552 <MACRO_STATE>\n {
553                                 fprintf( outfile, "%s\n", yytext );
554                                 BEGIN INITIAL;
555                         }
557 <MACRO_STATE>\\\n {
558                                 fprintf( outfile, "\\\n" );
559                         ;/* macro schadet nicht, koennte gebraucht werden */
560                         }
563 <MACRO_STATE>. {
564                         fprintf( outfile, "%s", yytext );
565                         ;/* ignore all this unused input */
566                         }
568 ";"             {ring->set_zero(); lasttoken = TOK_SEMICOLON; }
569 "="             {ring->set_zero(); lasttoken = TOK_EQUAL; }
570 "["             {ring->set_broken(); lasttoken = TOK_OPENBRACKET; }
571 "]"             {ring->set_broken(); lasttoken = TOK_CLOSEBRACKET; }
574 <EXCLUDE_STATE>"{"              {
575                                 exclude_bracelevel += 1;
576                                 //fprintf( stderr,"info: lev %d : found {\n", exclude_bracelevel );
577                         }
580 \\\n            |
581 "{"             {
582                                 // define continues
583                                 // or a brace opens a block
585                                 if( in_define && !strcmp(yytext,"\\\n") ) {
587                                         if( in_define++ == 1 )
588                                                 ;// keep on working
589                                         else
590                                                 goto blockend;
591                                 }
593                                 level++;
594                                 if( ares != NULL ){
595                                         if( level > 1 )
596                                                 dotappend( globalID, ares->localID );
597                                         ares->residfound = residfound;
598                                         push_resource( ares );
599                                 }
600                                 ares = new resource;
602                                 residfound = 0;
603                                 ares->residfound = 0;
605                                 ares->lineno = yylineno;
606                                 ares->lasttoken = lasttoken;
607                                 if( ring->size() == 2 ) {
608                                         ares->klasse = ring->extract_last();
609                                         ares->localID = ring->extract_actual();
610                                 } else if(ring->size() == 1) {
611                                         ares->klasse = ring->extract_actual();
612                                 }
613                                 if( level==1 ){ //Ausnahme: Resource auf Ebene 1
614                                         globalID= ares->localID;
615                                         ares->localID = NULL;
616                                         globalKLASSE= ares->klasse;
617                                 }
619                                 //fprintf(stderr,"info: { level: %d\n", level);
620                                 //
622                                 lasttoken = TOK_OPENBRACE;
623                                 ring->set_zero();
624                         }
626 <EXCLUDE_STATE>"}"              {
627                                 //-----------------------------
628                                 exclude_bracelevel -= 1;
629                                 //fprintf( stderr,"info: lev %d : found }\n", exclude_bracelevel );
630                                 if( exclude_bracelevel==1 ) {
631                                         BEGIN INITIAL;
632                                         exclude_bracelevel=0;
633                                 }
634                         }
637 \n                      |
638 "}"             {
639                                 //fprintf(stderr,"info:   } level: %d\n",level);
641                                 if( !strcmp(yytext,"}") )
642                                         ;
643                                 else if( in_define && (!strcmp(yytext,"\n") )) {
644                                         if( in_define==1 ) {
645                                                 //no continuation line for #define
646                                                 in_define=0;
647                                                 goto blockend;
648                                         }
649                                         else {
650                                                 //there was a continuation line for #define
651                                                 in_define=0;
652                                         }
653                                 }
654                                 else
655                                         goto blockend;
657                                 // ares ausgeben
658                                 if( ares != NULL ) {
660                                         #define LEER "leer"
661                                         char const * globklasse =
662                       globalKLASSE==NULL ? LEER:globalKLASSE;
663                                         char const * local =
664                       ares->localID==NULL ? LEER:ares->localID;
665                                         char const * klasse =
666                       ares->klasse==NULL ? LEER:ares->klasse;
667                                         char const * glob =
668                       globalID==NULL ? LEER:globalID;
671                                         //wg. Starview-Klasse String in ehdl.c und doc.c
672                                         // wenn generierte C++-Quellen compiliert werden
673                                         //
674                                         //if( !strcmp(globklasse,"String" )) globklasse = "string";
675                                         //if( !strcmp(klasse,"String" )) klasse = "string";
678                                         //---------------------------------------------------
679                                         // generate the body of a new C main program,
680                                         // which is filled with printf statements
681                                         // to compute (via preproseccor & compiler)
682                                         // the codenumbers for resource names like menu$RID_SVX$xyz
684                                         if( firstprint ) {
685                                                 firstprint=0;
686                                                 fprintf(outfile, "#include \"starview.hid\" \n\n");
687                                                 fprintf(outfile, " int main() { \n\n\n");
688                                         }
690                                         char globunder[256];
691                                     strcpy(globunder,glob);
692                                         dot2underline( globunder );
693                                         char const * globsuffix = strrchr(glob,'.');
694                                         globsuffix = globsuffix==NULL ? glob:globsuffix+1;
696                                         if( ares->helpID ) {
697                                                 fprintf( outfile,"\n\t printf(\"%s \\t %cs %cu \\n\",\n",
698                                                 ares->helpID,'%','%');
699                                                 fprintf(outfile,"\t\"HelpID\", (%s) ); \n", ares->helpID);
700                                         }
701                                         else if( ares->localID ) {
702                                                 fprintf( outfile,"\n\t printf(\"%s:%s:%s:%s \\t %cs %cu %cs %cu \\n\",\n",
703                                                 project,klasse,globunder,local,'%','%','%','%');
704                                                 fprintf( outfile,"\t\"Norm %s\", (%s), \"%s\", (%s) );\n",
705                                                 globklasse,globsuffix, klasse,local);
706                                         }
707                                         else if( (strcmpi("MenuItem",klasse)==0) ||
708                                                     (strcmpi("ToolBoxItem",klasse)==0) ) {
709                                                         ; //no output (99% is a separator)
710                                         }
711                                         else {
712                                                 fprintf( outfile,"\n\t printf(\"%s:%s:%s \\t %cs %cu %cs \\n\",\n",
713                                                 project,klasse,globunder,'%','%','%');
714                                                 fprintf( outfile,"\t\"Norm %s\", (%s), \"%s\" );\n",
715                                                 globklasse,globsuffix, klasse);
716                                         }
718                                         delete ares;
719                                 }
722                                 // ein level zurueck
723                                 if( level == 1) {
724                                         reset_globalID();
725                                         globalKLASSE = NULL;
726                                 }
727                                 level--;
728                                 ares = pop_resource();
729                                 residfound = ares->residfound;
730                                 dotsubtract( globalID, ares->localID );
733                                 //
734                                 lasttoken = TOK_CLOSEBRACE;
735                                 ring->set_zero();
736                 blockend:       ;
737                         }
739 ","             {ring->set_broken(); lasttoken = TOK_KOMMA; }
741 "<"             {ring->set_broken(); lasttoken = TOK_LESS; }
742 ">"             {ring->set_broken(); lasttoken = TOK_GREATER; }
744 "("             {ring->set_broken(); lasttoken = TOK_OPENPAREN; }
745 ")"             {ring->set_broken(); lasttoken = TOK_CLOSEPAREN; }
746 "+"             {ring->set_broken(); lasttoken = TOK_PLUS; }
747 "-"             {ring->set_broken(); lasttoken = TOK_MINUS; }
748 "*"             {ring->set_broken(); lasttoken = TOK_STAR; }
749 "/"             {ring->set_broken(); lasttoken = TOK_SLASH; }
752 {helptag}{w}"="{w}{helpid}{w}";" {
754                         // extract text for helpid and put to ares
755                         char*     pos = strchr(yytext,'=');
756                         size_t offset = strspn(pos+1," \t\n");
757                         char*   start = pos+1+offset;
758                         size_t offset2= strcspn( start, "; \t\n");
759                         char*     end = start+offset2;
760                         *end = '\0';
761                         char *helpid;
762                         makestring( &helpid, start );
763                         ares->helpID = helpid;
764                         }
766 {residentifier}{w}"="[ \t\n]*({identifier}|{number}) {
767                         ring->set_zero();
768                         lasttoken = TOK_RESID;
769                         residfound=1;
771                         //extract resource id and store as localID
772                         char *after = strrchr(yytext,'=');
773                         char *resid = after + strspn(after,"= \t\n");
774                         char *localID;
775                         makestring( &localID, resid );
776                         ares->localID = localID;
777                         }
779 {resfilelist}   |
780 {resstring}     |
781 {resstringlist} {
782                         BEGIN EXCLUDE_STATE;
783                         exclude_bracelevel = 1;
784                         //fprintf( stderr,"info: lev %d : found exclusion\n", exclude_bracelevel );
785                         }
787 ^[ \t]*#define          |
788 {number}                |
789 {identifier} {
790                 /* identifier/number in einem ring ablegen */
791                 char *identifier;
792                 char *def=strstr(yytext,"#define");
793                 if( def ) {
794                         in_define = 1;
795                         makestring( &identifier, def+1 );
796                 }
797                 else
798                         makestring( &identifier, yytext );
799                 ring->set( identifier );
800                 lasttoken = TOK_IDNUM;
802         }
803 <INITIAL,EXCLUDE_STATE>{string} {
804                         ring->set_broken();
805             lasttoken = TOK_STRING;
806                         //printf("%6s %11s %8d %s \n",project,filename,yylineno, yytext);
807                         }
810 <INITIAL,EXCLUDE_STATE>.        { //fprintf( stderr,"warning: unused input on line %d of %s \n%s\n",
811                                         //yylineno, filename, yytext);
812         }
814 <EXCLUDE_STATE>\n       {
815                                                 ; //do nothing, ignore
816         }
822 void makeversion( char* version )
824         char const *pos = strpbrk( Revision, "0123456789." );
825         size_t siz = strspn( pos,      "0123456789." );
826         if( pos && siz ) {
827                 strncpy(version, pos, siz);
828                 strcat( version, " ");
829         }
830         else
831                 strcpy( version," unknown " );
834 int main( int argc, char* argv[] )
836         static char const *Compiler = "HID-Compiler ";
837         static char const *Author   = "OG ";
838         static char HIDCompiler[100];
839         static char Version[100];
842         makeversion( Version );
843         strcpy( HIDCompiler, Compiler );
844         strcat( HIDCompiler, Version  );
845         strcat( HIDCompiler, Author   );
846         fprintf( stderr, "\n %s \n\n", HIDCompiler);
847         if(argc < 4) {
848                 fprintf(
849                 stderr,
850                 "usage: hidc file.src file.c project \n"
851                 "\n"
852                 "You must give exactly 3 arguments.\n"
853                 "1 - an existing SRC file.\n"
854                 "2 - C file to be generated (which generates the HID file when run).\n"
855                 "3 - the project name (an arbitrary name).\n\n"
856                 );
857                 exit(1);
858         }
860         project = argv[3];
862         char *outfilename = argv[2];
863         if( (outfile=fopen( outfilename , "w" )) ==NULL ) {
864                 fprintf(stderr,"error: could not open outputfile '%s' \n", outfilename);
865                 exit(1);
866         }
868         filename = argv[1];
869         nInputFileDepth = 0;
870         FILE* pFile;
871         pFile = fopen( filename, "r" );
872         if( pFile == NULL ) {
873                 fprintf( stderr, "error: could not open inputfile %s \n", filename );
874                 exit(1);
875         }
876         InputFiles[ nInputFileDepth ] = yy_create_buffer( pFile, YY_BUF_SIZE );
877     yy_switch_to_buffer( InputFiles[ nInputFileDepth ] );
878         ring = new ident_ring;
879         ares = new resource;
881         fprintf(outfile, "/* Generated from %s */\n\n", HIDCompiler );
882         fprintf(outfile, "/* Source was: %s */\n", filename );
884         yylineno = 1;
885         yylex(); /* do the real work here */
887         if( firstprint ) {
888                 fprintf(outfile, "#include \"starview.hid\" \n\n");
889                 fprintf(outfile, " int main() { \n\n\n");
890         }
891         fprintf(outfile, "\nreturn 0;");
892         fprintf(outfile, "\n} /*main*/\n");
893         return 0;
896 int yywrap()
898     yy_delete_buffer( InputFiles[ nInputFileDepth ] );
899         if ( nInputFileDepth == 0 )
900                 return 1;/* keine src files mehr */
901         else
902         {
903                 nInputFileDepth--;
904         fprintf(outfile, "// Done reading file\n\n");
905         yy_switch_to_buffer( InputFiles[ nInputFileDepth ] );
906                 return 0;
907         }
910 int eat_comment()
912         int c;
913         int lastc = ' ';
914         while( (c=yyinput()) != EOF ) {
915                 if( c=='\n')
916                         ;
917                 else if( c=='/' && lastc=='*' )
918                         break; /* end of comment found */
919                 lastc=c;
920         }
921         return 0;
924 int eat_cpp_comment()
926         int c;
927         while( (c=yyinput()) != EOF ) {
928                 if( c=='\n') {
929                         break;
930                 }
931         }
932         if( c != EOF )
933                 unput(c); /* because next #.... line was not found */
934         return 0;