*** empty log message ***

This commit is contained in:
hyung-hwan 2007-04-12 10:08:08 +00:00
parent ac7a89c0ed
commit e342f35f15
3 changed files with 231 additions and 122 deletions

View File

@ -1,38 +1,15 @@
/* /*
* $Id: AseAwk.java,v 1.3 2007-04-11 15:21:24 bacon Exp $ * $Id: AseAwk.java,v 1.4 2007-04-12 10:08:07 bacon Exp $
*/ */
import java.net.URL; import java.awt.*;
import java.awt.event.*;
public class AseAwk extends ase.awk.StdAwk public class AseAwk extends ase.awk.StdAwk
{ {
public AseAwk () throws ase.awk.Exception public AseAwk () throws ase.awk.Exception
{ {
super (); super ();
addBuiltinFunction ("xxx", 1, 10);
//addBuiltinFunction ("xxx", 1, 1);
//deleteBuiltinFunction ("sin");
//deleteBuiltinFunction ("sin");
}
public Object xxx (long runid, Object[] args)
{
System.out.println ("<<BFN_XXX>>");
for (int i = 0; i < args.length; i++)
{
System.out.print ("ARG #" + i);
System.out.print (": ");
if (args[i] == null) System.out.println ("nil");
else System.out.println (args[i].toString());
}
return null;
//return new String ("return value");
//return new Double (1.234);
//return new Float (1.234);
//return new Integer (1001);
//return new Long (1001);
//return new Short ((short)1001);
} }
protected String[] consoleInputNames () protected String[] consoleInputNames ()
@ -74,16 +51,36 @@ public class AseAwk extends ase.awk.StdAwk
public static void main (String[] args) public static void main (String[] args)
{ {
AseAwk awk = null; // AWT mode
if (args.length == 0)
{
final Frame frame = new Frame ();
/* frame.setLayout (new BorderLayout());
URL url = ase.awk.Awk.class.getResource ("aseawk_jni.dll"); frame.setTitle (AseAwk.class.getName());
if (url == null) url = ase.awk.Awk.class.getResource ("aseawk_jni.so"); frame.setSize (640, 480);
if (url != null) System.load (url.getFile()); frame.addWindowListener (new WindowListener ()
*/ {
public void windowActivated (WindowEvent e) {}
public void windowClosed (WindowEvent e) {}
public void windowClosing (WindowEvent e) { frame.dispose (); }
public void windowDeactivated (WindowEvent e) {}
public void windowDeiconified (WindowEvent e) {}
public void windowIconified (WindowEvent e) {}
public void windowOpened (WindowEvent e) {}
});
frame.add (new AseAwkPanel(), BorderLayout.CENTER);
frame.setVisible (true);
return;
}
// console mode
AseAwk awk = null;
if (args.length != 1) if (args.length != 1)
{ {
System.err.println ("Usage: " + AseAwk.class.getName() + " jni"); System.err.println ("Usage: " + AseAwk.class.getName() + " jni");
System.err.println ("Where jni := the full path to the jni library"); System.err.println ("Where jni := the full path to the jni library");
return; return;

View File

@ -1,108 +1,23 @@
/* /*
* $Id: AseAwkApplet.java,v 1.3 2007-04-11 10:49:34 bacon Exp $ * $Id: AseAwkApplet.java,v 1.4 2007-04-12 10:08:08 bacon Exp $
*/ */
import java.applet.*; import java.applet.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.net.URL;
import java.io.File;
public class AseAwkApplet extends Applet public class AseAwkApplet extends Applet
{ {
private TextArea srcIn; AseAwkPanel awkPanel;
private TextArea srcOut;
private TextArea conIn;
private TextArea conOut;
private TextField jniLib;
public void init () public void init ()
{ {
jniLib = new TextField (); awkPanel = new AseAwkPanel ();
srcIn = new TextArea (); setLayout (new BorderLayout ());
srcOut = new TextArea (); add (awkPanel, BorderLayout.CENTER);
conIn = new TextArea ();
conOut = new TextArea ();
Button runBtn = new Button ("Run Awk");
runBtn.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
runAwk ();
}
});
Panel topPanel = new Panel ();
BorderLayout topPanelLayout = new BorderLayout ();
topPanel.setLayout (topPanelLayout);
topPanelLayout.setHgap (2);
topPanelLayout.setVgap (2);
topPanel.add (new Label ("JNI Library: "), BorderLayout.WEST);
topPanel.add (jniLib, BorderLayout.CENTER);
Panel centerPanel = new Panel ();
GridLayout centerPanelLayout = new GridLayout (2, 2);
centerPanel.setLayout (centerPanelLayout);
centerPanelLayout.setHgap (2);
centerPanelLayout.setVgap (2);
centerPanel.add (srcIn);
centerPanel.add (srcOut);
centerPanel.add (conIn);
centerPanel.add (conOut);
BorderLayout mainLayout = new BorderLayout ();
mainLayout.setHgap (2);
mainLayout.setVgap (2);
setLayout (mainLayout);
add (topPanel, BorderLayout.NORTH);
add (centerPanel, BorderLayout.CENTER);
add (runBtn, BorderLayout.SOUTH);
URL url = this.getClass().getResource ("AseAwk.class");
File file = new File (url.getFile());
jniLib.setText (file.getParentFile().getParentFile().getParent() + "/lib/.libs/libaseawk_jni.dylib");
} }
public void stop () {} public void stop () {}
public void paint (Graphics g) {} public void paint (Graphics g) {}
private void runAwk ()
{
AseAwk awk = null;
try
{
try
{
System.load (jniLib.getText());
}
catch (Exception e)
{
System.err.println ("xxx fuck you - cannot load library: " + e.getMessage());
}
awk = new AseAwk ();
awk.parse ();
awk.run ();
}
catch (ase.awk.Exception e)
{
System.out.println ("ase.awk.Exception - " + e.getMessage());
}
finally
{
if (awk != null) awk.close ();
}
}
} }

View File

@ -0,0 +1,197 @@
/*
* $Id: AseAwkPanel.java,v 1.1 2007-04-12 10:08:08 bacon Exp $
*/
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import ase.awk.StdAwk;
public class AseAwkPanel extends Panel
{
class Awk extends StdAwk
{
private AseAwkPanel awkPanel;
private StringReader srcIn;
private StringWriter srcOut;
public Awk (AseAwkPanel awkPanel) throws Exception
{
super ();
this.awkPanel = awkPanel;
}
protected int openSource (int mode)
{
if (mode == SOURCE_READ)
{
srcIn = new StringReader (awkPanel.getSourceInput());
return 1;
}
else if (mode == SOURCE_WRITE)
{
srcOut = new StringWriter ();
return 1;
}
return -1;
}
protected int closeSource (int mode)
{
if (mode == SOURCE_READ)
{
srcIn.close ();
return 0;
}
else if (mode == SOURCE_WRITE)
{
awkPanel.setSourceOutput (srcOut.toString());
try { srcOut.close (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int readSource (char[] buf, int len)
{
try { return srcIn.read (buf, 0, len); }
catch (IOException e) { return -1; }
}
protected int writeSource (char[] buf, int len)
{
srcOut.write (buf, 0, len);
return len;
}
}
private TextArea srcIn;
private TextArea srcOut;
private TextArea conIn;
private TextArea conOut;
private TextField jniLib;
public AseAwkPanel ()
{
jniLib = new TextField ();
srcIn = new TextArea ();
srcOut = new TextArea ();
conIn = new TextArea ();
conOut = new TextArea ();
Button runBtn = new Button ("Run Awk");
runBtn.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
runAwk ();
}
});
Panel topPanel = new Panel ();
BorderLayout topPanelLayout = new BorderLayout ();
topPanel.setLayout (topPanelLayout);
topPanelLayout.setHgap (2);
topPanelLayout.setVgap (2);
topPanel.add (new Label ("JNI Library: "), BorderLayout.WEST);
topPanel.add (jniLib, BorderLayout.CENTER);
Panel centerPanel = new Panel ();
GridLayout centerPanelLayout = new GridLayout (2, 2);
centerPanel.setLayout (centerPanelLayout);
centerPanelLayout.setHgap (2);
centerPanelLayout.setVgap (2);
centerPanel.add (srcIn);
centerPanel.add (srcOut);
centerPanel.add (conIn);
centerPanel.add (conOut);
BorderLayout mainLayout = new BorderLayout ();
mainLayout.setHgap (2);
mainLayout.setVgap (2);
setLayout (mainLayout);
add (topPanel, BorderLayout.NORTH);
add (centerPanel, BorderLayout.CENTER);
add (runBtn, BorderLayout.SOUTH);
URL url = this.getClass().getResource ("AseAwkApplet.class");
File file = new File (url.getFile());
if (System.getProperty ("os.name").toLowerCase().startsWith ("windows"))
{
jniLib.setText (file.getParentFile().getParentFile().getParent() + "/lib/aseawk_jni.dll");
}
else
{
jniLib.setText (file.getParentFile().getParentFile().getParent() + "/lib/.libs/libaseawk_jni.dylib");
}
}
public String getSourceInput ()
{
return srcIn.getText ();
}
public void setSourceOutput (String output)
{
srcOut.setText (output);
}
private void runAwk ()
{
Awk awk = null;
try
{
try
{
System.load (jniLib.getText());
}
catch (Exception e)
{
System.err.println ("xxx fuck you - cannot load library: " + e.getMessage());
return;
}
try
{
awk = new Awk (this);
}
catch (Exception e)
{
System.err.println ("cannot create awk - " + e.getMessage());
}
awk.parse ();
awk.run ();
}
catch (ase.awk.Exception e)
{
System.out.println ("ase.awk.Exception - " + e.getMessage());
}
finally
{
if (awk != null) awk.close ();
}
}
}