initial checkin
[org.ibex.nanogoat.git] / src / org / ibex / plat / POSIX.java
1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [LGPL]
2 package org.ibex.plat;
3
4 import java.util.*;
5
6 /** Platform implementation for POSIX compliant operating systems */
7 public class POSIX extends GCJ {
8
9     // General Methods ///////////////////////////////////////////////////////
10
11     protected String getDescriptiveName() { return "GCJ Linux Binary"; }
12
13     /** returns the value of the environment variable key, or null if no such key exists */
14     protected native String _getEnv(String key);
15     
16     /** spawns a process which is immune to SIGHUP */
17     private static native void spawnChildProcess(String[] command);
18
19     protected void _newBrowserWindow(String url) {
20         String browserString = getEnv("BROWSER");
21         if (browserString == null) {
22             browserString = "netscape " + url;
23         } else if (browserString.indexOf("%s") != -1) {
24             browserString =
25                 browserString.substring(0, browserString.indexOf("%s")) +
26                 url + browserString.substring(browserString.indexOf("%s") + 2);
27         } else {
28             browserString += " " + url;
29         }
30
31         StringTokenizer st = new StringTokenizer(browserString, " ");
32         String[] cmd = new String[st.countTokens()];
33         for(int i=0; st.hasMoreTokens(); i++) cmd[i] = st.nextToken();
34
35         spawnChildProcess(cmd);
36     }
37
38 }
39
40
41