1 %{
2 /*---------------------------------------------------------------------------*
3   Project:  NitroSDK - tools - makelcf
4   File:     tlcf.l
5 
6   Copyright 2003-2008 Nintendo. All rights reserved.
7 
8   These coded instructions, statements, and computer programs contain
9   proprietary information of Nintendo of America Inc. and/or Nintendo
10   Company Ltd., and are protected by Federal copyright law. They may
11   not be disclosed to third parties or copied or duplicated in any form,
12   in whole or in part, without the prior written consent of Nintendo.
13 
14   $Log: tlcf.l,v $
15   Revision 1.25  2007/07/09 12:17:54  yasu
16   Support for TARGET_NAME
17 
18   Revision 1.24  2007/07/09 07:02:00  yasu
19   Support for IF.EXIST
20 
21   Revision 1.23  2007/04/12 03:29:45  yasu
22   Revised such that IF FIRST/LAST can also support FOREACH OBJECT/LIBRARY
23 
24   Revision 1.22  2007/04/10 14:13:20  yasu
25   Support for multiple uses of SEARCH_SYMBOL
26 
27   Revision 1.21  2006/05/10 02:06:00  yasu
28   Added support for CodeWarrior 2.x
29 
30   Revision 1.20  2006/03/30 23:59:45  yasu
31   Updated copyright year
32 
33   Revision 1.19  2006/03/30 03:17:46  yasu
34   Also now recognizing NUMBER_OVERLAYS in order to deal with a bug
35 
36   Revision 1.18  2006/03/29 13:13:22  yasu
37   IF-ELSE-ENDIF support
38 
39   Revision 1.17  2005/09/01 04:30:52  yasu
40   Support for Overlay Group
41 
42   Revision 1.16  2005/08/26 11:23:11  yasu
43   Overlay support for ITCM/DTCM
44 
45   Revision 1.15  2005/06/22 00:50:06  yasu
46   Updated copyright year
47 
48   Revision 1.14  2005/06/20 12:21:48  yasu
49   Changed Surffix to Suffix
50 
51   Revision 1.13  2004/07/10 04:06:17  yasu
52   Added support for command 'Library'
53   Support for modifier ':x' in template
54   Fixed line continue '\' issue
55 
56   Revision 1.12  2004/07/02 07:34:53  yasu
57   Added support for OBJECT( )
58 
59   Revision 1.11  2004/06/24 07:18:54  yasu
60   Support for keyword "Autoload"
61 
62   Revision 1.10  2004/06/14 11:28:45  yasu
63   Support for section filter "FOREACH.STATIC.OBJECTS=.sectionName"
64 
65   Revision 1.9  2004/03/26 05:07:11  yasu
66   Support for variables like as -DNAME=VALUE
67 
68   Revision 1.8  2004/02/13 07:13:03  yasu
69   Support for SDK_IRQ_STACKSIZE
70 
71   Revision 1.7  2004/02/05 07:09:03  yasu
72   Changed SDK prefix from iris to nitro
73 
74   Revision 1.6  2004/01/15 13:21:03  yasu
75   One line <FOREACH.*> command enabled
76 
77   Revision 1.5  2004/01/15 10:47:56  yasu
78   Implementation of a static StackSize
79 
80   Revision 1.4  2004/01/14 12:58:47  yasu
81   Handle '\r' as newline
82 
83   Revision 1.3  2004/01/14 12:38:08  yasu
84   Changed OverlayName to OverlayDefs
85 
86   Revision 1.2  2004/01/07 13:10:17  yasu
87   Fixed all warnings at compile -Wall
88 
89   Revision 1.1  2004/01/05 02:32:59  yasu
90   Initial version
91 
92   $NoKeywords: $
93  *---------------------------------------------------------------------------*/
94 #include	<stdio.h>
95 #include	<string.h>
96 #include	"makelcf.h"
97 #include	"tlcf.tab.h"
98 
99 #define	RETURN(x) { debug_printf( "%s [%s]\n", #x, tlcf_yytext ); return(x); }
100 
101 BOOL  GetLoopStackLevel( void );
102 
tlcf_yyerror(const char * str)103 void  tlcf_yyerror( const char* str )
104 {
105     if ( tlcf_yytext[0] >= ' ' )
106     {
107         fprintf( stderr, "makelcf: line %d: %s \'%s\'\n", tlcf_yylineno, str, tlcf_yytext );
108     }
109     else
110     {
111         fprintf( stderr, "makelcf: line %d: %s\n", tlcf_yylineno, str );
112     }
113 }
114 
getSectionDot(int dotpos,const char * default_section)115 static char* getSectionDot( int dotpos, const char* default_section )
116 {
117     // Skip dotpos dots ('.') and begin from the following dot ('.'), if dotpos > 0 and there are at least that many dots
118     char*  head = NULL;
119     char*  p;
120 
121     for ( p = tlcf_yytext; *p; p ++ )
122     {
123 	switch ( *p )
124 	{
125 	case '.':
126 	    dotpos --;
127             if (dotpos != 0) break;
128 
129 	case '=':
130 	case ':':
131 	    if ( !head )
132 	    {
133 		head = p;
134 	    }
135 	    break;
136 
137 	case '>':
138 	    if ( head )
139 	    {
140 	        *p = '\0';
141 		return strdup( head );
142 	    }
143 	    break;
144 
145 	default:
146 	    break;
147 	}
148     }
149     return default_section ? strdup( default_section ) : NULL;
150 }
151 
getSection(const char * default_section)152 static char* getSection( const char* default_section )
153 {
154     return getSectionDot( 0, default_section );  // Do not search for a dot
155 }
156 
157 %}
158 st			[ \t]*
159 ed			[ \t]*\r?\n
160 sec			(=[.a-zA-Z]*)?
161 mod			(:[htre])?
162 flt			(:[f])?
163 wordt			=[^:>]*
164 wordf			(:[^:>]*)?
165 identifier		[A-Za-z_][A-Za-z_0-9]*
166 equation		(==|!=|\.EQ\.|\.NE\.|\.GT\.|\.GE\.|\.LT\.|\.LE\.)
167 value			[^>\n]*
168 trgfmt			(=[^>\n]*)?
169 
170 TARGET_NAME		\<TARGET\.NAME{trgfmt}\>
171 
172 STATIC_OBJ		\<STATIC\.OBJECT{sec}{mod}\>
173 F_S_OBJS		\<FOREACH\.STATIC\.OBJECTS{sec}{flt}\>
174 E_S_OBJS		\<END\.STATIC\.OBJECTS{sec}{flt}\>
175 FOR_STATIC_OBJS_1	^{st}{F_S_OBJS}{ed}
176 FOR_STATIC_OBJS_2	{F_S_OBJS}
177 END_STATIC_OBJS_1	^{st}{E_S_OBJS}{ed}
178 END_STATIC_OBJS_2	{E_S_OBJS}
179 IF_STATIC_OBJ_FIRST	\<IF\.STATIC\.OBJECT\.FIRST{wordt}{wordf}\>
180 IF_STATIC_OBJ_LAST	\<IF\.STATIC\.OBJECT\.LAST{wordt}{wordf}\>
181 
182 STATIC_LIB		\<STATIC\.LIBRARY{sec}{mod}\>
183 F_S_LIBS		\<FOREACH\.STATIC\.LIBRARIES{sec}{flt}\>
184 E_S_LIBS		\<END\.STATIC\.LIBRARIES{sec}{flt}\>
185 FOR_STATIC_LIBS_1	^{st}{F_S_LIBS}{ed}
186 FOR_STATIC_LIBS_2	{F_S_LIBS}
187 END_STATIC_LIBS_1	^{st}{E_S_LIBS}{ed}
188 END_STATIC_LIBS_2	{E_S_LIBS}
189 IF_STATIC_LIB_FIRST	\<IF\.STATIC\.LIBRARY\.FIRST{wordt}{wordf}\>
190 IF_STATIC_LIB_LAST	\<IF\.STATIC\.LIBRARY\.LAST{wordt}{wordf}\>
191 
192 STATIC_SYM		\<STATIC\.SEARCHSYMBOL\>
193 F_S_SYMS		\<FOREACH\.STATIC\.SEARCHSYMBOLS\>
194 E_S_SYMS		\<END\.STATIC\.SEARCHSYMBOLS\>
195 FOR_STATIC_SYMS_1	^{st}{F_S_SYMS}{ed}
196 FOR_STATIC_SYMS_2	{F_S_SYMS}
197 END_STATIC_SYMS_1	^{st}{E_S_SYMS}{ed}
198 END_STATIC_SYMS_2	{E_S_SYMS}
199 IF_STATIC_SYM_FIRST	\<IF\.STATIC\.SEARCHSYMBOL\.FIRST{wordt}{wordf}\>
200 IF_STATIC_SYM_LAST	\<IF\.STATIC\.SEARCHSYMBOL\.LAST{wordt}{wordf}\>
201 
202 STATIC_FOR		\<STATIC\.FORCE\>
203 F_S_FORS		\<FOREACH\.STATIC\.FORCES\>
204 E_S_FORS		\<END\.STATIC\.FORCES\>
205 FOR_STATIC_FORS_1	^{st}{F_S_FORS}{ed}
206 FOR_STATIC_FORS_2	{F_S_FORS}
207 END_STATIC_FORS_1	^{st}{E_S_FORS}{ed}
208 END_STATIC_FORS_2	{E_S_FORS}
209 IF_STATIC_FOR_FIRST	\<IF\.STATIC\.FORCE\.FIRST{wordt}{wordf}\>
210 IF_STATIC_FOR_LAST	\<IF\.STATIC\.FORCE\.LAST{wordt}{wordf}\>
211 
212 F_ATLS			\<FOREACH\.AUTOLOADS{sec}{flt}\>
213 E_ATLS			\<END\.AUTOLOADS{sec}{flt}\>
214 FOR_AUTOLOADS_1		^{st}{F_ATLS}{ed}
215 FOR_AUTOLOADS_2		{F_ATLS}
216 END_AUTOLOADS_1		^{st}{E_ATLS}{ed}
217 END_AUTOLOADS_2		{E_ATLS}
218 IF_AUTOLOAD_FIRST	\<IF\.AUTOLOAD\.FIRST{wordt}{wordf}\>
219 IF_AUTOLOAD_LAST	\<IF\.AUTOLOAD\.LAST{wordt}{wordf}\>
220 
221 AUTOLOAD_OBJ		\<AUTOLOAD\.OBJECT{sec}{mod}\>
222 F_A_OBJS		\<FOREACH\.AUTOLOAD\.OBJECTS{sec}{flt}\>
223 E_A_OBJS		\<END\.AUTOLOAD\.OBJECTS{sec}{flt}\>
224 FOR_AUTOLOAD_OBJS_1	^{st}{F_A_OBJS}{ed}
225 FOR_AUTOLOAD_OBJS_2	{F_A_OBJS}
226 END_AUTOLOAD_OBJS_1	^{st}{E_A_OBJS}{ed}
227 END_AUTOLOAD_OBJS_2	{E_A_OBJS}
228 IF_AUTOLOAD_OBJ_FIRST	\<IF\.AUTOLOAD\.OBJECT\.FIRST{wordt}{wordf}\>
229 IF_AUTOLOAD_OBJ_LAST	\<IF\.AUTOLOAD\.OBJECT\.LAST{wordt}{wordf}\>
230 
231 AUTOLOAD_LIB		\<AUTOLOAD\.LIBRARY{sec}{mod}\>
232 F_A_LIBS		\<FOREACH\.AUTOLOAD\.LIBRARIES{sec}{flt}\>
233 E_A_LIBS		\<END\.AUTOLOAD\.LIBRARIES{sec}{flt}\>
234 FOR_AUTOLOAD_LIBS_1	^{st}{F_A_LIBS}{ed}
235 FOR_AUTOLOAD_LIBS_2	{F_A_LIBS}
236 END_AUTOLOAD_LIBS_1	^{st}{E_A_LIBS}{ed}
237 END_AUTOLOAD_LIBS_2	{E_A_LIBS}
238 IF_AUTOLOAD_LIB_FIRST	\<IF\.AUTOLOAD\.LIBRARY\.FIRST{wordt}{wordf}\>
239 IF_AUTOLOAD_LIB_LAST	\<IF\.AUTOLOAD\.LIBRARY\.LAST{wordt}{wordf}\>
240 
241 AUTOLOAD_SYM		\<AUTOLOAD\.SEARCHSYMBOL\>
242 F_A_SYMS		\<FOREACH\.AUTOLOAD\.SEARCHSYMBOLS\>
243 E_A_SYMS		\<END\.AUTOLOAD\.SEARCHSYMBOLS\>
244 FOR_AUTOLOAD_SYMS_1	^{st}{F_A_SYMS}{ed}
245 FOR_AUTOLOAD_SYMS_2	{F_A_SYMS}
246 END_AUTOLOAD_SYMS_1	^{st}{E_A_SYMS}{ed}
247 END_AUTOLOAD_SYMS_2	{E_A_SYMS}
248 IF_AUTOLOAD_SYM_FIRST	\<IF\.AUTOLOAD\.SEARCHSYMBOL\.FIRST{wordt}{wordf}\>
249 IF_AUTOLOAD_SYM_LAST	\<IF\.AUTOLOAD\.SEARCHSYMBOL\.LAST{wordt}{wordf}\>
250 
251 AUTOLOAD_FOR		\<AUTOLOAD\.FORCE\>
252 F_A_FORS		\<FOREACH\.AUTOLOAD\.FORCES\>
253 E_A_FORS		\<END\.AUTOLOAD\.FORCES\>
254 FOR_AUTOLOAD_FORS_1	^{st}{F_A_FORS}{ed}
255 FOR_AUTOLOAD_FORS_2	{F_A_FORS}
256 END_AUTOLOAD_FORS_1	^{st}{E_A_FORS}{ed}
257 END_AUTOLOAD_FORS_2	{E_A_FORS}
258 IF_AUTOLOAD_FOR_FIRST	\<IF\.AUTOLOAD\.FORCE\.FIRST{wordt}{wordf}\>
259 IF_AUTOLOAD_FOR_LAST	\<IF\.AUTOLOAD\.FORCE\.LAST{wordt}{wordf}\>
260 
261 F_OVLS			\<FOREACH\.OVERLAYS{sec}{flt}\>
262 E_OVLS			\<END\.OVERLAYS{sec}{flt}\>
263 FOR_OVERLAYS_1		^{st}{F_OVLS}{ed}
264 FOR_OVERLAYS_2		{F_OVLS}
265 END_OVERLAYS_1		^{st}{E_OVLS}{ed}
266 END_OVERLAYS_2		{E_OVLS}
267 IF_OVERLAY_FIRST	\<IF\.OVERLAY\.FIRST{wordt}{wordf}\>
268 IF_OVERLAY_LAST		\<IF\.OVERLAY\.LAST{wordt}{wordf}\>
269 
270 OVERLAY_OBJ		\<OVERLAY\.OBJECT{sec}{mod}\>
271 F_O_OBJS		\<FOREACH\.OVERLAY\.OBJECTS{sec}{flt}\>
272 E_O_OBJS		\<END\.OVERLAY\.OBJECTS{sec}{flt}\>
273 FOR_OVERLAY_OBJS_1	^{st}{F_O_OBJS}{ed}
274 FOR_OVERLAY_OBJS_2	{F_O_OBJS}
275 END_OVERLAY_OBJS_1	^{st}{E_O_OBJS}{ed}
276 END_OVERLAY_OBJS_2	{E_O_OBJS}
277 IF_OVERLAY_OBJ_FIRST	\<IF\.OVERLAY\.OBJECT\.FIRST{wordt}{wordf}\>
278 IF_OVERLAY_OBJ_LAST	\<IF\.OVERLAY\.OBJECT\.LAST{wordt}{wordf}\>
279 
280 OVERLAY_LIB		\<OVERLAY\.LIBRARY{sec}{mod}\>
281 F_O_LIBS		\<FOREACH\.OVERLAY\.LIBRARIES{sec}{flt}\>
282 E_O_LIBS		\<END\.OVERLAY\.LIBRARIES{sec}{flt}\>
283 FOR_OVERLAY_LIBS_1	^{st}{F_O_LIBS}{ed}
284 FOR_OVERLAY_LIBS_2	{F_O_LIBS}
285 END_OVERLAY_LIBS_1	^{st}{E_O_LIBS}{ed}
286 END_OVERLAY_LIBS_2	{E_O_LIBS}
287 IF_OVERLAY_LIB_FIRST	\<IF\.OVERLAY\.LIBRARY\.FIRST{wordt}{wordf}\>
288 IF_OVERLAY_LIB_LAST	\<IF\.OVERLAY\.LIBRARY\.LAST{wordt}{wordf}\>
289 
290 OVERLAY_SYM		\<OVERLAY\.SEARCHSYMBOL\>
291 F_O_SYMS		\<FOREACH\.OVERLAY\.SEARCHSYMBOLS\>
292 E_O_SYMS		\<END\.OVERLAY\.SEARCHSYMBOLS\>
293 FOR_OVERLAY_SYMS_1	^{st}{F_O_SYMS}{ed}
294 FOR_OVERLAY_SYMS_2	{F_O_SYMS}
295 END_OVERLAY_SYMS_1	^{st}{E_O_SYMS}{ed}
296 END_OVERLAY_SYMS_2	{E_O_SYMS}
297 IF_OVERLAY_SYM_FIRST	\<IF\.OVERLAY\.SEARCHSYMBOL\.FIRST{wordt}{wordf}\>
298 IF_OVERLAY_SYM_LAST	\<IF\.OVERLAY\.SEARCHSYMBOL\.LAST{wordt}{wordf}\>
299 
300 OVERLAY_FOR		\<OVERLAY\.FORCE\>
301 F_O_FORS		\<FOREACH\.OVERLAY\.FORCES\>
302 E_O_FORS		\<END\.OVERLAY\.FORCES\>
303 FOR_OVERLAY_FORS_1	^{st}{F_O_FORS}{ed}
304 FOR_OVERLAY_FORS_2	{F_O_FORS}
305 END_OVERLAY_FORS_1	^{st}{E_O_FORS}{ed}
306 END_OVERLAY_FORS_2	{E_O_FORS}
307 IF_OVERLAY_FOR_FIRST	\<IF\.OVERLAY\.FOR\.FIRST{wordt}{wordf}\>
308 IF_OVERLAY_FOR_LAST	\<IF\.OVERLAY\.FORCE\.LAST{wordt}{wordf}\>
309 
310 IF_EXIST_SECTION	\<IF\.EXIST\.SECTION\.{identifier}{wordt}{wordf}\>
311 IF_EXIST_STATIC		\<IF\.EXIST\.STATIC\.{identifier}{wordt}{wordf}\>
312 IF_EXIST_AUTOLOAD	\<IF\.EXIST\.AUTOLOAD\.{identifier}{wordt}{wordf}\>
313 IF_EXIST_OVERLAY	\<IF\.EXIST\.OVERLAY\.{identifier}{wordt}{wordf}\>
314 
315 %x IFCOND1
316 %x IFCOND2
317 %x IFCOND3
318 %option pointer
319 %option yylineno
320 %option noyywrap
321 %%
322 
323  //===========================================================================
324  //    LCF TOKENS
325  //===========================================================================
326 
327 \<IF\.				{ BEGIN IFCOND1; RETURN(tIF_OPEN);  }
328 <IFCOND1>{identifier}		{ BEGIN IFCOND2; tlcf_yylval.string = strdup(tlcf_yytext); RETURN(tIF_ID);    }
329 <IFCOND2>{equation}		{ BEGIN IFCOND3; tlcf_yylval.string = strdup(tlcf_yytext); RETURN(tIF_COMP);  }
330 <IFCOND3>{value}		{                tlcf_yylval.string = strdup(tlcf_yytext); RETURN(tIF_VALUE); }
331 <IFCOND3>\>			{ BEGIN INITIAL; RETURN(tIF_CLOSE); }
332 \<ELSE\>			{ RETURN(tIF_ELSE);  }
333 \<ENDIF\>			{ RETURN(tIF_ENDIF); }
334 
335 {TARGET_NAME}			{ tlcf_yylval.string = getSection(NULL); RETURN(tTARGET_NAME); }
336 
337 \<STATIC\.NAME\>		{ RETURN(tSTATIC_NAME);            }
338 \<STATIC\.ADDRESS\>		{ RETURN(tSTATIC_ADDRESS);         }
339 \<STATIC\.STACKSIZE\>		{ RETURN(tSTATIC_STACKSIZE);       }
340 \<STATIC\.IRQSTACKSIZE\>	{ RETURN(tSTATIC_IRQSTACKSIZE);    }
341 
342 {STATIC_OBJ}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_OBJECT);          }
343 {FOR_STATIC_OBJS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_OBJECTS); }
344 {FOR_STATIC_OBJS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_OBJECTS); }
345 {END_STATIC_OBJS_1}		{ RETURN(tEND_STATIC_OBJECTS);     }
346 {END_STATIC_OBJS_2}		{ RETURN(tEND_STATIC_OBJECTS);     }
347 {IF_STATIC_OBJ_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_OBJECT_FIRST); }
348 {IF_STATIC_OBJ_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_OBJECT_LAST);  }
349 
350 {STATIC_LIB}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_LIBRARY);           }
351 {FOR_STATIC_LIBS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_LIBRARIES); }
352 {FOR_STATIC_LIBS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_LIBRARIES); }
353 {END_STATIC_LIBS_1}		{ RETURN(tEND_STATIC_LIBRARIES);   }
354 {END_STATIC_LIBS_2}		{ RETURN(tEND_STATIC_LIBRARIES);   }
355 {IF_STATIC_LIB_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_LIBRARY_FIRST); }
356 {IF_STATIC_LIB_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_LIBRARY_LAST);  }
357 
358 {STATIC_SYM}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_SEARCHSYMBOL);          }
359 {FOR_STATIC_SYMS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_SEARCHSYMBOLS); }
360 {FOR_STATIC_SYMS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_SEARCHSYMBOLS); }
361 {END_STATIC_SYMS_1}		{ RETURN(tEND_STATIC_SEARCHSYMBOLS); }
362 {END_STATIC_SYMS_2}		{ RETURN(tEND_STATIC_SEARCHSYMBOLS); }
363 {IF_STATIC_SYM_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_SEARCHSYMBOL_FIRST); }
364 {IF_STATIC_SYM_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_SEARCHSYMBOL_LAST);  }
365 
366 {STATIC_FOR}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_FORCE);          }
367 {FOR_STATIC_FORS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_FORCES); }
368 {FOR_STATIC_FORS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_FORCES); }
369 {END_STATIC_FORS_1}		{ RETURN(tEND_STATIC_FORCES); }
370 {END_STATIC_FORS_2}		{ RETURN(tEND_STATIC_FORCES); }
371 {IF_STATIC_FOR_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_FORCE_FIRST); }
372 {IF_STATIC_FOR_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_FORCE_LAST);  }
373 
374 \<AUTOLOAD\.ID\>		{ RETURN(tAUTOLOAD_ID);            }
375 \<AUTOLOAD\.NAME\>		{ RETURN(tAUTOLOAD_NAME);          }
376 \<AUTOLOAD\.ADDRESS\>		{ RETURN(tAUTOLOAD_ADDRESS);       }
377 \<NUMBER\.AUTOLOADS\>		{ RETURN(tNUMBER_AUTOLOADS);       }
378 
379 {FOR_AUTOLOADS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOADS); }
380 {FOR_AUTOLOADS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOADS); }
381 {END_AUTOLOADS_1}		{ RETURN(tEND_AUTOLOADS);          }
382 {END_AUTOLOADS_2}		{ RETURN(tEND_AUTOLOADS);          }
383 {IF_AUTOLOAD_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_FIRST); }
384 {IF_AUTOLOAD_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_LAST);  }
385 
386 {AUTOLOAD_OBJ}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_OBJECT);          }
387 {FOR_AUTOLOAD_OBJS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_OBJECTS); }
388 {FOR_AUTOLOAD_OBJS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_OBJECTS); }
389 {END_AUTOLOAD_OBJS_1}		{ RETURN(tEND_AUTOLOAD_OBJECTS);   }
390 {END_AUTOLOAD_OBJS_2}		{ RETURN(tEND_AUTOLOAD_OBJECTS);   }
391 {IF_AUTOLOAD_OBJ_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_OBJECT_FIRST); }
392 {IF_AUTOLOAD_OBJ_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_OBJECT_LAST);  }
393 
394 {AUTOLOAD_LIB}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_LIBRARY);           }
395 {FOR_AUTOLOAD_LIBS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_LIBRARIES); }
396 {FOR_AUTOLOAD_LIBS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_LIBRARIES); }
397 {END_AUTOLOAD_LIBS_1}		{ RETURN(tEND_AUTOLOAD_LIBRARIES); }
398 {END_AUTOLOAD_LIBS_2}		{ RETURN(tEND_AUTOLOAD_LIBRARIES); }
399 {IF_AUTOLOAD_LIB_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_LIBRARY_FIRST); }
400 {IF_AUTOLOAD_LIB_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_LIBRARY_LAST);  }
401 
402 {AUTOLOAD_SYM}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_SEARCHSYMBOL);          }
403 {FOR_AUTOLOAD_SYMS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_SEARCHSYMBOLS); }
404 {FOR_AUTOLOAD_SYMS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_SEARCHSYMBOLS); }
405 {END_AUTOLOAD_SYMS_1}		{ RETURN(tEND_AUTOLOAD_SEARCHSYMBOLS); }
406 {END_AUTOLOAD_SYMS_2}		{ RETURN(tEND_AUTOLOAD_SEARCHSYMBOLS); }
407 {IF_AUTOLOAD_SYM_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_SEARCHSYMBOL_FIRST); }
408 {IF_AUTOLOAD_SYM_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_SEARCHSYMBOL_LAST);  }
409 
410 {AUTOLOAD_FOR}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_FORCE);          }
411 {FOR_AUTOLOAD_FORS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_FORCES); }
412 {FOR_AUTOLOAD_FORS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_FORCES); }
413 {END_AUTOLOAD_FORS_1}		{ RETURN(tEND_AUTOLOAD_FORCES); }
414 {END_AUTOLOAD_FORS_2}		{ RETURN(tEND_AUTOLOAD_FORCES); }
415 {IF_AUTOLOAD_FOR_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_FORCE_FIRST); }
416 {IF_AUTOLOAD_FOR_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_FORCE_LAST);  }
417 
418 \<OVERLAY\.ID\>			{ RETURN(tOVERLAY_ID);             }
419 \<OVERLAY\.NAME\>		{ RETURN(tOVERLAY_NAME);           }
420 \<OVERLAY\.GROUP\>		{ RETURN(tOVERLAY_GROUP);          }
421 \<OVERLAY\.ADDRESS\>		{ RETURN(tOVERLAY_ADDRESS);        }
422 \<OVERLAY\.COMPRESS\>		{ RETURN(tOVERLAY_COMPRESS);        }
423 \<NUMBER\.OVERLAYS\>		{ RETURN(tNUMBER_OVERLAYS);        }
424 \<NUMBER_OVERLAYS\>		{ RETURN(tNUMBER_OVERLAYS);        }
425 
426 {FOR_OVERLAYS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAYS); }
427 {FOR_OVERLAYS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAYS); }
428 {END_OVERLAYS_1}		{ RETURN(tEND_OVERLAYS);           }
429 {END_OVERLAYS_2}		{ RETURN(tEND_OVERLAYS);           }
430 {IF_OVERLAY_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_FIRST); }
431 {IF_OVERLAY_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_LAST);  }
432 
433 {OVERLAY_OBJ}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_OBJECT);          }
434 {FOR_OVERLAY_OBJS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_OBJECTS); }
435 {FOR_OVERLAY_OBJS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_OBJECTS); }
436 {END_OVERLAY_OBJS_1}		{ RETURN(tEND_OVERLAY_OBJECTS);    }
437 {END_OVERLAY_OBJS_2}		{ RETURN(tEND_OVERLAY_OBJECTS);    }
438 {IF_OVERLAY_OBJ_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_OBJECT_FIRST); }
439 {IF_OVERLAY_OBJ_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_OBJECT_LAST);  }
440 
441 {OVERLAY_LIB}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_LIBRARY);           }
442 {FOR_OVERLAY_LIBS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_LIBRARIES); }
443 {FOR_OVERLAY_LIBS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_LIBRARIES); }
444 {END_OVERLAY_LIBS_1}		{ RETURN(tEND_OVERLAY_LIBRARIES);  }
445 {END_OVERLAY_LIBS_2}		{ RETURN(tEND_OVERLAY_LIBRARIES);  }
446 {IF_OVERLAY_LIB_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_LIBRARY_FIRST); }
447 {IF_OVERLAY_LIB_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_LIBRARY_LAST);  }
448 
449 {OVERLAY_SYM}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_SEARCHSYMBOL);          }
450 {FOR_OVERLAY_SYMS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_SEARCHSYMBOLS); }
451 {FOR_OVERLAY_SYMS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_SEARCHSYMBOLS); }
452 {END_OVERLAY_SYMS_1}		{ RETURN(tEND_OVERLAY_SEARCHSYMBOLS);  }
453 {END_OVERLAY_SYMS_2}		{ RETURN(tEND_OVERLAY_SEARCHSYMBOLS);  }
454 {IF_OVERLAY_SYM_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_SEARCHSYMBOL_FIRST); }
455 {IF_OVERLAY_SYM_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_SEARCHSYMBOL_LAST);  }
456 
457 {OVERLAY_FOR}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_FORCE);          }
458 {FOR_OVERLAY_FORS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_FORCES); }
459 {FOR_OVERLAY_FORS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_FORCES); }
460 {END_OVERLAY_FORS_1}		{ RETURN(tEND_OVERLAY_FORCES);  }
461 {END_OVERLAY_FORS_2}		{ RETURN(tEND_OVERLAY_FORCES);  }
462 {IF_OVERLAY_FOR_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_FORCE_FIRST); }
463 {IF_OVERLAY_FOR_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_FORCE_LAST);  }
464 
465 \<PROPERTY\.OVERLAYDEFS\>	{ RETURN(tPROPERTY_OVERLAYDEFS);   }
466 \<PROPERTY\.OVERLAYTABLE\>	{ RETURN(tPROPERTY_OVERLAYTABLE);  }
467 \<PROPERTY\.SUR?FFIX\>		{ RETURN(tPROPERTY_SUFFIX);        }
468 
469 {IF_EXIST_SECTION}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_SECTION);  }
470 {IF_EXIST_STATIC}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_STATIC);   }
471 {IF_EXIST_AUTOLOAD}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_AUTOLOAD); }
472 {IF_EXIST_OVERLAY}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_OVERLAY);  }
473 
474 [^<\n]*\n?		|
475 \<			{
476 	tlcf_yylval.string = strdup(tlcf_yytext);
477 	RETURN(tSTRING);
478 }
479 
480 .   			{ RETURN(tlcf_yytext[0]); }
481 
482 %%
483 
484 /*============================================================================
485  *  PARSE TLCF FILE
486  */
487 int  ParseTlcfFile( const char* filename )
488 {
489     FILE *fp;
490     int   result;
491 
492     if ( NULL == ( fp = fopen( filename, "r" ) ) )
493     {
494 	fprintf( stderr, "Cannot open %s\n", filename );
495 	return 2;
496     }
497 
498     tlcf_yyin  = fp;
499     result = tlcf_yyparse();
500     fclose( fp );
501 
502     if ( GetLoopStackLevel( ) > 0 )
503     {
504 	tlcf_yyerror( "Unmatched foreach-end pair" );
505 	return 1;
506     }
507 
508     return result ? 1 : 0;
509 }
510