compuphase / minIni

A small and portable INI file library with read/write support
http://www.compuphase.com/minini.htm
Other
382 stars 114 forks source link

Consider preserving comments when re-writing values? #19

Open erwin opened 3 years ago

erwin commented 3 years ago

I've been searching quite a bit for an easy to use C config file library that supports preserving comments.

If I have the following in my INI file.

[section:foo]
alpha=True ; comment preserved
beta=True  ; until the value changes

And then use minIni to change the value of beta:

  ini_puts("section:foo", "beta", "False", inifile2);

The comment on beta will be lost...

[section:foo]
alpha=True ; comment preserved
beta=False

Not every config value change will invalidate the meaning of the associated comment, and since minIni doesn't write comments, only the user should be writing comments... Would be very frustrating for the end user to loose some comments they thought were important when we rewrite config changes.

As a workaround, one idea that comes to mind is putting a prefix or a suffix or both on the subset of key values that your program will be re-writing, so that these values jump out to the user as odd in the config file and are less surprised when comments there disappear. The downside of this approach would be as your software evolves and a value goes from user only to program re-written with the same name, so not an ideal workaround.

Something like:

[section:foo]
normal_key = value ; description of normal key
$app_configured = other value ; maybe less surprising if this comment gets erased?