X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Fir.c;h=f39f85b2371f700a6e8cbc98091f6ee4d62ad17d;hp=4cec2062cc232ee2afc95c54e6e3200e91f5c5e1;hb=78ec1b2aecefbd7f6839f54c52b2dd6e3f80bf1a;hpb=098067796d5d9e7f30451608c054e5dd30c85775 diff --git a/src/ir.c b/src/ir.c index 4cec206..f39f85b 100644 --- a/src/ir.c +++ b/src/ir.c @@ -23,6 +23,7 @@ void ir_quit(void); int ir_linker(void); int ir_condenser(void); /* Memory allocation structures */ +enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT }; struct pagenode_t; struct pagenode_header_t { struct pagenode_t* next; @@ -36,9 +37,6 @@ struct pagelist_t { struct pagenode_t* root, * head; size_t pagesize; }; -/* Set link data */ -enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT }; -enum ltype { OLINK, MLINK, VLINK, ALINK }; struct ir_namelist_t; struct ir_namelist_t { struct ir_namelist_t* nextsib; @@ -103,17 +101,17 @@ struct ir_set_t static inline int init_pagelist(struct pagelist_t*,size_t); static inline -struct ir_framebox_t* ir_set_add_framebox(struct ir_set_t*, uint8_t*); +struct ir_framebox_t* ir_set_add_framebox(struct ir_set_t*,const uint8_t*); static void ir_free_pagenodes(struct pagenode_t*); static inline -int bytes_identical(uint8_t*,uint8_t*); +int bytes_identical(const uint8_t*,const uint8_t*); static void* stack_alloc(size_t); static -uint8_t* name_alloc(uint8_t*); +uint8_t* name_alloc(const uint8_t*); static inline -union ir_setdata_t* ir_framedata (enum dtype,uint8_t*,apc_facing,int,int); +union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int); /* Function-Like Macros */ #define do_warn() do { \ } while (0) @@ -214,12 +212,17 @@ struct ir_class_t* ir_class_root */ struct ir_class_t* ir_class_addchild ( struct ir_class_t* class, - uint8_t* name + const uint8_t* name ) { struct ir_class_t* iter; + printf("Class %s, addchild %s\n", class->name, name); if (class->nextchild == NULL) - return class->nextchild = struct_alloc(ir_class_t); + goto alloc; iter = class->nextchild; + if (iter->name == NULL) + eprintf("Null name pointer in class %p\n", iter); + if (name == NULL) + eprintf("Null child added to class %s\n", iter->name); check: if (bytes_identical(iter->name, name)) return iter; @@ -227,6 +230,7 @@ struct ir_class_t* ir_class_addchild { iter = iter->nextsib; goto check; } + alloc: iter = struct_alloc(ir_class_t); iter->nextsib = class->nextchild; iter->name = name_alloc(name); @@ -239,12 +243,17 @@ struct ir_class_t* ir_class_addchild */ struct ir_set_t* ir_class_addset ( struct ir_class_t* class, - uint8_t* name + const uint8_t* name ) { struct ir_set_t* iter; + printf("Class %s, addset %s\n", class->name, name); if (class->root_set == NULL) - return class->root_set = struct_alloc(ir_set_t); + goto alloc; iter = class->root_set; + if (iter->name == NULL) + eprintf("Null name pointer in class %p\n", iter); + if (name == NULL) + eprintf("Null set added to class %s\n", iter->name); check: if (bytes_identical(iter->name, name)) return iter; @@ -252,6 +261,7 @@ struct ir_set_t* ir_class_addset { iter = iter->nextsib; goto check; } + alloc: iter = struct_alloc(ir_set_t); iter->nextsib = class->root_set; iter->name = name_alloc(name); @@ -264,12 +274,17 @@ struct ir_set_t* ir_class_addset */ struct ir_set_t* ir_set_addchild ( struct ir_set_t* set, - uint8_t* name + const uint8_t* name ) { struct ir_set_t* iter; + printf("Set %s, addchild %s\n", set->name, name); if (set->nextchild == NULL) - return set->nextchild = struct_alloc(ir_set_t); + goto alloc; iter = set->nextchild; + if (iter->name == NULL) + eprintf("Null name pointer in set %p\n", iter); + if (name == NULL) + eprintf("Null child added to set %s\n", iter->name); check: if (bytes_identical(iter->name, name)) return iter; @@ -277,6 +292,7 @@ struct ir_set_t* ir_set_addchild { iter = iter->nextsib; goto check; } + alloc: iter = struct_alloc(ir_set_t); iter->nextsib = set->nextchild; iter->name = name_alloc(name); @@ -290,11 +306,11 @@ struct ir_set_t* ir_set_addchild static inline struct ir_framebox_t* ir_set_add_framebox ( struct ir_set_t* set, - uint8_t* name + const uint8_t* name ) { struct ir_framebox_t* iter; if (set->frameboxes == NULL) - return set->frameboxes = struct_alloc(ir_framebox_t); + goto alloc; iter = set->frameboxes; check: if (bytes_identical(iter->header.data_name, name)) @@ -303,6 +319,7 @@ struct ir_framebox_t* ir_set_add_framebox { iter = (struct ir_framebox_t*) iter->header.nextsib; goto check; } + alloc: iter = struct_alloc(ir_framebox_t); iter->header.nextsib = (union ir_setdata_t*) set->frameboxes; iter->header.data_name = name_alloc(name); @@ -314,14 +331,14 @@ struct ir_framebox_t* ir_set_add_framebox */ static inline int bytes_identical -( uint8_t* stra, - uint8_t* strb +( const uint8_t* stra, + const uint8_t* strb ) { int ca, cb; do { ca = *stra++; cb = *strb++; - } while (ca && ca == cb); + } while (ca && ca != '_' && ca == cb); return (ca == cb); } @@ -390,39 +407,43 @@ void ir_set_assign_ref void ir_data_assign_path ( union ir_setdata_t* setdata, - uint8_t* path + const uint8_t* path ) -{ if (setdata->header.src_filename != NULL) +{ if (path == NULL) + eprintf("Null path in data %s\n", setdata->header.data_name); + if (setdata->header.src_filename != NULL) wprintf("Path override: %s -> %s for setdata %s\n", setdata->header.src_filename, path, setdata->header.data_name); setdata->header.src_filename = name_alloc(path); } union ir_setdata_t* ir_framesheet -( uint8_t* name, - apc_facing d, - int width, - int height +( const uint8_t* name, + apc_facing d, + int width, + int height ) { return ir_framedata(FSDAT, name, d, width, height); } union ir_setdata_t* ir_mapsheet -( uint8_t* name, - apc_facing d, - int width, - int height +( const uint8_t* name, + apc_facing d, + int width, + int height ) { return ir_framedata(MSDAT, name, d, width, height); } static inline union ir_setdata_t* ir_framedata -( enum dtype type, - uint8_t* name, - apc_facing d, - int width, - int height +( enum dtype type, + const uint8_t* name, + apc_facing d, + int width, + int height ) { struct ir_framedata_t* framedata = struct_alloc(ir_framedata_t); + if (name == NULL) + eprint("Null name in set allocation\n"); framedata->header.type = type; framedata->header.data_name = name_alloc(name); framedata->frameinfo.facing = d; @@ -432,8 +453,10 @@ union ir_setdata_t* ir_framedata } union ir_setdata_t* ir_audio -( uint8_t* name ) +( const uint8_t* name ) { struct ir_simplex_t* audio = struct_alloc(ir_simplex_t); + if (name == NULL) + eprint("Null audio\n"); audio->header.type = ADAT; audio->header.data_name = name_alloc(name); return (union ir_setdata_t*) audio; @@ -444,6 +467,8 @@ union ir_setdata_t* ir_audio struct ir_classld_t* ir_classld_from_class ( struct ir_class_t* class ) { struct ir_classld_t* classld; + if (class == NULL) + eprint("Null class in classld\n"); classld = struct_alloc(ir_classld_t); classld->root_class = class; return classld; @@ -459,7 +484,7 @@ struct ir_setld_t* ir_setld_from_ref struct ir_setld_t* ir_setld_from_classld ( struct ir_classld_t* classld, - uint8_t* name + const uint8_t* name ) { struct ir_setld_t* setld; setld = struct_alloc(ir_setld_t); @@ -472,7 +497,7 @@ struct ir_setld_t* ir_setld_from_classld struct ir_setld_t* ir_setld_addchild ( struct ir_setld_t* setld, - uint8_t* name + const uint8_t* name ) { if (setld->namelist == NULL) { setld->namelist = struct_alloc(ir_namelist_t); @@ -489,7 +514,7 @@ struct ir_setld_t* ir_setld_addchild union ir_setdata_t* ir_link ( enum ltype link_type, struct ir_setld_t* setld, - uint8_t* name + const uint8_t* name ) { struct ir_link_t* link; link = struct_alloc(ir_link_t); @@ -521,13 +546,14 @@ void* stack_alloc static uint8_t* name_alloc -( uint8_t* name_src ) -{ uint8_t* iter, * name; - int head_mem; +( 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--) + for (head_mem = PL_HEADMEM(namepages); *iter && *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);