Parse <prefix>/etc/gnucash/environment and set environment variables based on the contents of that file. Read the comments in <prefix>/etc/gnucash/environment for more details.
104 GKeyFile *keyfile = g_key_file_new();
109 gboolean got_keyfile;
113 env_parm = gnc_path_get_prefix();
114 if (!g_setenv(
"GNC_HOME", env_parm, FALSE))
115 g_warning (
"Couldn't set/override environment variable GNC_HOME.");
117 env_parm = gnc_path_get_bindir();
118 if (!g_setenv(
"GNC_BIN", env_parm, FALSE))
119 g_warning (
"Couldn't set/override environment variable GNC_BIN.");
121 env_parm = gnc_path_get_pkglibdir();
122 if (!g_setenv(
"GNC_LIB", env_parm, FALSE))
123 g_warning (
"Couldn't set/override environment variable GNC_LIB.");
125 env_parm = gnc_path_get_pkgdatadir();
126 if (!g_setenv(
"GNC_DATA", env_parm, FALSE))
127 g_warning (
"Couldn't set/override environment variable GNC_DATA.");
129 env_parm = gnc_path_get_pkgsysconfdir();
130 if (!g_setenv(
"GNC_CONF", env_parm, FALSE))
131 g_warning (
"Couldn't set/override environment variable GNC_CONF.");
133 env_parm = gnc_path_get_libdir();
134 if (!g_setenv(
"SYS_LIB", env_parm, FALSE))
135 g_warning (
"Couldn't set/override environment variable SYS_LIB.");
138 config_path = gnc_path_get_pkgsysconfdir();
142 gchar *pathext = g_build_path(
";",
".", g_getenv(
"PATHEXT"),
144 g_setenv(
"PATHEXT", pathext, TRUE);
149 env_file = g_build_filename (config_path,
"environment", NULL);
150 got_keyfile = g_key_file_load_from_file (keyfile, env_file, G_KEY_FILE_NONE, &error);
151 g_free (config_path);
155 g_key_file_free(keyfile);
160 env_vars = g_key_file_get_keys(keyfile,
"Variables", ¶m_count, &error);
161 for ( i = 0; i < param_count; i++ )
166 gchar *new_val = NULL, *tmp_val;
169 val_list = g_key_file_get_string_list (keyfile,
"Variables",
170 env_vars[i], &val_count,
172 if ( val_count == 0 )
173 g_unsetenv (env_vars[i]);
177 tmp_val = g_strdup (
"x");
178 for ( j = 0; j < val_count; j++ )
180 gchar *expanded = environment_expand (val_list[j]);
181 if (expanded && strlen(expanded))
183 new_val = g_build_path (G_SEARCHPATH_SEPARATOR_S, tmp_val, expanded, NULL);
189 g_strfreev (val_list);
192 if (g_strcmp0 (tmp_val,
"x"))
193 new_val = g_strdup (tmp_val +
sizeof (G_SEARCHPATH_SEPARATOR_S));
196 if (!g_setenv (env_vars[i], new_val, TRUE))
197 g_warning (
"Couldn't properly override environment variable \"%s\". "
198 "This may lead to unexpected results", env_vars[i]);
203 g_strfreev(env_vars);
204 g_key_file_free(keyfile);