2000-09-24 19:06:59 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2000-09-24 20:54:49 +00:00
|
|
|
/* config.c */
|
2000-09-24 19:06:59 +00:00
|
|
|
/* */
|
|
|
|
/* Disassembler configuration file handling */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* (C) 2000 Ullrich von Bassewitz */
|
|
|
|
/* Wacholderweg 14 */
|
|
|
|
/* D-70597 Stuttgart */
|
|
|
|
/* EMail: uz@musoftware.de */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
/* Microsoft compiler */
|
|
|
|
# include <io.h>
|
|
|
|
#else
|
|
|
|
/* Anyone else */
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
#include "xmalloc.h"
|
|
|
|
|
|
|
|
/* da65 */
|
2000-09-24 20:54:49 +00:00
|
|
|
#include "attrtab.h"
|
|
|
|
#include "error.h"
|
2000-09-24 19:06:59 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "scanner.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void GlobalSection (void)
|
|
|
|
/* Parse a global section */
|
|
|
|
{
|
|
|
|
static const IdentTok GlobalDefs[] = {
|
|
|
|
{ "INPUTNAME", CFGTOK_INPUTNAME },
|
|
|
|
{ "OUTPUTNAME", CFGTOK_OUTPUTNAME },
|
|
|
|
{ "PAGELENGTH", CFGTOK_PAGELENGTH },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Skip the token */
|
|
|
|
CfgNextTok ();
|
|
|
|
|
|
|
|
/* Expect the opening curly brace */
|
|
|
|
CfgConsumeLCurly ();
|
|
|
|
|
|
|
|
/* Look for section tokens */
|
|
|
|
while (CfgTok != CFGTOK_RCURLY) {
|
|
|
|
|
|
|
|
/* Convert to special token */
|
|
|
|
CfgSpecialToken (GlobalDefs, ENTRY_COUNT (GlobalDefs), "Global directive");
|
|
|
|
|
|
|
|
/* Look at the token */
|
|
|
|
switch (CfgTok) {
|
|
|
|
|
|
|
|
case CFGTOK_INPUTNAME:
|
|
|
|
CfgNextTok ();
|
|
|
|
CfgAssureStr ();
|
|
|
|
if (InFile) {
|
|
|
|
CfgError ("Input file name already given");
|
|
|
|
}
|
|
|
|
InFile = xstrdup (CfgSVal);
|
|
|
|
CfgNextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFGTOK_OUTPUTNAME:
|
|
|
|
CfgNextTok ();
|
|
|
|
CfgAssureStr ();
|
|
|
|
if (OutFile) {
|
|
|
|
CfgError ("Output file name already given");
|
|
|
|
}
|
|
|
|
OutFile = xstrdup (CfgSVal);
|
|
|
|
CfgNextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFGTOK_PAGELENGTH:
|
|
|
|
CfgNextTok ();
|
|
|
|
CfgAssureInt ();
|
|
|
|
if (CfgIVal != -1) {
|
|
|
|
CfgRangeCheck (MIN_PAGE_LEN, MAX_PAGE_LEN);
|
|
|
|
}
|
|
|
|
PageLength = CfgIVal;
|
|
|
|
CfgNextTok ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Directive is followed by a semicolon */
|
|
|
|
CfgConsumeSemi ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Consume the closing brace */
|
|
|
|
CfgConsumeRCurly ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void RangeSection (void)
|
|
|
|
/* Parse a range section */
|
|
|
|
{
|
|
|
|
static const IdentTok RangeDefs[] = {
|
2000-09-24 20:54:49 +00:00
|
|
|
{ "START", CFGTOK_START },
|
|
|
|
{ "END", CFGTOK_END },
|
2000-09-24 19:06:59 +00:00
|
|
|
{ "TYPE", CFGTOK_TYPE },
|
|
|
|
};
|
|
|
|
|
2000-09-24 20:54:49 +00:00
|
|
|
static const IdentTok TypeDefs[] = {
|
|
|
|
{ "CODE", CFGTOK_CODE },
|
|
|
|
{ "BYTETABLE", CFGTOK_BYTETAB },
|
|
|
|
{ "WORDTABLE", CFGTOK_WORDTAB },
|
2000-09-26 07:08:38 +00:00
|
|
|
{ "DWORDTABLE", CFGTOK_DWORDTAB },
|
2000-09-24 20:54:49 +00:00
|
|
|
{ "ADDRTABLE", CFGTOK_ADDRTAB },
|
|
|
|
{ "RTSTABLE", CFGTOK_RTSTAB },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Which values did we get? */
|
|
|
|
enum {
|
|
|
|
tNone = 0x00,
|
|
|
|
tStart = 0x01,
|
|
|
|
tEnd = 0x02,
|
|
|
|
tType = 0x04,
|
|
|
|
tAll = 0x07
|
|
|
|
} Needed = tNone;
|
|
|
|
|
|
|
|
/* Locals - initialize to avoid gcc warnings */
|
|
|
|
unsigned Start = 0;
|
|
|
|
unsigned End = 0;
|
|
|
|
unsigned char Type = 0;
|
|
|
|
|
2000-09-24 19:06:59 +00:00
|
|
|
/* Skip the token */
|
|
|
|
CfgNextTok ();
|
|
|
|
|
|
|
|
/* Expect the opening curly brace */
|
|
|
|
CfgConsumeLCurly ();
|
|
|
|
|
|
|
|
/* Look for section tokens */
|
|
|
|
while (CfgTok != CFGTOK_RCURLY) {
|
|
|
|
|
2000-09-24 20:54:49 +00:00
|
|
|
/* Convert to special token */
|
|
|
|
CfgSpecialToken (RangeDefs, ENTRY_COUNT (RangeDefs), "Range directive");
|
2000-09-24 19:06:59 +00:00
|
|
|
|
2000-09-24 20:54:49 +00:00
|
|
|
/* Look at the token */
|
|
|
|
switch (CfgTok) {
|
|
|
|
|
|
|
|
case CFGTOK_START:
|
|
|
|
CfgNextTok ();
|
|
|
|
CfgAssureInt ();
|
|
|
|
CfgRangeCheck (0x0000, 0xFFFF);
|
|
|
|
Start = CfgIVal;
|
|
|
|
Needed |= tStart;
|
|
|
|
CfgNextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFGTOK_END:
|
|
|
|
CfgNextTok ();
|
|
|
|
CfgAssureInt ();
|
|
|
|
CfgRangeCheck (0x0000, 0xFFFF);
|
|
|
|
End = CfgIVal;
|
|
|
|
Needed |= tEnd;
|
|
|
|
CfgNextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFGTOK_TYPE:
|
|
|
|
CfgNextTok ();
|
|
|
|
CfgSpecialToken (TypeDefs, ENTRY_COUNT (TypeDefs), "Type");
|
|
|
|
switch (CfgTok) {
|
|
|
|
case CFGTOK_CODE: Type = atCode; break;
|
|
|
|
case CFGTOK_BYTETAB: Type = atByteTab; break;
|
|
|
|
case CFGTOK_WORDTAB: Type = atWordTab; break;
|
2000-09-26 07:08:38 +00:00
|
|
|
case CFGTOK_DWORDTAB: Type = atDWordTab; break;
|
2000-09-24 20:54:49 +00:00
|
|
|
case CFGTOK_ADDRTAB: Type = atAddrTab; break;
|
|
|
|
case CFGTOK_RTSTAB: Type = atRtsTab; break;
|
|
|
|
}
|
|
|
|
Needed |= tType;
|
|
|
|
CfgNextTok ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Directive is followed by a semicolon */
|
|
|
|
CfgConsumeSemi ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we get all required values? */
|
|
|
|
if (Needed != tAll) {
|
|
|
|
Error ("Required values missing from this section");
|
2000-09-24 19:06:59 +00:00
|
|
|
}
|
|
|
|
|
2000-09-24 20:54:49 +00:00
|
|
|
/* Start must be less than end */
|
|
|
|
if (Start > End) {
|
|
|
|
Error ("Start value must not be greater than end value");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the range */
|
|
|
|
MarkRange (Start, End, Type);
|
|
|
|
|
2000-09-24 19:06:59 +00:00
|
|
|
/* Consume the closing brace */
|
|
|
|
CfgConsumeRCurly ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void LabelSection (void)
|
|
|
|
/* Parse a label section */
|
|
|
|
{
|
|
|
|
static const IdentTok Globals[] = {
|
|
|
|
{ "INPUTNAMEL", CFGTOK_INPUTNAME },
|
|
|
|
{ "OUTPUTNAME", CFGTOK_OUTPUTNAME },
|
|
|
|
{ "PAGELENGTH", CFGTOK_PAGELENGTH },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Skip the token */
|
|
|
|
CfgNextTok ();
|
|
|
|
|
|
|
|
/* Expect the opening curly brace */
|
|
|
|
CfgConsumeLCurly ();
|
|
|
|
|
|
|
|
/* Look for section tokens */
|
|
|
|
while (CfgTok != CFGTOK_RCURLY) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Consume the closing brace */
|
|
|
|
CfgConsumeRCurly ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void CfgParse (void)
|
|
|
|
/* Parse the config file */
|
|
|
|
{
|
|
|
|
static const IdentTok Globals[] = {
|
|
|
|
{ "GLOBAL", CFGTOK_GLOBAL },
|
|
|
|
{ "RANGE", CFGTOK_RANGE },
|
|
|
|
{ "LABEL", CFGTOK_LABEL },
|
|
|
|
};
|
|
|
|
|
|
|
|
while (CfgTok != CFGTOK_EOF) {
|
|
|
|
|
|
|
|
/* Convert an identifier into a token */
|
|
|
|
CfgSpecialToken (Globals, ENTRY_COUNT (Globals), "Config directive");
|
|
|
|
|
|
|
|
/* Check the token */
|
|
|
|
switch (CfgTok) {
|
|
|
|
|
|
|
|
case CFGTOK_GLOBAL:
|
|
|
|
GlobalSection ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFGTOK_RANGE:
|
|
|
|
RangeSection ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFGTOK_LABEL:
|
|
|
|
LabelSection ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Semicolon expected */
|
|
|
|
CfgConsumeSemi ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgRead (void)
|
|
|
|
/* Read the configuration if a configuration file exists */
|
|
|
|
{
|
|
|
|
/* Check if we have a config file given */
|
|
|
|
if (!CfgAvail() || access (CfgGetName(), 0) != 0) {
|
|
|
|
/* No name given or file not found */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the config file */
|
|
|
|
CfgOpenInput ();
|
|
|
|
|
|
|
|
/* Parse the config file */
|
|
|
|
CfgParse ();
|
|
|
|
|
|
|
|
/* Close the file */
|
|
|
|
CfgCloseInput ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|