diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-10 17:55:44 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-10 20:30:45 -0800 |
commit | 21f38190d3bf3f59ea70fe71bc109f438b49ab4c (patch) | |
tree | f63fd522a7be6b873cc0d198542f80a895ffc7df /main.c | |
parent | 868a2cc0905b719cb5f3eaf15f0550d6ce82dbeb (diff) | |
download | subsurface-21f38190d3bf3f59ea70fe71bc109f438b49ab4c.tar.gz |
Make the default preferences explicit
This makes it explicit what the default preferences are, so that we can
more easily avoid unnecessarily saving default settings. It also makes
imperial metrics the default for the US (Burma and Liberia always get
forgotten!)
Right now we tend to be somewhat confused about defaults. We do have
them, but then even if something has a default value, we tend to write
it out to the config file. Which is not just unnecessary, but makes it
really hard to see after-the-fact whether the user actually wanted that
*specific* value, or whether they just wanted the default behavior.
So this prepares for having explicit configuration for when we want
something different than the defaults.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 53 |
1 files changed, 51 insertions, 2 deletions
@@ -15,7 +15,24 @@ char *debugfilename; FILE *debugfile; #endif -struct units units; +struct preferences prefs; +struct preferences default_prefs = { + .units = SI_UNITS, + .visible_cols = { TRUE, FALSE, }, + .pp_graphs = { + .po2 = FALSE, + .pn2 = FALSE, + .phe = FALSE, + .po2_threshold = 1.6, + .pn2_threshold = 4.0, + .phe_threshold = 13.0, + }, + .profile_red_ceiling = FALSE, + .profile_calc_ceiling = FALSE, + .calc_ceiling_3m_incr = FALSE, + .gflow = 0.30, + .gfhigh = 0.75, +}; /* random helper functions, used here or elsewhere */ static int sortfn(const void *_a, const void *_b) @@ -239,6 +256,36 @@ void renumber_dives(int nr) mark_divelist_changed(TRUE); } +/* + * Under a POSIX setup, the locale string should have a format + * like [language[_territory][.codeset][@modifier]]. + * + * So search for the underscore, and see if the "territory" is + * US, and turn on imperial units by default. + * + * I guess Burma and Liberia should trigger this too. I'm too + * lazy to look up the territory names, though. + */ +static void setup_system_prefs(void) +{ + const char *env = getenv("LC_MEASUREMENT"); + + if (!env) + env = getenv("LC_ALL"); + if (!env) + env = getenv("LANG"); + if (!env) + return; + env = strchr(env, '_'); + if (!env) + return; + env++; + if (strncmp(env, "US", 2)) + return; + + default_prefs.units = IMPERIAL_units; +} + int main(int argc, char **argv) { int i; @@ -253,7 +300,9 @@ int main(int argc, char **argv) bindtextdomain("subsurface", path); bind_textdomain_codeset("subsurface", "utf-8"); textdomain("subsurface"); - units = SI_units; + + setup_system_prefs(); + prefs = default_prefs; #if DEBUGFILE > 1 debugfile = stderr; |