X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Fir.c;h=4ef2e5a9fa328be6fd935f8624dfc922a36239a3;hp=3f90e1875a58e7730c089904e8711068f02e709a;hb=32084db924eb07c8a5e44748aaf12883189b37d2;hpb=db01318a8e246249ceea23255a6512ea8a5c00c2 diff --git a/src/ir.c b/src/ir.c index 3f90e18..4ef2e5a 100644 --- a/src/ir.c +++ b/src/ir.c @@ -44,16 +44,15 @@ struct ir_classld_t }; struct ir_setld_t { struct ir_classld_t* classld; - long long ref; + uint32_t ref; struct ir_namelist_t* namelist, * namelist_head; }; struct ir_setdata_header_t { enum dtype type; uint8_t* src_filename, * data_name; union ir_setdata_t* nextsib; + long filepos; }; -struct ir_frameinfo_t -{ int facing, w, h; }; struct ir_framedata_t { struct ir_setdata_header_t header; struct ir_frameinfo_t frameinfo; @@ -82,6 +81,7 @@ struct ir_class_t { struct ir_class_t* nextchild, * nextsib; struct ir_set_t* root_set; uint8_t* name; + long filepos; }; struct ir_set_t { struct ir_set_t* nextchild, * nextsib; @@ -90,7 +90,7 @@ struct ir_set_t struct ir_framebox_t* frameboxes; struct ir_simplex_t* audio; struct ir_link_t* links; - long filepos; + long filepos; }; /* Functions */ static inline @@ -222,6 +222,11 @@ struct ir_set_t* ir_class_addset return iter->nextsib; } +/* Get the root set of the class */ +struct ir_set_t* ir_class_rootset +( struct ir_class_t* class ) +{ return class->root_set; } + struct ir_set_t* ir_set_from_ref ( uint32_t ref ) { uint16_t hash; @@ -330,6 +335,55 @@ int classnames_identical return (ca == cb); } +/* Return the name of the set */ +uint8_t* ir_set_name +( struct ir_set_t* set) +{ return set->name; } + +/* Return the next sib of the class */ +struct ir_class_t* ir_class_nextsib +( struct ir_class_t* class ) +{ return class->nextsib; } + +/* Return the next sib of the class */ +struct ir_class_t* ir_class_nextchild +( struct ir_class_t* class ) +{ return class->nextchild; } + +/* Get the file position of the class */ +long ir_class_fpos +( struct ir_class_t* class ) +{ return class->filepos; } + +/* Set the file position of the class */ +void ir_class_assign_fpos +( struct ir_class_t* class, + long newpos +) +{ class->filepos = newpos; } + +/* Get the next sibling of the provided set */ +struct ir_set_t* ir_set_nextsib +( struct ir_set_t* set ) +{ return set->nextsib; } + +/* Get the next child of the provided set */ +struct ir_set_t* ir_set_nextchild +( struct ir_set_t* set ) +{ return set->nextchild; } + +/* Get the file position of the class */ +long ir_set_fpos +( struct ir_set_t* set ) +{ return set->filepos; } + +/* Set the file position of the class */ +void ir_set_assign_fpos +( struct ir_set_t* set, + long newpos +) +{ set->filepos = newpos; } + /* Assign Setdata to Set */ void ir_set_assign_data ( struct ir_set_t* set, @@ -546,7 +600,171 @@ union ir_setdata_t* ir_link return (union ir_setdata_t*) link; } +/* Return a set's root framebox */ +union ir_setdata_t* ir_set_framebox +( struct ir_set_t* set ) +{ return (union ir_setdata_t*) set->frameboxes; } + +/* Return a set's root audio data */ +union ir_setdata_t* ir_set_audio +( struct ir_set_t* set ) +{ return (union ir_setdata_t*) set->audio; } + +/* Return a set's root link data */ +union ir_setdata_t* ir_set_link +( struct ir_set_t* set ) +{ return (union ir_setdata_t*) set->links; } + +/* Return the link type */ +enum ltype ir_linkdata_type +( union ir_setdata_t* linkdata ) +{ if (linkdata->header.type != LDAT) + eprintf("Data %s is not a link\n", linkdata->header.data_name); + return linkdata->link.type; +} + +/* Return the link type */ +uint32_t ir_linkdata_ref +( union ir_setdata_t* linkdata ) +{ if (linkdata->header.type != LDAT) + eprintf("Data %s is not a link\n", linkdata->header.data_name); + return linkdata->link.setld->ref; +} + +/* Resolve and return the link's target set + Fails on error, cannot return NULL +*/ +struct ir_set_t* ir_linkdata_set +( union ir_setdata_t* linkdata ) +{ struct ir_class_t* class_iter; + struct ir_namelist_t* namelist_iter,* namelist_iter_last; + struct ir_setld_t* setld; + struct ir_classld_t* classld; + struct ir_set_t* set; + set = NULL; + class_iter = NULL; + if (linkdata->header.type != LDAT) + eprintf("Data %s is not a link\n", linkdata->header.data_name); + setld = linkdata->link.setld; + if (linkdata->link.setld == NULL) + eprintf("Link data is invalid\n"); + classld = linkdata->link.classld; + if (classld != NULL) + { namelist_iter = classld->namelist; + if (classld->root_class == NULL) + eprintf("No root class for classld\n"); + class_iter = classld->root_class->nextchild; + namelist_iter_last = NULL; + while (class_iter != NULL) + { if (classnames_identical(class_iter->name, namelist_iter->name)) + { if (namelist_iter == classld->namelist_head) + break; + class_iter = class_iter->nextchild; + namelist_iter_last = namelist_iter; + namelist_iter = namelist_iter->nextsib; + } + else + class_iter = class_iter->nextsib; + } + if (class_iter == NULL) + { if (namelist_iter_last) + eprintf("No such subclass \"%s\" of class \"%s\"\n", + namelist_iter->name, + namelist_iter_last->name); + else + eprintf("No such class \"%s\"\n", namelist_iter->name); + } + set = class_iter->root_set; + } + else + set = ir_set_from_ref(setld->ref); + if (set == NULL) + eprintf("Initial set resolution failed\n"); + namelist_iter = setld->namelist; + namelist_iter_last = NULL; + if (setld->namelist != NULL) + { while (set != NULL) + { if (bytes_identical(set->name, namelist_iter->name)) + { if (namelist_iter == setld->namelist_head) + break; + set = set->nextchild; + namelist_iter_last = namelist_iter; + namelist_iter = namelist_iter->nextsib; + } + else + set = set->nextsib; + } + if (set == NULL) + { if (namelist_iter_last) + eprintf("No such subset \"%s\" of set \"%s\"\n", + namelist_iter->name, + namelist_iter_last->name); + else + eprintf("No such set \"%s\" in class \"%s\"\n", + namelist_iter->name, + class_iter->name); + } + } + return set; +} + +/* Get a setdata's next sibling */ +union ir_setdata_t* ir_setdata_nextsib +( union ir_setdata_t* setdata ) +{ return setdata->header.nextsib; } + +/* Get a setdata's name */ +uint8_t* ir_setdata_name +( union ir_setdata_t* setdata ) +{ return setdata->header.data_name; } + +/* Get a setdata's filename */ +uint8_t* ir_setdata_filename +( union ir_setdata_t* setdata ) +{ return setdata->header.src_filename; } + +/* Get a setdata's file position */ +long ir_setdata_fpos +( union ir_setdata_t* setdata ) +{ return setdata->header.filepos; } + +/* Set a setdata's file position */ +void ir_setdata_assign_fpos +( union ir_setdata_t* setdata, + long newpos +) +{ setdata->header.filepos = newpos; } + +/* Return a framebox's specified framesheet */ +union ir_setdata_t* ir_framebox_framesheet +( union ir_setdata_t* fbox, + apc_facing facing +) +{ if (fbox->header.type != FBDAT) + eprintf("Data %s is not a framebox\n", fbox->header.data_name); + return (union ir_setdata_t*) &fbox->framebox.framesheets[facing]; +} + +/* Return a framebox's specified mapsheet */ +union ir_setdata_t* ir_framebox_mapsheet +( union ir_setdata_t* fbox, + apc_facing facing +) +{ if (fbox->header.type != FBDAT) + eprintf("Data %s is not a framebox\n", fbox->header.data_name); + return (union ir_setdata_t*) &fbox->framebox.mapsheets[facing]; +} + +/* Return a framedata's frame info */ +struct ir_frameinfo_t* ir_framedata_frameinfo +( union ir_setdata_t* framedata ) +{ if (framedata->header.type != MSDAT && framedata->header.type != FSDAT) + eprintf("Data %s is not a framedata\n", framedata->header.data_name); + return &framedata->mapsheet.frameinfo; +} + +/** Allocators **/ static uint8_t* name_alloc ( const uint8_t* name_src ) @@ -588,13 +806,15 @@ uint8_t* classname_alloc static void crawl_class(struct ir_class_t*); static void crawl_set(struct ir_set_t*,int); +extern +int binout_init(ir_class); void ir_test(void) { uprintf("IR From Directory: %s\n",getcwd(NULL,255)); crawl_class(&root_class); if (root_class.root_set != NULL) crawl_set(root_class.root_set, 0); uprintf("starting binaryout \n"); - ir_binout_init(&root_class); + binout_init(&root_class); }