1 /*****************************************************************************/
5 /* Disassembler configuration file handling */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
37 /* Microsoft compiler */
56 /*****************************************************************************/
58 /*****************************************************************************/
62 static void GlobalSection (void)
63 /* Parse a global section */
65 static const IdentTok GlobalDefs[] = {
66 { "INPUTNAME", CFGTOK_INPUTNAME },
67 { "OUTPUTNAME", CFGTOK_OUTPUTNAME },
68 { "PAGELENGTH", CFGTOK_PAGELENGTH },
74 /* Expect the opening curly brace */
77 /* Look for section tokens */
78 while (CfgTok != CFGTOK_RCURLY) {
80 /* Convert to special token */
81 CfgSpecialToken (GlobalDefs, ENTRY_COUNT (GlobalDefs), "Global directive");
83 /* Look at the token */
86 case CFGTOK_INPUTNAME:
90 CfgError ("Input file name already given");
92 InFile = xstrdup (CfgSVal);
96 case CFGTOK_OUTPUTNAME:
100 CfgError ("Output file name already given");
102 OutFile = xstrdup (CfgSVal);
106 case CFGTOK_PAGELENGTH:
110 CfgRangeCheck (MIN_PAGE_LEN, MAX_PAGE_LEN);
112 PageLength = CfgIVal;
117 /* Directive is followed by a semicolon */
122 /* Consume the closing brace */
128 static void RangeSection (void)
129 /* Parse a range section */
131 static const IdentTok RangeDefs[] = {
132 { "START", CFGTOK_START },
133 { "END", CFGTOK_END },
134 { "TYPE", CFGTOK_TYPE },
137 static const IdentTok TypeDefs[] = {
138 { "CODE", CFGTOK_CODE },
139 { "BYTETABLE", CFGTOK_BYTETAB },
140 { "WORDTABLE", CFGTOK_WORDTAB },
141 { "DWORDTABLE", CFGTOK_DWORDTAB },
142 { "ADDRTABLE", CFGTOK_ADDRTAB },
143 { "RTSTABLE", CFGTOK_RTSTAB },
147 /* Which values did we get? */
156 /* Locals - initialize to avoid gcc warnings */
159 unsigned char Type = 0;
164 /* Expect the opening curly brace */
167 /* Look for section tokens */
168 while (CfgTok != CFGTOK_RCURLY) {
170 /* Convert to special token */
171 CfgSpecialToken (RangeDefs, ENTRY_COUNT (RangeDefs), "Range directive");
173 /* Look at the token */
179 CfgRangeCheck (0x0000, 0xFFFF);
188 CfgRangeCheck (0x0000, 0xFFFF);
196 CfgSpecialToken (TypeDefs, ENTRY_COUNT (TypeDefs), "Type");
198 case CFGTOK_CODE: Type = atCode; break;
199 case CFGTOK_BYTETAB: Type = atByteTab; break;
200 case CFGTOK_WORDTAB: Type = atWordTab; break;
201 case CFGTOK_DWORDTAB: Type = atDWordTab; break;
202 case CFGTOK_ADDRTAB: Type = atAddrTab; break;
203 case CFGTOK_RTSTAB: Type = atRtsTab; break;
210 /* Directive is followed by a semicolon */
215 /* Did we get all required values? */
216 if (Needed != tAll) {
217 Error ("Required values missing from this section");
220 /* Start must be less than end */
222 Error ("Start value must not be greater than end value");
226 MarkRange (Start, End, Type);
228 /* Consume the closing brace */
234 static void LabelSection (void)
235 /* Parse a label section */
237 static const IdentTok Globals[] = {
238 { "INPUTNAMEL", CFGTOK_INPUTNAME },
239 { "OUTPUTNAME", CFGTOK_OUTPUTNAME },
240 { "PAGELENGTH", CFGTOK_PAGELENGTH },
246 /* Expect the opening curly brace */
249 /* Look for section tokens */
250 while (CfgTok != CFGTOK_RCURLY) {
255 /* Consume the closing brace */
261 static void CfgParse (void)
262 /* Parse the config file */
264 static const IdentTok Globals[] = {
265 { "GLOBAL", CFGTOK_GLOBAL },
266 { "RANGE", CFGTOK_RANGE },
267 { "LABEL", CFGTOK_LABEL },
270 while (CfgTok != CFGTOK_EOF) {
272 /* Convert an identifier into a token */
273 CfgSpecialToken (Globals, ENTRY_COUNT (Globals), "Config directive");
275 /* Check the token */
292 /* Semicolon expected */
300 /* Read the configuration if a configuration file exists */
302 /* Check if we have a config file given */
303 if (!CfgAvail() || access (CfgGetName(), 0) != 0) {
304 /* No name given or file not found */
308 /* Open the config file */
311 /* Parse the config file */