X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Fir.c;h=a175ef3fdfd93e7c47b02f332a4ac3f4e2cfef67;hp=db970971de3d4a97424489a7284484878fafaf59;hb=7dae7dc73dfbabdc895a78738f550f56561da644;hpb=43f088652419e08b7426b2c689591b280c0f2330 diff --git a/src/ir.c b/src/ir.c index db97097..a175ef3 100644 --- a/src/ir.c +++ b/src/ir.c @@ -117,11 +117,15 @@ static void ir_free_pagenodes(struct pagenode_t*); static inline int bytes_identical(const uint8_t*,const uint8_t*); +static inline +int classnames_identical(const uint8_t*,const uint8_t*); static void* stack_alloc(size_t); #define struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T))) static uint8_t* name_alloc(const uint8_t*); +static +uint8_t* classname_alloc(const uint8_t*); extern //apc.c long sys_pagesize; static @@ -209,7 +213,7 @@ struct ir_class_t* ir_class_addchild if (name == NULL) eprintf("Null child added to class %s\n", iter->name); check: - if (bytes_identical(iter->name, name)) + if (classnames_identical(iter->name, name)) return iter; if (iter->nextsib != NULL) { iter = iter->nextsib; @@ -218,7 +222,7 @@ struct ir_class_t* ir_class_addchild alloc: iter = struct_alloc(ir_class_t); iter->nextsib = class->nextchild; - iter->name = name_alloc(name); + iter->name = classname_alloc(name); return class->nextchild = iter; } @@ -325,6 +329,19 @@ int bytes_identical return (ca == cb); } +static inline +int classnames_identical +( const uint8_t* stra, + const uint8_t* strb +) +{ int ca, cb; + do { + ca = *stra++; + cb = *strb++; + } while (ca && ca == cb); + return (ca == cb); +} + /* Assign Setdata to Set */ @@ -549,3 +566,26 @@ uint8_t* name_alloc *(namepages.head->header.head)++ = '\0'; return name; } + +static +uint8_t* classname_alloc +( const uint8_t* name_src ) +{ const uint8_t* iter; + uint8_t* name; + int head_mem; + copy: + name = (uint8_t*)namepages.head->header.head; + iter = name_src; + for (head_mem = PL_HEADMEM(namepages); *iter && head_mem; head_mem--) + *(namepages.head->header.head)++ = *iter++; + if (head_mem == 0) //not enough room + { namepages.head->header.next = (struct pagenode_t*) calloc(namepages.pagesize,1); + if (namepages.head->header.next == NULL) + eprintf("Memory allocation error\n"); + namepages.head = namepages.head->header.next; + namepages.head->header.head = namepages.head->root; + goto copy; + } + *(namepages.head->header.head)++ = '\0'; + return name; +}