summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/options.c
diff options
context:
space:
mode:
author Michaël Banaan Ananas <happppp@users.noreply.github.com>2011-08-22 16:04:36 +0000
committer Michaël Banaan Ananas <happppp@users.noreply.github.com>2011-08-22 16:04:36 +0000
commitff95e0a898a04f70e66ae88c7586a2edc0249369 (patch)
tree05c4904fb24be005180152b9a435b03717b6db55 /src/lib/util/options.c
parent80ccc62d18d0d52d0eb7570f0e61fed817dfb6be (diff)
ini file write: skip those <UNADORNED..> options, and don't start the file with a newline
Diffstat (limited to 'src/lib/util/options.c')
-rw-r--r--src/lib/util/options.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/lib/util/options.c b/src/lib/util/options.c
index 9e7dbaeed08..ed1a62a6f6c 100644
--- a/src/lib/util/options.c
+++ b/src/lib/util/options.c
@@ -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
buffer.reset();
- // loop over all items
+ int num_valid_headers = 0;
+ int unadorned_index = 0;
const char *last_header = NULL;
+
+ // loop over all items
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
if (curentry->is_header())
last_header = curentry->description();
@@ -496,22 +510,25 @@ const char *core_options::output_ini(astring &buffer, const core_options *diff)
else if (!curentry->is_command())
{
// 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)
{
// output header, if we have one
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;
}
- // and finally output the data
- if (strchr(value, ' ') != NULL)
- buffer.catprintf("%-25s \"%s\"\n", name, value);
- else
- buffer.catprintf("%-25s %s\n", name, value);
+ // and finally output the data, skip if unadorned
+ if (!is_unadorned)
+ {
+ if (strchr(value, ' ') != NULL)
+ buffer.catprintf("%-25s \"%s\"\n", name, value);
+ else
+ buffer.catprintf("%-25s %s\n", name, value);
+ }
}
}
}