summaryrefslogtreecommitdiff
path: root/src/callproc.c
diff options
context:
space:
mode:
authorDan Nicolaescu <dann@ics.uci.edu>2007-07-03 04:53:21 +0000
committerDan Nicolaescu <dann@ics.uci.edu>2007-07-03 04:53:21 +0000
commitde87fb5978903768aff3c71857ebca173461bea3 (patch)
treea730da52bd15d248d83d5a897c462bc2c2b3a65b /src/callproc.c
parent5f06b6081389843ba2d2d817683eb4e610f7a24e (diff)
downloademacs-de87fb5978903768aff3c71857ebca173461bea3.tar.gz
* server.el (server-process-filter): Likewise.
(server-process-filter): Likewise. Also set COLORFGBG and COLORTERM. * frame.el (frame-initialize, make-frame): Likewise. * faces.el (tty-set-up-initial-frame-faces): Likewise. * env.el (read-envvar-name): Don't consider the environment frame param. (setenv): Set display-environment-variable and term-environment-variable. * frame.c (Qterm_environment_variable, Qdisplay_environment_variable): New variables. (syms_of_frame): Intern and staticpro them. * frame.h: Declare them here. * callproc.c (child_setup): Use the display-environment-variable and term-environment-variable frame params. (getenv_internal): Likewise. (set_initial_environment): Initialise Vprocess_environment. * frames.texi (Basic Parameters): Add display-environment-variable and term-environment-variable.
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c113
1 files changed, 105 insertions, 8 deletions
diff --git a/src/callproc.c b/src/callproc.c
index ce9eb73dd54..a2d517b1bea 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1245,6 +1245,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
{
char **env;
char *pwd_var;
+ char *term_var;
+ char *display_var;
#ifdef WINDOWSNT
int cpid;
HANDLE handles[3];
@@ -1325,9 +1327,12 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
register char **new_env;
char **p, **q;
register int new_length;
- Lisp_Object local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
- Qenvironment);
+ Lisp_Object local = selected_frame; /* get_frame_param (XFRAME (Fframe_with_environment (selected_frame)), */
+/* Qenvironment); */
+ Lisp_Object term;
+ Lisp_Object display;
+
new_length = 0;
for (tem = Vprocess_environment;
@@ -1335,10 +1340,21 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
tem = XCDR (tem))
new_length++;
+#if 0
for (tem = local;
CONSP (tem) && STRINGP (XCAR (tem));
tem = XCDR (tem))
new_length++;
+#endif
+
+ /* Add TERM and DISPLAY from the frame local values. */
+ term = get_frame_param (XFRAME (local), Qterm_environment_variable);
+ if (! NILP (term))
+ new_length++;
+
+ display = get_frame_param (XFRAME (local), Qdisplay_environment_variable);
+ if (! NILP (display))
+ new_length++;
/* new_length + 2 to include PWD and terminating 0. */
env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
@@ -1348,18 +1364,43 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
if (egetenv ("PWD"))
*new_env++ = pwd_var;
+ if (! NILP (term))
+ {
+ int vlen = strlen ("TERM=") + strlen (SDATA (term)) + 1;
+ char *vdata = (char *) alloca (vlen);
+ strcpy (vdata, "TERM=");
+ strcat (vdata, SDATA (term));
+ new_env = add_env (env, new_env, vdata);
+ }
+
+ if (! NILP (display))
+ {
+ int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1;
+ char *vdata = (char *) alloca (vlen);
+ strcpy (vdata, "DISPLAY=");
+ strcat (vdata, SDATA (display));
+ new_env = add_env (env, new_env, vdata);
+ }
+
/* Overrides. */
for (tem = Vprocess_environment;
CONSP (tem) && STRINGP (XCAR (tem));
tem = XCDR (tem))
- new_env = add_env (env, new_env, SDATA (XCAR (tem)));
+ {
+ if ((strcmp (SDATA (XCAR (tem)), "TERM") != 0)
+ && (strcmp (SDATA (XCAR (tem)), "DISPLAY") != 0))
+ new_env = add_env (env, new_env, SDATA (XCAR (tem)));
+ }
+
+#if 0
/* Local part of environment. */
for (tem = local;
CONSP (tem) && STRINGP (XCAR (tem));
tem = XCDR (tem))
new_env = add_env (env, new_env, SDATA (XCAR (tem)));
-
+#endif
+
*new_env = 0;
/* Remove variable names without values. */
@@ -1373,6 +1414,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
p++;
}
}
+
+
#ifdef WINDOWSNT
prepare_standard_handles (in, out, err, handles);
set_process_dir (SDATA (current_dir));
@@ -1494,6 +1537,9 @@ getenv_internal (var, varlen, value, valuelen, frame)
Lisp_Object frame;
{
Lisp_Object scan;
+ Lisp_Object term;
+ Lisp_Object display;
+
if (NILP (frame))
{
@@ -1528,6 +1574,56 @@ getenv_internal (var, varlen, value, valuelen, frame)
frame = selected_frame;
}
+ /* For TERM and DISPLAY first try to get the values from the frame. */
+ term = get_frame_param (XFRAME (frame), Qterm_environment_variable);
+ if (strcmp (var, "TERM") == 0)
+ if (! NILP (term))
+ {
+ *value = (char *) SDATA (term);
+ *valuelen = SBYTES (term);
+ return 1;
+ }
+ display = get_frame_param (XFRAME (frame), Qdisplay_environment_variable);
+ if (strcmp (var, "DISPLAY") == 0)
+ if (! NILP (display))
+ {
+ *value = (char *) SDATA (display);
+ *valuelen = SBYTES (display);
+ return 1;
+ }
+
+ {
+ /* Try to find VAR in Vprocess_environment. */
+ for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
+ {
+ Lisp_Object entry = XCAR (scan);
+ if (STRINGP (entry)
+ && SBYTES (entry) >= varlen
+#ifdef WINDOWSNT
+ /* NT environment variables are case insensitive. */
+ && ! strnicmp (SDATA (entry), var, varlen)
+#else /* not WINDOWSNT */
+ && ! bcmp (SDATA (entry), var, varlen)
+#endif /* not WINDOWSNT */
+ )
+ {
+ if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
+ {
+ *value = (char *) SDATA (entry) + (varlen + 1);
+ *valuelen = SBYTES (entry) - (varlen + 1);
+ return 1;
+ }
+ else if (SBYTES (entry) == varlen)
+ {
+ /* Lone variable names in Vprocess_environment mean that
+ variable should be removed from the environment. */
+ return 0;
+ }
+ }
+ }
+ }
+
+#if 0
/* Find the environment in which to search the variable. */
CHECK_FRAME (frame);
frame = Fframe_with_environment (frame);
@@ -1555,7 +1651,7 @@ getenv_internal (var, varlen, value, valuelen, frame)
return 1;
}
}
-
+#endif
return 0;
}
@@ -1737,14 +1833,15 @@ void
set_initial_environment ()
{
register char **envp;
- Lisp_Object env = Qnil;
+ Lisp_Object env = Vprocess_environment;
#ifndef CANNOT_DUMP
if (initialized)
#endif
{
for (envp = environ; *envp; envp++)
- env = Fcons (build_string (*envp), env);
- store_frame_param (SELECTED_FRAME(), Qenvironment, env);
+ Vprocess_environment = Fcons (build_string (*envp),
+ Vprocess_environment);
+ store_frame_param (SELECTED_FRAME(), Qenvironment, Vprocess_environment);
}
}