diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index ba65dfff..f808df28 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.9 2007/05/06 06:55:05 bacon Exp $ + * $Id: Awk.cpp,v 1.11 2007/05/06 10:38:22 bacon Exp $ */ #include @@ -81,7 +81,6 @@ namespace ASE Awk::~Awk () { - close (); } int Awk::parse () @@ -105,10 +104,8 @@ namespace ASE runios.pipe = pipeHandler; runios.coproc = ASE_NULL; - /* runios.file = fileHandler; runios.console = consoleHandler; - */ runios.custom_data = this; return ase_awk_run ( diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index cc1b8364..f9caa9f9 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.8 2007/05/06 06:55:05 bacon Exp $ + * $Id: Awk.hpp,v 1.10 2007/05/06 10:38:22 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -9,6 +9,16 @@ #include #include +#ifdef malloc +#undef malloc +#endif +#ifdef realloc +#undef realloc +#endif +#ifdef free +#undef free +#endif + namespace ASE { @@ -108,7 +118,6 @@ namespace ASE Mode mode; }; - Awk (); virtual ~Awk (); @@ -231,7 +240,7 @@ namespace ASE const char_t* fmt, ...); static void dprintf (void* custom, const char_t* fmt, ...); - private: + protected: ase_awk_t* awk; ase_awk_map_t* functionMap; diff --git a/ase/awk/StdAwk.cpp b/ase/awk/StdAwk.cpp index 4a2a72d3..94f5f04f 100644 --- a/ase/awk/StdAwk.cpp +++ b/ase/awk/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp,v 1.3 2007/05/06 06:55:05 bacon Exp $ + * $Id: StdAwk.cpp,v 1.4 2007/05/06 10:38:22 bacon Exp $ */ #include @@ -16,11 +16,23 @@ namespace ASE int n = Awk::open (); if (n == 0) { - /* + int opt = ASE_AWK_IMPLICIT | + ASE_AWK_EXPLICIT | + ASE_AWK_UNIQUEFN | + ASE_AWK_IDIV | + ASE_AWK_SHADING | + ASE_AWK_SHIFT | + ASE_AWK_EXTIO | + ASE_AWK_BLOCKLESS | + ASE_AWK_STRBASEONE | + ASE_AWK_STRIPSPACES | + ASE_AWK_NEXTOFILE /*| + ASE_AWK_ARGSTOMAIN*/; + ase_awk_setoption (awk, opt); + addFunction (ASE_T("sin"), 1, 1, (FunctionHandler)&StdAwk::sin); addFunction (ASE_T("cos"), 1, 1, (FunctionHandler)&StdAwk::cos); addFunction (ASE_T("tan"), 1, 1, (FunctionHandler)&StdAwk::tan); - */ } return n; diff --git a/ase/awk/awk.c b/ase/awk/awk.c index f513ddd9..70651990 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.4 2007/05/05 16:32:46 bacon Exp $ + * $Id: awk.c,v 1.5 2007/05/06 10:38:22 bacon Exp $ * * {License} */ @@ -40,12 +40,9 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data) prmfns->misc.sprintf != ASE_NULL && prmfns->misc.dprintf != ASE_NULL); -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - awk = (ase_awk_t*) malloc (ASE_SIZEOF(ase_awk_t)); -#else - awk = (ase_awk_t*) prmfns->mmgr.malloc ( - prmfns->mmgr.custom_data, ASE_SIZEOF(ase_awk_t)); -#endif + /* use ASE_MALLOC instead of ASE_AWK_MALLOC because + * the awk object has not been initialized yet */ + awk = ASE_MALLOC (&prmfns->mmgr, ASE_SIZEOF(ase_awk_t)); if (awk == ASE_NULL) return ASE_NULL; /* it uses the built-in ase_awk_memset because awk is not diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index ffeb8207..565ceadf 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.4 2007/05/05 16:32:46 bacon Exp $ + * $Id: awk_i.h,v 1.5 2007/05/06 10:08:54 bacon Exp $ * * {License} */ @@ -34,18 +34,9 @@ typedef struct ase_awk_tree_t ase_awk_tree_t; #define ASE_AWK_MAX_LOCALS 9999 #define ASE_AWK_MAX_PARAMS 9999 -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - #define _CRTDBG_MAP_ALLOC - #include - - #define ASE_AWK_MALLOC(awk,size) malloc (size) - #define ASE_AWK_REALLOC(awk,ptr,size) realloc (ptr, size) - #define ASE_AWK_FREE(awk,ptr) free (ptr) -#else - #define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size) - #define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size) - #define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr) -#endif +#define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size) +#define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size) +#define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr) #define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c) diff --git a/ase/awk/map.c b/ase/awk/map.c index 8d71234d..22095a81 100644 --- a/ase/awk/map.c +++ b/ase/awk/map.c @@ -1,5 +1,5 @@ /* - * $Id: map.c,v 1.5 2007/05/06 06:55:05 bacon Exp $ + * $Id: map.c,v 1.6 2007/05/06 08:52:18 bacon Exp $ * * {License} */ @@ -36,7 +36,7 @@ ase_awk_map_t* ase_awk_map_open ( ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_pair_t*) * capa); if (map->buck == ASE_NULL) { - if (map->__dynamic) ASE_AWK_FREE (awk, map); + ASE_AWK_FREE (awk, map); return ASE_NULL; } diff --git a/ase/awk/map.h b/ase/awk/map.h index 029b7531..7a79f675 100644 --- a/ase/awk/map.h +++ b/ase/awk/map.h @@ -1,5 +1,5 @@ /* - * $Id: map.h,v 1.5 2007/05/06 06:55:05 bacon Exp $ + * $Id: map.h,v 1.6 2007/05/06 08:52:18 bacon Exp $ * * {License} */ @@ -34,7 +34,6 @@ struct ase_awk_map_t ase_awk_pair_t** buck; void (*freeval) (void*,void*); ase_awk_t* awk; - ase_bool_t __dynamic; }; #define ASE_AWK_PAIR_KEYPTR(p) ((p)->key.ptr) diff --git a/ase/cmn/macros.h b/ase/cmn/macros.h index 113e7efc..c97b4044 100644 --- a/ase/cmn/macros.h +++ b/ase/cmn/macros.h @@ -1,5 +1,5 @@ /* - * $Id: macros.h,v 1.3 2007/04/30 05:55:36 bacon Exp $ + * $Id: macros.h,v 1.5 2007/05/06 10:08:36 bacon Exp $ * * {License} */ @@ -118,9 +118,23 @@ (ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0)) #endif -#define ASE_MALLOC(mmgr,size) (mmgr)->malloc((mmgr)->custom_data, size) -#define ASE_REALLOC(mmgr,ptr,size) (mmgr)->realloc((mmgr)->custom_data, ptr, size) -#define ASE_FREE(mmgr,ptr) (mmgr)->free((mmgr)->custom_data, ptr) +#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) + #include + #define _CRTDBG_MAP_ALLOC + #include + + #define ASE_MALLOC(mmgr,size) malloc (size) + #define ASE_REALLOC(mmgr,ptr,size) realloc (ptr, size) + #define ASE_FREE(mmgr,ptr) free (ptr) +#else + + #define ASE_MALLOC(mmgr,size) \ + (mmgr)->malloc((mmgr)->custom_data, size) + #define ASE_REALLOC(mmgr,ptr,size) \ + (mmgr)->realloc((mmgr)->custom_data, ptr, size) + #define ASE_FREE(mmgr,ptr) \ + (mmgr)->free((mmgr)->custom_data, ptr) +#endif #define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->custom_data,c) #define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->custom_data,c) diff --git a/ase/cmn/types.h b/ase/cmn/types.h index 34ae0960..e2100358 100644 --- a/ase/cmn/types.h +++ b/ase/cmn/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h,v 1.4 2007/05/05 10:43:08 bacon Exp $ + * $Id: types.h,v 1.6 2007/05/06 08:08:22 bacon Exp $ * * {License} */ @@ -163,7 +163,7 @@ typedef ase_uint_t ase_word_t; typedef char ase_mchar_t; typedef int ase_mcint_t; -#if defined(__cplusplus) && (__cplusplus>1) +#if defined(__cplusplus) && !(defined(_MSC_VER)&&(_MSC_VER<=1200)) /* C++ */ typedef wchar_t ase_wchar_t; typedef wchar_t ase_wcint_t; diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp index da640d2a..8f0004a9 100644 --- a/ase/test/awk/Awk.cpp +++ b/ase/test/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.2 2007/05/06 06:55:05 bacon Exp $ + * $Id: Awk.cpp,v 1.5 2007/05/06 10:38:22 bacon Exp $ */ #include @@ -11,11 +11,19 @@ #include #include + +#if defined(_WIN32) #include +#endif class TestAwk: public ASE::StdAwk { public: + ~TestAwk () + { + close (); + } + int parse (const char_t* name) { ase_strxcpy (sourceInName, ASE_COUNTOF(sourceInName), name); @@ -32,6 +40,7 @@ protected: FILE* fp = ase_fopen (sourceInName, ASE_T("r")); if (fp == ASE_NULL) return -1; io.setHandle (fp); + return 1; } else if (mode == Source::WRITE) { @@ -61,7 +70,13 @@ protected: ssize_t readSource (Source& io, char_t* buf, size_t count) { - return 0; + if (count <= 0) return -1; + + // TOOD: read more characters... + cint_t c = ase_fgetc ((FILE*)io.getHandle()); + if (c == ASE_CHAR_EOF) return 0; + buf[0] = (ase_char_t)c; + return 1; } ssize_t writeSource (Source& io, char_t* buf, size_t count) @@ -95,7 +110,7 @@ protected: } ssize_t writeConsole (Console& io, char_t* buf, size_t len) { - return ase_printf (ASE_T(".%s"), len, buf); + return ase_printf (ASE_T("%.*s"), len, buf); } int flushConsole (Console& io) { return 0; } int nextConsole (Console& io) { return 0; } @@ -171,7 +186,7 @@ void ase_assert_printf (const ase_char_t* fmt, ...) } #endif -int ase_main (int argc, ase_char_t* argv[]) +extern "C" int ase_main (int argc, ase_char_t* argv[]) { TestAwk awk; @@ -182,7 +197,6 @@ int ase_main (int argc, ase_char_t* argv[]) return -1; } -return -1; if (awk.parse(ASE_T("t.awk")) == -1) { ase_fprintf (stderr, ASE_T("cannot parse\n")); @@ -197,6 +211,6 @@ return -1; return -1; } - awk.close (); +// awk.close (); return 0; } diff --git a/ase/test/awk/makefile.in b/ase/test/awk/makefile.in index e1f0b3e3..c6f387fd 100644 --- a/ase/test/awk/makefile.in +++ b/ase/test/awk/makefile.in @@ -1,11 +1,13 @@ # -# $Id: makefile.in,v 1.3 2007/04/30 08:32:41 bacon Exp $ +# $Id: makefile.in,v 1.5 2007/05/06 08:10:31 bacon Exp $ # CC = @CC@ +CXX = @CXX@ CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/@BUILDMODE@/lib LIBS = @LIBS@ -laseawk -lasecmn -laseutl -lm +LIBS_CXX = -laseawk++ ${LIBS} MODE = @BUILDMODE@ JAVAC = @JAVAC@ @@ -21,7 +23,7 @@ ASEAWK_LIB = all: build$(JNI) -build: $(TMP_DIR) $(OUT_DIR) $(OUT_DIR)/aseawk $(OUT_DIR)/aseawk_mini +build: $(TMP_DIR) $(OUT_DIR) $(OUT_DIR)/aseawk $(OUT_DIR)/aseawk_mini $(OUT_DIR)/aseawk++ buildjni: build $(OUT_DIR)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html @@ -31,6 +33,9 @@ $(OUT_DIR)/aseawk: awk.c $(OUT_DIR)/aseawk_mini: mini.c $(CC) $(CFLAGS) -o $@ mini.c $(LDFLAGS) $(LIBS) +$(OUT_DIR)/aseawk++: Awk.cpp + $(CXX) $(CFLAGS) -o $@ Awk.cpp $(LDFLAGS) $(LIBS_CXX) + $(OUT_DIR)/aseawk.jar: $(TMP_DIR)/AseAwkPanel.class $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkApplet.class cd $(TMP_DIR); $(JAR) -xvf ../$(LIB_DIR)/aseawk.jar cd $(TMP_DIR); $(JAR) -cvfm ../$@ ../manifest *.class ase @@ -55,5 +60,5 @@ $(TMP_DIR): mkdir -p $(TMP_DIR) clean: - rm -rf $(OUT_DIR)/aseawk $(OUT_DIR)/aseawk_mini $(OUT_DIR)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html $(TMP_DIR)/*.class + rm -rf $(OUT_DIR)/aseawk $(OUT_DIR)/aseawk_mini $(OUT_DIR)/aseawk++ $(OUT_DIR)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html $(TMP_DIR)/*.class diff --git a/ase/test/cnt/asetestcnt.csproj b/ase/test/cnt/asetestcnt.csproj index f36f9922..67842324 100644 --- a/ase/test/cnt/asetestcnt.csproj +++ b/ase/test/cnt/asetestcnt.csproj @@ -30,7 +30,7 @@ False - obj\Release\Interop.ASECOM.dll + ..\..\cnt\obj\Debug\Interop.ASECOM.dll diff --git a/ase/utl/main.h b/ase/utl/main.h index bedd41bc..b9d83c2f 100644 --- a/ase/utl/main.h +++ b/ase/utl/main.h @@ -1,5 +1,5 @@ /* - * $Id: main.h,v 1.3 2007/04/30 08:32:50 bacon Exp $ + * $Id: main.h,v 1.4 2007/05/06 08:05:36 bacon Exp $ */ #ifndef _ASE_UTL_MAIN_H_ @@ -16,7 +16,7 @@ #else #ifdef __cplusplus - extern "C" { int ase_main (...); } + /*extern "C" { int ase_main (...); }*/ #else extern int ase_main (); #endif