diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-24 07:31:40 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-24 07:46:01 +0100 |
commit | abda28b2763e48f8b6b77220a677c1cdeb5d8970 (patch) | |
tree | f1b533fcb85b8e32001bd8e4183768fc2631ac67 | |
parent | 7b11290de97fa6cb2dabfbd6d2099da875ccc099 (diff) | |
download | sciteco-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
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | bootstrap.am | 1 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rwxr-xr-x | distribute | 5 | ||||
-rw-r--r-- | doc/sciteco.1.in | 48 | ||||
-rw-r--r-- | lib/session.tes | 2 | ||||
-rw-r--r-- | sample.teco_ini (renamed from teco.ini) | 0 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/main.cpp | 63 |
9 files changed, 76 insertions, 54 deletions
diff --git a/Makefile.am b/Makefile.am index c019f96..32bbb38 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = src lib doc -dist_pkgdata_DATA = teco.ini +dist_pkgdata_DATA = sample.teco_ini noinst_HEADERS = compat/bsd/sys/cdefs.h \ compat/bsd/sys/queue.h \ diff --git a/bootstrap.am b/bootstrap.am index 09e65f0..0707420 100644 --- a/bootstrap.am +++ b/bootstrap.am @@ -13,7 +13,6 @@ SUBST_MACRO = eb$<\e \ <fs@bindir^Q@\e$(bindir)\e;>j \ <fs@pkgdatadir^Q@\e$(pkgdatadir)\e;>j \ <fs@scitecolibdir^Q@\e$(scitecolibdir)\e;>j \ - <fs@DEFAULT_SCITECOPATH^Q@\e@DEFAULT_SCITECOPATH@\e;>j \ <fs@TECO_INTEGER^Q@\e@TECO_INTEGER@\e;>j \ <fs@DATE^Q@\e$(shell LC_ALL=C @DATE@ "+%d %b %Y")\e;>j \ ew$@\e diff --git a/configure.ac b/configure.ac index 4e8d886..77b71a7 100644 --- a/configure.ac +++ b/configure.ac @@ -174,13 +174,6 @@ esac AM_CONDITIONAL(INTERFACE_GTK, [test x$INTERFACE = xgtk]) -AC_ARG_WITH(default-scitecopath, - AS_HELP_STRING([--with-default-scitecopath=PATH], - [Specify the default value of the $SCITECOPATH variable - [default=DATADIR/sciteco/lib]]), - [DEFAULT_SCITECOPATH=$withval], [DEFAULT_SCITECOPATH=$scitecolibdir]) -AC_SUBST(DEFAULT_SCITECOPATH) - AC_ARG_WITH(teco-integer, AS_HELP_STRING([--with-teco-integer=SIZE], [Storage size of TECO integers in bits [default=64]]), @@ -66,10 +66,9 @@ sciteco-$(SCITECO_VERSION)-win32.zip : $(SCITECO_SRC) (cd sciteco-$(SCITECO_VERSION); \ ./configure --host=i686-w64-mingw32 --prefix=/ \ --with-interface=pdcurses \ - --with-default-scitecopath=lib \ --disable-bootstrap \ --enable-html-manual \ - CFLAGS="-g -O3" CXXFLAGS="-g -O3"; \ + CFLAGS="-O3" CXXFLAGS="-O3"; \ ) $(MAKE) -C sciteco-$(SCITECO_VERSION) \ install DESTDIR=`pwd`/temp-install @@ -78,6 +77,8 @@ sciteco-$(SCITECO_VERSION)-win32.zip : $(SCITECO_SRC) mkdir temp-bin/ cp -r temp-install/bin/* temp-install/share/sciteco/* temp-install/share/doc/sciteco/* \ temp-bin/ + cp temp-install/share/sciteco/sample.teco_ini \ + temp-bin/.teco_ini rm -rf temp-install/ cp /usr/i686-w64-mingw32/bin/intl.dll \ /usr/i686-w64-mingw32/bin/libglib-2.0-0.dll \ diff --git a/doc/sciteco.1.in b/doc/sciteco.1.in index eea0189..2cfd7ec 100644 --- a/doc/sciteco.1.in +++ b/doc/sciteco.1.in @@ -95,8 +95,11 @@ undo token accumulation. If the .B \-\-mung option is absent, \*(ST will mung -.I ~/.teco_ini +.I $SCITECOCONFIG/.teco_ini (if existing) which is called the profile. +On UNIX/Linux, the default profile is at +.I ~/.teco_ini +(see \fBENVIRONMENT\fP). The profile will usually set up various Scintilla and \*(ST options, configure syntax highlighting, define commonly used macros and open files specified as arguments to \*(ST. @@ -116,10 +119,9 @@ If the option is specified, the .B \-\-mung option has no effect. .IP "\fB-m\fR, \fB--mung\fR \fIfile" -Mung -.IR file . +Mung \fIfile\fP. Default is -.IR ~/.teco_ini . +.IR $SCITECOCONFIG/.teco_ini . . . .SH EXIT STATUS @@ -137,30 +139,48 @@ table. A dollar sign is prepended before each variable name, so that for instance the variable \(lqHOME\(rq can be examined by macros by reading the string-content of Q-Register \(lq$HOME\(rq. -The following environment variables have a special meaning for -\*(ST: +The following environment variables are initialized with default +values by \*(ST if they are unset: +.TP +.B SCITECOCONFIG +Path where \*(ST looks for configuration files. +For instance, this is the path of the default profile. +If unset, this variable defaults to the \fBHOME\fP +environment variable on UNIX/Linux. +If \fBHOME\fP is unset, it defaults to the current user's +home directory as set by +.BR passwd (5). +On Windows, this variable defaults to the location of the +\*(ST program executable, so that \*(ST is self-contained +on Windows. +On other platforms, this variable defaults to some other +user-specific configuration directory. .TP .B SCITECOPATH Standard library macro path. Macros can expect to find standard library macros in this directory. -It defaults to -.B "@DEFAULT_SCITECOPATH@" -(often the standard library path). +On Windows, this variable defaults to the \(lqlib\(rq +subdirectory of the directory containing +the \*(ST program executable, so that \*(ST is self-contained +on Windows. +On all other platforms (including UNIX/Linux) this variable +defaults to the standard library installation path at +.BR "@scitecolibdir@" . . . .SH FILES . .TP -.B ~/.teco_ini +.B $SCITECOCONFIG/.teco_ini Default profile macro. .TP -.B @pkgdatadir@/teco.ini +.B @pkgdatadir@/sample.teco_ini Sample profile macro configuring commonly used run-time options, syntax highlighting, session handling and opening files specified on the command line. .TP -.B @scitecolibdir@/... +.B $SCITECOPATH/*.tes Standard library macros. .TP .BI .teco- x - filename @@ -168,12 +188,12 @@ Save point files created by \*(ST when saving files during interactive execution have this format. These files can be ignored by version control systems, etc. .TP -.B ~/.teco_session +.B $SCITECOCONFIG/.teco_session Macro storing the default buffer session. This is not written by \*(ST itself, but by the standard library \fBsession.tes\fP macros. When the \(lqsession.git\(rq macro is used, these files -will also be created in Git repositories. +will also be created in the roots of Git repositories. . . .SH BUGS diff --git a/lib/session.tes b/lib/session.tes index 3dfb05f..99dce52 100644 --- a/lib/session.tes +++ b/lib/session.tes @@ -2,7 +2,7 @@ ! Path of the session profile. Change this to save/load a custom profile ! -EU[session.path]Q[$HOME]/.teco_session +EU[session.path]Q[$SCITECOCONFIG]/.teco_session ! Save current session to the file specified by "session.path" ! @[session.save]{ diff --git a/teco.ini b/sample.teco_ini index 67ead44..67ead44 100644 --- a/teco.ini +++ b/sample.teco_ini 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); |