import java.net.*; import java.io.*; /** * FakeFril.java * * Title: FakeFril * * Description * Tutorial example using high level Fril Foreign Language Interface functions. * This is a simple tty-based app, which fakes a normal tty Fril. Input and * output are connected to stdin and stdout respectively. One difference from * the genuine article is that lines read from the BufferedReader are not * terminated by a carriage return - this may be important (for example) if the trace * package is run. * Limited testing has been carried out, but the system may not be stable under error * conditions, interrupts, etc and under no circumstances should it be used for controlling * nuclear submarines. * Error checking is very limited. * * @author T. P. Martin * @date June 2001 * @version 1.0b1 */ public class FakeFril { private static JFril aFril; // the embedded Fril object private static final String THISCLASS = "FakeFril::"; private static final String PROMPT = "prompt >"; private static final String CREATIONDATE = "07-06-01"; // this is a query run when the system is created - replace it as necessary private static final String INITQUERY = "?((pp initQuery)(getenv frlib X)(p Fril library at X)(pp))"; public static void main(String[] args) throws IOException { PrintWriter out ; // handles the output from Fril BufferedReader stdIn ; // handles the input for Fril int ret; // return value from Fril execution System.out.println(THISCLASS + " starting up version of " + CREATIONDATE); try { out = new PrintWriter(System.out, true); stdIn = new BufferedReader(new InputStreamReader(System.in)); System.out.println(THISCLASS + "about to create aFril"); aFril = new JFril(out, INITQUERY); // create a JFril object and run INITQUERY if (aFril == null) System.out.println(THISCLASS + "couldn't create aFril"); else System.out.println(THISCLASS + "loaded native Fril version" + aFril.jFrilGetVersion()); out.flush(); out.print(THISCLASS + PROMPT); out.flush(); if(aFril != null) { while (aFril.jFrilGetStatus()) { if( stdIn.ready() ) // something to give to Fril { ret = aFril.jFrilExecuteFril(stdIn); // pass it on and let Fril execute switch (ret) { case JFril.JFRILSUCCEEDED: out.println("yes"); break; case JFril.JFRILFAILED: out.println("no"); break; case JFril.JFRILTERMINATED: out.println("Fril has terminated"); break; default: out.println(THISCLASS + "unexpected return value from jFrilExecuteFril " + ret); } out.print(THISCLASS + PROMPT ); out.flush(); } } out.print(THISCLASS + "> aFril status false <"); } out.close(); stdIn.close(); } catch (IOException e) { System.err.println(THISCLASS + "IO Error " + e); System.exit(1); } System.exit(0); } }