ini file write: skip those <UNADORNED..> options, and don't start the file with a newline

This commit is contained in:
Michaël Banaan Ananas 2011-08-22 16:04:36 +00:00
parent 80ccc62d18
commit ff95e0a898

View File

@ -484,10 +484,24 @@ const char *core_options::output_ini(astring &buffer, const core_options *diff)
// INI files are complete, so always start with a blank buffer // INI files are complete, so always start with a blank buffer
buffer.reset(); buffer.reset();
// loop over all items int num_valid_headers = 0;
int unadorned_index = 0;
const char *last_header = NULL; const char *last_header = NULL;
// loop over all items
for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next())
{ {
const char *name = curentry->name();
const char *value = curentry->value();
bool is_unadorned = false;
// check if it's unadorned
if (name && strlen(name) && !strcmp(name, core_options::unadorned(unadorned_index)))
{
unadorned_index++;
is_unadorned = true;
}
// header: record description // header: record description
if (curentry->is_header()) if (curentry->is_header())
last_header = curentry->description(); last_header = curentry->description();
@ -496,18 +510,20 @@ const char *core_options::output_ini(astring &buffer, const core_options *diff)
else if (!curentry->is_command()) else if (!curentry->is_command())
{ {
// look up counterpart in diff, if diff is specified // look up counterpart in diff, if diff is specified
const char *name = curentry->name();
const char *value = curentry->value();
if (diff == NULL || strcmp(value, diff->value(name)) != 0) if (diff == NULL || strcmp(value, diff->value(name)) != 0)
{ {
// output header, if we have one // output header, if we have one
if (last_header != NULL) if (last_header != NULL)
{ {
buffer.catprintf("\n#\n# %s\n#\n", last_header); if (num_valid_headers++)
buffer.catprintf("\n");
buffer.catprintf("#\n# %s\n#\n", last_header);
last_header = NULL; last_header = NULL;
} }
// and finally output the data // and finally output the data, skip if unadorned
if (!is_unadorned)
{
if (strchr(value, ' ') != NULL) if (strchr(value, ' ') != NULL)
buffer.catprintf("%-25s \"%s\"\n", name, value); buffer.catprintf("%-25s \"%s\"\n", name, value);
else else
@ -515,6 +531,7 @@ const char *core_options::output_ini(astring &buffer, const core_options *diff)
} }
} }
} }
}
return buffer; return buffer;
} }