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 F_ATLS			\<FOREACH\.AUTOLOADS{sec}{flt}\>
203 E_ATLS			\<END\.AUTOLOADS{sec}{flt}\>
204 FOR_AUTOLOADS_1		^{st}{F_ATLS}{ed}
205 FOR_AUTOLOADS_2		{F_ATLS}
206 END_AUTOLOADS_1		^{st}{E_ATLS}{ed}
207 END_AUTOLOADS_2		{E_ATLS}
208 IF_AUTOLOAD_FIRST	\<IF\.AUTOLOAD\.FIRST{wordt}{wordf}\>
209 IF_AUTOLOAD_LAST	\<IF\.AUTOLOAD\.LAST{wordt}{wordf}\>
210 
211 AUTOLOAD_OBJ		\<AUTOLOAD\.OBJECT{sec}{mod}\>
212 F_A_OBJS		\<FOREACH\.AUTOLOAD\.OBJECTS{sec}{flt}\>
213 E_A_OBJS		\<END\.AUTOLOAD\.OBJECTS{sec}{flt}\>
214 FOR_AUTOLOAD_OBJS_1	^{st}{F_A_OBJS}{ed}
215 FOR_AUTOLOAD_OBJS_2	{F_A_OBJS}
216 END_AUTOLOAD_OBJS_1	^{st}{E_A_OBJS}{ed}
217 END_AUTOLOAD_OBJS_2	{E_A_OBJS}
218 IF_AUTOLOAD_OBJ_FIRST	\<IF\.AUTOLOAD\.OBJECT\.FIRST{wordt}{wordf}\>
219 IF_AUTOLOAD_OBJ_LAST	\<IF\.AUTOLOAD\.OBJECT\.LAST{wordt}{wordf}\>
220 
221 AUTOLOAD_LIB		\<AUTOLOAD\.LIBRARY{sec}{mod}\>
222 F_A_LIBS		\<FOREACH\.AUTOLOAD\.LIBRARIES{sec}{flt}\>
223 E_A_LIBS		\<END\.AUTOLOAD\.LIBRARIES{sec}{flt}\>
224 FOR_AUTOLOAD_LIBS_1	^{st}{F_A_LIBS}{ed}
225 FOR_AUTOLOAD_LIBS_2	{F_A_LIBS}
226 END_AUTOLOAD_LIBS_1	^{st}{E_A_LIBS}{ed}
227 END_AUTOLOAD_LIBS_2	{E_A_LIBS}
228 IF_AUTOLOAD_LIB_FIRST	\<IF\.AUTOLOAD\.LIBRARY\.FIRST{wordt}{wordf}\>
229 IF_AUTOLOAD_LIB_LAST	\<IF\.AUTOLOAD\.LIBRARY\.LAST{wordt}{wordf}\>
230 
231 AUTOLOAD_SYM		\<AUTOLOAD\.SEARCHSYMBOL\>
232 F_A_SYMS		\<FOREACH\.AUTOLOAD\.SEARCHSYMBOLS\>
233 E_A_SYMS		\<END\.AUTOLOAD\.SEARCHSYMBOLS\>
234 FOR_AUTOLOAD_SYMS_1	^{st}{F_A_SYMS}{ed}
235 FOR_AUTOLOAD_SYMS_2	{F_A_SYMS}
236 END_AUTOLOAD_SYMS_1	^{st}{E_A_SYMS}{ed}
237 END_AUTOLOAD_SYMS_2	{E_A_SYMS}
238 IF_AUTOLOAD_SYM_FIRST	\<IF\.AUTOLOAD\.SEARCHSYMBOL\.FIRST{wordt}{wordf}\>
239 IF_AUTOLOAD_SYM_LAST	\<IF\.AUTOLOAD\.SEARCHSYMBOL\.LAST{wordt}{wordf}\>
240 
241 F_OVLS			\<FOREACH\.OVERLAYS{sec}{flt}\>
242 E_OVLS			\<END\.OVERLAYS{sec}{flt}\>
243 FOR_OVERLAYS_1		^{st}{F_OVLS}{ed}
244 FOR_OVERLAYS_2		{F_OVLS}
245 END_OVERLAYS_1		^{st}{E_OVLS}{ed}
246 END_OVERLAYS_2		{E_OVLS}
247 IF_OVERLAY_FIRST	\<IF\.OVERLAY\.FIRST{wordt}{wordf}\>
248 IF_OVERLAY_LAST		\<IF\.OVERLAY\.LAST{wordt}{wordf}\>
249 
250 OVERLAY_OBJ		\<OVERLAY\.OBJECT{sec}{mod}\>
251 F_O_OBJS		\<FOREACH\.OVERLAY\.OBJECTS{sec}{flt}\>
252 E_O_OBJS		\<END\.OVERLAY\.OBJECTS{sec}{flt}\>
253 FOR_OVERLAY_OBJS_1	^{st}{F_O_OBJS}{ed}
254 FOR_OVERLAY_OBJS_2	{F_O_OBJS}
255 END_OVERLAY_OBJS_1	^{st}{E_O_OBJS}{ed}
256 END_OVERLAY_OBJS_2	{E_O_OBJS}
257 IF_OVERLAY_OBJ_FIRST	\<IF\.OVERLAY\.OBJECT\.FIRST{wordt}{wordf}\>
258 IF_OVERLAY_OBJ_LAST	\<IF\.OVERLAY\.OBJECT\.LAST{wordt}{wordf}\>
259 
260 OVERLAY_LIB		\<OVERLAY\.LIBRARY{sec}{mod}\>
261 F_O_LIBS		\<FOREACH\.OVERLAY\.LIBRARIES{sec}{flt}\>
262 E_O_LIBS		\<END\.OVERLAY\.LIBRARIES{sec}{flt}\>
263 FOR_OVERLAY_LIBS_1	^{st}{F_O_LIBS}{ed}
264 FOR_OVERLAY_LIBS_2	{F_O_LIBS}
265 END_OVERLAY_LIBS_1	^{st}{E_O_LIBS}{ed}
266 END_OVERLAY_LIBS_2	{E_O_LIBS}
267 IF_OVERLAY_LIB_FIRST	\<IF\.OVERLAY\.LIBRARY\.FIRST{wordt}{wordf}\>
268 IF_OVERLAY_LIB_LAST	\<IF\.OVERLAY\.LIBRARY\.LAST{wordt}{wordf}\>
269 
270 OVERLAY_SYM		\<OVERLAY\.SEARCHSYMBOL\>
271 F_O_SYMS		\<FOREACH\.OVERLAY\.SEARCHSYMBOLS\>
272 E_O_SYMS		\<END\.OVERLAY\.SEARCHSYMBOLS\>
273 FOR_OVERLAY_SYMS_1	^{st}{F_O_SYMS}{ed}
274 FOR_OVERLAY_SYMS_2	{F_O_SYMS}
275 END_OVERLAY_SYMS_1	^{st}{E_O_SYMS}{ed}
276 END_OVERLAY_SYMS_2	{E_O_SYMS}
277 IF_OVERLAY_SYM_FIRST	\<IF\.OVERLAY\.SEARCHSYMBOL\.FIRST{wordt}{wordf}\>
278 IF_OVERLAY_SYM_LAST	\<IF\.OVERLAY\.SEARCHSYMBOL\.LAST{wordt}{wordf}\>
279 
280 IF_EXIST_SECTION	\<IF\.EXIST\.SECTION\.{identifier}{wordt}{wordf}\>
281 IF_EXIST_STATIC		\<IF\.EXIST\.STATIC\.{identifier}{wordt}{wordf}\>
282 IF_EXIST_AUTOLOAD	\<IF\.EXIST\.AUTOLOAD\.{identifier}{wordt}{wordf}\>
283 IF_EXIST_OVERLAY	\<IF\.EXIST\.OVERLAY\.{identifier}{wordt}{wordf}\>
284 
285 %x IFCOND1
286 %x IFCOND2
287 %x IFCOND3
288 %option pointer
289 %option yylineno
290 %option noyywrap
291 %%
292 
293  //===========================================================================
294  //    LCF TOKENS
295  //===========================================================================
296 
297 \<IF\.				{ BEGIN IFCOND1; RETURN(tIF_OPEN);  }
298 <IFCOND1>{identifier}		{ BEGIN IFCOND2; tlcf_yylval.string = strdup(tlcf_yytext); RETURN(tIF_ID);    }
299 <IFCOND2>{equation}		{ BEGIN IFCOND3; tlcf_yylval.string = strdup(tlcf_yytext); RETURN(tIF_COMP);  }
300 <IFCOND3>{value}		{                tlcf_yylval.string = strdup(tlcf_yytext); RETURN(tIF_VALUE); }
301 <IFCOND3>\>			{ BEGIN INITIAL; RETURN(tIF_CLOSE); }
302 \<ELSE\>			{ RETURN(tIF_ELSE);  }
303 \<ENDIF\>			{ RETURN(tIF_ENDIF); }
304 
305 {TARGET_NAME}			{ tlcf_yylval.string = getSection(NULL); RETURN(tTARGET_NAME); }
306 
307 \<STATIC\.NAME\>		{ RETURN(tSTATIC_NAME);            }
308 \<STATIC\.ADDRESS\>		{ RETURN(tSTATIC_ADDRESS);         }
309 \<STATIC\.STACKSIZE\>		{ RETURN(tSTATIC_STACKSIZE);       }
310 \<STATIC\.IRQSTACKSIZE\>	{ RETURN(tSTATIC_IRQSTACKSIZE);    }
311 
312 {STATIC_OBJ}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_OBJECT);          }
313 {FOR_STATIC_OBJS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_OBJECTS); }
314 {FOR_STATIC_OBJS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_OBJECTS); }
315 {END_STATIC_OBJS_1}		{ RETURN(tEND_STATIC_OBJECTS);     }
316 {END_STATIC_OBJS_2}		{ RETURN(tEND_STATIC_OBJECTS);     }
317 {IF_STATIC_OBJ_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_OBJECT_FIRST); }
318 {IF_STATIC_OBJ_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_OBJECT_LAST);  }
319 
320 {STATIC_LIB}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_LIBRARY);           }
321 {FOR_STATIC_LIBS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_LIBRARIES); }
322 {FOR_STATIC_LIBS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_LIBRARIES); }
323 {END_STATIC_LIBS_1}		{ RETURN(tEND_STATIC_LIBRARIES);   }
324 {END_STATIC_LIBS_2}		{ RETURN(tEND_STATIC_LIBRARIES);   }
325 {IF_STATIC_LIB_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_LIBRARY_FIRST); }
326 {IF_STATIC_LIB_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_LIBRARY_LAST);  }
327 
328 {STATIC_SYM}			{ tlcf_yylval.string = getSection(NULL); RETURN(tSTATIC_SEARCHSYMBOL);          }
329 {FOR_STATIC_SYMS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_SEARCHSYMBOLS); }
330 {FOR_STATIC_SYMS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_STATIC_SEARCHSYMBOLS); }
331 {END_STATIC_SYMS_1}		{ RETURN(tEND_STATIC_SEARCHSYMBOLS); }
332 {END_STATIC_SYMS_2}		{ RETURN(tEND_STATIC_SEARCHSYMBOLS); }
333 {IF_STATIC_SYM_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_SEARCHSYMBOL_FIRST); }
334 {IF_STATIC_SYM_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_STATIC_SEARCHSYMBOL_LAST);  }
335 
336 \<AUTOLOAD\.ID\>		{ RETURN(tAUTOLOAD_ID);            }
337 \<AUTOLOAD\.NAME\>		{ RETURN(tAUTOLOAD_NAME);          }
338 \<AUTOLOAD\.ADDRESS\>		{ RETURN(tAUTOLOAD_ADDRESS);       }
339 \<NUMBER\.AUTOLOADS\>		{ RETURN(tNUMBER_AUTOLOADS);       }
340 
341 {FOR_AUTOLOADS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOADS); }
342 {FOR_AUTOLOADS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOADS); }
343 {END_AUTOLOADS_1}		{ RETURN(tEND_AUTOLOADS);          }
344 {END_AUTOLOADS_2}		{ RETURN(tEND_AUTOLOADS);          }
345 {IF_AUTOLOAD_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_FIRST); }
346 {IF_AUTOLOAD_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_LAST);  }
347 
348 {AUTOLOAD_OBJ}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_OBJECT);          }
349 {FOR_AUTOLOAD_OBJS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_OBJECTS); }
350 {FOR_AUTOLOAD_OBJS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_OBJECTS); }
351 {END_AUTOLOAD_OBJS_1}		{ RETURN(tEND_AUTOLOAD_OBJECTS);   }
352 {END_AUTOLOAD_OBJS_2}		{ RETURN(tEND_AUTOLOAD_OBJECTS);   }
353 {IF_AUTOLOAD_OBJ_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_OBJECT_FIRST); }
354 {IF_AUTOLOAD_OBJ_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_OBJECT_LAST);  }
355 
356 {AUTOLOAD_LIB}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_LIBRARY);           }
357 {FOR_AUTOLOAD_LIBS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_LIBRARIES); }
358 {FOR_AUTOLOAD_LIBS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_LIBRARIES); }
359 {END_AUTOLOAD_LIBS_1}		{ RETURN(tEND_AUTOLOAD_LIBRARIES); }
360 {END_AUTOLOAD_LIBS_2}		{ RETURN(tEND_AUTOLOAD_LIBRARIES); }
361 {IF_AUTOLOAD_LIB_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_LIBRARY_FIRST); }
362 {IF_AUTOLOAD_LIB_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_LIBRARY_LAST);  }
363 
364 {AUTOLOAD_SYM}			{ tlcf_yylval.string = getSection(NULL); RETURN(tAUTOLOAD_SEARCHSYMBOL);          }
365 {FOR_AUTOLOAD_SYMS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_SEARCHSYMBOLS); }
366 {FOR_AUTOLOAD_SYMS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_AUTOLOAD_SEARCHSYMBOLS); }
367 {END_AUTOLOAD_SYMS_1}		{ RETURN(tEND_AUTOLOAD_SEARCHSYMBOLS); }
368 {END_AUTOLOAD_SYMS_2}		{ RETURN(tEND_AUTOLOAD_SEARCHSYMBOLS); }
369 {IF_AUTOLOAD_SYM_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_SEARCHSYMBOL_FIRST); }
370 {IF_AUTOLOAD_SYM_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_AUTOLOAD_SEARCHSYMBOL_LAST);  }
371 
372 \<OVERLAY\.ID\>			{ RETURN(tOVERLAY_ID);             }
373 \<OVERLAY\.NAME\>		{ RETURN(tOVERLAY_NAME);           }
374 \<OVERLAY\.GROUP\>		{ RETURN(tOVERLAY_GROUP);          }
375 \<OVERLAY\.ADDRESS\>		{ RETURN(tOVERLAY_ADDRESS);        }
376 \<NUMBER\.OVERLAYS\>		{ RETURN(tNUMBER_OVERLAYS);        }
377 \<NUMBER_OVERLAYS\>		{ RETURN(tNUMBER_OVERLAYS);        }
378 
379 {FOR_OVERLAYS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAYS); }
380 {FOR_OVERLAYS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAYS); }
381 {END_OVERLAYS_1}		{ RETURN(tEND_OVERLAYS);           }
382 {END_OVERLAYS_2}		{ RETURN(tEND_OVERLAYS);           }
383 {IF_OVERLAY_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_FIRST); }
384 {IF_OVERLAY_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_LAST);  }
385 
386 {OVERLAY_OBJ}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_OBJECT);          }
387 {FOR_OVERLAY_OBJS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_OBJECTS); }
388 {FOR_OVERLAY_OBJS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_OBJECTS); }
389 {END_OVERLAY_OBJS_1}		{ RETURN(tEND_OVERLAY_OBJECTS);    }
390 {END_OVERLAY_OBJS_2}		{ RETURN(tEND_OVERLAY_OBJECTS);    }
391 {IF_OVERLAY_OBJ_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_OBJECT_FIRST); }
392 {IF_OVERLAY_OBJ_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_OBJECT_LAST);  }
393 
394 {OVERLAY_LIB}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_LIBRARY);           }
395 {FOR_OVERLAY_LIBS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_LIBRARIES); }
396 {FOR_OVERLAY_LIBS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_LIBRARIES); }
397 {END_OVERLAY_LIBS_1}		{ RETURN(tEND_OVERLAY_LIBRARIES);  }
398 {END_OVERLAY_LIBS_2}		{ RETURN(tEND_OVERLAY_LIBRARIES);  }
399 {IF_OVERLAY_LIB_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_LIBRARY_FIRST); }
400 {IF_OVERLAY_LIB_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_LIBRARY_LAST);  }
401 
402 {OVERLAY_SYM}			{ tlcf_yylval.string = getSection(NULL); RETURN(tOVERLAY_SEARCHSYMBOL);          }
403 {FOR_OVERLAY_SYMS_1}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_SEARCHSYMBOLS); }
404 {FOR_OVERLAY_SYMS_2}		{ tlcf_yylval.string = getSection("=*"); RETURN(tFOREACH_OVERLAY_SEARCHSYMBOLS); }
405 {END_OVERLAY_SYMS_1}		{ RETURN(tEND_OVERLAY_SEARCHSYMBOLS);  }
406 {END_OVERLAY_SYMS_2}		{ RETURN(tEND_OVERLAY_SEARCHSYMBOLS);  }
407 {IF_OVERLAY_SYM_FIRST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_SEARCHSYMBOL_FIRST); }
408 {IF_OVERLAY_SYM_LAST}		{ tlcf_yylval.string = getSection(NULL); RETURN(tIF_OVERLAY_SEARCHSYMBOL_LAST);  }
409 
410 \<PROPERTY\.OVERLAYDEFS\>	{ RETURN(tPROPERTY_OVERLAYDEFS);   }
411 \<PROPERTY\.OVERLAYTABLE\>	{ RETURN(tPROPERTY_OVERLAYTABLE);  }
412 \<PROPERTY\.SUR?FFIX\>		{ RETURN(tPROPERTY_SUFFIX);        }
413 
414 {IF_EXIST_SECTION}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_SECTION);  }
415 {IF_EXIST_STATIC}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_STATIC);   }
416 {IF_EXIST_AUTOLOAD}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_AUTOLOAD); }
417 {IF_EXIST_OVERLAY}		{ tlcf_yylval.string = getSectionDot(3,NULL); RETURN(tIF_EXIST_OVERLAY);  }
418 
419 [^<\n]*\n?		|
420 \<			{
421 	tlcf_yylval.string = strdup(tlcf_yytext);
422 	RETURN(tSTRING);
423 }
424 
425 .   			{ RETURN(tlcf_yytext[0]); }
426 
427 %%
428 
429 /*============================================================================
430  *  PARSE TLCF FILE
431  */
432 int  ParseTlcfFile( const char* filename )
433 {
434     FILE *fp;
435     int   result;
436 
437     if ( NULL == ( fp = fopen( filename, "r" ) ) )
438     {
439 	fprintf( stderr, "Cannot open %s\n", filename );
440 	return 2;
441     }
442 
443     tlcf_yyin  = fp;
444     result = tlcf_yyparse();
445     fclose( fp );
446 
447     if ( GetLoopStackLevel( ) > 0 )
448     {
449 	tlcf_yyerror( "Unmatched foreach-end pair" );
450 	return 1;
451     }
452 
453     return result ? 1 : 0;
454 }
455