cleaned up code

This commit is contained in:
hyung-hwan 2009-02-17 02:11:31 +00:00
parent 66b21c8eab
commit 26b4ecd16e
19 changed files with 492 additions and 470 deletions

View File

@ -1,5 +1,19 @@
/* /*
* $Id: Awk.cpp 341 2008-08-20 10:58:19Z baconevi $ * $Id: Awk.cpp 341 2008-08-20 10:58:19Z baconevi $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/ */
#include <qse/awk/StdAwk.hpp> #include <qse/awk/StdAwk.hpp>
@ -34,6 +48,9 @@ static BOOL WINAPI stop_run (DWORD ctrl_type);
static void stop_run (int sig); static void stop_run (int sig);
#endif #endif
static void set_intr_run (void);
static void unset_intr_run (void);
TestAwk* app_awk = QSE_NULL; TestAwk* app_awk = QSE_NULL;
static bool verbose = false; static bool verbose = false;
@ -232,57 +249,16 @@ public:
protected: protected:
bool onRunStart (Run& run)
{
if (verbose) qse_printf (QSE_T("*** awk run started ***\n"));
app_awk = this;
#ifdef _WIN32
SetConsoleCtrlHandler (stop_run, TRUE);
#else
struct sigaction sa_int;
sa_int.sa_handler = stop_run;
sigemptyset (&sa_int.sa_mask);
sa_int.sa_flags = 0;
#ifdef SA_RESTART
sa_int.sa_flags |= SA_RESTART;
#endif
sigaction (SIGINT, &sa_int, NULL);
#endif
return true;
}
void onRunEnd (Run& run)
{
ErrorCode err = run.getErrorCode();
if (err != ERR_NOERR)
{
qse_fprintf (stderr, QSE_T("cannot run: LINE[%d] %s\n"),
run.getErrorLine(), run.getErrorMessage());
}
#ifdef _WIN32
SetConsoleCtrlHandler (stop_run, FALSE);
#else
struct sigaction sa_int;
sa_int.sa_handler = SIG_DFL;
sigemptyset (&sa_int.sa_mask);
sa_int.sa_flags = 0;
sigaction (SIGINT, &sa_int, NULL);
#endif
app_awk = QSE_NULL;
if (verbose) qse_printf (QSE_T("*** awk run ended ***\n"));
}
bool onRunEnter (Run& run) bool onRunEnter (Run& run)
{ {
set_intr_run ();
return true; return true;
} }
void onRunReturn (Run& run, const Argument& ret) void onRunExit (Run& run, const Argument& ret)
{ {
unset_intr_run ();
if (verbose) if (verbose)
{ {
size_t len; size_t len;
@ -290,6 +266,7 @@ protected:
qse_printf (QSE_T("*** return [%.*s] ***\n"), (int)len, ptr); qse_printf (QSE_T("*** return [%.*s] ***\n"), (int)len, ptr);
} }
} }
int openSource (Source& io) int openSource (Source& io)
{ {
@ -650,6 +627,31 @@ static BOOL WINAPI stop_run (DWORD ctrl_type)
return FALSE; return FALSE;
} }
#else #else
static int setsignal (int sig, void(*handler)(int), int restart)
{
struct sigaction sa_int;
sa_int.sa_handler = handler;
sigemptyset (&sa_int.sa_mask);
sa_int.sa_flags = 0;
if (restart)
{
#ifdef SA_RESTART
sa_int.sa_flags |= SA_RESTART;
#endif
}
else
{
#ifdef SA_INTERRUPT
sa_int.sa_flags |= SA_INTERRUPT;
#endif
}
return sigaction (sig, &sa_int, NULL);
}
static void stop_run (int sig) static void stop_run (int sig)
{ {
int e = errno; int e = errno;
@ -658,6 +660,24 @@ static void stop_run (int sig)
} }
#endif #endif
static void set_intr_run (void)
{
#ifdef _WIN32
SetConsoleCtrlHandler (stop_run, TRUE);
#else
/*setsignal (SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/
setsignal (SIGINT, stop_run, 0);
#endif
}
static void unset_intr_run (void)
{
#ifdef _WIN32
SetConsoleCtrlHandler (stop_run, FALSE);
#else
setsignal (SIGINT, SIG_DFL, 1);
#endif
}
#ifndef NDEBUG #ifndef NDEBUG
void qse_assert_abort (void) void qse_assert_abort (void)
@ -921,6 +941,7 @@ static int awk_main (int argc, qse_char_t* argv[])
} }
awk.enableRunCallback (); awk.enableRunCallback ();
app_awk = &awk;
if (awk.run (args, nargs) == -1) if (awk.run (args, nargs) == -1)
{ {
@ -930,6 +951,7 @@ static int awk_main (int argc, qse_char_t* argv[])
return -1; return -1;
} }
app_awk = QSE_NULL;
awk.close (); awk.close ();
return 0; return 0;

View File

@ -1,5 +1,19 @@
/* /*
* $Id: awk.c 499 2008-12-16 09:42:48Z baconevi $ * $Id: awk.c 499 2008-12-16 09:42:48Z baconevi $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/ */
#include <qse/awk/awk.h> #include <qse/awk/awk.h>
@ -22,7 +36,6 @@
# include <windows.h> # include <windows.h>
# include <tchar.h> # include <tchar.h>
# include <process.h> # include <process.h>
# if defined(_MSC_VER) && defined(_DEBUG) # if defined(_MSC_VER) && defined(_DEBUG)
# define _CRTDBG_MAP_ALLOC # define _CRTDBG_MAP_ALLOC
# include <crtdbg.h> # include <crtdbg.h>

View File

@ -68,7 +68,7 @@ public:
/** Represents an runtime I/O data */ /** Represents an runtime I/O data */
typedef qse_awk_riod_t riod_t; typedef qse_awk_riod_t riod_t;
enum ccls_type_t enum ccls_id_t
{ {
CCLS_UPPER = QSE_CCLS_UPPER, CCLS_UPPER = QSE_CCLS_UPPER,
CCLS_LOWER = QSE_CCLS_LOWER, CCLS_LOWER = QSE_CCLS_LOWER,
@ -743,10 +743,9 @@ public:
void free (void* ptr); void free (void* ptr);
protected: protected:
Awk* awk; Awk* awk;
rtx_t* run; rtx_t* run;
bool callbackFailed; void* data;
void* data;
}; };
/** Constructor */ /** Constructor */
@ -1045,8 +1044,6 @@ protected:
/*@}*/ /*@}*/
// run-time callbacks // run-time callbacks
virtual bool onRunStart (Run& run);
virtual void onRunEnd (Run& run);
virtual bool onRunEnter (Run& run); virtual bool onRunEnter (Run& run);
virtual void onRunExit (Run& run, const Argument& ret); virtual void onRunExit (Run& run, const Argument& ret);
virtual void onRunStatement (Run& run, size_t line); virtual void onRunStatement (Run& run, size_t line);
@ -1056,8 +1053,8 @@ protected:
virtual void* reallocMem (void* ptr, size_t n) = 0; virtual void* reallocMem (void* ptr, size_t n) = 0;
virtual void freeMem (void* ptr) = 0; virtual void freeMem (void* ptr) = 0;
virtual bool_t isType (cint_t c, ccls_type_t type) = 0; virtual bool_t isType (cint_t c, ccls_id_t type) = 0;
virtual cint_t transCase (cint_t c, ccls_type_t type) = 0; virtual cint_t transCase (cint_t c, ccls_id_t type) = 0;
virtual real_t pow (real_t x, real_t y) = 0; virtual real_t pow (real_t x, real_t y) = 0;
virtual int vsprintf (char_t* buf, size_t size, virtual int vsprintf (char_t* buf, size_t size,
@ -1065,23 +1062,24 @@ protected:
// static glue members for various handlers // static glue members for various handlers
static ssize_t sourceReader ( static ssize_t sourceReader (
awk_t* awk, int cmd, char_t* data, size_t count); awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count);
static ssize_t sourceWriter ( static ssize_t sourceWriter (
awk_t* awk, int cmd, char_t* data, size_t count); awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count);
static ssize_t pipeHandler ( static ssize_t pipeHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count); rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count);
static ssize_t fileHandler ( static ssize_t fileHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count); rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count);
static ssize_t consoleHandler ( static ssize_t consoleHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count); rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count);
static int functionHandler ( static int functionHandler (
rtx_t* rtx, const char_t* name, size_t len); rtx_t* rtx, const char_t* name, size_t len);
static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen); static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen);
static int onRunStart (rtx_t* run, void* data);
static void onRunEnd (rtx_t* run, int errnum, void* data);
static int onRunEnter (rtx_t* run, void* data); static int onRunEnter (rtx_t* run, void* data);
static void onRunExit (rtx_t* run, val_t* ret, void* data); static void onRunExit (rtx_t* run, val_t* ret, void* data);
static void onRunStatement (rtx_t* run, size_t line, void* data); static void onRunStatement (rtx_t* run, size_t line, void* data);
@ -1090,8 +1088,8 @@ protected:
static void* reallocMem (void* data, void* ptr, size_t n); static void* reallocMem (void* data, void* ptr, size_t n);
static void freeMem (void* data, void* ptr); static void freeMem (void* data, void* ptr);
static bool_t isType (void* data, cint_t c, qse_ccls_type_t type); static bool_t isType (awk_t* awk, cint_t c, qse_ccls_id_t type);
static cint_t transCase (void* data, cint_t c, qse_ccls_type_t type); static cint_t transCase (awk_t* awk, cint_t c, qse_ccls_id_t type);
static real_t pow (awk_t* data, real_t x, real_t y); static real_t pow (awk_t* data, real_t x, real_t y);
static int sprintf (awk_t* data, char_t* buf, size_t size, static int sprintf (awk_t* data, char_t* buf, size_t size,
@ -1115,8 +1113,6 @@ private:
Awk& operator= (const Awk&); Awk& operator= (const Awk&);
mmgr_t mmgr; mmgr_t mmgr;
ccls_t ccls;
qse_awk_prm_t prm;
}; };
///////////////////////////////// /////////////////////////////////

View File

