*** 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}
*/
@ -27,9 +27,13 @@ public abstract class StdAwk extends Awk
private long seed;
private java.util.Random random;
private static Reader stdin = null;
private static Writer stdout = null;
private final static Reader stdin =
new BufferedReader (new InputStreamReader (System.in));
private final static Writer stdout =
new BufferedWriter (new OutputStreamWriter (System.out));
/*
static
{
stdin = new BufferedReader (
@ -37,6 +41,7 @@ public abstract class StdAwk extends Awk
stdout = new BufferedWriter (
new OutputStreamWriter (System.out));
}
*/
public StdAwk () throws Exception
{
@ -95,12 +100,12 @@ public abstract class StdAwk extends Awk
/* == source code names == */
protected abstract String[] sourceInputNames ();
protected String[] sourceInputNames () { return null; }
protected String[] sourceOutputNames () { return null; }
/* == console names == */
protected abstract String[] consoleInputNames ();
protected abstract String[] consoleOutputNames ();
protected String[] consoleInputNames () { return null; }
protected String[] consoleOutputNames () { return null; }
/* == source code == */
protected int openSource (int mode)
@ -434,17 +439,7 @@ public abstract class StdAwk extends Awk
{
Reader isr;
if (name == null || name.length() == 0)
{
//FileInputStream fis;
//fis = new FileInputStream (FileDescriptor.in);
//isr = new BufferedReader (new InputStreamReader (fis));
//isr = new BufferedReader (
// new InputStreamReader (System.in));
isr = StdAwk.stdin;
}
if (name == null || name.length() == 0) isr = StdAwk.stdin;
else
{
FileInputStream fis;
@ -460,18 +455,7 @@ public abstract class StdAwk extends Awk
{
Writer osw;
if (name == null || name.length() == 0)
{
//FileOutputStream fos;
//fos = new FileOutputStream (FileDescriptor.out);
//osw = new BufferedWriter (new OutputStreamWriter (fos));
//osw = new BufferedWriter(
// new OutputStreamWriter (System.out));
osw = StdAwk.stdout;
}
if (name == null || name.length() == 0) osw = StdAwk.stdout;
else
{
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.*;
@ -12,15 +12,78 @@ import java.io.StringReader;
import java.io.StringWriter;
import ase.awk.StdAwk;
import ase.awk.Extio;
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
{
private AseAwkPanel awkPanel;
private StringReader srcIn;
private StringWriter srcOut;
private StringReader conIn;
private StringWriter conOut;
public Awk (AseAwkPanel awkPanel) throws Exception
{
@ -65,7 +128,12 @@ public class AseAwkPanel extends Panel
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; }
}
@ -74,6 +142,103 @@ public class AseAwkPanel extends Panel
srcOut.write (buf, 0, 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;
@ -82,6 +247,8 @@ public class AseAwkPanel extends Panel
private TextArea conOut;
private TextField jniLib;
private boolean jniLibLoaded = false;
public AseAwkPanel ()
{
jniLib = new TextField ();
@ -133,16 +300,19 @@ public class AseAwkPanel extends Panel
add (centerPanel, BorderLayout.CENTER);
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());
System.out.println (System.getProperty("os.name"));
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
{
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);
}
public String getConsoleInput ()
{
return conIn.getText ();
}
public void setConsoleOutput (String output)
{
conOut.setText (output);
}
private void runAwk ()
{
Awk awk = null;
try
if (!jniLibLoaded)
{
try
{
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;
}
}
try
{
try
{
awk = new Awk (this);
}
catch (Exception e)
{
System.err.println ("cannot create awk - " + e.getMessage());
showMessage ("Cannot instantiate awk - " + e.getMessage());
return;
}
awk.parse ();
@ -187,11 +372,21 @@ public class AseAwkPanel extends Panel
}
catch (ase.awk.Exception e)
{
System.out.println ("ase.awk.Exception - " + e.getMessage());
showMessage ("An exception occurred - " + e.getMessage());
return;
}
finally
{
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@
@ -31,7 +31,7 @@ $(OUT_DIR)/aseawk: awk.c
$(OUT_DIR)/aseawk_mini: mini.c
$(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) -Mcvf ../$@ *.class 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
$(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
$(JAVAC) -classpath $(TMP_DIR):$(LIB_DIR)/aseawk.jar -d $(TMP_DIR) AseAwkApplet.java