imgtool_library *imgtool_library_create(void) { imgtool_library *library; object_pool *pool; /* create a memory pool */ pool = pool_alloc_lib(NULL); if (!pool) goto error; /* allocate the main structure */ library = (imgtool_library *)pool_malloc_lib(pool, sizeof(struct _imgtool_library)); if (!library) goto error; /* initialize the structure */ memset(library, 0, sizeof(*library)); library->pool = pool; return library; error: if (pool) pool_free_lib(pool); return NULL; }
option_resolution *option_resolution_create(const option_guide *guide, const char *specification) { option_resolution *resolution = nullptr; const option_guide *guide_entry; int option_count; int opt = -1; object_pool *pool; assert(guide); /* first count the number of options specified in the guide */ option_count = option_resolution_countoptions(guide, specification); /* create a memory pool for this structure */ pool = pool_alloc_lib(nullptr); if (!pool) goto outofmemory; /* allocate the main structure */ resolution = (option_resolution *)pool_malloc_lib(pool, sizeof(option_resolution)); if (!resolution) goto outofmemory; memset(resolution, 0, sizeof(*resolution)); resolution->pool = pool; /* set up the entries list */ resolution->option_count = option_count; resolution->specification = specification; resolution->entries = (option_resolution_entry *)pool_malloc_lib(resolution->pool, sizeof(struct option_resolution_entry) * option_count); if (!resolution->entries) goto outofmemory; memset(resolution->entries, 0, sizeof(struct option_resolution_entry) * option_count); /* initialize each of the entries */ opt = 0; guide_entry = guide; while(guide_entry->option_type != OPTIONTYPE_END) { switch(guide_entry->option_type) { case OPTIONTYPE_INT: case OPTIONTYPE_ENUM_BEGIN: case OPTIONTYPE_STRING: if (lookup_in_specification(specification, guide_entry)) resolution->entries[opt++].guide_entry = guide_entry; break; case OPTIONTYPE_ENUM_VALUE: break; default: goto unexpected; } guide_entry++; } assert(opt == option_count); return resolution; unexpected: assert(FALSE); outofmemory: if (resolution) option_resolution_close(resolution); return nullptr; }
multicart_open_error multicart_open(emu_options &options, const char *filename, const char *gamedrv, multicart_load_flags load_flags, multicart_t **cart) { multicart_open_error err; zip_error ziperr; object_pool *pool; multicart_load_state state = {0, }; const zip_file_header *header; const char *pcb_type; char *layout_text = NULL; /* allocate an object pool */ pool = pool_alloc_lib(NULL); if (pool == NULL) { err = MCERR_OUT_OF_MEMORY; goto done; } /* allocate the multicart */ state.multicart = (multicart_t*)pool_malloc_lib(pool, sizeof(*state.multicart)); if (state.multicart == NULL) { err = MCERR_OUT_OF_MEMORY; goto done; } memset(state.multicart, 0, sizeof(*state.multicart)); /* allocate the multicart's private data */ state.multicart->data = (multicart_private*)pool_malloc_lib(pool, sizeof(*state.multicart->data)); if (state.multicart->data == NULL) { err = MCERR_OUT_OF_MEMORY; goto done; } memset(state.multicart->data, 0, sizeof(*state.multicart->data)); state.multicart->data->pool = pool; pool = NULL; /* open the ZIP file */ ziperr = zip_file_open(filename, &state.zip); if (ziperr != ZIPERR_NONE) { err = MCERR_NOT_MULTICART; goto done; } /* find the layout.xml file */ header = find_file(state.zip, "layout.xml"); if (header == NULL) { err = MCERR_MISSING_LAYOUT; goto done; } /* reserve space for the layout text */ layout_text = (char*)malloc(header->uncompressed_length + 1); if (layout_text == NULL) { err = MCERR_OUT_OF_MEMORY; goto done; } /* uncompress the layout text */ ziperr = zip_file_decompress(state.zip, layout_text, header->uncompressed_length); if (ziperr != ZIPERR_NONE) { err = MCERR_ZIP_ERROR; goto done; } layout_text[header->uncompressed_length] = '\0'; /* parse the layout text */ state.layout_xml = xml_string_read(layout_text, NULL); if (state.layout_xml == NULL) { err = MCERR_XML_ERROR; goto done; } /* locate the PCB node */ if (!find_pcb_and_resource_nodes(state.layout_xml, &state.pcb_node, &state.resources_node)) { err = MCERR_NO_PCB_OR_RESOURCES; goto done; } /* get the PCB resource_type */ pcb_type = xml_get_attribute_string(state.pcb_node, "type", ""); state.multicart->pcb_type = pool_strdup_lib(state.multicart->data->pool, pcb_type); if (state.multicart->pcb_type == NULL) { err = MCERR_OUT_OF_MEMORY; goto done; } state.multicart->gamedrv_name = pool_strdup_lib(state.multicart->data->pool, gamedrv); if (state.multicart->gamedrv_name == NULL) { err = MCERR_OUT_OF_MEMORY; goto done; } /* do we have to load resources? */ if (load_flags & MULTICART_FLAGS_LOAD_RESOURCES) { err = load_all_resources(options, &state); if (err != MCERR_NONE) goto done; err = load_all_sockets(&state); if (err != MCERR_NONE) goto done; } err = MCERR_NONE; done: if (pool != NULL) pool_free_lib(pool); if (state.zip != NULL) zip_file_close(state.zip); if (layout_text != NULL) free(layout_text); if (state.layout_xml != NULL) xml_file_free(state.layout_xml); if ((err != MCERR_NONE) && (state.multicart != NULL)) { multicart_close(options, state.multicart); state.multicart = NULL; } *cart = state.multicart; return err; }
library::library() { m_pool = pool_alloc_lib(nullptr); if (!m_pool) throw std::bad_alloc(); }
void node_testmess(xml_data_node *node) { xml_data_node *child_node; xml_attribute_node *attr_node; int result; pile_init(&command_pile); command_pool = pool_alloc_lib(NULL); memset(&new_command, 0, sizeof(new_command)); command_count = 0; /* 'driver' attribute */ attr_node = xml_get_attribute(node, "driver"); if (!attr_node) { error_missingattribute("driver"); return; } current_testcase.driver = attr_node->value; /* 'name' attribute */ attr_node = xml_get_attribute(node, "name"); current_testcase.name = attr_node ? attr_node->value : current_testcase.driver; /* 'bios' attribute */ attr_node = xml_get_attribute(node, "bios"); current_testcase.bios = attr_node ? attr_node->value : NULL; /* 'ramsize' attribute */ attr_node = xml_get_attribute(node, "ramsize"); current_testcase.ram = attr_node ? ram_parse_string(attr_node->value) : 0; /* 'wavwrite' attribute */ attr_node = xml_get_attribute(node, "wavwrite"); current_testcase.wavwrite = attr_node && (atoi(attr_node->value) != 0); /* 'enabled' attribute */ attr_node = xml_get_attribute(node, "enabled"); current_testcase.enabled = (!attr_node || atoi(attr_node->value)) ? TRUE : FALSE; /* report the beginning of the test case */ report_testcase_begin(current_testcase.name); if (current_testcase.enabled) { current_testcase.commands = NULL; for (child_node = node->child; child_node; child_node = child_node->next) { if (!strcmp(child_node->name, "wait")) node_wait(child_node); else if (!strcmp(child_node->name, "input")) node_input(child_node); else if (!strcmp(child_node->name, "rawinput")) node_rawinput(child_node); else if (!strcmp(child_node->name, "switch")) node_switch(child_node); else if (!strcmp(child_node->name, "screenshot")) node_screenshot(child_node); else if (!strcmp(child_node->name, "checkblank")) node_checkblank(child_node); else if (!strcmp(child_node->name, "imagecreate")) node_imagecreate(child_node); else if (!strcmp(child_node->name, "imageload")) node_imageload(child_node); else if (!strcmp(child_node->name, "memverify")) node_memverify(child_node); else if (!strcmp(child_node->name, "imageverify")) node_imageverify(child_node); else if (!strcmp(child_node->name, "trace")) node_trace(child_node); else if (!strcmp(child_node->name, "reset")) node_soft_reset(child_node); else if (!strcmp(child_node->name, "hardreset")) node_hard_reset(child_node); } memset(&new_command, 0, sizeof(new_command)); new_command.command_type = MESSTEST_COMMAND_END; if (!append_command()) { error_outofmemory(); return; } result = run_test(0, NULL); } else { /* report that the test case was skipped */ report_message(MSG_INFO, "Test case skipped"); result = 0; } report_testcase_ran(result); pile_delete(&command_pile); pool_free_lib(command_pool); }
int messdocs(const char *toc_filename, const char *dest_dir, const char *help_project_filename, const char *help_contents_filename, const char *help_filename) { char buf[4096]; struct messdocs_state state; int len; int done; FILE *in; FILE *chm_hhp; int i; char *s; XML_Memory_Handling_Suite memcallbacks; memset(&state, 0, sizeof(state)); state.m_pool = pool_alloc_lib(NULL); /* open the DOC */ in = fopen(toc_filename, "r"); if (!in) { fprintf(stderr, "Cannot open TOC file '%s'\n", toc_filename); goto error; } /* figure out the TOC directory */ state.m_toc_dir = pool_strdup_lib(state.m_pool, toc_filename); if (!state.m_toc_dir) goto outofmemory; for (i = strlen(state.m_toc_dir) - 1; (i > 0) && !osd_is_path_separator(state.m_toc_dir[i]); i--) state.m_toc_dir[i] = '\0'; /* clean the target directory */ rmdir_recursive(dest_dir); osd_mkdir(dest_dir); /* create the help contents file */ s = (char*)pool_malloc_lib(state.m_pool, strlen(dest_dir) + 1 + strlen(help_project_filename) + 1); if (!s) goto outofmemory; strcpy(s, dest_dir); strcat(s, PATH_SEPARATOR); strcat(s, help_contents_filename); state.m_chm_toc = fopen(s, "w"); state.m_dest_dir = dest_dir; if (!state.m_chm_toc) { fprintf(stderr, "Cannot open file %s\n", s); goto error; } fprintf(state.m_chm_toc, "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"\n"); fprintf(state.m_chm_toc, "<HTML>\n"); fprintf(state.m_chm_toc, "<HEAD>\n"); fprintf(state.m_chm_toc, "</HEAD>\n"); fprintf(state.m_chm_toc, "<BODY>\n"); fprintf(state.m_chm_toc, "<OBJECT type=\"text/site properties\">\n"); fprintf(state.m_chm_toc, "\t<param name=\"Window Styles\" value=\"0x800625\">\n"); fprintf(state.m_chm_toc, "\t<param name=\"ImageType\" value=\"Folder\">\n"); fprintf(state.m_chm_toc, "\t<param name=\"Font\" value=\"Arial,8,0\">\n"); fprintf(state.m_chm_toc, "</OBJECT>\n"); fprintf(state.m_chm_toc, "<UL>\n"); /* create the XML parser */ memcallbacks.malloc_fcn = expat_malloc; memcallbacks.realloc_fcn = expat_realloc; memcallbacks.free_fcn = expat_free; state.m_parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); if (!state.m_parser) goto outofmemory; XML_SetUserData(state.m_parser, &state); XML_SetElementHandler(state.m_parser, start_handler, end_handler); XML_SetCharacterDataHandler(state.m_parser, data_handler); do { len = (int) fread(buf, 1, sizeof(buf), in); done = feof(in); if (XML_Parse(state.m_parser, buf, len, done) == XML_STATUS_ERROR) { process_error(&state, NULL, NULL); break; } } while(!done); fprintf(state.m_chm_toc, "</UL>\n"); fprintf(state.m_chm_toc, "</BODY></HTML>"); fclose(state.m_chm_toc); /* create the help project file */ s = (char*)pool_malloc_lib(state.m_pool, strlen(dest_dir) + 1 + strlen(help_project_filename) + 1); if (!s) goto outofmemory; strcpy(s, dest_dir); strcat(s, PATH_SEPARATOR); strcat(s, help_project_filename); chm_hhp = fopen(s, "w"); if (!chm_hhp) { fprintf(stderr, "Cannot open file %s\n", s); goto error; } fprintf(chm_hhp, "[OPTIONS]\n"); fprintf(chm_hhp, "Compiled file=%s\n", help_filename); fprintf(chm_hhp, "Contents file=%s\n", help_contents_filename); fprintf(chm_hhp, "Default topic=%s\n", state.m_default_topic); fprintf(chm_hhp, "Language=0x409 English (United States)\n"); fprintf(chm_hhp, "Title=%s\n", state.m_title); fprintf(chm_hhp, "\n"); fclose(chm_hhp); /* finish up */ XML_ParserFree(state.m_parser); fclose(in); pool_free_lib(state.m_pool); return state.m_error ? -1 : 0; outofmemory: fprintf(stderr, "Out of memory"); error: if (state.m_chm_toc) fclose(state.m_chm_toc); if (in) fclose(in); return -1; }