From 6f28e48ff984ad8d8a22bdae78bbe901a95f0e4b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 4 May 2007 00:14:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-05-03 15:14:00 --- ase/awk/Awk.cpp | 73 ++++++++++++++++++++++++++++++++++++++------ ase/awk/Awk.hpp | 27 ++++++++++++++-- ase/awk/makefile.in | 10 +++--- ase/test/awk/Awk.cpp | 34 +++++++++++++++++++++ 4 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 ase/test/awk/Awk.cpp diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index 979b1347..62c0e52a 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,23 +1,18 @@ /* - * $Id: Awk.cpp,v 1.2 2007/05/01 12:39:22 bacon Exp $ + * $Id: Awk.cpp,v 1.4 2007/05/02 15:07:33 bacon Exp $ */ #include namespace ASE { - Awk::Awk (): awk (ASE_NULL) { } Awk::~Awk () { - if (awk != ASE_NULL) - { - ase_awk_close (awk); - awk = ASE_NULL; - } + close (); } int Awk::parse () @@ -27,18 +22,76 @@ namespace ASE /*awk = ase_awk_open (*/ } + ase_awk_srcios_t srcios; + + srcios.in = sourceReader; + srcios.out = sourceWriter; + srcios.custom_data = this; + return ase_awk_parse (awk, ASE_NULL); } - int Awk::run (/*const ase_char_t* main*/) + int Awk::run (const ase_char_t* main, const ase_char_t** args) { - if (awk == ASE_NULL) + if (awk == ASE_NULL) { + // TODO: SET ERROR INFO + return -1; } //return ase_awk_run (awk, main); return 0; } -} + void Awk::close () + { + if (awk != ASE_NULL) + { + ase_awk_close (awk); + awk = ASE_NULL; + } + } + ase_ssize_t Awk::sourceReader ( + int cmd, void* arg, ase_char_t* data, ase_size_t count) + { + ASE::Awk* awk = (ASE::Awk*)arg; + + if (cmd == ASE_AWK_IO_OPEN) + { + return awk->openSource (ASE::Awk::SOURCE_READ); + } + else if (cmd == ASE_AWK_IO_CLOSE) + { + return awk->closeSource (ASE::Awk::SOURCE_READ); + } + else if (cmd == ASE_AWK_IO_READ) + { + return awk->readSource (data, count); + } + + return -1; + } + + ase_ssize_t Awk::sourceWriter ( + int cmd, void* arg, ase_char_t* data, ase_size_t count) + { + ASE::Awk* awk = (ASE::Awk*)arg; + + if (cmd == ASE_AWK_IO_OPEN) + { + return awk->openSource (ASE::Awk::SOURCE_WRITE); + } + else if (cmd == ASE_AWK_IO_CLOSE) + { + return awk->closeSource (ASE::Awk::SOURCE_WRITE); + } + else if (cmd == ASE_AWK_IO_WRITE) + { + return awk->writeSource (data, count); + } + + return -1; + } + +} diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index ee2ddd70..21ff8089 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.1 2007/04/30 05:47:33 bacon Exp $ + * $Id: Awk.hpp,v 1.3 2007/05/02 15:07:33 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -14,10 +14,31 @@ namespace ASE { public: Awk (); - ~Awk (); + virtual ~Awk (); int parse (); - int run (); + int run (const ase_char_t* main, const ase_char_t** args); + void close (); + + enum SourceMode + { + SOURCE_READ, + SOURCE_WRITE + }; + + protected: + virtual int openSource (SourceMode mode) = 0; + virtual int closeSource (SourceMode mode) = 0; + + virtual ase_ssize_t readSource ( + ase_char_t* buf, ase_size_t len) = 0; + virtual ase_ssize_t writeSource ( + ase_char_t* buf, ase_size_t len) = 0; + + static ase_ssize_t sourceReader ( + int cmd, void* arg, ase_char_t* data, ase_size_t count); + static ase_ssize_t sourceWriter ( + int cmd, void* arg, ase_char_t* data, ase_size_t count); private: ase_awk_t* awk; diff --git a/ase/awk/makefile.in b/ase/awk/makefile.in index b06408f7..9c8bd07f 100644 --- a/ase/awk/makefile.in +++ b/ase/awk/makefile.in @@ -1,5 +1,5 @@ # -# $Id: makefile.in,v 1.3 2007/04/30 05:47:33 bacon Exp $ +# $Id: makefile.in,v 1.4 2007/05/02 15:07:33 bacon Exp $ # NAME = aseawk @@ -51,9 +51,7 @@ OBJ_FILES_LIB = \ OBJ_FILES_JNI = $(TMP_DIR)/jni.o -OBJ_FILES_LIB_CXX = \ - $(OBJ_FILES_LIB) \ - $(TMP_DIR)/cxx/Awk.o +OBJ_FILES_LIB_CXX = $(TMP_DIR)/cxx/Awk.o OBJ_FILES_SO = $(OBJ_FILES_LIB:.o=.lo) $(OBJ_FILES_JNI:.o=.lo) @@ -77,7 +75,7 @@ $(OUT_FILE_JNI): $(TMP_DIR) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OUT_FILE_LIB) $(LIBTOOL_LINK) $(CC) -rpath $(TOP_INSTALLDIR)/lib -version-info 1:0:0 -o $(OUT_FILE_JNI) $(OBJ_FILES_SO) -lm -L$(OUT_DIR) -l$(NAME) -lasecmn -laseutl $(JAR) -Mcvf $(OUT_FILE_JAR) -C $(TMP_DIR) ase -$(OUT_FILE_LIB_CXX): $(TMP_DIR_CXX) $(OUT_DIR) $(OBJ_FILES_LIB_CXX) +$(OUT_FILE_LIB_CXX): $(TMP_DIR_CXX) $(OUT_DIR) $(OUT_FILE_LIB) $(OBJ_FILES_LIB_CXX) $(AR) cr $(OUT_FILE_LIB_CXX) $(OBJ_FILES_LIB_CXX) if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE_LIB_CXX); fi @@ -135,7 +133,7 @@ $(TMP_DIR)/ase/awk/Extio.class: $(TMP_DIR)/ase/awk/Exception.class: $(JAVAC) -classpath ../.. -d $(TMP_DIR) Exception.java -$(TMP_DIR)/cxx/Awk.o: +$(TMP_DIR)/cxx/Awk.o: Awk.cpp Awk.hpp $(CXX) $(CXXFLAGS) -o $@ -c Awk.cpp $(OUT_DIR): diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp new file mode 100644 index 00000000..12a57c14 --- /dev/null +++ b/ase/test/awk/Awk.cpp @@ -0,0 +1,34 @@ +/* + * $Id: Awk.cpp,v 1.1 2007/05/02 15:07:33 bacon Exp $ + */ + +#include + +class TestAwk: public ASE::Awk +{ + int openSource (SourceMode mode) + { + return 1; + } + + int closeSource (SourceMode mode) + { + return 0; + } + + ase_ssize_t readSource (ase_char_t* buf, ase_size_t count) + { + return 0; + } + + ase_ssize_t writeSource (ase_char_t* buf, ase_size_t count); + { + return 0; + } +}; + +int main () +{ + + +}