Changeset 15391


Ignore:
Timestamp:
10/10/20 21:43:20 (3 years ago)
Author:
Mark Evenson
Message:

pathname: normalize Pathname to new Java conventions

  1. use setter/getter methods for accessing internal components
  1. use create() to construct new Pathname objects

Also known as using a Factory pattern which allows one to do stuff
like:

Pathname p = new Pathname("/foo/").setName("build").setType("me");

TODO: remove invalidateNamestring()

Disallow use of Pathname constructor where possible to encourage use
of create() routines.

Location:
trunk/abcl
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Extensions.java

    r14877 r15391  
    319319        File file = File.createTempFile(prefix, suffix, null);
    320320        if (file != null)
    321           return new Pathname(file.getPath());
     321          return Pathname.create(file.getPath());
    322322      } catch (IllegalArgumentException e) {
    323323        // "Failed to create temporary file due to argument problems."
     
    348348        dir.delete();
    349349        if (dir.mkdirs()) {
    350           return new Pathname(dir + "/");
     350          return Pathname.create(dir + "/");
    351351        }
    352352      } catch (Throwable t) {
  • trunk/abcl/src/org/armedbear/lisp/FaslClassLoader.java

    r14015 r15391  
    106106      final LispThread thread = LispThread.currentThread();
    107107
    108       Pathname name = new Pathname(resourceName.substring("org/armedbear/lisp/".length()));
     108      Pathname name = Pathname.create(resourceName.substring("org/armedbear/lisp/".length()));
    109109      LispObject truenameFasl = Symbol.LOAD_TRUENAME_FASL.symbolValue(thread);
    110110      LispObject truename = Symbol.LOAD_TRUENAME.symbolValue(thread);
  • trunk/abcl/src/org/armedbear/lisp/Interpreter.java

    r14591 r15391  
    156156        if (!initialDirectory.endsWith(File.separator))
    157157            initialDirectory = initialDirectory.concat(File.separator);
    158         Symbol.DEFAULT_PATHNAME_DEFAULTS.setSymbolValue(new Pathname(initialDirectory));
     158        Symbol.DEFAULT_PATHNAME_DEFAULTS.setSymbolValue(Pathname.create(initialDirectory));
    159159    }
    160160
     
    331331                    if (i + 1 < args.length) {
    332332                        if (arg.equals("--load"))
    333                             Load.load(Pathname.mergePathnames(new Pathname(args[i + 1]),
     333                            Load.load(Pathname.mergePathnames(Pathname.create(args[i + 1]),
    334334                                    checkPathname(Symbol.DEFAULT_PATHNAME_DEFAULTS.getSymbolValue())),
    335335                                      false, false, true);
  • trunk/abcl/src/org/armedbear/lisp/JarStream.java

    r13440 r15391  
    6363        super(Symbol.JAR_STREAM);
    6464        Debug.assertTrue(direction == Keyword.INPUT);
    65         Debug.assertTrue(pathname.name != NIL);
     65        Debug.assertTrue(pathname.getName() != NIL);
    6666        isInputStream = true;
    6767
  • trunk/abcl/src/org/armedbear/lisp/JavaClassLoader.java

    r14363 r15391  
    8787    public byte[] getFunctionClassBytes(String name) {
    8888        Pathname pathname
    89             = new Pathname(name.substring("org/armedbear/lisp/".length())
    90                            + "." + Lisp._COMPILE_FILE_CLASS_EXTENSION_.symbolValue().getStringValue());
     89            = Pathname.create(name.substring("org/armedbear/lisp/".length())
     90                    + "." + Lisp._COMPILE_FILE_CLASS_EXTENSION_.symbolValue().getStringValue());
    9191        return readFunctionBytes(pathname);
    9292    }
     
    327327            jcl.addURL(((Pathname) jar).toURL());
    328328        } else if (jar instanceof AbstractString) {
    329             jcl.addURL(new Pathname(jar.toString()).toURL());
     329            jcl.addURL(Pathname.create(jar.toString()).toURL());
    330330        } else {
    331331            error(new TypeError(jar + " must be a pathname designator"));
     
    338338            LispObject list = NIL;
    339339            for(URL u : ((URLClassLoader) o).getURLs()) {
    340                 list = list.push(new Pathname(u));
     340                list = list.push(Pathname.create(u));
    341341            }
    342342            return new Cons(new JavaObject(o), list.nreverse());
  • trunk/abcl/src/org/armedbear/lisp/Lisp.java

    r15389 r15391  
    13591359  public static final LispObject loadCompiledFunction(final String namestring)
    13601360  {
    1361       Pathname name = new Pathname(namestring);
     1361      Pathname name = Pathname.create(namestring);
    13621362      byte[] bytes = readFunctionBytes(name);
    13631363      if (bytes != null)
  • trunk/abcl/src/org/armedbear/lisp/Load.java

    r14914 r15391  
    5858    {
    5959        final LispThread thread = LispThread.currentThread();
    60         return load(new Pathname(filename),
     60        return load(Pathname.create(filename),
    6161                    Symbol.LOAD_VERBOSE.symbolValue(thread) != NIL,
    6262                    Symbol.LOAD_PRINT.symbolValue(thread) != NIL,
     
    7070        if (truename instanceof Pathname) {
    7171            Pathname t = (Pathname)truename;
    72             if (t.name != NIL
    73                 && t.name != null) {
     72            if (t.getName() != NIL
     73                && t.getName() != null) {
    7474                return t;
    7575            }
    7676        }
    7777        final String COMPILE_FILE_TYPE = Lisp._COMPILE_FILE_TYPE_.symbolValue().getStringValue();
    78         if (name.type == NIL
    79             && (name.name != NIL || name.name != null)) {
    80             Pathname lispPathname = new Pathname(name);
    81             lispPathname.type = new SimpleString("lisp");
     78        if (name.getType() == NIL
     79            && (name.getName() != NIL || name.getName() != null)) {
     80            Pathname lispPathname = Pathname.create(name);
     81            lispPathname.setType(new SimpleString("lisp"));
    8282            lispPathname.invalidateNamestring();
    8383            LispObject lisp = Pathname.truename(lispPathname, false);
    84             Pathname abclPathname = new Pathname(name);
    85             abclPathname.type = new SimpleString(COMPILE_FILE_TYPE);
     84            Pathname abclPathname = Pathname.create(name);
     85            abclPathname.setType(new SimpleString(COMPILE_FILE_TYPE));
    8686            abclPathname.invalidateNamestring();
    8787            LispObject abcl = Pathname.truename(abclPathname, false);
     
    103103        }
    104104        if (name.isJar()) {
    105             if (name.type.equals(NIL)) {
    106                 name.type = COMPILE_FILE_INIT_FASL_TYPE;
     105            if (name.getType().equals(NIL)) {
     106                name.setType(COMPILE_FILE_INIT_FASL_TYPE);
    107107                name.invalidateNamestring();
    108108                Pathname result = findLoadableFile(name);
     
    110110                    return result;
    111111                }
    112                 name.type = new SimpleString(COMPILE_FILE_TYPE);
     112                name.setType(new SimpleString(COMPILE_FILE_TYPE));
    113113                name.invalidateNamestring();
    114114                result = findLoadableFile(name);
     
    174174        if (Utilities.checkZipFile(truename)) {
    175175            String n = truename.getNamestring();
    176             String name = Pathname.uriEncode(truename.name.getStringValue());
     176            String name = Pathname.uriEncode(truename.getName().getStringValue());
    177177            if (n.startsWith("jar:")) {
    178178                n = "jar:" + n + "!/" + name + "."
     
    185185                    + COMPILE_FILE_INIT_FASL_TYPE;
    186186            }
    187             if (!((mergedPathname = new Pathname(n)) instanceof Pathname)) {
     187            if (!((mergedPathname = Pathname.create(n)) instanceof Pathname)) {
    188188              return error(new FileError((MessageFormat.format("Failed to address JAR-PATHNAME truename {0} for name {1}", truename.princToString(), name)), truename));
    189189            }
     
    192192            if (initTruename == null || initTruename.equals(NIL)) {
    193193                // Maybe the enclosing JAR has been renamed?
    194                 Pathname p = new Pathname(mergedPathname);
    195                 p.name = Keyword.WILD;
     194                Pathname p = Pathname.create(mergedPathname);
     195                p.setName(Keyword.WILD);
    196196                p.invalidateNamestring();
    197197                LispObject result = Pathname.MATCH_WILD_JAR_PATHNAME.execute(p);
     
    294294        Pathname pathname = null;
    295295        Pathname truename = null;
    296         pathname = new Pathname(filename);
     296        pathname = Pathname.create(filename);
    297297        LispObject bootPath = Site.getLispHome();
    298298        Pathname mergedPathname;
     
    325325            }               
    326326            if (!bootPath.equals(NIL)) {
    327                 Pathname urlPathname = new Pathname(url);
     327                Pathname urlPathname = Pathname.create(url);
    328328                loadableFile = findLoadableFile(urlPathname);
    329329                truename = (Pathname)Pathname.truename(loadableFile);
     
    339339        // Look for a init FASL inside a packed FASL
    340340        if (truename != null
    341             && truename.type.princToString().equals(COMPILE_FILE_TYPE) && Utilities.checkZipFile(truename))  {
    342             Pathname init = new Pathname(truename.getNamestring());
    343             init.type = COMPILE_FILE_INIT_FASL_TYPE;
    344             init.name = new SimpleString("__loader__");
     341            && truename.getType().princToString().equals(COMPILE_FILE_TYPE) && Utilities.checkZipFile(truename))  {
     342            Pathname init = Pathname.create(truename.getNamestring());
     343            init.setType(COMPILE_FILE_INIT_FASL_TYPE);
     344            init.setName(new SimpleString("__loader__"));
    345345            LispObject t = Pathname.truename(init);
    346346            if (t instanceof Pathname) {
     
    526526            if (!truename.equals(NIL)) {
    527527                if (truename instanceof Pathname) {
    528                     truePathname = new Pathname((Pathname)truename);
     528                    truePathname = Pathname.create((Pathname)truename);
    529529                } else if (truename instanceof AbstractString) {
    530                     truePathname = new Pathname(truename.getStringValue());
     530                    truePathname = Pathname.create(truename.getStringValue());
    531531                } else {
    532532                    Debug.assertTrue(false);
    533533                }
    534                 String type = truePathname.type.getStringValue();
     534                String type = truePathname.getType().getStringValue();
    535535                if (type.equals(Lisp._COMPILE_FILE_TYPE_.symbolValue(thread).getStringValue())
    536536                    || type.equals(COMPILE_FILE_INIT_FASL_TYPE.toString())) {
    537                     Pathname truenameFasl = new Pathname(truePathname);
     537                    Pathname truenameFasl = Pathname.create(truePathname);
    538538                    thread.bindSpecial(Symbol.LOAD_TRUENAME_FASL, truenameFasl);
    539539                }
    540                 if (truePathname.type.getStringValue()
     540                if (truePathname.getType().getStringValue()
    541541                    .equals(COMPILE_FILE_INIT_FASL_TYPE.getStringValue())
    542542                    && truePathname.isJar()) {
    543                     if (truePathname.device.cdr() != NIL ) {
     543                    if (truePathname.getDevice().cdr() != NIL ) {
    544544                        // We set *LOAD-TRUENAME* to the argument that
    545545                        // a user would pass to LOAD.
    546                         Pathname enclosingJar = (Pathname)truePathname.device.cdr().car();
    547                         truePathname.device = new Cons(truePathname.device.car(), NIL);
    548                         truePathname.host = NIL;
    549                         truePathname.directory = enclosingJar.directory;
    550                         if (truePathname.directory.car().equals(Keyword.RELATIVE)) {
    551                             truePathname.directory.setCar(Keyword.ABSOLUTE);
     546                        Pathname enclosingJar = (Pathname)truePathname.getDevice().cdr().car();
     547                        truePathname.setDevice(new Cons(truePathname.getDevice().car(), NIL));
     548                        truePathname.setHost(NIL);
     549                        truePathname.setDirectory(enclosingJar.getDirectory());
     550                        if (truePathname.getDirectory().car().equals(Keyword.RELATIVE)) {
     551                            truePathname.getDirectory().setCar(Keyword.ABSOLUTE);
    552552                        }
    553                         truePathname.name = enclosingJar.name;
    554                         truePathname.type = enclosingJar.type;
     553                        truePathname.setName(enclosingJar.getName());
     554                        truePathname.setType(enclosingJar.getType());
    555555                        truePathname.invalidateNamestring();
    556556                    } else {
     
    559559                        // cases but this currently passes the tests.
    560560                        if (!(truePathname.device.car() instanceof AbstractString)) {
    561                           assert truePathname.device.car() instanceof Pathname;
    562                           Pathname p = new Pathname((Pathname)truePathname.device.car());
     561                          assert truePathname.getDevice().car() instanceof Pathname;
     562                          Pathname p = Pathname.create((Pathname)truePathname.getDevice().car());
    563563                          truePathname
    564564                            = (Pathname) probe_file.PROBE_FILE.execute(p);
  • trunk/abcl/src/org/armedbear/lisp/LogicalPathname.java

    r14793 r15391  
    3838import java.util.HashMap;
    3939import java.util.StringTokenizer;
     40import java.text.MessageFormat;
    4041
    4142public final class LogicalPathname extends Pathname
    4243{
    43     private static final String LOGICAL_PATHNAME_CHARS =
    44         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-;*.";
    45 
    46     private static final HashMap map = new HashMap();
    47 
    48     protected LogicalPathname()
    49     {
    50     }
    51 
    52     protected LogicalPathname(Pathname p) {
    53         super(p);
    54     }
    55 
    56     public LogicalPathname(String host, String rest)
    57     {
    58         final int limit = rest.length();
    59         for (int i = 0; i < limit; i++) {
    60             char c = rest.charAt(i);
    61             if (LOGICAL_PATHNAME_CHARS.indexOf(c) < 0) {
    62                 error(new ParseError("The character #\\" + c + " is not valid in a logical pathname."));
    63                 return;
    64             }
    65         }
    66 
    67         this.host = new SimpleString(host);
    68 
    69         // "The device component of a logical pathname is always :UNSPECIFIC;
    70         // no other component of a logical pathname can be :UNSPECIFIC."
    71         device = Keyword.UNSPECIFIC;
    72 
    73         int semi = rest.lastIndexOf(';');
    74         if (semi >= 0) {
    75             // Directory.
    76             String d = rest.substring(0, semi + 1);
    77             directory = parseDirectory(d);
    78             rest = rest.substring(semi + 1);
     44  public static final String LOGICAL_PATHNAME_CHARS
     45    = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-;*.";
     46  private static final HashMap map
     47    = new HashMap();
     48
     49  static public boolean isValidLogicalPathname(String namestring) {
     50    if (!isValidURL(namestring)) {
     51      String host = getHostString(namestring);
     52      if (host != null
     53       && LOGICAL_PATHNAME_TRANSLATIONS.get(new SimpleString(host)) != null) {
     54        return true;
     55      }
     56    }
     57    return false;
     58  }
     59
     60  public static LogicalPathname create(String namestring) {
     61    // parse host out then call create(host, rest);
     62    if (LogicalPathname.isValidLogicalPathname(namestring)) {
     63      String h = LogicalPathname.getHostString(namestring);
     64      return LogicalPathname.create(h,
     65                                    namestring.substring(namestring.indexOf(':') + 1));
     66    }
     67    return null;  // Ugh.  I bet this is gonna cause problems. Tighten entrance points
     68  }
     69
     70  public static LogicalPathname create(String host, String rest) {
     71    // This may be "too late" in the creation chain to be meaningful?
     72    SimpleString h = new SimpleString(host);
     73    if (LOGICAL_PATHNAME_TRANSLATIONS.get(h) == null) {
     74      // Logical pathnames are only valid when it's host exists
     75      String message = MessageFormat.format("'{0}' is not a defined logical host", host);
     76      error(new SimpleError(message));
     77    }
     78    LogicalPathname result = new LogicalPathname();
     79    final int limit = rest.length();
     80    for (int i = 0; i < limit; i++) {
     81      char c = rest.charAt (i);
     82      if (LOGICAL_PATHNAME_CHARS.indexOf(c) < 0) {
     83        error(new ParseError("The character #\\" + c + " is not valid in a logical pathname."));
     84
     85      }
     86    }
     87
     88    result.setHost(h);
     89
     90    // "The device component of a logical pathname is always :UNSPECIFIC;
     91    // no other component of a logical pathname can be :UNSPECIFIC."
     92    result.setDevice(Keyword.UNSPECIFIC);
     93
     94    int semi = rest.lastIndexOf(';');
     95    if (semi >= 0) {
     96      // Directory.
     97      String d = rest.substring(0, semi + 1);
     98      result.setDirectory(parseDirectory(d));
     99      rest = rest.substring(semi + 1);
     100    } else {
     101      // "If a relative-directory-marker precedes the directories, the
     102      // directory component parsed is as relative; otherwise, the
     103            // directory component is parsed as absolute."
     104          result.setDirectory(new Cons(Keyword.ABSOLUTE));
     105    }
     106
     107    int dot = rest.indexOf('.');
     108    if (dot >= 0) {
     109      String n = rest.substring(0, dot);
     110      if (n.equals("*")) {
     111        result.setName(Keyword.WILD);
     112      } else {
     113        result.setName(new SimpleString(n.toUpperCase()));
     114      }
     115      rest = rest.substring(dot + 1);
     116      dot = rest.indexOf('.');
     117      if (dot >= 0) {
     118        String t = rest.substring(0, dot);
     119        if (t.equals("*")) {
     120          result.setType(Keyword.WILD);
    79121        } else {
    80             // "If a relative-directory-marker precedes the directories, the
    81             // directory component parsed is as relative; otherwise, the
    82             // directory component is parsed as absolute."
    83             directory = new Cons(Keyword.ABSOLUTE);
    84         }
    85 
    86         int dot = rest.indexOf('.');
    87         if (dot >= 0) {
    88             String n = rest.substring(0, dot);
    89             if (n.equals("*"))
    90                 name = Keyword.WILD;
    91             else
    92                 name = new SimpleString(n.toUpperCase());
    93             rest = rest.substring(dot + 1);
    94             dot = rest.indexOf('.');
    95             if (dot >= 0) {
    96                 String t = rest.substring(0, dot);
    97                 if (t.equals("*"))
    98                     type = Keyword.WILD;
    99                 else
    100                     type = new SimpleString(t.toUpperCase());
    101                 // What's left is the version.
    102                 String v = rest.substring(dot + 1);
    103                 if (v.equals("*"))
    104                     version = Keyword.WILD;
    105                 else if (v.equals("NEWEST") || v.equals("newest"))
    106                     version = Keyword.NEWEST;
    107                 else
    108                     version = PACKAGE_CL.intern("PARSE-INTEGER").execute(new SimpleString(v));
    109             } else {
    110                 String t = rest;
    111                 if (t.equals("*"))
    112                     type = Keyword.WILD;
    113                 else
    114                     type = new SimpleString(t.toUpperCase());
    115             }
     122          result.setType(new SimpleString(t.toUpperCase()));
     123        }
     124        // What's left is the version.
     125        String v = rest.substring(dot + 1);
     126        if (v.equals("*")) {
     127          result.setVersion(Keyword.WILD);
     128        } else if (v.equals("NEWEST") || v.equals("newest")) {
     129          result.setVersion(Keyword.NEWEST);
    116130        } else {
    117             String n = rest;
    118             if (n.equals("*"))
    119                 name = Keyword.WILD;
    120             else if (n.length() > 0)
    121                 name = new SimpleString(n.toUpperCase());
    122         }
    123     }
    124 
    125     private static final String LOGICAL_PATHNAME_COMPONENT_CHARS =
    126         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
    127 
    128     public static final SimpleString canonicalizeStringComponent(AbstractString s)
    129 
    130     {
    131         final int limit = s.length();
    132         for (int i = 0; i < limit; i++) {
    133             char c = s.charAt(i);
    134             if (LOGICAL_PATHNAME_COMPONENT_CHARS.indexOf(c) < 0) {
    135                 error(new ParseError("Invalid character #\\" + c +
    136                                       " in logical pathname component \"" + s +
    137                                       '"'));
    138                 // Not reached.
    139                 return null;
    140             }
    141         }
    142         return new SimpleString(s.getStringValue().toUpperCase());
    143     }
    144 
    145     public static Pathname translateLogicalPathname(LogicalPathname pathname)
    146 
    147     {
    148         return (Pathname) Symbol.TRANSLATE_LOGICAL_PATHNAME.execute(pathname);
    149     }
    150 
    151     private static final LispObject parseDirectory(String s)
    152 
    153     {
    154         LispObject result;
    155         if (s.charAt(0) == ';') {
    156             result = new Cons(Keyword.RELATIVE);
    157             s = s.substring(1);
    158         } else
    159             result = new Cons(Keyword.ABSOLUTE);
    160         StringTokenizer st = new StringTokenizer(s, ";");
    161         while (st.hasMoreTokens()) {
    162             String token = st.nextToken();
    163             LispObject obj;
    164             if (token.equals("*"))
    165                 obj = Keyword.WILD;
    166             else if (token.equals("**"))
    167                 obj = Keyword.WILD_INFERIORS;
    168             else if (token.equals("..")) {
    169                 if (result.car() instanceof AbstractString) {
    170                     result = result.cdr();
    171                     continue;
    172                 }
    173                 obj= Keyword.UP;
    174             } else
    175                 obj = new SimpleString(token.toUpperCase());
    176             result = new Cons(obj, result);
    177         }
    178         return result.nreverse();
    179     }
    180 
    181     @Override
    182     public LispObject typeOf()
    183     {
    184         return Symbol.LOGICAL_PATHNAME;
    185     }
    186 
    187     @Override
    188     public LispObject classOf()
    189     {
    190         return BuiltInClass.LOGICAL_PATHNAME;
    191     }
    192 
    193     @Override
    194     public LispObject typep(LispObject type)
    195     {
    196         if (type == Symbol.LOGICAL_PATHNAME)
    197             return T;
    198         if (type == BuiltInClass.LOGICAL_PATHNAME)
    199             return T;
    200         return super.typep(type);
    201     }
    202 
    203     @Override
    204     protected String getDirectoryNamestring()
    205     {
    206         StringBuilder sb = new StringBuilder();
    207         // "If a pathname is converted to a namestring, the symbols NIL and
    208         // :UNSPECIFIC cause the field to be treated as if it were empty. That
    209         // is, both NIL and :UNSPECIFIC cause the component not to appear in
    210         // the namestring." 19.2.2.2.3.1
    211         if (directory != NIL) {
    212             LispObject temp = directory;
    213             LispObject part = temp.car();
    214             if (part == Keyword.ABSOLUTE) {
    215             } else if (part == Keyword.RELATIVE)
    216                 sb.append(';');
    217             else
    218                 error(new FileError("Unsupported directory component " + part.princToString() + ".",
    219                                      this));
    220             temp = temp.cdr();
    221             while (temp != NIL) {
    222                 part = temp.car();
    223                 if (part instanceof AbstractString)
    224                     sb.append(part.getStringValue());
    225                 else if (part == Keyword.WILD)
    226                     sb.append('*');
    227                 else if (part == Keyword.WILD_INFERIORS)
    228                     sb.append("**");
    229                 else if (part == Keyword.UP)
    230                     sb.append("..");
    231                 else
    232                     error(new FileError("Unsupported directory component " + part.princToString() + ".",
    233                                          this));
    234                 sb.append(';');
    235                 temp = temp.cdr();
    236             }
    237         }
    238         return sb.toString();
    239     }
    240 
    241     @Override
    242     public String printObject()
    243     {
    244         final LispThread thread = LispThread.currentThread();
    245         boolean printReadably = (Symbol.PRINT_READABLY.symbolValue(thread) != NIL);
    246         boolean printEscape = (Symbol.PRINT_ESCAPE.symbolValue(thread) != NIL);
    247         StringBuilder sb = new StringBuilder();
    248         if (printReadably || printEscape)
    249             sb.append("#P\"");
    250         sb.append(host.getStringValue());
    251         sb.append(':');
    252         if (directory != NIL)
    253             sb.append(getDirectoryNamestring());
    254         if (name != NIL) {
    255             if (name == Keyword.WILD)
    256                 sb.append('*');
    257             else
    258                 sb.append(name.getStringValue());
    259         }
    260         if (type != NIL) {
    261             sb.append('.');
    262             if (type == Keyword.WILD)
    263                 sb.append('*');
    264             else
    265                 sb.append(type.getStringValue());
    266         }
    267         if (version.integerp()) {
    268             sb.append('.');
    269             int base = Fixnum.getValue(Symbol.PRINT_BASE.symbolValue(thread));
    270             if (version instanceof Fixnum)
    271                 sb.append(Integer.toString(((Fixnum)version).value, base).toUpperCase());
    272             else if (version instanceof Bignum)
    273                 sb.append(((Bignum)version).value.toString(base).toUpperCase());
    274         } else if (version == Keyword.WILD) {
    275             sb.append(".*");
    276         } else if (version == Keyword.NEWEST) {
    277             sb.append(".NEWEST");
    278         }
    279         if (printReadably || printEscape)
    280             sb.append('"');
    281         return sb.toString();
    282     }
     131          result.setVersion(PACKAGE_CL.intern("PARSE-INTEGER").execute(new SimpleString(v)));
     132        }
     133      } else {
     134        String t = rest;
     135        if (t.equals("*")) {
     136          result.setType(Keyword.WILD);
     137        } else {
     138          result.setType(new SimpleString(t.toUpperCase()));
     139        }
     140      }
     141    } else {
     142      String n = rest;
     143      if (n.equals("*")) {
     144        result.setName(Keyword.WILD);
     145      } else if (n.length() > 0) {
     146        result.setName(new SimpleString(n.toUpperCase()));
     147      }
     148    }
     149    return result;
     150  }
     151
     152  public static final SimpleString canonicalizeStringComponent(AbstractString s) {
     153    final int limit = s.length();
     154    for (int i = 0; i < limit; i++) {
     155      char c = s.charAt(i);
     156      if (LOGICAL_PATHNAME_CHARS.indexOf(c) < 0) {
     157        error(new ParseError("Invalid character #\\" + c +
     158                             " in logical pathname component \"" + s +
     159                             '"'));
     160        // Not reached.
     161        return null;
     162      }
     163    }
     164    return new SimpleString(s.getStringValue().toUpperCase());
     165  }
     166
     167  public static Pathname translateLogicalPathname(LogicalPathname pathname) {
     168    return (Pathname) Symbol.TRANSLATE_LOGICAL_PATHNAME.execute(pathname);
     169  }
     170
     171  private static final LispObject parseDirectory(String s) {
     172    LispObject result;
     173    if (s.charAt(0) == ';') {
     174      result = new Cons(Keyword.RELATIVE);
     175      s = s.substring(1);
     176    } else
     177      result = new Cons(Keyword.ABSOLUTE);
     178    StringTokenizer st = new StringTokenizer(s, ";");
     179    while (st.hasMoreTokens()) {
     180      String token = st.nextToken();
     181      LispObject obj;
     182      if (token.equals("*"))
     183        obj = Keyword.WILD;
     184      else if (token.equals("**"))
     185        obj = Keyword.WILD_INFERIORS;
     186      else if (token.equals("..")) {
     187        if (result.car() instanceof AbstractString) {
     188          result = result.cdr();
     189          continue;
     190        }
     191        obj= Keyword.UP;
     192      } else
     193        obj = new SimpleString(token.toUpperCase());
     194      result = new Cons(obj, result);
     195    }
     196    return result.nreverse();
     197  }
     198
     199  @Override
     200  public LispObject typeOf() {
     201    return Symbol.LOGICAL_PATHNAME;
     202  }
     203
     204  @Override
     205  public LispObject classOf() {
     206    return BuiltInClass.LOGICAL_PATHNAME;
     207  }
     208
     209  @Override
     210  public LispObject typep(LispObject type) {
     211    if (type == Symbol.LOGICAL_PATHNAME)
     212      return T;
     213    if (type == BuiltInClass.LOGICAL_PATHNAME)
     214      return T;
     215    return super.typep(type);
     216  }
     217 
     218  @Override
     219  protected String getDirectoryNamestring() {
     220    StringBuilder sb = new StringBuilder();
     221    // "If a pathname is converted to a namestring, the symbols NIL and
     222    // :UNSPECIFIC cause the field to be treated as if it were empty. That
     223    // is, both NIL and :UNSPECIFIC cause the component not to appear in
     224    // the namestring." 19.2.2.2.3.1
     225    if (getDirectory() != NIL) {
     226      LispObject temp = getDirectory();
     227      LispObject part = temp.car();
     228      if (part == Keyword.ABSOLUTE) {
     229      } else if (part == Keyword.RELATIVE)
     230        sb.append(';');
     231      else
     232        error(new FileError("Unsupported directory component " + part.princToString() + ".",
     233                            this));
     234      temp = temp.cdr();
     235      while (temp != NIL) {
     236        part = temp.car();
     237        if (part instanceof AbstractString)
     238          sb.append(part.getStringValue());
     239        else if (part == Keyword.WILD)
     240          sb.append('*');
     241        else if (part == Keyword.WILD_INFERIORS)
     242          sb.append("**");
     243        else if (part == Keyword.UP)
     244          sb.append("..");
     245        else
     246          error(new FileError("Unsupported directory component " + part.princToString() + ".",
     247                              this));
     248        sb.append(';');
     249        temp = temp.cdr();
     250      }
     251    }
     252    return sb.toString();
     253  }
     254
     255  @Override
     256  public String printObject() {
     257    final LispThread thread = LispThread.currentThread();
     258    boolean printReadably = (Symbol.PRINT_READABLY.symbolValue(thread) != NIL);
     259    boolean printEscape = (Symbol.PRINT_ESCAPE.symbolValue(thread) != NIL);
     260    StringBuilder sb = new StringBuilder();
     261    if (printReadably || printEscape)
     262      sb.append("#P\"");
     263    sb.append(getHost().getStringValue());
     264    sb.append(':');
     265    if (getDirectory() != NIL)
     266      sb.append(getDirectoryNamestring());
     267    if (getName() != NIL) {
     268      if (getName() == Keyword.WILD)
     269        sb.append('*');
     270      else
     271        sb.append(getName().getStringValue());
     272    }
     273    if (getType() != NIL) {
     274      sb.append('.');
     275      if (getType() == Keyword.WILD)
     276        sb.append('*');
     277      else
     278        sb.append(getType().getStringValue());
     279    }
     280    if (getVersion().integerp()) {
     281      sb.append('.');
     282      int base = Fixnum.getValue(Symbol.PRINT_BASE.symbolValue(thread));
     283      if (getVersion() instanceof Fixnum)
     284        sb.append(Integer.toString(((Fixnum)getVersion()).value, base).toUpperCase());
     285      else if (getVersion() instanceof Bignum)
     286        sb.append(((Bignum)getVersion()).value.toString(base).toUpperCase());
     287    } else if (getVersion() == Keyword.WILD) {
     288      sb.append(".*");
     289    } else if (getVersion() == Keyword.NEWEST) {
     290      sb.append(".NEWEST");
     291    }
     292    if (printReadably || printEscape)
     293      sb.append('"');
     294    return sb.toString();
     295  }
    283296
    284297    // ### canonicalize-logical-host host => canonical-host
     
    324337                if (Pathname.LOGICAL_PATHNAME_TRANSLATIONS.get(new SimpleString(h)) != null) {
    325338                    // A defined logical pathname host.
    326                     return new LogicalPathname(h, s.substring(s.indexOf(':') + 1));
     339                    return LogicalPathname.create(h, s.substring(s.indexOf(':') + 1));
    327340                }
    328341            }
     
    331344    }
    332345
     346  // "one or more uppercase letters, digits, and hyphens"
     347  protected static String getHostString(String s) {
     348    int colon = s.indexOf(':');
     349    if (colon >= 0) {
     350      return s.substring(0, colon).toUpperCase();
     351    } else {
     352      return null;
     353    }
     354  }
     355
    333356    public long getLastModified() {
    334357        Pathname p = translateLogicalPathname(this);
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r15360 r15391  
    5050public class Pathname extends LispObject implements Serializable {
    5151
     52  protected static Pathname create(Pathname p) {
     53    return new Pathname(p);
     54  }
     55
     56  protected static Pathname create() {
     57    return new Pathname();
     58  }
     59
     60  public static Pathname create(String s) {
     61    // TODO distinguish between logical hosts and schemes for URLs
     62    // which we can meaningfully parse.
     63    if (!isValidURL(s)) {
     64      if (LogicalPathname.isValidLogicalPathname(s)) {
     65        return LogicalPathname.create(s);
     66      }
     67    }
     68    return new Pathname(s);
     69  }
     70
     71  public static Pathname create(String s, String host) {
     72    return LogicalPathname.create(s, host);
     73  }
     74
     75  public static Pathname create(URL url) {
     76    return new Pathname(url);
     77  }
     78
     79  public static Pathname create(URI uri) {
     80    return new Pathname(uri);
     81  }
     82  protected LispObject host = NIL;
     83  public LispObject getHost() {
     84    return host;
     85  }
     86  public LispObject setHost(LispObject host) {
     87    this.host = host;
     88    return this;
     89  }
     90
     91  protected LispObject device = NIL;
     92  public final LispObject getDevice() {
     93    return device;
     94  }
     95  public LispObject setDevice(LispObject device) {
     96    this.device = device;
     97    return this;
     98  }
     99
     100  protected LispObject directory = NIL;
     101  public LispObject getDirectory() {
     102    return directory;
     103  }
     104  public LispObject setDirectory(LispObject directory) {
     105    this.directory = directory;
     106    return this;
     107  }
     108
     109  protected LispObject name = NIL;
     110  public LispObject getName() {
     111    return name;
     112  }
     113  public LispObject setName(LispObject name) {
     114    this.name = name;
     115    return this;
     116  }
     117
     118  /**  A string, NIL, :WILD or :UNSPECIFIC. */
     119  protected LispObject type = NIL;
     120  public LispObject getType() {
     121    return type;
     122  }
     123  public LispObject setType(LispObject type) {
     124    this.type = type;
     125    return this;
     126  }
     127
     128  /** A positive integer, or NIL, :WILD, :UNSPECIFIC, or :NEWEST. */
     129  protected LispObject version = NIL;
     130  public LispObject getVersion() {
     131    return version;
     132  }
     133
     134  public LispObject setVersion(LispObject version) {
     135    this.version = version;
     136    return this;
     137  }
     138
     139
    52140    /** The path component separator used by internally generated
    53141     * path namestrings.
     
    55143    public final static char separator = '/';
    56144
    57     protected LispObject host = NIL;
    58     protected LispObject device = NIL;
    59     protected LispObject directory = NIL;
    60     protected LispObject name = NIL;
    61     // A string, NIL, :WILD or :UNSPECIFIC.
    62     protected LispObject type = NIL;
    63     // A positive integer, or NIL, :WILD, :UNSPECIFIC, or :NEWEST.
    64     protected LispObject version = NIL;
    65 
    66     private volatile String namestring;
     145  private volatile String namestring;
    67146
    68147    /** The protocol for changing any instance field (i.e. 'host',
     
    99178    }
    100179
     180  // If not protected, then inheriting classes cannot invoke their constructors
    101181    protected Pathname() {}
    102182
    103183    /** Copy constructor which shares no structure with the original. */
    104     protected Pathname(Pathname p) {
     184    private Pathname(Pathname p) {
    105185        if (p.host != NIL) {
    106186            if (p.host instanceof SimpleString) {
    107                 host = new SimpleString(((SimpleString)p.host).getStringValue());
     187                host = new SimpleString(((SimpleString)p.getHost()).getStringValue());
    108188            } else  if (p.host instanceof Symbol) {
    109189                host = p.host;
    110190            } else if (p.host instanceof Cons) {
    111                 host = new Cons((Cons)p.host);
     191                host = new Cons((Cons)p.getHost());
    112192            } else {
    113193                Debug.assertTrue(false);
     
    116196        if (p.device != NIL) {
    117197            if (p.device instanceof SimpleString) {
    118                 device = new SimpleString(((SimpleString)p.device).getStringValue());
     198                device = new SimpleString(((SimpleString)p.getDevice()).getStringValue());
    119199            } else if (p.device instanceof Cons) {
    120200                Cons jars = (Cons)p.device;
     
    122202                LispObject first = jars.car();
    123203                if (first instanceof Pathname) {
    124                     ((Cons)device).car = new Pathname((Pathname)first);
     204                    ((Cons)device).car = Pathname.create((Pathname)first);
    125205                } else {
    126206                    Debug.assertTrue(false);
     
    128208                if (!jars.cdr().equals(NIL)) {
    129209                    if (jars.cdr() instanceof Cons) {
    130                         ((Cons)device).cdr = new Cons(new Pathname((Pathname)jars.cdr().car()), NIL);
     210                        ((Cons)device).cdr = new Cons(Pathname.create((Pathname)jars.cdr().car()), NIL);
    131211                    } else {
    132212                        Debug.assertTrue(false);
     
    159239        if (p.name != NIL) {
    160240            if (p.name instanceof SimpleString) {
    161                 name = new SimpleString(((SimpleString)p.name).getStringValue());
     241                name = new SimpleString(((SimpleString)p.getName()).getStringValue());
    162242            } else if (p.name instanceof Symbol) {
    163243                name = p.name;
     
    168248        if (p.type != NIL) {
    169249            if (p.type instanceof SimpleString) {
    170                 type = new SimpleString(((SimpleString)p.type).getStringValue());
     250                type = new SimpleString(((SimpleString)p.getType()).getStringValue());
    171251            } else if (p.type instanceof Symbol) {
    172252                type = p.type;
     
    186266    }
    187267
    188     public Pathname(String s) {
     268    private Pathname(String s) {
    189269        init(s);
    190270    }
     
    209289    }
    210290
    211     public Pathname(URL url) {
     291    private Pathname(URL url) {
    212292         // URL handling is now buried in init(String), as the URI
    213293         // escaping mechanism didn't interact well with '+' and other
     
    216296    }
    217297   
    218     public Pathname(URI uri) {
     298    private Pathname(URI uri) {
    219299        init(uri.toString());
    220300    }
     
    232312        if (s.equals(".") || s.equals("./")
    233313          || (Utilities.isPlatformWindows && s.equals(".\\"))) {
    234             directory = new Cons(Keyword.RELATIVE);
     314            setDirectory(new Cons(Keyword.RELATIVE));
    235315            return;
    236316        }
    237317        if (s.equals("..") || s.equals("../")) {
    238             directory = list(Keyword.RELATIVE, Keyword.UP);
     318            setDirectory(list(Keyword.RELATIVE, Keyword.UP));
    239319            return;
    240320        }
     
    257337            }
    258338
    259             host = new SimpleString(s.substring(2, shareIndex));
    260             device = new SimpleString(s.substring(shareIndex + 1, dirIndex));
    261 
    262             Pathname p = new Pathname(s.substring(dirIndex));
    263             directory = p.directory;
    264             name = p.name;
    265             type = p.type;
    266             version = p.version;
     339            setHost(new SimpleString(s.substring(2, shareIndex)));
     340            setDevice(new SimpleString(s.substring(shareIndex + 1, dirIndex)));
     341
     342            Pathname p = Pathname.create(s.substring(dirIndex));
     343            setDirectory(p.getDirectory());
     344            setName(p.getName());
     345            setType(p.getType());
     346            setVersion(p.getVersion());
    267347            invalidateNamestring();
    268348            return;
     
    282362                jar = "jar:file:" + s.substring(i + jarSeparator.length());
    283363                s = s.substring("jar:".length(), i + jarSeparator.length());
    284                 Pathname p = new Pathname(s);
    285                 jars = jars.push(p.device.car());
     364                Pathname p = Pathname.create(s);
     365                jars = jars.push(p.getDevice().car());
    286366            }
    287367            if (jar.startsWith("jar:file:")) {
     
    309389                        // We allow "jar:file:baz.jar!/" to construct a relative
    310390                        // path for jar files, so MERGE-PATHNAMES means something.
    311                         jarPathname = new Pathname(uri.getSchemeSpecificPart());
     391                        jarPathname = Pathname.create(uri.getSchemeSpecificPart());
    312392                    } else {
    313                         jarPathname = new Pathname((new File(path)).getPath());
     393                        jarPathname = Pathname.create((new File(path)).getPath());
    314394                    }
    315395                } else {
    316                     jarPathname = new Pathname("");
     396                    jarPathname = Pathname.create("");
    317397                }
    318398                jars = jars.push(jarPathname);
     
    321401                try {
    322402                    url = new URL(jar.substring("jar:".length(), jar.length() - 2));
    323                     Pathname p = new Pathname(url);
     403                    Pathname p = Pathname.create(url);
    324404                    jars = jars.push(p);
    325405                } catch (MalformedURLException e) {
     
    330410            }
    331411            jars = jars.nreverse();
    332             device = jars;
     412            setDevice(jars);
    333413            invalidateNamestring();
    334414            return;
     
    347427                                    + ex.getMessage()));
    348428            }
    349             Pathname d = new Pathname(url);
    350             if (device instanceof Cons) {
     429            Pathname d = Pathname.create(url);
     430            if (getDevice() instanceof Cons) {
    351431                LispObject[] jars = d.copyToArray();
    352432                //  XXX Is this ever reached?  If so, need to append lists
    353433                Debug.assertTrue(false);
    354434            } else {
    355                 device = d.device;
     435                setDevice(d.getDevice());
    356436            }
    357437            s = "/" + s.substring(separatorIndex + jarSeparator.length());
    358             Pathname p = new Pathname("file:" + s); // Use URI escaping rules
    359             directory = p.directory;
    360             name = p.name;
    361             type = p.type;
    362             version = p.version;
     438            Pathname p = Pathname.create("file:" + s); // Use URI escaping rules
     439            setDirectory(p.getDirectory());
     440            setName(p.getName());
     441            setType(p.getType());
     442            setVersion(p.getVersion());
    363443            return;
    364444        }
     
    397477                  path += "/";
    398478                }
    399                 final Pathname p = new Pathname(path);
    400                 this.host = p.host;
    401                 this.device = p.device;
    402                 this.directory = p.directory;
    403                 this.name = p.name;
    404                 this.type = p.type;
    405                 this.version = p.version;
     479                final Pathname p = Pathname.create(path);
     480                this.setHost(p.getHost());
     481                this.setDevice(p.getDevice());
     482                this.setDirectory(p.getDirectory());
     483                this.setName(p.getName());
     484                this.setType(p.getType());
     485                this.setVersion(p.getVersion());
    406486                return;
    407487            }
     
    423503        }
    424504
    425         host = NIL;
    426         host = host.push(SCHEME);
    427         host = host.push(new SimpleString(scheme));
     505        setHost(NIL);
     506        setHost(getHost().push(SCHEME));
     507        setHost(getHost().push(new SimpleString(scheme)));
    428508
    429509        if (authority != null) {
    430           host = host.push(AUTHORITY);
    431           host = host.push(new SimpleString(authority));
    432         }
    433 
    434         device = NIL;
     510          setHost(getHost().push(AUTHORITY));
     511          setHost(getHost().push(new SimpleString(authority)));
     512        }
     513
     514        setDevice(NIL);
    435515           
    436516        // URI encode necessary characters
     
    441521        String query = uri.getRawQuery();
    442522        if (query != null) {
    443           host = host.push(QUERY);
    444                 host = host.push(new SimpleString(query));
     523          setHost(getHost().push(QUERY));
     524                setHost(getHost().push(new SimpleString(query)));
    445525            }
    446526            String fragment = uri.getRawFragment();
    447527            if (fragment != null) {
    448                 host = host.push(FRAGMENT);
    449                 host = host.push(new SimpleString(fragment));
    450             }
    451             Pathname p = new Pathname(path != null ? path : "");
    452 
    453             directory = p.directory;
    454             name = p.name;
    455             type = p.type;
     528                setHost(getHost().push(FRAGMENT));
     529                setHost(getHost().push(new SimpleString(fragment)));
     530            }
     531            Pathname p = Pathname.create(path != null ? path : "");
     532
     533            setDirectory(p.getDirectory());
     534            setName(p.getName());
     535            setType(p.getType());
    456536           
    457             host = host.nreverse();
     537            setHost(getHost().nreverse());
    458538            invalidateNamestring();
    459539            return;
     
    477557        if (Utilities.isPlatformWindows) {
    478558            if (s.length() >= 2 && s.charAt(1) == ':') {
    479                 device = new SimpleString(s.charAt(0));
     559                setDevice(new SimpleString(s.charAt(0)));
    480560                s = s.substring(2);
    481561            }
     
    495575                s = "";
    496576            }
    497             directory = parseDirectory(d);
     577            setDirectory(parseDirectory(d));
    498578        }
    499579        if (s.startsWith(".")
     
    501581            && (s.indexOf(".", 1) == -1
    502582                || s.substring(s.length() -1).equals("."))) {
    503             name = new SimpleString(s);
     583            setName(new SimpleString(s));
    504584            return;
    505585        }
     
    515595        if (n != null) {
    516596            if (n.equals("*")) {
    517                 name = Keyword.WILD;
    518             } else {
    519                 name = new SimpleString(n);
     597                setName(Keyword.WILD);
     598            } else {
     599                setName(new SimpleString(n));
    520600            }
    521601        }
    522602        if (t != null) {
    523603            if (t.equals("*")) {
    524                 type = Keyword.WILD;
    525             } else {
    526                 type = new SimpleString(t);
     604                setType(Keyword.WILD);
     605            } else {
     606                setType(new SimpleString(t));
    527607            }
    528608        }
     
    564644    public LispObject getParts() {
    565645        LispObject parts = NIL;
    566         parts = parts.push(new Cons("HOST", host));
    567         parts = parts.push(new Cons("DEVICE", device));
    568         parts = parts.push(new Cons("DIRECTORY", directory));
    569         parts = parts.push(new Cons("NAME", name));
    570         parts = parts.push(new Cons("TYPE", type));
    571         parts = parts.push(new Cons("VERSION", version));
     646        parts = parts.push(new Cons("HOST", getHost()));
     647        parts = parts.push(new Cons("DEVICE", getDevice()));
     648        parts = parts.push(new Cons("DIRECTORY", getDirectory()));
     649        parts = parts.push(new Cons("NAME", getName()));
     650        parts = parts.push(new Cons("TYPE", getType()));
     651        parts = parts.push(new Cons("VERSION", getVersion()));
    572652        return parts.nreverse();
    573653    }
     
    618698    }
    619699
    620     public final LispObject getDevice() {
    621         return device;
    622     }
    623 
    624700    public String getNamestring() {
    625701        if (namestring != null) {
    626702            return namestring;
    627703        }
    628         if (name == NIL && type != NIL) {
     704        if (getName() == NIL && getType() != NIL) {
    629705            Debug.assertTrue(namestring == null);
    630706            return null;
    631707        }
    632         if (directory instanceof AbstractString) {
     708        if (getDirectory() instanceof AbstractString) {
    633709            Debug.assertTrue(false);
    634710        }
     
    638714        // is, both NIL and :UNSPECIFIC cause the component not to appear in
    639715        // the namestring." 19.2.2.2.3.1
    640         if (host != NIL) {
    641             Debug.assertTrue(host instanceof AbstractString
     716        if (getHost() != NIL) {
     717            Debug.assertTrue(getHost() instanceof AbstractString
    642718                             || isURL());
    643719            if (isURL()) {
    644                 LispObject scheme = Symbol.GETF.execute(host, SCHEME, NIL);
    645                 LispObject authority = Symbol.GETF.execute(host, AUTHORITY, NIL);
     720                LispObject scheme = Symbol.GETF.execute(getHost(), SCHEME, NIL);
     721                LispObject authority = Symbol.GETF.execute(getHost(), AUTHORITY, NIL);
    646722                Debug.assertTrue(scheme != NIL);
    647723                sb.append(scheme.getStringValue());
     
    652728                }
    653729            } else if (this instanceof LogicalPathname) {
    654                 sb.append(host.getStringValue());
     730                sb.append(getHost().getStringValue());
    655731                sb.append(':');
    656732            } else {
    657733              // A UNC path
    658               sb.append("//").append(host.getStringValue()).append("/");
     734              sb.append("//").append(getHost().getStringValue()).append("/");
    659735            }
    660736        }
    661737        boolean uriEncoded = false;
    662         if (device == NIL) {
    663         } else if (device == Keyword.UNSPECIFIC) {
     738        if (getDevice() == NIL) {
     739        } else if (getDevice() == Keyword.UNSPECIFIC) {
    664740        } else if (isJar()) {
    665             LispObject[] jars = ((Cons) device).copyToArray();
     741            LispObject[] jars = ((Cons) getDevice()).copyToArray();
    666742            StringBuilder prefix = new StringBuilder();
    667743            for (int i = 0; i < jars.length; i++) {
     
    686762            }
    687763            sb = prefix.append(sb);
    688         } else if (device instanceof AbstractString) {
    689             sb.append(device.getStringValue());
     764        } else if (getDevice() instanceof AbstractString) {
     765            sb.append(getDevice().getStringValue());
    690766            if (this instanceof LogicalPathname
    691                 || host == NIL) {
     767                || getHost() == NIL) {
    692768              sb.append(':'); // non-UNC paths
    693769            }
     
    708784            sb.append(directoryNamestring);
    709785        }
    710         if (name instanceof AbstractString) {
    711             String n = name.getStringValue();
     786        if (getName() instanceof AbstractString) {
     787            String n = getName().getStringValue();
    712788            if (n.indexOf('/') >= 0) {
    713789                Debug.assertTrue(namestring == null);
     
    719795                sb.append(n);
    720796            }
    721         } else if (name == Keyword.WILD) {
     797        } else if (getName() == Keyword.WILD) {
    722798            sb.append('*');
    723799        }
    724         if (type != NIL && type != Keyword.UNSPECIFIC) {
     800        if (getType() != NIL && getType() != Keyword.UNSPECIFIC) {
    725801            sb.append('.');
    726             if (type instanceof AbstractString) {
    727                 String t = type.getStringValue();
     802            if (getType() instanceof AbstractString) {
     803                String t = getType().getStringValue();
    728804                // Allow Windows shortcuts to include TYPE
    729805                if (!(t.endsWith(".lnk") && Utilities.isPlatformWindows)) {
     
    738814                    sb.append(t);
    739815                }
    740             } else if (type == Keyword.WILD) {
     816            } else if (getType() == Keyword.WILD) {
    741817                sb.append('*');
    742818            } else {
     
    746822       
    747823        if (isURL()) {
    748             LispObject o = Symbol.GETF.execute(host, QUERY, NIL);
     824            LispObject o = Symbol.GETF.execute(getHost(), QUERY, NIL);
    749825            if (o != NIL) {
    750826                sb.append("?");
    751827                sb.append(o.getStringValue());
    752828            }
    753             o = Symbol.GETF.execute(host, FRAGMENT, NIL);
     829            o = Symbol.GETF.execute(getHost(), FRAGMENT, NIL);
    754830            if (o != NIL) {
    755831                sb.append("#");
     
    759835           
    760836        if (this instanceof LogicalPathname) {
    761             if (version.integerp()) {
     837            if (getVersion().integerp()) {
    762838                sb.append('.');
    763839                int base = Fixnum.getValue(Symbol.PRINT_BASE.symbolValue());
    764                 if (version instanceof Fixnum) {
    765                     sb.append(Integer.toString(((Fixnum) version).value, base).toUpperCase());
    766                 } else if (version instanceof Bignum) {
    767                     sb.append(((Bignum) version).value.toString(base).toUpperCase());
    768                 }
    769             } else if (version == Keyword.WILD) {
     840                if (getVersion() instanceof Fixnum) {
     841                    sb.append(Integer.toString(((Fixnum) getVersion()).value, base).toUpperCase());
     842                } else if (getVersion() instanceof Bignum) {
     843                    sb.append(((Bignum) getVersion()).value.toString(base).toUpperCase());
     844                }
     845            } else if (getVersion() == Keyword.WILD) {
    770846                sb.append(".*");
    771             } else if (version == Keyword.NEWEST) {
     847            } else if (getVersion() == Keyword.NEWEST) {
    772848                sb.append(".NEWEST");
    773849            }
     
    788864        // is, both NIL and :UNSPECIFIC cause the component not to appear in
    789865        // the namestring." 19.2.2.2.3.1
    790         if (directory != NIL && directory != Keyword.UNSPECIFIC) {
     866        if (getDirectory() != NIL && getDirectory() != Keyword.UNSPECIFIC) {
    791867            final char separatorChar = '/';
    792             LispObject temp = directory;
     868            LispObject temp = getDirectory();
    793869            LispObject part = temp.car();
    794870            temp = temp.cdr();
     
    829905     */
    830906    protected String asEntryPath() {
    831         Pathname p = new Pathname();
    832         p.directory = directory;
    833         p.name = name;
    834         p.type = type;
     907        Pathname p = Pathname.create();
     908        p.setDirectory(getDirectory());
     909        p.setName(getName());
     910        p.setType(getType());
    835911        p.invalidateNamestring();
    836912        String path = p.getNamestring();
     
    906982    @Override
    907983    public int sxhash() {
    908         return ((host.sxhash()
    909           ^ device.sxhash()
    910           ^ directory.sxhash()
    911           ^ name.sxhash()
    912           ^ type.sxhash()) & 0x7fffffff);
     984        return ((getHost().sxhash()
     985          ^ getDevice().sxhash()
     986          ^ getDirectory().sxhash()
     987          ^ getName().sxhash()
     988          ^ getType().sxhash()) & 0x7fffffff);
    913989    }
    914990
     
    9261002                // We have a namestring. Check for pathname components that
    9271003                // can't be read from the namestring.
    928                 if ((host != NIL && !isURL())
    929                     || version != NIL)
     1004                if ((getHost() != NIL && !isURL())
     1005                    || getVersion() != NIL)
    9301006                {
    9311007                    useNamestring = false;
    932                 } else if (name instanceof AbstractString) {
    933                     String n = name.getStringValue();
     1008                } else if (getName() instanceof AbstractString) {
     1009                    String n = getName().getStringValue();
    9341010                    if (n.equals(".") || n.equals("..")) {
    9351011                        useNamestring = false;
     
    9651041
    9661042        sb.append("PATHNAME (with no namestring) ");
    967         if (host != NIL) {
     1043        if (getHost() != NIL) {
    9681044            sb.append(":HOST ");
    969             sb.append(host.printObject());
     1045            sb.append(getHost().printObject());
    9701046            sb.append(" ");
    9711047        }
    972         if (device != NIL) {
     1048        if (getDevice() != NIL) {
    9731049            sb.append(":DEVICE ");
    974             sb.append(device.printObject());
     1050            sb.append(getDevice().printObject());
    9751051            sb.append(" ");
    9761052        }
    977         if (directory != NIL) {
     1053        if (getDirectory() != NIL) {
    9781054            sb.append(":DIRECTORY ");
    979             sb.append(directory.printObject());
     1055            sb.append(getDirectory().printObject());
    9801056            sb.append(" ");
    9811057        }
    982         if (name != NIL) {
     1058        if (getName() != NIL) {
    9831059            sb.append(":NAME ");
    984             sb.append(name.printObject());
     1060            sb.append(getName().printObject());
    9851061            sb.append(" ");
    9861062        }
    987         if (type != NIL) {
     1063        if (getType() != NIL) {
    9881064            sb.append(":TYPE ");
    989             sb.append(type.printObject());
     1065            sb.append(getType().printObject());
    9901066            sb.append(" ");
    9911067        }
    992         if (version != NIL) {
     1068        if (getVersion() != NIL) {
    9931069            sb.append(":VERSION ");
    994             sb.append(version.printObject());
     1070            sb.append(getVersion().printObject());
    9951071            sb.append(" ");
    9961072        }
     
    10101086
    10111087    public static Pathname parseNamestring(String s) {
    1012         return new Pathname(s);
     1088        return Pathname.create(s);
    10131089    }
    10141090
     
    10291105            URL url = new URL(s);
    10301106        } catch (MalformedURLException e) {
    1031             // Generating an exception is a heavy operation,
    1032             // we want to try hard not to get into this branch, without
    1033             // implementing the URL class ourselves
    1034             return false;
     1107          return false;
    10351108        }
    10361109        return true;
     
    10631136        String s = namestring.getStringValue();
    10641137        if (!isValidURL(s)) {
    1065             String h = getHostString(s);
     1138            String h = LogicalPathname.getHostString(s);
    10661139            if (h != null && LOGICAL_PATHNAME_TRANSLATIONS.get(new SimpleString(h)) != null) {
    10671140                // A defined logical pathname host.
    1068                 return new LogicalPathname(h, s.substring(s.indexOf(':') + 1));
    1069             }
    1070         }
    1071         return new Pathname(s);
     1141                return LogicalPathname.create(h, s.substring(s.indexOf(':') + 1));
     1142            }
     1143        }
     1144        return Pathname.create(s);
    10721145    }
    10731146
     
    10791152
    10801153        // Look for a logical pathname host in the namestring.       
    1081         String h = getHostString(s);
     1154        String h = LogicalPathname.getHostString(s);
    10821155        if (h != null) {
    10831156            if (!h.equals(host.getStringValue())) {
     
    10931166        if (LOGICAL_PATHNAME_TRANSLATIONS.get(host) != null) {
    10941167            // A defined logical pathname host.
    1095             return new LogicalPathname(host.getStringValue(), s);
     1168            return LogicalPathname.create(host.getStringValue(), s);
    10961169        }
    10971170        error(new LispError(host.princToString() + " is not defined as a logical pathname host."));
    10981171        // Not reached.
    10991172        return null;
    1100     }
    1101 
    1102     // "one or more uppercase letters, digits, and hyphens"
    1103     protected static String getHostString(String s) {
    1104         int colon = s.indexOf(':');
    1105         if (colon >= 0) {
    1106             return s.substring(0, colon).toUpperCase();
    1107         } else {
    1108             return null;
    1109         }
    11101173    }
    11111174
     
    11261189        public LispObject execute(LispObject first, LispObject second) {
    11271190            checkCaseArgument(second); // FIXME Why is this ignored?
    1128             return coerceToPathname(first).host;
     1191            return coerceToPathname(first).getHost();
    11291192        }
    11301193    }
     
    11381201        public LispObject execute(LispObject first, LispObject second) {
    11391202            checkCaseArgument(second); // FIXME Why is this ignored?
    1140             return coerceToPathname(first).device;
     1203            return coerceToPathname(first).getDevice();
    11411204        }
    11421205    }
     
    11501213        public LispObject execute(LispObject first, LispObject second) {
    11511214            checkCaseArgument(second); // FIXME Why is this ignored?
    1152             return coerceToPathname(first).directory;
     1215            return coerceToPathname(first).getDirectory();
    11531216        }
    11541217    }
     
    11621225        public LispObject execute(LispObject first, LispObject second) {
    11631226            checkCaseArgument(second); // FIXME Why is this ignored?
    1164             return coerceToPathname(first).name;
     1227            return coerceToPathname(first).getName();
    11651228        }
    11661229    }
     
    11741237        public LispObject execute(LispObject first, LispObject second) {
    11751238            checkCaseArgument(second); // FIXME Why is this ignored?
    1176             return coerceToPathname(first).type;
     1239            return coerceToPathname(first).getType();
    11771240        }
    11781241    }
     
    11891252        @Override
    11901253        public LispObject execute(LispObject arg) {
    1191             return coerceToPathname(arg).version;
     1254            return coerceToPathname(arg).getVersion();
    11921255        }
    11931256    }
     
    12691332                third = coerceToPathname(third);
    12701333                if (third instanceof LogicalPathname) {
    1271                     second = ((LogicalPathname) third).host;
     1334                    second = ((LogicalPathname) third).getHost();
    12721335                } else {
    12731336                    return thread.setValues(parseNamestring(namestring),
     
    13111374            return null;
    13121375        }
    1313         return new Pathname(namestring);
     1376        return Pathname.create(namestring);
    13141377    }
    13151378
     
    13831446        if (defaults != null) {
    13841447            if (!hostSupplied) {
    1385                 host = defaults.host;
     1448                host = defaults.getHost();
    13861449            }
    13871450            if (!directorySupplied) {
    1388                 directory = defaults.directory;
     1451                directory = defaults.getDirectory();
    13891452            }
    13901453            if (!deviceSupplied) {
    1391                 device = defaults.device;
     1454                device = defaults.getDevice();
    13921455            }
    13931456            if (!nameSupplied) {
    1394                 name = defaults.name;
     1457                name = defaults.getName();
    13951458            }
    13961459            if (!typeSupplied) {
    1397                 type = defaults.type;
     1460                type = defaults.getType();
    13981461            }
    13991462            if (!versionSupplied) {
    1400                 version = defaults.version;
     1463                version = defaults.getVersion();
    14011464            }
    14021465        }
     
    14111474                // Not a defined logical pathname host -- A UNC path
    14121475                //warning(new LispError(host.printObject() + " is not defined as a logical pathname host."));
    1413                 p = new Pathname();
     1476                p = Pathname.create();
    14141477                logical = false;
    1415                 p.host = host;
     1478                p.setHost(host);
    14161479            } else {
    1417                 p = new LogicalPathname();
     1480                p = LogicalPathname.create();
    14181481                logical = true;
    1419                 p.host = logicalHost;
    1420             }
    1421             p.device = Keyword.UNSPECIFIC;
     1482                p.setHost(logicalHost);
     1483            }
     1484            p.setDevice(Keyword.UNSPECIFIC);
    14221485        } else {
    1423             p = new Pathname();
     1486            p = Pathname.create();
    14241487            logical = false;
    14251488        }
     
    14311494                }
    14321495            } else {
    1433                 p.device = device;
     1496              p.setDevice(device);
    14341497            }
    14351498        }
     
    14471510                        directory = directory.cdr();
    14481511                    }
    1449                     p.directory = d.nreverse();
     1512                    p.setDirectory(d.nreverse());
    14501513                } else if (directory == Keyword.WILD || directory == Keyword.WILD_INFERIORS) {
    1451                     p.directory = directory;
     1514                  p.setDirectory(directory);
    14521515                } else {
    14531516                    error(new LispError("Invalid directory component for logical pathname: " + directory.princToString()));
    14541517                }
    14551518            } else {
    1456                 p.directory = directory;
     1519              p.setDirectory(directory);
    14571520            }
    14581521        }
    14591522        if (name != NIL) {
    14601523            if (logical && name instanceof AbstractString) {
    1461                 p.name = LogicalPathname.canonicalizeStringComponent((AbstractString) name);
     1524              p.setName(LogicalPathname.canonicalizeStringComponent((AbstractString) name));
    14621525            } else if (name instanceof AbstractString) {
    1463                 p.name = validateStringComponent((AbstractString) name);
    1464             } else {
    1465                 p.name = name;
     1526              p.setName(validateStringComponent((AbstractString) name));
     1527            } else {
     1528              p.setName(name);
    14661529            }
    14671530        }
    14681531        if (type != NIL) {
    14691532            if (logical && type instanceof AbstractString) {
    1470                 p.type = LogicalPathname.canonicalizeStringComponent((AbstractString) type);
    1471             } else {
    1472                 p.type = type;
     1533              p.setType(LogicalPathname.canonicalizeStringComponent((AbstractString) type));
     1534            } else {
     1535              p.setType(type);
    14731536            }
    14741537        }
    14751538       
    1476         p.version = version;
     1539        p.setVersion(version);
    14771540        p.validateDirectory(true);
    14781541        return p;
     
    14961559
    14971560    private final boolean validateDirectory(boolean signalError) {
    1498         LispObject temp = directory;
     1561        LispObject temp = getDirectory();
    14991562        if (temp == Keyword.UNSPECIFIC) {
    15001563            return true;
     
    15791642                    s = s.concat(File.separator);
    15801643                }
    1581                 return new Pathname(s);
     1644                return Pathname.create(s);
    15821645            }
    15831646            case 1:
     
    16141677                Debug.assertTrue(directory != null);  // We should only be listing directories
    16151678
    1616                 if (pathname.device.cdr() instanceof Cons) {
     1679                if (pathname.getDevice().cdr() instanceof Cons) {
    16171680                    return error(new FileError("Unimplemented directory listing of JAR within JAR.", pathname));
    16181681                }
     
    16301693                SimpleString wildcardDirectory = new SimpleString(directory + "/");
    16311694
    1632                 ZipFile jar = ZipCache.get((Pathname)pathname.device.car());
     1695                ZipFile jar = ZipCache.get((Pathname)pathname.getDevice().car());
    16331696                LispObject matches;
    16341697                for (Enumeration<? extends ZipEntry> entries = jar.entries();
     
    16481711                        namestring = namestring.substring(0, namestring.lastIndexOf("!/") + 2)
    16491712                                 + entry.getName();
    1650                         Pathname p = new Pathname(namestring);
     1713                        Pathname p = Pathname.create(namestring);
    16511714                        result = new Cons(p, result);
    16521715                    }
     
    16801743                            }
    16811744                            URI pathURI = (new File(path)).toURI();
    1682                             p = new Pathname(pathURI);
     1745                            p = Pathname.create(pathURI);
    16831746                            result = new Cons(p, result);
    16841747                        }
     
    17191782                return new FileError("Not a wild pathname.", pathname);
    17201783            }
    1721             Pathname jarPathname = new Pathname(pathname);
    1722             jarPathname.directory = NIL;
    1723             jarPathname.name = NIL;
    1724             jarPathname.type = NIL;
     1784            Pathname jarPathname = Pathname.create(pathname);
     1785            jarPathname.setDirectory(NIL);
     1786            jarPathname.setName(NIL);
     1787            jarPathname.setType(NIL);
    17251788            jarPathname.invalidateNamestring();
    17261789            LispObject jarTruename = truename(jarPathname, false);
     
    17351798            final SimpleString wildcard = new SimpleString(wild);
    17361799
    1737             if (pathname.device.cdr() instanceof Cons) {
    1738                 ZipFile outerJar = ZipCache.get((Pathname)pathname.device.car());
    1739                 String entryPath = ((Pathname)pathname.device.cdr().car()).getNamestring(); //???
     1800            if (pathname.getDevice().cdr() instanceof Cons) {
     1801                ZipFile outerJar = ZipCache.get((Pathname)pathname.getDevice().car());
     1802                String entryPath = ((Pathname)pathname.getDevice().cdr().car()).getNamestring(); //???
    17401803                if (entryPath.startsWith("/")) {
    17411804                    entryPath = entryPath.substring(1);
     
    17621825                            namestring = namestring.substring(0, namestring.lastIndexOf("!/") + 2)
    17631826                                + entry.getName();
    1764                             Pathname p = new Pathname(namestring);
     1827                            Pathname p = Pathname.create(namestring);
    17651828                            result = new Cons(p, result);
    17661829                        }
     
    17711834                }
    17721835            } else {
    1773                 ZipFile jar = ZipCache.get((Pathname)pathname.device.car());
     1836                ZipFile jar = ZipCache.get((Pathname)pathname.getDevice().car());
    17741837                for (Enumeration<? extends ZipEntry> entries = jar.entries();
    17751838                     entries.hasMoreElements();)
     
    17841847                            namestring = namestring.substring(0, namestring.lastIndexOf("!/") + 2)
    17851848                                + entry.getName();
    1786                             Pathname p = new Pathname(namestring);
     1849                            Pathname p = Pathname.create(namestring);
    17871850                            result = new Cons(p, result);
    17881851                        }
     
    17951858    public boolean isAbsolute()  {
    17961859        if (!directory.equals(NIL) || !(directory == null)) {
    1797             if (directory instanceof Cons) {
    1798                 if (((Cons)directory).car().equals(Keyword.ABSOLUTE)) {
     1860            if (getDirectory() instanceof Cons) {
     1861                if (((Cons)getDirectory()).car().equals(Keyword.ABSOLUTE)) {
    17991862                    return true;
    18001863                }
     
    18211884
    18221885    public boolean isJar() {
    1823         return (device instanceof Cons);
     1886        return (getDevice() instanceof Cons);
    18241887    }
    18251888
     
    18421905
    18431906    public boolean isURL() {
    1844         return (host instanceof Cons);
     1907        return (getHost() instanceof Cons);
    18451908    }
    18461909
    18471910    public boolean isWild() {
    1848         if (host == Keyword.WILD || host == Keyword.WILD_INFERIORS) {
     1911        if (getHost() == Keyword.WILD || getHost() == Keyword.WILD_INFERIORS) {
    18491912            return true;
    18501913        }
    1851         if (device == Keyword.WILD || device == Keyword.WILD_INFERIORS) {
     1914        if (getDevice() == Keyword.WILD || getDevice() == Keyword.WILD_INFERIORS) {
    18521915            return true;
    18531916        }
    1854         if (directory instanceof Cons) {
    1855             if (memq(Keyword.WILD, directory)) {
     1917        if (getDirectory() instanceof Cons) {
     1918            if (memq(Keyword.WILD, getDirectory())) {
    18561919                return true;
    18571920            }
    1858             if (memq(Keyword.WILD_INFERIORS, directory)) {
     1921            if (memq(Keyword.WILD_INFERIORS, getDirectory())) {
    18591922                return true;
    18601923            }
    1861             Cons d = (Cons) directory;
     1924            Cons d = (Cons) getDirectory();
    18621925            while (true) {
    18631926                if (d.car() instanceof AbstractString) {
     
    18731936            }
    18741937        }
    1875         if (name == Keyword.WILD || name == Keyword.WILD_INFERIORS) {
     1938        if (getName() == Keyword.WILD || getName() == Keyword.WILD_INFERIORS) {
    18761939            return true;
    18771940        }
    1878         if (name instanceof AbstractString) {
    1879             if (name.printObject().contains("*")) {
     1941        if (getName() instanceof AbstractString) {
     1942            if (getName().printObject().contains("*")) {
    18801943                return true;
    18811944            }
    18821945        }
    1883         if (type == Keyword.WILD || type == Keyword.WILD_INFERIORS) {
     1946        if (getType() == Keyword.WILD || getType() == Keyword.WILD_INFERIORS) {
    18841947            return true;
    18851948        }
    1886         if (type instanceof AbstractString) {
    1887             if (type.printObject().contains("*")) {
     1949        if (getType() instanceof AbstractString) {
     1950            if (getType().printObject().contains("*")) {
    18881951                return true;
    18891952            }
    18901953        }
    1891         if (version == Keyword.WILD || version == Keyword.WILD_INFERIORS) {
     1954        if (getVersion() == Keyword.WILD || getVersion() == Keyword.WILD_INFERIORS) {
    18921955            return true;
    18931956        }
     
    19141977            }
    19151978            if (second == Keyword.DIRECTORY) {
    1916                 if (pathname.directory instanceof Cons) {
    1917                     if (memq(Keyword.WILD, pathname.directory)) {
     1979                if (pathname.getDirectory() instanceof Cons) {
     1980                    if (memq(Keyword.WILD, pathname.getDirectory())) {
    19181981                        return T;
    19191982                    }
    1920                     if (memq(Keyword.WILD_INFERIORS, pathname.directory)) {
     1983                    if (memq(Keyword.WILD_INFERIORS, pathname.getDirectory())) {
    19211984                        return T;
    19221985                    }
     
    19261989            LispObject value;
    19271990            if (second == Keyword.HOST) {
    1928                 value = pathname.host;
     1991                value = pathname.getHost();
    19291992            } else if (second == Keyword.DEVICE) {
    1930                 value = pathname.device;
     1993                value = pathname.getDevice();
    19311994            } else if (second == Keyword.NAME) {
    1932                 value = pathname.name;
     1995                value = pathname.getName();
    19331996            } else if (second == Keyword.TYPE) {
    1934                 value = pathname.type;
     1997                value = pathname.getType();
    19351998            } else if (second == Keyword.VERSION) {
    1936                 value = pathname.version;
     1999                value = pathname.getVersion();
    19372000            } else {
    19382001                return program_error("Unrecognized keyword "
     
    19932056    {
    19942057        Pathname result;
    1995         Pathname p = new Pathname(pathname);
     2058        Pathname p = Pathname.create(pathname);
    19962059        Pathname d;
    19972060
    19982061        if (pathname instanceof LogicalPathname) {
    1999             result = new LogicalPathname();
    2000             d = new Pathname(defaultPathname);
     2062            result = LogicalPathname.create();
     2063            d = Pathname.create(defaultPathname);
    20012064        } else {
    2002             result = new Pathname();
     2065            result = Pathname.create();
    20032066            if (defaultPathname instanceof LogicalPathname) {
    20042067                d = LogicalPathname.translateLogicalPathname((LogicalPathname) defaultPathname);
    20052068            } else {
    2006                 d = new Pathname(defaultPathname);
    2007             }
    2008         }
    2009         if (pathname.host != NIL) {
    2010             result.host = p.host;
     2069                d = Pathname.create(defaultPathname);
     2070            }
     2071        }
     2072        if (pathname.getHost() != NIL) {
     2073          result.setHost(p.getHost());
    20112074        } else {
    2012             result.host = d.host;
    2013         }
    2014 
    2015         if (pathname.device != NIL) { // XXX if device represent JARs we want to merge
    2016             result.device = p.device;
     2075          result.setHost(d.getHost());
     2076        }
     2077
     2078        if (pathname.getDevice() != NIL) { // XXX if device represent JARs we want to merge
     2079          result.setDevice(p.getDevice());
    20172080        } else {
    20182081            if (!p.isURL()) {
     
    20222085                // relative DIRECTORY, then on non-MSDOG, set its
    20232086                // device to :UNSPECIFIC.
    2024                 if (pathname.host == NIL
    2025                     && pathname.device == NIL
     2087                if (pathname.getHost() == NIL
     2088                    && pathname.getDevice() == NIL
    20262089                    && d.isJar()
    20272090                    && !Utilities.isPlatformWindows) {
    2028                     if (pathname.directory != NIL
    2029                         && pathname.directory.car() == Keyword.ABSOLUTE) {
    2030                         result.device = Keyword.UNSPECIFIC;
     2091                    if (pathname.getDirectory() != NIL
     2092                        && pathname.getDirectory().car() == Keyword.ABSOLUTE) {
     2093                      result.setDevice(Keyword.UNSPECIFIC);
    20312094                    } else {
    2032                         result.device = d.device;
     2095                      result.setDevice(d.getDevice());
    20332096                    }
    20342097                } else {
    2035                     result.device = d.device;
     2098                  result.setDevice(d.getDevice());
    20362099                }
    20372100            }
     
    20392102
    20402103        if (pathname.isJar()) {
    2041             Cons jars = (Cons)result.device;
     2104            Cons jars = (Cons)result.getDevice();
    20422105            LispObject jar = jars.car;
    20432106            if (jar instanceof Pathname) {
    2044                 Pathname defaults = new Pathname(d);
     2107                Pathname defaults = Pathname.create(d);
    20452108                if (defaults.isJar()) {
    2046                     defaults.device = NIL;
     2109                  defaults.setDevice(NIL);
    20472110                }
    20482111                Pathname o = mergePathnames((Pathname)jar, defaults);
    2049                 if (o.directory instanceof Cons
    2050                     && ((Cons)o.directory).length() == 1) { // i.e. (:ABSOLUTE) or (:RELATIVE)
    2051                     o.directory = NIL;
     2112                if (o.getDirectory() instanceof Cons
     2113                    && ((Cons)o.getDirectory()).length() == 1) { // i.e. (:ABSOLUTE) or (:RELATIVE)
     2114                  o.setDirectory(NIL);
    20522115                }
    20532116                ((Cons)result.device).car = o;
    20542117            }
    2055             result.directory = p.directory;
     2118            result.setDirectory(p.getDirectory());
    20562119        } else {
    2057             result.directory = mergeDirectories(p.directory, d.directory);
    2058         }
    2059 
    2060         if (pathname.name != NIL) {
    2061             result.name = p.name;
     2120          result.setDirectory(mergeDirectories(p.getDirectory(), d.getDirectory()));
     2121        }
     2122
     2123        if (pathname.getName() != NIL) {
     2124          result.setName(p.getName());
    20622125        } else {
    2063             result.name = d.name;
    2064         }
    2065         if (pathname.type != NIL) {
    2066             result.type = p.type;
     2126          result.setName(d.getName());
     2127        }
     2128        if (pathname.getType() != NIL) {
     2129          result.setType(p.getType());
    20672130        } else {
    2068             result.type = d.type;
     2131          result.setType(d.getType());
    20692132        }
    20702133        //  CLtLv2 MERGE-PATHNAMES
     
    20852148    // version missing, the default version is used."
    20862149
    2087         if (p.version != NIL) {
    2088             result.version = p.version;
    2089         } else if (p.name == NIL) {
    2090             if (defaultPathname.version == NIL) {
    2091                 result.version = defaultVersion;
    2092             } else {
    2093                 result.version = defaultPathname.version;
     2150        if (p.getVersion() != NIL) {
     2151          result.setVersion(p.getVersion());
     2152        } else if (p.getName() == NIL) {
     2153            if (defaultPathname.getVersion() == NIL) {
     2154              result.setVersion(defaultVersion);
     2155            } else {
     2156              result.setVersion(defaultPathname.getVersion());
    20942157            }
    20952158        } else if (defaultVersion == NIL) {
    2096             result.version = p.version;
     2159          result.setVersion(p.getVersion());
    20972160        }
    2098         if (result.version == NIL) {
    2099             result.version = defaultVersion;
     2161        if (result.getVersion() == NIL) {
     2162          result.setVersion(defaultVersion);
    21002163        }
    21012164
    21022165        if (pathname instanceof LogicalPathname) {
    21032166            // When we're returning a logical
    2104             result.device = Keyword.UNSPECIFIC;
    2105             if (result.directory.listp()) {
    2106                 LispObject original = result.directory;
     2167            result.setDevice(Keyword.UNSPECIFIC);
     2168            if (result.getDirectory().listp()) {
     2169                LispObject original = result.getDirectory();
    21072170                LispObject canonical = NIL;
    21082171                while (original != NIL) {
     
    21142177                    original = original.cdr();
    21152178                }
    2116                 result.directory = canonical.nreverse();
    2117             }
    2118             if (result.name instanceof AbstractString) {
    2119                 result.name = LogicalPathname.canonicalizeStringComponent((AbstractString) result.name);
    2120             }
    2121             if (result.type instanceof AbstractString) {
    2122                 result.type = LogicalPathname.canonicalizeStringComponent((AbstractString) result.type);
     2179                result.setDirectory(canonical.nreverse());
     2180            }
     2181            if (result.getName() instanceof AbstractString) {
     2182              result.setName(LogicalPathname.canonicalizeStringComponent((AbstractString) result.getName()));
     2183            }
     2184            if (result.getType() instanceof AbstractString) {
     2185              result.setType(LogicalPathname.canonicalizeStringComponent((AbstractString) result.getType()));
    21232186            }
    21242187        }
     
    22052268                } else {
    22062269                    try {
    2207                         result = new Pathname(file.getCanonicalPath());
     2270                        result = Pathname.create(file.getCanonicalPath());
    22082271                    } catch (IOException e) {
    22092272                        return error(new FileError(e.getMessage(), pathname));
     
    22112274                }
    22122275                if (Utilities.isPlatformUnix) {
    2213                   result.device = Keyword.UNSPECIFIC;
     2276                  result.setDevice(Keyword.UNSPECIFIC);
    22142277                }
    22152278                return result;
     
    22192282              // If there is no type, query or fragment, we check to
    22202283              // see if there is URL available "underneath".
    2221               if (pathname.name != NIL
    2222                   && pathname.type == NIL
    2223                   && Symbol.GETF.execute(pathname.host, QUERY, NIL) == NIL
    2224                   && Symbol.GETF.execute(pathname.host, FRAGMENT, NIL) == NIL) {
    2225                 Pathname p = new Pathname(pathname.getNamestring() + "/");
     2284              if (pathname.getName() != NIL
     2285                  && pathname.getType() == NIL
     2286                  && Symbol.GETF.execute(pathname.getHost(), QUERY, NIL) == NIL
     2287                  && Symbol.GETF.execute(pathname.getHost(), FRAGMENT, NIL) == NIL) {
     2288                Pathname p = Pathname.create(pathname.getNamestring() + "/");
    22262289                if (p.getInputStream() != null) {
    22272290                  return p;
     
    22332296        jarfile: {
    22342297            // Possibly canonicalize jar file directory
    2235             Cons jars = (Cons) pathname.device;
     2298            Cons jars = (Cons) pathname.getDevice();
    22362299            LispObject o = jars.car();
    22372300        if (!(o instanceof Pathname)) {
     
    23672430            // XXX We only return the bytes of an entry in a JAR
    23682431            Debug.assertTrue(entryPath != null);
    2369             ZipFile jarFile = ZipCache.get((Pathname)device.car());
     2432            ZipFile jarFile = ZipCache.get((Pathname)getDevice().car());
    23702433            Debug.assertTrue(jarFile != null);
    23712434            // Is this a JAR within a JAR?
    2372             if (device.cdr() instanceof Cons) {
    2373                 Pathname inner = (Pathname) device.cdr().car();
     2435            if (getDevice().cdr() instanceof Cons) {
     2436                Pathname inner = (Pathname) getDevice().cdr().car();
    23742437                InputStream input = Utilities.getInputStream(jarFile, inner);
    23752438                ZipInputStream zipInputStream = new ZipInputStream(input);
     
    24302493            // 4.  Entry in JAR in JAR
    24312494            String entryPath = asEntryPath();
    2432             Cons d = (Cons)device;
     2495            Cons d = (Cons)getDevice();
    24332496            if (d.cdr().equals(NIL)) {
    24342497                if (entryPath.length() == 0) {
     
    24402503                    // 3. Entry in JAR
    24412504                    final ZipEntry entry
    2442                         = ZipCache.get((Pathname)device.car()).getEntry(entryPath);
     2505                        = ZipCache.get((Pathname)getDevice().car()).getEntry(entryPath);
    24432506                    if (entry == null) {
    24442507                        return 0;
     
    25962659            Pathname p = coerceToPathname(arg);
    25972660            StringBuilder sb = new StringBuilder();
    2598             if (p.name instanceof AbstractString) {
    2599                 sb.append(p.name.getStringValue());
    2600             } else if (p.name == Keyword.WILD) {
     2661            if (p.getName() instanceof AbstractString) {
     2662                sb.append(p.getName().getStringValue());
     2663            } else if (p.getName() == Keyword.WILD) {
    26012664                sb.append('*');
    26022665            } else {
    26032666                return NIL;
    26042667            }
    2605             if (p.type instanceof AbstractString) {
     2668            if (p.getType() instanceof AbstractString) {
    26062669                sb.append('.');
    2607                 sb.append(p.type.getStringValue());
    2608             } else if (p.type == Keyword.WILD) {
     2670                sb.append(p.getType().getStringValue());
     2671            } else if (p.getType() == Keyword.WILD) {
    26092672                sb.append(".*");
    26102673            }
     
    26242687        @Override
    26252688        public LispObject execute(LispObject arg) {
    2626             return coerceToPathname(arg).host; // XXX URL-PATHNAME
     2689            return coerceToPathname(arg).getHost(); // XXX URL-PATHNAME
    26272690        }
    26282691    }
     
    27422805                }
    27432806            }
    2744             return new Pathname(namestring);
     2807            return Pathname.create(namestring);
    27452808        } catch (IOException e) {
    27462809            error(new LispError(e.getMessage()));
     
    27502813    }
    27512814
     2815  // BEGIN REMOVE ME use standard Factory pattern create() method instead
     2816  public static Pathname make(String s) {
     2817    Pathname p = Pathname.create();
     2818    p.init(s);
     2819    return p;
     2820  }
     2821
     2822  public static Pathname makeFrom(Pathname p) {
     2823    return Pathname.create(p);
     2824  }
     2825
     2826  public static Pathname makeFrom(Pathname p, String s) {
     2827    p.init(s);
     2828    return p;
     2829  }
     2830  // END REMOVE ME
    27522831}
    27532832
  • trunk/abcl/src/org/armedbear/lisp/Site.java

    r13095 r15391  
    5050                s += fileSeparator;
    5151            }
    52             LISP_HOME = new Pathname(s);
     52            LISP_HOME = Pathname.create(s);
    5353            return;
    5454        }
     
    5858                LISP_HOME = NIL;
    5959            } else {
    60                 Pathname p = new Pathname(url);
    61                 p.name = NIL;
    62                 p.type = NIL;
     60                Pathname p = Pathname.create(url);
     61                p.setName(NIL);
     62                p.setType(NIL);
    6363                p.invalidateNamestring();
    6464                LISP_HOME = p;
  • trunk/abcl/src/org/armedbear/lisp/delete_file.java

    r13440 r15391  
    7878                Thread.yield();
    7979            }
    80             Pathname truename = new Pathname(file.getAbsolutePath());
     80            Pathname truename = Pathname.create(file.getAbsolutePath());
    8181            StringBuilder sb = new StringBuilder("Unable to delete ");
    8282            sb.append(file.isDirectory() ? "directory " : "file ");
  • trunk/abcl/src/org/armedbear/lisp/unzip.java

    r14892 r15391  
    6565        Pathname zipFile = coerceToPathname(first);
    6666        Pathname directory = coerceToPathname(second);
    67         directory.name = NIL;
    68         directory.type = NIL;
     67        directory.setName(NIL);
     68        directory.setType(NIL);
    6969        directory.invalidateNamestring();
    7070        return unzipToDirectory(zipFile, directory);
     
    110110                out.close();
    111111                in.close();
    112                 result = result.push(new Pathname(filename));
     112                result = result.push(Pathname.create(filename));
    113113            }
    114114        } catch (IOException e) {
  • trunk/abcl/test/src/org/armedbear/lisp/PathnameTest.java

    r14624 r15391  
    2929        System.out.println(e.getMessage());
    3030    }
    31     Pathname pathname = new Pathname(url);
     31    Pathname pathname = Pathname.create(url);
    3232    assertNotNull(pathname);
    3333    assertNotNull(pathname.getNamestring());
    34     assertNotNull(pathname.name);
    35     assertNotNull(pathname.type);
    36     assertNotNull(pathname.directory);
     34    assertNotNull(pathname.getName());
     35    assertNotNull(pathname.getType());
     36    assertNotNull(pathname.getDirectory());
    3737  }
    3838 
     
    6060  @Test
    6161  public void copyConstructor() {
    62       Pathname orig = new Pathname("/a/b/c/d/e/foo.lisp");
    63       Pathname copy = new Pathname(orig.getNamestring());
     62      Pathname orig = Pathname.create("/a/b/c/d/e/foo.lisp");
     63      Pathname copy = Pathname.create(orig.getNamestring());
    6464      assertTrue(orig.getNamestring().equals(copy.getNamestring()));
    6565  }
     
    6767  @Test
    6868  public void mergePathnames1() {
    69       Pathname p = new Pathname("a/b/c/d/foo.lisp");
    70       Pathname d = new Pathname("/foo/bar/there");
     69      Pathname p = Pathname.create("a/b/c/d/foo.lisp");
     70      Pathname d = Pathname.create("/foo/bar/there");
    7171      Pathname r = Pathname.mergePathnames(p, d);
    7272      String s = r.getNamestring();
     
    7676  @Test
    7777  public void mergePathnames2() {
    78       Pathname p = new Pathname("/a/b/c/d/foo.lisp");
    79       Pathname d = new Pathname("/foo/bar/there");
     78      Pathname p = Pathname.create("/a/b/c/d/foo.lisp");
     79      Pathname d = Pathname.create("/foo/bar/there");
    8080      Pathname r = Pathname.mergePathnames(p, d);
    8181      assertTrue(r.getNamestring().equals("/a/b/c/d/foo.lisp"));
     
    8989      args = args.nreverse();
    9090      Pathname p = Pathname.makePathname(args);
    91       Pathname d = new Pathname("/foo/bar.abcl");
     91      Pathname d = Pathname.create("/foo/bar.abcl");
    9292      Pathname r = Pathname.mergePathnames(p, d);
    9393      assertTrue(r.getNamestring().equals("/foo/bar.abcl-tmp"));
     
    9696  @Test
    9797  public void mergePathnames4() {
    98       Pathname p = new Pathname("jar:file:foo.jar!/bar.abcl");
    99       Pathname d = new Pathname("/a/b/c/");
     98      Pathname p = Pathname.create("jar:file:foo.jar!/bar.abcl");
     99      Pathname d = Pathname.create("/a/b/c/");
    100100      Pathname r = Pathname.mergePathnames(p, d);
    101101      String s = r.getNamestring();
     
    104104  @Test
    105105  public void constructorFileDirectory() {
    106     Pathname p = new Pathname("file://tmp/");
     106    Pathname p = Pathname.create("file://tmp/");
    107107    assertTrue(p.getNamestring().endsWith("/"));
    108108  }
    109109  @Test
    110110    public void constructorFileWindowsDevice() {
    111     Pathname p = new Pathname("file:c://tmp/");
     111    Pathname p = Pathname.create("file:c://tmp/");
    112112    LispObject device = p.getDevice();
    113113    if (Utilities.isPlatformWindows) {
  • trunk/abcl/test/src/org/armedbear/lisp/UtilitiesTest.java

    r12424 r15391  
    4242  public void getZipInputStreamZipEntry() throws FileNotFoundException, IOException {
    4343      JarFile jar = new JarFile(zipFile);
    44       Pathname pathname = new Pathname("a/b/bar.abcl");
     44      Pathname pathname = Pathname.create("a/b/bar.abcl");
    4545      InputStream entryInputStream = Utilities.getInputStream(jar, pathname);
    4646      assertNotNull(entryInputStream);
Note: See TracChangeset for help on using the changeset viewer.