From 66c802faf5eed27033b71f674554738a0a1ca359 Mon Sep 17 00:00:00 2001
From: hyung-hwan
-Note: This java applet has been signed with a self-signed certificate. If you allow the program to run, it will download a JNI DLL into your home directory. Currently, it supports Microsoft Windows only and the only file downloaded by this applet is aseawk_jni.dll. If you decide to clean your system later, don't forget to delete this file from your home directory. +Note: This java applet has been signed with a self-signed certificate. If you allow the program to run, it will download a JNI file into your home directory. Currently, it supports Linux(i386) and Microsoft Windows(x86). If you decide to clean your system later, don't forget to delete the local JNI file downloaded.
Copyright (c) 2006-2007, Hyung-Hwan Chung. All rights reserved. diff --git a/ase/test/awk/AseAwkPanel.java b/ase/test/awk/AseAwkPanel.java index e6a91266..b751a1dd 100644 --- a/ase/test/awk/AseAwkPanel.java +++ b/ase/test/awk/AseAwkPanel.java @@ -1,5 +1,5 @@ /* - * $Id: AseAwkPanel.java,v 1.28 2007/11/11 06:10:42 bacon Exp $ + * $Id: AseAwkPanel.java,v 1.31 2007/11/11 15:06:47 bacon Exp $ */ import java.awt.*; @@ -352,23 +352,23 @@ public class AseAwkPanel extends Panel implements DropTargetListener protected Option[] options = new Option[] { - new Option("IMPLICIT", AseAwk.OPTION_IMPLICIT, true), - new Option("EXPLICIT", AseAwk.OPTION_EXPLICIT, false), - new Option("UNIQUEFN", AseAwk.OPTION_UNIQUEFN, true), - new Option("SHADING", AseAwk.OPTION_SHADING, true), - new Option("SHIFT", AseAwk.OPTION_SHIFT, false), - new Option("IDIV", AseAwk.OPTION_IDIV, false), - new Option("STRCONCAT", AseAwk.OPTION_STRCONCAT, false), - new Option("EXTIO", AseAwk.OPTION_EXTIO, true), - new Option("BLOCKLESS", AseAwk.OPTION_BLOCKLESS, true), - new Option("BASEONE", AseAwk.OPTION_BASEONE, true), - new Option("STRIPSPACES", AseAwk.OPTION_STRIPSPACES, false), - new Option("NEXTOFILE", AseAwk.OPTION_NEXTOFILE, false), - //new Option("CRLF", AseAwk.OPTION_CRLF, false), - new Option("ARGSTOMAIN", AseAwk.OPTION_ARGSTOMAIN, false), - new Option("RESET", AseAwk.OPTION_RESET, false), - new Option("MAPTOVAR", AseAwk.OPTION_MAPTOVAR, false), - new Option("PABLOCK", AseAwk.OPTION_PABLOCK, true) + new Option("IMPLICIT", StdAwk.OPTION_IMPLICIT, true), + new Option("EXPLICIT", StdAwk.OPTION_EXPLICIT, false), + new Option("UNIQUEFN", StdAwk.OPTION_UNIQUEFN, true), + new Option("SHADING", StdAwk.OPTION_SHADING, true), + new Option("SHIFT", StdAwk.OPTION_SHIFT, false), + new Option("IDIV", StdAwk.OPTION_IDIV, false), + new Option("STRCONCAT", StdAwk.OPTION_STRCONCAT, false), + new Option("EXTIO", StdAwk.OPTION_EXTIO, true), + new Option("BLOCKLESS", StdAwk.OPTION_BLOCKLESS, true), + new Option("BASEONE", StdAwk.OPTION_BASEONE, true), + new Option("STRIPSPACES", StdAwk.OPTION_STRIPSPACES, false), + new Option("NEXTOFILE", StdAwk.OPTION_NEXTOFILE, false), + //new Option("CRLF", StdAwk.OPTION_CRLF, false), + new Option("ARGSTOMAIN", StdAwk.OPTION_ARGSTOMAIN, false), + new Option("RESET", StdAwk.OPTION_RESET, false), + new Option("MAPTOVAR", StdAwk.OPTION_MAPTOVAR, false), + new Option("PABLOCK", StdAwk.OPTION_PABLOCK, true) }; public AseAwkPanel () @@ -381,7 +381,10 @@ public class AseAwkPanel extends Panel implements DropTargetListener { jniLib = new TextField (); - Font font = new Font ("Monospaced", Font.PLAIN, 14); + String osname = System.getProperty ("os.name").toLowerCase(); + int fontSize = (osname.startsWith("windows"))? 14: 12; + + Font font = new Font ("Monospaced", Font.PLAIN, fontSize); srcIn = new TextArea (); srcOut = new TextArea (); @@ -488,7 +491,7 @@ public class AseAwkPanel extends Panel implements DropTargetListener mainLayout.setVgap (2); setLayout (mainLayout); - statusLabel = new Label ("Ready"); + statusLabel = new Label ("Ready - " + System.getProperty("user.dir")); statusLabel.setBackground (Color.GREEN); add (topPanel, BorderLayout.NORTH); @@ -503,6 +506,12 @@ public class AseAwkPanel extends Panel implements DropTargetListener public void prepareNativeInterface () { String osname = System.getProperty ("os.name").toLowerCase(); + String osarch = System.getProperty("os.arch").toLowerCase(); + String userHome = System.getProperty("user.home"); + + if (osname.startsWith("windows")) osname = "win"; + else if (osname.startsWith("linux")) osname = "linux"; + else if (osname.startsWith("mac")) osname = "mac"; URL url = this.getClass().getResource ( this.getClass().getName() + ".class"); @@ -515,46 +524,67 @@ public class AseAwkPanel extends Panel implements DropTargetListener file.getParentFile().getParentFile().getParent(): file.getParentFile().getParent(); - if (osname.startsWith ("windows")) + String libBase = "aseawk_jni"; + if (isHttp) libBase = libBase + "-" + osname + "-" + osarch; + String libName = System.mapLibraryName(libBase); + + if (osname.equals("win")) { - String path; + String jniLocal; if (isHttp) { base = "http://" + base.substring(6).replace('\\', '/'); - String jniUrl = base + "/lib/aseawk_jni.dll"; + String jniUrl = base + "/lib/" + libName; String md5Url = jniUrl + ".md5"; - String userHome = System.getProperty("user.home"); - path = userHome + "\\aseawk_jni.dll"; + jniLocal = userHome + "\\" + libName; try { - downloadNative (md5Url, jniUrl, path); + downloadNative (md5Url, jniUrl, jniLocal); } catch (Exception e) { showMessage ("Cannot download native library - " + e.getMessage()); - path = "ERROR - Not Available"; + jniLocal = "ERROR - Not Available"; } } else { - path = base + "\\lib\\aseawk_jni.dll"; - if (protocol.equals("jar")) path = path.substring(6); + jniLocal = base + "\\lib\\" + libName; + if (protocol.equals("jar")) jniLocal = jniLocal.substring(6); } - jniLib.setText (path); + + jniLib.setText (jniLocal); } - else if (osname.startsWith ("mac")) + else { - String path = base + "/lib/.libs/libaseawk_jni.dylib"; - if (!isHttp && protocol.equals("jar")) path = path.substring(5); - jniLib.setText (path); - } - else - { - String path = base + "/lib/.libs/libaseawk_jni.so"; - if (!isHttp && protocol.equals("jar")) path = path.substring(5); - jniLib.setText (path); + String jniLocal; + if (isHttp) + { + base = "http://" + base.substring(6); + String jniUrl = base + "/lib/" + libName; + String md5Url = jniUrl + ".md5"; + + jniLocal = userHome + "/" + libName; + + try + { + downloadNative (md5Url, jniUrl, jniLocal); + } + catch (Exception e) + { + showMessage ("Cannot download native library - " + e.getMessage()); + jniLocal = "ERROR - Not Available"; + } + } + else + { + jniLocal = base + "/lib/.libs/" + libName; + if (protocol.equals("jar")) jniLocal = jniLocal.substring(5); + } + + jniLib.setText (jniLocal); } } diff --git a/ase/test/awk/makefile.in b/ase/test/awk/makefile.in index c6f387fd..5f1e4e7f 100644 --- a/ase/test/awk/makefile.in +++ b/ase/test/awk/makefile.in @@ -1,5 +1,5 @@ # -# $Id: makefile.in,v 1.5 2007/05/06 08:10:31 bacon Exp $ +# $Id: makefile.in,v 1.6 2007/11/11 15:06:47 bacon Exp $ # CC = @CC@ @@ -15,50 +15,51 @@ JAR = @JAR@ CFLAGS_JNI = @CFLAGS_JNI@ JNI = @JNI@ -LIB_DIR = ../../$(MODE)/lib -OUT_DIR = ../../$(MODE)/bin +OUT_DIR= ../../$(MODE) +OUT_DIR_LIB = $(OUT_DIR)/lib +OUT_DIR_BIN = $(OUT_DIR)/bin TMP_DIR = $(MODE) ASEAWK_LIB = all: build$(JNI) -build: $(TMP_DIR) $(OUT_DIR) $(OUT_DIR)/aseawk $(OUT_DIR)/aseawk_mini $(OUT_DIR)/aseawk++ +build: $(TMP_DIR) $(OUT_DIR_BIN) $(OUT_DIR_BIN)/aseawk $(OUT_DIR_BIN)/aseawk_mini $(OUT_DIR_BIN)/aseawk++ -buildjni: build $(OUT_DIR)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html +buildjni: build $(OUT_DIR_BIN)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html -$(OUT_DIR)/aseawk: awk.c +$(OUT_DIR_BIN)/aseawk: awk.c $(CC) $(CFLAGS) -o $@ awk.c $(LDFLAGS) $(LIBS) -$(OUT_DIR)/aseawk_mini: mini.c +$(OUT_DIR_BIN)/aseawk_mini: mini.c $(CC) $(CFLAGS) -o $@ mini.c $(LDFLAGS) $(LIBS) -$(OUT_DIR)/aseawk++: Awk.cpp +$(OUT_DIR_BIN)/aseawk++: Awk.cpp $(CXX) $(CFLAGS) -o $@ Awk.cpp $(LDFLAGS) $(LIBS_CXX) -$(OUT_DIR)/aseawk.jar: $(TMP_DIR)/AseAwkPanel.class $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkApplet.class - cd $(TMP_DIR); $(JAR) -xvf ../$(LIB_DIR)/aseawk.jar +$(OUT_DIR_BIN)/aseawk.jar: $(TMP_DIR)/AseAwkPanel.class $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkApplet.class + cd $(TMP_DIR); $(JAR) -xvf ../$(OUT_DIR_LIB)/aseawk.jar cd $(TMP_DIR); $(JAR) -cvfm ../$@ ../manifest *.class ase rm -rf $(TMP_DIR)/ase $(TMP_DIR)/AseAwkPanel.class: AseAwkPanel.java - $(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwkPanel.java + $(JAVAC) -classpath $(TMP_DIR):$(OUT_DIR_LIB)/aseawk.jar -d $(TMP_DIR) AseAwkPanel.java $(TMP_DIR)/AseAwk.class: AseAwk.java - $(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwk.java + $(JAVAC) -classpath $(TMP_DIR):$(OUT_DIR_LIB)/aseawk.jar -d $(TMP_DIR) AseAwk.java $(TMP_DIR)/AseAwkApplet.class: AseAwkApplet.java - $(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwkApplet.java + $(JAVAC) -classpath $(TMP_DIR):$(OUT_DIR_LIB)/aseawk.jar -d $(TMP_DIR) AseAwkApplet.java $(OUT_DIR)/AseAwkApplet.html: AseAwkApplet.html cp -pf AseAwkApplet.html $(OUT_DIR) -$(OUT_DIR): - mkdir -p $(OUT_DIR) +$(OUT_DIR_BIN): + mkdir -p $(OUT_DIR_BIN) $(TMP_DIR): mkdir -p $(TMP_DIR) clean: - rm -rf $(OUT_DIR)/aseawk $(OUT_DIR)/aseawk_mini $(OUT_DIR)/aseawk++ $(OUT_DIR)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html $(TMP_DIR)/*.class + rm -rf $(OUT_DIR_BIN)/aseawk $(OUT_DIR_BIN)/aseawk_mini $(OUT_DIR_BIN)/aseawk++ $(OUT_DIR_BIN)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html $(TMP_DIR)/*.class