Changeset 12612
- Timestamp:
- 04/15/10 14:50:33 (14 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/Cons.java
r12607 r12612 69 69 result = result.push(rest.car()); 70 70 if (rest.cdr() == NIL) { 71 result = result.push(NIL);72 71 break; 73 72 } -
trunk/abcl/src/org/armedbear/lisp/Pathname.java
r12608 r12612 98 98 device = new Cons(NIL, NIL); 99 99 LispObject first = jars.car(); 100 if (first instanceof SimpleString) { 101 ((Cons)device).car = new SimpleString(((SimpleString)first).getStringValue()); 102 } else if (first instanceof Pathname) { 100 if (first instanceof Pathname) { 103 101 ((Cons)device).car = new Pathname((Pathname)first); 104 102 } else { … … 214 212 static final Symbol SCHEME = internKeyword("SCHEME"); 215 213 static final Symbol AUTHORITY = internKeyword("AUTHORITY"); 214 static final Symbol QUERY = internKeyword("QUERY"); 215 static final Symbol FRAGMENT = internKeyword("FRAGMENT"); 216 216 217 217 static final private String jarSeparator = "!/"; … … 249 249 type = p.type; 250 250 version = p.version; 251 invalidateNamestring(); 251 252 return; 252 253 } … … 266 267 s = s.substring("jar:".length(), i + jarSeparator.length()); 267 268 Pathname p = new Pathname(s); 268 LispObject first = ((Cons) p.device).car(); 269 if (first instanceof AbstractString) { 270 jars = jars.push(first); 271 } else { 272 jars = jars.push(p.device.car()); 273 } 269 jars = jars.push(p.device.car()); 274 270 } 275 271 if (jar.startsWith("jar:file:")) { 276 String jarString = jar.substring("jar:".length(), 277 jar.length() - jarSeparator.length()); 272 String jarString 273 = jar.substring("jar:".length(), 274 jar.length() - jarSeparator.length()); 278 275 // Use URL constructor to normalize Windows' use of device 279 276 URL url = null; … … 286 283 } 287 284 Pathname jarPathname = new Pathname(url); 288 if (jarString.endsWith(jarSeparator)) { 289 jars = jars.push(jarPathname.device); 290 } else { 291 jars = jars.push(jarPathname); 292 } 285 jars = jars.push(jarPathname); 293 286 } else { 294 287 URL url = null; 295 288 try { 296 289 url = new URL(jar.substring("jar:".length(), jar.length() - 2)); 297 jars = jars.push(new SimpleString(url.toString())); 290 Pathname p = new Pathname(url); 291 jars = jars.push(p); 298 292 } catch (MalformedURLException e) { 299 error(new LispError("Failed to parse url '" + url + "'" 300 + e.getMessage())); 293 error(new LispError("Failed to parse URL " 294 + "'" + url + "'" 295 + e.getMessage())); 301 296 } 302 297 } 303 298 jars = jars.nreverse(); 304 299 device = jars; 300 invalidateNamestring(); 305 301 return; 306 302 } … … 336 332 } 337 333 String scheme = url.getProtocol(); 334 if (scheme.equals("file")) { 335 Pathname p = new Pathname(s); 336 this.host = p.host; 337 this.device = p.device; 338 this.directory = p.directory; 339 this.name = p.name; 340 this.type = p.type; 341 this.version = p.version; 342 return; 343 } 338 344 Debug.assertTrue(scheme != null); 339 345 String authority = url.getAuthority(); … … 345 351 host = host.push(AUTHORITY); 346 352 host = host.push(new SimpleString(authority)); 347 host = host.nreverse();348 353 349 354 device = NIL; … … 365 370 String query = uri.getRawQuery(); 366 371 if (query != null) { 367 path += "?" + query; 372 host = host.push(QUERY); 373 host = host.push(new SimpleString(query)); 368 374 } 369 375 String fragment = uri.getRawFragment(); 370 376 if (fragment != null) { 371 path += "#" + fragment; 377 host = host.push(FRAGMENT); 378 host = host.push(new SimpleString(fragment)); 372 379 } 373 380 Pathname p = new Pathname(path != null ? path : ""); … … 377 384 type = p.type; 378 385 386 host = host.nreverse(); 387 invalidateNamestring(); 379 388 return; 380 389 } … … 613 622 } else if (device instanceof Cons) { 614 623 LispObject[] jars = ((Cons) device).copyToArray(); 615 int i = 0;616 if (jars[0] instanceof AbstractString) {617 sb.append("jar:");618 sb.append(((AbstractString) jars[0]).getStringValue());619 sb.append("!/");620 i = 1;621 }622 624 StringBuilder prefix = new StringBuilder(); 623 for ( ; i < jars.length; i++) {625 for (int i = 0; i < jars.length; i++) { 624 626 prefix.append("jar:"); 625 if ( i == 0) {627 if (!((Pathname)jars[i]).isURL() && i == 0) { 626 628 sb.append("file:"); 627 629 } 628 if (jars[i] instanceof Pathname) { 629 sb.append(((Pathname) jars[i]).getNamestring()); 630 } 630 sb.append(((Pathname) jars[i]).getNamestring()); 631 631 sb.append("!/"); 632 632 } … … 679 679 } 680 680 } 681 682 if (isURL()) { 683 LispObject o = Symbol.GETF.execute(host, QUERY, NIL); 684 if (o != NIL) { 685 sb.append("?"); 686 sb.append(o.getStringValue()); 687 } 688 o = Symbol.GETF.execute(host, FRAGMENT, NIL); 689 if (o != NIL) { 690 sb.append("#"); 691 sb.append(o.getStringValue()); 692 } 693 } 694 681 695 if (this instanceof LogicalPathname) { 682 696 if (version.integerp()) { … … 695 709 } 696 710 namestring = sb.toString(); 697 if (isURL()) { 711 if (isURL()) { 698 712 namestring = Utilities.uriEncode(namestring); 699 713 } … … 1462 1476 SimpleString wildcardDirectory = new SimpleString(directory + "/"); 1463 1477 1464 ZipFile jar = ZipCache.get( pathname.device.car());1478 ZipFile jar = ZipCache.get((Pathname)pathname.device.car()); 1465 1479 LispObject matches; 1466 1480 for (Enumeration<? extends ZipEntry> entries = jar.entries(); … … 1560 1574 final SimpleString wildcard = new SimpleString(wild); 1561 1575 1562 ZipFile jar = ZipCache.get( pathname.device.car());1576 ZipFile jar = ZipCache.get((Pathname)pathname.device.car()); 1563 1577 1564 1578 for (Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements();) { … … 1929 1943 Cons jars = (Cons) pathname.device; 1930 1944 LispObject o = jars.car(); 1931 if (o instanceof Pathname ) {1945 if (o instanceof Pathname && ! (((Pathname)o).isURL())) { 1932 1946 LispObject truename = Pathname.truename((Pathname)o, errorIfDoesNotExist); 1933 1947 if (truename != null … … 1946 1960 // 3. JAR with Entry 1947 1961 // 4. JAR in JAR with Entry 1948 ZipFile jarFile = ZipCache.get( jars.car());1962 ZipFile jarFile = ZipCache.get((Pathname)jars.car()); 1949 1963 String entryPath = pathname.asEntryPath(); 1950 1964 if (jarFile != null) { … … 2013 2027 } 2014 2028 2015 protected static URL makeURL( LispObject device) {2029 protected static URL makeURL(Pathname pathname) { 2016 2030 URL result = null; 2017 2031 try { 2018 if (device instanceof SimpleString) { 2019 result = new URL(((SimpleString)device).getStringValue()); 2020 } else { 2021 // XXX ensure that we have cannonical path. 2022 Pathname p = (Pathname)device; 2023 result = new URL("file:" + p.getNamestring()); 2024 } 2032 if (pathname.isURL()) { 2033 result = new URL(pathname.getNamestring()); 2034 } else { 2035 // XXX ensure that we have cannonical path. 2036 result = new URL("file://" + pathname.getNamestring()); 2037 } 2025 2038 } catch (MalformedURLException e) { 2026 Debug.trace("Could not form URL from " + device);2039 Debug.trace("Could not form URL from " + pathname); 2027 2040 } 2028 2041 return result; … … 2035 2048 // XXX We only return the bytes of an entry in a JAR 2036 2049 Debug.assertTrue(entryPath != null); 2037 ZipFile jarFile = ZipCache.get( device.car());2050 ZipFile jarFile = ZipCache.get((Pathname)device.car()); 2038 2051 Debug.assertTrue(jarFile != null); 2039 2052 // Is this a JAR within a JAR? … … 2064 2077 result = url.openStream(); 2065 2078 } catch (IOException e) { 2066 error(new FileError("Failed to get InputStream from " 2067 + "'" + Utilities.escapeFormat(getNamestring()) + "'" 2068 + ": " + e, 2069 this)); 2079 Debug.trace("Failed to get InputStream from " 2080 + "'" + getNamestring() + "'" 2081 + ": " + e); 2070 2082 } 2071 2083 } else { … … 2074 2086 result = new FileInputStream(file); 2075 2087 } catch (IOException e) { 2076 error(new FileError("Failed to get InputStream from "2077 2078 + ": " + e, this));2088 Debug.trace("Failed to get InputStream from " 2089 + "'" + getNamestring() + "'" 2090 + ": " + e); 2079 2091 } 2080 2092 } … … 2103 2115 if (entryPath.length() == 0) { 2104 2116 LispObject o = d.car(); 2105 if (o instanceof SimpleString) {2106 2117 // 0. JAR from URL 2107 // URL u = makeJarURL(o.getStringValue());2108 // XXX unimplemented2109 Debug.assertTrue(false);2110 // URLConnection c = null;2111 // try {2112 // c = u.openConnection();2113 // } catch(IOException e) {2114 // Debug.trace("Failed to open Connection for URL "2115 // + "'" + u + "'");2116 // return 0;2117 // }2118 // c.getLastModified();2119 } else {2120 2118 // 1. JAR 2121 return ((Pathname)o).getLastModified(); 2122 } 2119 return ((Pathname)o).getLastModified(); 2123 2120 } else { 2124 2121 // 3. Entry in JAR 2125 2122 final ZipEntry entry 2126 = ZipCache.get( device.car()).getEntry(entryPath);2123 = ZipCache.get((Pathname)device.car()).getEntry(entryPath); 2127 2124 if (entry == null) { 2128 2125 return 0; … … 2135 2132 } 2136 2133 } else { 2137 ZipFile outerJar = ZipCache.get( d.car());2134 ZipFile outerJar = ZipCache.get((Pathname)d.car()); 2138 2135 if (entryPath.length() == 0) { 2139 2136 // 4. JAR in JAR … … 2210 2207 error(new FileError("Bad place for a wild pathname.", newName)); 2211 2208 } 2209 if (original.isJar()) { 2210 error(new FileError("Bad place for a jar pathname.", original)); 2211 } 2212 if (newName.isJar()) { 2213 error(new FileError("Bad place for a jar pathname.", newName)); 2214 } 2215 if (original.isURL()) { 2216 error(new FileError("Bad place for a URL pathname.", original)); 2217 } 2218 if (newName.isURL()) { 2219 error(new FileError("Bad place for a jar pathname.", newName)); 2220 } 2221 2212 2222 newName = mergePathnames(newName, original, NIL); 2213 2223 final String newNamestring; … … 2273 2283 @Override 2274 2284 public LispObject execute(LispObject arg) { 2275 return coerceToPathname(arg).host; 2285 return coerceToPathname(arg).host; // XXX URL-PATHNAME 2276 2286 } 2277 2287 } -
trunk/abcl/src/org/armedbear/lisp/Utilities.java
r12607 r12612 152 152 153 153 public static InputStream getEntryAsInputStream(ZipInputStream zipInputStream, 154 154 String entryName) 155 155 { 156 156 ZipEntry entry = getEntry(zipInputStream, entryName); … … 255 255 } 256 256 257 258 257 static String uriEncode(String s) { 259 258 try { -
trunk/abcl/src/org/armedbear/lisp/ZipCache.java
r12607 r12612 98 98 static HashMap<URL, Entry> zipCache = new HashMap<URL, Entry>(); 99 99 100 synchronized public static ZipFile get( LispObject arg) {101 return get(Pathname.makeURL( arg));100 synchronized public static ZipFile get(Pathname p) { 101 return get(Pathname.makeURL(p)); 102 102 } 103 103
Note: See TracChangeset
for help on using the changeset viewer.