*** empty log message ***

This commit is contained in:
hyung-hwan 2007-04-12 10:51:14 +00:00
parent e342f35f15
commit 651b920e89
3 changed files with 224 additions and 42 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.java,v 1.19 2007-04-11 15:21:23 bacon Exp $ * $Id: StdAwk.java,v 1.20 2007-04-12 10:50:05 bacon Exp $
* *
* {License} * {License}
*/ */
@ -27,9 +27,13 @@ public abstract class StdAwk extends Awk
private long seed; private long seed;
private java.util.Random random; private java.util.Random random;
private static Reader stdin = null; private final static Reader stdin =
private static Writer stdout = null; new BufferedReader (new InputStreamReader (System.in));
private final static Writer stdout =
new BufferedWriter (new OutputStreamWriter (System.out));
/*
static static
{ {
stdin = new BufferedReader ( stdin = new BufferedReader (
@ -37,6 +41,7 @@ public abstract class StdAwk extends Awk
stdout = new BufferedWriter ( stdout = new BufferedWriter (
new OutputStreamWriter (System.out)); new OutputStreamWriter (System.out));
} }
*/
public StdAwk () throws Exception public StdAwk () throws Exception
{ {
@ -95,12 +100,12 @@ public abstract class StdAwk extends Awk
/* == source code names == */ /* == source code names == */
protected abstract String[] sourceInputNames (); protected String[] sourceInputNames () { return null; }
protected String[] sourceOutputNames () { return null; } protected String[] sourceOutputNames () { return null; }
/* == console names == */ /* == console names == */
protected abstract String[] consoleInputNames (); protected String[] consoleInputNames () { return null; }
protected abstract String[] consoleOutputNames (); protected String[] consoleOutputNames () { return null; }
/* == source code == */ /* == source code == */
protected int openSource (int mode) protected int openSource (int mode)
@ -434,17 +439,7 @@ public abstract class StdAwk extends Awk
{ {
Reader isr; Reader isr;
if (name == null || name.length() == 0) if (name == null || name.length() == 0) isr = StdAwk.stdin;
{
//FileInputStream fis;
//fis = new FileInputStream (FileDescriptor.in);
//isr = new BufferedReader (new InputStreamReader (fis));
//isr = new BufferedReader (
// new InputStreamReader (System.in));
isr = StdAwk.stdin;
}
else else
{ {
FileInputStream fis; FileInputStream fis;
@ -460,18 +455,7 @@ public abstract class StdAwk extends Awk
{ {
Writer osw; Writer osw;
if (name == null || name.length() == 0) if (name == null || name.length() == 0) osw = StdAwk.stdout;
{
//FileOutputStream fos;
//fos = new FileOutputStream (FileDescriptor.out);
//osw = new BufferedWriter (new OutputStreamWriter (fos));
//osw = new BufferedWriter(
// new OutputStreamWriter (System.out));
osw = StdAwk.stdout;
}
else else
{ {
FileOutputStream fos; FileOutputStream fos;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: AseAwkPanel.java,v 1.1 2007-04-12 10:08:08 bacon Exp $ * $Id: AseAwkPanel.java,v 1.2 2007-04-12 10:50:05 bacon Exp $
*/ */
import java.awt.*; import java.awt.*;
@ -12,9 +12,69 @@ import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import ase.awk.StdAwk; import ase.awk.StdAwk;
import ase.awk.Extio;
public class AseAwkPanel extends Panel public class AseAwkPanel extends Panel
{ {
/* MsgBox taken from http://www.rgagnon.com/javadetails/java-0242.html */
class MsgBox extends Dialog implements ActionListener
{
boolean id = false;
Button ok,can;
MsgBox (Frame frame, String msg, boolean okcan)
{
super (frame, "Message", true);
setLayout(new BorderLayout());
add("Center",new Label(msg));
addOKCancelPanel(okcan);
createFrame();
pack();
setVisible(true);
}
void addOKCancelPanel( boolean okcan )
{
Panel p = new Panel();
p.setLayout(new FlowLayout());
createOKButton( p );
if (okcan == true) createCancelButton( p );
add("South",p);
}
void createOKButton(Panel p)
{
p.add(ok = new Button("OK"));
ok.addActionListener(this);
}
void createCancelButton(Panel p)
{
p.add(can = new Button("Cancel"));
can.addActionListener(this);
}
void createFrame()
{
Dimension d = getToolkit().getScreenSize();
setLocation(d.width/3,d.height/3);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == ok)
{
id = true;
setVisible(false);
}
else if(ae.getSource() == can)
{
setVisible(false);
}
}
}
class Awk extends StdAwk class Awk extends StdAwk
{ {
private AseAwkPanel awkPanel; private AseAwkPanel awkPanel;
@ -22,6 +82,9 @@ public class AseAwkPanel extends Panel
private StringReader srcIn; private StringReader srcIn;
private StringWriter srcOut; private StringWriter srcOut;
private StringReader conIn;
private StringWriter conOut;
public Awk (AseAwkPanel awkPanel) throws Exception public Awk (AseAwkPanel awkPanel) throws Exception
{ {
super (); super ();
@ -65,7 +128,12 @@ public class AseAwkPanel extends Panel
protected int readSource (char[] buf, int len) protected int readSource (char[] buf, int len)
{ {
try { return srcIn.read (buf, 0, len); } try
{
int n = srcIn.read (buf, 0, len);
if (n == -1) n = 0;
return n;
}
catch (IOException e) { return -1; } catch (IOException e) { return -1; }
} }
@ -74,6 +142,103 @@ public class AseAwkPanel extends Panel
srcOut.write (buf, 0, len); srcOut.write (buf, 0, len);
return len; return len;
} }
protected int openConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
conIn = new StringReader (awkPanel.getConsoleInput());
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
conOut = new StringWriter ();
return 1;
}
return -1;
}
protected int closeConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
conIn.close ();
return 0;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
awkPanel.setConsoleOutput (conOut.toString());
try { conOut.close (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int readConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
try
{
int n = conIn.read (buf, 0, len);
if (n == -1) n = 0;
return n;
}
catch (IOException e) { return -1; }
}
return -1;
}
protected int writeConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_WRITE)
{
conOut.write (buf, 0, len);
return len;
}
return -1;
}
protected int flushConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_WRITE)
{
return 0;
}
return -1;
}
protected int nextConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
}
return -1;
}
} }
private TextArea srcIn; private TextArea srcIn;
@ -82,6 +247,8 @@ public class AseAwkPanel extends Panel
private TextArea conOut; private TextArea conOut;
private TextField jniLib; private TextField jniLib;
private boolean jniLibLoaded = false;
public AseAwkPanel () public AseAwkPanel ()
{ {
jniLib = new TextField (); jniLib = new TextField ();
@ -133,16 +300,19 @@ public class AseAwkPanel extends Panel
add (centerPanel, BorderLayout.CENTER); add (centerPanel, BorderLayout.CENTER);
add (runBtn, BorderLayout.SOUTH); add (runBtn, BorderLayout.SOUTH);
URL url = this.getClass().getResource ("AseAwkApplet.class"); URL url = this.getClass().getResource (this.getClass().getName() + ".class");
File file = new File (url.getFile()); File file = new File (url.getFile());
System.out.println (System.getProperty("os.name"));
if (System.getProperty ("os.name").toLowerCase().startsWith ("windows")) if (System.getProperty ("os.name").toLowerCase().startsWith ("windows"))
{ {
jniLib.setText (file.getParentFile().getParentFile().getParent() + "/lib/aseawk_jni.dll"); String path = file.getParentFile().getParentFile().getParent() + "\\lib\\aseawk_jni.dll";
jniLib.setText (path.substring(6));
} }
else else
{ {
jniLib.setText (file.getParentFile().getParentFile().getParent() + "/lib/.libs/libaseawk_jni.dylib"); String path = file.getParentFile().getParentFile().getParent() + "/lib/.libs/libaseawk_jni.dylib";
jniLib.setText (path.substring(6));
} }
} }
@ -156,30 +326,45 @@ public class AseAwkPanel extends Panel
srcOut.setText (output); srcOut.setText (output);
} }
public String getConsoleInput ()
{
return conIn.getText ();
}
public void setConsoleOutput (String output)
{
conOut.setText (output);
}
private void runAwk () private void runAwk ()
{ {
Awk awk = null; Awk awk = null;
try if (!jniLibLoaded)
{ {
try try
{ {
System.load (jniLib.getText()); System.load (jniLib.getText());
jniLib.setEnabled (false);
jniLibLoaded = true;
} }
catch (Exception e) catch (UnsatisfiedLinkError e)
{ {
System.err.println ("xxx fuck you - cannot load library: " + e.getMessage()); showMessage ("Cannot load libraryi - " + e.getMessage());
return; return;
} }
}
try
{
try try
{ {
awk = new Awk (this); awk = new Awk (this);
} }
catch (Exception e) catch (Exception e)
{ {
System.err.println ("cannot create awk - " + e.getMessage()); showMessage ("Cannot instantiate awk - " + e.getMessage());
return;
} }
awk.parse (); awk.parse ();
@ -187,11 +372,21 @@ public class AseAwkPanel extends Panel
} }
catch (ase.awk.Exception e) catch (ase.awk.Exception e)
{ {
System.out.println ("ase.awk.Exception - " + e.getMessage()); showMessage ("An exception occurred - " + e.getMessage());
return;
} }
finally finally
{ {
if (awk != null) awk.close (); if (awk != null) awk.close ();
} }
} }
private void showMessage (String msg)
{
Frame tmp = new Frame ("");
MsgBox message = new MsgBox (tmp, msg, false);
requestFocus ();
message.dispose ();
tmp.dispose ();
}
} }

