/* bootstrap the structures for xml_parse() to be able to get started */ XmlNode* xml_load(const char * filename) { struct XMLBUF xml; XmlNode *ret = NULL; // printf("xml_load(\"%s\");\n", filename); xml.error = 0; xml.eof = 0; xml.read_index = 0; xml.fptr = fopen(filename, "rb"); if(!xml.fptr) return NULL; xml.buf = malloc(BUFFER+1); if(!xml.buf) goto xml_load_fail_malloc_buf; xml.buf[BUFFER]=0; xml.len = BUFFER; xml_read_file(&xml); ret = xml_parse(&xml); if(xml.error) { xml_free(ret); ret = NULL; } free(xml.buf); xml_load_fail_malloc_buf: fclose(xml.fptr); return ret; }
static void scene_init(int width, int height) { options.scene = new Scene(options.scene_params, options.session_params.device); xml_read_file(options.scene, options.filepath.c_str()); if (width == 0 || height == 0) { options.width = options.scene->camera->width; options.height = options.scene->camera->height; } }
static void scene_init(int width, int height) { printf("scene_init.\n"); options.scene = new Scene(options.scene_params); xml_read_file(options.scene, options.filepath.c_str()); if (width == 0 || height == 0) { options.width = options.scene->camera->width; options.height = options.scene->camera->height; } }
/*** read a byte and advance the offset */ static char xml_read_byte(XMLBUF *xml) { char ret = xml_peek(xml); xml->read_index++; if(xml->read_index >= xml->len) { if(xml->eof) { xml->read_index = xml->len; return ret; } xml->read_index = 0 ; xml_read_file(xml); } return ret; }
/* * char* xml_feed(x, test) * * Reads as many contiguous chars that pass test() into a newly allocated * string. * * Instead of calling xml_read_byte and flogging realloc() for each byte, * it checks the buffer itself. */ static char* xml_feed( XMLBUF *xml, int (*test)(char) ) { int offset = xml->read_index; int delta; char *ret = NULL; char *tmp = NULL; int size = 0; /* perform first and N middle realloc()'s */ while( test(xml->buf[offset]) ) { offset ++; if(offset >= xml->len) { delta = offset - xml->read_index; tmp = realloc(ret, size + delta + 1); if(!tmp)goto xml_feed_malloc; ret = tmp; memcpy(ret+size, xml->buf + xml->read_index, delta); size += delta; ret[size]=0; if(xml->eof)return ret; xml_read_file(xml); xml->read_index = 0; offset = 0; } } /* perform final realloc() if needed */ if(offset > xml->read_index) { delta = offset - xml->read_index; tmp = realloc(ret, size + delta + 1); if(!tmp)goto xml_feed_malloc; ret = tmp; memcpy(ret+size, xml->buf + xml->read_index, delta); xml->read_index = offset; size += delta; ret[size]=0; } return ret; xml_feed_malloc: free(ret); xml_end_file(xml); return 0; }
static void scene_init() { options.scene = new Scene(options.scene_params, options.session_params.device); /* Read XML */ xml_read_file(options.scene, options.filepath.c_str()); /* Camera width/height override? */ if(!(options.width == 0 || options.height == 0)) { options.scene->camera->width = options.width; options.scene->camera->height = options.height; } else { options.width = options.scene->camera->width; options.height = options.scene->camera->height; } /* Calculate Viewplane */ options.scene->camera->compute_auto_viewplane(); }