[armedbear-cvs] r12798 - trunk/abcl/src/org/armedbear/lisp

Mark Evenson mevenson at common-lisp.net
Sat Jul 10 20:22:36 UTC 2010


Author: mevenson
Date: Sat Jul 10 16:22:36 2010
New Revision: 12798

Log:
[HEADS UP] Break Pathname to normalize cross-platform serializations.

Convert to forward slash '/' as directory separator in namestring
output.

FIXME: Breaks UNC paths, as the sequence "//" in
"//mount$share/dir/file" gets stripped, whereas the HOST should be
interpreted in this case.  But who uses these?  Please test.



Modified:
   trunk/abcl/src/org/armedbear/lisp/Pathname.java

Modified: trunk/abcl/src/org/armedbear/lisp/Pathname.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Pathname.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Pathname.java	Sat Jul 10 16:22:36 2010
@@ -61,7 +61,7 @@
     // A positive integer, or NIL, :WILD, :UNSPECIFIC, or :NEWEST.
     protected LispObject version = NIL;
 
-    private String namestring;
+    private volatile String namestring;
 
     /** The protocol for changing any instance field (i.e. 'host', 'type', etc.)
      *  is to call this method after changing the field to recompute the namestring.
@@ -242,7 +242,7 @@
             return;
         }
         if (Utilities.isPlatformWindows) {
-            if (s.startsWith("\\\\")) {
+            if (s.startsWith("\\\\")) { // XXX What if string starts with '//'?
                 //UNC path support
                 // match \\<server>\<share>\[directories-and-files]
 
@@ -401,24 +401,9 @@
         }
 
         if (Utilities.isPlatformWindows) {
-            if (!s.contains(jarSeparator)) {
-                s = s.replace("/", "\\");
-            } else {
-              StringBuilder result = new StringBuilder();
-              for (int i = 0; i < s.length(); i++) {
-                  char c = s.charAt(i);
-                  if ( c != '/') {
-                      result.append(c);
-                  } else {
-                      if (i != 0 && s.charAt(i-1) != '!') {
-                          result.append("\\");
-                      } else {
-                          result.append(c);
-                      }
-                  }
-              }
-              s = result.toString();
-            }
+            if (s.contains("\\")) {
+                s = s.replace("\\", "/");
+            } 
         }
 
         // Expand user home directories
@@ -438,22 +423,11 @@
         }
         String d = null;
         // Find last file separator char.
-        if (Utilities.isPlatformWindows) {
-            for (int i = s.length(); i-- > 0;) {
-                char c = s.charAt(i);
-                if (c == '/' || c == '\\') {
-                    d = s.substring(0, i + 1);
-                    s = s.substring(i + 1);
-                    break;
-                }
-            }
-        } else {
-            for (int i = s.length(); i-- > 0;) {
-                if (s.charAt(i) == '/') {
-                    d = s.substring(0, i + 1);
-                    s = s.substring(i + 1);
-                    break;
-                }
+        for (int i = s.length(); i-- > 0;) {
+            if (s.charAt(i) == '/') {
+                d = s.substring(0, i + 1);
+                s = s.substring(i + 1);
+                break;
             }
         }
         if (d != null) {
@@ -667,7 +641,7 @@
         }
         if (name instanceof AbstractString) {
             String n = name.getStringValue();
-            if (n.indexOf(File.separatorChar) >= 0) {
+            if (n.indexOf('/') >= 0) {
                 Debug.assertTrue(namestring == null);
                 return null;
             }
@@ -738,12 +712,7 @@
         // is, both NIL and :UNSPECIFIC cause the component not to appear in
         // the namestring." 19.2.2.2.3.1
         if (directory != NIL) {
-            final char separatorChar;
-            if (isJar() || isURL()) {
-                separatorChar = '/'; 
-            } else {
-                separatorChar = File.separatorChar;
-            }
+            final char separatorChar = '/';
             LispObject temp = directory;
             LispObject part = temp.car();
             temp = temp.cdr();
@@ -791,18 +760,8 @@
         p.invalidateNamestring();
         String path = p.getNamestring();
         StringBuilder result = new StringBuilder();
-        if (Utilities.isPlatformWindows) {
-	    for (int i = 0; i < path.length(); i++) {
-		char c = path.charAt(i);
-		if (c == '\\') {
-		    result.append('/');
-		} else {
-		    result.append(c);
-		}
-	    }
-        } else  {
-            result.append(path);
-        }
+        result.append(path);
+
         // Entries in jar files are always relative, but Pathname
         // directories are :ABSOLUTE.
         if (result.length() > 1
@@ -904,7 +863,7 @@
                     }
                 }
             }
-        } else {
+        } else { 
             useNamestring = false;
         }
         StringBuilder sb = new StringBuilder();
@@ -926,41 +885,53 @@
                 sb.append('"');
             }
         } else {
-            sb.append("#P(");
+            final boolean ANSI_COMPATIBLE = true;
+            final String separator;
+            if (ANSI_COMPATIBLE) {
+                sb.append("#P(");
+                separator = "\"";
+            } else {
+                sb.append("#P(");
+                separator = " ";
+            }
             if (host != NIL) {
                 sb.append(":HOST ");
                 sb.append(host.writeToString());
-                sb.append(' ');
+                sb.append(separator);
             }
             if (device != NIL) {
                 sb.append(":DEVICE ");
                 sb.append(device.writeToString());
-                sb.append(' ');
+                sb.append(separator);
             }
             if (directory != NIL) {
                 sb.append(":DIRECTORY ");
                 sb.append(directory.writeToString());
-                sb.append(" ");
+                sb.append(separator);
             }
             if (name != NIL) {
                 sb.append(":NAME ");
                 sb.append(name.writeToString());
-                sb.append(' ');
+                sb.append(separator);
             }
             if (type != NIL) {
                 sb.append(":TYPE ");
                 sb.append(type.writeToString());
-                sb.append(' ');
+                sb.append(separator);
             }
             if (version != NIL) {
                 sb.append(":VERSION ");
                 sb.append(version.writeToString());
-                sb.append(' ');
+                sb.append(separator);
             }
-            if (sb.charAt(sb.length() - 1) == ' ') {
+            if (sb.charAt(sb.length() - 1) == ' ') { // XXX
                 sb.setLength(sb.length() - 1);
             }
-            sb.append(')');
+            if (ANSI_COMPATIBLE) {
+                sb.append(')' + separator);
+            } else {
+                sb.append(')');
+            }
         }
         return sb.toString();
     }
@@ -1378,6 +1349,7 @@
         final int limit = s.length();
         for (int i = 0; i < limit; i++) {
             char c = s.charAt(i);
+            // XXX '\\' should be illegal in all Pathnames at this point?
             if (c == '/' || c == '\\' && Utilities.isPlatformWindows) {
                 error(new LispError("Invalid character #\\" + c
                   + " in pathname component \"" + s




More information about the armedbear-cvs mailing list