@ -84,8 +84,8 @@ protected:
void* reallocMem (void* ptr, size_t n); void* reallocMem (void* ptr, size_t n);
void freeMem (void* ptr); void freeMem (void* ptr);
bool_t isType (cint_t c, ccls_type_t type); bool_t isType (cint_t c, ccls_id_t type);
cint_t transCase (cint_t c, ccls_type_t type); cint_t transCase (cint_t c, ccls_id_t type);
real_t pow (real_t x, real_t y); real_t pow (real_t x, real_t y);
int vsprintf (char_t* buf, size_t size, int vsprintf (char_t* buf, size_t size,

View File

@ -58,7 +58,6 @@ typedef struct qse_awk_rio_t qse_awk_rio_t;
typedef struct qse_awk_riod_t qse_awk_riod_t; typedef struct qse_awk_riod_t qse_awk_riod_t;
typedef struct qse_awk_rcb_t qse_awk_rcb_t; typedef struct qse_awk_rcb_t qse_awk_rcb_t;
typedef struct qse_awk_rexfns_t qse_awk_rexfns_t;
typedef qse_real_t (*qse_awk_pow_t) ( typedef qse_real_t (*qse_awk_pow_t) (
qse_awk_t* awk, qse_awk_t* awk,
@ -74,36 +73,70 @@ typedef int (*qse_awk_sprintf_t) (
... ...
); );
typedef qse_bool_t (*qse_awk_isccls_t) (
qse_awk_t* awk,
qse_cint_t c,
qse_ccls_id_t type
);
typedef qse_cint_t (*qse_awk_toccls_t) (
qse_awk_t* awk,
qse_cint_t c,
qse_ccls_id_t type
);
enum qse_awk_sio_cmd_t
{
QSE_AWK_SIO_OPEN = 0,
QSE_AWK_SIO_CLOSE = 1,
QSE_AWK_SIO_READ = 2,
QSE_AWK_SIO_WRITE = 3
};
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
/****t* AWK/qse_awk_siof_t /****t* AWK/qse_awk_siof_t
* NAME * NAME
* qse_awk_siof_t - define a source IO function * qse_awk_siof_t - define a source IO function
* SYNOPSIS * SYNOPSIS
*/ */
typedef qse_ssize_t (*qse_awk_siof_t) ( typedef qse_ssize_t (*qse_awk_siof_t) (
qse_awk_t* awk, qse_awk_t* awk,
int cmd, qse_awk_sio_cmd_t cmd,
qse_char_t* data, qse_char_t* data,
qse_size_t count qse_size_t count
); );
/*****/ /*****/
enum qse_awk_rio_cmd_t
{
QSE_AWK_RIO_OPEN = 0,
QSE_AWK_RIO_CLOSE = 1,
QSE_AWK_RIO_READ = 2,
QSE_AWK_RIO_WRITE = 3,
QSE_AWK_RIO_FLUSH = 4,
QSE_AWK_RIO_NEXT = 5
};
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
/****f* AWK/qse_awk_riof_t /****f* AWK/qse_awk_riof_t
* NAME * NAME
* qse_awk_riof_t - define a runtime IO function * qse_awk_riof_t - define a runtime IO function
* SYNOPSIS * SYNOPSIS
*/ */
typedef qse_ssize_t (*qse_awk_riof_t) ( typedef qse_ssize_t (*qse_awk_riof_t) (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
int cmd, qse_awk_rio_cmd_t cmd,
qse_awk_riod_t* riod, qse_awk_riod_t* riod,
qse_char_t* data, qse_char_t* data,
qse_size_t count qse_size_t count
); );
/******/ /******/
/****f* AWK/qse_awk_riod_t /****f* AWK/qse_awk_riod_t
* NAME * NAME
* qse_awk_riod_f - define a data passed to a rio function * qse_awk_riod_f - define the data passed to a rio function
* SYNOPSIS * SYNOPSIS
*/ */
struct qse_awk_riod_t struct qse_awk_riod_t
@ -135,40 +168,13 @@ struct qse_awk_riod_t
struct qse_awk_prm_t struct qse_awk_prm_t
{ {
qse_awk_pow_t pow; /* required */ qse_awk_pow_t pow;
qse_awk_sprintf_t sprintf; /* required */ qse_awk_sprintf_t sprintf;
}; qse_awk_isccls_t isccls;
qse_awk_toccls_t toccls;
struct qse_awk_sio_t #if 0
{ /* TODO: accept regular expression handling functions */
qse_awk_siof_t in;
qse_awk_siof_t out;
};
struct qse_awk_rio_t
{
qse_awk_riof_t pipe;
qse_awk_riof_t file;
qse_awk_riof_t console;
};
struct qse_awk_rcb_t
{
int (*on_enter) (
qse_awk_rtx_t* rtx, void* data);
void (*on_statement) (
qse_awk_rtx_t* rtx, qse_size_t line, void* data);
void (*on_exit) (
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* data);
void* data;
};
struct qse_awk_rexfns_t
{
/* TODO: implement functions to get/set rexfns */
void* (*build) ( void* (*build) (
qse_awk_t* awk, qse_awk_t* awk,
const qse_char_t* ptn, const qse_char_t* ptn,
@ -196,17 +202,34 @@ struct qse_awk_rexfns_t
qse_awk_t* awk, qse_awk_t* awk,
void* code void* code
); );
#endif
}; };
/* io function commands */ struct qse_awk_sio_t
enum qse_awk_iocmd_t
{ {
QSE_AWK_IO_OPEN = 0, qse_awk_siof_t in;
QSE_AWK_IO_CLOSE = 1, qse_awk_siof_t out;
QSE_AWK_IO_READ = 2, };
QSE_AWK_IO_WRITE = 3,
QSE_AWK_IO_FLUSH = 4, struct qse_awk_rio_t
QSE_AWK_IO_NEXT = 5 {
qse_awk_riof_t pipe;
qse_awk_riof_t file;
qse_awk_riof_t console;
};
struct qse_awk_rcb_t
{
int (*on_enter) (
qse_awk_rtx_t* rtx, void* data);
void (*on_statement) (
qse_awk_rtx_t* rtx, qse_size_t line, void* data);
void (*on_exit) (
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* data);
void* data;
}; };
/* various options */ /* various options */
@ -649,19 +672,35 @@ extern qse_awk_val_t* qse_awk_val_one;
* NAME * NAME
* qse_awk_open - create an awk object * qse_awk_open - create an awk object
* DESCRIPTION * DESCRIPTION
* The qse_awk_open() function creates a new qse_awk_t instance. * The qse_awk_open() function creates a new qse_awk_t object.
* The instance created can be passed to other qse_awk_xxx() functions and * The instance created can be passed to other qse_awk_xxx() functions and
* is valid until it is successfully destroyed using the qse_qse_close() * is valid until it is successfully destroyed using the qse_qse_close()
* function. * function. The function save the memory manager pointer while it copies
* the contents of the primitive function structures. Therefore, you should
* keep the memory manager valid during the whole life cycle of an qse_awk_t
* object.
*
* qse_awk_t* dummy()
* {
* qse_mmgr_t mmgr;
* qse_awk_prm_t prm;
* return qse_awk_open (
* &mmgr, // NOT OK because the contents of mmgr is
* // invalidated when dummy() returns.
* 0,
* &prm // OK
* );
* }
*
* RETURN * RETURN
* The qse_awk_open() function returns the pointer to a qse_awk_t instance * The qse_awk_open() function returns the pointer to a qse_awk_t object
* on success and QSE_NULL on failure. * on success and QSE_NULL on failure.
* SYNOPSIS * SYNOPSIS
*/ */
qse_awk_t* qse_awk_open ( qse_awk_t* qse_awk_open (
qse_mmgr_t* mmgr /* a memory manager */, qse_mmgr_t* mmgr /* a memory manager */,
qse_size_t xtn /* the size of extension in bytes */, qse_size_t xtn /* the size of extension in bytes */,
qse_ccls_t* ccls qse_awk_prm_t* prm /* primitive functoins */
); );
/******/ /******/
@ -723,27 +762,6 @@ void* qse_awk_getxtn (
); );
/******/ /******/
/****f* AWK/qse_awk_getccls
* NAME
* qse_awk_getccls - get a character classifier
* SYNOPSIS
*/
qse_ccls_t* qse_awk_getccls (
qse_awk_t* awk
);
/******/
/****f* AWK/qse_awk_setccls
* NAME
* qse_awk_setccls - set the character classfier
* SYNOPSIS
*/
void qse_awk_setccls (
qse_awk_t* awk,
qse_ccls_t* ccls
);
/******/
/****f* AWK/qse_awk_getprm /****f* AWK/qse_awk_getprm
* NAME * NAME
* qse_awk_getprm - get primitive functions * qse_awk_getprm - get primitive functions
@ -754,14 +772,13 @@ qse_awk_prm_t* qse_awk_getprm (
); );
/******/ /******/
/****f* AWK/qse_awk_setprm /****f* AWK/qse_awk_getccls
* NAME * NAME
* qse_awk_setprm - set primitive functions * qse_awk_getcclas - get the character classifier
* SYNOPSIS * SYNOPSIS
*/ */
void qse_awk_setprm ( qse_ccls_t* qse_awk_getccls (
qse_awk_t* awk, qse_awk_t* ccls
qse_awk_prm_t* prm
); );
/******/ /******/
@ -1450,7 +1467,7 @@ qse_awk_val_t* qse_awk_rtx_makerefval (
qse_awk_val_t** adr qse_awk_val_t** adr
); );
qse_bool_t qse_awk_isstaticval ( qse_bool_t qse_awk_rtx_isstaticval (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
qse_awk_val_t* val qse_awk_val_t* val
); );

View File

@ -53,16 +53,14 @@ extern qse_ccls_t* qse_ccls;
qse_bool_t qse_ccls_is ( qse_bool_t qse_ccls_is (
qse_cint_t c, qse_cint_t c,
qse_ccls_type_t type qse_ccls_id_t type
); );
qse_cint_t qse_ccls_to ( qse_cint_t qse_ccls_to (
qse_cint_t c, qse_cint_t c,
qse_ccls_type_t type qse_ccls_id_t type
); );
qse_size_t qse_mblen ( qse_size_t qse_mblen (
const qse_mchar_t* mb, const qse_mchar_t* mb,
qse_size_t mblen qse_size_t mblen

View File

@ -172,6 +172,26 @@ qse_mmgr_t* qse_##name##_getmmgr (qse_##name##_t* name); \
void* qse_##name##_getxtn (qse_##name##_t* name); void* qse_##name##_getxtn (qse_##name##_t* name);
/******/ /******/
/****d* Base/QSE_MMGR
* NAME
* QSE_MMGR - get the memory manager field
* SYNOPSIS
*/
#define QSE_MMGR(obj) (obj->mmgr)
/******/
/****d* Base/QSE_XTN
* NAME
* QSE_XTN - get a pointer to extension space
* DESCRIPTION
* The QSE_XTN() macro is a convenience macro to retrieve the pointer to
* extension space located at the end of an object. The type of the object
* should be known in advance for it to work properly.
* SYNOPSIS
*/
#define QSE_XTN(obj) ((void*)(obj + 1))
/******/
/****d* Base/QSE_IMPLEMENT_COMMON_FUNCTIONS /****d* Base/QSE_IMPLEMENT_COMMON_FUNCTIONS
* NAME * NAME
* QSE_IMPLEMENT_COMMON_FUNCTIONS - implement common functions * QSE_IMPLEMENT_COMMON_FUNCTIONS - implement common functions
@ -180,16 +200,17 @@ void* qse_##name##_getxtn (qse_##name##_t* name);
#define QSE_IMPLEMENT_COMMON_FUNCTIONS(name) \ #define QSE_IMPLEMENT_COMMON_FUNCTIONS(name) \
void qse_##name##_setmmgr (qse_##name##_t* name, qse_mmgr_t* mmgr) \ void qse_##name##_setmmgr (qse_##name##_t* name, qse_mmgr_t* mmgr) \
{ \ { \
name->mmgr = mmgr; \ QSE_MMGR(name) = mmgr; \
} \ } \
qse_mmgr_t* qse_##name##_getmmgr (qse_##name##_t* name) \ qse_mmgr_t* qse_##name##_getmmgr (qse_##name##_t* name) \
{ \ { \
return name->mmgr; \ return QSE_MMGR(name); \
} \ } \
void* qse_##name##_getxtn (qse_##name##_t* name) \ void* qse_##name##_getxtn (qse_##name##_t* name) \
{ \ { \
return (void*)(name + 1); \ return QSE_XTN(name); \
} }
/******/ /******/
#endif #endif

View File

@ -413,12 +413,12 @@ struct qse_mmgr_t
}; };
/******/ /******/
/****t* Base/qse_ccls_type_t /****t* Base/qse_ccls_id_t
* NAME * NAME
* qse_ccls_type_t - define character class types * qse_ccls_id_t - define character class types
* SYNOPSIS * SYNOPSIS
*/ */
enum qse_ccls_type_t enum qse_ccls_id_t
{ {
QSE_CCLS_UPPER, QSE_CCLS_UPPER,
QSE_CCLS_LOWER, QSE_CCLS_LOWER,
@ -434,7 +434,12 @@ enum qse_ccls_type_t
}; };
/******/ /******/
typedef enum qse_ccls_type_t qse_ccls_type_t; typedef enum qse_ccls_id_t qse_ccls_id_t;
typedef qse_bool_t (*qse_ccls_is_t) (
void* data, qse_cint_t c, qse_ccls_id_t type);
typedef qse_cint_t (*qse_ccls_to_t) (
void* data, qse_cint_t c, qse_ccls_id_t type);
/****t* Base/qse_ccls_t /****t* Base/qse_ccls_t
* NAME * NAME
@ -443,9 +448,9 @@ typedef enum qse_ccls_type_t qse_ccls_type_t;
*/ */
struct qse_ccls_t struct qse_ccls_t
{ {
qse_bool_t (*is) (void* data, qse_cint_t c, qse_ccls_type_t type); qse_ccls_is_t is;
qse_cint_t (*to) (void* data, qse_cint_t c, qse_ccls_type_t type); qse_ccls_to_t to;
void* data; void* data;
}; };
/******/ /******/

View File

@ -19,6 +19,7 @@
#include <qse/awk/Awk.hpp> #include <qse/awk/Awk.hpp>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include "../cmn/mem.h" #include "../cmn/mem.h"
#include "awk.h"
#include <qse/utl/stdio.h> #include <qse/utl/stdio.h>
///////////////////////////////// /////////////////////////////////
@ -83,7 +84,7 @@ void Awk::RIO::setHandle (void* handle)
Awk::RIO::operator Awk::Awk* () const Awk::RIO::operator Awk::Awk* () const
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (this->rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (this->rtx);
return rxtn->run->awk; return rxtn->run->awk;
} }
@ -909,13 +910,11 @@ void Awk::Return::clear ()
// Awk::Run // Awk::Run
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
Awk::Run::Run (Awk* awk): Awk::Run::Run (Awk* awk): awk (awk), run (QSE_NULL)
awk (awk), run (QSE_NULL), callbackFailed (false)
{ {
} }
Awk::Run::Run (Awk* awk, rtx_t* run): Awk::Run::Run (Awk* awk, rtx_t* run): awk (awk), run (run), data (QSE_NULL)
awk (awk), run (run), callbackFailed (false), data (QSE_NULL)
{ {
QSE_ASSERT (this->run != QSE_NULL); QSE_ASSERT (this->run != QSE_NULL);
} }
@ -1077,13 +1076,6 @@ Awk::Awk (): awk (QSE_NULL), functionMap (QSE_NULL),
mmgr.realloc = reallocMem; mmgr.realloc = reallocMem;
mmgr.free = freeMem; mmgr.free = freeMem;
mmgr.data = this; mmgr.data = this;
ccls.is = isType;
ccls.to = transCase;
ccls.data = this;
prm.pow = pow;
prm.sprintf = sprintf;
} }
Awk::~Awk () Awk::~Awk ()
@ -1196,7 +1188,13 @@ int Awk::open ()
{ {
QSE_ASSERT (awk == QSE_NULL && functionMap == QSE_NULL); QSE_ASSERT (awk == QSE_NULL && functionMap == QSE_NULL);
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t), &ccls); qse_awk_prm_t prm;
prm.pow = pow;
prm.sprintf = sprintf;
prm.isccls = isType;
prm.toccls = transCase;
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t), &prm);
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
setError (ERR_NOMEM); setError (ERR_NOMEM);
@ -1204,11 +1202,9 @@ int Awk::open ()
} }
// associate this Awk object with the underlying awk object // associate this Awk object with the underlying awk object
xtn_t* xtn = (xtn_t*)qse_awk_getxtn (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
xtn->awk = this; xtn->awk = this;
qse_awk_setprm (awk, &prm);
//functionMap = qse_map_open ( //functionMap = qse_map_open (
// this, 512, 70, freeFunctionMapValue, QSE_NULL, // this, 512, 70, freeFunctionMapValue, QSE_NULL,
// qse_awk_getmmgr(awk)); // qse_awk_getmmgr(awk));
@ -1223,7 +1219,7 @@ int Awk::open ()
return -1; return -1;
} }
*(Awk**)qse_map_getxtn(functionMap) = this; *(Awk**)QSE_XTN(functionMap) = this;
qse_map_setcopier (functionMap, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (functionMap, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setfreeer (functionMap, QSE_MAP_VAL, freeFunctionMapValue); qse_map_setfreeer (functionMap, QSE_MAP_VAL, freeFunctionMapValue);
qse_map_setscale (functionMap, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (functionMap, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
@ -1415,7 +1411,7 @@ int Awk::run (const char_t** args, size_t nargs)
{ {
runctx.run = rtx; runctx.run = rtx;
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
rxtn->run = &runctx; rxtn->run = &runctx;
if (runCallback) qse_awk_rtx_setrcb (rtx, &rcb); if (runCallback) qse_awk_rtx_setrcb (rtx, &rcb);
@ -1581,15 +1577,6 @@ void Awk::disableRunCallback ()
runCallback = false; runCallback = false;
} }
bool Awk::onRunStart (Run& run)
{
return true;
}
void Awk::onRunEnd (Run& run)
{
}
bool Awk::onRunEnter (Run& run) bool Awk::onRunEnter (Run& run)
{ {
return true; return true;
@ -1604,45 +1591,50 @@ void Awk::onRunStatement (Run& run, size_t line)
} }
Awk::ssize_t Awk::sourceReader ( Awk::ssize_t Awk::sourceReader (
awk_t* awk, int cmd, char_t* data, size_t count) awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count)
{ {
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_SIO_OPEN:
return xtn->awk->openSource (xtn->awk->sourceIn); return xtn->awk->openSource (xtn->awk->sourceIn);
case QSE_AWK_IO_CLOSE: case QSE_AWK_SIO_CLOSE:
return xtn->awk->closeSource (xtn->awk->sourceIn); return xtn->awk->closeSource (xtn->awk->sourceIn);
case QSE_AWK_IO_READ: case QSE_AWK_SIO_READ:
return xtn->awk->readSource (xtn->awk->sourceIn, data, count); return xtn->awk->readSource (xtn->awk->sourceIn, data, count);
case QSE_AWK_SIO_WRITE:
return -1;
} }
return -1; return -1;
} }
Awk::ssize_t Awk::sourceWriter ( Awk::ssize_t Awk::sourceWriter (
awk_t* awk, int cmd, char_t* data, size_t count) awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count)
{ {
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_SIO_OPEN:
return xtn->awk->openSource (xtn->awk->sourceOut); return xtn->awk->openSource (xtn->awk->sourceOut);
case QSE_AWK_IO_CLOSE: case QSE_AWK_SIO_CLOSE:
return xtn->awk->closeSource (xtn->awk->sourceOut); return xtn->awk->closeSource (xtn->awk->sourceOut);
case QSE_AWK_IO_WRITE: case QSE_AWK_SIO_WRITE:
return xtn->awk->writeSource (xtn->awk->sourceOut, data, count); return xtn->awk->writeSource (xtn->awk->sourceOut, data, count);
case QSE_AWK_SIO_READ:
return -1;
} }
return -1; return -1;
} }
Awk::ssize_t Awk::pipeHandler ( Awk::ssize_t Awk::pipeHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count) rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count)
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
Awk* awk = rxtn->run->awk; Awk* awk = rxtn->run->awk;
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_PIPE); QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_PIPE);
@ -1651,20 +1643,20 @@ Awk::ssize_t Awk::pipeHandler (
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_RIO_OPEN:
return awk->openPipe (pipe); return awk->openPipe (pipe);
case QSE_AWK_IO_CLOSE: case QSE_AWK_RIO_CLOSE:
return awk->closePipe (pipe); return awk->closePipe (pipe);
case QSE_AWK_IO_READ: case QSE_AWK_RIO_READ:
return awk->readPipe (pipe, data, count); return awk->readPipe (pipe, data, count);
case QSE_AWK_IO_WRITE: case QSE_AWK_RIO_WRITE:
return awk->writePipe (pipe, data, count); return awk->writePipe (pipe, data, count);
case QSE_AWK_IO_FLUSH: case QSE_AWK_RIO_FLUSH:
return awk->flushPipe (pipe); return awk->flushPipe (pipe);
case QSE_AWK_IO_NEXT: case QSE_AWK_RIO_NEXT:
return -1; return -1;
} }
@ -1672,9 +1664,10 @@ Awk::ssize_t Awk::pipeHandler (
} }
Awk::ssize_t Awk::fileHandler ( Awk::ssize_t Awk::fileHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count) rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count)
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
Awk* awk = rxtn->run->awk; Awk* awk = rxtn->run->awk;
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_FILE); QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_FILE);
@ -1683,20 +1676,20 @@ Awk::ssize_t Awk::fileHandler (
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_RIO_OPEN:
return awk->openFile (file); return awk->openFile (file);
case QSE_AWK_IO_CLOSE: case QSE_AWK_RIO_CLOSE:
return awk->closeFile (file); return awk->closeFile (file);
case QSE_AWK_IO_READ: case QSE_AWK_RIO_READ:
return awk->readFile (file, data, count); return awk->readFile (file, data, count);
case QSE_AWK_IO_WRITE: case QSE_AWK_RIO_WRITE:
return awk->writeFile (file, data, count); return awk->writeFile (file, data, count);
case QSE_AWK_IO_FLUSH: case QSE_AWK_RIO_FLUSH:
return awk->flushFile (file); return awk->flushFile (file);
case QSE_AWK_IO_NEXT: case QSE_AWK_RIO_NEXT:
return -1; return -1;
} }
@ -1704,9 +1697,10 @@ Awk::ssize_t Awk::fileHandler (
} }
Awk::ssize_t Awk::consoleHandler ( Awk::ssize_t Awk::consoleHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count) rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count)
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
Awk* awk = rxtn->run->awk; Awk* awk = rxtn->run->awk;
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_CONSOLE); QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_CONSOLE);
@ -1715,19 +1709,19 @@ Awk::ssize_t Awk::consoleHandler (
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_RIO_OPEN:
return awk->openConsole (console); return awk->openConsole (console);
case QSE_AWK_IO_CLOSE: case QSE_AWK_RIO_CLOSE:
return awk->closeConsole (console); return awk->closeConsole (console);
case QSE_AWK_IO_READ: case QSE_AWK_RIO_READ:
return awk->readConsole (console, data, count); return awk->readConsole (console, data, count);
case QSE_AWK_IO_WRITE: case QSE_AWK_RIO_WRITE:
return awk->writeConsole (console, data, count); return awk->writeConsole (console, data, count);
case QSE_AWK_IO_FLUSH: case QSE_AWK_RIO_FLUSH:
return awk->flushConsole (console); return awk->flushConsole (console);
case QSE_AWK_IO_NEXT: case QSE_AWK_RIO_NEXT:
return awk->nextConsole (console); return awk->nextConsole (console);
} }
@ -1736,57 +1730,35 @@ Awk::ssize_t Awk::consoleHandler (
int Awk::functionHandler (rtx_t* rtx, const char_t* name, size_t len) int Awk::functionHandler (rtx_t* rtx, const char_t* name, size_t len)
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
return rxtn->run->awk->dispatchFunction (rxtn->run, name, len); return rxtn->run->awk->dispatchFunction (rxtn->run, name, len);
} }
void Awk::freeFunctionMapValue (map_t* map, void* dptr, size_t dlen) void Awk::freeFunctionMapValue (map_t* map, void* dptr, size_t dlen)
{ {
//Awk* awk = (Awk*)owner; Awk* awk = *(Awk**) QSE_XTN (map);
Awk* awk = *(Awk**)qse_map_getxtn(map);
qse_awk_free (awk->awk, dptr); qse_awk_free (awk->awk, dptr);
} }
int Awk::onRunStart (rtx_t* run, void* data)
{
Run* r = (Run*)data;
r->callbackFailed = false;
return r->awk->onRunStart(*r)? 0: -1;
}
void Awk::onRunEnd (rtx_t* run, int errnum, void* data)
{
Run* r = (Run*)data;
if (errnum == ERR_NOERR && r->callbackFailed)
{
qse_awk_rtx_seterrnum (r->run, ERR_NOMEM);
}
r->awk->onRunEnd (*r);
}
int Awk::onRunEnter (rtx_t* run, void* data) int Awk::onRunEnter (rtx_t* run, void* data)
{ {
Run* r = (Run*)data; Run* r = (Run*)data;
if (r->callbackFailed) return false;
return r->awk->onRunEnter(*r)? 0: -1; return r->awk->onRunEnter(*r)? 0: -1;
} }
void Awk::onRunExit (rtx_t* run, val_t* ret, void* data) void Awk::onRunExit (rtx_t* run, val_t* ret, void* data)
{ {
Run* r = (Run*)data; Run* r = (Run*)data;
if (r->callbackFailed) return;
Argument x (r); Argument x (r);
if (x.init (ret) == -1) r->callbackFailed = true; if (x.init (ret) == -1)
qse_awk_rtx_seterrnum (r->run, ERR_NOMEM);
else r->awk->onRunExit (*r, x); else r->awk->onRunExit (*r, x);
} }
void Awk::onRunStatement (rtx_t* run, size_t line, void* data) void Awk::onRunStatement (rtx_t* run, size_t line, void* data)
{ {
Run* r = (Run*)data; Run* r = (Run*)data;
if (r->callbackFailed) return;
r->awk->onRunStatement (*r, line); r->awk->onRunStatement (*r, line);
} }
@ -1805,26 +1777,28 @@ void Awk::freeMem (void* data, void* ptr)
((Awk*)data)->freeMem (ptr); ((Awk*)data)->freeMem (ptr);
} }
Awk::bool_t Awk::isType (void* data, cint_t c, qse_ccls_type_t type) Awk::bool_t Awk::isType (awk_t* awk, cint_t c, qse_ccls_id_t type)
{ {
return ((Awk*)data)->isType (c, (ccls_type_t)type); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
return xtn->awk->isType (c, (ccls_id_t)type);
} }
Awk::cint_t Awk::transCase (void* data, cint_t c, qse_ccls_type_t type) Awk::cint_t Awk::transCase (awk_t* awk, cint_t c, qse_ccls_id_t type)
{ {
return ((Awk*)data)->transCase (c, (ccls_type_t)type); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
return xtn->awk->transCase (c, (ccls_id_t)type);
} }
Awk::real_t Awk::pow (awk_t* awk, real_t x, real_t y) Awk::real_t Awk::pow (awk_t* awk, real_t x, real_t y)
{ {
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
return xtn->awk->pow (x, y); return xtn->awk->pow (x, y);
} }
int Awk::sprintf (awk_t* awk, char_t* buf, size_t size, int Awk::sprintf (awk_t* awk, char_t* buf, size_t size,
const char_t* fmt, ...) const char_t* fmt, ...)
{ {
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
va_list ap; va_list ap;
va_start (ap, fmt); va_start (ap, fmt);

View File

@ -412,14 +412,14 @@ void StdAwk::freeMem (void* ptr)
} }
// character handling primitive // character handling primitive
Awk::bool_t StdAwk::isType (cint_t c, ccls_type_t type) Awk::bool_t StdAwk::isType (cint_t c, ccls_id_t type)
{ {
return qse_ccls_is (c, (qse_ccls_type_t)type); return qse_ccls_is (c, (qse_ccls_id_t)type);
} }
Awk::cint_t StdAwk::transCase (cint_t c, ccls_type_t type) Awk::cint_t StdAwk::transCase (cint_t c, ccls_id_t type)
{ {
return qse_ccls_to (c, (qse_ccls_type_t)type); return qse_ccls_to (c, (qse_ccls_id_t)type);
} }
// miscellaneous primitive // miscellaneous primitive

