src/ChangeLog addition:
2007-12-11  Aidan Kehoe  <kehoea(a)parhasard.net>
	* fileio.c (Fsubstitute_in_file_name):
	On encountering non-existent environment variables or incorrect
	syntax for specifying environment variables (as is routine on
	Windows) don't error, instead pass the original strings through.
XEmacs Trunk source patch:
Diff command:   cvs -q diff -u
Files affected: src/fileio.c
===================================================================
RCS
Index: src/fileio.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/fileio.c,v
retrieving revision 1.113
diff -u -r1.113 fileio.c
--- src/fileio.c	2007/11/14 18:51:22	1.113
+++ src/fileio.c	2007/12/11 16:06:31
@@ -1518,10 +1518,10 @@
   /* This function can GC.  GC checked 2000-07-28 ben. */
   Ibyte *nm;
 
-  Ibyte *s, *p, *o, *x, *endp;
+  Ibyte *s, *p, *o, *x, *endp, *got;
   Ibyte *target = 0;
   int total = 0;
-  int substituted = 0;
+  int substituted = 0, seen_braces;
   Ibyte *xnm;
   Lisp_Object handler;
 
@@ -1576,7 +1576,10 @@
       {
 	p++;
 	if (p == endp)
-	  goto badsubst;
+	  {
+	    /* No substitution, no error. */
+	    break;
+	  }
 	else if (*p == '$')
 	  {
 	    /* "$$" means a single "$" */
@@ -1589,7 +1592,12 @@
 	  {
 	    o = ++p;
 	    while (p != endp && *p != '}') p++;
-	    if (*p != '}') goto missingclose;
+	    if (*p != '}')
+	      {
+		/* No substitution, no error. Keep looking. */
+		p = o;
+		continue;
+	      }
 	    s = p;
 	  }
 	else
@@ -1608,10 +1616,12 @@
 #endif /* WIN32_NATIVE */
 
 	/* Get variable value */
-	o = egetenv ((CIbyte *) target);
-	if (!o) goto badvar;
-	total += qxestrlen (o);
-	substituted = 1;
+	got = egetenv ((CIbyte *) target);
+	if (got)
+	  {
+	    total += qxestrlen (got);
+	    substituted = 1;
+	  }
       }
 
   if (!substituted)
@@ -1629,8 +1639,12 @@
     else
       {
 	p++;
+	seen_braces = 0;
 	if (p == endp)
-	  goto badsubst;
+	  {
+	    *x++ = '$';
+	    break;
+	  }
 	else if (*p == '$')
 	  {
 	    *x++ = *p++;
@@ -1638,9 +1652,16 @@
 	  }
 	else if (*p == '{')
 	  {
+	    seen_braces = 1;
 	    o = ++p;
 	    while (p != endp && *p != '}') p++;
-	    if (*p != '}') goto missingclose;
+	    if (*p != '}')
+	      {
+		/* Don't syntax error, don't substitute */
+		*x++ = '{';
+		p = o;
+		continue;
+	      }
 	    s = p++;
 	  }
 	else
@@ -1659,12 +1680,28 @@
 #endif /* WIN32_NATIVE */
 
 	/* Get variable value */
-	o = egetenv ((CIbyte *) target);
-	if (!o)
-	  goto badvar;
-
-	qxestrcpy (x, o);
-	x += qxestrlen (o);
+	got = egetenv ((CIbyte *) target);
+	if (got)
+	  {
+	    qxestrcpy (x, got);
+	    x += qxestrlen (got);
+	  }
+	else
+	  {
+	    *x++ = '$';
+	    if (seen_braces)
+	      {
+		*x++ = '{';
+		qxestrcpy (x, target);
+		x += qxestrlen (target);
+		*x++ = '}';
+	      }
+	    else
+	      {
+		qxestrcpy (x, target);
+		x += qxestrlen (target);
+	      }
+	  }
       }
 
   *x = 0;
@@ -1689,17 +1726,6 @@
 #endif
 
   return make_string (xnm, x - xnm);
-
- badsubst:
-  syntax_error ("Bad format environment-variable substitution", filename);
- missingclose:
-  syntax_error ("Missing \"}\" in environment-variable
substitution",
-		filename);
- badvar:
-  syntax_error_2 ("Substituting nonexistent environment variable",
-		  filename, build_intstring (target));
-
-  RETURN_NOT_REACHED (Qnil);
 }
 
 /* A slightly faster and more convenient way to get
-- 
¿Dónde estará ahora mi sobrino Yoghurtu Nghé, que tuvo que huir
precipitadamente de la aldea por culpa de la escasez de rinocerontes?
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-patches