diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-02-24 05:04:15 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-02-24 05:04:15 +0100 |
commit | 39124fd2ad6a3e0bf51d4b7c91fafef6108eacd5 (patch) | |
tree | fad2f09e7e22f21107ed18b43d9a53010d89d9ae | |
parent | 9f7f187f1860047c8cb24ca34552f31bf7a2c3ce (diff) | |
download | sciteco-39124fd2ad6a3e0bf51d4b7c91fafef6108eacd5.tar.gz |
EG and EC use $SHELL and $COMSPEC as the default command interpreters now
* The default command interpreter will thus be inherited from
the operating system. In the case of UNIX from the user's
passwd entry.
E.g. if bash is used, bash extensions can be used immediately
if flag 128 is not set in the ED flags.
* On DOS-like systems there are also alternative interpreters
(e.g. 4NT, 4OS2) that are configurable now.
* At least on UNIX with $SHELL it is not guaranteed that
the interpreter supports the standard command line arguments
like "-c". If they don't, this will cause problems with EC.
Since $SHELL is mapped to a Q-Register, it can however
always be easily customized for SciTECO sessions in the
user's .teco_ini.
-rw-r--r-- | doc/sciteco.1.in | 9 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/spawn.cpp | 45 |
3 files changed, 43 insertions, 17 deletions
diff --git a/doc/sciteco.1.in b/doc/sciteco.1.in index 468c060..bb7d29b 100644 --- a/doc/sciteco.1.in +++ b/doc/sciteco.1.in @@ -208,6 +208,15 @@ Initialization of this variable ensures that the \(lq$HOME\(rq Q-Register is available even on Windows and the home directory can always be re-configured. .TP +.BR SHELL " or " COMSPEC +Path of the command interpreter used by \fBEG\fP and \fBEC\fP +commands if UNIX98 shell emulation is \fIdisabled\fP. +\fBSHELL\fP is used on UNIX-like systems, while \fBCOMSPEC\fP +is used on DOS-like systems (like Windows). +Both variables are usually already set in the process environment +but are initialized to \(lq/bin/sh\(rq or \(lqcmd.exe\(rq +should they nevertheless be unset. +.TP .B SCITECOCONFIG Path where \*(ST looks for configuration files. For instance, this is the path of the default profile. diff --git a/src/main.cpp b/src/main.cpp index bf25c73..d14e2e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -247,6 +247,12 @@ initialize_environment(const gchar *program) g_setenv("HOME", abs_path, TRUE); g_free(abs_path); +#ifdef G_OS_WIN32 + g_setenv("COMSPEC", "cmd.exe", FALSE); +#elif defined(G_OS_UNIX) || defined(G_OS_HAIKU) + g_setenv("SHELL", "/bin/sh", FALSE); +#endif + /* * Initialize $SCITECOCONFIG and $SCITECOPATH */ diff --git a/src/spawn.cpp b/src/spawn.cpp index fce7209..9ea3919 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -97,17 +97,24 @@ parse_shell_command_line(const gchar *cmdline, GError **error) #ifdef G_OS_WIN32 if (!(Flags::ed & Flags::ED_SHELLEMU)) { - const gchar *argv_win32[] = { - "cmd.exe", "/q", "/c", cmdline, NULL - }; - return g_strdupv((gchar **)argv_win32); + QRegister *reg = QRegisters::globals["$COMSPEC"]; + argv = (gchar **)g_malloc(5*sizeof(gchar *)); + argv[0] = reg->get_string(); + argv[1] = g_strdup("/q"); + argv[2] = g_strdup("/c"); + argv[3] = g_strdup(cmdline); + argv[4] = NULL; + return argv; } #elif defined(G_OS_UNIX) || defined(G_OS_HAIKU) if (!(Flags::ed & Flags::ED_SHELLEMU)) { - const gchar *argv_unix[] = { - "/bin/sh", "-c", cmdline, NULL - }; - return g_strdupv((gchar **)argv_unix); + QRegister *reg = QRegisters::globals["$SHELL"]; + argv = (gchar **)g_malloc(4*sizeof(gchar *)); + argv[0] = reg->get_string(); + argv[1] = g_strdup("-c"); + argv[2] = g_strdup(cmdline); + argv[3] = NULL; + return argv; } #endif @@ -178,12 +185,16 @@ parse_shell_command_line(const gchar *cmdline, GError **error) * specific process exit code. * * <command> execution is by default platform-dependent. - * On Windows, <command> is passed to the default command - * interpreter \(lqcmd.exe\(rq with the \(lq/c\(rq - * command-line argument. - * On Unix/Linux, <command> is passed to the \(lq/bin/sh\(rq - * shell with the \(lq-c\(rq command-line argument. - * Therefore operating system restrictions on the maximum + * On DOS-like systems like Windows, <command> is passed to + * the command interpreter specified in the \fB$COMSPEC\fP + * environment variable with the \(lq/q\(rq and \(lq/c\(rq + * command-line arguments. + * On UNIX-like systems, <command> is passed to the interpreter + * specified by the \fB$SHELL\fP environment variable + * with the \(lq-c\(rq command-line argument. + * Therefore the default shell can be configured using + * the corresponding environment registers. + * The operating system restrictions on the maximum * length of command-line arguments apply to <command> and * quoting of parameters within <command> is somewhat platform * dependent. @@ -191,10 +202,10 @@ parse_shell_command_line(const gchar *cmdline, GError **error) * <command> just as an UNIX98 \(lq/bin/sh\(rq would, but without * performing any expansions. * The program specified in <command> is searched for in - * standard locations (according to the \(lqPATH\(rq environment + * standard locations (according to the \fB$PATH\fP environment * variable). - * This mode of operation can also be enforced on Windows and - * Unix by enabling bit 7 in the ED flag, e.g. by executing + * This mode of operation can also be enforced on all platforms + * by enabling bit 7 in the ED flag, e.g. by executing * \(lq0,128ED\(rq, and is recommended when writing cross-platform * macros using the EC command. * |