01: /*
02: * probe_file.java
03: *
04: * Copyright (C) 2003 Peter Graves
05: * $Id: probe_file.java,v 1.6 2003/11/15 11:03:33 beedlem Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.lisp;
23:
24: import java.io.File;
25: import java.io.IOException;
26:
27: public final class probe_file extends Lisp {
28: // ### probe-file
29: // probe-file pathspec => truename
30: private static final Primitive1 PROBE_FILE = new Primitive1(
31: "probe-file") {
32: public LispObject execute(LispObject arg)
33: throws ConditionThrowable {
34: File file = Utilities.getFile(arg);
35: if (!file.exists())
36: return NIL;
37: try {
38: return new LispString(file.getCanonicalPath());
39: } catch (IOException e) {
40: throw new ConditionThrowable(new LispError(e
41: .getMessage()));
42: }
43: }
44: };
45:
46: // ### probe-directory
47: // probe-directory pathspec => truename
48: private static final Primitive1 PROBE_DIRECTORY = new Primitive1(
49: "probe-directory", PACKAGE_EXT, true) {
50: public LispObject execute(LispObject arg)
51: throws ConditionThrowable {
52: File file = Utilities.getFile(arg);
53: if (!file.isDirectory())
54: return NIL;
55: try {
56: return new LispString(file.getCanonicalPath());
57: } catch (IOException e) {
58: throw new ConditionThrowable(new LispError(e
59: .getMessage()));
60: }
61: }
62: };
63:
64: // ### file-directory-p
65: // file-directory-p pathspec => generalized-boolean
66: private static final Primitive1 FILE_DIRECTORY_P = new Primitive1(
67: "file-directory-p", PACKAGE_EXT, true) {
68: public LispObject execute(LispObject arg)
69: throws ConditionThrowable {
70: File file = Utilities.getFile(arg);
71: return file.isDirectory() ? T : NIL;
72: }
73: };
74: }
|