From abda28b2763e48f8b6b77220a677c1cdeb5d8970 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 24 Nov 2014 07:31:40 +0100 Subject: introduced $SCITECOCONFIG env variable, and set different default for $SCITECOPATH on Windows * $SCITECOCONFIG has been introduced, so have a macro-accessible location for the profile, buffer session etc. This is set to the program dir on Windows. That way, the config files will be found, regardless of the current working dir, but it may also be set up for Unix-like environments on Windows. * $SCITECOPATH defaults to the program dir + "/lib" now on Windows. * The default profile is now always called ".teco_ini". Also on Windows. Platform differences like this would need to be documented. * The sample teco.ini has been renamed to "sample.teco_ini" for clarity --- src/main.cpp | 63 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 9123224..40b36cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,11 +42,7 @@ namespace SciTECO { -#ifdef G_OS_UNIX #define INI_FILE ".teco_ini" -#else -#define INI_FILE "teco.ini" -#endif /* * defining the global objects here ensures @@ -112,33 +108,33 @@ String::get_coord(const gchar *str, gint pos, /* * Keep program self-contained under Windows - * (look for profile in program's directory) + * Look for config files (profile and session), + * as well as standard library macros in the + * program's directory. */ static inline gchar * -get_teco_ini(const gchar *program) +get_default_config_path(const gchar *program) { - gchar *bin_dir = g_path_get_dirname(program); - gchar *ini = g_build_filename(bin_dir, INI_FILE, NIL); - g_free(bin_dir); - return ini; + return g_path_get_dirname(program); } -#else +#elif defined(G_OS_UNIX) static inline gchar * -get_teco_ini(const gchar *program) +get_default_config_path(const gchar *program) { - const gchar *home; + return g_strdup(g_getenv("HOME") ? : g_get_home_dir()); +} -#ifdef G_OS_UNIX - home = g_getenv("HOME") ? : g_get_home_dir(); #else - home = g_get_user_config_dir(); -#endif - return g_build_filename(home, INI_FILE, NIL); + +static inline gchar * +get_default_config_path(const gchar *program) +{ + return g_strdup(g_get_user_config_dir()); } -#endif /* !G_OS_WIN32 */ +#endif static inline void process_options(int &argc, char **&argv) @@ -172,23 +168,32 @@ process_options(int &argc, char **&argv) if (mung_file) { if (!g_file_test(mung_file, G_FILE_TEST_IS_REGULAR)) { - g_printf("Cannot mung \"%s\". File does not exist!\n", - mung_file); + g_fprintf(stderr, "Cannot mung \"%s\". File does not exist!\n", + mung_file); exit(EXIT_FAILURE); } - } else { - mung_file = get_teco_ini(argv[0]); } /* remaining arguments, are arguments to the interface */ } static inline void -initialize_environment(void) +initialize_environment(const gchar *program) { + gchar *default_configpath; gchar **env; - g_setenv("SCITECOPATH", DEFAULT_SCITECOPATH, FALSE); + default_configpath = get_default_config_path(program); + g_setenv("SCITECOCONFIG", default_configpath, FALSE); +#ifdef G_OS_WIN32 + gchar *default_scitecopath; + default_scitecopath = g_build_filename(default_configpath, "lib", NIL); + g_setenv("SCITECOPATH", default_scitecopath, FALSE); + g_free(default_scitecopath); +#else + g_setenv("SCITECOPATH", SCITECOLIBDIR, FALSE); +#endif + g_free(default_configpath); env = g_listenv(); @@ -300,8 +305,8 @@ main(int argc, char **argv) QRegisters::globals.insert("-"); /* current buffer name and number ("*") */ QRegisters::globals.insert(new QRegisterBufferInfo()); - /* environment registers */ - initialize_environment(); + /* environment defaults and registers */ + initialize_environment(argv[0]); QRegisters::locals = &local_qregs; @@ -333,6 +338,10 @@ main(int argc, char **argv) exit(EXIT_SUCCESS); } + if (!mung_file) + mung_file = g_build_filename(g_getenv("SCITECOCONFIG"), + INI_FILE, NIL); + if (g_file_test(mung_file, G_FILE_TEST_IS_REGULAR)) { Execute::file(mung_file, false); -- cgit v1.2.3