Recovered from cvs revision 2007-05-06 16:04:00

This commit is contained in:
hyung-hwan 2007-05-07 01:05:00 +00:00
parent 0f3ea15c69
commit 4821ee87ce
9 changed files with 302 additions and 51 deletions

View File

@ -87,6 +87,18 @@ Package=<4>
############################################################################### ###############################################################################
Project: "asetestawk++"=.\test\awk\asetestawk++.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "aselsp"=.\lsp\aselsp.dsp - Package Owner=<4> Project: "aselsp"=.\lsp\aselsp.dsp - Package Owner=<4>
Package=<5> Package=<5>

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.8 2007/05/05 16:32:46 bacon Exp $ * $Id: Awk.cpp,v 1.9 2007/05/06 06:55:05 bacon Exp $
*/ */
#include <ase/awk/Awk.hpp> #include <ase/awk/Awk.hpp>
@ -9,6 +9,10 @@
namespace ASE namespace ASE
{ {
Awk::Source::Source (Mode mode): mode (mode)
{
}
Awk::Source::Mode Awk::Source::getMode () const Awk::Source::Mode Awk::Source::getMode () const
{ {
return this->mode; return this->mode;
@ -70,7 +74,7 @@ namespace ASE
return this->mode; return this->mode;
} }
Awk::Awk (): awk (ASE_NULL), Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL),
sourceIn (Source::READ), sourceOut (Source::WRITE) sourceIn (Source::READ), sourceOut (Source::WRITE)
{ {
} }
@ -82,7 +86,7 @@ namespace ASE
int Awk::parse () int Awk::parse ()
{ {
if (awk == ASE_NULL && open() == -1) return -1; ASE_ASSERT (awk != ASE_NULL);
ase_awk_srcios_t srcios; ase_awk_srcios_t srcios;
@ -95,11 +99,7 @@ namespace ASE
int Awk::run (const char_t* main, const char_t** args) int Awk::run (const char_t* main, const char_t** args)
{ {
if (awk == ASE_NULL) ASE_ASSERT (awk != ASE_NULL);
{
// TODO: SET ERROR INFO
return -1;
}
ase_awk_runios_t runios; ase_awk_runios_t runios;
@ -117,6 +117,8 @@ namespace ASE
int Awk::open () int Awk::open ()
{ {
ASE_ASSERT (awk == ASE_NULL && functionMap == ASE_NULL);
ase_awk_prmfns_t prmfns; ase_awk_prmfns_t prmfns;
prmfns.mmgr.malloc = malloc; prmfns.mmgr.malloc = malloc;
@ -156,7 +158,8 @@ namespace ASE
return -1; return -1;
} }
functionMap = ase_awk_map_open (this, 512, ASE_NULL, awk); functionMap = ase_awk_map_open (
this, 512, freeFunctionMapValue, awk);
if (functionMap == ASE_NULL) if (functionMap == ASE_NULL)
{ {
// TODO: set ERROR INFO -> ENOMEM... // TODO: set ERROR INFO -> ENOMEM...
@ -190,26 +193,63 @@ namespace ASE
pair = ase_awk_map_get (functionMap, name, len); pair = ase_awk_map_get (functionMap, name, len);
if (pair == ASE_NULL) return -1; if (pair == ASE_NULL) return -1;
//ASE_AWK_PAIR_VAL(pair); FunctionHandler handler;
return 0; handler = *(FunctionHandler*)ASE_AWK_PAIR_VAL(pair);
return (this->*handler) ();
} }
int Awk::addFunction ( int Awk::addFunction (
const char_t* name, size_t minArgs, size_t maxArgs, const char_t* name, size_t minArgs, size_t maxArgs,
FunctionHandler handler) FunctionHandler handler)
{ {
void* p = ase_awk_addbfn (awk, name, ase_strlen(name), ASE_ASSERT (awk != ASE_NULL);
FunctionHandler* tmp;
tmp = (FunctionHandler*)this->malloc (ASE_SIZEOF(handler));
if (tmp == ASE_NULL)
{
// TODO: SET ERROR INFO -> ENOMEM
return -1;
}
//ase_memcpy (tmp, &handler, ASE_SIZEOF(handler));
*tmp = handler;
size_t nameLen = ase_strlen(name);
void* p = ase_awk_addbfn (awk, name, nameLen,
0, minArgs, maxArgs, ASE_NULL, 0, minArgs, maxArgs, ASE_NULL,
functionHandler); functionHandler);
if (p == ASE_NULL)
{
this->free (tmp);
return -1;
}
//ase_memcpy (ASE_NULL, &handler, sizeof(handler)); ase_awk_pair_t* pair;
return (p == ASE_NULL)? -1: 0; pair = ase_awk_map_put (functionMap, name, nameLen, tmp);
if (pair == ASE_NULL)
{
// TODO: SET ERROR INFO
ase_awk_delbfn (awk, name, nameLen);
this->free (tmp);
return -1;
}
return 0;
} }
int Awk::deleteFunction (const char_t* name) int Awk::deleteFunction (const char_t* name)
{ {
// TODO: open if it is not open.... ASE_ASSERT (awk != ASE_NULL);
return ase_awk_delbfn (awk, name, ase_strlen(name));
size_t nameLen = ase_strlen(name);
int n = ase_awk_delbfn (awk, name, nameLen);
if (n == 0) ase_awk_map_remove (functionMap, name, nameLen);
return n;
} }
Awk::ssize_t Awk::sourceReader ( Awk::ssize_t Awk::sourceReader (
@ -348,6 +388,12 @@ namespace ASE
return awk->dispatchFunction (name, len); return awk->dispatchFunction (name, len);
} }
void Awk::freeFunctionMapValue (void* owner, void* value)
{
Awk* awk = (Awk*)owner;
awk->free (value);
}
void* Awk::malloc (void* custom, size_t n) void* Awk::malloc (void* custom, size_t n)
{ {
return ((Awk*)custom)->malloc (n); return ((Awk*)custom)->malloc (n);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.hpp,v 1.7 2007/05/05 16:32:46 bacon Exp $ * $Id: Awk.hpp,v 1.8 2007/05/06 06:55:05 bacon Exp $
*/ */
#ifndef _ASE_AWK_AWK_HPP_ #ifndef _ASE_AWK_AWK_HPP_
@ -112,20 +112,21 @@ namespace ASE
Awk (); Awk ();
virtual ~Awk (); virtual ~Awk ();
int parse (); virtual int open ();
int run (const char_t* main, const char_t** args); virtual void close ();
void close ();
virtual int parse ();
virtual int run (const char_t* main = ASE_NULL,
const char_t** args = ASE_NULL);
typedef int (Awk::*FunctionHandler) (); typedef int (Awk::*FunctionHandler) ();
int addFunction ( virtual int addFunction (
const char_t* name, size_t minArgs, size_t maxArgs, const char_t* name, size_t minArgs, size_t maxArgs,
FunctionHandler handler); FunctionHandler handler);
int deleteFunction (const char_t* main); virtual int deleteFunction (const char_t* main);
protected: protected:
int open ();
virtual int dispatchFunction (const char_t* name, size_t len); virtual int dispatchFunction (const char_t* name, size_t len);
@ -205,6 +206,7 @@ namespace ASE
static int functionHandler ( static int functionHandler (
ase_awk_run_t* run, const char_t* name, size_t len); ase_awk_run_t* run, const char_t* name, size_t len);
static void freeFunctionMapValue (void* owner, void* value);
static void* malloc (void* custom, size_t n); static void* malloc (void* custom, size_t n);
static void* realloc (void* custom, void* ptr, size_t n); static void* realloc (void* custom, void* ptr, size_t n);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.cpp,v 1.2 2007/05/05 16:32:46 bacon Exp $ * $Id: StdAwk.cpp,v 1.3 2007/05/06 06:55:05 bacon Exp $
*/ */
#include <ase/awk/StdAwk.hpp> #include <ase/awk/StdAwk.hpp>
@ -9,9 +9,21 @@ namespace ASE
StdAwk::StdAwk () StdAwk::StdAwk ()
{ {
}
int StdAwk::open ()
{
int n = Awk::open ();
if (n == 0)
{
/*
addFunction (ASE_T("sin"), 1, 1, (FunctionHandler)&StdAwk::sin); addFunction (ASE_T("sin"), 1, 1, (FunctionHandler)&StdAwk::sin);
addFunction (ASE_T("cos"), 1, 1, (FunctionHandler)&StdAwk::cos); addFunction (ASE_T("cos"), 1, 1, (FunctionHandler)&StdAwk::cos);
addFunction (ASE_T("tan"), 1, 1, (FunctionHandler)&StdAwk::tan); addFunction (ASE_T("tan"), 1, 1, (FunctionHandler)&StdAwk::tan);
*/
}
return n;
} }
int StdAwk::sin () int StdAwk::sin ()

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.hpp,v 1.2 2007/05/05 16:32:46 bacon Exp $ * $Id: StdAwk.hpp,v 1.3 2007/05/06 06:55:05 bacon Exp $
*/ */
#ifndef _ASE_AWK_STDAWK_HPP_ #ifndef _ASE_AWK_STDAWK_HPP_
@ -15,6 +15,8 @@ namespace ASE
public: public:
StdAwk (); StdAwk ();
int open ();
protected: protected:
int sin (); int sin ();
int cos (); int cos ();

View File

@ -1,5 +1,5 @@
# #
# $Id: makefile.in,v 1.4 2007/05/02 15:07:33 bacon Exp $ # $Id: makefile.in,v 1.5 2007/05/06 04:23:44 bacon Exp $
# #
NAME = aseawk NAME = aseawk
@ -51,7 +51,9 @@ OBJ_FILES_LIB = \
OBJ_FILES_JNI = $(TMP_DIR)/jni.o OBJ_FILES_JNI = $(TMP_DIR)/jni.o
OBJ_FILES_LIB_CXX = $(TMP_DIR)/cxx/Awk.o OBJ_FILES_LIB_CXX = \
$(TMP_DIR)/cxx/Awk.o \
$(TMP_DIR)/cxx/StdAwk.o
OBJ_FILES_SO = $(OBJ_FILES_LIB:.o=.lo) $(OBJ_FILES_JNI:.o=.lo) OBJ_FILES_SO = $(OBJ_FILES_LIB:.o=.lo) $(OBJ_FILES_JNI:.o=.lo)
@ -136,6 +138,9 @@ $(TMP_DIR)/ase/awk/Exception.class:
$(TMP_DIR)/cxx/Awk.o: Awk.cpp Awk.hpp $(TMP_DIR)/cxx/Awk.o: Awk.cpp Awk.hpp
$(CXX) $(CXXFLAGS) -o $@ -c Awk.cpp $(CXX) $(CXXFLAGS) -o $@ -c Awk.cpp
$(TMP_DIR)/cxx/StdAwk.o: StdAwk.cpp StdAwk.hpp Awk.hpp
$(CXX) $(CXXFLAGS) -o $@ -c StdAwk.cpp
$(OUT_DIR): $(OUT_DIR):
mkdir -p $(OUT_DIR) mkdir -p $(OUT_DIR)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: map.c,v 1.4 2007/05/05 16:32:46 bacon Exp $ * $Id: map.c,v 1.5 2007/05/06 06:55:05 bacon Exp $
* *
* {License} * {License}
*/ */
@ -105,7 +105,8 @@ ase_awk_pair_t* ase_awk_map_get (
} }
ase_awk_pair_t* ase_awk_map_put ( ase_awk_pair_t* ase_awk_map_put (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val) ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void* val)
{ {
int n; int n;
ase_awk_pair_t* px; ase_awk_pair_t* px;
@ -116,7 +117,7 @@ ase_awk_pair_t* ase_awk_map_put (
} }
int ase_awk_map_putx ( int ase_awk_map_putx (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void* val, ase_awk_pair_t** px) void* val, ase_awk_pair_t** px)
{ {
ase_awk_pair_t* pair; ase_awk_pair_t* pair;
@ -165,7 +166,8 @@ int ase_awk_map_putx (
} }
ase_awk_pair_t* ase_awk_map_set ( ase_awk_pair_t* ase_awk_map_set (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val) ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void* val)
{ {
ase_awk_pair_t* pair; ase_awk_pair_t* pair;
ase_size_t hc; ase_size_t hc;
@ -217,7 +219,7 @@ ase_awk_pair_t* ase_awk_map_setpair (
} }
int ase_awk_map_remove ( int ase_awk_map_remove (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen) ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
{ {
ase_awk_pair_t* pair, * prev; ase_awk_pair_t* pair, * prev;
ase_size_t hc; ase_size_t hc;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: map.h,v 1.4 2007/05/05 16:32:46 bacon Exp $ * $Id: map.h,v 1.5 2007/05/06 06:55:05 bacon Exp $
* *
* {License} * {License}
*/ */
@ -60,14 +60,16 @@ ase_awk_pair_t* ase_awk_map_get (
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen); ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
ase_awk_pair_t* ase_awk_map_put ( ase_awk_pair_t* ase_awk_map_put (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val); ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void* val);
int ase_awk_map_putx ( int ase_awk_map_putx (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void* val, ase_awk_pair_t** px); void* val, ase_awk_pair_t** px);
ase_awk_pair_t* ase_awk_map_set ( ase_awk_pair_t* ase_awk_map_set (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val); ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void* val);
ase_awk_pair_t* ase_awk_map_getpair ( ase_awk_pair_t* ase_awk_map_getpair (
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen, ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
@ -77,7 +79,7 @@ ase_awk_pair_t* ase_awk_map_setpair (
ase_awk_map_t* map, ase_awk_pair_t* pair, void* val); ase_awk_map_t* map, ase_awk_pair_t* pair, void* val);
int ase_awk_map_remove ( int ase_awk_map_remove (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen); ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
int ase_awk_map_walk (ase_awk_map_t* map, int ase_awk_map_walk (ase_awk_map_t* map,
int (*walker)(ase_awk_pair_t*,void*), void* arg); int (*walker)(ase_awk_pair_t*,void*), void* arg);

View File

@ -1,34 +1,202 @@
/* /*
* $Id: Awk.cpp,v 1.1 2007/05/02 15:07:33 bacon Exp $ * $Id: Awk.cpp,v 1.2 2007/05/06 06:55:05 bacon Exp $
*/ */
#include <ase/awk/Awk.h> #include <ase/awk/StdAwk.hpp>
#include <ase/cmn/str.h>
class TestAwk: public ASE::Awk #include <ase/utl/ctype.h>
#include <ase/utl/stdio.h>
#include <ase/utl/main.h>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
class TestAwk: public ASE::StdAwk
{ {
int openSource (SourceMode mode) public:
int parse (const char_t* name)
{ {
return 1; ase_strxcpy (sourceInName, ASE_COUNTOF(sourceInName), name);
return StdAwk::parse ();
} }
int closeSource (SourceMode mode) protected:
int openSource (Source& io)
{
Source::Mode mode = io.getMode();
if (mode == Source::READ)
{
FILE* fp = ase_fopen (sourceInName, ASE_T("r"));
if (fp == ASE_NULL) return -1;
io.setHandle (fp);
}
else if (mode == Source::WRITE)
{ {
return 0; return 0;
} }
ase_ssize_t readSource (ase_char_t* buf, ase_size_t count) return -1;
}
int closeSource (Source& io)
{
Source::Mode mode = io.getMode();
if (mode == Source::READ)
{
fclose ((FILE*)io.getHandle());
io.setHandle (ASE_NULL);
return 0;
}
else if (mode == Source::WRITE)
{ {
return 0; return 0;
} }
ase_ssize_t writeSource (ase_char_t* buf, ase_size_t count); return -1;
}
ssize_t readSource (Source& io, char_t* buf, size_t count)
{ {
return 0; return 0;
} }
ssize_t writeSource (Source& io, char_t* buf, size_t count)
{
return 0;
}
// pipe io handlers
int openPipe (Pipe& io) { return -1; }
int closePipe (Pipe& io) { return 0; }
ssize_t readPipe (Pipe& io, char_t* buf, size_t len) { return 0; }
ssize_t writePipe (Pipe& io, char_t* buf, size_t len) { return 0; }
int flushPipe (Pipe& io) { return 0; }
int nextPipe (Pipe& io) { return 0; }
// file io handlers
int openFile (File& io) { return -1; }
int closeFile (File& io) { return 0; }
ssize_t readFile (File& io, char_t* buf, size_t len) { return 0; }
ssize_t writeFile (File& io, char_t* buf, size_t len) { return 0; }
int flushFile (File& io) { return 0; }
int nextFile (File& io) { return 0; }
// console io handlers
int openConsole (Console& io) { return 1; }
int closeConsole (Console& io) { return 0; }
ssize_t readConsole (Console& io, char_t* buf, size_t len)
{
return 0;
}
ssize_t writeConsole (Console& io, char_t* buf, size_t len)
{
return ase_printf (ASE_T(".%s"), len, buf);
}
int flushConsole (Console& io) { return 0; }
int nextConsole (Console& io) { return 0; }
// primitive operations
void* malloc (size_t n) { return ::malloc (n); }
void* realloc (void* ptr, size_t n) { return ::realloc (ptr, n); }
void free (void* ptr) { ::free (ptr); }
bool_t isUpper (cint_t c) { return ase_isupper (c); }
bool_t isLower (cint_t c) { return ase_islower (c); }
bool_t isAlpha (cint_t c) { return ase_isalpha (c); }
bool_t isDigit (cint_t c) { return ase_isdigit (c); }
bool_t isXdigit (cint_t c) { return ase_isxdigit (c); }
bool_t isAlnum (cint_t c) { return ase_isalnum (c); }
bool_t isSpace (cint_t c) { return ase_isspace (c); }
bool_t isPrint (cint_t c) { return ase_isprint (c); }
bool_t isGraph (cint_t c) { return ase_isgraph (c); }
bool_t isCntrl (cint_t c) { return ase_iscntrl (c); }
bool_t isPunct (cint_t c) { return ase_ispunct (c); }
cint_t toUpper (cint_t c) { return ase_toupper (c); }
cint_t toLower (cint_t c) { return ase_tolower (c); }
real_t pow (real_t x, real_t y)
{
return ::pow (x, y);
}
int vsprintf (char_t* buf, size_t size, const char_t* fmt, va_list arg)
{
return ase_vsprintf (buf, size, fmt, arg);
}
void vdprintf (const char_t* fmt, va_list arg)
{
ase_vfprintf (stderr, fmt, arg);
}
private:
char_t sourceInName[1024+1];
}; };
int main () #ifndef NDEBUG
void ase_assert_abort (void)
{ {
abort ();
}
void ase_assert_printf (const ase_char_t* fmt, ...)
{
va_list ap;
#ifdef _WIN32
int n;
ase_char_t buf[1024];
#endif
va_start (ap, fmt);
#if defined(_WIN32)
n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap);
if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0');
#if defined(_MSC_VER) && (_MSC_VER<1400)
MessageBox (NULL, buf,
ASE_T("Assertion Failure"), MB_OK|MB_ICONERROR);
#else
MessageBox (NULL, buf,
ASE_T("\uB2DD\uAE30\uB9AC \uC870\uB610"), MB_OK|MB_ICONERROR);
#endif
#else
ase_vprintf (fmt, ap);
#endif
va_end (ap);
}
#endif
int ase_main (int argc, ase_char_t* argv[])
{
TestAwk awk;
if (awk.open() == -1)
{
ase_fprintf (stderr, ASE_T("cannot open awk\n"));
//awk.close ();
return -1;
}
return -1;
if (awk.parse(ASE_T("t.awk")) == -1)
{
ase_fprintf (stderr, ASE_T("cannot parse\n"));
//awk.close ();
return -1;
}
if (awk.run () == -1)
{
ase_fprintf (stderr, ASE_T("cannot run\n"));
//awk.close ();
return -1;
}
awk.close ();
return 0;
} }