Esempio n. 1
0
File: main.c Progetto: dinkc64/mame
static int cmd_create(const struct command *c, int argc, char *argv[])
{
	imgtoolerr_t err;
	int unnamedargs;
	const imgtool_module *module;
	option_resolution *resolution = NULL;

	module = imgtool_find_module(argv[0]);
	if (!module)
	{
		err = (imgtoolerr_t)(IMGTOOLERR_MODULENOTFOUND | IMGTOOLERR_SRC_MODULE);
		goto error;
	}

	if (module->createimage_optguide && module->createimage_optspec)
	{
		resolution = option_resolution_create(module->createimage_optguide, module->createimage_optspec);
		if (!resolution)
		{
			err = IMGTOOLERR_OUTOFMEMORY;
			goto error;
		}
	}

	unnamedargs = parse_options(argc, argv, 2, 3, resolution, NULL, NULL);
	if (unnamedargs < 0)
		return -1;

	err = imgtool_image_create(module, argv[1], resolution, NULL);
	if (err)
		goto error;

	if (resolution)
		option_resolution_close(resolution);
	return 0;

error:
	if (resolution)
		option_resolution_close(resolution);
	reporterror(err, c, argv[0], argv[1], NULL, NULL, 0);
	return -1;
}
Esempio n. 2
0
floperr_t floppy_format_track(floppy_image *floppy, int head, int track, option_resolution *parameters)
{
    floperr_t err;
    struct FloppyCallbacks *format;
    option_resolution *alloc_resolution = NULL;
    optreserr_t oerr;

    /* supported? */
    format = floppy_callbacks(floppy);
    if (!format->format_track)
    {
        err = FLOPPY_ERROR_UNSUPPORTED;
        goto done;
    }

    /* create a dummy resolution; if no parameters were specified */
    if (!parameters)
    {
        alloc_resolution = option_resolution_create(floppy_option_guide, floppy->floppy_option->param_guidelines);
        if (!alloc_resolution)
        {
            err = FLOPPY_ERROR_OUTOFMEMORY;
            goto done;
        }
        parameters = alloc_resolution;
    }

    oerr = option_resolution_finish(parameters);
    if (oerr)
    {
        err = option_to_floppy_error(oerr);
        goto done;
    }

    err = format->format_track(floppy, head, track, parameters);
    if (err)
        goto done;

done:
    if (alloc_resolution)
        option_resolution_close(alloc_resolution);
    return err;
}
Esempio n. 3
0
imgtoolerr_t win_show_option_dialog(HWND parent, struct transfer_suggestion_info *suggestion_info,
	const struct OptionGuide *guide, const char *optspec,
	option_resolution **result, BOOL *cancel)
{
	imgtoolerr_t err = IMGTOOLERR_SUCCESS;
	option_resolution *res = NULL;
	struct putfileopt_info pfo_info;
	int rc;

	*cancel = FALSE;

	if (guide)
	{
		res = option_resolution_create(guide, optspec);
		if (!res)
		{
			err = IMGTOOLERR_OUTOFMEMORY;
			goto done;
		}
	}

	pfo_info.resolution = res;
	pfo_info.guide = guide;
	pfo_info.optspec = optspec;
	pfo_info.suggestion_info = suggestion_info;
	rc = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_FILEOPTIONS), parent,
		putfileopt_dialogproc, (LPARAM) &pfo_info);
	*cancel = (rc == IDCANCEL);

