1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 17:29:50 +00:00

Added an AddrSizeFromStr function.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4050 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2009-08-27 14:11:07 +00:00
parent 23dae5a04b
commit 6f39a15eff
2 changed files with 53 additions and 11 deletions

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2003 Ullrich von Bassewitz */ /* (C) 2003-2009, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -35,6 +35,7 @@
/* common */ /* common */
#include "addrsize.h" #include "addrsize.h"
#include "strutil.h"
@ -59,3 +60,38 @@ 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;
}

View File

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2003 Ullrich von Bassewitz */ /* (C) 2003-2009, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -44,6 +44,7 @@
#define ADDR_SIZE_INVALID 0xFF
#define ADDR_SIZE_DEFAULT 0x00 #define ADDR_SIZE_DEFAULT 0x00
#define ADDR_SIZE_ZP 0x01 #define ADDR_SIZE_ZP 0x01
#define ADDR_SIZE_ABS 0x02 #define ADDR_SIZE_ABS 0x02
@ -61,6 +62,11 @@
const char* AddrSizeToStr (unsigned char AddrSize); const char* AddrSizeToStr (unsigned char AddrSize);
/* Return the name for an address size specifier */ /* 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 */ /* End of addrsize.h */