Changeset 15404
- Timestamp:
- 10/10/20 21:43:42 (3 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/Pathname.java
r15403 r15404 753 753 sb.append("PATHNAME (with no namestring) "); 754 754 if (getHost() != NIL) { 755 sb.append(":HOST ") ;756 sb.append(getHost().printObject());757 sb.append(" ");755 sb.append(":HOST ") 756 .append(getHost().printObject()) 757 .append(" "); 758 758 } 759 759 if (getDevice() != NIL) { 760 sb.append(":DEVICE ") ;761 sb.append(getDevice().printObject());762 sb.append(" ");760 sb.append(":DEVICE ") 761 .append(getDevice().printObject()) 762 .append(" "); 763 763 } 764 764 if (getDirectory() != NIL) { 765 sb.append(":DIRECTORY ") ;766 sb.append(getDirectory().printObject());767 sb.append(" ");765 sb.append(":DIRECTORY ") 766 .append(getDirectory().printObject()) 767 .append(" "); 768 768 } 769 769 if (getName() != NIL) { 770 sb.append(":NAME ") ;771 sb.append(getName().printObject());772 sb.append(" ");770 sb.append(":NAME ") 771 .append(getName().printObject()) 772 .append(" "); 773 773 } 774 774 if (getType() != NIL) { 775 sb.append(":TYPE ") ;776 sb.append(getType().printObject());777 sb.append(" ");775 sb.append(":TYPE ") 776 .append(getType().printObject()) 777 .append(" "); 778 778 } 779 779 if (getVersion() != NIL) { 780 sb.append(":VERSION ") ;781 sb.append(getVersion().printObject());782 sb.append(" ");780 sb.append(":VERSION ") 781 .append(getVersion().printObject()) 782 .append(" "); 783 783 } 784 784 if (sb.charAt(sb.length() - 1) == ' ') { -
trunk/abcl/src/org/armedbear/lisp/PathnameJar.java
r15401 r15404 68 68 public static LispObject createFromPathname(Pathname p) { 69 69 if (p instanceof PathnameURL) { 70 return PathnameJar.create(JAR_URI_PREFIX + ((PathnameURL)p).getNamestringAsURI() + JAR_URI_SUFFIX); 70 return PathnameJar.create(JAR_URI_PREFIX 71 + ((PathnameURL)p).getNamestringAsURI() 72 + JAR_URI_SUFFIX); 71 73 } else if (p instanceof Pathname) { 72 74 // FIXME: not going to work with namestrings with characters that need URI escaping 73 return PathnameJar.create(JAR_URI_PREFIX + "file://" + p.getNamestring() + JAR_URI_SUFFIX); 75 return PathnameJar.create(JAR_URI_PREFIX 76 + "file://" + p.getNamestring() 77 + JAR_URI_SUFFIX); 74 78 } else { 75 79 return p; … … 155 159 } 156 160 157 // FIXME: badly named158 static PathnameJar createJarPathname(String ns) {159 PathnameJar result = new PathnameJar();160 if (ns.length() == 0) { // ??? what calls in this state?161 return result;162 }163 164 PathnameURL p;165 166 URL url = null;167 URI uri = null;168 169 String nsURL = ns;170 if (!Pathname.isValidURL(nsURL)) {171 nsURL = "file:" + nsURL;172 }173 174 try {175 url = new URL(nsURL);176 uri = url.toURI();177 } catch (MalformedURLException e1) {178 parse_error("Failed to create URI from " + "'" + nsURL + "'" + ": " + e1.getMessage());179 return null;180 } catch (URISyntaxException e2) {181 parse_error("Failed to create URI from " + "'" + nsURL + "'" + ": " + e2.getMessage());182 return null;183 }184 185 String path = uri.getPath();186 String pathAsURI;187 if (path == null) {188 // We allow "jar:file:baz.jar!/" to construct a relative189 // path for jar files, so MERGE-PATHNAMES means something.190 pathAsURI = "file:" + uri.getSchemeSpecificPart();191 } else {192 // FIXME: Windows drive letters???193 String pathFromFile = (new File(path)).getPath();194 pathAsURI = "file:" + pathFromFile;195 }196 197 p = (PathnameURL)PathnameURL.create(pathAsURI);198 Pathname.ncoerce(p, result);199 200 return result;201 }202 203 161 static public LispObject create(String s) { 204 162 if (!s.startsWith(JAR_URI_PREFIX)) { … … 230 188 Pathname pathname = (Pathname)Pathname.create(nsWithoutSuffix); 231 189 Pathname jar = new Pathname(); 232 Pathname.ncoerce(pathname, jar);190 jar.copyFrom(pathname); 233 191 jars = jars.push(jar); 234 192 } else { 235 193 Pathname p = (Pathname)Pathname.create(contents.get(i)); 236 Pathname.ncoerce(p, result);194 result.copyFrom(p); 237 195 } 238 196 } … … 271 229 272 230 if (jars.equals(NIL) || jars.equals(Keyword.UNSPECIFIC)) { 273 System.out.println("Pathname transitional problem: JAR-PATHNAME has bad PATHNAME-DEVICE"); 274 return null; 231 type_error("JAR-PATHNAME has bad DEVICE", 232 jars, 233 list(Symbol.NOT, 234 list(Symbol.OR, 235 list(Symbol.EQL, NIL), 236 list(Symbol.EQL, Keyword.UNSPECIFIC)))); 237 return (String)UNREACHED; 275 238 } 276 239 … … 301 264 Pathname jar = (Pathname)innerJars.car(); 302 265 Pathname p = new Pathname(); 303 Pathname.ncoerce(jar, p);304 p.setDevice(NIL);266 p.copyFrom(jar) 267 .setDevice(NIL); 305 268 String ns = p.getNamestring(); 306 269 sb.append(ns) … … 332 295 LispObject jars = getJars(); 333 296 if (!(jars instanceof Cons)) { 334 System.out.println("Transitional pathname error: PATHNAME-DEVICE is not a Cons cell"); 335 return NIL; 297 type_error("JAR-PATHNAME device is not a cons", 298 jars, 299 Symbol.CONS); 300 return (LispObject)UNREACHED; 336 301 } 337 302 … … 591 556 } 592 557 } 593 594 595 // String rootJarNamestring = ((Pathname)rootJar).getNamestring();596 // try {597 // ZipFile jarFile = new ZipFile(rootJarNamestring);598 // ZipFileInputStream inputStream = null;599 // while (enclosingJars.car() != NIL) {600 // LispObject jar = enclosingJars.car();601 // String ns = ((Pathname)jar).getNamestring();602 // ZipEntry entry = currentZip.getEntry(ns);603 // if (entry == null) {604 // return simple_error("Failed to find entry ~a in ~a", ns, pathname);605 // }606 // InputStream i = entry.getInputStream();607 // ZipInputStream zi = new ZipInputStream(i);608 // enclosingJars = enclosingJars.cdr();609 // }610 // } catch (IOException e) {611 // return Pathname.doTruenameExit(result, errorIfDoesNotExist);612 // }613 614 615 616 617 618 // truename619 // jarfile: {620 // // Possibly canonicalize jar file directory621 // LispObject o = pathname.getDevice();622 // if (!(o instanceof Pathname)) {623 // return doTruenameExit(pathname, errorIfDoesNotExist);624 // }625 // if (o instanceof Pathname626 // && !(((Pathname)o).isURL())627 // // XXX Silently fail to call truename() if the default628 // // pathname defaults exist within a jar, as that will629 // // (probably) not succeed. The better solution would630 // // probably be to parametize the value of631 // // *DEFAULT-PATHNAME-DEFAULTS* on invocations of632 // // truename().633 // && !coerceToPathname(Symbol.DEFAULT_PATHNAME_DEFAULTS.symbolValue()).isJar())634 // {635 // LispObject truename = Pathname.truename((Pathname)o, errorIfDoesNotExist);636 // if (truename != null && truename != NIL637 // && truename instanceof Pathname) {638 // Pathname truePathname = (Pathname)truename;639 // // A jar that is a directory makes no sense, so exit640 // if (truePathname.getNamestring().endsWith("/")) {641 // break jarfile;642 // }643 // jars.car = truePathname;644 // } else {645 // break jarfile;646 // }647 // }648 649 // // Check for existence of a JAR file and/or JarEntry650 // //651 // // Cases:652 // // 1. JAR653 // // 2. JAR in JAR654 // // 3. JAR with Entry655 // // 4. JAR in JAR with Entry656 657 // ZipFile jarFile = ZipCache.get((Pathname)jars.car());658 // String entryPath = pathname.asEntryPath();659 // if (jarFile != null) {660 // if (jars.cdr() instanceof Cons) {661 // Pathname inner = (Pathname) jars.cdr().car();662 // InputStream inputStream = Utilities.getInputStream(jarFile, inner);663 // if (inputStream != null) {664 // if (entryPath.length() == 0) {665 // return pathname; // Case 2666 // } else {667 // ZipInputStream zipInputStream668 // = new ZipInputStream(inputStream);669 // ZipEntry entry = Utilities.getEntry(zipInputStream,670 // entryPath,671 // false);672 // if (entry != null) {673 // // XXX this could possibly be a directory?674 // return pathname; // Case 4675 // }676 // }677 // }678 // } else {679 // if (entryPath.length() == 0) {680 // return pathname; // Case 1681 // } else {682 // ZipEntry entry = jarFile.getEntry(entryPath);683 // if (entry != null) {684 // // ensure this isn't a directory685 // if (entry.isDirectory()) {686 // break jarfile;687 // }688 // try {689 // InputStream input = jarFile.getInputStream(entry);690 // if (input != null) {691 // return pathname; // Case 3692 // }693 // } catch (IOException e) {694 // break jarfile;695 // }696 // }697 // }698 // }699 // }700 // }701 702 703 704 705 // Pathname.init()706 // A JAR file707 708 709 // LispObject jars = NIL;710 // int i = s.lastIndexOf(jarSeparator, s.length() - jarSeparator.length() - 1);711 // String jar = null;712 // if (i == -1) {713 // jar = s;714 // } else {715 // // There can be no more than two jar references and the716 // // inner one must be a file reference within the outer.717 // jar = "jar:file:" + s.substring(i + jarSeparator.length());718 // s = s.substring("jar:".length(), i + jarSeparator.length());719 // Pathname p = (Pathname) Pathname.create(s);720 // jars = jars.push(p.getDevice().car());721 // }722 // if (jar.startsWith("jar:file:")) { // PathnameJar should handle this partâŠ723 // String file724 // = jar.substring("jar:file:".length(),725 // jar.length() - jarSeparator.length());726 // Pathname jarPathname;727 // if (file.length() > 0) {728 // URL url = null;729 // URI uri = null;730 // try {731 // url = new URL("file:" + file);732 // uri = url.toURI();733 // } catch (MalformedURLException e1) {734 // error(new SimpleError("Failed to create URI from "735 // + "'" + file + "'"736 // + ": " + e1.getMessage()));737 // } catch (URISyntaxException e2) {738 // error(new SimpleError("Failed to create URI from "739 // + "'" + file + "'"740 // + ": " + e2.getMessage()));741 // }742 // String path = uri.getPath();743 // if (path == null) {744 // // We allow "jar:file:baz.jar!/" to construct a relative745 // // path for jar files, so MERGE-PATHNAMES means something.746 // jarPathname = (Pathname)Pathname.create(uri.getSchemeSpecificPart());747 // } else {748 // jarPathname = (Pathname)Pathname.create((new File(path)).getPath());749 // }750 // } else {751 // jarPathname = (Pathname)Pathname.create("");752 // }753 // jars = jars.push(jarPathname);754 // } else {755 // URL url = null;756 // try {757 // url = new URL(jar.substring("jar:".length(), jar.length() - 2));758 // Pathname p = (Pathname)Pathname.create(url);759 // jars = jars.push(p);760 // } catch (MalformedURLException e) {761 // error(new LispError("Failed to parse URL "762 // + "'" + url + "'"763 // + e.getMessage()));764 // }765 // }766 // jars = jars.nreverse();767 // setDevice(jars);768 // invalidateNamestring();769 // return;770 771 772 // // An entry in a JAR file773 // final int separatorIndex = s.lastIndexOf(jarSeparator);774 // if (separatorIndex > 0 && s.startsWith("jar:")) {775 // return PathnameJar.create(s);776 // }777 // final String jarURL = s.substring(0, separatorIndex + jarSeparator.length());778 // URL url = null;779 // try {780 // url = new URL(jarURL);781 // } catch (MalformedURLException ex) {782 // error(new LispError("Failed to parse URL "783 // + "'" + jarURL + "'"784 // + ex.getMessage()));785 // }786 // Pathname d = (Pathname)Pathname.create(url);787 // if (getDevice() instanceof Cons) {788 // LispObject[] jars = d.copyToArray();789 // // XXX Is this ever reached? If so, need to append lists790 // Debug.assertTrue(false);791 // } else {792 // setDevice(d.getDevice());793 // }794 // s = "/" + s.substring(separatorIndex + jarSeparator.length());795 // Pathname p = (Pathname)Pathname.create("file:" + s); // Use URI escaping rules796 // setDirectory(p.getDirectory());797 // setName(p.getName());798 // setType(p.getType());799 // setVersion(p.getVersion());800 // return;801 // }802 803 804 805 -
trunk/abcl/src/org/armedbear/lisp/PathnameURL.java
r15401 r15404 190 190 // Use the output of Pathname 191 191 Pathname p = new Pathname(); 192 p.copyFrom(this); 193 Pathname.ncoerce(this, p); 194 p.setHost(NIL); 195 p.setDevice(NIL); 196 p.setDirectory(NIL); 192 p.copyFrom(this) 193 .setHost(NIL) 194 .setDevice(NIL) 195 .setDirectory(NIL); 197 196 String nameTypeVersion = p.getNamestring(); 198 197 sb.append(nameTypeVersion); … … 200 199 LispObject o = Symbol.GETF.execute(getHost(), QUERY, NIL); 201 200 if (o != NIL) { 202 sb.append("?") ;203 sb.append(o.getStringValue());201 sb.append("?") 202 .append(o.getStringValue()); 204 203 } 205 204 o = Symbol.GETF.execute(getHost(), FRAGMENT, NIL); 206 205 if (o != NIL) { 207 sb.append("#"); 208 sb.append(o.getStringValue()); 209 } 210 211 //namestring = sb.toString(); 206 sb.append("#") 207 .append(o.getStringValue()); 208 } 209 212 210 return sb.toString(); 213 211 } … … 316 314 } 317 315 318 319 316 public long getLastModified() { 320 317 return getURLConnection().getLastModified(); 321 318 } 322 319 323 320 @DocString(name="uri-decode", 324 321 args="string", 325 322 returns="string", 326 doc="Decode STRING percent escape sequences in the manner of URI encodings.")323 doc="Decode STRING percent escape sequences in the manner of URI encodings.") 327 324 private static final Primitive URI_DECODE = new pf_uri_decode(); 328 325 private static final class pf_uri_decode extends Primitive { … … 351 348 args="string", 352 349 returns="string", 353 doc="Encode percent escape sequences in the manner of URI encodings.")350 doc="Encode percent escape sequences in the manner of URI encodings.") 354 351 private static final Primitive URI_ENCODE = new pf_uri_encode(); 355 352 private static final class pf_uri_encode extends Primitive {
Note: See TracChangeset
for help on using the changeset viewer.