From 70b8ed1f8de4aa810e4322b3615dc978251a0fb7 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 29 May 2007 00:42:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-05-27 05:11:00 --- ase/awk/Awk.java | 187 ++++++++++++++------- ase/awk/Console.java | 28 ++++ ase/awk/Extio.java | 31 ++-- ase/awk/File.java | 18 +++ ase/awk/IO.java | 44 +++++ ase/awk/Pipe.java | 16 ++ ase/awk/StdAwk.java | 296 +++++++++++++++++----------------- ase/awk/makefile.in | 14 +- ase/change.log | 8 +- ase/test/awk/AseAwk.java | 160 +++++++++--------- ase/test/awk/AseAwkPanel.java | 75 +++++---- ase/test/awk/Awk.cpp | 4 +- ase/test/awk/x.awk | 2 +- 13 files changed, 531 insertions(+), 352 deletions(-) create mode 100644 ase/awk/Console.java create mode 100644 ase/awk/File.java create mode 100644 ase/awk/IO.java create mode 100644 ase/awk/Pipe.java diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java index dd1721dd..cf72221a 100644 --- a/ase/awk/Awk.java +++ b/ase/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.8 2007/05/25 14:41:48 bacon Exp $ + * $Id: Awk.java,v 1.10 2007/05/26 10:52:48 bacon Exp $ * * {License} */ @@ -50,15 +50,14 @@ public abstract class Awk public Awk () throws Exception { this.handle = 0; - open (); } /* == just in case == */ protected void finalize () throws Throwable { - super.finalize (); if (handle != 0) close (); + super.finalize (); } /* == native methods == */ @@ -80,9 +79,9 @@ public abstract class Awk String name, int min_args, int max_args) throws Exception; private native void delbfn (String name) throws Exception; - private native void setfilename ( + native void setfilename ( long runid, String name) throws Exception; - private native void setofilename ( + native void setofilename ( long runid, String name) throws Exception; private native Object strtonum ( @@ -266,21 +265,51 @@ public abstract class Awk /* == external io interface == */ protected int openExtio (Extio extio) { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return openConsole (extio); - if (type == Extio.TYPE_FILE) return openFile (extio); - if (type == Extio.TYPE_PIPE) return openPipe (extio); - //if (type == Extio.TYPE_COPROC) return openCoproc (extio); + switch (extio.getType()) + { + case Extio.TYPE_CONSOLE: + { + Console con = new Console (this, extio); + int n = openConsole (con); + extio.setHandle (con); + return n; + } + + case Extio.TYPE_FILE: + { + File file = new File (this, extio); + int n = openFile (file); + extio.setHandle (file); + return n; + } + + case Extio.TYPE_PIPE: + { + Pipe pipe = new Pipe (this, extio); + int n = openPipe (pipe); + extio.setHandle (pipe); + return n; + } + } + return -1; } protected int closeExtio (Extio extio) { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return closeConsole (extio); - if (type == Extio.TYPE_FILE) return closeFile (extio); - if (type == Extio.TYPE_PIPE) return closePipe (extio); - //if (type == Extio.TYPE_COPROC) return closeCoproc (extio); + switch (extio.getType()) + { + case Extio.TYPE_CONSOLE: + return closeConsole ( + (Console)extio.getHandle()); + + case Extio.TYPE_FILE: + return closeFile ((File)extio.getHandle()); + + case Extio.TYPE_PIPE: + return closePipe ((Pipe)extio.getHandle()); + } + return -1; } @@ -292,15 +321,28 @@ public abstract class Awk // the end of the stream. if (len <= 0) return -1; - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) - return readConsole (extio, buf, len); - if (type == Extio.TYPE_FILE) - return readFile (extio, buf, len); - if (type == Extio.TYPE_PIPE) - return readPipe (extio, buf, len); - //if (type == Extio.TYPE_COPROC) - // return readCoproc (extio, buf, len); + switch (extio.getType()) + { + + case Extio.TYPE_CONSOLE: + { + return readConsole ( + (Console)extio.getHandle(), buf, len); + } + + case Extio.TYPE_FILE: + { + return readFile ( + (File)extio.getHandle(), buf, len); + } + + case Extio.TYPE_PIPE: + { + return readPipe ( + (Pipe)extio.getHandle(), buf, len); + } + } + return -1; } @@ -308,51 +350,86 @@ public abstract class Awk { if (len <= 0) return -1; - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) - return writeConsole (extio, buf, len); - if (type == Extio.TYPE_FILE) - return writeFile (extio, buf, len); - if (type == Extio.TYPE_PIPE) - return writePipe (extio, buf, len); - //if (type == Extio.TYPE_COPROC) - // return writeCoproc (extio, buf, len); + switch (extio.getType()) + { + + case Extio.TYPE_CONSOLE: + { + return writeConsole ( + (Console)extio.getHandle(), buf, len); + } + + case Extio.TYPE_FILE: + { + return writeFile ( + (File)extio.getHandle(), buf, len); + } + + case Extio.TYPE_PIPE: + { + return writePipe ( + (Pipe)extio.getHandle(), buf, len); + } + } + return -1; } protected int flushExtio (Extio extio) { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return flushConsole (extio); - if (type == Extio.TYPE_FILE) return flushFile (extio); - if (type == Extio.TYPE_PIPE) return flushPipe (extio); - //if (type == Extio.TYPE_COPROC) return flushCoproc (extio); + switch (extio.getType()) + { + + case Extio.TYPE_CONSOLE: + { + return flushConsole ((Console)extio.getHandle()); + } + + case Extio.TYPE_FILE: + { + return flushFile ((File)extio.getHandle()); + } + + case Extio.TYPE_PIPE: + { + return flushPipe ((Pipe)extio.getHandle()); + } + } + return -1; } protected int nextExtio (Extio extio) { int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return nextConsole (extio); + + switch (extio.getType()) + { + case Extio.TYPE_CONSOLE: + { + return nextConsole ((Console)extio.getHandle()); + } + } + return -1; } - protected abstract int openConsole (Extio extio); - protected abstract int closeConsole (Extio extio); - protected abstract int readConsole (Extio extio, char[] buf, int len); - protected abstract int writeConsole (Extio extio, char[] buf, int len); - protected abstract int flushConsole (Extio extio); - protected abstract int nextConsole (Extio extio); + protected abstract int openConsole (Console con); + protected abstract int closeConsole (Console con); + protected abstract int readConsole (Console con, char[] buf, int len); + protected abstract int writeConsole (Console con, char[] buf, int len); + protected abstract int flushConsole (Console con); + protected abstract int nextConsole (Console con); - protected abstract int openFile (Extio extio); - protected abstract int closeFile (Extio extio); - protected abstract int readFile (Extio extio, char[] buf, int len); - protected abstract int writeFile (Extio extio, char[] buf, int len); - protected abstract int flushFile (Extio extio); + protected abstract int openFile (File file); + protected abstract int closeFile (File file); + protected abstract int readFile (File file, char[] buf, int len); + protected abstract int writeFile (File file, char[] buf, int len); + protected abstract int flushFile (File file); - protected abstract int openPipe (Extio extio); - protected abstract int closePipe (Extio extio); - protected abstract int readPipe (Extio extio, char[] buf, int len); - protected abstract int writePipe (Extio extio, char[] buf, int len); - protected abstract int flushPipe (Extio extio); + protected abstract int openPipe (Pipe pipe); + protected abstract int closePipe (Pipe pipe); + protected abstract int readPipe (Pipe pipe, char[] buf, int len); + protected abstract int writePipe (Pipe pipe, char[] buf, int len); + protected abstract int flushPipe (Pipe pipe); } diff --git a/ase/awk/Console.java b/ase/awk/Console.java new file mode 100644 index 00000000..97f6e9d5 --- /dev/null +++ b/ase/awk/Console.java @@ -0,0 +1,28 @@ +/* + * $Id: Console.java,v 1.2 2007/05/26 10:52:48 bacon Exp $ + */ + +package ase.awk; + +public class Console extends IO +{ + public static final int MODE_READ = Extio.MODE_CONSOLE_READ; + public static final int MODE_WRITE = Extio.MODE_CONSOLE_WRITE; + + protected Console (Awk awk, Extio extio) + { + super (awk, extio); + } + + public void setFileName (String name) throws Exception + { + if (getMode() == MODE_READ) + { + awk.setfilename (getRunId(), name); + } + else + { + awk.setofilename (getRunId(), name); + } + } +} diff --git a/ase/awk/Extio.java b/ase/awk/Extio.java index 165c3a49..9e110285 100644 --- a/ase/awk/Extio.java +++ b/ase/awk/Extio.java @@ -1,27 +1,27 @@ /* - * $Id: Extio.java,v 1.3 2007/04/30 05:47:33 bacon Exp $ + * $Id: Extio.java,v 1.5 2007/05/26 10:52:48 bacon Exp $ * * {License} */ package ase.awk; -public class Extio +class Extio { - public static final int TYPE_PIPE = 0; - public static final int TYPE_COPROC = 1; - public static final int TYPE_FILE = 2; - public static final int TYPE_CONSOLE = 3; + protected static final int TYPE_PIPE = 0; + protected static final int TYPE_COPROC = 1; + protected static final int TYPE_FILE = 2; + protected static final int TYPE_CONSOLE = 3; - public static final int MODE_PIPE_READ = 0; - public static final int MODE_PIPE_WRITE = 1; + protected static final int MODE_PIPE_READ = 0; + protected static final int MODE_PIPE_WRITE = 1; - public static final int MODE_FILE_READ = 0; - public static final int MODE_FILE_WRITE = 1; - public static final int MODE_FILE_APPEND = 2; + protected static final int MODE_FILE_READ = 0; + protected static final int MODE_FILE_WRITE = 1; + protected static final int MODE_FILE_APPEND = 2; - public static final int MODE_CONSOLE_READ = 0; - public static final int MODE_CONSOLE_WRITE = 1; + protected static final int MODE_CONSOLE_READ = 0; + protected static final int MODE_CONSOLE_WRITE = 1; private String name; private int type; @@ -67,9 +67,4 @@ public class Extio { return this.handle; } - - protected void finalize () throws Throwable - { - super.finalize (); - } }; diff --git a/ase/awk/File.java b/ase/awk/File.java new file mode 100644 index 00000000..bbeedd96 --- /dev/null +++ b/ase/awk/File.java @@ -0,0 +1,18 @@ +/* + * $Id: File.java,v 1.2 2007/05/26 10:52:48 bacon Exp $ + */ + +package ase.awk; + +public class File extends IO +{ + public static final int MODE_READ = Extio.MODE_FILE_READ; + public static final int MODE_WRITE = Extio.MODE_FILE_WRITE; + public static final int MODE_APPEND = Extio.MODE_FILE_APPEND; + + protected File (Awk awk, Extio extio) + { + super (awk, extio); + } + +} diff --git a/ase/awk/IO.java b/ase/awk/IO.java new file mode 100644 index 00000000..131eda56 --- /dev/null +++ b/ase/awk/IO.java @@ -0,0 +1,44 @@ +/* + * $Id: IO.java,v 1.1 2007/05/26 10:52:48 bacon Exp $ + */ + +package ase.awk; + +class IO +{ + protected Awk awk; + protected Extio extio; + protected Object handle; + + protected IO (Awk awk, Extio extio) + { + this.awk = awk; + this.extio = extio; + } + + public String getName () + { + return extio.getName(); + } + + public int getMode () + { + return extio.getMode(); + } + + public long getRunId () + { + return extio.getRunId(); + } + + public void setHandle (Object handle) + { + this.handle = handle; + } + + public Object getHandle () + { + return handle; + } + +} diff --git a/ase/awk/Pipe.java b/ase/awk/Pipe.java new file mode 100644 index 00000000..f4f6d445 --- /dev/null +++ b/ase/awk/Pipe.java @@ -0,0 +1,16 @@ +/* + * $Id: Pipe.java,v 1.2 2007/05/26 10:52:48 bacon Exp $ + */ + +package ase.awk; + +public class Pipe extends IO +{ + public static final int MODE_READ = Extio.MODE_PIPE_READ; + public static final int MODE_WRITE = Extio.MODE_PIPE_WRITE; + + protected Pipe (Awk awk, Extio extio) + { + super (awk, extio); + } +} diff --git a/ase/awk/StdAwk.java b/ase/awk/StdAwk.java index 3b5aab0b..1903c9a4 100644 --- a/ase/awk/StdAwk.java +++ b/ase/awk/StdAwk.java @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.java,v 1.9 2007/05/25 14:41:48 bacon Exp $ + * $Id: StdAwk.java,v 1.10 2007/05/26 10:23:52 bacon Exp $ * * {License} */ @@ -40,139 +40,124 @@ public abstract class StdAwk extends Awk } /* == file interface == */ - protected int openFile (Extio extio) + protected int openFile (File file) { - int mode = extio.getMode(); + int mode = file.getMode(); - if (mode == Extio.MODE_FILE_READ) + if (mode == File.MODE_READ) { FileInputStream fis; - Reader isr; - try { fis = new FileInputStream (extio.getName()); } + try { fis = new FileInputStream (file.getName()); } catch (IOException e) { return -1; } - isr = new BufferedReader (new InputStreamReader (fis)); - extio.setHandle (isr); + Reader rd = new BufferedReader ( + new InputStreamReader (fis)); + file.setHandle (rd); return 1; } - else if (mode == Extio.MODE_FILE_WRITE) + else if (mode == File.MODE_WRITE) { FileOutputStream fos; - Writer osw; - try { fos = new FileOutputStream (extio.getName()); } + try { fos = new FileOutputStream (file.getName()); } catch (IOException e) { return -1; } - osw = new BufferedWriter (new OutputStreamWriter (fos)); - extio.setHandle (osw); + Writer wr = new BufferedWriter ( + new OutputStreamWriter (fos)); + file.setHandle (wr); return 1; } - else if (mode == Extio.MODE_FILE_APPEND) + else if (mode == File.MODE_APPEND) { FileOutputStream fos; - Writer osw; - try { fos = new FileOutputStream (extio.getName(), true); } + try { fos = new FileOutputStream (file.getName(), true); } catch (IOException e) { return -1; } - osw = new BufferedWriter (new OutputStreamWriter (fos)); - extio.setHandle (osw); + Writer wr = new BufferedWriter ( + new OutputStreamWriter (fos)); + file.setHandle (wr); return 1; } return -1; } - protected int closeFile (Extio extio) + protected int closeFile (File file) { - int mode = extio.getMode(); + int mode = file.getMode(); - if (mode == Extio.MODE_FILE_READ) + if (mode == File.MODE_READ) { - Reader isr; - isr = (Reader)extio.getHandle(); - if (isr != null) - { - try { isr.close (); } - catch (IOException e) { return -1; } - } + Reader isr = (Reader)file.getHandle(); + try { isr.close (); } + catch (IOException e) { return -1; } return 0; } - else if (mode == Extio.MODE_FILE_WRITE) + else if (mode == File.MODE_WRITE) { - Writer osw; - osw = (Writer)extio.getHandle(); - if (osw != null) - { - try { osw.close (); } - catch (IOException e) { return -1; } - } + Writer osw = (Writer)file.getHandle(); + try { osw.close (); } + catch (IOException e) { return -1; } return 0; } - else if (mode == Extio.MODE_FILE_APPEND) + else if (mode == File.MODE_APPEND) { - Writer osw; - osw = (Writer)extio.getHandle(); - if (osw != null) - { - try { osw.close (); } - catch (IOException e) { return -1; } - } + Writer osw = (Writer)file.getHandle(); + try { osw.close (); } + catch (IOException e) { return -1; } return 0; } return -1; } - protected int readFile (Extio extio, char[] buf, int len) + protected int readFile (File file, char[] buf, int len) { - int mode = extio.getMode(); + int mode = file.getMode(); - if (mode == Extio.MODE_FILE_READ) + if (mode == File.MODE_READ) { - Reader isr; - isr = (Reader)extio.getHandle(); + Reader rd = (Reader)file.getHandle(); try { - len = isr.read (buf, 0, len); - if (len == -1) len = 0; + len = rd.read (buf, 0, len); + if (len == -1) return 0; } - catch (IOException e) { len = -1; } + catch (IOException e) { return -1; } return len; } return -1; } - protected int writeFile (Extio extio, char[] buf, int len) + protected int writeFile (File file, char[] buf, int len) { - int mode = extio.getMode(); + int mode = file.getMode(); - if (mode == Extio.MODE_FILE_WRITE || - mode == Extio.MODE_FILE_APPEND) + if (mode == File.MODE_WRITE || + mode == File.MODE_APPEND) { - Writer osw; - osw = (Writer)extio.getHandle(); - try { osw.write (buf, 0, len); } - catch (IOException e) { len = -1; } + Writer wr = (Writer)file.getHandle(); + try { wr.write (buf, 0, len); } + catch (IOException e) { return -1; } return len; } return -1; } - protected int flushFile (Extio extio) + protected int flushFile (File file) { - int mode = extio.getMode (); + int mode = file.getMode (); - if (mode == Extio.MODE_FILE_WRITE || - mode == Extio.MODE_FILE_APPEND) + if (mode == File.MODE_WRITE || + mode == File.MODE_APPEND) { - Writer osw; - osw = (Writer)extio.getHandle (); - try { osw.flush (); } + Writer wr = (Writer)file.getHandle (); + try { wr.flush (); } catch (IOException e) { return -1; } return 0; } @@ -180,82 +165,126 @@ public abstract class StdAwk extends Awk return -1; } + private class RWE + { + public Writer wr; + public Reader rd; + public Reader er; + + public RWE (Writer wr, Reader rd, Reader er) + { + this.wr = wr; + this.rd = rd; + this.er = er; + } + }; + /* == pipe interface == */ - protected int openPipe (Extio extio) + protected int openPipe (Pipe pipe) { - int mode = extio.getMode(); + int mode = pipe.getMode(); - if (mode == Extio.MODE_PIPE_READ) + if (mode == Pipe.MODE_READ) { - Process proc; - Reader isr; - try { proc = popen (extio.getName()); } + try { proc = popen (pipe.getName()); } catch (IOException e) { return -1; } - isr = new BufferedReader (new InputStreamReader (proc.getInputStream())); - extio.setHandle (isr); + Reader rd = new BufferedReader ( + new InputStreamReader (proc.getInputStream())); + + pipe.setHandle (rd); return 1; } - else if (mode == Extio.MODE_PIPE_WRITE) + else if (mode == Pipe.MODE_WRITE) { Process proc; - Writer osw; - try { proc = popen (extio.getName()); } + try { proc = popen (pipe.getName()); } catch (IOException e) { return -1; } - osw = new BufferedWriter (new OutputStreamWriter (proc.getOutputStream())); - extio.setHandle (osw); + Writer wr = new BufferedWriter ( + new OutputStreamWriter (proc.getOutputStream())); + Reader rd = new BufferedReader ( + new InputStreamReader (proc.getInputStream())); + Reader er = new BufferedReader ( + new InputStreamReader (proc.getErrorStream())); + + pipe.setHandle (new RWE (wr, rd, er)); return 1; } return -1; } - protected int closePipe (Extio extio) + protected int closePipe (Pipe pipe) { - int mode = extio.getMode(); + int mode = pipe.getMode(); - if (mode == Extio.MODE_PIPE_READ) + if (mode == Pipe.MODE_READ) { - Reader isr; - isr = (Reader)extio.getHandle(); - if (isr != null) - { - try { isr.close (); } - catch (IOException e) { return -1; } - } + Reader rd = (Reader)pipe.getHandle(); + try { rd.close (); } + catch (IOException e) { return -1; } return 0; } - else if (mode == Extio.MODE_PIPE_WRITE) + else if (mode == Pipe.MODE_WRITE) { - Writer osw; - osw = (Writer)extio.getHandle(); - if (osw != null) + //Writer wr = (Writer)pipe.getHandle(); + RWE rwe = (RWE)pipe.getHandle(); + + try { rwe.wr.close (); } + catch (IOException e) { return -1; } + + char[] buf = new char[256]; + + try { - try { osw.close (); } - catch (IOException e) { return -1; } + while (true) + { + int len = rwe.rd.read (buf, 0, buf.length); + if (len == -1) break; + System.out.print (new String (buf, 0, len)); + } + + System.out.flush (); } + catch (IOException e) {} + + try + { + while (true) + { + int len = rwe.er.read (buf, 0, buf.length); + if (len == -1) break; + System.err.print (new String (buf, 0, len)); + } + + System.err.flush (); + } + catch (IOException e) {} + + try { rwe.rd.close (); } catch (IOException e) {} + try { rwe.er.close (); } catch (IOException e) {} + + pipe.setHandle (null); return 0; } return -1; } - protected int readPipe (Extio extio, char[] buf, int len) + protected int readPipe (Pipe pipe, char[] buf, int len) { - int mode = extio.getMode(); + int mode = pipe.getMode(); - if (mode == Extio.MODE_PIPE_READ) + if (mode == Pipe.MODE_READ) { - Reader isr; - isr = (Reader)extio.getHandle(); - + Reader rd = (Reader)pipe.getHandle(); try { - len = isr.read (buf, 0, len); + len = rd.read (buf, 0, len); if (len == -1) len = 0; } catch (IOException e) { len = -1; } @@ -265,31 +294,34 @@ public abstract class StdAwk extends Awk return -1; } - protected int writePipe (Extio extio, char[] buf, int len) + protected int writePipe (Pipe pipe, char[] buf, int len) { - int mode = extio.getMode(); + int mode = pipe.getMode(); - if (mode == Extio.MODE_PIPE_WRITE) + if (mode == Pipe.MODE_WRITE) { - Writer osw; - osw = (Writer)extio.getHandle(); - try { osw.write (buf, 0, len); } - catch (IOException e) { len = -1; } + //Writer wr = (Writer)pipe.getHandle (); + RWE rw = (RWE)pipe.getHandle(); + try + { + rw.wr.write (buf, 0, len); + rw.wr.flush (); + } + catch (IOException e) { return -1; } return len; } return -1; } - protected int flushPipe (Extio extio) + protected int flushPipe (Pipe pipe) { - int mode = extio.getMode (); + int mode = pipe.getMode (); - if (mode == Extio.MODE_PIPE_WRITE) + if (mode == Pipe.MODE_WRITE) { - Writer osw; - osw = (Writer)extio.getHandle (); - try { osw.flush (); } + Writer wr = (Writer)pipe.getHandle (); + try { wr.flush (); } catch (IOException e) { return -1; } return 0; } @@ -390,38 +422,6 @@ public abstract class StdAwk extends Awk { String str = builtinFunctionArgumentToString (runid, args[0]); return system (str); - - /* - String str = builtinFunctionArgumentToString (runid, args[0]); - Process proc = null; - int n = 0; - - str = builtinFunctionArgumentToString (runid, args[0]); - - try { proc = popen (str); } - catch (IOException e) { n = -1; } - - if (proc != null) - { - InputStream is; - byte[] buf = new byte[1024]; - - is = proc.getInputStream(); - - // TODO; better error handling... program execution.. io redirection??? - try { while (is.read (buf) != -1) ; } - catch (IOException e) { n = -1; }; - - try { n = proc.waitFor (); } - catch (InterruptedException e) - { - proc.destroy (); - n = -1; - } - } - - return new Long (n); - */ } /* == utility functions == */ diff --git a/ase/awk/makefile.in b/ase/awk/makefile.in index 159780e2..0b9bf15d 100644 --- a/ase/awk/makefile.in +++ b/ase/awk/makefile.in @@ -1,5 +1,5 @@ # -# $Id: makefile.in,v 1.6 2007/05/25 11:49:42 bacon Exp $ +# $Id: makefile.in,v 1.7 2007/05/26 10:58:38 bacon Exp $ # NAME = aseawk @@ -132,6 +132,18 @@ $(TMP_DIR)/ase/awk/StdAwk.class: StdAwk.java $(TMP_DIR)/ase/awk/Extio.class: Extio.java $(JAVAC) -classpath ../.. -d $(TMP_DIR) Extio.java +$(TMP_DIR)/ase/awk/IO.class: IO.java + $(JAVAC) -classpath ../.. -d $(TMP_DIR) IO.java + +$(TMP_DIR)/ase/awk/Console.class: Console.java + $(JAVAC) -classpath ../.. -d $(TMP_DIR) Console.java + +$(TMP_DIR)/ase/awk/File.class: File.java + $(JAVAC) -classpath ../.. -d $(TMP_DIR) File.java + +$(TMP_DIR)/ase/awk/Pipe.class: Pipe.java + $(JAVAC) -classpath ../.. -d $(TMP_DIR) Pipe.java + $(TMP_DIR)/ase/awk/Exception.class: Exception.java $(JAVAC) -classpath ../.. -d $(TMP_DIR) Exception.java diff --git a/ase/change.log b/ase/change.log index 813460de..362576fb 100644 --- a/ase/change.log +++ b/ase/change.log @@ -2,7 +2,7 @@ * fixed bug (nextofile shown as nextfile in source output) * fixed bug (nextofile not allowed in the BEGIN and END block) -* fixed bug (ASE_MALLOC/ASE_FREE defined wrongly causing test programs +* fixed bug (ASE_MALLOC/ASE_FREE defined wrongly causing sample programs to crash in the debug mode when compiled with MSVC/C++. * fixed bug (the first character of the next record lost when RS are multiple characters) @@ -10,11 +10,9 @@ multiple characters) * added awk c++ classes (awk/Awk.hpp awk/Awk.cpp awk/StdAwk.hpp awk/StdAwk.cpp) -* added c++ test program (test/awk/Awk.cpp) - -* modified the java test program (test/awk/AseAwk.java) to be the same as - the c++ test program functionally +* added c++ sample program (test/awk/Awk.cpp) +* changed test/awk/AseAwk.java to be funtionally identical to test/awk/Awk.cpp * changed the way to invoke the main function (utl/main.h utl/main.c) [0.1.0] diff --git a/ase/test/awk/AseAwk.java b/ase/test/awk/AseAwk.java index 8bce6b9f..a41d625c 100644 --- a/ase/test/awk/AseAwk.java +++ b/ase/test/awk/AseAwk.java @@ -1,5 +1,5 @@ /* - * $Id: AseAwk.java,v 1.6 2007/05/25 16:55:02 bacon Exp $ + * $Id: AseAwk.java,v 1.7 2007/05/26 10:23:52 bacon Exp $ */ import java.awt.*; @@ -62,7 +62,7 @@ public class AseAwk extends StdAwk { URL url = AseAwk.class.getResource ( AseAwk.class.getName() + ".class"); - File file = new File (url.getFile()); + java.io.File file = new java.io.File (url.getFile()); String osname = System.getProperty ("os.name").toLowerCase(); String aseBase = file.getParentFile().getParentFile().getParent( @@ -249,8 +249,6 @@ public class AseAwk extends StdAwk private String srcInName; private String srcOutName; - private Reader conReader; - private Writer conWriter; private LinkedList conInNames; private LinkedList conOutNames; private Iterator conInIter; @@ -266,9 +264,6 @@ public class AseAwk extends StdAwk srcInName = null; srcOutName = null; - conReader = null; - conWriter = null; - conInNames = new LinkedList (); conOutNames = new LinkedList (); @@ -446,11 +441,11 @@ public class AseAwk extends StdAwk return len; } - protected int openConsole (Extio extio) + protected int openConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { Reader rd; @@ -467,10 +462,7 @@ public class AseAwk extends StdAwk } catch (IOException e) { return -1; } - try - { - setConsoleInputName (extio, fn); - } + try { con.setFileName (fn); } catch (ase.awk.Exception e) { try { rd.close(); } @@ -479,10 +471,10 @@ public class AseAwk extends StdAwk } } - conReader = rd; + con.setHandle (rd); return 1; } - else if (mode == Extio.MODE_CONSOLE_WRITE) + else if (mode == Console.MODE_WRITE) { Writer wr; @@ -499,10 +491,7 @@ public class AseAwk extends StdAwk } catch (IOException e) { return -1; } - try - { - setConsoleOutputName (extio, fn); - } + try { con.setFileName (fn); } catch (ase.awk.Exception e) { try { wr.close(); } @@ -511,7 +500,7 @@ public class AseAwk extends StdAwk } } - conWriter = wr; + con.setHandle (wr); return 1; } @@ -519,53 +508,32 @@ public class AseAwk extends StdAwk } - protected int closeConsole (Extio extio) + protected int closeConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { - if (conReader != null) + Reader rd = (Reader)con.getHandle(); + if (rd != null && rd != stdin) { - if (conReader == stdin) - { - conReader = null; - } - else - { - try - { - conReader.close (); - conReader = null; - } - catch (IOException e) { return -1; } - } + try { rd.close (); } + catch (IOException e) { return -1; } } return 0; } - else if (mode == Extio.MODE_CONSOLE_WRITE) + else if (mode == Console.MODE_WRITE) { - if (conWriter != null) + Writer wr = (Writer)con.getHandle(); + if (wr != null) { - if (conWriter == stdout) - { - try - { - conWriter.flush (); - conWriter = null; - } - catch (IOException e) { return -1; } - } - else - { - try - { - conWriter.close (); - conWriter = null; - } - catch (IOException e) { return -1; } + try + { + wr.flush (); + if (wr != stdout) wr.close (); } + catch (IOException e) { return -1; } } return 0; @@ -574,15 +542,17 @@ public class AseAwk extends StdAwk return -1; } - protected int readConsole (Extio extio, char[] buf, int len) + protected int readConsole (Console con, char[] buf, int len) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { + Reader rd = (Reader)con.getHandle(); + try { - int n = conReader.read (buf, 0, len); + int n = rd.read (buf, 0, len); if (n == -1) n = 0; return n; } @@ -592,16 +562,17 @@ public class AseAwk extends StdAwk return -1; } - protected int writeConsole (Extio extio, char[] buf, int len) + protected int writeConsole (Console con, char[] buf, int len) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_WRITE) + if (mode == Console.MODE_WRITE) { + Writer wr = (Writer)con.getHandle(); try { - conWriter.write (buf, 0, len); - conWriter.flush (); + wr.write (buf, 0, len); + wr.flush (); } catch (IOException e) { return -1; } return len; @@ -610,13 +581,14 @@ public class AseAwk extends StdAwk return -1; } - protected int flushConsole (Extio extio) + protected int flushConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_WRITE) + if (mode == Console.MODE_WRITE) { - try { conWriter.flush (); } + Writer wr = (Writer)con.getHandle(); + try { wr.flush (); } catch (IOException e) { return -1; } return 0; } @@ -624,11 +596,11 @@ public class AseAwk extends StdAwk return -1; } - protected int nextConsole (Extio extio) + protected int nextConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { if (!conInIter.hasNext()) return 0; String fn = (String)conInIter.next(); @@ -643,10 +615,7 @@ public class AseAwk extends StdAwk } catch (IOException e) { return -1; } - try - { - setConsoleInputName (extio, fn); - } + try { con.setFileName (fn); } catch (ase.awk.Exception e) { try { rd.close(); } @@ -654,13 +623,22 @@ public class AseAwk extends StdAwk return -1; } - try { conReader.close (); } - catch (IOException e) { return -1; } + Reader tmp = (Reader)con.getHandle(); + if (tmp != stdin) + { + try { tmp.close (); } + catch (IOException e) + { + try { rd.close (); } + catch (IOException e2) {} + return -1; + } + } - conReader = rd; + con.setHandle (rd); return 1; } - else if (mode == Extio.MODE_CONSOLE_WRITE) + else if (mode == Console.MODE_WRITE) { if (!conOutIter.hasNext()) return 0; String fn = (String)conOutIter.next(); @@ -675,10 +653,7 @@ public class AseAwk extends StdAwk } catch (IOException e) { return -1; } - try - { - setConsoleOutputName (extio, fn); - } + try { con.setFileName (fn); } catch (ase.awk.Exception e) { try { wr.close(); } @@ -686,10 +661,19 @@ public class AseAwk extends StdAwk return -1; } - try { conWriter.close (); } - catch (IOException e) { return -1; } + Writer tmp = (Writer)con.getHandle(); + if (tmp != stdout) + { + try { tmp.close (); } + catch (IOException e) + { + try { wr.close (); } + catch (IOException e2) {} + return -1; + } + } - conWriter = wr; + con.setHandle (wr); return 1; } diff --git a/ase/test/awk/AseAwkPanel.java b/ase/test/awk/AseAwkPanel.java index d67d7e7f..d77ff3dc 100644 --- a/ase/test/awk/AseAwkPanel.java +++ b/ase/test/awk/AseAwkPanel.java @@ -1,5 +1,5 @@ /* - * $Id: AseAwkPanel.java,v 1.1 2007/04/30 08:32:41 bacon Exp $ + * $Id: AseAwkPanel.java,v 1.2 2007/05/26 10:23:52 bacon Exp $ */ import java.awt.*; @@ -10,9 +10,11 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.io.Reader; +import java.io.Writer; import ase.awk.StdAwk; -import ase.awk.Extio; +import ase.awk.Console; public class AseAwkPanel extends Panel { @@ -81,9 +83,6 @@ public class AseAwkPanel extends Panel private StringReader srcIn; private StringWriter srcOut; - private StringReader conIn; - private StringWriter conOut; - public Awk (AseAwkPanel awkPanel) throws Exception { super (); @@ -142,18 +141,18 @@ public class AseAwkPanel extends Panel return len; } - protected int openConsole (Extio extio) + protected int openConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { - conIn = new StringReader (awkPanel.getConsoleInput()); + con.setHandle (new StringReader (awkPanel.getConsoleInput())); return 1; } - else if (mode == Extio.MODE_CONSOLE_WRITE) + else if (mode == Console.MODE_WRITE) { - conOut = new StringWriter (); + con.setHandle (new StringWriter ()); return 1; } @@ -161,20 +160,22 @@ public class AseAwkPanel extends Panel } - protected int closeConsole (Extio extio) + protected int closeConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { - conIn.close (); + Reader rd = (Reader)con.getHandle(); + try { rd.close (); } + catch (IOException e) { return -1; } return 0; } - else if (mode == Extio.MODE_CONSOLE_WRITE) + else if (mode == Console.MODE_WRITE) { - awkPanel.setConsoleOutput (conOut.toString()); - - try { conOut.close (); } + Writer wr = (Writer)con.getHandle(); + awkPanel.setConsoleOutput (wr.toString()); + try { wr.close (); } catch (IOException e) { return -1; } return 0; } @@ -182,15 +183,17 @@ public class AseAwkPanel extends Panel return -1; } - protected int readConsole (Extio extio, char[] buf, int len) + protected int readConsole (Console con, char[] buf, int len) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { + Reader rd = (Reader)con.getHandle(); + try { - int n = conIn.read (buf, 0, len); + int n = rd.read (buf, 0, len); if (n == -1) n = 0; return n; } @@ -200,24 +203,26 @@ public class AseAwkPanel extends Panel return -1; } - protected int writeConsole (Extio extio, char[] buf, int len) + protected int writeConsole (Console con, char[] buf, int len) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_WRITE) + if (mode == Console.MODE_WRITE) { - conOut.write (buf, 0, len); + Writer wr = (Writer)con.getHandle(); + try { wr.write (buf, 0, len); } + catch (IOException e) { return -1; } return len; } return -1; } - protected int flushConsole (Extio extio) + protected int flushConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_WRITE) + if (mode == Console.MODE_WRITE) { return 0; } @@ -225,15 +230,17 @@ public class AseAwkPanel extends Panel return -1; } - protected int nextConsole (Extio extio) + protected int nextConsole (Console con) { - int mode = extio.getMode (); + int mode = con.getMode (); - if (mode == Extio.MODE_CONSOLE_READ) + if (mode == Console.MODE_READ) { + return 0; } - else if (mode == Extio.MODE_CONSOLE_WRITE) + else if (mode == Console.MODE_WRITE) { + return 0; } return -1; diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp index 38ff7d92..14630fd3 100644 --- a/ase/test/awk/Awk.cpp +++ b/ase/test/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.22 2007/05/25 14:41:48 bacon Exp $ + * $Id: Awk.cpp,v 1.23 2007/05/26 10:23:52 bacon Exp $ */ #include @@ -73,7 +73,7 @@ public: { #ifdef _WIN32 ::Sleep (args[0].toInt() * 1000); - return ret->set (0); + return ret->set ((long_t)0); #else return ret->set ((long_t)::sleep (args[0].toInt())); #endif diff --git a/ase/test/awk/x.awk b/ase/test/awk/x.awk index 3861eba6..d348324a 100644 --- a/ase/test/awk/x.awk +++ b/ase/test/awk/x.awk @@ -23,7 +23,7 @@ BEGIN { #print 1 | # 1; - print .0; + print 0.0; print 10; print fflush ("abc");