#include <stdio.h>
#include <string.h>
-#include "../common/hashstr.h"
+/* common */
+#include "hashstr.h"
+#include "xmalloc.h"
+/* cc65 */
#include "error.h"
-#include "mem.h"
#include "macrotab.h"
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;
-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];
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);
/* 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 */
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;
+}
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;
}
}
/* 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);
}
+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. */
{