From: cuz Date: Wed, 24 Aug 2005 20:05:08 +0000 (+0000) Subject: Added a new option --macpack-dir that allows to load the macro packages X-Git-Tag: V2.12.0~257 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1f6276d21e1cd6ddb8855ee537ca1529c8cd1f70;p=cc65 Added a new option --macpack-dir that allows to load the macro packages from files instead of using the builtin ones. git-svn-id: svn://svn.cc65.org/cc65/trunk@3587 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/global.c b/src/ca65/global.c index e0196226a..2449ce44e 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -78,7 +78,7 @@ unsigned char MissingCharTerm = 0; /* Allow lda #'a (no closing term) */ unsigned char UbiquitousIdents = 0; /* Allow ubiquitous identifiers */ /* Misc stuff */ -const char Copyright[] = "(C) Copyright 1998-2004 Ullrich von Bassewitz"; +const char Copyright[] = "(C) Copyright 1998-2005 Ullrich von Bassewitz"; diff --git a/src/ca65/macpack.c b/src/ca65/macpack.c index f9c77c612..6cf5c09d3 100644 --- a/src/ca65/macpack.c +++ b/src/ca65/macpack.c @@ -35,6 +35,8 @@ /* common */ #include "check.h" +#include "strbuf.h" +#include "strutil.h" /* ca65 */ #include "error.h" @@ -56,13 +58,20 @@ #include "longbranch.inc" /* Table with pointers to the different packages */ -static char* MacPackages [] = { - MacGeneric, - MacLongBranch, - MacCBM, - MacCPU +static struct { + const char* Name; + char* Package; +} MacPackages[MAC_COUNT] = { + /* Packages sorted by id */ + { "cbm", MacCBM }, + { "cpu", MacCPU }, + { "generic", MacGeneric }, + { "longbranch", MacLongBranch }, }; +/* Directory that contains standard macro package files */ +static StrBuf MacPackDir = STATIC_STRBUF_INITIALIZER; + /*****************************************************************************/ @@ -71,14 +80,80 @@ static char* MacPackages [] = { -void InsertMacPack (unsigned Id) +int MacPackFind (const char* Name) +/* Find a macro package by name. The function will either return the id or + * -1 if the package name was not found. + */ +{ + int I; + + for (I = 0; I < MAC_COUNT; ++I) { + if (StrCaseCmp (Name, MacPackages[I].Name) == 0) { + /* Found */ + return I; + } + } + + /* Not found */ + return -1; +} + + + +void MacPackInsert (int Id) /* Insert the macro package with the given id in the input stream */ { /* Check the parameter */ - CHECK (Id < sizeof (MacPackages) / sizeof (MacPackages [0])); + CHECK (Id >= 0 && Id < MAC_COUNT); + + /* If we have a macro package directory given, load a file from the + * directory, otherwise use the builtin stuff. + */ + if (SB_IsEmpty (&MacPackDir)) { + + /* Insert the builtin package */ + NewInputData (MacPackages[Id].Package, 0); - /* Insert the package */ - NewInputData (MacPackages[Id], 0); + } else { + + StrBuf Filename = AUTO_STRBUF_INITIALIZER; + + /* Build the complete file name */ + SB_Copy (&Filename, &MacPackDir); + SB_AppendStr (&Filename, MacPackages[Id].Name); + SB_AppendStr (&Filename, ".mac"); + SB_Terminate (&Filename); + + /* Open the macro package as include file */ + NewInputFile (SB_GetConstBuf (&Filename)); + + /* Destroy the contents of Filename */ + DoneStrBuf (&Filename); + + } +} + + + +void MacPackSetDir (const char* Dir) +/* Set a directory where files for macro packages can be found. Standard is + * to use the builtin packages. For debugging macro packages, external files + * can be used. + */ +{ + /* Copy the directory name to the buffer */ + SB_CopyStr (&MacPackDir, Dir); + + /* Make sure that the last character is a path delimiter */ + if (SB_NotEmpty (&MacPackDir)) { + char C = SB_LookAtLast (&MacPackDir); + if (C != '\\' && C != '/') { + SB_AppendChar (&MacPackDir, '/'); + } + } + + /* Terminate the buffer so it's usable as a C string */ + SB_Terminate (&MacPackDir); } diff --git a/src/ca65/macpack.h b/src/ca65/macpack.h index d46ee9dda..75ca43b5c 100644 --- a/src/ca65/macpack.h +++ b/src/ca65/macpack.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2005, Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -45,10 +45,15 @@ /* Constants for the predefined packages */ -#define MAC_GENERIC 0 -#define MAC_LONGBRANCH 1 -#define MAC_CBM 2 -#define MAC_CPU 3 +enum { + MAC_CBM, + MAC_CPU, + MAC_GENERIC, + MAC_LONGBRANCH, + + /* Number of known packages */ + MAC_COUNT +}; @@ -58,9 +63,20 @@ -void InsertMacPack (unsigned Id); +int MacPackFind (const char* Name); +/* Find a macro package by name. The function will either return the id or + * -1 if the package name was not found. + */ + +void MacPackInsert (int Id); /* Insert the macro package with the given id in the input stream */ +void MacPackSetDir (const char* Dir); +/* Set a directory where files for macro packages can be found. Standard is + * to use the builtin packages. For debugging macro packages, external files + * can be used. + */ + /* End of macpack.h */ diff --git a/src/ca65/main.c b/src/ca65/main.c index 42b2891b0..1ccef1fc4 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2004 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2005, Ullrich von Bassewitz */ +/* Römerstraße 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -61,6 +61,7 @@ #include "istack.h" #include "lineinfo.h" #include "listing.h" +#include "macpack.h" #include "macro.h" #include "nexttok.h" #include "objfile.h" @@ -111,6 +112,7 @@ static void Usage (void) " --include-dir dir\tSet an include directory search path\n" " --listing\t\tCreate a listing if assembly was ok\n" " --list-bytes n\tMaximum number of bytes per listing line\n" + " --macpack-dir dir\tSet a macro package directory\n" " --memory-model model\tSet the memory model\n" " --pagelength n\tSet the page length for the listing\n" " --smart\t\tEnable smart mode\n" @@ -420,6 +422,15 @@ static void OptListing (const char* Opt attribute ((unused)), +static void OptMacPackDir (const char* Opt attribute ((unused)), const char* Arg) +/* Set a macro package directory */ +{ + /* Use the directory */ + MacPackSetDir (Arg); +} + + + static void OptMemoryModel (const char* Opt, const char* Arg) /* Set the memory model */ { @@ -754,6 +765,7 @@ int main (int argc, char* argv []) { "--include-dir", 1, OptIncludeDir }, { "--list-bytes", 1, OptListBytes }, { "--listing", 0, OptListing }, + { "--macpack-dir", 1, OptMacPackDir }, { "--memory-model", 1, OptMemoryModel }, { "--pagelength", 1, OptPageLength }, { "--smart", 0, OptSmart }, diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 1eed86f94..cfd5592e9 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1206,14 +1206,6 @@ static void DoLocalChar (void) static void DoMacPack (void) /* Insert a macro package */ { - /* Macro package names */ - static const char* Keys [] = { - "GENERIC", - "LONGBRANCH", - "CBM", - "CPU" - }; - int Package; /* We expect an identifier */ @@ -1222,8 +1214,8 @@ static void DoMacPack (void) return; } - /* Map the keyword to a number */ - Package = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0])); + /* Search for the macro package name */ + Package = MacPackFind (SVal); if (Package < 0) { /* Not found */ ErrorSkip ("Invalid macro package"); @@ -1234,7 +1226,7 @@ static void DoMacPack (void) NextTok (); /* Insert the package */ - InsertMacPack (Package); + MacPackInsert (Package); }