本文整理汇总了C++中astring::catprintf方法的典型用法代码示例。如果您正苦于以下问题:C++ astring::catprintf方法的具体用法?C++ astring::catprintf怎么用?C++ astring::catprintf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astring
的用法示例。
在下文中一共展示了astring::catprintf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_ini_file
bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_priority, astring &error_string)
{
// loop over lines in the file
char buffer[4096];
while (core_fgets(buffer, ARRAY_LENGTH(buffer), &inifile) != NULL)
{
// find the extent of the name
char *optionname;
for (optionname = buffer; *optionname != 0; optionname++)
if (!isspace((UINT8)*optionname))
break;
// skip comments
if (*optionname == 0 || *optionname == '#')
continue;
// scan forward to find the first space
char *temp;
for (temp = optionname; *temp != 0; temp++)
if (isspace((UINT8)*temp))
break;
// if we hit the end early, print a warning and continue
if (*temp == 0)
{
error_string.catprintf("Warning: invalid line in INI: %s", buffer);
continue;
}
// NULL-terminate
*temp++ = 0;
char *optiondata = temp;
// scan the data, stopping when we hit a comment
bool inquotes = false;
for (temp = optiondata; *temp != 0; temp++)
{
if (*temp == '"')
inquotes = !inquotes;
if (*temp == '#' && !inquotes)
break;
}
*temp = 0;
// find our entry
entry *curentry = m_entrymap.find(optionname);
if (curentry == NULL)
{
if (priority >= ignore_priority)
error_string.catprintf("Warning: unknown option in INI: %s\n", optionname);
continue;
}
// set the new data
validate_and_set_data(*curentry, optiondata, priority, error_string);
}
return true;
}
示例2: parse_command_line
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;
}
示例3: image_info_astring
void ui_menu_image_info::image_info_astring(running_machine &machine, astring &string)
{
string.printf("%s\n\n", machine.system().description);
#if 0
if (mess_ram_size > 0)
{
char buf2[RAM_STRING_BUFLEN];
string.catprintf("RAM: %s\n\n", ram_string(buf2, mess_ram_size));
}
#endif
image_interface_iterator iter(machine.root_device());
for (device_image_interface *image = iter.first(); image != NULL; image = iter.next())
{
const char *name = image->filename();
if (name != NULL)
{
const char *base_filename;
const char *info;
char *base_filename_noextension;
base_filename = image->basename();
base_filename_noextension = strip_extension(base_filename);
// display device type and filename
string.catprintf("%s: %s\n", image->device().name(), base_filename);
// display long filename, if present and doesn't correspond to name
info = image->longname();
if (info && (!base_filename_noextension || core_stricmp(info, base_filename_noextension)))
string.catprintf("%s\n", info);
// display manufacturer, if available
info = image->manufacturer();
if (info != NULL)
{
string.catprintf("%s", info);
info = stripspace(image->year());
if (info && *info)
string.catprintf(", %s", info);
string.catprintf("\n");
}
// display supported information, if available
switch(image->supported()) {
case SOFTWARE_SUPPORTED_NO : string.catprintf("Not supported\n"); break;
case SOFTWARE_SUPPORTED_PARTIAL : string.catprintf("Partially supported\n"); break;
default : break;
}
if (base_filename_noextension != NULL)
free(base_filename_noextension);
}
else
{
string.catprintf("%s: ---\n", image->device().name());
}
}
}
示例4: pad_astring_to_length
void debug_view_breakpoints::pad_astring_to_length(astring& str, int len)
{
int diff = len - str.len();
if (diff > 0)
{
astring buffer;
buffer.expand(diff);
for (int i = 0; i < diff; i++)
buffer.catprintf(" ");
str.catprintf("%s", buffer.cstr());
}
}
示例5: set_value
bool core_options::set_value(const char *name, const char *value, int priority, astring &error_string)
{
// find the entry first
entry *curentry = m_entrymap.find(name);
if (curentry == NULL)
{
error_string.catprintf("Attempted to set unknown option %s\n", name);
return false;
}
// validate and set the item normally
return validate_and_set_data(*curentry, value, priority, error_string);
}
示例6: validate_and_set_data
bool core_options::validate_and_set_data(core_options::entry &curentry, const char *newdata, int priority, astring &error_string)
{
// trim any whitespace
astring data(newdata);
data.trimspace();
// trim quotes
if (data.chr(0, '"') == 0 && data.rchr(0, '"') == data.len() - 1)
{
data.del(0, 1);
data.del(data.len() - 1, 1);
}
// validate the type of data and optionally the range
float fval;
int ival;
switch (curentry.type())
{
// booleans must be 0 or 1
case OPTION_BOOLEAN:
if (sscanf(data, "%d", &ival) != 1 || ival < 0 || ival > 1)
{
error_string.catprintf("Illegal boolean value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.cstr(), curentry.value());
return false;
}
break;
// integers must be integral
case OPTION_INTEGER:
if (sscanf(data, "%d", &ival) != 1)
{
error_string.catprintf("Illegal integer value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.cstr(), curentry.value());
return false;
}
if (curentry.has_range() && (ival < atoi(curentry.minimum()) || ival > atoi(curentry.maximum())))
{
error_string.catprintf("Out-of-range integer value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.cstr(), curentry.minimum(), curentry.maximum(), curentry.value());
return false;
}
break;
// floating-point values must be numeric
case OPTION_FLOAT:
if (sscanf(data, "%f", &fval) != 1)
{
error_string.catprintf("Illegal float value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.cstr(), curentry.value());
return false;
}
if (curentry.has_range() && (fval < atof(curentry.minimum()) || fval > atof(curentry.maximum())))
{
error_string.catprintf("Out-of-range float value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.cstr(), curentry.minimum(), curentry.maximum(), curentry.value());
return false;
}
break;
// strings can be anything
case OPTION_STRING:
break;
// anything else is invalid
case OPTION_INVALID:
case OPTION_HEADER:
default:
error_string.catprintf("Attempted to set invalid option %s\n", curentry.name());
return false;
}
// set the data
curentry.set_value(data, priority);
return true;
}