// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the GNU General Public License version 2 ("the License"). // You may not use this file except in compliance with the License. package org.ibex.core; import java.net.*; import java.io.*; import java.util.*; import org.ibex.js.*; import org.ibex.util.*; import org.ibex.plat.*; import org.ibex.graphics.*; /** Entry point for the Ibex Engine; handles splash screen, initial xwar loading, and argument processing */ public class Main { // ugly hack: we have to set these properties before AWT loads static { System.setProperty("apple.awt.showGrowBox", "false"); System.setProperty("apple.awt.graphics.EnableLazyDrawing", "40"); System.setProperty("apple.awt.graphics.EnableLazyDrawing", "true"); System.setProperty("apple.awt.window.position.forceSafeUserPositioning", "true"); System.setProperty("apple.awt.window.position.forceSafeCreation", "true"); System.setProperty("com.apple.hwaccel", "true"); System.setProperty("com.apple.forcehwaccel", "true"); } /** * FEATURE: this should be implemented using self-emulation * Used for security checks. If this is null, it means that only * scripts originating from the local filesystem are loaded in * the engine (maximum permissions). If scripts have been loaded * from multiple locations, this will be 0.0.0.0 (the invalid * IP). */ public static java.net.InetAddress originAddr = null; public static String originHost = null; public static String origin = null; public static String initialTemplate = null; //public static final Fountain builtin = new Fountain.Zip(new Fountain.FromInputStream(Platform.getBuiltinInputStream())); public static final Fountain vera; static { Fountain temp = null; try { temp = new Fountain.FromInputStream(Encode.JavaSourceCode.decode(Vera.data)); } catch (Exception e) { Log.error(Main.class, e); } vera = temp; } public static void printUsage() { System.err.println("Usage: ibex [-lawp] [ url | file | directory ]"); System.err.println(""); System.err.println(" -l set logging level to { debug, info (default), warn, error, silent }"); System.err.println(" -l rpc log all XML-RPC and SOAP conversations"); System.err.println(" -l user@host email log to user@host"); System.err.println(" -l host:port emit log to TCP socket"); System.err.println(" -l write log to a file on disk"); //System.err.println(" -a check assertions"); System.err.println(" -w reserved for libibex"); System.err.println(" -p dump profiling information [not yet supported]"); Runtime.getRuntime().exit(-1); } public static void main(String[] args) throws UnknownHostException, JSExn, IOException { int startargs = 0; while (true) { if (startargs > args.length - 1) printUsage(); // FEATURE: This should be enabled at the parser level - there shouldn't even be an assert bytecode /*else if (args[startargs].equals("-a")) JS.checkAssertions = true;*/ else if (args[startargs].equals("-l")) { startargs++; StringTokenizer opts = new StringTokenizer(args[startargs], ","); while(opts.hasMoreTokens()) { String opt = opts.nextToken(); if (opt.indexOf('@') != -1) Log.email(opt); else if (opt.indexOf(':') != -1) Log.tcp(opt.substring(0, opt.indexOf(':')), Integer.parseInt(opt.substring(opt.indexOf(':') + 1))); else if (opt.equals("debug")) Log.level = Log.DEBUG; else if (opt.equals("info")) Log.level = Log.INFO; else if (opt.equals("warn")) Log.level = Log.WARN; else if (opt.equals("error")) Log.level = Log.ERROR; else if (opt.equals("silent")) Log.level = Log.SILENT; else if (opt.equals("rpc")) Log.rpc = true; else Log.file(opt); } } else break; startargs++; } org.ibex.plat.Platform.forceLoad(); if (Log.on) for(int i=0; i startargs + 1 ? args[startargs + 1] : "main"; origin = args[startargs]; Fountain rr; final String startupTemplate; if (origin.startsWith("http://") || origin.startsWith("https://")) { originHost = origin.substring(origin.indexOf('/') + 2); originHost = originHost.substring(0, originHost.indexOf('/') == -1 ? originHost.length() : originHost.indexOf('/')); if (originHost.indexOf('@') != -1) originHost = originHost.substring(originHost.indexOf('@') + 1); originAddr = InetAddress.getByName(originHost); //rr = builtin; //startupTemplate = "org.ibex.builtin.splash"; rr = new Fountain.HTTP(origin); startupTemplate = initialTemplate; } else { rr = new Fountain.File(origin); if (!new File(origin).isDirectory()) rr = new Fountain.Zip(rr); startupTemplate = initialTemplate; } if (Log.on) Log.info(Main.class, "loading xwar"); final Ibex ibex = new Ibex(rr); try { JS blessed = ibex.bless(new Fountain.FromInputStream(Encode.JavaSourceCode.decode(org.ibex.core.builtin.Scar.data))); org.ibex.graphics.Surface.scarImage = Platform.createPicture(blessed); } catch (Exception e) { Log.error(Main.class, e); } Platform.Scheduler.add(new Callable() { private final JS[] callargs = new JS[1]; public Object run(Object o) throws JSExn,UnknownHostException { if (Log.on) Log.info(Main.class, "invoking initial template"); try { callargs[0] = new Box(); ibex.resolveString(startupTemplate, false).call(null, callargs); } finally { callargs[0] = null; } return null; } }); Platform.Scheduler.init(); } }