Esempio n. 1
0
File: main.c Progetto: dinkc64/mame
static int cmd_getall(const struct command *c, int argc, char *argv[])
{
	imgtoolerr_t err;
	imgtool_image *image = NULL;
	imgtool_partition *partition = NULL;
	imgtool_directory *imgenum = NULL;
	imgtool_dirent ent;
	filter_getinfoproc filter;
	int unnamedargs;
	const char *path = NULL;
	int arg;
	int partition_index = 0;

	err = imgtool_image_open_byname(argv[0], argv[1], OSD_FOPEN_READ, &image);
	if (err)
		goto done;

	err = imgtool_partition_open(image, partition_index, &partition);
	if (err)
		goto done;

	arg = 2;
	if ((argc > 2) && (argv[2][0] != '-'))
	{
		path = argv[arg++];
	}

	unnamedargs = parse_options(argc, argv, arg, arg, NULL, &filter, NULL);
	if (unnamedargs < 0)
		goto done;

	err = imgtool_directory_open(partition, path, &imgenum);
	if (err)
		goto done;

	memset(&ent, 0, sizeof(ent));

	while (((err = imgtool_directory_get_next(imgenum, &ent)) == 0) && !ent.eof)
	{
		fprintf(stdout, "Retrieving %s (%u bytes)\n", ent.filename, (unsigned int) ent.filesize);

		err = imgtool_partition_get_file(partition, ent.filename, NULL, NULL, filter);
		if (err)
			goto done;
	}

done:
	if (imgenum)
		imgtool_directory_close(imgenum);
	if (partition)
		imgtool_partition_close(partition);
	if (image)
		imgtool_image_close(image);
	if (err)
		reporterror(err, c, argv[0], argv[1], NULL, NULL, NULL);
	return err ? -1 : 0;
}
Esempio n. 2
0
static void node_checkdirectory(struct imgtooltest_state *state, xml_data_node *node)
{
	imgtoolerr_t err = IMGTOOLERR_SUCCESS;
	imgtool_directory *imageenum;
	imgtool_dirent ent;
	char expected_listing[1024];
	char actual_listing[1024];
	int i/*, actual_count*/;
	int mismatch;
	xml_attribute_node *attr_node;
	xml_data_node *child_node;
	const char *filename;
	expected_dirent *entry;
	expected_dirent entries[256];
	int entry_count;

	if (!state->m_partition)
	{
		state->m_failed = 1;
		report_message(MSG_FAILURE, "Partition not loaded");
		return;
	}

	attr_node = xml_get_attribute(node, "path");
	filename = attr_node ? attr_node->value : "";

	memset(&entries, 0, sizeof(entries));
	entry_count = 0;

	for (child_node = xml_get_sibling(node->child, "entry"); child_node; child_node = xml_get_sibling(child_node->next, "entry"))
	{
		if (entry_count >= ARRAY_LENGTH(entries))
		{
			report_message(MSG_FAILURE, "Too many directory entries");
			return;
		}

		entry = &entries[entry_count++];

		attr_node = xml_get_attribute(child_node, "name");
		entry->filename = attr_node ? attr_node->value : NULL;

		attr_node = xml_get_attribute(child_node, "size");
		entry->size = attr_node ? atoi(attr_node->value) : -1;
	}

	/* build expected listing string */
	expected_listing[0] = '\0';
	for (i = 0; i < entry_count; i++)
	{
		append_to_list(expected_listing,
			ARRAY_LENGTH(expected_listing),
			entries[i].filename);
	}

	/* now enumerate though listing */
	//actual_count = 0;
	actual_listing[0] = '\0';
	mismatch = FALSE;

	memset(&ent, 0, sizeof(ent));

	err = imgtool_directory_open(state->m_partition, filename, &imageenum);
	if (err)
		goto done;

	i = 0;
	do
	{
		err = imgtool_directory_get_next(imageenum, &ent);
		if (err)
			goto done;

		if (!ent.eof)
		{
			append_to_list(actual_listing,
				ARRAY_LENGTH(actual_listing),
				ent.filename);

			if (i < entry_count && (strcmp(ent.filename, entries[i].filename)))
				mismatch = TRUE;
			i++;
		}
	}
	while(!ent.eof);

	if (i != entry_count)
		mismatch = TRUE;

	if (mismatch)
	{
		state->m_failed = 1;
		report_message(MSG_FAILURE, "File listing mismatch: {%s} expected {%s}",
			actual_listing, expected_listing);
		goto done;
	}

done:
	if (imageenum)
		imgtool_directory_close(imageenum);
	if (err)
	{
		state->m_failed = 1;
		report_imgtoolerr(err);
	}
}
Esempio n. 3
0
File: main.c Progetto: dinkc64/mame
static int cmd_dir(const struct command *c, int argc, char *argv[])
{
	imgtoolerr_t err;
	int total_count, total_size, freespace_err;
	UINT64 freespace;
	imgtool_image *image = NULL;
	imgtool_partition *partition = NULL;
	imgtool_directory *imgenum = NULL;
	imgtool_dirent ent;
	char buf[512];
	char last_modified[19];
	const char *path;
	int partition_index = 0;

	/* attempt to open image */
	err = imgtool_image_open_byname(argv[0], argv[1], OSD_FOPEN_READ, &image);
	if (err)
		goto done;

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

	path = argc > 2 ? argv[2] : NULL;

	err = imgtool_directory_open(partition, path, &imgenum);
	if (err)
		goto done;

	memset(&ent, 0, sizeof(ent));
	last_modified[0] = '\0';
	total_count = 0;
	total_size = 0;

	fprintf(stdout, "Contents of %s:%s\n", argv[1], path ? path : "");

	imgtool_image_info(image, buf, sizeof(buf));
	if (buf[0])
		fprintf(stdout, "%s\n", buf);
	fprintf(stdout, "------------------------------  --------  ---------------  ------------------\n");

	while (((err = imgtool_directory_get_next(imgenum, &ent)) == 0) && !ent.eof)
	{
		if (ent.directory)
			snprintf(buf, sizeof(buf), "<DIR>");
		else
			snprintf(buf, sizeof(buf), "%u", (unsigned int) ent.filesize);

		if (ent.lastmodified_time != 0)
			strftime(last_modified, sizeof(last_modified), "%d-%b-%y %H:%M:%S",
				localtime(&ent.lastmodified_time));

		if (ent.hardlink)
			strcat(ent.filename, " <hl>");

		fprintf(stdout, "%-30s  %8s  %15s  %18s\n", ent.filename, buf, ent.attr, last_modified);

		if (ent.softlink && ent.softlink[0] != '\0')
			fprintf(stdout, "-> %s\n", ent.softlink);

		if (ent.comment && ent.comment[0] != '\0')
			fprintf(stdout, ": %s\n", ent.comment);

		total_count++;
		total_size += ent.filesize;

		memset(&ent, 0, sizeof(ent));
	}

	freespace_err = imgtool_partition_get_free_space(partition, &freespace);

	if (err)
		goto done;

	fprintf(stdout, "------------------------  ------ ---------------\n");
	fprintf(stdout, "%8i File(s)        %8i bytes\n", total_count, total_size);
	if (!freespace_err)
		fprintf(stdout, "                        %8u bytes free\n", (unsigned int) freespace);

done:
	if (imgenum)
		imgtool_directory_close(imgenum);
	if (partition)
		imgtool_partition_close(partition);
	if (image)
		imgtool_image_close(image);
	if (err)
		reporterror(err, c, argv[0], argv[1], NULL, NULL, NULL);
	return err ? -1 : 0;
}
Esempio n. 4
0
int cmd_testsuite(struct command *c, int argc, char *argv[])
{
	const char *testsuitefile;
	FILE *inifile;
	const imgtool_module *module = NULL;
	char buffer[1024];
	char buffer2[1024];
	char filename[1024];
	char *filename_base;
	size_t filename_len;
	char *s;
	char *s2;
	const char *directive;
	const char *directive_value;
	imgtool_image *img = NULL;
	imgtool_directory *imgenum;
	imgtool_dirent imgdirent;
	int err = -1, i;

	testsuitefile = argv[0];

	/* open the testsuite file */
	inifile = fopen(testsuitefile, "r");
	if (!inifile)
	{
		fprintf(stderr, "*** cannot open testsuite file '%s'\n", testsuitefile);
		goto error;
	}

	/* change to the current directory of the test suite */
	strncpyz(filename, testsuitefile, sizeof(filename));
	s = filename + strlen(filename) - 1;
	while((*s != '/') && (*s != '\\'))
		*(s--) = '\0';
	filename_base = s+1;
	filename_len = filename_base - filename;

	while(!feof(inifile))
	{
		buffer[0] = '\0';
		fgets(buffer, sizeof(buffer) / sizeof(buffer[0]), inifile);

		if (buffer[0] != '\0')
		{
			s = buffer + strlen(buffer) -1;
			while(isspace(*s))
				*(s--) = '\0';
		}
		s = buffer;
		while(isspace(*s))
			s++;

		if (*s == '[')
		{
			s2 = strchr(s, ']');
			if (!s2)
				goto syntaxerror;
			*s2 = '\0';
			module = findimagemodule(s+1);
			if (!module)
			{
				fprintf(stderr, "*** unrecognized imagemodule '%s'\n", s+1);
				goto error;
			}
			imgtool_test(module);
		}
		else if (isalpha(*s))
		{
			directive = s;
			while(isalpha(*s))
				s++;
			while(isspace(*s))
				*(s++) = '\0';

			if (*s != '=')
			{
				fprintf(stderr, "*** expected '='\n");
				goto error;
			}
			*(s++) = '\0';
			while(isspace(*s))
				s++;
			directive_value = s;

			if (!mame_stricmp(directive, "imagefile"))
			{
				/* imagefile directive */
				if (img)
					imgtool_image_close(img);
				strncpyz(filename_base, directive_value, filename_len);
				err = imgtool_image_open(module, filename, OSD_FOPEN_READ, &img);
				if (err)
					goto error;

				fprintf(stdout, "%s\n", filename);
			}
			else if (!mame_stricmp(directive, "files"))
			{
				/* files directive */
				if (!img)
					goto needimgmodule;
				err = imgtool_directory_open(img, &imgenum);
				if (err)
					goto error;

				memset(&imgdirent, 0, sizeof(imgdirent));
				imgdirent.fname = buffer2;
				imgdirent.fname_len = sizeof(buffer2);
				while(((err = imgtool_directory_get_next(imgenum, &imgdirent)) == 0) && imgdirent.fname[0])
				{
					i = strlen(buffer2);
					buffer2[i++] = ',';
					imgdirent.fname = &buffer2[i];
					imgdirent.fname_len = sizeof(buffer2) - i;
				}
				imgtool_directory_close(imgenum);
				if (err)
					goto error;
				i = strlen(buffer2);
				if (i > 0)
					buffer2[i-1] = '\0';

				if (strcmp(directive_value, buffer2))
				{
					fprintf(stderr, "*** expected files '%s', but instead got '%s'", directive_value, buffer2);
					goto error;
				}
			}
			else
			{
				fprintf(stderr, "*** unrecognized directive '%s'\n", directive);
				goto done;
			}
		}
	}
	err = 0;
	goto done;

needimgmodule:
	fprintf(stderr, "*** need [format] declaration before any directives\n");
	goto error;

syntaxerror:
	fprintf(stderr, "*** syntax error: %s\n", buffer);
	goto error;

error:
	if (err && (err != -1))
		reporterror(err, c, module ? module->name : NULL, filename, NULL, NULL, NULL);

done:
	if (inifile)
		fclose(inifile);
	if (img)
		imgtool_image_close(img);
	return err;
}