View File

@ -1,5 +1,5 @@
# #
# $Id: makefile.in,v 1.21 2007-04-11 09:39:46 bacon Exp $ # $Id: makefile.in,v 1.22 2007-04-12 10:51:14 bacon Exp $
# #
CC = @CC@ CC = @CC@
@ -31,7 +31,7 @@ $(OUT_DIR)/aseawk: awk.c
$(OUT_DIR)/aseawk_mini: mini.c $(OUT_DIR)/aseawk_mini: mini.c
$(CC) $(CFLAGS) -o $@ mini.c $(LDFLAGS) $(LIBS) $(CC) $(CFLAGS) -o $@ mini.c $(LDFLAGS) $(LIBS)
$(OUT_DIR)/aseawk.jar: $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkApplet.class $(OUT_DIR)/aseawk.jar: $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkPanel.class $(TMP_DIR)/AseAwkApplet.class
cd $(TMP_DIR); $(JAR) -xvf ../$(LIB_DIR)/aseawk.jar cd $(TMP_DIR); $(JAR) -xvf ../$(LIB_DIR)/aseawk.jar
cd $(TMP_DIR); $(JAR) -Mcvf ../$@ *.class ase cd $(TMP_DIR); $(JAR) -Mcvf ../$@ *.class ase
rm -rf $(TMP_DIR)/ase rm -rf $(TMP_DIR)/ase
@ -39,6 +39,9 @@ $(OUT_DIR)/aseawk.jar: $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkApplet.class
$(TMP_DIR)/AseAwk.class: $(TMP_DIR) AseAwk.java $(TMP_DIR)/AseAwk.class: $(TMP_DIR) AseAwk.java
$(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwk.java $(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwk.java
$(TMP_DIR)/AseAwkPanel.class: $(TMP_DIR) AseAwkPanel.java
$(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwkPanel.java
$(TMP_DIR)/AseAwkApplet.class: $(TMP_DIR) AseAwkApplet.java $(TMP_DIR)/AseAwkApplet.class: $(TMP_DIR) AseAwkApplet.java
$(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwkApplet.java $(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwkApplet.java