00001 //tabstop=4 00002 //*****************************************************************************/ 00003 // Project: jpl 00004 // 00005 // File: $Id$ 00006 // Date: $Date$ 00007 // Author: Fred Dushin <fadushin@syr.edu> 00008 // 00009 // 00010 // Description: 00011 // 00012 // 00013 // ------------------------------------------------------------------------- 00014 // Copyright (c) 2004 Paul Singleton 00015 // Copyright (c) 1998 Fred Dushin 00016 // All rights reserved. 00017 // 00018 // This library is free software; you can redistribute it and/or 00019 // modify it under the terms of the GNU Library Public License 00020 // as published by the Free Software Foundation; either version 2 00021 // of the License, or (at your option) any later version. 00022 // 00023 // This library is distributed in the hope that it will be useful, 00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 // GNU Library Public License for more details. 00027 //*****************************************************************************/ 00028 package jpl; 00029 00030 import java.io.File; 00031 import jpl.fli.Prolog; 00032 00033 //----------------------------------------------------------------------/ 00034 // JPL 00062 public class JPL { 00063 protected static final boolean DEBUG = false; 00064 // 00065 public static final Term JFALSE = new Compound("@", new Term[] {new Atom("false")}); 00066 public static final Term JTRUE = new Compound("@", new Term[] {new Atom("true")}); 00067 public static final Term JNULL = new Compound("@", new Term[] {new Atom("null")}); 00068 public static final Term JVOID = new Compound("@", new Term[] {new Atom("void")}); 00069 00070 protected static boolean modeDontTellMe = true; 00071 00072 private static String nativeLibraryName = "jpl"; 00073 private static String nativeLibraryDir = null; 00074 private static String nativeLibraryPath = null; 00075 public static String setNativeLibraryName(String newName) { 00076 if (newName == null) { 00077 throw new NullPointerException("newName cannot be null"); 00078 } else { 00079 String oldName = nativeLibraryName; 00080 nativeLibraryName = newName; 00081 return oldName; 00082 } 00083 } 00084 public static String setNativeLibraryDir(String newDir) { 00085 String oldDir = nativeLibraryDir; 00086 nativeLibraryDir = newDir; 00087 return oldDir; 00088 } 00089 public static String setNativeLibraryPath(String newPath) { 00090 String oldPath = nativeLibraryPath; 00091 nativeLibraryPath = newPath; 00092 return oldPath; 00093 } 00094 public static void loadNativeLibrary() { 00095 if (nativeLibraryPath != null) { 00096 System.load((new File(nativeLibraryPath)).getAbsolutePath()); 00097 } else if (nativeLibraryDir != null) { 00098 System.load((new File(nativeLibraryDir, System.mapLibraryName(nativeLibraryName))).getAbsolutePath()); 00099 } else { 00100 System.loadLibrary(nativeLibraryName); // as resolved somewhere on system property 'java.library.path' 00101 } 00102 } 00103 // setDTMMode 00118 public static void setDTMMode( boolean dtm){ 00119 modeDontTellMe = dtm; 00120 } 00121 00122 // getDefaultInitArgs 00132 public static String[] getDefaultInitArgs() { 00133 return Prolog.get_default_init_args(); 00134 } 00135 00136 // setDefaultInitArgs 00143 public static void setDefaultInitArgs(String[] args) { 00144 Prolog.set_default_init_args(args); 00145 } 00146 00147 // getActualInitArgs 00157 public static String[] getActualInitArgs() { 00158 return Prolog.get_actual_init_args(); 00159 } 00160 00161 // init 00176 public static boolean init(String[] args) { 00177 return Prolog.set_default_init_args(args) && init(); 00178 } 00179 00180 // init 00185 public static boolean init() { 00186 return Prolog.initialise(); 00187 } 00188 00189 // isTag(String) 00193 public static boolean isTag(String s) { 00194 return s.length()==22 && s.charAt(0)=='J' && s.charAt(1)=='#' && Character.isDigit(s.charAt(2)) && Character.isDigit(s.charAt(3)) && Character.isDigit(s.charAt(4)) && Character.isDigit(s.charAt(5)) && Character.isDigit(s.charAt(6)) && Character.isDigit(s.charAt(7)) && Character.isDigit(s.charAt(8)) && Character.isDigit(s.charAt(9)) && Character.isDigit(s.charAt(10)) && Character.isDigit(s.charAt(11)) && Character.isDigit(s.charAt(12)) && Character.isDigit(s.charAt(13)) && Character.isDigit(s.charAt(14)) && Character.isDigit(s.charAt(15)) && Character.isDigit(s.charAt(16)) && Character.isDigit(s.charAt(17)) && Character.isDigit(s.charAt(18)) && Character.isDigit(s.charAt(19)) && Character.isDigit(s.charAt(20)) && Character.isDigit(s.charAt(21)); 00195 } 00196 00197 // newJRef(Object) 00201 public static Term newJRef(Object obj) { 00202 return new Compound( "@", new Term[]{new Atom(Prolog.object_to_tag(obj))}); 00203 } 00204 00205 // halt 00213 public static void halt() { 00214 Prolog.halt(0); 00215 } 00216 00217 // a static reference to the current Version 00218 private static final Version version_ = new Version(); 00219 00220 // version 00225 public static Version version() { 00226 return version_; 00227 } 00228 00229 // version_string 00234 public static String version_string() { 00235 return version_.major + "." + version_.minor + "." + version_.patch + "-" + version_.status; 00236 } 00237 00238 public static void main(String[] args) { 00239 System.out.println(version_string()); 00240 } 00241 } 00242 00243 //345678901234567890123456789012346578901234567890123456789012345678901234567890