From 817b2ac261ee0f0121542e3b6a9202f744a161dd Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 9 Aug 2003 08:28:44 +0000 Subject: [PATCH] Renamed the config file to info file and changed the handling when the disassembler is invoked. git-svn-id: svn://svn.cc65.org/cc65/trunk@2255 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/da65/{config.c => infofile.c} | 291 +++++++++++++++--------------- src/da65/{config.h => infofile.h} | 22 +-- src/da65/main.c | 26 ++- src/da65/make/gcc.mak | 2 +- src/da65/make/watcom.mak | 8 +- src/da65/scanner.c | 251 ++++++++++++-------------- src/da65/scanner.h | 143 +++++++-------- 7 files changed, 362 insertions(+), 381 deletions(-) rename src/da65/{config.c => infofile.c} (54%) rename src/da65/{config.h => infofile.h} (81%) diff --git a/src/da65/config.c b/src/da65/infofile.c similarity index 54% rename from src/da65/config.c rename to src/da65/infofile.c index f6fefab7f..c9e0863aa 100644 --- a/src/da65/config.c +++ b/src/da65/infofile.c @@ -1,15 +1,15 @@ /*****************************************************************************/ /* */ -/* config.c */ +/* infofile.h */ /* */ -/* Disassembler configuration file handling */ +/* Disassembler info file handling */ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -50,8 +50,8 @@ #include "attrtab.h" #include "error.h" #include "global.h" +#include "infofile.h" #include "scanner.h" -#include "config.h" @@ -65,74 +65,74 @@ static void GlobalSection (void) /* Parse a global section */ { static const IdentTok GlobalDefs[] = { - { "INPUTNAME", CFGTOK_INPUTNAME }, - { "OUTPUTNAME", CFGTOK_OUTPUTNAME }, - { "PAGELENGTH", CFGTOK_PAGELENGTH }, - { "STARTADDR", CFGTOK_STARTADDR }, + { "INPUTNAME", INFOTOK_INPUTNAME }, + { "OUTPUTNAME", INFOTOK_OUTPUTNAME }, + { "PAGELENGTH", INFOTOK_PAGELENGTH }, + { "STARTADDR", INFOTOK_STARTADDR }, }; /* Skip the token */ - CfgNextTok (); + InfoNextTok (); /* Expect the opening curly brace */ - CfgConsumeLCurly (); + InfoConsumeLCurly (); /* Look for section tokens */ - while (CfgTok != CFGTOK_RCURLY) { + while (InfoTok != INFOTOK_RCURLY) { /* Convert to special token */ - CfgSpecialToken (GlobalDefs, ENTRY_COUNT (GlobalDefs), "Global directive"); + InfoSpecialToken (GlobalDefs, ENTRY_COUNT (GlobalDefs), "Global directive"); /* Look at the token */ - switch (CfgTok) { + switch (InfoTok) { - case CFGTOK_INPUTNAME: - CfgNextTok (); - CfgAssureStr (); + case INFOTOK_INPUTNAME: + InfoNextTok (); + InfoAssureStr (); if (InFile) { - CfgError ("Input file name already given"); + InfoError ("Input file name already given"); } - InFile = xstrdup (CfgSVal); - CfgNextTok (); + InFile = xstrdup (InfoSVal); + InfoNextTok (); break; - case CFGTOK_OUTPUTNAME: - CfgNextTok (); - CfgAssureStr (); + case INFOTOK_OUTPUTNAME: + InfoNextTok (); + InfoAssureStr (); if (OutFile) { - CfgError ("Output file name already given"); + InfoError ("Output file name already given"); } - OutFile = xstrdup (CfgSVal); - CfgNextTok (); + OutFile = xstrdup (InfoSVal); + InfoNextTok (); break; - case CFGTOK_PAGELENGTH: - CfgNextTok (); - CfgAssureInt (); - if (CfgIVal != -1) { - CfgRangeCheck (MIN_PAGE_LEN, MAX_PAGE_LEN); + case INFOTOK_PAGELENGTH: + InfoNextTok (); + InfoAssureInt (); + if (InfoIVal != -1) { + InfoRangeCheck (MIN_PAGE_LEN, MAX_PAGE_LEN); } - PageLength = CfgIVal; - CfgNextTok (); + PageLength = InfoIVal; + InfoNextTok (); break; - case CFGTOK_STARTADDR: - CfgNextTok (); - CfgAssureInt (); - CfgRangeCheck (0x0000, 0xFFFF); - StartAddr = CfgIVal; - CfgNextTok (); + case INFOTOK_STARTADDR: + InfoNextTok (); + InfoAssureInt (); + InfoRangeCheck (0x0000, 0xFFFF); + StartAddr = InfoIVal; + InfoNextTok (); break; } /* Directive is followed by a semicolon */ - CfgConsumeSemi (); + InfoConsumeSemi (); } /* Consume the closing brace */ - CfgConsumeRCurly (); + InfoConsumeRCurly (); } @@ -141,19 +141,19 @@ static void RangeSection (void) /* Parse a range section */ { static const IdentTok RangeDefs[] = { - { "START", CFGTOK_START }, - { "END", CFGTOK_END }, - { "TYPE", CFGTOK_TYPE }, + { "START", INFOTOK_START }, + { "END", INFOTOK_END }, + { "TYPE", INFOTOK_TYPE }, }; static const IdentTok TypeDefs[] = { - { "CODE", CFGTOK_CODE }, - { "BYTETABLE", CFGTOK_BYTETAB }, - { "WORDTABLE", CFGTOK_WORDTAB }, - { "DWORDTABLE", CFGTOK_DWORDTAB }, - { "ADDRTABLE", CFGTOK_ADDRTAB }, - { "RTSTABLE", CFGTOK_RTSTAB }, - { "TEXTTABLE", CFGTOK_TEXTTAB }, + { "CODE", INFOTOK_CODE }, + { "BYTETABLE", INFOTOK_BYTETAB }, + { "WORDTABLE", INFOTOK_WORDTAB }, + { "DWORDTABLE", INFOTOK_DWORDTAB }, + { "ADDRTABLE", INFOTOK_ADDRTAB }, + { "RTSTABLE", INFOTOK_RTSTAB }, + { "TEXTTABLE", INFOTOK_TEXTTAB }, }; @@ -172,75 +172,75 @@ static void RangeSection (void) unsigned char Type = 0; /* Skip the token */ - CfgNextTok (); + InfoNextTok (); /* Expect the opening curly brace */ - CfgConsumeLCurly (); + InfoConsumeLCurly (); /* Look for section tokens */ - while (CfgTok != CFGTOK_RCURLY) { + while (InfoTok != INFOTOK_RCURLY) { /* Convert to special token */ - CfgSpecialToken (RangeDefs, ENTRY_COUNT (RangeDefs), "Range directive"); + InfoSpecialToken (RangeDefs, ENTRY_COUNT (RangeDefs), "Range directive"); /* Look at the token */ - switch (CfgTok) { + switch (InfoTok) { - case CFGTOK_START: - CfgNextTok (); - CfgAssureInt (); - CfgRangeCheck (0x0000, 0xFFFF); - Start = CfgIVal; + case INFOTOK_START: + InfoNextTok (); + InfoAssureInt (); + InfoRangeCheck (0x0000, 0xFFFF); + Start = InfoIVal; Needed |= tStart; - CfgNextTok (); + InfoNextTok (); break; - case CFGTOK_END: - CfgNextTok (); - CfgAssureInt (); - CfgRangeCheck (0x0000, 0xFFFF); - End = CfgIVal; + case INFOTOK_END: + InfoNextTok (); + InfoAssureInt (); + InfoRangeCheck (0x0000, 0xFFFF); + End = InfoIVal; Needed |= tEnd; - CfgNextTok (); + InfoNextTok (); 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; - case CFGTOK_DWORDTAB: Type = atDWordTab; break; - case CFGTOK_ADDRTAB: Type = atAddrTab; break; - case CFGTOK_RTSTAB: Type = atRtsTab; break; - case CFGTOK_TEXTTAB: Type = atTextTab; break; + case INFOTOK_TYPE: + InfoNextTok (); + InfoSpecialToken (TypeDefs, ENTRY_COUNT (TypeDefs), "Type"); + switch (InfoTok) { + case INFOTOK_CODE: Type = atCode; break; + case INFOTOK_BYTETAB: Type = atByteTab; break; + case INFOTOK_WORDTAB: Type = atWordTab; break; + case INFOTOK_DWORDTAB: Type = atDWordTab; break; + case INFOTOK_ADDRTAB: Type = atAddrTab; break; + case INFOTOK_RTSTAB: Type = atRtsTab; break; + case INFOTOK_TEXTTAB: Type = atTextTab; break; } Needed |= tType; - CfgNextTok (); + InfoNextTok (); break; } /* Directive is followed by a semicolon */ - CfgConsumeSemi (); + InfoConsumeSemi (); } /* Did we get all required values? */ if (Needed != tAll) { - CfgError ("Required values missing from this section"); + InfoError ("Required values missing from this section"); } /* Start must be less than end */ if (Start > End) { - CfgError ("Start value must not be greater than end value"); + InfoError ("Start value must not be greater than end value"); } /* Set the range */ MarkRange (Start, End, Type); /* Consume the closing brace */ - CfgConsumeRCurly (); + InfoConsumeRCurly (); } @@ -249,9 +249,9 @@ static void LabelSection (void) /* Parse a label section */ { static const IdentTok LabelDefs[] = { - { "NAME", CFGTOK_NAME }, - { "ADDR", CFGTOK_ADDR }, - { "SIZE", CFGTOK_SIZE }, + { "NAME", INFOTOK_NAME }, + { "ADDR", INFOTOK_ADDR }, + { "SIZE", INFOTOK_SIZE }, }; /* Locals - initialize to avoid gcc warnings */ @@ -260,77 +260,77 @@ static void LabelSection (void) long Size = -1; /* Skip the token */ - CfgNextTok (); + InfoNextTok (); /* Expect the opening curly brace */ - CfgConsumeLCurly (); + InfoConsumeLCurly (); /* Look for section tokens */ - while (CfgTok != CFGTOK_RCURLY) { + while (InfoTok != INFOTOK_RCURLY) { /* Convert to special token */ - CfgSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Label directive"); + InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Label directive"); /* Look at the token */ - switch (CfgTok) { + switch (InfoTok) { - case CFGTOK_NAME: - CfgNextTok (); + case INFOTOK_NAME: + InfoNextTok (); if (Name) { - CfgError ("Name already given"); + InfoError ("Name already given"); } - CfgAssureStr (); - if (CfgSVal[0] == '\0') { - CfgError ("Name may not be empty"); + InfoAssureStr (); + if (InfoSVal[0] == '\0') { + InfoError ("Name may not be empty"); } - Name = xstrdup (CfgSVal); - CfgNextTok (); + Name = xstrdup (InfoSVal); + InfoNextTok (); break; - case CFGTOK_ADDR: - CfgNextTok (); + case INFOTOK_ADDR: + InfoNextTok (); if (Value >= 0) { - CfgError ("Value already given"); + InfoError ("Value already given"); } - CfgAssureInt (); - CfgRangeCheck (0, 0xFFFF); - Value = CfgIVal; - CfgNextTok (); + InfoAssureInt (); + InfoRangeCheck (0, 0xFFFF); + Value = InfoIVal; + InfoNextTok (); break; - case CFGTOK_SIZE: - CfgNextTok (); + case INFOTOK_SIZE: + InfoNextTok (); if (Size >= 0) { - CfgError ("Size already given"); + InfoError ("Size already given"); } - CfgAssureInt (); - CfgRangeCheck (1, 0x10000); - Size = CfgIVal; - CfgNextTok (); + InfoAssureInt (); + InfoRangeCheck (1, 0x10000); + Size = InfoIVal; + InfoNextTok (); break; } /* Directive is followed by a semicolon */ - CfgConsumeSemi (); + InfoConsumeSemi (); } /* Did we get the necessary data */ if (Name == 0) { - CfgError ("Label name is missing"); + InfoError ("Label name is missing"); } if (Value < 0) { - CfgError ("Label value is missing"); + InfoError ("Label value is missing"); } if (Size < 0) { /* Use default */ Size = 1; } if (Value + Size > 0x10000) { - CfgError ("Invalid size (address out of range)"); + InfoError ("Invalid size (address out of range)"); } if (HaveLabel ((unsigned) Value)) { - CfgError ("Label for address $%04lX already defined", Value); + InfoError ("Label for address $%04lX already defined", Value); } /* Define the label */ @@ -363,66 +363,63 @@ static void LabelSection (void) xfree (Name); /* Consume the closing brace */ - CfgConsumeRCurly (); + InfoConsumeRCurly (); } -static void CfgParse (void) +static void InfoParse (void) /* Parse the config file */ { static const IdentTok Globals[] = { - { "GLOBAL", CFGTOK_GLOBAL }, - { "RANGE", CFGTOK_RANGE }, - { "LABEL", CFGTOK_LABEL }, + { "GLOBAL", INFOTOK_GLOBAL }, + { "RANGE", INFOTOK_RANGE }, + { "LABEL", INFOTOK_LABEL }, }; - while (CfgTok != CFGTOK_EOF) { + while (InfoTok != INFOTOK_EOF) { /* Convert an identifier into a token */ - CfgSpecialToken (Globals, ENTRY_COUNT (Globals), "Config directive"); + InfoSpecialToken (Globals, ENTRY_COUNT (Globals), "Config directive"); /* Check the token */ - switch (CfgTok) { + switch (InfoTok) { - case CFGTOK_GLOBAL: + case INFOTOK_GLOBAL: GlobalSection (); break; - case CFGTOK_RANGE: + case INFOTOK_RANGE: RangeSection (); break; - case CFGTOK_LABEL: + case INFOTOK_LABEL: LabelSection (); break; } /* Semicolon expected */ - CfgConsumeSemi (); + InfoConsumeSemi (); } } -void CfgRead (void) -/* Read the configuration if a configuration file exists */ +void ReadInfoFile (void) +/* Read the info file */ { - /* 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 (); + /* Check if we have a info file given */ + if (InfoAvail()) { + /* Open the config file */ + InfoOpenInput (); - /* Parse the config file */ - CfgParse (); + /* Parse the config file */ + InfoParse (); - /* Close the file */ - CfgCloseInput (); + /* Close the file */ + InfoCloseInput (); + } } diff --git a/src/da65/config.h b/src/da65/infofile.h similarity index 81% rename from src/da65/config.h rename to src/da65/infofile.h index 382279241..a39a02d43 100644 --- a/src/da65/config.h +++ b/src/da65/infofile.h @@ -1,15 +1,15 @@ /*****************************************************************************/ /* */ -/* config.h */ +/* infofile.h */ /* */ -/* Disassembler configuration file handling */ +/* Disassembler info file handling */ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -33,8 +33,8 @@ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef INFOFILE_H +#define INFOFILE_H @@ -44,12 +44,12 @@ -void CfgRead (void); -/* Read the configuration if a configuration file exists */ +void ReadInfoFile (void); +/* Read the info file */ -/* End of config.h */ +/* End of infofile.h */ #endif diff --git a/src/da65/main.c b/src/da65/main.c index 0a9e0bcd9..ea8dea627 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -50,10 +50,10 @@ /* da65 */ #include "attrtab.h" #include "code.h" -#include "config.h" #include "data.h" #include "error.h" #include "global.h" +#include "infofile.h" #include "opctable.h" #include "output.h" #include "scanner.h" @@ -74,6 +74,7 @@ static void Usage (void) "Short options:\n" " -g\t\t\tAdd debug info to object file\n" " -h\t\t\tHelp (this text)\n" + " -i name\t\tSpecify an info file\n" " -o name\t\tName the output file\n" " -v\t\t\tIncrease verbosity\n" " -F\t\t\tAdd formfeeds to the output\n" @@ -85,6 +86,7 @@ static void Usage (void) " --debug-info\t\tAdd debug info to object file\n" " --formfeeds\t\tAdd formfeeds to the output\n" " --help\t\tHelp (this text)\n" + " --info name\t\tSpecify an info file\n" " --pagelength n\tSet the page length for the listing\n" " --start-addr addr\tSet the start/load address\n" " --verbose\t\tIncrease verbosity\n" @@ -159,6 +161,14 @@ static void OptHelp (const char* Opt attribute ((unused)), +static void OptInfo (const char* Opt attribute ((unused)), const char* Arg) +/* Handle the --info option */ +{ + InfoSetName (Arg); +} + + + static void OptPageLength (const char* Opt attribute ((unused)), const char* Arg) /* Handle the --pagelength option */ { @@ -222,7 +232,7 @@ static void OneOpcode (unsigned RemainingBytes) if (GetStyleAttr (PC) == atDefault) { if (D->Size > RemainingBytes) { MarkAddr (PC, atIllegal); - } else if (D->Flags & flIllegal) { + } else if (D->Flags & flIllegal) { MarkAddr (PC, atIllegal); } else { unsigned I; @@ -320,6 +330,7 @@ int main (int argc, char* argv []) { "--debug-info", 0, OptDebugInfo }, { "--formfeeds", 0, OptFormFeeds }, { "--help", 0, OptHelp }, + { "--info", 1, OptInfo }, { "--pagelength", 1, OptPageLength }, { "--start-addr", 1, OptStartAddr }, { "--verbose", 0, OptVerbose }, @@ -354,6 +365,10 @@ int main (int argc, char* argv []) OptHelp (Arg, 0); break; + case 'i': + OptInfo (Arg, GetArg (&I, 2)); + break; + case 'o': OutFile = GetArg (&I, 2); break; @@ -395,13 +410,8 @@ int main (int argc, char* argv []) AbEnd ("No input file"); } - /* Make the config file name from the input file if none was given */ - if (!CfgAvail ()) { - CfgSetName (MakeFilename (InFile, CfgExt)); - } - /* Try to read the configuration file */ - CfgRead (); + ReadInfoFile (); /* Make the output file name from the input file name if none was given */ if (OutFile == 0) { diff --git a/src/da65/make/gcc.mak b/src/da65/make/gcc.mak index 9f98eee83..d2d38a8a1 100644 --- a/src/da65/make/gcc.mak +++ b/src/da65/make/gcc.mak @@ -12,11 +12,11 @@ LDFLAGS= OBJS = attrtab.o \ code.o \ - config.o \ data.o \ error.o \ global.o \ handler.o \ + infofile.o \ main.o \ opc6502.o \ opc65816.o \ diff --git a/src/da65/make/watcom.mak b/src/da65/make/watcom.mak index cab12ff51..3468706c6 100644 --- a/src/da65/make/watcom.mak +++ b/src/da65/make/watcom.mak @@ -45,14 +45,18 @@ CFLAGS += -i=..\common OBJS = attrtab.obj \ code.obj \ - config.obj \ cpu.obj \ data.obj \ error.obj \ global.obj \ handler.obj \ + infofile.obj \ main.obj \ - opctable.obj \ + opc6502.obj \ + opc65816.obj \ + opc65c02.obj \ + opc65sc02.obj \ + opctable.obj \ output.obj \ scanner.obj diff --git a/src/da65/scanner.c b/src/da65/scanner.c index eca7ef692..6d1315faf 100644 --- a/src/da65/scanner.c +++ b/src/da65/scanner.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -37,7 +37,6 @@ #include #include #include -#include /* common */ #include "chartype.h" @@ -57,17 +56,16 @@ /* Current token and attributes */ -unsigned CfgTok; -char CfgSVal [CFG_MAX_IDENT_LEN+1]; -long CfgIVal; +unsigned InfoTok; +char InfoSVal [CFG_MAX_IDENT_LEN+1]; +long InfoIVal; /* Error location */ -unsigned CfgErrorLine; -unsigned CfgErrorCol; +unsigned InfoErrorLine; +unsigned InfoErrorCol; /* Input sources for the configuration */ -static const char* CfgFile = 0; -static const char* CfgBuf = 0; +static const char* InfoFile = 0; /* Other input stuff */ static int C = ' '; @@ -83,7 +81,7 @@ static FILE* InputFile = 0; -void CfgWarning (const char* Format, ...) +void InfoWarning (const char* Format, ...) /* Print a warning message adding file name and line number of the config file */ { char Buf [512]; @@ -93,12 +91,12 @@ void CfgWarning (const char* Format, ...) xvsprintf (Buf, sizeof (Buf), Format, ap); va_end (ap); - Warning ("%s(%u): %s", CfgFile, CfgErrorLine, Buf); + Warning ("%s(%u): %s", InfoFile, InfoErrorLine, Buf); } -void CfgError (const char* Format, ...) +void InfoError (const char* Format, ...) /* Print an error message adding file name and line number of the config file */ { char Buf [512]; @@ -108,7 +106,7 @@ void CfgError (const char* Format, ...) xvsprintf (Buf, sizeof (Buf), Format, ap); va_end (ap); - Error ("%s(%u): %s", CfgFile, CfgErrorLine, Buf); + Error ("%s(%u): %s", InfoFile, InfoErrorLine, Buf); } @@ -122,18 +120,8 @@ void CfgError (const char* Format, ...) static void NextChar (void) /* Read the next character from the input file */ { - if (CfgBuf) { - /* Read from buffer */ - C = (unsigned char)(*CfgBuf); - if (C == 0) { - C = EOF; - } else { - ++CfgBuf; - } - } else { - /* Read from the file */ - C = getc (InputFile); - } + /* Read from the file */ + C = getc (InputFile); /* Count columns */ if (C != EOF) { @@ -152,7 +140,7 @@ static void NextChar (void) static unsigned DigitVal (int C) /* Return the value for a numeric digit */ { - if (isdigit (C)) { + if (IsDigit (C)) { return C - '0'; } else { return toupper (C) - 'A' + 10; @@ -161,7 +149,7 @@ static unsigned DigitVal (int C) -void CfgNextTok (void) +void InfoNextTok (void) /* Read the next token from the input stream */ { unsigned I; @@ -169,13 +157,13 @@ void CfgNextTok (void) Again: /* Skip whitespace */ - while (isspace (C)) { + while (IsSpace (C)) { NextChar (); } /* Remember the current position */ - CfgErrorLine = InputLine; - CfgErrorCol = InputCol; + InfoErrorLine = InputLine; + InfoErrorCol = InputCol; /* Identifier? */ if (C == '_' || IsAlpha (C)) { @@ -184,38 +172,38 @@ Again: I = 0; while (C == '_' || IsAlNum (C)) { if (I < CFG_MAX_IDENT_LEN) { - CfgSVal [I++] = C; + InfoSVal [I++] = C; } NextChar (); } - CfgSVal [I] = '\0'; - CfgTok = CFGTOK_IDENT; + InfoSVal [I] = '\0'; + InfoTok = INFOTOK_IDENT; return; } /* Hex number? */ if (C == '$') { NextChar (); - if (!isxdigit (C)) { - CfgError ("Hex digit expected"); + if (!IsXDigit (C)) { + InfoError ("Hex digit expected"); } - CfgIVal = 0; - while (isxdigit (C)) { - CfgIVal = CfgIVal * 16 + DigitVal (C); + InfoIVal = 0; + while (IsXDigit (C)) { + InfoIVal = InfoIVal * 16 + DigitVal (C); NextChar (); } - CfgTok = CFGTOK_INTCON; + InfoTok = INFOTOK_INTCON; return; } /* Decimal number? */ - if (isdigit (C)) { - CfgIVal = 0; - while (isdigit (C)) { - CfgIVal = CfgIVal * 10 + DigitVal (C); + if (IsDigit (C)) { + InfoIVal = 0; + while (IsDigit (C)) { + InfoIVal = InfoIVal * 10 + DigitVal (C); NextChar (); } - CfgTok = CFGTOK_INTCON; + InfoTok = INFOTOK_INTCON; return; } @@ -224,37 +212,37 @@ Again: case '{': NextChar (); - CfgTok = CFGTOK_LCURLY; + InfoTok = INFOTOK_LCURLY; break; case '}': NextChar (); - CfgTok = CFGTOK_RCURLY; + InfoTok = INFOTOK_RCURLY; break; case ';': NextChar (); - CfgTok = CFGTOK_SEMI; + InfoTok = INFOTOK_SEMI; break; case '.': NextChar (); - CfgTok = CFGTOK_DOT; + InfoTok = INFOTOK_DOT; break; case ',': NextChar (); - CfgTok = CFGTOK_COMMA; + InfoTok = INFOTOK_COMMA; break; case '=': NextChar (); - CfgTok = CFGTOK_EQ; + InfoTok = INFOTOK_EQ; break; case ':': NextChar (); - CfgTok = CFGTOK_COLON; + InfoTok = INFOTOK_COLON; break; case '\"': @@ -262,16 +250,16 @@ Again: I = 0; while (C != '\"') { if (C == EOF || C == '\n') { - CfgError ("Unterminated string"); + InfoError ("Unterminated string"); } if (I < CFG_MAX_IDENT_LEN) { - CfgSVal [I++] = C; + InfoSVal [I++] = C; } NextChar (); } NextChar (); - CfgSVal [I] = '\0'; - CfgTok = CFGTOK_STRCON; + InfoSVal [I] = '\0'; + InfoTok = INFOTOK_STRCON; break; case '#': @@ -282,143 +270,143 @@ Again: if (C != EOF) { goto Again; } - CfgTok = CFGTOK_EOF; + InfoTok = INFOTOK_EOF; break; case EOF: - CfgTok = CFGTOK_EOF; + InfoTok = INFOTOK_EOF; break; default: - CfgError ("Invalid character `%c'", C); + InfoError ("Invalid character `%c'", C); } } -void CfgConsume (unsigned T, const char* Msg) +void InfoConsume (unsigned T, const char* Msg) /* Skip a token, print an error message if not found */ { - if (CfgTok != T) { - CfgError (Msg); + if (InfoTok != T) { + InfoError (Msg); } - CfgNextTok (); + InfoNextTok (); } -void CfgConsumeLCurly (void) +void InfoConsumeLCurly (void) /* Consume a left curly brace */ { - CfgConsume (CFGTOK_LCURLY, "`{' expected"); + InfoConsume (INFOTOK_LCURLY, "`{' expected"); } -void CfgConsumeRCurly (void) +void InfoConsumeRCurly (void) /* Consume a right curly brace */ { - CfgConsume (CFGTOK_RCURLY, "`}' expected"); + InfoConsume (INFOTOK_RCURLY, "`}' expected"); } -void CfgConsumeSemi (void) +void InfoConsumeSemi (void) /* Consume a semicolon */ { - CfgConsume (CFGTOK_SEMI, "`;' expected"); + InfoConsume (INFOTOK_SEMI, "`;' expected"); } -void CfgConsumeColon (void) +void InfoConsumeColon (void) /* Consume a colon */ { - CfgConsume (CFGTOK_COLON, "`:' expected"); + InfoConsume (INFOTOK_COLON, "`:' expected"); } -void CfgOptionalComma (void) +void InfoOptionalComma (void) /* Consume a comma if there is one */ { - if (CfgTok == CFGTOK_COMMA) { - CfgNextTok (); + if (InfoTok == INFOTOK_COMMA) { + InfoNextTok (); } } -void CfgOptionalAssign (void) +void InfoOptionalAssign (void) /* Consume an equal sign if there is one */ { - if (CfgTok == CFGTOK_EQ) { - CfgNextTok (); + if (InfoTok == INFOTOK_EQ) { + InfoNextTok (); } } -void CfgAssureInt (void) +void InfoAssureInt (void) /* Make sure the next token is an integer */ { - if (CfgTok != CFGTOK_INTCON) { - CfgError ("Integer constant expected"); + if (InfoTok != INFOTOK_INTCON) { + InfoError ("Integer constant expected"); } } -void CfgAssureStr (void) +void InfoAssureStr (void) /* Make sure the next token is a string constant */ { - if (CfgTok != CFGTOK_STRCON) { - CfgError ("String constant expected"); + if (InfoTok != INFOTOK_STRCON) { + InfoError ("String constant expected"); } } -void CfgAssureIdent (void) +void InfoAssureIdent (void) /* Make sure the next token is an identifier */ { - if (CfgTok != CFGTOK_IDENT) { - CfgError ("Identifier expected"); + if (InfoTok != INFOTOK_IDENT) { + InfoError ("Identifier expected"); } } -void CfgRangeCheck (long Lo, long Hi) -/* Check the range of CfgIVal */ +void InfoRangeCheck (long Lo, long Hi) +/* Check the range of InfoIVal */ { - if (CfgIVal < Lo || CfgIVal > Hi) { - CfgError ("Range error"); + if (InfoIVal < Lo || InfoIVal > Hi) { + InfoError ("Range error"); } } -void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name) +void InfoSpecialToken (const IdentTok* Table, unsigned Size, const char* Name) /* Map an identifier to one of the special tokens in the table */ { unsigned I; /* We need an identifier */ - if (CfgTok == CFGTOK_IDENT) { + if (InfoTok == INFOTOK_IDENT) { /* Make it upper case */ I = 0; - while (CfgSVal [I]) { - CfgSVal [I] = toupper (CfgSVal [I]); + while (InfoSVal [I]) { + InfoSVal [I] = toupper (InfoSVal [I]); ++I; } /* Linear search */ for (I = 0; I < Size; ++I) { - if (strcmp (CfgSVal, Table [I].Ident) == 0) { - CfgTok = Table [I].Tok; + if (strcmp (InfoSVal, Table [I].Ident) == 0) { + InfoTok = Table [I].Tok; return; } } @@ -426,81 +414,66 @@ void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name) } /* Not found or no identifier */ - CfgError ("%s expected", Name); + InfoError ("%s expected", Name); } -void CfgBoolToken (void) +void InfoBoolToken (void) /* Map an identifier or integer to a boolean token */ { static const IdentTok Booleans [] = { - { "YES", CFGTOK_TRUE }, - { "NO", CFGTOK_FALSE }, - { "TRUE", CFGTOK_TRUE }, - { "FALSE", CFGTOK_FALSE }, + { "YES", INFOTOK_TRUE }, + { "NO", INFOTOK_FALSE }, + { "TRUE", INFOTOK_TRUE }, + { "FALSE", INFOTOK_FALSE }, }; /* If we have an identifier, map it to a boolean token */ - if (CfgTok == CFGTOK_IDENT) { - CfgSpecialToken (Booleans, ENTRY_COUNT (Booleans), "Boolean"); + if (InfoTok == INFOTOK_IDENT) { + InfoSpecialToken (Booleans, ENTRY_COUNT (Booleans), "Boolean"); } else { /* We expected an integer here */ - if (CfgTok != CFGTOK_INTCON) { - CfgError ("Boolean value expected"); + if (InfoTok != INFOTOK_INTCON) { + InfoError ("Boolean value expected"); } - CfgTok = (CfgIVal == 0)? CFGTOK_FALSE : CFGTOK_TRUE; + InfoTok = (InfoIVal == 0)? INFOTOK_FALSE : INFOTOK_TRUE; } } -void CfgSetName (const char* Name) +void InfoSetName (const char* Name) /* Set a name for a config file */ { - CfgFile = Name; + InfoFile = Name; } -const char* CfgGetName (void) +const char* InfoGetName (void) /* Get the name of the config file */ { - return CfgFile? CfgFile : ""; -} - - - -void CfgSetBuf (const char* Buf) -/* Set a memory buffer for the config */ -{ - CfgBuf = Buf; + return InfoFile? InfoFile : ""; } -int CfgAvail (void) -/* Return true if we have a configuration available */ +int InfoAvail () +/* Return true if we have an info file given */ { - return CfgFile != 0 || CfgBuf != 0; + return (InfoFile != 0); } -void CfgOpenInput (void) -/* Open the input file if we have one */ +void InfoOpenInput (void) +/* Open the input file */ { - /* If we have a config name given, open the file, otherwise we will read - * from a buffer. - */ - if (!CfgBuf) { - - /* Open the file */ - InputFile = fopen (CfgFile, "r"); - if (InputFile == 0) { - Error ("Cannot open `%s': %s", CfgFile, strerror (errno)); - } - + /* Open the file */ + InputFile = fopen (InfoFile, "r"); + if (InputFile == 0) { + Error ("Cannot open `%s': %s", InfoFile, strerror (errno)); } /* Initialize variables */ @@ -509,12 +482,12 @@ void CfgOpenInput (void) InputCol = 0; /* Start the ball rolling ... */ - CfgNextTok (); + InfoNextTok (); } -void CfgCloseInput (void) +void InfoCloseInput (void) /* Close the input file if we have one */ { /* Close the input file if we had one */ diff --git a/src/da65/scanner.h b/src/da65/scanner.h index ec14e0973..529b0aa13 100644 --- a/src/da65/scanner.h +++ b/src/da65/scanner.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -44,59 +44,59 @@ -/* Config file tokens */ +/* Info file tokens */ typedef enum token_t { - CFGTOK_NONE, - CFGTOK_INTCON, - CFGTOK_STRCON, - CFGTOK_IDENT, - CFGTOK_LCURLY, - CFGTOK_RCURLY, - CFGTOK_SEMI, - CFGTOK_COMMA, - CFGTOK_EQ, - CFGTOK_COLON, - CFGTOK_DOT, - CFGTOK_EOF, + INFOTOK_NONE, + INFOTOK_INTCON, + INFOTOK_STRCON, + INFOTOK_IDENT, + INFOTOK_LCURLY, + INFOTOK_RCURLY, + INFOTOK_SEMI, + INFOTOK_COMMA, + INFOTOK_EQ, + INFOTOK_COLON, + INFOTOK_DOT, + INFOTOK_EOF, /* Special tokens */ - CFGTOK_GLOBAL, - CFGTOK_RANGE, - CFGTOK_LABEL, + INFOTOK_GLOBAL, + INFOTOK_RANGE, + INFOTOK_LABEL, /* Global section */ - CFGTOK_INPUTNAME, - CFGTOK_OUTPUTNAME, - CFGTOK_PAGELENGTH, - CFGTOK_STARTADDR, + INFOTOK_INPUTNAME, + INFOTOK_OUTPUTNAME, + INFOTOK_PAGELENGTH, + INFOTOK_STARTADDR, /* Range section */ - CFGTOK_START, - CFGTOK_END, - CFGTOK_TYPE, - - CFGTOK_CODE, - CFGTOK_BYTETAB, - CFGTOK_WORDTAB, - CFGTOK_DWORDTAB, - CFGTOK_ADDRTAB, - CFGTOK_RTSTAB, - CFGTOK_TEXTTAB, + INFOTOK_START, + INFOTOK_END, + INFOTOK_TYPE, + + INFOTOK_CODE, + INFOTOK_BYTETAB, + INFOTOK_WORDTAB, + INFOTOK_DWORDTAB, + INFOTOK_ADDRTAB, + INFOTOK_RTSTAB, + INFOTOK_TEXTTAB, /* Label section */ - CFGTOK_NAME, - CFGTOK_ADDR, - CFGTOK_SIZE, + INFOTOK_NAME, + INFOTOK_ADDR, + INFOTOK_SIZE, /* */ - CFGTOK_TRUE, - CFGTOK_FALSE + INFOTOK_TRUE, + INFOTOK_FALSE } token_t; /* Mapping table entry, special identifier --> token */ -typedef struct IdentTok_ IdentTok; -struct IdentTok_ { +typedef struct IdentTok IdentTok; +struct IdentTok { const char* Ident; /* Identifier */ token_t Tok; /* Token for identifier */ }; @@ -106,13 +106,13 @@ struct IdentTok_ { /* Current token and attributes */ #define CFG_MAX_IDENT_LEN 255 -extern unsigned CfgTok; -extern char CfgSVal [CFG_MAX_IDENT_LEN+1]; -extern long CfgIVal; +extern unsigned InfoTok; +extern char InfoSVal [CFG_MAX_IDENT_LEN+1]; +extern long InfoIVal; /* Error location */ -extern unsigned CfgErrorLine; -extern unsigned CfgErrorCol; +extern unsigned InfoErrorLine; +extern unsigned InfoErrorCol; @@ -122,70 +122,67 @@ extern unsigned CfgErrorCol; -void CfgWarning (const char* Format, ...); +void InfoWarning (const char* Format, ...); /* Print a warning message adding file name and line number of the config file */ -void CfgError (const char* Format, ...); +void InfoError (const char* Format, ...); /* Print an error message adding file name and line number of the config file */ -void CfgNextTok (void); +void InfoNextTok (void); /* Read the next token from the input stream */ -void CfgConsume (unsigned T, const char* Msg); +void InfoConsume (unsigned T, const char* Msg); /* Skip a token, print an error message if not found */ -void CfgConsumeLCurly (void); +void InfoConsumeLCurly (void); /* Consume a left curly brace */ -void CfgConsumeRCurly (void); +void InfoConsumeRCurly (void); /* Consume a right curly brace */ -void CfgConsumeSemi (void); +void InfoConsumeSemi (void); /* Consume a semicolon */ -void CfgConsumeColon (void); +void InfoConsumeColon (void); /* Consume a colon */ -void CfgOptionalComma (void); +void InfoOptionalComma (void); /* Consume a comma if there is one */ -void CfgOptionalAssign (void); +void InfoOptionalAssign (void); /* Consume an equal sign if there is one */ -void CfgAssureInt (void); +void InfoAssureInt (void); /* Make sure the next token is an integer */ -void CfgAssureStr (void); +void InfoAssureStr (void); /* Make sure the next token is a string constant */ -void CfgAssureIdent (void); +void InfoAssureIdent (void); /* Make sure the next token is an identifier */ -void CfgRangeCheck (long Lo, long Hi); -/* Check the range of CfgIVal */ +void InfoRangeCheck (long Lo, long Hi); +/* Check the range of InfoIVal */ -void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name); +void InfoSpecialToken (const IdentTok* Table, unsigned Size, const char* Name); /* Map an identifier to one of the special tokens in the table */ -void CfgBoolToken (void); +void InfoBoolToken (void); /* Map an identifier or integer to a boolean token */ -void CfgSetName (const char* Name); +void InfoSetName (const char* Name); /* Set a name for a config file */ -const char* CfgGetName (void); +const char* InfoGetName (void); /* Get the name of the config file */ -void CfgSetBuf (const char* Buf); -/* Set a memory buffer for the config */ +int InfoAvail (); +/* Return true if we have an info file given */ -int CfgAvail (void); -/* Return true if we have a configuration available */ - -void CfgOpenInput (void); +void InfoOpenInput (void); /* Open the input file if we have one */ -void CfgCloseInput (void); +void InfoCloseInput (void); /* Close the input file if we have one */ -- 2.39.5