X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fmacrotab.c;h=45a290fe7f6845a89d379ae121b75bba4be0acb2;hb=b8c4dc9b0661e19e46ba60372db3831cdcf5961f;hp=d0a0a3a6748e4492e49920524a15a2c0da4a12e4;hpb=774b4bb424a03c1fa972a8ebd275ce99ac484ad4;p=cc65 diff --git a/src/cc65/macrotab.c b/src/cc65/macrotab.c index d0a0a3a67..45a290fe7 100644 --- a/src/cc65/macrotab.c +++ b/src/cc65/macrotab.c @@ -36,10 +36,12 @@ #include #include -#include "../common/hashstr.h" +/* common */ +#include "hashstr.h" +#include "xmalloc.h" +/* cc65 */ #include "error.h" -#include "mem.h" #include "macrotab.h" @@ -77,7 +79,7 @@ Macro* NewMacro (const char* Name) unsigned Len = strlen(Name); /* Allocate the structure */ - Macro* M = xmalloc (sizeof(Macro) + Len); + Macro* M = (Macro*) xmalloc (sizeof(Macro) + Len); /* Initialize the data */ M->Next = 0; @@ -112,8 +114,8 @@ void FreeMacro (Macro* M) -void AddNumericMacro (const char* Name, long Val) -/* Add a macro for a numeric constant */ +void DefineNumericMacro (const char* Name, long Val) +/* Define a macro for a numeric constant */ { char Buf[64]; @@ -121,13 +123,13 @@ void AddNumericMacro (const char* Name, long Val) sprintf (Buf, "%ld", Val); /* Handle as text macro */ - AddTextMacro (Name, Buf); + DefineTextMacro (Name, Buf); } -void AddTextMacro (const char* Name, const char* Val) -/* Add a macro for a textual constant */ +void DefineTextMacro (const char* Name, const char* Val) +/* Define a macro for a textual constant */ { /* Create a new macro */ Macro* M = NewMacro (Name); @@ -150,7 +152,7 @@ void InsertMacro (Macro* M) /* Allocate the ActualArgs parameter array */ if (M->ArgCount > 0) { - M->ActualArgs = xmalloc (M->ArgCount * sizeof(char*)); + M->ActualArgs = (char const**) xmalloc (M->ArgCount * sizeof(char*)); } /* Get the hash value of the macro name */ @@ -237,8 +239,8 @@ Macro* FindMacro (const char* Name) int IsMacro (const char* Name) /* Return true if the given name is the name of a macro, return false otherwise */ { - return FindMacro(Name) != 0; -} + return MaybeMacro(Name[0]) && FindMacro(Name) != 0; +} @@ -281,7 +283,7 @@ void AddMacroArg (Macro* M, const char* Arg) for (I = 0; I < M->ArgCount; ++I) { if (strcmp (M->FormalArgs[I], Arg) == 0) { /* Found */ - Error (ERR_DUPLICATE_MACRO_ARG, Arg); + Error ("Duplicate macro parameter: `%s'", Arg); break; } } @@ -289,11 +291,11 @@ void AddMacroArg (Macro* M, const char* Arg) /* Check if we have enough room available, otherwise expand the array * that holds the formal argument list. */ - if (M->ArgCount >= M->MaxArgs) { + if (M->ArgCount >= (int) M->MaxArgs) { /* We must expand the array */ char** OldArgs = M->FormalArgs; M->MaxArgs += 10; - M->FormalArgs = xmalloc (M->MaxArgs * sizeof(char*)); + M->FormalArgs = (char**) xmalloc (M->MaxArgs * sizeof(char*)); memcpy (M->FormalArgs, OldArgs, M->ArgCount * sizeof (char*)); xfree (OldArgs); } @@ -304,6 +306,29 @@ void AddMacroArg (Macro* M, const char* Arg) +int MacroCmp (const Macro* M1, const Macro* M2) +/* Compare two macros and return zero if both are identical. */ +{ + int I; + + /* Argument count must be identical */ + if (M1->ArgCount != M2->ArgCount) { + return 1; + } + + /* Compare the arguments */ + for (I = 0; I < M1->ArgCount; ++I) { + if (strcmp (M1->FormalArgs[I], M2->FormalArgs[I]) != 0) { + return 1; + } + } + + /* Compare the replacement */ + return strcmp (M1->Replacement, M2->Replacement); +} + + + void PrintMacroStats (FILE* F) /* Print macro statistics to the given text file. */ {