]> git.sur5r.net Git - cc65/commitdiff
Add a gentype.c module that contains GT_FromStrBuf.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 20 Aug 2011 22:13:58 +0000 (22:13 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 20 Aug 2011 22:13:58 +0000 (22:13 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5238 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/common/gentype.c [new file with mode: 0644]
src/common/gentype.h
src/common/make/gcc.mak
src/common/make/watcom.mak

diff --git a/src/common/gentype.c b/src/common/gentype.c
new file mode 100644 (file)
index 0000000..fe682d1
--- /dev/null
@@ -0,0 +1,74 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 gentype.c                                 */
+/*                                                                           */
+/*                        Generic data type encoding                         */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2011,      Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "gentype.h"
+#include "strbuf.h"
+#include "xmalloc.h"
+
+
+
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+gt_string GT_FromStrBuf (const struct StrBuf* S)
+/* Create a dynamically allocated type string from a string buffer. */
+{
+    /* To avoid silly mistakes, check if the last character in S is a
+     * terminator. If not, don't rely on S being terminated.
+     */
+    unsigned Len = SB_GetLen (S);
+    if (Len > 0 && SB_LookAtLast (S) == '\0') {
+        /* String is terminated - allocate memory */
+        gt_string Type = xmalloc (Len);
+        /* Copy the data and return the result */
+        return memcpy (Type, SB_GetConstBuf (S), Len);
+    } else {
+        /* String not terminated - allocate memory */
+        gt_string Type = xmalloc (Len + 1);
+        /* Copy the data */
+        memcpy (Type, SB_GetConstBuf (S), Len);
+        /* Terminate the string */
+        Type[Len] = GT_END;
+        /* Return the copy */
+        return Type;
+    }
+}
+
+
+
index 4a01b409ead6bdf8aab3439c8922ea9b80a9124e..c229b5aa2ddf3bf62708727db8c0c2ded554c6ae 100644 (file)
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                 Forwards                                  */
 /*****************************************************************************/
 
 
 
+struct StrBuf;
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* The data type used to encode a generic type */
+typedef unsigned char* gt_string;
+
+
+
 /* Termination, so we can use string functions to handle type strings */
 #define GT_END                  0x00U
 
 #define GT_IS_FUNCTION(x)       (GT_GET_TYPE(x) == GT_FUNCTION)
 #define GT_IS_STRUCT(x)         (GT_GET_TYPE(x) == GT_STRUCT)
 #define GT_IS_UNION(x)          (GT_GET_TYPE(x) == GT_UNION)
-                                                            
+
 /* Combined values for the 6502 family */
 #define GT_BYTE         (GT_INTEGER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_1)
 #define GT_WORD         (GT_INTEGER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_2)
 
 
 
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+gt_string GT_FromStrBuf (const struct StrBuf* S);
+/* Create a dynamically allocated type string from a string buffer */
+
+
+
 /* End of gentype.h */
 
 #endif
index 558c97337088cc1680f09d740156452cdca6b44d..d0fc1904b1ebeccd405e2e003b9e05ced63bdd3e 100644 (file)
@@ -28,6 +28,7 @@ OBJS =        abend.o         \
        filetype.o      \
        fname.o         \
        fp.o            \
+        gentype.o       \
        hashfunc.o      \
        hashtab.o       \
        intstack.o      \
index 8b59787ba342106415ef41f84f2b65b871456628..e814115e503e77ebde427d6866de67f16649a288 100644 (file)
@@ -70,6 +70,7 @@ OBJS =        abend.obj       \
         filetype.obj    \
        fname.obj       \
         fp.obj          \
+        gentype.obj     \
        hashfunc.obj    \
         hashtab.obj     \
         intstack.obj    \