1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
8 import org.ibex.util.*;
9 import org.ibex.plat.*;
10 import org.ibex.graphics.*;
11 import org.ibex.core.builtin.*;
13 /** Entry point for the Ibex Engine; handles splash screen, initial xwar loading, and argument processing */
17 * FEATURE: this should be implemented using self-emulation
18 * Used for security checks. If this is null, it means that only
19 * scripts originating from the local filesystem are loaded in
20 * the engine (maximum permissions). If scripts have been loaded
21 * from multiple locations, this will be 0.0.0.0 (the invalid
24 public static java.net.InetAddress originAddr = null;
25 public static String originHost = null;
26 public static String origin = null;
27 public static String initialTemplate = null;
29 public static final Stream builtin = new Stream.Zip(new Stream.Builtin());
31 public static void printUsage() {
32 System.err.println("Usage: ibex [-lawp] [ url | file | directory ]");
33 System.err.println("");
34 System.err.println(" -l <level> set logging level to { debug, info (default), warn, error, silent }");
35 System.err.println(" -l rpc log all XML-RPC and SOAP conversations");
36 System.err.println(" -l user@host email log to user@host");
37 System.err.println(" -l host:port emit log to TCP socket");
38 System.err.println(" -l <file> write log to a file on disk");
39 //System.err.println(" -a check assertions");
40 System.err.println(" -w <window-id> reserved for libibex");
41 System.err.println(" -p dump profiling information [not yet supported]");
42 Runtime.getRuntime().exit(-1);
45 public static void main(String[] args) throws UnknownHostException, JSExn, IOException {
48 if (startargs > args.length - 1) printUsage();
49 // FEATURE: This should be enabled at the parser level - there shouldn't even be an assert bytecode
50 /*else if (args[startargs].equals("-a")) JS.checkAssertions = true;*/
51 else if (args[startargs].equals("-l")) {
53 StringTokenizer opts = new StringTokenizer(args[startargs], ",");
54 while(opts.hasMoreTokens()) {
55 String opt = opts.nextToken();
56 if (opt.indexOf('@') != -1) Log.email(opt);
57 else if (opt.indexOf(':') != -1)
58 Log.tcp(opt.substring(0, opt.indexOf(':')),
59 Integer.parseInt(opt.substring(opt.indexOf(':') + 1)));
60 else if (opt.equals("debug")) Log.level = Log.DEBUG;
61 else if (opt.equals("info")) Log.level = Log.INFO;
62 else if (opt.equals("warn")) Log.level = Log.WARN;
63 else if (opt.equals("error")) Log.level = Log.ERROR;
64 else if (opt.equals("silent")) Log.level = Log.SILENT;
65 else if (opt.equals("rpc")) Log.rpc = true;
73 org.ibex.plat.Platform.forceLoad();
74 if (Log.on) for(int i=0; i<args.length; i++) Log.info(Main.class, "argument " + i + ": " + args[i]);
76 initialTemplate = args.length > startargs + 1 ? args[startargs + 1] : "main";
77 origin = args[startargs];
80 final String startupTemplate;
81 if (origin.startsWith("http://") || origin.startsWith("https://")) {
82 originHost = origin.substring(origin.indexOf('/') + 2);
83 originHost = originHost.substring(0, originHost.indexOf('/') == -1 ? originHost.length() : originHost.indexOf('/'));
84 if (originHost.indexOf('@') != -1) originHost = originHost.substring(originHost.indexOf('@') + 1);
85 originAddr = InetAddress.getByName(originHost);
87 //startupTemplate = "org.ibex.builtin.splash";
88 rr = new Stream.HTTP(origin);
89 startupTemplate = initialTemplate;
91 rr = new Stream.File(origin);
92 if (!new File(origin).isDirectory()) rr = new Stream.Zip(rr);
93 startupTemplate = initialTemplate;
96 if (Log.on) Log.info(Main.class, "loading xwar");
97 final Ibex ibex = new Ibex(rr);
99 org.ibex.graphics.Surface.scarImage =
100 Picture.load(new Stream.FromInputStream(Encode.JavaSourceCode.decode(Scar.data)),
101 new Task() { public void perform() throws JSExn, UnknownHostException {
102 if (Log.on) Log.info(Main.class, "invoking initial template");
103 ibex.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1);