]> git.sur5r.net Git - cc65/commitdiff
Added an AddrSizeFromStr function.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 27 Aug 2009 14:11:07 +0000 (14:11 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 27 Aug 2009 14:11:07 +0000 (14:11 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4050 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/common/addrsize.c
src/common/addrsize.h

index a316801263770aeb1c06cb48cd19e52f447f543a..82dc14d0073c73d6fd1cd56c58cb161c8c25702e 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -35,6 +35,7 @@
 
 /* common */
 #include "addrsize.h"
+#include "strutil.h"
 
 
 
@@ -58,4 +59,39 @@ const char* AddrSizeToStr (unsigned char AddrSize)
 }
 
 
-                                                    
+
+unsigned char AddrSizeFromStr (const char* Str)
+/* Return the address size for a given string. Returns ADDR_SIZE_INVALID if
+ * the string cannot be mapped to an address size.
+ */
+{
+    static const struct {
+        const char*     Name;
+        unsigned char   AddrSize;
+    } AddrSizeTable[] = {
+        { "abs",        ADDR_SIZE_ABS     },
+        { "absolute",   ADDR_SIZE_ABS     },
+        { "default",    ADDR_SIZE_DEFAULT },
+        { "direct",     ADDR_SIZE_ZP      },
+        { "dword",      ADDR_SIZE_LONG    },
+        { "far",        ADDR_SIZE_FAR     },
+        { "long",       ADDR_SIZE_LONG    },
+        { "near",       ADDR_SIZE_ABS     },
+        { "zeropage",   ADDR_SIZE_ZP      },
+        { "zp",         ADDR_SIZE_ZP      },
+    };
+    unsigned I;
+
+    for (I = 0; I < sizeof (AddrSizeTable) / sizeof (AddrSizeTable[0]); ++I) {
+        if (StrCaseCmp (Str, AddrSizeTable[I].Name) == 0) {
+            /* Found */
+            return AddrSizeTable[I].AddrSize;
+        }
+    }
+
+    /* Not found */
+    return ADDR_SIZE_INVALID;
+}
+
+
+
index 263481bbacbd6ca6879ef636faf17cd6ce4873a3..9d11ce44cda0e5e4fc4608a211b3ec4e86b413a3 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                          Data                                    */
 /*****************************************************************************/
 
 
 
+#define ADDR_SIZE_INVALID       0xFF
 #define ADDR_SIZE_DEFAULT       0x00
 #define ADDR_SIZE_ZP            0x01
 #define ADDR_SIZE_ABS           0x02
@@ -53,7 +54,7 @@
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                          Code                                    */
 /*****************************************************************************/
 
 
 const char* AddrSizeToStr (unsigned char AddrSize);
 /* Return the name for an address size specifier */
 
+unsigned char AddrSizeFromStr (const char* Str);
+/* Return the address size for a given string. Returns ADDR_SIZE_INVALID if
+ * the string cannot be mapped to an address size.
+ */
+
 
 
 /* End of addrsize.h */