]> git.sur5r.net Git - cc65/blobdiff - src/cc65/macrotab.c
Changed most "backticks" (grave accents) into apostrophes.
[cc65] / src / cc65 / macrotab.c
index 35639f832326431869e73eabc6ff5f29b9028379..09f0db50a1d8cb9593dc4ad5dd7876f39b654dd0 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                               macrotab.h                                 */
+/*                                macrotab.h                                 */
 /*                                                                           */
-/*            Preprocessor macro table for the cc65 C compiler              */
+/*             Preprocessor macro table for the cc65 C compiler              */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2008, Ullrich von Bassewitz                                      */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -37,7 +37,7 @@
 #include <string.h>
 
 /* common */
-#include "hashstr.h"
+#include "hashfunc.h"
 #include "xmalloc.h"
 
 /* cc65 */
 
 
 /*****************************************************************************/
-/*                                  data                                    */
+/*                                   data                                    */
 /*****************************************************************************/
 
 
 
 /* The macro hash table */
-#define MACRO_TAB_SIZE 211
+#define MACRO_TAB_SIZE  211
 static Macro* MacroTab[MACRO_TAB_SIZE];
 
 
 
 /*****************************************************************************/
-/*                                  code                                    */
+/*                                   code                                    */
 /*****************************************************************************/
 
 
 
 Macro* NewMacro (const char* Name)
 /* Allocate a macro structure with the given name. The structure is not
- * inserted into the macro table.
- */
+** inserted into the macro table.
+*/
 {
     /* Get the length of the macro name */
     unsigned Len = strlen(Name);
@@ -76,10 +76,10 @@ Macro* NewMacro (const char* Name)
     Macro* M = (Macro*) xmalloc (sizeof(Macro) + Len);
 
     /* Initialize the data */
-    M->Next       = 0;
+    M->Next        = 0;
     M->Expanding   = 0;
-    M->ArgCount    = -1;       /* Flag: Not a function like macro */
-    M->MaxArgs    = 0;
+    M->ArgCount    = -1;        /* Flag: Not a function like macro */
+    M->MaxArgs     = 0;
     InitCollection (&M->FormalArgs);
     SB_Init (&M->Replacement);
     M->Variadic    = 0;
@@ -93,13 +93,13 @@ Macro* NewMacro (const char* Name)
 
 void FreeMacro (Macro* M)
 /* Delete a macro definition. The function will NOT remove the macro from the
- * table, use UndefineMacro for that.
- */
+** table, use UndefineMacro for that.
+*/
 {
     unsigned I;
 
     for (I = 0; I < CollCount (&M->FormalArgs); ++I) {
-       xfree (CollAtUnchecked (&M->FormalArgs, I));
+        xfree (CollAtUnchecked (&M->FormalArgs, I));
     }
     DoneCollection (&M->FormalArgs);
     SB_Done (&M->Replacement);
@@ -152,9 +152,9 @@ void InsertMacro (Macro* M)
 
 int UndefineMacro (const char* Name)
 /* Search for the macro with the given name and remove it from the macro
- * table if it exists. Return 1 if a macro was found and deleted, return
- * 0 otherwise.
- */
+** table if it exists. Return 1 if a macro was found and deleted, return
+** 0 otherwise.
+*/
 {
     /* Get the hash value of the macro name */
     unsigned Hash = HashStr (Name) % MACRO_TAB_SIZE;
@@ -163,26 +163,26 @@ int UndefineMacro (const char* Name)
     Macro* L = 0;
     Macro* M = MacroTab[Hash];
     while (M) {
-       if (strcmp (M->Name, Name) == 0) {
-
-           /* Found it */
-           if (L == 0) {
-               /* First in chain */
-               MacroTab[Hash] = M->Next;
-           } else {
-               L->Next = M->Next;
-           }
-
-           /* Delete the macro */
-           FreeMacro (M);
-
-           /* Done */
-           return 1;
-       }
-
-       /* Next macro */
-       L = M;
-       M = M->Next;
+        if (strcmp (M->Name, Name) == 0) {
+
+            /* Found it */
+            if (L == 0) {
+                /* First in chain */
+                MacroTab[Hash] = M->Next;
+            } else {
+                L->Next = M->Next;
+            }
+
+            /* Delete the macro */
+            FreeMacro (M);
+
+            /* Done */
+            return 1;
+        }
+
+        /* Next macro */
+        L = M;
+        M = M->Next;
     }
 
     /* Not found */
@@ -200,13 +200,13 @@ Macro* FindMacro (const char* Name)
     /* Search the hash chain */
     Macro* M = MacroTab[Hash];
     while (M) {
-       if (strcmp (M->Name, Name) == 0) {
-           /* Found it */
-           return M;
-       }
+        if (strcmp (M->Name, Name) == 0) {
+            /* Found it */
+            return M;
+        }
 
-       /* Next macro */
-       M = M->Next;
+        /* Next macro */
+        M = M->Next;
     }
 
     /* Not found */
@@ -217,15 +217,15 @@ Macro* FindMacro (const char* Name)
 
 int FindMacroArg (Macro* M, const char* Arg)
 /* Search for a formal macro argument. If found, return the index of the
- * argument. If the argument was not found, return -1.
- */
+** argument. If the argument was not found, return -1.
+*/
 {
     unsigned I;
     for (I = 0; I < CollCount (&M->FormalArgs); ++I) {
-               if (strcmp (CollAtUnchecked (&M->FormalArgs, I), Arg) == 0) {
-           /* Found */
-                   return I;
-       }
+        if (strcmp (CollAtUnchecked (&M->FormalArgs, I), Arg) == 0) {
+            /* Found */
+            return I;
+        }
     }
 
     /* Not found */
@@ -238,16 +238,16 @@ void AddMacroArg (Macro* M, const char* Arg)
 /* Add a formal macro argument. */
 {
     /* Check if we have a duplicate macro argument, but add it anyway.
-     * Beware: Don't use FindMacroArg here, since the actual argument array
-     * may not be initialized.
-     */
+    ** Beware: Don't use FindMacroArg here, since the actual argument array
+    ** may not be initialized.
+    */
     unsigned I;
     for (I = 0; I < CollCount (&M->FormalArgs); ++I) {
-               if (strcmp (CollAtUnchecked (&M->FormalArgs, I), Arg) == 0) {
-           /* Found */
-           Error ("Duplicate macro parameter: `%s'", Arg);
-           break;
-       }
+        if (strcmp (CollAtUnchecked (&M->FormalArgs, I), Arg) == 0) {
+            /* Found */
+            Error ("Duplicate macro parameter: '%s'", Arg);
+            break;
+        }
     }
 
     /* Add the new argument */
@@ -264,15 +264,15 @@ int MacroCmp (const Macro* M1, const Macro* M2)
 
     /* Argument count must be identical */
     if (M1->ArgCount != M2->ArgCount) {
-       return 1;
+        return 1;
     }
 
     /* Compare the arguments */
     for (I = 0; I < M1->ArgCount; ++I) {
-               if (strcmp (CollConstAt (&M1->FormalArgs, I),
+        if (strcmp (CollConstAt (&M1->FormalArgs, I),
                     CollConstAt (&M2->FormalArgs, I)) != 0) {
-           return 1;
-       }
+            return 1;
+        }
     }
 
     /* Compare the replacement */
@@ -289,19 +289,16 @@ void PrintMacroStats (FILE* F)
 
     fprintf (F, "\n\nMacro Hash Table Summary\n");
     for (I = 0; I < MACRO_TAB_SIZE; ++I) {
-               fprintf (F, "%3u : ", I);
-       M = MacroTab [I];
-       if (M) {
-           while (M) {
-               fprintf (F, "%s ", M->Name);
-               M = M->Next;
-           }
-           fprintf (F, "\n");
-       } else {
-           fprintf (F, "empty\n");
-       }
+        fprintf (F, "%3u : ", I);
+        M = MacroTab [I];
+        if (M) {
+            while (M) {
+                fprintf (F, "%s ", M->Name);
+                M = M->Next;
+            }
+            fprintf (F, "\n");
+        } else {
+            fprintf (F, "empty\n");
+        }
     }
 }
-
-
-