61 Commits

Author SHA1 Message Date
Lukas Fleischer
47ceb96e13 src/config.c: Add missing configuration variables
Append missing configuration variables to the end of our configuration
file instead of keeping them undefined.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:06:54 +01:00
Lukas Fleischer
8aba3be1e8 src/config.c: Revamp configuration file parsing
Reintroduce a map for configuration variable parsing. We use a different
approach this time: Each map entry contains

* a key,
* a callback that can be used to parse that variable,
* a callback that can be used to serialize that variable and
* a target buffer that the parsed value is written to/read from.

Commits 4f4891bdb88410ae04225f3d6acfa31d73a3901a and
6377582841118688aee13aff98c9216403582e45 show that we are pretty
undecided on using a map or not. However, now that we use parser and
serialization wrappers for every variable, having a central map makes
everything much cleaner. The runtimes of config_load() and config_save()
are slightly increased (by a constant factor). This will also allow us
for implementing proper detection of missing configuration variables in
the configuration file.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:06:49 +01:00
Lukas Fleischer
fcd2c69dd4 src/config.c: Add more parser/serialization wrappers
Add convenience parser/serialization wrappers for all configuration
variables that don't use the default config_parse_*() and
config_serialize_*() helpers yet. This is nothing but a dirty hack and
should be refactored later (e.g. by separating configuration variable
parsing and validation or by adding optional validation functions). It
makes it easier to switch to a more generic configuration parser,
though.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:05:45 +01:00
Lukas Fleischer
b03b5694bc src/config.c: Introduce config_parse_str()
Be consistent with other parser helpers and with config_serialize_str().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:02:22 +01:00
Lukas Fleischer
2ecfe91e04 src/config.c: Keep formatting and comments
Switch to using the new config_file_walk() helper in config_save() and
update existing configuration variables instead of blindly overwriting
the existing configuration file.

Note: This breaks configuration setting storage if one or more settings
are missing in the configuration file. We need to refactor our parser
and serialization routines another time before this can be implemented
properly, though.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:02:22 +01:00
Lukas Fleischer
18efc06ff4 src/config.c: Add serialization helper
Add config_serialize_conf() which can be used to serialize the value of
a configuration setting (counterpart to config_parse_conf()).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:02:20 +01:00
Lukas Fleischer
b105bf8fab src/config.c: Add junk callback to config_file_walk()
This can be used if we care about junk, such as empty lines and
comments. Currently unused since we skip these when parsing
configuration settings. This makes sense if we want to make slight
modifications to the configuration file without losing formatting and
comments, though.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-16 10:45:09 +01:00
Lukas Fleischer
4c5d6fe612 src/config.c: Make config file reading more flexible
This adds one level of abstraction to config_load() by splitting out the
actual reading routine and the variable setter into two separate
functions. config_file_walk() can be used to read the configuration
file, strip comments and pass every key/value pair to a callback.
config_load_cb() is the new callback used in config_load().

Rationale: It makes sense to reuse the key/value parser to allow for a
much saner config_save() routine that changes single values only instead
of rewriting (and overwriting) the whole configuration file every time.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-16 10:39:14 +01:00
Lukas Fleischer
a548660569 src/config.c: Drop support for legacy color schemes
We used different naming schemes in versions prior to 1.8. Given that
calcurse 1.8 has been released more than 4.5 years ago, remove the
legacy code that still handles these. Users upgrading from <1.8 to 3.0.0
might need to convert the appropriate config file variable manually.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-12 12:12:13 +01:00
Lukas Fleischer
4f4891bdb8 src/config.c: Remove map for configuration variables
This patch kind of reverts what we did in commit
6377582841118688aee13aff98c9216403582e45. We were a tad off-base there
since using a map doesn't improve maintainability, really. Using
strcmp() at a central location seems perfectly fine and doesn't have the
overhead of the map scanning algorithm.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 22:35:12 +01:00
Lukas Fleischer
093b28ac39 Extract config file handlers into a separate file
We used custom_load_conf() to load the configuration file and
io_save_conf() to save configuration. Move these functions, including
all helpers, to a central location.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 20:54:20 +01:00