View File

@ -35,7 +35,7 @@
static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen) static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen)
{ {
qse_awk_t* awk = *(qse_awk_t**)qse_map_getxtn(map); qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(map);
qse_awk_fun_t* f = (qse_awk_fun_t*)vptr; qse_awk_fun_t* f = (qse_awk_fun_t*)vptr;
/* f->name doesn't have to be freed */ /* f->name doesn't have to be freed */
@ -47,13 +47,13 @@ static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen)
static void free_fnc (qse_map_t* map, void* vptr, qse_size_t vlen) static void free_fnc (qse_map_t* map, void* vptr, qse_size_t vlen)
{ {
qse_awk_t* awk = *(qse_awk_t**)qse_map_getxtn(map); qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(map);
qse_awk_fnc_t* f = (qse_awk_fnc_t*)vptr; qse_awk_fnc_t* f = (qse_awk_fnc_t*)vptr;
QSE_AWK_FREE (awk, f); QSE_AWK_FREE (awk, f);
} }
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls) qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
{ {
qse_awk_t* awk; qse_awk_t* awk;
@ -67,19 +67,34 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls)
if (mmgr == QSE_NULL) return QSE_NULL; if (mmgr == QSE_NULL) return QSE_NULL;
} }
/* allocate the object */
awk = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_awk_t) + xtn); awk = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_awk_t) + xtn);
if (awk == QSE_NULL) return QSE_NULL; if (awk == QSE_NULL) return QSE_NULL;
/* zero out the object */
QSE_MEMSET (awk, 0, QSE_SIZEOF(qse_awk_t) + xtn); QSE_MEMSET (awk, 0, QSE_SIZEOF(qse_awk_t) + xtn);
/* remember the memory manager */
awk->mmgr = mmgr; awk->mmgr = mmgr;
awk->ccls = ccls;
/* progagate the primitive functions */
QSE_ASSERT (prm->pow != QSE_NULL);
QSE_ASSERT (prm->sprintf != QSE_NULL);
QSE_ASSERT (prm->isccls != QSE_NULL);
QSE_ASSERT (prm->toccls != QSE_NULL);
awk->prm = *prm;
/* build a character classifier from the primitive functions */
awk->ccls.is = (qse_ccls_is_t) prm->isccls;
awk->ccls.to = (qse_ccls_to_t) prm->toccls;
awk->ccls.data = awk;
awk->token.name = qse_str_open (mmgr, 0, 128); awk->token.name = qse_str_open (mmgr, 0, 128);
if (awk->token.name == QSE_NULL) goto oops; if (awk->token.name == QSE_NULL) goto oops;
awk->wtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70); awk->wtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
if (awk->wtab == QSE_NULL) goto oops; if (awk->wtab == QSE_NULL) goto oops;
*(qse_awk_t**)qse_map_getxtn(awk->wtab) = awk; *(qse_awk_t**)QSE_XTN(awk->wtab) = awk;
qse_map_setcopier (awk->wtab, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->wtab, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setcopier (awk->wtab, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->wtab, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
qse_map_setscale (awk->wtab, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (awk->wtab, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
@ -87,7 +102,7 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls)
awk->rwtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70); awk->rwtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
if (awk->rwtab == QSE_NULL) goto oops; if (awk->rwtab == QSE_NULL) goto oops;
*(qse_awk_t**)qse_map_getxtn(awk->rwtab) = awk; *(qse_awk_t**)QSE_XTN(awk->rwtab) = awk;
qse_map_setcopier (awk->rwtab, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->rwtab, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setcopier (awk->rwtab, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->rwtab, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
qse_map_setscale (awk->rwtab, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (awk->rwtab, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
@ -96,21 +111,21 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls)
/* TODO: initial map size?? */ /* TODO: initial map size?? */
awk->tree.funs = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70); awk->tree.funs = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
if (awk->tree.funs == QSE_NULL) goto oops; if (awk->tree.funs == QSE_NULL) goto oops;
*(qse_awk_t**)qse_map_getxtn(awk->tree.funs) = awk; *(qse_awk_t**)QSE_XTN(awk->tree.funs) = awk;
qse_map_setcopier (awk->tree.funs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->tree.funs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setfreeer (awk->tree.funs, QSE_MAP_VAL, free_fun); qse_map_setfreeer (awk->tree.funs, QSE_MAP_VAL, free_fun);
qse_map_setscale (awk->tree.funs, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (awk->tree.funs, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
awk->parse.funs = qse_map_open (mmgr, QSE_SIZEOF(awk), 256, 70); awk->parse.funs = qse_map_open (mmgr, QSE_SIZEOF(awk), 256, 70);
if (awk->parse.funs == QSE_NULL) goto oops; if (awk->parse.funs == QSE_NULL) goto oops;
*(qse_awk_t**)qse_map_getxtn(awk->parse.funs) = awk; *(qse_awk_t**)QSE_XTN(awk->parse.funs) = awk;
qse_map_setcopier (awk->parse.funs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->parse.funs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setcopier (awk->parse.funs, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->parse.funs, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
qse_map_setscale (awk->parse.funs, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (awk->parse.funs, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
awk->parse.named = qse_map_open (mmgr, QSE_SIZEOF(awk), 256, 70); awk->parse.named = qse_map_open (mmgr, QSE_SIZEOF(awk), 256, 70);
if (awk->parse.named == QSE_NULL) goto oops; if (awk->parse.named == QSE_NULL) goto oops;
*(qse_awk_t**)qse_map_getxtn(awk->parse.named) = awk; *(qse_awk_t**)QSE_XTN(awk->parse.named) = awk;
qse_map_setcopier (awk->parse.named, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->parse.named, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setcopier (awk->parse.named, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->parse.named, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
qse_map_setscale (awk->parse.named, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (awk->parse.named, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
@ -123,15 +138,15 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls)
awk->parse.lcls == QSE_NULL || awk->parse.lcls == QSE_NULL ||
awk->parse.params == QSE_NULL) goto oops; awk->parse.params == QSE_NULL) goto oops;
*(qse_awk_t**)qse_lda_getxtn(awk->parse.gbls) = awk; *(qse_awk_t**)QSE_XTN(awk->parse.gbls) = awk;
qse_lda_setcopier (awk->parse.gbls, QSE_LDA_COPIER_INLINE); qse_lda_setcopier (awk->parse.gbls, QSE_LDA_COPIER_INLINE);
qse_lda_setscale (awk->parse.gbls, QSE_SIZEOF(qse_char_t)); qse_lda_setscale (awk->parse.gbls, QSE_SIZEOF(qse_char_t));
*(qse_awk_t**)qse_lda_getxtn(awk->parse.lcls) = awk; *(qse_awk_t**)QSE_XTN(awk->parse.lcls) = awk;
qse_lda_setcopier (awk->parse.lcls, QSE_LDA_COPIER_INLINE); qse_lda_setcopier (awk->parse.lcls, QSE_LDA_COPIER_INLINE);
qse_lda_setscale (awk->parse.lcls, QSE_SIZEOF(qse_char_t)); qse_lda_setscale (awk->parse.lcls, QSE_SIZEOF(qse_char_t));
*(qse_awk_t**)qse_lda_getxtn(awk->parse.params) = awk; *(qse_awk_t**)QSE_XTN(awk->parse.params) = awk;
qse_lda_setcopier (awk->parse.params, QSE_LDA_COPIER_INLINE); qse_lda_setcopier (awk->parse.params, QSE_LDA_COPIER_INLINE);
qse_lda_setscale (awk->parse.params, QSE_SIZEOF(qse_char_t)); qse_lda_setscale (awk->parse.params, QSE_SIZEOF(qse_char_t));
@ -169,7 +184,7 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls)
awk->fnc.sys = QSE_NULL; awk->fnc.sys = QSE_NULL;
awk->fnc.user = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70); awk->fnc.user = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
if (awk->fnc.user == QSE_NULL) goto oops; if (awk->fnc.user == QSE_NULL) goto oops;
*(qse_awk_t**)qse_map_getxtn(awk->fnc.user) = awk; *(qse_awk_t**)QSE_XTN(awk->fnc.user) = awk;
qse_map_setcopier (awk->fnc.user, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (awk->fnc.user, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setfreeer (awk->fnc.user, QSE_MAP_VAL, free_fnc); qse_map_setfreeer (awk->fnc.user, QSE_MAP_VAL, free_fnc);
qse_map_setscale (awk->fnc.user, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); qse_map_setscale (awk->fnc.user, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
@ -329,28 +344,14 @@ void qse_awk_setmmgr (qse_awk_t* awk, qse_mmgr_t* mmgr)
awk->mmgr = mmgr; awk->mmgr = mmgr;
} }
qse_ccls_t* qse_awk_getccls (qse_awk_t* awk)
{
return awk->ccls;
}
void qse_awk_setccls (qse_awk_t* awk, qse_ccls_t* ccls)
{
QSE_ASSERT (ccls->is != QSE_NULL);
QSE_ASSERT (ccls->to != QSE_NULL);
awk->ccls = ccls;
}
qse_awk_prm_t* qse_awk_getprm (qse_awk_t* awk) qse_awk_prm_t* qse_awk_getprm (qse_awk_t* awk)
{ {
return &awk->prm; return &awk->prm;
} }
void qse_awk_setprm (qse_awk_t* awk, qse_awk_prm_t* prm) qse_ccls_t* qse_awk_getccls (qse_awk_t* awk)
{ {
QSE_ASSERT (prm->pow != QSE_NULL); return &awk->ccls;
QSE_ASSERT (prm->sprintf != QSE_NULL);
awk->prm = *prm;
} }
int qse_awk_getoption (qse_awk_t* awk) int qse_awk_getoption (qse_awk_t* awk)
@ -446,20 +447,3 @@ int qse_awk_setword (qse_awk_t* awk,
return 0; return 0;
} }
#if 0
/* TODO: qse_awk_setrexfns... */
int qse_awk_setrexfns (qse_awk_t* awk, qse_awk_rexfns_t* rexfns)
{
if (rexfns->build == QSE_NULL ||
rexfns->match == QSE_NULL ||
rexfns->free == QSE_NULL ||
rexfns->isempty == QSE_NULL)
{
SETERR (awk, QSE_AWK_EINVAL);
return -1;
}
awk->rexfns = rexfns;
return 0;
}
#endif

View File

@ -46,19 +46,19 @@ typedef struct qse_awk_tree_t qse_awk_tree_t;
#define QSE_AWK_REALLOC(awk,ptr,size) QSE_MMGR_REALLOC((awk)->mmgr,ptr,size) #define QSE_AWK_REALLOC(awk,ptr,size) QSE_MMGR_REALLOC((awk)->mmgr,ptr,size)
#define QSE_AWK_FREE(awk,ptr) QSE_MMGR_FREE((awk)->mmgr,ptr) #define QSE_AWK_FREE(awk,ptr) QSE_MMGR_FREE((awk)->mmgr,ptr)
#define QSE_AWK_ISUPPER(awk,c) QSE_CCLS_ISUPPER((awk)->ccls,c) #define QSE_AWK_ISUPPER(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_UPPER)
#define QSE_AWK_ISLOWER(awk,c) QSE_CCLS_ISLOWER((awk)->ccls,c) #define QSE_AWK_ISLOWER(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_UPPER)
#define QSE_AWK_ISALPHA(awk,c) QSE_CCLS_ISALPHA((awk)->ccls,c) #define QSE_AWK_ISALPHA(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_ALPHA)
#define QSE_AWK_ISDIGIT(awk,c) QSE_CCLS_ISDIGIT((awk)->ccls,c) #define QSE_AWK_ISDIGIT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_DIGIT)
#define QSE_AWK_ISXDIGIT(awk,c) QSE_CCLS_ISXDIGIT((awk)->ccls,c) #define QSE_AWK_ISXDIGIT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_XDIGIT)
#define QSE_AWK_ISALNUM(awk,c) QSE_CCLS_ISALNUM((awk)->ccls,c) #define QSE_AWK_ISALNUM(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_ALNUM)
#define QSE_AWK_ISSPACE(awk,c) QSE_CCLS_ISSPACE((awk)->ccls,c) #define QSE_AWK_ISSPACE(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_SPACE)
#define QSE_AWK_ISPRINT(awk,c) QSE_CCLS_ISPRINT((awk)->ccls,c) #define QSE_AWK_ISPRINT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_PRINT)
#define QSE_AWK_ISGRAPH(awk,c) QSE_CCLS_ISGRAPH((awk)->ccls,c) #define QSE_AWK_ISGRAPH(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_GRAPH)
#define QSE_AWK_ISCNTRL(awk,c) QSE_CCLS_ISCNTRL((awk)->ccls,c) #define QSE_AWK_ISCNTRL(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_CNTRL)
#define QSE_AWK_ISPUNCT(awk,c) QSE_CCLS_ISPUNCT((awk)->ccls,c) #define QSE_AWK_ISPUNCT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_PUNCT)
#define QSE_AWK_TOUPPER(awk,c) QSE_CCLS_TOUPPER((awk)->ccls,c) #define QSE_AWK_TOUPPER(awk,c) awk->prm.toccls(awk,c,QSE_CCLS_UPPER)
#define QSE_AWK_TOLOWER(awk,c) QSE_CCLS_TOLOWER((awk)->ccls,c) #define QSE_AWK_TOLOWER(awk,c) awk->prm.toccls(awk,c,QSE_CCLS_LOWER)
#define QSE_AWK_STRDUP(awk,str) (qse_strdup(str,(awk)->mmgr)) #define QSE_AWK_STRDUP(awk,str) (qse_strdup(str,(awk)->mmgr))
#define QSE_AWK_STRXDUP(awk,str,len) (qse_strxdup(str,len,(awk)->mmgr)) #define QSE_AWK_STRXDUP(awk,str,len) (qse_strxdup(str,len,(awk)->mmgr))
@ -85,10 +85,17 @@ struct qse_awk_tree_t
struct qse_awk_t struct qse_awk_t
{ {
/* memory manager */
qse_mmgr_t* mmgr; qse_mmgr_t* mmgr;
qse_ccls_t* ccls;
/* primitive functions */
qse_awk_prm_t prm; qse_awk_prm_t prm;
/* character classifier composed from primitive functions.
* it is used in calling some functions that require a character
* classifier */
qse_ccls_t ccls;
/* options */ /* options */
int option; int option;
@ -97,9 +104,6 @@ struct qse_awk_t
/* reverse word table */ /* reverse word table */
qse_map_t* rwtab; qse_map_t* rwtab;
/* regular expression processing routines */
qse_awk_rexfns_t* rexfns;
/* parse tree */ /* parse tree */
qse_awk_tree_t tree; qse_awk_tree_t tree;

View File

@ -961,7 +961,7 @@ int qse_awk_matchrex (
int err, x; int err, x;
x = qse_matchrex ( x = qse_matchrex (
awk->mmgr, awk->ccls, awk->rex.depth.max.match, awk->mmgr, &awk->ccls, awk->rex.depth.max.match,
code, option, str, len, match_ptr, match_len, &err); code, option, str, len, match_ptr, match_len, &err);
if (x < 0) *errnum = QSE_AWK_REXERRTOERR(err); if (x < 0) *errnum = QSE_AWK_REXERRTOERR(err);
return x; return x;

View File

@ -469,8 +469,6 @@ int qse_awk_parse (qse_awk_t* awk, qse_awk_sio_t* sio)
{ {
int n; int n;
QSE_ASSERTX (awk->ccls != QSE_NULL, "Call qse_setccls() first");
QSE_ASSERTX ( QSE_ASSERTX (
sio != QSE_NULL && sio->in != QSE_NULL, sio != QSE_NULL && sio->in != QSE_NULL,
"the source code input stream must be provided at least"); "the source code input stream must be provided at least");
@ -496,7 +494,7 @@ static int parse (qse_awk_t* awk)
QSE_ASSERT (awk->src.ios.in != QSE_NULL); QSE_ASSERT (awk->src.ios.in != QSE_NULL);
CLRERR (awk); CLRERR (awk);
op = awk->src.ios.in (awk, QSE_AWK_IO_OPEN, QSE_NULL, 0); op = awk->src.ios.in (awk, QSE_AWK_SIO_OPEN, QSE_NULL, 0);
if (op <= -1) if (op <= -1)
{ {
/* cannot open the source file. /* cannot open the source file.
@ -567,7 +565,7 @@ static int parse (qse_awk_t* awk)
#undef EXIT_PARSE #undef EXIT_PARSE
exit_parse: exit_parse:
if (n == 0) CLRERR (awk); if (n == 0) CLRERR (awk);
if (awk->src.ios.in (awk, QSE_AWK_IO_CLOSE, QSE_NULL, 0) != 0) if (awk->src.ios.in (awk, QSE_AWK_SIO_CLOSE, QSE_NULL, 0) != 0)
{ {
if (n == 0) if (n == 0)
{ {
@ -1421,7 +1419,7 @@ struct check_global_t
static qse_lda_walk_t check_global (qse_lda_t* lda, qse_size_t index, void* arg) static qse_lda_walk_t check_global (qse_lda_t* lda, qse_size_t index, void* arg)
{ {
qse_cstr_t tmp; qse_cstr_t tmp;
qse_awk_t* awk = *(qse_awk_t**)qse_lda_getxtn(lda); qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(lda);
check_global_t* cg = (check_global_t*)arg; check_global_t* cg = (check_global_t*)arg;
tmp.ptr = QSE_LDA_DPTR(lda,index); tmp.ptr = QSE_LDA_DPTR(lda,index);
@ -5276,7 +5274,7 @@ static int get_char (qse_awk_t* awk)
{ {
CLRERR (awk); CLRERR (awk);
n = awk->src.ios.in ( n = awk->src.ios.in (
awk, QSE_AWK_IO_READ, awk, QSE_AWK_SIO_READ,
awk->src.shared.buf, QSE_COUNTOF(awk->src.shared.buf) awk->src.shared.buf, QSE_COUNTOF(awk->src.shared.buf)
); );
if (n <= -1) if (n <= -1)
@ -5578,7 +5576,7 @@ static int deparse (qse_awk_t* awk)
awk->src.shared.buf_pos = 0; awk->src.shared.buf_pos = 0;
CLRERR (awk); CLRERR (awk);
op = awk->src.ios.out (awk, QSE_AWK_IO_OPEN, QSE_NULL, 0); op = awk->src.ios.out (awk, QSE_AWK_SIO_OPEN, QSE_NULL, 0);
if (op <= -1) if (op <= -1)
{ {
if (ISNOERR(awk)) SETERR (awk, QSE_AWK_ESOUTOP); if (ISNOERR(awk)) SETERR (awk, QSE_AWK_ESOUTOP);
@ -5783,7 +5781,7 @@ static int deparse (qse_awk_t* awk)
exit_deparse: exit_deparse:
if (n == 0) CLRERR (awk); if (n == 0) CLRERR (awk);
if (awk->src.ios.out (awk, QSE_AWK_IO_CLOSE, QSE_NULL, 0) != 0) if (awk->src.ios.out (awk, QSE_AWK_SIO_CLOSE, QSE_NULL, 0) != 0)
{ {
if (n == 0) if (n == 0)
{ {
@ -5880,7 +5878,7 @@ static int flush_out (qse_awk_t* awk)
CLRERR (awk); CLRERR (awk);
n = awk->src.ios.out ( n = awk->src.ios.out (
awk, QSE_AWK_IO_WRITE, awk, QSE_AWK_SIO_WRITE,
&awk->src.shared.buf[awk->src.shared.buf_pos], &awk->src.shared.buf[awk->src.shared.buf_pos],
awk->src.shared.buf_len - awk->src.shared.buf_pos awk->src.shared.buf_len - awk->src.shared.buf_pos
); );

View File

@ -146,7 +146,6 @@ int qse_awk_rtx_readio (
return -1; return -1;
} }
/*p->rtx = run;*/
p->type = (io_type | io_mask); p->type = (io_type | io_mask);
p->mode = io_mode; p->mode = io_mode;
p->handle = QSE_NULL; p->handle = QSE_NULL;
@ -161,7 +160,7 @@ int qse_awk_rtx_readio (
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
/* request to open the stream */ /* request to open the stream */
x = handler (run, QSE_AWK_IO_OPEN, p, QSE_NULL, 0); x = handler (run, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
if (x <= -1) if (x <= -1)
{ {
QSE_AWK_FREE (run->awk, p->name); QSE_AWK_FREE (run->awk, p->name);
@ -244,7 +243,7 @@ int qse_awk_rtx_readio (
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_READ, n = handler (run, QSE_AWK_RIO_READ,
p, p->in.buf, QSE_COUNTOF(p->in.buf)); p, p->in.buf, QSE_COUNTOF(p->in.buf));
if (n <= -1) if (n <= -1)
{ {
@ -503,7 +502,6 @@ int qse_awk_rtx_writeio_str (
return -1; return -1;
} }
/*p->rtx = run;*/
p->type = (io_type | io_mask); p->type = (io_type | io_mask);
p->mode = io_mode; p->mode = io_mode;
p->handle = QSE_NULL; p->handle = QSE_NULL;
@ -513,7 +511,7 @@ int qse_awk_rtx_writeio_str (
p->out.eos = QSE_FALSE; p->out.eos = QSE_FALSE;
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_OPEN, p, QSE_NULL, 0); n = handler (run, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
if (n <= -1) if (n <= -1)
{ {
QSE_AWK_FREE (run->awk, p->name); QSE_AWK_FREE (run->awk, p->name);
@ -557,7 +555,7 @@ int qse_awk_rtx_writeio_str (
while (len > 0) while (len > 0)
{ {
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_WRITE, p, str, len); n = handler (run, QSE_AWK_RIO_WRITE, p, str, len);
if (n <= -1) if (n <= -1)
{ {
if (run->errnum == QSE_AWK_ENOERR) if (run->errnum == QSE_AWK_ENOERR)
@ -612,7 +610,7 @@ int qse_awk_rtx_flushio (
(name == QSE_NULL || qse_strcmp(p->name,name) == 0)) (name == QSE_NULL || qse_strcmp(p->name,name) == 0))
{ {
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_FLUSH, p, QSE_NULL, 0); n = handler (run, QSE_AWK_RIO_FLUSH, p, QSE_NULL, 0);
if (n <= -1) if (n <= -1)
{ {
@ -682,7 +680,7 @@ int qse_awk_rtx_nextio_read (
} }
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_NEXT, p, QSE_NULL, 0); n = handler (run, QSE_AWK_RIO_NEXT, p, QSE_NULL, 0);
if (n <= -1) if (n <= -1)
{ {
if (run->errnum == QSE_AWK_ENOERR) if (run->errnum == QSE_AWK_ENOERR)
@ -760,7 +758,7 @@ int qse_awk_rtx_nextio_write (
} }
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_NEXT, p, QSE_NULL, 0); n = handler (run, QSE_AWK_RIO_NEXT, p, QSE_NULL, 0);
if (n <= -1) if (n <= -1)
{ {
if (run->errnum == QSE_AWK_ENOERR) if (run->errnum == QSE_AWK_ENOERR)
@ -819,7 +817,7 @@ int qse_awk_rtx_closio_read (
handler = run->rio.handler[p->type & MASK_CLEAR]; handler = run->rio.handler[p->type & MASK_CLEAR];
if (handler != QSE_NULL) if (handler != QSE_NULL)
{ {
if (handler (run, QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1) if (handler (run, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
{ {
/* this is not a run-time error.*/ /* this is not a run-time error.*/
qse_awk_rtx_seterror (run, QSE_AWK_EIOIMPL, 0, QSE_NULL); qse_awk_rtx_seterror (run, QSE_AWK_EIOIMPL, 0, QSE_NULL);
@ -879,7 +877,7 @@ int qse_awk_rtx_closio_write (
if (handler != QSE_NULL) if (handler != QSE_NULL)
{ {
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
if (handler (run, QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1) if (handler (run, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
{ {
if (run->errnum == QSE_AWK_ENOERR) if (run->errnum == QSE_AWK_ENOERR)
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL); qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL);
@ -919,7 +917,7 @@ int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
if (handler != QSE_NULL) if (handler != QSE_NULL)
{ {
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
if (handler (run, QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1) if (handler (run, QSE_AWK_RIO_CLOSE, p, QSE_NULL, 0) <= -1)
{ {
/* this is not a run-time error.*/ /* this is not a run-time error.*/
if (run->errnum == QSE_AWK_ENOERR) if (run->errnum == QSE_AWK_ENOERR)
@ -960,7 +958,7 @@ void qse_awk_rtx_cleario (qse_awk_rtx_t* run)
if (handler != QSE_NULL) if (handler != QSE_NULL)
{ {
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
n = handler (run, QSE_AWK_IO_CLOSE, run->rio.chain, QSE_NULL, 0); n = handler (run, QSE_AWK_RIO_CLOSE, run->rio.chain, QSE_NULL, 0);
if (n <= -1) if (n <= -1)
{ {
if (run->errnum == QSE_AWK_ENOERR) if (run->errnum == QSE_AWK_ENOERR)

View File

@ -29,7 +29,6 @@
#define IDXBUFSIZE 64 #define IDXBUFSIZE 64
#define MMGR(run) ((run)->awk->mmgr) #define MMGR(run) ((run)->awk->mmgr)
#define CCLS(run) ((run)->awk->ccls)
#define STACK_AT(run,n) ((run)->stack[(run)->stack_base+(n)]) #define STACK_AT(run,n) ((run)->stack[(run)->stack_base+(n)])
#define STACK_NARGS(run) (STACK_AT(run,3)) #define STACK_NARGS(run) (STACK_AT(run,3))
@ -617,7 +616,7 @@ int qse_awk_rtx_setofilename (
void* qse_awk_rtx_getxtn (qse_awk_rtx_t* rtx) void* qse_awk_rtx_getxtn (qse_awk_rtx_t* rtx)
{ {
return (void*)(rtx + 1); return QSE_XTN(rtx);
} }
qse_awk_t* qse_awk_rtx_getawk (qse_awk_rtx_t* rtx) qse_awk_t* qse_awk_rtx_getawk (qse_awk_rtx_t* rtx)
@ -627,7 +626,7 @@ qse_awk_t* qse_awk_rtx_getawk (qse_awk_rtx_t* rtx)
qse_mmgr_t* qse_awk_rtx_getmmgr (qse_awk_rtx_t* rtx) qse_mmgr_t* qse_awk_rtx_getmmgr (qse_awk_rtx_t* rtx)
{ {
return rtx->awk->mmgr; return MMGR(rtx);
} }
qse_map_t* qse_awk_rtx_getnvmap (qse_awk_rtx_t* rtx) qse_map_t* qse_awk_rtx_getnvmap (qse_awk_rtx_t* rtx)
@ -641,9 +640,10 @@ qse_awk_rtx_t* qse_awk_rtx_open (
{ {
qse_awk_rtx_t* rtx; qse_awk_rtx_t* rtx;
QSE_ASSERTX (awk->ccls != QSE_NULL, "Call qse_awk_setccls() first");
QSE_ASSERTX (awk->prm.pow != QSE_NULL, "Call qse_awk_setprm() first"); QSE_ASSERTX (awk->prm.pow != QSE_NULL, "Call qse_awk_setprm() first");
QSE_ASSERTX (awk->prm.sprintf != QSE_NULL, "Call qse_awk_setprm() first"); QSE_ASSERTX (awk->prm.sprintf != QSE_NULL, "Call qse_awk_setprm() first");
QSE_ASSERTX (awk->prm.isccls != QSE_NULL, "Call qse_awk_setprm() first");
QSE_ASSERTX (awk->prm.toccls != QSE_NULL, "Call qse_awk_setprm() first");
/* clear the awk error code */ /* clear the awk error code */
qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL); qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL);
@ -723,13 +723,13 @@ void qse_awk_rtx_setrcb (qse_awk_rtx_t* rtx, qse_awk_rcb_t* rcb)
static void free_namedval (qse_map_t* map, void* dptr, qse_size_t dlen) static void free_namedval (qse_map_t* map, void* dptr, qse_size_t dlen)
{ {
qse_awk_rtx_refdownval ( qse_awk_rtx_refdownval (
*(qse_awk_rtx_t**)qse_map_getxtn(map), dptr); *(qse_awk_rtx_t**)QSE_XTN(map), dptr);
} }
static void same_namedval (qse_map_t* map, void* dptr, qse_size_t dlen) static void same_namedval (qse_map_t* map, void* dptr, qse_size_t dlen)
{ {
qse_awk_rtx_refdownval_nofree ( qse_awk_rtx_refdownval_nofree (
*(qse_awk_rtx_t**)qse_map_getxtn(map), dptr); *(qse_awk_rtx_t**)QSE_XTN(map), dptr);
} }
static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio) static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
@ -796,7 +796,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL); qse_awk_seterror (awk, QSE_AWK_ENOMEM, 0, QSE_NULL);
return -1; return -1;
} }
*(qse_awk_rtx_t**)qse_map_getxtn(rtx->named) = rtx; *(qse_awk_rtx_t**)QSE_XTN(rtx->named) = rtx;
qse_map_setcopier (rtx->named, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (rtx->named, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
qse_map_setfreeer (rtx->named, QSE_MAP_VAL, free_namedval); qse_map_setfreeer (rtx->named, QSE_MAP_VAL, free_namedval);
qse_map_setkeeper (rtx->named, same_namedval); qse_map_setkeeper (rtx->named, same_namedval);
@ -1430,16 +1430,21 @@ static int run_bpae_loop (qse_awk_rtx_t* rtx)
* for BEGIN/pattern action/END block execution.*/ * for BEGIN/pattern action/END block execution.*/
nargs = (qse_size_t)STACK_NARGS(rtx); nargs = (qse_size_t)STACK_NARGS(rtx);
QSE_ASSERT (nargs == 0); QSE_ASSERT (nargs == 0);
for (i = 0; i < nargs; i++) qse_awk_rtx_refdownval (rtx, STACK_ARG(rtx,i)); for (i = 0; i < nargs; i++)
qse_awk_rtx_refdownval (rtx, STACK_ARG(rtx,i));
/* get the return value in the current stack frame */ /* get the return value in the current stack frame */
v = STACK_RETVAL(rtx); v = STACK_RETVAL(rtx);
if (ret == 0)
if (rtx->rcb.on_exit != QSE_NULL)
{ {
if (rtx->rcb.on_exit != QSE_NULL) /* we call the on_exit handler regardless of ret.
rtx->rcb.on_exit (rtx, v, rtx->rcb.data); * the return value passed is the global return value
* in the stack. */
rtx->rcb.on_exit (rtx, v, rtx->rcb.data);
} }
/* end the life of the gbl return value */
/* end the life of the global return value */
qse_awk_rtx_refdownval (rtx, v); qse_awk_rtx_refdownval (rtx, v);
return ret; return ret;
@ -4042,7 +4047,7 @@ static int __cmp_int_str (
str, len, str, len,
((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->ptr,
((qse_awk_val_str_t*)right)->len, ((qse_awk_val_str_t*)right)->len,
CCLS(run)); &run->awk->ccls);
} }
else else
{ {
@ -4114,7 +4119,7 @@ static int __cmp_real_str (
str, len, str, len,
((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->ptr,
((qse_awk_val_str_t*)right)->len, ((qse_awk_val_str_t*)right)->len,
CCLS(run)); &run->awk->ccls);
} }
else else
{ {
@ -4158,7 +4163,8 @@ static int __cmp_str_str (
if (run->gbl.ignorecase) if (run->gbl.ignorecase)
{ {
n = qse_strxncasecmp ( n = qse_strxncasecmp (
ls->ptr, ls->len, rs->ptr, rs->len, CCLS(run)); ls->ptr, ls->len, rs->ptr, rs->len,
&run->awk->ccls);
} }
else else
{ {

View File

@ -93,6 +93,20 @@ static int custom_awk_sprintf (
return n; return n;
} }
static qse_bool_t custom_awk_isccls (
qse_awk_t* awk, qse_cint_t c, qse_ccls_id_t id)
{
qse_ccls_t* ccls = QSE_CCLS_GETDFL();
return ccls->is (ccls->data, c, id);
}
static qse_cint_t custom_awk_toccls (
qse_awk_t* awk, qse_cint_t c, qse_ccls_id_t id)
{
qse_ccls_t* ccls = QSE_CCLS_GETDFL();
return ccls->to (ccls->data, c, id);
}
static int add_functions (qse_awk_t* awk); static int add_functions (qse_awk_t* awk);
qse_awk_t* qse_awk_opensimple (void) qse_awk_t* qse_awk_opensimple (void)
@ -101,23 +115,19 @@ qse_awk_t* qse_awk_opensimple (void)
qse_awk_prm_t prm; qse_awk_prm_t prm;
xtn_t* xtn; xtn_t* xtn;
prm.pow = custom_awk_pow;
prm.sprintf = custom_awk_sprintf;
prm.isccls = custom_awk_isccls;
prm.toccls = custom_awk_toccls;
/* create an object */ /* create an object */
awk = qse_awk_open ( awk = qse_awk_open (QSE_MMGR_GETDFL(), QSE_SIZEOF(xtn_t), &prm);
QSE_MMGR_GETDFL(),
QSE_SIZEOF(xtn_t),
QSE_CCLS_GETDFL()
);
if (awk == QSE_NULL) return QSE_NULL; if (awk == QSE_NULL) return QSE_NULL;
/* initialize extension */ /* initialize extension */
xtn = (xtn_t*) qse_awk_getxtn (awk); xtn = (xtn_t*) QSE_XTN (awk);
QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t)); QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t));
/* set primitive functions */
prm.pow = custom_awk_pow;
prm.sprintf = custom_awk_sprintf;
qse_awk_setprm (awk, &prm);
/* set default options */ /* set default options */
qse_awk_setoption (awk, qse_awk_setoption (awk,
QSE_AWK_IMPLICIT | QSE_AWK_RIO | QSE_AWK_NEWLINE | QSE_AWK_IMPLICIT | QSE_AWK_RIO | QSE_AWK_NEWLINE |
@ -135,11 +145,13 @@ qse_awk_t* qse_awk_opensimple (void)
/*** PARSESIMPLE ***/ /*** PARSESIMPLE ***/
static qse_ssize_t sf_in (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t size) static qse_ssize_t sf_in (
qse_awk_t* awk, qse_awk_sio_cmd_t cmd,
qse_char_t* data, qse_size_t size)
{ {
xtn_t* xtn = qse_awk_getxtn (awk); xtn_t* xtn = QSE_XTN (awk);
if (cmd == QSE_AWK_IO_OPEN) if (cmd == QSE_AWK_SIO_OPEN)
{ {
if (xtn->s.in.type == QSE_AWK_PARSE_FILES) if (xtn->s.in.type == QSE_AWK_PARSE_FILES)
{ {
@ -167,7 +179,7 @@ static qse_ssize_t sf_in (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t
return 1; return 1;
} }
else if (cmd == QSE_AWK_IO_CLOSE) else if (cmd == QSE_AWK_SIO_CLOSE)
{ {
if (xtn->s.in.handle != QSE_NULL && if (xtn->s.in.handle != QSE_NULL &&
xtn->s.in.handle != qse_sio_in && xtn->s.in.handle != qse_sio_in &&
@ -179,7 +191,7 @@ static qse_ssize_t sf_in (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t
return 0; return 0;
} }
else if (cmd == QSE_AWK_IO_READ) else if (cmd == QSE_AWK_SIO_READ)
{ {
qse_ssize_t n = 0; qse_ssize_t n = 0;
@ -231,11 +243,13 @@ static qse_ssize_t sf_in (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t
return -1; return -1;
} }
static qse_ssize_t sf_out (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t size) static qse_ssize_t sf_out (
qse_awk_t* awk, qse_awk_sio_cmd_t cmd,
qse_char_t* data, qse_size_t size)
{ {
xtn_t* xtn = qse_awk_getxtn (awk); xtn_t* xtn = QSE_XTN (awk);
if (cmd == QSE_AWK_IO_OPEN) if (cmd == QSE_AWK_SIO_OPEN)
{ {
if (xtn->s.out.file[0] == QSE_T('\0')) if (xtn->s.out.file[0] == QSE_T('\0'))
{ {
@ -254,7 +268,7 @@ static qse_ssize_t sf_out (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t
return 1; return 1;
} }
else if (cmd == QSE_AWK_IO_CLOSE) else if (cmd == QSE_AWK_SIO_CLOSE)
{ {
if (xtn->s.out.handle != QSE_NULL) if (xtn->s.out.handle != QSE_NULL)
{ {
@ -269,7 +283,7 @@ static qse_ssize_t sf_out (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t
return 0; return 0;
} }
else if (cmd == QSE_AWK_IO_WRITE) else if (cmd == QSE_AWK_SIO_WRITE)
{ {
/* /*
qse_size_t left = size; qse_size_t left = size;
@ -302,7 +316,7 @@ int qse_awk_parsesimple (
qse_awk_t* awk, int ist, const void* isp, const qse_char_t* osf) qse_awk_t* awk, int ist, const void* isp, const qse_char_t* osf)
{ {
qse_awk_sio_t sio; qse_awk_sio_t sio;
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
if (isp == QSE_NULL) if (isp == QSE_NULL)
{ {
@ -340,12 +354,12 @@ int qse_awk_parsesimple (
/*** RUNSIMPLE ***/ /*** RUNSIMPLE ***/
static qse_ssize_t awk_rio_pipe ( static qse_ssize_t awk_rio_pipe (
qse_awk_rtx_t* rtx, int cmd, qse_awk_riod_t* riod, qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
qse_char_t* data, qse_size_t size) qse_char_t* data, qse_size_t size)
{ {
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_RIO_OPEN:
{ {
qse_pio_t* handle; qse_pio_t* handle;
int flags; int flags;
@ -382,7 +396,7 @@ static qse_ssize_t awk_rio_pipe (
return 1; return 1;
} }
case QSE_AWK_IO_CLOSE: case QSE_AWK_RIO_CLOSE:
{ {
/*dprint (QSE_T("closing %s of type (pipe) %d\n"), riod->name, riod->type);*/ /*dprint (QSE_T("closing %s of type (pipe) %d\n"), riod->name, riod->type);*/
qse_pio_close ((qse_pio_t*)riod->handle); qse_pio_close ((qse_pio_t*)riod->handle);
@ -390,7 +404,7 @@ static qse_ssize_t awk_rio_pipe (
return 0; return 0;
} }
case QSE_AWK_IO_READ: case QSE_AWK_RIO_READ:
{ {
return qse_pio_read ( return qse_pio_read (
(qse_pio_t*)riod->handle, (qse_pio_t*)riod->handle,
@ -400,7 +414,7 @@ static qse_ssize_t awk_rio_pipe (
); );
} }
case QSE_AWK_IO_WRITE: case QSE_AWK_RIO_WRITE:
{ {
return qse_pio_write ( return qse_pio_write (
(qse_pio_t*)riod->handle, (qse_pio_t*)riod->handle,
@ -410,13 +424,13 @@ static qse_ssize_t awk_rio_pipe (
); );
} }
case QSE_AWK_IO_FLUSH: case QSE_AWK_RIO_FLUSH:
{ {
/*if (riod->mode == QSE_AWK_RIO_PIPE_READ) return -1;*/ /*if (riod->mode == QSE_AWK_RIO_PIPE_READ) return -1;*/
return qse_pio_flush ((qse_pio_t*)riod->handle, QSE_PIO_IN); return qse_pio_flush ((qse_pio_t*)riod->handle, QSE_PIO_IN);
} }
case QSE_AWK_IO_NEXT: case QSE_AWK_RIO_NEXT:
{ {
return -1; return -1;
} }
@ -426,12 +440,12 @@ static qse_ssize_t awk_rio_pipe (
} }
static qse_ssize_t awk_rio_file ( static qse_ssize_t awk_rio_file (
qse_awk_rtx_t* rtx, int cmd, qse_awk_riod_t* riod, qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
qse_char_t* data, qse_size_t size) qse_char_t* data, qse_size_t size)
{ {
switch (cmd) switch (cmd)
{ {
case QSE_AWK_IO_OPEN: case QSE_AWK_RIO_OPEN:
{ {
qse_fio_t* handle; qse_fio_t* handle;
int flags; int flags;
@ -477,7 +491,7 @@ static qse_ssize_t awk_rio_file (
return 1; return 1;
} }
case QSE_AWK_IO_CLOSE: case QSE_AWK_RIO_CLOSE:
{ {
/*dprint (QSE_T("closing %s of type %d (file)\n"), riod->name, riod->type);*/ /*dprint (QSE_T("closing %s of type %d (file)\n"), riod->name, riod->type);*/
qse_fio_close ((qse_fio_t*)riod->handle); qse_fio_close ((qse_fio_t*)riod->handle);
@ -485,7 +499,7 @@ static qse_ssize_t awk_rio_file (
return 0; return 0;
} }
case QSE_AWK_IO_READ: case QSE_AWK_RIO_READ:
{ {
return qse_fio_read ( return qse_fio_read (
(qse_fio_t*)riod->handle, (qse_fio_t*)riod->handle,
@ -494,7 +508,7 @@ static qse_ssize_t awk_rio_file (
); );
} }
case QSE_AWK_IO_WRITE: case QSE_AWK_RIO_WRITE:
{ {
return qse_fio_write ( return qse_fio_write (
(qse_fio_t*)riod->handle, (qse_fio_t*)riod->handle,
@ -503,12 +517,12 @@ static qse_ssize_t awk_rio_file (
); );
} }
case QSE_AWK_IO_FLUSH: case QSE_AWK_RIO_FLUSH:
{ {
return qse_fio_flush ((qse_fio_t*)riod->handle); return qse_fio_flush ((qse_fio_t*)riod->handle);
} }
case QSE_AWK_IO_NEXT: case QSE_AWK_RIO_NEXT:
{ {
return -1; return -1;
} }
@ -520,7 +534,7 @@ static qse_ssize_t awk_rio_file (
static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod) static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod)
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
/*dprint (QSE_T("opening console[%s] of type %x\n"), riod->name, riod->type);*/ /*dprint (QSE_T("opening console[%s] of type %x\n"), riod->name, riod->type);*/
@ -593,16 +607,16 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod)
} }
static qse_ssize_t awk_rio_console ( static qse_ssize_t awk_rio_console (
qse_awk_rtx_t* rtx, int cmd, qse_awk_riod_t* riod, qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
qse_char_t* data, qse_size_t size) qse_char_t* data, qse_size_t size)
{ {
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
if (cmd == QSE_AWK_IO_OPEN) if (cmd == QSE_AWK_RIO_OPEN)
{ {
return open_rio_console (rtx, riod); return open_rio_console (rtx, riod);
} }
else if (cmd == QSE_AWK_IO_CLOSE) else if (cmd == QSE_AWK_RIO_CLOSE)
{ {
/*dprint (QSE_T("closing console of type %x\n"), riod->type);*/ /*dprint (QSE_T("closing console of type %x\n"), riod->type);*/
@ -616,7 +630,7 @@ static qse_ssize_t awk_rio_console (
return 0; return 0;
} }
else if (cmd == QSE_AWK_IO_READ) else if (cmd == QSE_AWK_RIO_READ)
{ {
qse_ssize_t n; qse_ssize_t n;
@ -697,7 +711,7 @@ static qse_ssize_t awk_rio_console (
return n; return n;
} }
else if (cmd == QSE_AWK_IO_WRITE) else if (cmd == QSE_AWK_RIO_WRITE)
{ {
return qse_sio_putsn ( return qse_sio_putsn (
(qse_sio_t*)riod->handle, (qse_sio_t*)riod->handle,
@ -705,11 +719,11 @@ static qse_ssize_t awk_rio_console (
size size
); );
} }
else if (cmd == QSE_AWK_IO_FLUSH) else if (cmd == QSE_AWK_RIO_FLUSH)
{ {
return qse_sio_flush ((qse_sio_t*)riod->handle); return qse_sio_flush ((qse_sio_t*)riod->handle);
} }
else if (cmd == QSE_AWK_IO_NEXT) else if (cmd == QSE_AWK_RIO_NEXT)
{ {
int n; int n;
qse_sio_t* fp = (qse_sio_t*)riod->handle; qse_sio_t* fp = (qse_sio_t*)riod->handle;
@ -758,7 +772,7 @@ qse_awk_rtx_t* qse_awk_rtx_opensimple (qse_awk_t* awk, qse_char_t** icf)
); );
if (rtx == QSE_NULL) return QSE_NULL; if (rtx == QSE_NULL) return QSE_NULL;
rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx); rxtn = (rxtn_t*) QSE_XTN (rtx);
QSE_MEMSET (rxtn, 0, QSE_SIZEOF(rxtn_t)); QSE_MEMSET (rxtn, 0, QSE_SIZEOF(rxtn_t));
if (qse_gettime (&now) == -1) rxtn->seed = 0; if (qse_gettime (&now) == -1) rxtn->seed = 0;
@ -1061,7 +1075,7 @@ static int fnc_srand (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
unsigned int prev; unsigned int prev;
rxtn_t* rxtn; rxtn_t* rxtn;
rxtn = (rxtn_t*)qse_awk_rtx_getxtn (run); rxtn = (rxtn_t*) QSE_XTN (run);
nargs = qse_awk_rtx_getnargs (run); nargs = qse_awk_rtx_getnargs (run);
QSE_ASSERT (nargs == 0 || nargs == 1); QSE_ASSERT (nargs == 0 || nargs == 1);

View File

@ -384,68 +384,41 @@ qse_awk_val_t* qse_awk_rtx_makerexval (
qse_awk_rtx_t* run, const qse_char_t* buf, qse_size_t len, void* code) qse_awk_rtx_t* run, const qse_char_t* buf, qse_size_t len, void* code)
{ {
qse_awk_val_rex_t* val; qse_awk_val_rex_t* val;
qse_size_t totsz;
val = (qse_awk_val_rex_t*) QSE_AWK_ALLOC ( /* the regular expression value holds:
run->awk, QSE_SIZEOF(qse_awk_val_rex_t) + * header
(QSE_SIZEOF(*buf)*len+1) + QSE_REX_LEN(code)); * a raw string plus with added a terminating '\0'
if (val == QSE_NULL) return QSE_NULL; * a compiled regular expression
* the total size is just large enough for all these.
*/
totsz = QSE_SIZEOF(qse_awk_val_rex_t) +
(QSE_SIZEOF(*buf) * (len + 1)) +
QSE_REX_LEN(code);
val = (qse_awk_val_rex_t*) QSE_AWK_ALLOC (run->awk, totsz);
if (val == QSE_NULL)
{
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
return QSE_NULL;
}
val->type = QSE_AWK_VAL_REX; val->type = QSE_AWK_VAL_REX;
val->ref = 0; val->ref = 0;
val->len = len; val->len = len;
/*
val->ptr = QSE_AWK_STRXDUP (run->awk, buf, len);
if (val->ptr == QSE_NULL)
{
QSE_AWK_FREE (run->awk, val);
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
return QSE_NULL;
}*/
val->ptr = (qse_char_t*)(val + 1); val->ptr = (qse_char_t*)(val + 1);
qse_strncpy (val->ptr, buf, len); qse_strncpy (val->ptr, buf, len);
/*
val->code = QSE_AWK_ALLOC (run->awk, QSE_REX_LEN(code));
if (val->code == QSE_NULL)
{
QSE_AWK_FREE (run->awk, val->ptr);
QSE_AWK_FREE (run->awk, val);
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
return QSE_NULL;
}
*/
val->code = val->ptr + len + 1; val->code = val->ptr + len + 1;
QSE_MEMCPY (val->code, code, QSE_REX_LEN(code)); QSE_MEMCPY (val->code, code, QSE_REX_LEN(code));
return (qse_awk_val_t*)val; return (qse_awk_val_t*)val;
} }
/* CHECK */
/*
static void free_mapval (void* run, void* v)
{
#ifdef DEBUG_VAL
qse_dprintf (QSE_T("refdown in map free..."));
qse_awk_dprintval (run, v);
qse_dprintf (QSE_T("\n"));
#endif
qse_awk_rtx_refdownval (run, v);
}
static void same_mapval (void* run, void* v)
{
#ifdef DEBUG_VAL
qse_dprintf (QSE_T("refdown nofree in map free..."));
qse_awk_dprintval (run, v);
qse_dprintf (QSE_T("\n"));
#endif
qse_awk_rtx_refdownval_nofree (run, v);
}
*/
static void free_mapval (qse_map_t* map, void* dptr, qse_size_t dlen) static void free_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
{ {
qse_awk_rtx_t* run = *(qse_awk_rtx_t**)qse_map_getxtn(map); qse_awk_rtx_t* run = *(qse_awk_rtx_t**)QSE_XTN(map);
#ifdef DEBUG_VAL #ifdef DEBUG_VAL
qse_dprintf (QSE_T("refdown in map free...")); qse_dprintf (QSE_T("refdown in map free..."));
@ -458,7 +431,7 @@ static void free_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
static void same_mapval (qse_map_t* map, void* dptr, qse_size_t dlen) static void same_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
{ {
qse_awk_rtx_t* run = *(qse_awk_rtx_t**)qse_map_getxtn(map); qse_awk_rtx_t* run = *(qse_awk_rtx_t**)QSE_XTN(map);
#ifdef DEBUG_VAL #ifdef DEBUG_VAL
qse_dprintf (QSE_T("refdown nofree in map free...")); qse_dprintf (QSE_T("refdown nofree in map free..."));
qse_awk_dprintval (run, dptr); qse_awk_dprintval (run, dptr);
@ -466,7 +439,6 @@ static void same_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
#endif #endif
qse_awk_rtx_refdownval_nofree (run, dptr); qse_awk_rtx_refdownval_nofree (run, dptr);
} }
/* END CHECK */
qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* run) qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* run)
{ {
@ -516,7 +488,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* run)
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM); qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
return QSE_NULL; return QSE_NULL;
} }
*(qse_awk_rtx_t**)qse_map_getxtn(val->map) = run; *(qse_awk_rtx_t**)QSE_XTN(val->map) = run;
/* the key is copied inline into a pair and is freed when the pair /* the key is copied inline into a pair and is freed when the pair
* is destroyed */ * is destroyed */
@ -569,7 +541,7 @@ qse_awk_val_t* qse_awk_rtx_makerefval (qse_awk_rtx_t* run, int id, qse_awk_val_t
((val) >= (qse_awk_val_t*)&awk_int[0] && \ ((val) >= (qse_awk_val_t*)&awk_int[0] && \
(val) <= (qse_awk_val_t*)&awk_int[QSE_COUNTOF(awk_int)-1])) (val) <= (qse_awk_val_t*)&awk_int[QSE_COUNTOF(awk_int)-1]))
qse_bool_t qse_awk_isstaticval (qse_awk_rtx_t* rtx, qse_awk_val_t* val) qse_bool_t qse_awk_rtx_isstaticval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
{ {
return IS_STATICVAL(val); return IS_STATICVAL(val);
} }
@ -1151,7 +1123,7 @@ static qse_map_walk_t print_pair (
{ {
qse_awk_rtx_t* run = (qse_awk_rtx_t*)arg; qse_awk_rtx_t* run = (qse_awk_rtx_t*)arg;
QSE_ASSERT (run == *(qse_awk_rtx_t**)qse_map_getxtn(map)); QSE_ASSERT (run == *(qse_awk_rtx_t**)QSE_XTN(map));
DPRINTF (DCUSTOM, QSE_T(" %.*s=>"), DPRINTF (DCUSTOM, QSE_T(" %.*s=>"),
(int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair)); (int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair));

View File

@ -34,7 +34,7 @@ static qse_bool_t is_graph (qse_cint_t c) { return isgraph(c); }
static qse_bool_t is_cntrl (qse_cint_t c) { return iscntrl(c); } static qse_bool_t is_cntrl (qse_cint_t c) { return iscntrl(c); }
static qse_bool_t is_punct (qse_cint_t c) { return ispunct(c); } static qse_bool_t is_punct (qse_cint_t c) { return ispunct(c); }
qse_bool_t qse_ccls_is (qse_cint_t c, qse_ccls_type_t type) qse_bool_t qse_ccls_is (qse_cint_t c, qse_ccls_id_t type)
{ {
/* TODO: use GetStringTypeW/A for WIN32 to implement these */ /* TODO: use GetStringTypeW/A for WIN32 to implement these */
@ -54,11 +54,11 @@ qse_bool_t qse_ccls_is (qse_cint_t c, qse_ccls_type_t type)
}; };
QSE_ASSERTX (type >= QSE_CCLS_UPPER && type <= QSE_CCLS_PUNCT, QSE_ASSERTX (type >= QSE_CCLS_UPPER && type <= QSE_CCLS_PUNCT,
"The character type should be one of qse_ccls_type_t values"); "The character type should be one of qse_ccls_id_t values");
return f[type] (c); return f[type] (c);
} }
qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_type_t type) qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_id_t type)
{ {
QSE_ASSERTX (type >= QSE_CCLS_UPPER && type <= QSE_CCLS_LOWER, QSE_ASSERTX (type >= QSE_CCLS_UPPER && type <= QSE_CCLS_LOWER,
"The character type should be one of QSE_CCLS_UPPER and QSE_CCLS_LOWER"); "The character type should be one of QSE_CCLS_UPPER and QSE_CCLS_LOWER");
@ -72,7 +72,7 @@ qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_type_t type)
#include <wctype.h> #include <wctype.h>
qse_bool_t qse_ccls_is (qse_cint_t c, qse_ccls_type_t type) qse_bool_t qse_ccls_is (qse_cint_t c, qse_ccls_id_t type)
{ {
static const char* name[] = static const char* name[] =
{ {
@ -105,13 +105,13 @@ qse_bool_t qse_ccls_is (qse_cint_t c, qse_ccls_type_t type)
}; };
QSE_ASSERTX (type >= QSE_CCLS_UPPER && type <= QSE_CCLS_PUNCT, QSE_ASSERTX (type >= QSE_CCLS_UPPER && type <= QSE_CCLS_PUNCT,
"The character type should be one of qse_ccls_type_t values"); "The character type should be one of qse_ccls_id_t values");
if (desc[type] == (wctype_t)0) desc[type] = wctype(name[type]); if (desc[type] == (wctype_t)0) desc[type] = wctype(name[type]);
return iswctype (c, desc[type]); return iswctype (c, desc[type]);
} }
qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_type_t type) qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_id_t type)
{ {
static const char* name[] = static const char* name[] =
{ {
@ -136,12 +136,12 @@ qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_type_t type)
#error unsupported character type #error unsupported character type
#endif #endif
static qse_bool_t ccls_is (void* data, qse_cint_t c, qse_ccls_type_t type) static qse_bool_t ccls_is (void* data, qse_cint_t c, qse_ccls_id_t type)
{ {
return qse_ccls_is (c, type); return qse_ccls_is (c, type);
} }
static qse_cint_t ccls_to (void* data, qse_cint_t c, qse_ccls_type_t type) static qse_cint_t ccls_to (void* data, qse_cint_t c, qse_ccls_id_t type)
{ {
return qse_ccls_to (c, type); return qse_ccls_to (c, type);
} }