Changeset 5295


Ignore:
Timestamp:
01/01/04 00:40:35 (17 years ago)
Author:
piso
Message:

Work in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Pathname.java

    r5292 r5295  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: Pathname.java,v 1.22 2003-12-31 19:40:13 piso Exp $
     5 * $Id: Pathname.java,v 1.23 2004-01-01 00:40:35 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    169169    }
    170170
     171    private static Pathname coerceToPathname(LispObject arg)
     172        throws ConditionThrowable
     173    {
     174        if (arg instanceof Pathname)
     175            return (Pathname) arg;
     176        if (arg instanceof LispString)
     177            return new Pathname(((LispString)arg).getValue());
     178        signal(new TypeError(arg, "pathname designator"));
     179        // Not reached.
     180        return null;
     181    }
     182
     183    // ### pathname-host
     184    private static final Primitive PATHNAME_HOST =
     185        new Primitive("pathname-host", "pathname &key case")
     186    {
     187        public LispObject execute(LispObject arg) throws ConditionThrowable
     188        {
     189            return coerceToPathname(arg).host;
     190        }
     191    };
     192
     193    // ### pathname-device
     194    private static final Primitive PATHNAME_DEVICE =
     195        new Primitive("pathname-device", "pathname &key case")
     196    {
     197        public LispObject execute(LispObject arg) throws ConditionThrowable
     198        {
     199            return coerceToPathname(arg).device;
     200        }
     201    };
     202
     203    // ### pathname-directory
     204    private static final Primitive PATHNAME_DIRECTORY =
     205        new Primitive("pathname-directory", "pathname &key case")
     206    {
     207        public LispObject execute(LispObject arg) throws ConditionThrowable
     208        {
     209            return coerceToPathname(arg).directory;
     210        }
     211    };
     212
     213    // ### pathname-name
     214    private static final Primitive PATHNAME_NAME =
     215        new Primitive("pathname-name", "pathname &key case")
     216    {
     217        public LispObject execute(LispObject arg) throws ConditionThrowable
     218        {
     219            return coerceToPathname(arg).name;
     220        }
     221    };
     222
     223    // ### pathname-type
     224    private static final Primitive PATHNAME_TYPE =
     225        new Primitive("pathname-type", "pathname &key case")
     226    {
     227        public LispObject execute(LispObject arg) throws ConditionThrowable
     228        {
     229            return coerceToPathname(arg).type;
     230        }
     231    };
     232
     233    // ### pathname-version
     234    private static final Primitive PATHNAME_VERSION =
     235        new Primitive("pathname-version", "pathname &key case")
     236    {
     237        public LispObject execute(LispObject arg) throws ConditionThrowable
     238        {
     239            return coerceToPathname(arg).version;
     240        }
     241    };
     242
    171243    // ### namestring
    172244    // namestring pathname => namestring
     
    188260    // FIXME arg can be a stream, too...
    189261    private static final Primitive1 DIRECTORY_NAMESTRING =
    190         new Primitive1("directory-namestring","pathname")
     262        new Primitive1("directory-namestring", "pathname")
    191263    {
    192264        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    213285    // pathname pathspec => pathname
    214286    // FIXME pathspec can be a stream, too...
    215     private static final Primitive1 PATHNAME = new Primitive1("pathname","pathspec")
    216     {
    217         public LispObject execute(LispObject arg) throws ConditionThrowable
    218         {
    219             if (arg instanceof Pathname)
    220                 return arg;
    221             if (arg instanceof LispString)
    222                 return new Pathname(((LispString)arg).getValue());
    223             return signal(new TypeError(arg, "pathname designator"));
     287    private static final Primitive1 PATHNAME =
     288        new Primitive1("pathname", "pathspec")
     289    {
     290        public LispObject execute(LispObject arg) throws ConditionThrowable
     291        {
     292            return coerceToPathname(arg);
    224293        }
    225294    };
     
    259328    };
    260329
    261     // ### pathname-type
    262     private static final Primitive1 PATHNAME_TYPE =
    263         new Primitive1("pathname-type", "pathname &key case")
    264     {
    265         public LispObject execute(LispObject arg) throws ConditionThrowable
    266         {
    267             String namestring;
    268             if (arg instanceof LispString)
    269                 namestring = ((LispString)arg).getValue();
    270             else if (arg instanceof Pathname)
    271                 namestring = ((Pathname)arg).getNamestring();
    272             else
    273                 return signal(new TypeError(arg, "pathname designator"));
    274             if (namestring != null) {
    275                 for (int i = namestring.length(); i-- > 0;) {
    276                     char c = namestring.charAt(i);
    277                     if (c == '.')
    278                         return new LispString(namestring.substring(i + 1));
    279                 }
    280             }
    281             return NIL;
    282         }
    283     };
     330//     // ### pathname-type
     331//     private static final Primitive1 PATHNAME_TYPE =
     332//         new Primitive1("pathname-type", "pathname &key case")
     333//     {
     334//         public LispObject execute(LispObject arg) throws ConditionThrowable
     335//         {
     336//             String namestring;
     337//             if (arg instanceof LispString)
     338//                 namestring = ((LispString)arg).getValue();
     339//             else if (arg instanceof Pathname)
     340//                 namestring = ((Pathname)arg).getNamestring();
     341//             else
     342//                 return signal(new TypeError(arg, "pathname designator"));
     343//             if (namestring != null) {
     344//                 for (int i = namestring.length(); i-- > 0;) {
     345//                     char c = namestring.charAt(i);
     346//                     if (c == '.')
     347//                         return new LispString(namestring.substring(i + 1));
     348//                 }
     349//             }
     350//             return NIL;
     351//         }
     352//     };
    284353
    285354    // ### user-homedir-pathname
Note: See TracChangeset for help on using the changeset viewer.