From 6583320b79cf3f1dda36f51b29163f18fd9144c0 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 21 Aug 2011 20:04:27 +0000 Subject: [PATCH] Added GT_AsString(). git-svn-id: svn://svn.cc65.org/cc65/trunk@5255 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/gentype.c | 24 ++++++++++++++++++++++++ src/common/gentype.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/common/gentype.c b/src/common/gentype.c index b6bb9a579..7bdddaf33 100644 --- a/src/common/gentype.c +++ b/src/common/gentype.c @@ -79,6 +79,30 @@ unsigned GT_GetArraySize (StrBuf* Type) +void GT_AsString (const StrBuf* Type, StrBuf* String) +/* Convert the type into a readable representation */ +{ + static const char HexTab[16] = "0123456789ABCDEF"; + unsigned I; + + /* Convert Type into readable hex. String will have twice then length + * plus a terminator. + */ + SB_Realloc (String, 2 * SB_GetLen (Type) + 1); + SB_Clear (String); + + for (I = 0; I < SB_GetLen (Type); ++I) { + unsigned char C = SB_AtUnchecked (Type, I); + SB_AppendChar (String, HexTab[(C & 0xF0) >> 4]); + SB_AppendChar (String, HexTab[(C & 0x0F) >> 0]); + } + + /* Terminate the string so it can be used with string functions */ + SB_Terminate (String); +} + + + diff --git a/src/common/gentype.h b/src/common/gentype.h index f383cc689..afadbbb12 100644 --- a/src/common/gentype.h +++ b/src/common/gentype.h @@ -136,6 +136,9 @@ unsigned GT_GetArraySize (StrBuf* Type); * The index position will get moved past the array size. */ +void GT_AsString (const StrBuf* Type, StrBuf* String); +/* Convert the type into a readable representation */ + /* End of gentype.h */ -- 2.39.5