licensing update to APSL 2.0
[nestedvm.git] / src / tests / Env.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package tests;
6
7 import org.ibex.nestedvm.Runtime;
8
9 class Env {
10     public static void main(String[] args) throws Exception {
11         int n = 0;
12         while(n < args.length && args[n].indexOf("=") != -1) n++;
13
14         if(n==args.length) {
15             System.err.println("Usage: Env [name=value ...] classname [args ...]");
16             System.exit(1);
17         }
18         
19         String[] env = new String[n];
20         String[] appArgs = new String[args.length-n-1];
21         for(int i=0;i<n;i++) env[i] = args[i];
22         String className = args[n];
23         for(int i=n+1;i<args.length;i++) appArgs[i-n-1] = args[i];
24         
25         Runtime rt;
26         if(className.endsWith(".mips")) {
27             rt = new org.ibex.nestedvm.Interpreter(className);
28         } else {
29             Class c = Class.forName(className);
30             if(!Runtime.class.isAssignableFrom(c)) { System.err.println(className + " isn't a MIPS compiled class"); System.exit(1); }
31             rt = (Runtime) c.newInstance();
32         }
33         System.exit(rt.run(appArgs,env));
34     }
35 }