1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
7 import org.ibex.util.*;
9 /** Entry point for the Ibex Engine; handles splash screen, initial xwar loading, and argument processing */
13 * FEATURE: this should be implemented using self-emulation
14 * Used for security checks. If this is null, it means that only
15 * scripts originating from the local filesystem are loaded in
16 * the engine (maximum permissions). If scripts have been loaded
17 * from multiple locations, this will be 0.0.0.0 (the invalid
20 public static java.net.InetAddress originAddr = null;
21 public static String originHost = null;
22 public static String origin = null;
23 public static String initialTemplate = null;
25 public static final Stream builtin = new Stream.Zip(new Stream.Builtin());
26 public static Picture scarImage = null;
28 public static void printUsage() {
29 System.err.println("Usage: ibex [-s] [-v] [-l <port>/<url>] source-location [initial-template]");
30 System.err.println("");
31 System.err.println("Options:");
32 System.err.println(" -v verbose logging (required for logging on Win32)");
33 System.err.println(" -s [not yet supported]");
34 System.err.println(" -l [not yet supported]");
35 System.err.println("");
36 System.err.println("Source-location is one of the following:");
37 System.err.println(" - the path to an xwar file");
38 System.err.println(" - the path to a directory to be used as an xwar");
39 System.err.println(" - the http url of an xwar");
40 System.err.println("");
41 System.err.println("Initial-template is the path of the template to load; defaults to 'main'");
42 Runtime.getRuntime().exit(-1);
45 public static void main(String[] args) throws UnknownHostException, JSExn {
48 if (startargs > args.length - 1) printUsage();
49 else if (args[startargs].equals("-v")) Log.verbose = true;
55 if (Log.on) for(int i=0; i<args.length; i++) Log.info(Main.class, "argument " + i + ": " + args[i]);
57 initialTemplate = args.length > startargs + 1 ? args[startargs + 1] : "main";
58 origin = args[startargs];
61 final String startupTemplate;
62 if (origin.startsWith("http://") || origin.startsWith("https://")) {
63 originHost = origin.substring(origin.indexOf('/') + 2);
64 originHost = originHost.substring(0, originHost.indexOf('/') == -1 ? originHost.length() : originHost.indexOf('/'));
65 if (originHost.indexOf('@') != -1) originHost = originHost.substring(originHost.indexOf('@') + 1);
66 originAddr = InetAddress.getByName(originHost);
68 startupTemplate = "org.ibex.builtin.splash";
70 rr = new Stream.File(origin);
71 if (!new File(origin).isDirectory()) rr = new Stream.Zip(rr);
72 startupTemplate = initialTemplate;
75 if (Log.on) Log.info(Main.class, "loading xwar");
76 final Ibex ibex = new Ibex(rr);
79 Picture.load((Stream)Main.builtin.get("org/ibex/builtin/scar.png"),
80 new Scheduler.Task() { public void perform() throws JSExn, UnknownHostException {
81 ibex.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1);