debug print formatting
[henge/apc.git] / src / ir.c
index db97097..a175ef3 100644 (file)
--- a/src/ir.c
+++ b/src/ir.c
@@ -117,11 +117,15 @@ static
 void     ir_free_pagenodes(struct pagenode_t*);\r
 static inline\r
 int      bytes_identical(const uint8_t*,const uint8_t*);\r
+static inline\r
+int      classnames_identical(const uint8_t*,const uint8_t*);\r
 static\r
 void*    stack_alloc(size_t);\r
 #define  struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T)))\r
 static\r
 uint8_t* name_alloc(const uint8_t*);\r
+static\r
+uint8_t* classname_alloc(const uint8_t*);\r
 extern //apc.c\r
 long     sys_pagesize;\r
 static\r
@@ -209,7 +213,7 @@ struct ir_class_t* ir_class_addchild
   if (name == NULL)\r
     eprintf("Null child added to class %s\n", iter->name);\r
  check:\r
-  if (bytes_identical(iter->name, name))\r
+  if (classnames_identical(iter->name, name))\r
     return iter;\r
   if (iter->nextsib != NULL)\r
     { iter = iter->nextsib;\r
@@ -218,7 +222,7 @@ struct ir_class_t* ir_class_addchild
  alloc:\r
   iter = struct_alloc(ir_class_t);\r
   iter->nextsib = class->nextchild;\r
-  iter->name = name_alloc(name);\r
+  iter->name = classname_alloc(name);\r
   return class->nextchild = iter;\r
 }\r
 \r
@@ -325,6 +329,19 @@ int bytes_identical
   return (ca == cb);\r
 }\r
 \r
+static inline\r
+int classnames_identical\r
+( const uint8_t* stra,\r
+  const uint8_t* strb\r
+)\r
+{ int ca, cb;\r
+  do {\r
+    ca = *stra++;\r
+    cb = *strb++;\r
+  } while (ca && ca == cb);\r
+  return (ca == cb);\r
+}\r
+\r
 /* Assign Setdata to Set\r
 \r
  */\r
@@ -549,3 +566,26 @@ uint8_t* name_alloc
   *(namepages.head->header.head)++ = '\0';\r
   return name;\r
 }\r
+\r
+static\r
+uint8_t* classname_alloc\r
+( const uint8_t* name_src )\r
+{ const uint8_t* iter;\r
+  uint8_t*       name;\r
+  int            head_mem;\r
+ copy:\r
+  name = (uint8_t*)namepages.head->header.head;\r
+  iter = name_src;\r
+  for (head_mem = PL_HEADMEM(namepages); *iter && head_mem; head_mem--)\r
+    *(namepages.head->header.head)++ = *iter++;\r
+  if (head_mem == 0) //not enough room\r
+    { namepages.head->header.next = (struct pagenode_t*) calloc(namepages.pagesize,1);\r
+      if (namepages.head->header.next == NULL)\r
+       eprintf("Memory allocation error\n");\r
+      namepages.head = namepages.head->header.next;\r
+      namepages.head->header.head = namepages.head->root;\r
+      goto copy;\r
+    }\r
+  *(namepages.head->header.head)++ = '\0';\r
+  return name;\r
+}\r