コード例 #1
0
ファイル: library.c プロジェクト: broftkd/mess-cvs
static void imgtool_library_add_class(imgtool_library *library, const imgtool_class *imgclass)
{
	imgtool_module *module;
	char *s1, *s2;
	size_t len;

	/* allocate the module and place it in the chain */
	module = auto_malloc(sizeof(*module));
	memset(module, 0, sizeof(*module));
	module->previous = library->last;
	if (library->last)
		library->last->next = module;
	else
		library->first = module;
	library->last = module;

	/* extensions have a weird format */
	s1 = imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_FILE_EXTENSIONS);
	len = strlen(s1);;
	s2 = auto_malloc(len + 2);
	strcpy(s2, s1);
	s2[len + 1] = '\0';
	while((s1 = strchr(s2, ',')) != NULL)
		*s1 = '\0';
	module->extensions = s2;

	module->imgclass					= *imgclass;
	module->name						= auto_strdup(imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_NAME));
	module->description					= auto_strdup(imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_DESCRIPTION));
	module->eoln						= auto_strdup_allow_null(imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_EOLN));
	module->initial_path_separator		= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_INITIAL_PATH_SEPARATOR) ? 1 : 0;
	module->open_is_strict				= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_OPEN_IS_STRICT) ? 1 : 0;
	module->tracks_are_called_cylinders	= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_TRACKS_ARE_CALLED_CYLINDERS) ? 1 : 0;
	module->writing_untested			= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED) ? 1 : 0;
	module->creation_untested			= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_CREATION_UNTESTED) ? 1 : 0;
	module->open						= (imgtoolerr_t (*)(imgtool_image *, imgtool_stream *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
	module->create						= (imgtoolerr_t (*)(imgtool_image *, imgtool_stream *, option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
	module->close						= (void (*)(imgtool_image *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CLOSE);
	module->info						= (void (*)(imgtool_image *, char *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO);
	module->read_sector					= (imgtoolerr_t (*)(imgtool_image *, UINT32, UINT32, UINT32, void *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_SECTOR);
	module->write_sector				= (imgtoolerr_t (*)(imgtool_image *, UINT32, UINT32, UINT32, const void *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_WRITE_SECTOR);
	module->get_geometry				= (imgtoolerr_t (*)(imgtool_image *, UINT32 *, UINT32 *, UINT32 *))imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_GET_GEOMETRY);
	module->get_sector_size				= (imgtoolerr_t (*)(imgtool_image *, UINT32, UINT32, UINT32, UINT32 *))imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_GET_SECTOR_SIZE);
	module->read_block					= (imgtoolerr_t (*)(imgtool_image *, void *, UINT64)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_BLOCK);
	module->write_block					= (imgtoolerr_t (*)(imgtool_image *, const void *, UINT64)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_WRITE_BLOCK);
	module->list_partitions				= (imgtoolerr_t (*)(imgtool_image *, imgtool_partition_info *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_LIST_PARTITIONS);
	module->block_size					= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_BLOCK_SIZE);
	module->createimage_optguide		= (const struct OptionGuide *) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE);
	module->createimage_optspec			= auto_strdup_allow_null(imgtool_get_info_ptr(imgclass, IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC));
	module->image_extra_bytes			+= imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES);
}
コード例 #2
0
ファイル: library.c プロジェクト: broftkd/mess-cvs
void imgtool_library_add(imgtool_library *library, imgtool_get_info get_info)
{
	int (*make_class)(int index, imgtool_class *imgclass);
	imgtool_class imgclass;
	int i, result;

	/* try this class */
	memset(&imgclass, 0, sizeof(imgclass));
	imgclass.get_info = get_info;

	/* do we have derived getinfo functions? */
	make_class = (int (*)(int index, imgtool_class *imgclass))
		imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_MAKE_CLASS);

	if (make_class)
	{
		i = 0;
		do
		{
			/* clear out the class */
			memset(&imgclass, 0, sizeof(imgclass));
			imgclass.get_info = get_info;

			/* make the class */
			result = make_class(i++, &imgclass);
			if (result)
				imgtool_library_add_class(library, &imgclass);
		}
		while(result);
	}
	else
	{
		imgtool_library_add_class(library, &imgclass);
	}
}
コード例 #3
0
ファイル: library.cpp プロジェクト: RalfVB/mame
void library::add(imgtool_get_info get_info)
{
	int (*make_class)(int index, imgtool_class *imgclass);
	imgtool_class imgclass;
	int i, result;

	// try this class
	memset(&imgclass, 0, sizeof(imgclass));
	imgclass.get_info = get_info;

	// do we have derived getinfo functions?
	make_class = (int (*)(int index, imgtool_class *imgclass))
		imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_MAKE_CLASS);

	if (make_class)
	{
		i = 0;
		do
		{
			// clear out the class
			memset(&imgclass, 0, sizeof(imgclass));
			imgclass.get_info = get_info;

			// make the class
			result = make_class(i++, &imgclass);
			if (result)
				add_class(&imgclass);
		}
		while(result);
	}
	else
	{
		add_class(&imgclass);
	}
}
コード例 #4
0
ファイル: library.cpp プロジェクト: RalfVB/mame
void library::add_class(const imgtool_class *imgclass)
{
	char *s1, *s2;

	// allocate the module and place it in the chain
	m_modules.emplace_back(std::make_unique<imgtool_module>());
	imgtool_module *module = m_modules.back().get();
	memset(module, 0, sizeof(*module));

	// extensions have a weird format
	s1 = imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_FILE_EXTENSIONS);
	s2 = (char*)imgtool_library_malloc(strlen(s1) + 1);
	strcpy(s2, s1);
	module->extensions = s2;

	module->imgclass                    = *imgclass;
	module->name                        = imgtool_library_strdup(imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_NAME));
	module->description                 = imgtool_library_strdup(imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_DESCRIPTION));
	module->eoln                        = imgtool_library_strdup_allow_null(imgtool_get_info_string(imgclass, IMGTOOLINFO_STR_EOLN));
	module->initial_path_separator      = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_INITIAL_PATH_SEPARATOR) ? 1 : 0;
	module->open_is_strict              = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_OPEN_IS_STRICT) ? 1 : 0;
	module->tracks_are_called_cylinders = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_TRACKS_ARE_CALLED_CYLINDERS) ? 1 : 0;
	module->writing_untested            = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED) ? 1 : 0;
	module->creation_untested           = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_CREATION_UNTESTED) ? 1 : 0;
	module->open                        = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
	module->create                      = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
	module->close                       = (void (*)(imgtool::image *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CLOSE);
	module->info                        = (void (*)(imgtool::image *, char *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO);
	module->read_sector                 = (imgtoolerr_t (*)(imgtool::image *, UINT32, UINT32, UINT32, std::vector<UINT8> &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_SECTOR);
	module->write_sector                = (imgtoolerr_t (*)(imgtool::image *, UINT32, UINT32, UINT32, const void *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_WRITE_SECTOR);
	module->get_geometry                = (imgtoolerr_t (*)(imgtool::image *, UINT32 *, UINT32 *, UINT32 *))imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_GET_GEOMETRY);
	module->read_block                  = (imgtoolerr_t (*)(imgtool::image *, void *, UINT64)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_BLOCK);
	module->write_block                 = (imgtoolerr_t (*)(imgtool::image *, const void *, UINT64)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_WRITE_BLOCK);
	module->list_partitions             = (imgtoolerr_t (*)(imgtool::image *, imgtool_partition_info *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_LIST_PARTITIONS);
	module->block_size                  = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_BLOCK_SIZE);
	module->createimage_optguide        = (const util::option_guide *) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE);
	module->createimage_optspec         = imgtool_library_strdup_allow_null((const char*)imgtool_get_info_ptr(imgclass, IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC));
	module->image_extra_bytes           += imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES);
}
コード例 #5
0
imgtoolerr_t imgtool_floppy_createmodule(imgtool_library *library, const char *format_name,
	const char *description, const struct FloppyFormat *format,
	void (*getinfo)(UINT32 state, union imgtoolinfo *info))
{
	imgtoolerr_t err;
	struct ImageModule *module;
	int format_index;
	char buffer[512];
	struct ImgtoolFloppyExtra *extra;

	for (format_index = 0; format[format_index].construct; format_index++)
	{
		extra = imgtool_library_alloc(library, sizeof(*extra));
		if (!extra)
			return IMGTOOLERR_OUTOFMEMORY;
		memset(extra, 0, sizeof(*extra));
		extra->format = &format[format_index];

		snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%s_%s",
			format[format_index].name, format_name);

		err = imgtool_library_createmodule(library, buffer, &module);
		if (err)
			return err;

		snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%s (%s)",
			format[format_index].description, description);

		module->image_extra_bytes		= sizeof(struct imgtool_floppy_image);
		module->description				= imgtool_library_strdup(library, buffer);
		module->open					= imgtool_floppy_open;
		module->create					= imgtool_floppy_create;
		module->close					= imgtool_floppy_close;
		module->extensions				= format[format_index].extensions;
		module->extra					= extra;
		module->createimage_optguide	= format[format_index].param_guidelines ? floppy_option_guide : NULL;
		module->createimage_optspec		= format[format_index].param_guidelines;
		module->get_sector_size			= imgtool_floppy_get_sector_size;
		module->read_sector				= imgtool_floppy_read_sector;
		module->write_sector			= imgtool_floppy_write_sector;

		if (getinfo)
		{
			extra->create						= (imgtoolerr_t	(*)(imgtool_image *, imgtool_stream *, option_resolution *)) imgtool_get_info_ptr(getinfo, IMGTOOLINFO_PTR_CREATE);
			extra->open							= (imgtoolerr_t	(*)(imgtool_image *, imgtool_stream *)) imgtool_get_info_ptr(getinfo, IMGTOOLINFO_PTR_OPEN);
			module->eoln						= imgtool_library_strdup(library, imgtool_get_info_ptr(getinfo, IMGTOOLINFO_STR_EOLN));
			module->path_separator				= (char) imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_PATH_SEPARATOR);
			module->alternate_path_separator	= (char) imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_ALTERNATE_PATH_SEPARATOR);
			module->prefer_ucase				= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_PREFER_UCASE) ? 1 : 0;
			module->initial_path_separator		= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_INITIAL_PATH_SEPARATOR) ? 1 : 0;
			module->open_is_strict				= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_OPEN_IS_STRICT) ? 1 : 0;
			module->supports_creation_time		= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_SUPPORTS_CREATION_TIME) ? 1 : 0;
			module->supports_lastmodified_time	= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_SUPPORTS_LASTMODIFIED_TIME) ? 1 : 0;
			module->tracks_are_called_cylinders	= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_TRACKS_ARE_CALLED_CYLINDERS) ? 1 : 0;
			module->writing_untested			= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_WRITING_UNTESTED) ? 1 : 0;
			module->creation_untested			= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_CREATION_UNTESTED) ? 1 : 0;
			module->supports_bootblock			= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_SUPPORTS_BOOTBLOCK) ? 1 : 0;
			module->info						= (void (*)(imgtool_image *, char *, size_t)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_INFO);
			module->begin_enum					= (imgtoolerr_t (*)(imgtool_imageenum *, const char *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_BEGIN_ENUM);
			module->next_enum					= (imgtoolerr_t (*)(imgtool_imageenum *, imgtool_dirent *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_NEXT_ENUM);
			module->close_enum					= (void (*)(imgtool_imageenum *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_CLOSE_ENUM);
			module->free_space					= (imgtoolerr_t (*)(imgtool_image *, UINT64 *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_FREE_SPACE);
			module->read_file					= (imgtoolerr_t (*)(imgtool_image *, const char *, const char *, imgtool_stream *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_READ_FILE);
			module->write_file					= (imgtoolerr_t (*)(imgtool_image *, const char *, const char *, imgtool_stream *, option_resolution *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_WRITE_FILE);
			module->delete_file					= (imgtoolerr_t (*)(imgtool_image *, const char *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_DELETE_FILE);
			module->list_forks					= (imgtoolerr_t (*)(imgtool_image *, const char *, imgtool_forkent *, size_t)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_LIST_FORKS);
			module->create_dir					= (imgtoolerr_t (*)(imgtool_image *, const char *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_CREATE_DIR);
			module->delete_dir					= (imgtoolerr_t (*)(imgtool_image *, const char *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_DELETE_DIR);
			module->list_attrs					= (imgtoolerr_t (*)(imgtool_image *, const char *, UINT32 *, size_t)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_LIST_ATTRS);
			module->get_attrs					= (imgtoolerr_t (*)(imgtool_image *, const char *, const UINT32 *, imgtool_attribute *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_GET_ATTRS);
			module->set_attrs					= (imgtoolerr_t (*)(imgtool_image *, const char *, const UINT32 *, const imgtool_attribute *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_SET_ATTRS);
			module->attr_name					= (imgtoolerr_t (*)(UINT32, const imgtool_attribute *, char *, size_t)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_ATTR_NAME);
			module->get_iconinfo				= (imgtoolerr_t (*)(imgtool_image *, const char *, imgtool_iconinfo *)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_GET_ICON_INFO);
			module->suggest_transfer			= (imgtoolerr_t (*)(imgtool_image *, const char *, imgtool_transfer_suggestion *, size_t))  imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_SUGGEST_TRANSFER);
			module->get_chain					= (imgtoolerr_t (*)(imgtool_image *, const char *, imgtool_chainent *, size_t)) imgtool_get_info_fct(getinfo, IMGTOOLINFO_PTR_GET_CHAIN);
			module->writefile_optguide			= (const struct OptionGuide *) imgtool_get_info_ptr(getinfo, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE);
			module->writefile_optspec			= imgtool_library_strdup(library, imgtool_get_info_ptr(getinfo, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC));
			module->image_extra_bytes			+= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES);
			module->imageenum_extra_bytes		+= imgtool_get_info_int(getinfo, IMGTOOLINFO_INT_ENUM_EXTRA_BYTES);
		}
	}
	return IMGTOOLERR_SUCCESS;
}