done:
	if (err && res)
	{
		option_resolution_close(res);
		res = NULL;
	}
	*result = res;
	return err;
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
static void node_createimage(struct imgtooltest_state *state, xml_data_node *node)
{
	imgtoolerr_t err;
	xml_data_node *child_node;
	xml_attribute_node *attr_node;
	option_resolution *opts = NULL;
	const imgtool_module *module;
	const char *driver;
	const char *param_name;
	const char *param_value;

	attr_node = xml_get_attribute(node, "driver");
	if (!attr_node)
	{
		error_missingattribute("driver");
		return;
	}
	driver = attr_node->value;

	/* does image creation support options? */
	module = imgtool_find_module(attr_node->value);
	if (module && module->createimage_optguide && module->createimage_optspec)
		opts = option_resolution_create(module->createimage_optguide, module->createimage_optspec);

	report_message(MSG_INFO, "Creating image (module '%s')", driver);

	for (child_node = xml_get_sibling(node->child, "param"); child_node; child_node = xml_get_sibling(child_node->next, "param"))
	{
		if (!opts)
		{
			report_message(MSG_FAILURE, "Cannot specify creation options with this module");
			return;
		}

		attr_node = xml_get_attribute(child_node, "name");
		if (!attr_node)
		{
			error_missingattribute("name");
			return;
		}
		param_name = attr_node->value;

		attr_node = xml_get_attribute(child_node, "value");
		if (!attr_node)
		{
			error_missingattribute("value");
			return;
		}
		param_value = attr_node->value;

		option_resolution_add_param(opts, param_name, param_value);
	}

	err = imgtool_image_create_byname(driver, tempfile_name(), opts, &state->m_image);
	if (opts)
	{
		option_resolution_close(opts);
		opts = NULL;
	}
	if (err)
	{
		state->m_failed = 1;
		report_imgtoolerr(err);
		return;
	}

	err = imgtool_partition_open(state->m_image, 0, &state->m_partition);
	if (err)
	{
		state->m_failed = 1;
		report_imgtoolerr(err);
		return;
	}
}
Esempio n. 6
0
File: main.c Progetto: dinkc64/mame
static int cmd_put(const struct command *c, int argc, char *argv[])
{
	imgtoolerr_t err = IMGTOOLERR_SUCCESS;
	int i;
	imgtool_image *image = NULL;
	imgtool_partition *partition = NULL;
	const char *filename = NULL;
	int unnamedargs;
	filter_getinfoproc filter;
	const imgtool_module *module;
	option_resolution *resolution = NULL;
	const char *fork;
	const char *new_filename;
	char **filename_list;
	int filename_count;
	int partition_index = 0;
	const option_guide *writefile_optguide;
	const char *writefile_optspec;

	module = imgtool_find_module(argv[0]);
	if (!module)
	{
		err = (imgtoolerr_t)(IMGTOOLERR_MODULENOTFOUND | IMGTOOLERR_SRC_MODULE);
		goto done;
	}

	/* ugh I hate the way this function is set up, this is because the
	 * arguments depend on the partition; something that requires some
	 * rudimentary parsing */
	if (argc >= 2)
	{
		/* open up the image */
		err = imgtool_image_open(module, argv[1], OSD_FOPEN_RW, &image);
		if (err)
			goto done;

		/* open up the partition */
		err = imgtool_partition_open(image, partition_index, &partition);
		if (err)
			goto done;

		writefile_optguide = (const option_guide *) imgtool_partition_get_info_ptr(partition, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE);
		writefile_optspec = (const char *)imgtool_partition_get_info_ptr(partition, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC);

		if (writefile_optguide && writefile_optspec)
		{
			resolution = option_resolution_create(writefile_optguide, writefile_optspec);
			if (!resolution)
			{
				err = IMGTOOLERR_OUTOFMEMORY;
				goto done;
			}
		}
	}

	unnamedargs = parse_options(argc, argv, 4, 0xffff, resolution, &filter, &fork);
	if (unnamedargs < 0)
		return -1;

	/* pick out which args are filenames, and which one is the destination */
	new_filename = interpret_filename(argv[unnamedargs - 1]);
	filename_list = &argv[2];
	filename_count = unnamedargs - 3;

	/* loop through the filenames, and put them */
	for (i = 0; i < filename_count; i++)
	{
		filename = filename_list[i];
		printf("Putting file '%s'...\n", filename);
		err = imgtool_partition_put_file(partition, new_filename, fork, filename, resolution, filter);
		if (err)
			goto done;
	}

done:
	if (partition)
		imgtool_partition_close(partition);
	if (image)
		imgtool_image_close(image);
	if (resolution)
		option_resolution_close(resolution);
	if (err)
		reporterror(err, c, argv[0], argv[1], filename, NULL, resolution);
	return err ? -1 : 0;
}
Esempio n. 7
0
floperr_t floppy_create(void *fp, const struct io_procs *procs, const struct FloppyFormat *format, option_resolution *parameters, floppy_image **outfloppy)
{
    floppy_image *floppy = NULL;
    optreserr_t oerr;
    floperr_t err;
    int heads, tracks, h, t;
    option_resolution *alloc_resolution = NULL;

    assert(format);

    /* create the new image */
    floppy = floppy_init(fp, procs, 0);
    if (!floppy)
    {
        err = FLOPPY_ERROR_OUTOFMEMORY;
        goto done;
    }

    /* if this format expects creation parameters and none were specified, create some */
    if (!parameters && floppy_option_guide && format->param_guidelines)
    {
        alloc_resolution = option_resolution_create(floppy_option_guide, format->param_guidelines);
        if (!alloc_resolution)
        {
            err = FLOPPY_ERROR_OUTOFMEMORY;
            goto done;
        }
        parameters = alloc_resolution;
    }

    /* finish the parameters, if specified */
    if (parameters)
    {
        oerr = option_resolution_finish(parameters);
        if (oerr)
        {
            err = option_to_floppy_error(oerr);
            goto done;
        }
    }

    /* call the format constructor */
    err = format->construct(floppy, format, parameters);
    if (err)
        goto done;

    /* format the disk, ignoring if formatting not implemented */
    if (floppy->format.format_track)
    {
        heads = floppy_get_heads_per_disk(floppy);
        tracks = floppy_get_tracks_per_disk(floppy);

        for (h = 0; h < heads; h++)
        {
            for (t = 0; t < tracks; t++)
            {
                err = floppy->format.format_track(floppy, h, t, parameters);
                if (err)
                    goto done;
            }
        }
    }

    /* call the post_format function, if present */
    if (floppy->format.post_format)
    {
        err = floppy->format.post_format(floppy, parameters);
        if (err)
            goto done;
    }

    floppy->floppy_option = format;
    err = FLOPPY_ERROR_SUCCESS;

done:
    if (err && floppy)
    {
        floppy_close_internal(floppy, FALSE);
        floppy = NULL;
    }

    if (outfloppy)
        *outfloppy = floppy;
    else if (floppy)
        floppy_close_internal(floppy, FALSE);

    if (alloc_resolution)
        option_resolution_close(alloc_resolution);
    return err;
}