aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-24 07:31:40 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-24 07:46:01 +0100
commitabda28b2763e48f8b6b77220a677c1cdeb5d8970 (patch)
treef1b533fcb85b8e32001bd8e4183768fc2631ac67 /src
parent7b11290de97fa6cb2dabfbd6d2099da875ccc099 (diff)
downloadsciteco-abda28b2763e48f8b6b77220a677c1cdeb5d8970.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/main.cpp63
2 files changed, 37 insertions, 28 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9972f71..1819c19 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,7 @@ if CLANG
AM_CXXFLAGS += -Wno-mismatched-tags
endif
-AM_CPPFLAGS = -D'DEFAULT_SCITECOPATH="@DEFAULT_SCITECOPATH@"'
+AM_CPPFLAGS = -D'SCITECOLIBDIR="@scitecolibdir@"'
if NEED_COMPAT
AM_CPPFLAGS += -I@top_srcdir@/compat
endif
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);