Recovered from cvs revision 2007-05-04 10:25:00

This commit is contained in:
hyung-hwan 2007-05-04 20:30:00 +00:00
parent 6f28e48ff9
commit e42e318a13
2 changed files with 207 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.4 2007/05/02 15:07:33 bacon Exp $
* $Id: Awk.cpp,v 1.5 2007/05/03 15:14:02 bacon Exp $
*/
#include <ase/awk/Awk.hpp>
@ -17,10 +17,7 @@ namespace ASE
int Awk::parse ()
{
if (awk == ASE_NULL)
{
/*awk = ase_awk_open (*/
}
if (awk == ASE_NULL && open() == -1) return -1;
ase_awk_srcios_t srcios;
@ -31,7 +28,7 @@ namespace ASE
return ase_awk_parse (awk, ASE_NULL);
}
int Awk::run (const ase_char_t* main, const ase_char_t** args)
int Awk::run (const char_t* main, const char_t** args)
{
if (awk == ASE_NULL)
{
@ -43,6 +40,45 @@ namespace ASE
return 0;
}
int Awk::open ()
{
ase_awk_prmfns_t prmfns;
prmfns.mmgr.malloc = malloc;
prmfns.mmgr.realloc = realloc;
prmfns.mmgr.free = free;
prmfns.mmgr.custom_data = this;
prmfns.ccls.is_upper = isUpper;
prmfns.ccls.is_lower = isLower;
prmfns.ccls.is_alpha = isAlpha;
prmfns.ccls.is_digit = isDigit;
prmfns.ccls.is_xdigit = isXdigit;
prmfns.ccls.is_alnum = isAlnum;
prmfns.ccls.is_space = isSpace;
prmfns.ccls.is_print = isPrint;
prmfns.ccls.is_graph = isGraph;
prmfns.ccls.is_cntrl = isCntrl;
prmfns.ccls.is_punct = isPunct;
prmfns.ccls.to_upper = toUpper;
prmfns.ccls.to_lower = toLower;
prmfns.ccls.custom_data = this;
prmfns.misc.pow = pow;
prmfns.misc.sprintf = sprintf;
prmfns.misc.dprintf = dprintf;
prmfns.misc.custom_data = this;
awk = ase_awk_open (&prmfns, ASE_NULL);
if (awk == ASE_NULL)
{
// TODO: SET ERROR INFO
return -1;
}
return 0;
}
void Awk::close ()
{
if (awk != ASE_NULL)
@ -52,18 +88,18 @@ namespace ASE
}
}
ase_ssize_t Awk::sourceReader (
int cmd, void* arg, ase_char_t* data, ase_size_t count)
Awk::ssize_t Awk::sourceReader (
int cmd, void* arg, char_t* data, size_t count)
{
ASE::Awk* awk = (ASE::Awk*)arg;
Awk* awk = (Awk*)arg;
if (cmd == ASE_AWK_IO_OPEN)
{
return awk->openSource (ASE::Awk::SOURCE_READ);
return awk->openSource (Awk::SOURCE_READ);
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
return awk->closeSource (ASE::Awk::SOURCE_READ);
return awk->closeSource (Awk::SOURCE_READ);
}
else if (cmd == ASE_AWK_IO_READ)
{
@ -72,19 +108,19 @@ namespace ASE
return -1;
}
ase_ssize_t Awk::sourceWriter (
int cmd, void* arg, ase_char_t* data, ase_size_t count)
Awk::ssize_t Awk::sourceWriter (
int cmd, void* arg, char_t* data, size_t count)
{
ASE::Awk* awk = (ASE::Awk*)arg;
Awk* awk = (Awk*)arg;
if (cmd == ASE_AWK_IO_OPEN)
{
return awk->openSource (ASE::Awk::SOURCE_WRITE);
return awk->openSource (Awk::SOURCE_WRITE);
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
return awk->closeSource (ASE::Awk::SOURCE_WRITE);
return awk->closeSource (Awk::SOURCE_WRITE);
}
else if (cmd == ASE_AWK_IO_WRITE)
{
@ -94,4 +130,99 @@ namespace ASE
return -1;
}
void* Awk::malloc (void* custom, size_t n)
{
return ((Awk*)custom)->malloc (n);
}
void* Awk::realloc (void* custom, void* ptr, size_t n)
{
return ((Awk*)custom)->realloc (ptr, n);
}
void Awk::free (void* custom, void* ptr)
{
((Awk*)custom)->free (ptr);
}
Awk::bool_t Awk::isUpper (void* custom, cint_t c)
{
return ((Awk*)custom)->isUpper (c);
}
Awk::bool_t Awk::isLower (void* custom, cint_t c)
{
return ((Awk*)custom)->isLower (c);
}
Awk::bool_t Awk::isAlpha (void* custom, cint_t c)
{
return ((Awk*)custom)->isAlpha (c);
}
Awk::bool_t Awk::isDigit (void* custom, cint_t c)
{
return ((Awk*)custom)->isDigit (c);
}
Awk::bool_t Awk::isXdigit (void* custom, cint_t c)
{
return ((Awk*)custom)->isXdigit (c);
}
Awk::bool_t Awk::isAlnum (void* custom, cint_t c)
{
return ((Awk*)custom)->isAlnum (c);
}
Awk::bool_t Awk::isSpace (void* custom, cint_t c)
{
return ((Awk*)custom)->isSpace (c);
}
Awk::bool_t Awk::isPrint (void* custom, cint_t c)
{
return ((Awk*)custom)->isPrint (c);
}
Awk::bool_t Awk::isGraph (void* custom, cint_t c)
{
return ((Awk*)custom)->isGraph (c);
}
Awk::bool_t Awk::isCntrl (void* custom, cint_t c)
{
return ((Awk*)custom)->isCntrl (c);
}
Awk::bool_t Awk::isPunct (void* custom, cint_t c)
{
return ((Awk*)custom)->isPunct (c);
}
Awk::cint_t Awk::toUpper (void* custom, cint_t c)
{
return ((Awk*)custom)->toUpper (c);
}
Awk::cint_t Awk::toLower (void* custom, cint_t c)
{
return ((Awk*)custom)->toLower (c);
}
Awk::real_t Awk::pow (void* custom, real_t x, real_t y)
{
return ((Awk*)custom)->pow (x, y);
}
int Awk::sprintf (void* custom, char_t* buf, size_t size,
const char_t* fmt, ...)
{
return 0;
}
void Awk::dprintf (void* custom, const char_t* fmt, ...)
{
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.3 2007/05/02 15:07:33 bacon Exp $
* $Id: Awk.hpp,v 1.4 2007/05/03 15:14:02 bacon Exp $
*/
#ifndef _ASE_AWK_AWK_HPP_
@ -13,11 +13,18 @@ namespace ASE
class Awk
{
public:
typedef ase_bool_t bool_t;
typedef ase_char_t char_t;
typedef ase_cint_t cint_t;
typedef ase_size_t size_t;
typedef ase_ssize_t ssize_t;
typedef ase_real_t real_t;
Awk ();
virtual ~Awk ();
int parse ();
int run (const ase_char_t* main, const ase_char_t** args);
int run (const char_t* main, const char_t** args);
void close ();
enum SourceMode
@ -27,18 +34,60 @@ namespace ASE
};
protected:
int open ();
virtual int openSource (SourceMode mode) = 0;
virtual int closeSource (SourceMode mode) = 0;
virtual ssize_t readSource (char_t* buf, size_t len) = 0;
virtual ssize_t writeSource (char_t* buf, size_t len) = 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;
virtual void* malloc (size_t n) = 0;
virtual void* realloc (void* ptr, size_t n) = 0;
virtual void free (void* ptr) = 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);
virtual bool_t isUpper (cint_t c) = 0;
virtual bool_t isLower (cint_t c) = 0;
virtual bool_t isAlpha (cint_t c) = 0;
virtual bool_t isDigit (cint_t c) = 0;
virtual bool_t isXdigit (cint_t c) = 0;
virtual bool_t isAlnum (cint_t c) = 0;
virtual bool_t isSpace (cint_t c) = 0;
virtual bool_t isPrint (cint_t c) = 0;
virtual bool_t isGraph (cint_t c) = 0;
virtual bool_t isCntrl (cint_t c) = 0;
virtual bool_t isPunct (cint_t c) = 0;
virtual cint_t toUpper (cint_t c) = 0;
virtual cint_t toLower (cint_t c) = 0;
virtual real_t pow (real_t x, real_t y) = 0;
static ssize_t sourceReader (
int cmd, void* arg, char_t* data, size_t count);
static ssize_t sourceWriter (
int cmd, void* arg, char_t* data, size_t count);
static void* malloc (void* custom, size_t n);
static void* realloc (void* custom, void* ptr, size_t n);
static void free (void* custom, void* ptr);
static bool_t isUpper (void* custom, cint_t c);
static bool_t isLower (void* custom, cint_t c);
static bool_t isAlpha (void* custom, cint_t c);
static bool_t isDigit (void* custom, cint_t c);
static bool_t isXdigit (void* custom, cint_t c);
static bool_t isAlnum (void* custom, cint_t c);
static bool_t isSpace (void* custom, cint_t c);
static bool_t isPrint (void* custom, cint_t c);
static bool_t isGraph (void* custom, cint_t c);
static bool_t isCntrl (void* custom, cint_t c);
static bool_t isPunct (void* custom, cint_t c);
static cint_t toUpper (void* custom, cint_t c);
static cint_t toLower (void* custom, cint_t c);
static real_t pow (void* custom, real_t x, real_t y);
static int sprintf (void* custom, char_t* buf, size_t size,
const char_t* fmt, ...);
static void dprintf (void* custom, const char_t* fmt, ...);
private:
ase_awk_t* awk;