Example #1
0
void device_image_interface::software_name_split(const char *swlist_swname, astring &swlist_name, astring &swname, astring &swpart)
{
	// reset all output parameters
	swlist_name.reset();
	swname.reset();
	swpart.reset();

	// if no colon, this is the swname by itself
	const char *split1 = strchr(swlist_swname, ':');
	if (split1 == NULL)
	{
		swname.cpy(swlist_swname);
		return;
	}

	// if one colon, it is the swname and swpart alone
	const char *split2 = strchr(split1 + 1, ':');
	if (split2 == NULL)
	{
		swname.cpy(swlist_swname, split1 - swlist_swname);
		swpart.cpy(split1 + 1);
		return;
	}

	// if two colons present, split into 3 parts
	swlist_name.cpy(swlist_swname, split1 - swlist_swname);
	swname.cpy(split1 + 1, split2 - (split1 + 1));
	swpart.cpy(split2 + 1);
}
Example #2
0
bool core_options::parse_command_line(int argc, char **argv, int priority, astring &error_string)
{
	// reset the errors and the command
	error_string.reset();
	m_command.reset();

	// iterate through arguments
	int unadorned_index = 0;
	bool retVal = true;
	for (int arg = 1; arg < argc; arg++)
	{
		// determine the entry name to search for
		const char *curarg = argv[arg];
		bool is_unadorned = (curarg[0] != '-');
		const char *optionname = is_unadorned ? core_options::unadorned(unadorned_index++) : &curarg[1];

		// find our entry; if not found, indicate invalid option
		entry *curentry = m_entrymap.find(optionname);
		if (curentry == NULL)
		{
			error_string.catprintf("Error: unknown option: %s\n", curarg);
			retVal = false;
			if (!is_unadorned) arg++;
			continue;
		}

		// process commands first
		if (curentry->type() == OPTION_COMMAND)
		{
			// can only have one command
			if (m_command)
			{
				error_string.catprintf("Error: multiple commands specified -%s and %s\n", m_command.cstr(), curarg);
				return false;
			}
			m_command = curentry->name();
			continue;
		}

		// get the data for this argument, special casing booleans
		const char *newdata;
		if (curentry->type() == OPTION_BOOLEAN)
			newdata = (strncmp(&curarg[1], "no", 2) == 0) ? "0" : "1";
		else if (is_unadorned)
			newdata = curarg;
		else if (arg + 1 < argc)
			newdata = argv[++arg];
		else
		{
			error_string.catprintf("Error: option %s expected a parameter\n", curarg);
			return false;
		}

		// set the new data
		validate_and_set_data(*curentry, newdata, priority, error_string);
	}
	return retVal;
}
Example #3
0
void emu_options::parse_standard_inis(astring &error_string)
{
	// start with an empty string
	error_string.reset();

	// parse the INI file defined by the platform (e.g., "mame.ini")
	// we do this twice so that the first file can change the INI path
	parse_one_ini(emulator_info::get_configname(), OPTION_PRIORITY_MAME_INI);
	parse_one_ini(emulator_info::get_configname(), OPTION_PRIORITY_MAME_INI, &error_string);

	// debug mode: parse "debug.ini" as well
	if (debug())
		parse_one_ini("debug", OPTION_PRIORITY_DEBUG_INI, &error_string);

	// if we have a valid system driver, parse system-specific INI files
	const game_driver *cursystem = system();
	if (cursystem == NULL)
		return;

	// parse "vertical.ini" or "horizont.ini"
	if (cursystem->flags & ORIENTATION_SWAP_XY)
		parse_one_ini("vertical", OPTION_PRIORITY_ORIENTATION_INI, &error_string);
	else
		parse_one_ini("horizont", OPTION_PRIORITY_ORIENTATION_INI, &error_string);

	// parse "vector.ini" for vector games
	{
		machine_config config(*cursystem, *this);
		screen_device_iterator iter(config.root_device());
		for (const screen_device *device = iter.first(); device != NULL; device = iter.next())
			if (device->screen_type() == SCREEN_TYPE_VECTOR)
			{
				parse_one_ini("vector", OPTION_PRIORITY_VECTOR_INI, &error_string);
				break;
			}
	}

	// next parse "source/<sourcefile>.ini"; if that doesn't exist, try <sourcefile>.ini
	astring sourcename;
	core_filename_extract_base(sourcename, cursystem->source_file, true).ins(0, "source" PATH_SEPARATOR);
	if (!parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string))
	{
		core_filename_extract_base(sourcename, cursystem->source_file, true);
		parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string);
	}

	// then parse the grandparent, parent, and system-specific INIs
	int parent = driver_list::clone(*cursystem);
	int gparent = (parent != -1) ? driver_list::clone(parent) : -1;
	if (gparent != -1)
		parse_one_ini(driver_list::driver(gparent).name, OPTION_PRIORITY_GPARENT_INI, &error_string);
	if (parent != -1)
		parse_one_ini(driver_list::driver(parent).name, OPTION_PRIORITY_PARENT_INI, &error_string);
	parse_one_ini(cursystem->name, OPTION_PRIORITY_DRIVER_INI, &error_string);

	// Re-evaluate slot options after loading ini files
	update_slot_options();
}
Example #4
0
void device_image_interface::software_get_default_slot(astring &result, const char *default_card_slot)
{
	const char *path = device().mconfig().options().value(instance_name());
	result.reset();
	if (strlen(path) > 0)
	{
		result.cpy(default_card_slot);
		software_part *swpart = find_software_item(path, true);
		if (swpart != NULL)
		{
			const char *slot = swpart->feature("slot");
			if (slot != NULL)
				result.cpy(slot);
		}
	}
}
Example #5
0
void cbm_crt_get_card(astring &result, core_file *file)
{
	// read the header
	cbm_crt_header header;
	core_fread(file, &header, CRT_HEADER_LENGTH);

	if (memcmp(header.signature, CRT_SIGNATURE, 16) == 0)
	{
		UINT16 hardware = pick_integer_be(header.hardware, 0, 2);

		result.cpy(CRT_C64_SLOT_NAMES[hardware]);
		return;
	}

	result.reset();
}
Example #6
0
void cheat_entry::menu_text(astring &description, astring &state, UINT32 &flags)
{
	// description is standard
	description.cpy(m_description);
	state.reset();
	flags = 0;

	// some cheat entries are just text for display
	if (is_text_only())
	{
		if (description)
		{
			description.trimspace();
			if (!description)
				description.cpy(MENU_SEPARATOR_ITEM);
		}
		flags = MENU_FLAG_DISABLE;
	}

	// if we have no parameter and no run or off script, it's a oneshot cheat
	else if (is_oneshot())
		state.cpy("Set");

	// if we have no parameter, it's just on/off
	else if (is_onoff())
	{
		state.cpy((m_state == SCRIPT_STATE_RUN) ? "On" : "Off");
		flags = (m_state != 0) ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW;
	}

	// if we have a value parameter, compute it
	else if (m_parameter != NULL)
	{
		if (m_state == SCRIPT_STATE_OFF)
		{
			state.cpy(is_oneshot_parameter() ? "Set" : "Off");
			flags = MENU_FLAG_RIGHT_ARROW;
		}
		else
		{
			state.cpy(m_parameter->text());
			flags = MENU_FLAG_LEFT_ARROW;
			if (!m_parameter->is_maximum())
				flags |= MENU_FLAG_RIGHT_ARROW;
		}
	}
}
Example #7
0
static file_error zippath_resolve(const char *path, osd_dir_entry_type &entry_type, zip_file *&zipfile, astring &newpath)
{
	file_error err;
	osd_directory_entry *current_entry = NULL;
	osd_dir_entry_type current_entry_type;
	int went_up = FALSE;
	int i;

	newpath.reset();

	/* be conservative */
	entry_type = ENTTYPE_NONE;
	zipfile = NULL;

	astring apath(path);
	astring apath_trimmed;
	do
	{
		/* trim the path of trailing path separators */
		i = apath.len();
		while (i > 1 && is_path_separator(apath[i - 1]))
			i--;
		apath_trimmed.cpysubstr(apath, 0, i);

		/* stat the path */
		current_entry = osd_stat(apath_trimmed);

		/* did we find anything? */
		if (current_entry != NULL)
		{
			/* get the entry type and free the stat entry */
			current_entry_type = current_entry->type;
			osd_free(current_entry);
			current_entry = NULL;
		}
		else
		{
			/* if we have not found the file or directory, go up */
			current_entry_type = ENTTYPE_NONE;
			went_up = TRUE;
			astring parent;
			apath.cpy(zippath_parent(parent, apath));
		}
	}
	while (current_entry_type == ENTTYPE_NONE && !is_root(apath));

	/* if we did not find anything, then error out */
	if (current_entry_type == ENTTYPE_NONE)
	{
		err = FILERR_NOT_FOUND;
		goto done;
	}

	/* is this file a ZIP file? */
	if ((current_entry_type == ENTTYPE_FILE) && is_zip_file(apath_trimmed)
		&& (zip_file_open(apath_trimmed, &zipfile) == ZIPERR_NONE))
	{
		i = strlen(path + apath.len());
		while (i > 0 && is_zip_path_separator(path[apath.len() + i - 1]))
			i--;
		newpath.cpy(path + apath.len(), i);

		/* this was a true ZIP path - attempt to identify the type of path */
		zippath_find_sub_path(zipfile, newpath, &current_entry_type);
		if (current_entry_type == ENTTYPE_NONE)
		{
			err = FILERR_NOT_FOUND;
			goto done;
		}
	}
	else
	{
		/* this was a normal path */
		if (went_up)
		{
			err = FILERR_NOT_FOUND;
			goto done;
		}
		newpath.cpy(path);
	}

	/* success! */
	entry_type = current_entry_type;
	err = FILERR_NONE;

done:
	return err;
}
Example #8
0
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, astring &revised_path)
{
	file_error filerr = FILERR_NOT_FOUND;
	zip_error ziperr;
	zip_file *zip = NULL;
	const zip_file_header *header;
	osd_dir_entry_type entry_type;
	char *alloc_fullpath = NULL;
	int len;

	/* first, set up the two types of paths */
	astring mainpath(filename);
	astring subpath;
	file = NULL;

	/* loop through */
	while((file == NULL) && (mainpath.len() > 0)
		&& ((openflags == OPEN_FLAG_READ) || (subpath.len() == 0)))
	{
		/* is the mainpath a ZIP path? */
		if (is_zip_file(mainpath))
		{
			/* this file might be a zip file - lets take a look */
			ziperr = zip_file_open(mainpath, &zip);
			if (ziperr == ZIPERR_NONE)
			{
				/* it is a zip file - error if we're not opening for reading */
				if (openflags != OPEN_FLAG_READ)
				{
					filerr = FILERR_ACCESS_DENIED;
					goto done;
				}

				if (subpath.len() > 0)
					header = zippath_find_sub_path(zip, subpath, &entry_type);
				else
					header = zip_file_first_file(zip);

				if (header == NULL)
				{
					filerr = FILERR_NOT_FOUND;
					goto done;
				}

				/* attempt to read the file */
				filerr = create_core_file_from_zip(zip, header, file);
				if (filerr != FILERR_NONE)
					goto done;

				/* update subpath, if appropriate */
				if (subpath.len() == 0)
					subpath.cpy(header->filename);

				/* we're done */
				goto done;
			}
		}
		else if (is_7z_file(mainpath))
		{
			filerr = FILERR_INVALID_DATA;
			goto done;
		}

		if (subpath.len() == 0)
			filerr = core_fopen(filename, openflags, &file);
		else
			filerr = FILERR_NOT_FOUND;

		/* if we errored, then go up a directory */
		if (filerr != FILERR_NONE)
		{
			/* go up a directory */
			astring temp;
			zippath_parent(temp, mainpath);

			/* append to the sub path */
			if (subpath.len() > 0)
			{
				astring temp2;
				temp2.cpysubstr(mainpath, temp.len()).cat(PATH_SEPARATOR).cat(subpath);
				subpath.cpy(temp2);
			}
			else
				subpath.cpysubstr(mainpath, temp.len());

			/* get the new main path, truncating path separators */
			len = temp.len();
			while (len > 0 && is_zip_file_separator(temp[len - 1]))
				len--;
			mainpath.cpysubstr(temp, 0, len);
		}
	}

done:
	/* store the revised path */
	revised_path.reset();
	if (filerr == FILERR_NONE)
	{
		/* cannonicalize mainpath */
		filerr = osd_get_full_path(&alloc_fullpath, mainpath);
		if (filerr == FILERR_NONE)
		{
			if (subpath.len() > 0)
				revised_path.cpy(alloc_fullpath).cat(PATH_SEPARATOR).cat(subpath);
			else
				revised_path.cpy(alloc_fullpath);
		}
	}

	if (zip != NULL)
		zip_file_close(zip);
	if (alloc_fullpath != NULL)
		osd_free(alloc_fullpath);
	return filerr;
}