X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fxwt%2FMain.java;h=533e763c92677b1f5205f5cb912024237ee31369;hp=c61bcf1b356d18b670e28dd11e3b1dc2999e253d;hb=8ad8837b741bd77cd8aeef1881159ad839ce3828;hpb=ce833e3c1a159dd84cb5f7c3548248a09f63590a diff --git a/src/org/xwt/Main.java b/src/org/xwt/Main.java index c61bcf1..533e763 100644 --- a/src/org/xwt/Main.java +++ b/src/org/xwt/Main.java @@ -1,18 +1,24 @@ -// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt; import java.net.*; import java.util.*; import java.io.*; import java.awt.*; -import org.bouncycastle.util.encoders.Base64; import org.xwt.js.*; import org.xwt.util.*; +import org.xwt.translators.*; +import org.xwt.plat.*; +import org.bouncycastle.util.encoders.Base64; /** Entry point for the XWT Engine; handles splash screen, initial xwar loading, and argument processing */ public class Main { + // to prevent GCJ from dropping these classes + private static final Class[] keep = new Class[] { GCJ.class, Linux.class, Solaris.class, Darwin.class, Win32.class }; + /** + * 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 @@ -21,114 +27,69 @@ public class Main { */ public static java.net.InetAddress originAddr = null; public static String originHost = null; - - /** the URL where the initial xwar came from. */ public static String origin = null; - - /** true iff the user asked for rendered regions to be shown with a red rectangle */ - public static boolean showRenders = false; - - /** don't check if all surfaces are gone (and quit) until this is true */ - public static boolean doneInitializing = false; - - public static void main(String[] args) throws Exception { - org.xwt.imp.MIPSInterpreter interpreter = new org.xwt.imp.MIPSInterpreter(); - System.out.println("exit code: " + - interpreter.run(new String[] { "build/mips/freetype.mips", "padua.ttf" })); + public static String initialTemplate = null; + + public static final Stream builtin = new Stream.Zip(new Stream.Builtin()); + public static Picture scarImage = null; + + public static void printUsage() { + System.err.println("Usage: xwt [-s] [-v] [-l /] source-location [initial-template]"); + System.err.println(""); + System.err.println("Options:"); + System.err.println(" -v verbose logging"); + System.err.println(" -s [not yet supported]"); + System.err.println(" -l [not yet supported]"); + System.err.println(""); + System.err.println("Source-location is one of the following:"); + System.err.println(" - the path to an xwar file"); + System.err.println(" - the path to a directory to be used as an xwar"); + System.err.println(" - the http url of an xwar"); + System.err.println(""); + System.err.println("Initial-template is the path of the template to load; defaults to 'main'"); + Runtime.getRuntime().exit(-1); } - /** common entry point */ - public static void main_(String[] args) { - try { - int startargs = 0; - while (true) { - if (startargs > args.length - 1) { - System.err.println("Usage: xwt [-s] [-v] [-l /] source-location [initial-template]"); - System.err.println(""); - System.err.println("Options:"); - System.err.println(" -s show rendering activity with red rectangles"); - System.err.println(" -v verbose logging"); - System.err.println(" -l serve logs via HTTP on 127.0.0.1:/"); - System.err.println(""); - System.err.println("Source-location is one of the following:"); - System.err.println(" - the path to an xwar file"); - System.err.println(" - the path to a directory to be used as an xwar"); - System.err.println(" - the http url of an xwar"); - System.err.println(""); - System.err.println("Initial-template is the resource name of the template to load; defaults to 'main'"); - Runtime.getRuntime().exit(-1); - } - else if (args[startargs].equals("-s")) showRenders = true; - else if (args[startargs].equals("-v")) Log.verbose = true; - else if (args[startargs].equals("-l")) startargs++; - else break; - startargs++; - } - final String instancename = args.length > startargs + 1 ? args[startargs + 1] : "main"; - - Platform.forceLoad(); - if (Log.on) for(int i=0; i startargs) { - if (args[startargs].startsWith("http://")) { - if (Log.on) Log.log(Main.class, "downloading xwar"); - origin = args[startargs]; - initialTemplate = "org.xwt.builtin.splash"; - - } else { - if (Log.on) Log.log(Main.class, "loading xwar from local filesystem"); + public static void main(String[] args) throws Exception { + int startargs = 0; + while (true) { + if (startargs > args.length - 1) printUsage(); + else if (args[startargs].equals("-v")) Log.verbose = true; + else break; + startargs++; + } - // HACK because MSIE turns \'s into /'s in URLs... argh!! - if (Platform.platform.getClass().getName().endsWith("Win32")) - args[startargs] = args[startargs].replace('/', '\\'); + Platform.forceLoad(); + if (Log.on) for(int i=0; i startargs + 1 ? args[startargs + 1] : "main"; + origin = args[startargs]; + + Stream 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.xwt.builtin.splash"; + } else { + rr = new Stream.File(origin); + if (!new File(origin).isDirectory()) rr = new Stream.Zip(rr); + startupTemplate = initialTemplate; + } - File f = new File(args[startargs]); - origin = "file:" + f.getAbsolutePath(); - if (f.isDirectory()) { - Resources.loadDirectory(f); - Surface.scarAllSurfacesFromNowOn = true; - } else { - initialTemplate = "org.xwt.builtin.splash"; - } + if (Log.on) Log.info(Main.class, "loading xwar"); + final XWT xwt = new XWT(rr); + final JS final_rr = (JS)xwt.get(""); - if (args.length > startargs + 1) initialTemplate = args[startargs + 1]; - } - } - - if (Log.on) Log.log(Main.class, "instantiating " + initialTemplate); - final String initialTemplate_f = initialTemplate; - ThreadMessage.newthread(new JS.Callable() { - public Object call(JS.Array args) throws JS.Exn { - Box b = new Box(); - Template.getTemplate(initialTemplate_f, null).apply(b, null, null, null, 0, 0); - doneInitializing = true; - if (Surface.allSurfaces.size() == 0) { - Log.log(this, "exiting because all surfaces are gone"); - Platform.exit(); - } - return null; - } - }); - - // gcj-win32 exit()'s when the original thread dies, so we have to deadlock ourselves - //if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore"); - //new org.xwt.util.Semaphore().block(); - Platform.running(); + scarImage = + Picture.load((Stream)Main.builtin.get("org/xwt/builtin/scar.png"), + new Scheduler.Task() { public void perform() throws Exception { + xwt.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1); + } }); - } catch (Throwable e) { - e.printStackTrace(); - Platform.criticalAbort("exception in Main.main(): " + e); - } + Scheduler.init(); } - }