emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/callproc.c,v


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/src/callproc.c,v
Date: Thu, 20 Sep 2007 22:38:16 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Stefan Monnier <monnier>        07/09/20 22:38:15

Index: callproc.c
===================================================================
RCS file: /sources/emacs/emacs/src/callproc.c,v
retrieving revision 1.228
retrieving revision 1.229
diff -u -b -r1.228 -r1.229
--- callproc.c  12 Sep 2007 07:17:16 -0000      1.228
+++ callproc.c  20 Sep 2007 22:38:15 -0000      1.229
@@ -1512,24 +1512,16 @@
 }
 
 static int
-getenv_internal (var, varlen, value, valuelen, frame)
+getenv_internal_1 (var, varlen, value, valuelen, env)
      char *var;
      int varlen;
      char **value;
      int *valuelen;
-     Lisp_Object frame;
+     Lisp_Object env;
 {
-  Lisp_Object scan;
-  Lisp_Object display;
-
-  /* FIXME: Code duplication.  */
-
-  if (NILP (frame))
-    {
-      /* Try to find VAR in Vprocess_environment first.  */
-      for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
+  for (; CONSP (env); env = XCDR (env))
         {
-          Lisp_Object entry = XCAR (scan);
+      Lisp_Object entry = XCAR (env);
           if (STRINGP (entry)
               && SBYTES (entry) >= varlen
 #ifdef WINDOWSNT
@@ -1550,10 +1542,33 @@
                 {
                   /* Lone variable names in Vprocess_environment mean that
                      variable should be removed from the environment. */
-                  return 0;
+             *value = NULL;
+             return 1;
                 }
             }
         }
+  return 0;
+}
+
+static int
+getenv_internal (var, varlen, value, valuelen, frame)
+     char *var;
+     int varlen;
+     char **value;
+     int *valuelen;
+     Lisp_Object frame;
+{
+  Lisp_Object display;
+
+  /* FIXME: weird behavior.  */
+
+  if (NILP (frame))
+    {
+      /* Try to find VAR in Vprocess_environment first.  */
+      if (getenv_internal_1 (var, varlen, value, valuelen,
+                            Vprocess_environment))
+       return value ? 1 : 0;
+      else
       frame = selected_frame;
     }
 
@@ -1567,65 +1582,19 @@
          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 (getenv_internal_1 (var, varlen, value, valuelen,
+                        Vprocess_environment))
+    return value ? 1 : 0;
 
 #if 0
   /* Find the environment in which to search the variable. */
   CHECK_FRAME (frame);
   frame = Fframe_with_environment (frame);
 
-  for (scan = get_frame_param (XFRAME (frame), Qenvironment);
-       CONSP (scan);
-       scan = XCDR (scan))
-    {
-      Lisp_Object entry;
-
-      entry = XCAR (scan);
-      if (STRINGP (entry)
-          && SBYTES (entry) > varlen
-          && SREF (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 */
-          )
-       {
-         *value    = (char *) SDATA (entry) + (varlen + 1);
-         *valuelen = SBYTES (entry) - (varlen + 1);
-         return 1;
-       }
-    }
+  if (getenv_internal_1 (var, varlen, value, valuelen,
+                        get_frame_param (XFRAME (frame), Qenvironment)))
+    return value ? 1 : 0;
 #endif
   return 0;
 }
@@ -1639,18 +1608,28 @@
 not found there, then it continues the search in the environment list
 of the selected frame.
 
-If optional parameter FRAME is non-nil, then this function will ignore
-`process-environment' and will simply look up the variable in that
-frame's environment.  */)
-     (variable, frame)
-     Lisp_Object variable, frame;
+If optional parameter ENV is a list, then search this list instead of
+`process-environment', and return t when encountering a negative entry.
+
+If it is a frame, then this function will ignore `process-environment' and
+will simply look up the variable in that frame's environment.  */)
+     (variable, env)
+     Lisp_Object variable, env;
 {
   char *value;
   int valuelen;
 
   CHECK_STRING (variable);
-  if (getenv_internal (SDATA (variable), SBYTES (variable),
-                      &value, &valuelen, frame))
+  if (CONSP (env))
+    {
+      if (getenv_internal_1 (SDATA (variable), SBYTES (variable),
+                            &value, &valuelen, env))
+       return value ? make_string (value, valuelen) : Qt;
+      else
+       return Qnil;
+    }
+  else if (getenv_internal (SDATA (variable), SBYTES (variable),
+                      &value, &valuelen, env))
     return make_string (value, valuelen);
   else
     return Qnil;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]