This commit is contained in:
hyung-hwan 2008-07-21 06:42:39 +00:00
parent a665af8f49
commit c995006f78
11 changed files with 178 additions and 406 deletions

View File

@ -93,80 +93,12 @@ static void custom_awk_free (void* custom, void* ptr)
#endif #endif
} }
/* custom character class functions */
static ase_bool_t custom_awk_isupper (void* custom, ase_cint_t c)
{
return ase_isupper (c);
}
static ase_bool_t custom_awk_islower (void* custom, ase_cint_t c)
{
return ase_islower (c);
}
static ase_bool_t custom_awk_isalpha (void* custom, ase_cint_t c)
{
return ase_isalpha (c);
}
static ase_bool_t custom_awk_isdigit (void* custom, ase_cint_t c)
{
return ase_isdigit (c);
}
static ase_bool_t custom_awk_isxdigit (void* custom, ase_cint_t c)
{
return ase_isxdigit (c);
}
static ase_bool_t custom_awk_isalnum (void* custom, ase_cint_t c)
{
return ase_isalnum (c);
}
static ase_bool_t custom_awk_isspace (void* custom, ase_cint_t c)
{
return ase_isspace (c);
}
static ase_bool_t custom_awk_isprint (void* custom, ase_cint_t c)
{
return ase_isprint (c);
}
static ase_bool_t custom_awk_isgraph (void* custom, ase_cint_t c)
{
return ase_isgraph (c);
}
static ase_bool_t custom_awk_iscntrl (void* custom, ase_cint_t c)
{
return ase_iscntrl (c);
}
static ase_bool_t custom_awk_ispunct (void* custom, ase_cint_t c)
{
return ase_ispunct (c);
}
static ase_cint_t custom_awk_toupper (void* custom, ase_cint_t c)
{
return ase_toupper (c);
}
static ase_cint_t custom_awk_tolower (void* custom, ase_cint_t c)
{
return ase_tolower (c);
}
/* custom miscellaneous functions */ /* custom miscellaneous functions */
static ase_real_t custom_awk_pow (void* custom, ase_real_t x, ase_real_t y) static ase_real_t custom_awk_pow (void* custom, ase_real_t x, ase_real_t y)
{ {
return pow (x, y); return pow (x, y);
} }
static int custom_awk_sprintf ( static int custom_awk_sprintf (
void* custom, ase_char_t* buf, ase_size_t size, void* custom, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...) const ase_char_t* fmt, ...)
@ -982,34 +914,12 @@ static int bfn_sleep (
return 0; return 0;
} }
static int awk_main (int argc, ase_char_t* argv[]) #if 0
static void handle_args (argc, argv)
{ {
ase_awk_t* awk; int i;
ase_awk_srcios_t srcios;
ase_awk_prmfns_t prmfns;
struct awk_src_io src_io = { NULL, NULL };
int opt, i, file_count = 0;
#ifdef _WIN32
struct mmgr_data_t mmgr_data;
#endif
const ase_char_t* mfn = ASE_NULL;
int mode = 0;
int runarg_count = 0;
ase_awk_runarg_t runarg[128];
int deparse = 0;
opt = ASE_AWK_IMPLICIT |
ASE_AWK_EXTIO |
ASE_AWK_NEWLINE |
ASE_AWK_BASEONE |
ASE_AWK_PABLOCK;
if (argc <= 1)
{
print_usage (argv[0]);
return -1;
}
if (argc <= 1) return -1;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
@ -1116,6 +1026,47 @@ static int awk_main (int argc, ase_char_t* argv[])
} }
} }
}
#endif
typedef struct extension_t
{
ase_awk_prmfns_t prmfns;
}
extension_t;
static int awk_main (int argc, ase_char_t* argv[])
{
ase_awk_t* awk;
ase_mmgr_t mmgr;
extension_t* extension;
ase_awk_srcios_t srcios;
struct awk_src_io src_io = { NULL, NULL };
int opt, i, file_count = 0;
#ifdef _WIN32
struct mmgr_data_t mmgr_data;
#endif
const ase_char_t* mfn = ASE_NULL;
int mode = 0;
int runarg_count = 0;
ase_awk_runarg_t runarg[128];
int deparse = 0;
opt = ASE_AWK_IMPLICIT |
ASE_AWK_EXTIO |
ASE_AWK_NEWLINE |
ASE_AWK_BASEONE |
ASE_AWK_PABLOCK;
#if 0
if (handle_args (argc, argv) == -1)
{
print_usage (argv[0]);
return -1;
}
#endif
infiles[file_count] = ASE_NULL; infiles[file_count] = ASE_NULL;
runarg[runarg_count].ptr = NULL; runarg[runarg_count].ptr = NULL;
runarg[runarg_count].len = 0; runarg[runarg_count].len = 0;
@ -1126,11 +1077,10 @@ static int awk_main (int argc, ase_char_t* argv[])
return -1; return -1;
} }
memset (&prmfns, 0, ASE_SIZEOF(prmfns)); memset (&mmgr, 0, ASE_SIZEOF(mmgr));
mmgr.malloc = custom_awk_malloc;
prmfns.mmgr.malloc = custom_awk_malloc; mmgr.realloc = custom_awk_realloc;
prmfns.mmgr.realloc = custom_awk_realloc; mmgr.free = custom_awk_free;
prmfns.mmgr.free = custom_awk_free;
#ifdef _WIN32 #ifdef _WIN32
mmgr_data.heap = HeapCreate (0, 1000000, 1000000); mmgr_data.heap = HeapCreate (0, 1000000, 1000000);
if (mmgr_data.heap == NULL) if (mmgr_data.heap == NULL)
@ -1139,20 +1089,12 @@ static int awk_main (int argc, ase_char_t* argv[])
return -1; return -1;
} }
prmfns.mmgr.custom_data = &mmgr_data; mmgr.custom_data = &mmgr_data;
#else #else
prmfns.mmgr.custom_data = NULL; mmgr.custom_data = ASE_NULL;
#endif #endif
/*prmfns.mmgr = *ASE_GETMMGR();*/ awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t));
prmfns.ccls = *ASE_GETCCLS();
prmfns.misc.pow = custom_awk_pow;
prmfns.misc.sprintf = custom_awk_sprintf;
prmfns.misc.dprintf = custom_awk_dprintf;
prmfns.misc.custom_data = NULL;
awk = ase_awk_open(&prmfns);
if (awk == ASE_NULL) if (awk == ASE_NULL)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -1164,6 +1106,17 @@ static int awk_main (int argc, ase_char_t* argv[])
app_awk = awk; app_awk = awk;
extension = (extension_t*) ase_awk_getextension (awk);
//extension->mmgr = mmgr;
extension->prmfns.pow = custom_awk_pow;
extension->prmfns.sprintf = custom_awk_sprintf;
extension->prmfns.dprintf = custom_awk_dprintf;
extension->prmfns.custom_data = ASE_NULL;
ase_awk_setccls (awk, ASE_GETCCLS());
ase_awk_setprmfns (awk, &extension->prmfns);
if (ase_awk_addfunc (awk, if (ase_awk_addfunc (awk,
ASE_T("sleep"), 5, 0, ASE_T("sleep"), 5, 0,
1, 1, ASE_NULL, bfn_sleep) == ASE_NULL) 1, 1, ASE_NULL, bfn_sleep) == ASE_NULL)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h 270 2008-07-20 05:53:29Z baconevi $ * $Id: awk.h 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -65,18 +65,12 @@ struct ase_awk_extio_t
struct ase_awk_prmfns_t struct ase_awk_prmfns_t
{ {
ase_ccls_t ccls;
struct
{
/* utilities */
ase_awk_pow_t pow; /* required */ ase_awk_pow_t pow; /* required */
ase_awk_sprintf_t sprintf; /* required */ ase_awk_sprintf_t sprintf; /* required */
ase_awk_dprintf_t dprintf; /* required in the debug mode */ ase_awk_dprintf_t dprintf; /* required in the debug mode */
/* user-defined data passed to the functions above */ /* user-defined data passed to the functions above */
void* custom_data; /* optional */ void* custom_data; /* optional */
} misc;
}; };
struct ase_awk_srcios_t struct ase_awk_srcios_t
@ -609,7 +603,7 @@ ase_awk_t* ase_awk_open (
/* memory manager */ /* memory manager */
ase_mmgr_t* mmgr, ase_mmgr_t* mmgr,
/* size of extension area to allocate in bytes */ /* size of extension area to allocate in bytes */
unsigned int extension; unsigned int extension
); );
/* /*
@ -662,6 +656,16 @@ void ase_awk_setccls (
ase_ccls_t* ccls ase_ccls_t* ccls
); );
/*
* set primitive functions
*/
void ase_awk_setprmfns (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk,
/* the pointer to a primitive function structure */
ase_awk_prmfns_t* prmfns
);
/* /*
* clear an ase_awk_t instance * clear an ase_awk_t instance
* *
@ -676,35 +680,6 @@ int ase_awk_clear (
ase_awk_t* awk ase_awk_t* awk
); );
/*
* associate the user-specified data with an ase_awk_t instance
*
* The ase_awk_setassocdata() function is used to associate custom data
* with an ase_awk_t instance. The associated data can be retrieved with
* the ase_awk_getassocdata() function.
*/
void ase_awk_setassocdata (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk,
/* the pointer to user-specified data */
void* data
);
/*
* return the user-specified data associated with an ase_awk_t instance
*
* The ase_awk_getassocdata() function is used to retrieve custom data
* specified by a user with the ase_awk_setassocdata() function.
*
* RETURNS the pointer to the user-specified data through ase_awk_setassocdata
* is returned. ASE_NULL is returned if ase_awk_setassocdata was never called.
*/
void* ase_awk_getassocdata (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk
);
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num); const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num);
int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str); int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c 270 2008-07-20 05:53:29Z baconevi $ * $Id: awk.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -24,7 +24,7 @@ static void free_bfn (void* awk, void* afn);
ase_awk_seterror ((awk), (code), (line), &errarg, 1); \ ase_awk_seterror ((awk), (code), (line), &errarg, 1); \
} while (0) } while (0)
ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr, unsigned int extension) ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, unsigned int extension)
{ {
ase_awk_t* awk; ase_awk_t* awk;
@ -35,9 +35,7 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr, unsigned int extension)
awk = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_awk_t) + extension); awk = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_awk_t) + extension);
if (awk == ASE_NULL) return ASE_NULL; if (awk == ASE_NULL) return ASE_NULL;
/* it uses the built-in ase_awk_memset because awk is not ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t) + extension);
* fully initialized yet */
ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t));
awk->mmgr = mmgr; awk->mmgr = mmgr;
if (ase_str_open (&awk->token.name, 128, mmgr) == ASE_NULL) if (ase_str_open (&awk->token.name, 128, mmgr) == ASE_NULL)
@ -357,14 +355,14 @@ void* ase_awk_getextension (ase_awk_t* awk)
return (void*)(awk + 1); return (void*)(awk + 1);
} }
void ase_awk_setassocdata (ase_awk_t* awk, void* data) void ase_awk_setccls (ase_awk_t* awk, ase_ccls_t* ccls)
{ {
awk->assoc_data = data; awk->ccls = ccls;
} }
void* ase_awk_getassocdata (ase_awk_t* awk) void ase_awk_setprmfns (ase_awk_t* awk, ase_awk_prmfns_t* prmfns)
{ {
return awk->assoc_data; awk->prmfns = prmfns;
} }
int ase_awk_getoption (ase_awk_t* awk) int ase_awk_getoption (ase_awk_t* awk)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h 270 2008-07-20 05:53:29Z baconevi $ * $Id: awk_i.h 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -37,19 +37,19 @@ typedef struct ase_awk_tree_t ase_awk_tree_t;
#define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC((awk)->mmgr,ptr,size) #define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC((awk)->mmgr,ptr,size)
#define ASE_AWK_FREE(awk,ptr) ASE_FREE((awk)->mmgr,ptr) #define ASE_AWK_FREE(awk,ptr) ASE_FREE((awk)->mmgr,ptr)
#define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER((awk)->ccls,c)
#define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER((awk)->ccls,c)
#define ASE_AWK_ISALPHA(awk,c) ASE_ISALPHA(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISALPHA(awk,c) ASE_ISALPHA((awk)->ccls,c)
#define ASE_AWK_ISDIGIT(awk,c) ASE_ISDIGIT(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISDIGIT(awk,c) ASE_ISDIGIT((awk)->ccls,c)
#define ASE_AWK_ISXDIGIT(awk,c) ASE_ISXDIGIT(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISXDIGIT(awk,c) ASE_ISXDIGIT((awk)->ccls,c)
#define ASE_AWK_ISALNUM(awk,c) ASE_ISALNUM(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISALNUM(awk,c) ASE_ISALNUM((awk)->ccls,c)
#define ASE_AWK_ISSPACE(awk,c) ASE_ISSPACE(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISSPACE(awk,c) ASE_ISSPACE((awk)->ccls,c)
#define ASE_AWK_ISPRINT(awk,c) ASE_ISPRINT(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISPRINT(awk,c) ASE_ISPRINT((awk)->ccls,c)
#define ASE_AWK_ISGRAPH(awk,c) ASE_ISGRAPH(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISGRAPH(awk,c) ASE_ISGRAPH((awk)->ccls,c)
#define ASE_AWK_ISCNTRL(awk,c) ASE_ISCNTRL(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISCNTRL(awk,c) ASE_ISCNTRL((awk)->ccls,c)
#define ASE_AWK_ISPUNCT(awk,c) ASE_ISPUNCT(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISPUNCT(awk,c) ASE_ISPUNCT((awk)->ccls,c)
#define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c) #define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER((awk)->ccls,c)
#define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c) #define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER((awk)->ccls,c)
#define ASE_AWK_STRDUP(awk,str) (ase_strdup(str,(awk)->mmgr)) #define ASE_AWK_STRDUP(awk,str) (ase_strdup(str,(awk)->mmgr))
#define ASE_AWK_STRXDUP(awk,str,len) (ase_strxdup(str,len,(awk)->mmgr)) #define ASE_AWK_STRXDUP(awk,str,len) (ase_strxdup(str,len,(awk)->mmgr))
@ -78,8 +78,8 @@ struct ase_awk_t
{ {
ase_mmgr_t* mmgr; ase_mmgr_t* mmgr;
ase_ccls_t* ccls; ase_ccls_t* ccls;
ase_awk_prmfns_t* prmfns;
ase_awk_prmfns_t prmfns;
void* assoc_data; void* assoc_data;
/* options */ /* options */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c 270 2008-07-20 05:53:29Z baconevi $ * $Id: err.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -176,7 +176,7 @@ int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str)
if (str == ASE_NULL) dup = ASE_NULL; if (str == ASE_NULL) dup = ASE_NULL;
else else
{ {
dup = ASE_STRDUP(awk, str); dup = ASE_AWK_STRDUP (awk, str);
if (dup == ASE_NULL) return -1; if (dup == ASE_NULL) return -1;
} }
@ -251,8 +251,8 @@ void ase_awk_seterror (
switch (argcnt) switch (argcnt)
{ {
case 0: case 0:
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->errmsg, awk->errmsg,
ASE_COUNTOF(awk->errmsg), ASE_COUNTOF(awk->errmsg),
errfmt); errfmt);
@ -279,8 +279,8 @@ void ase_awk_seterror (
ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len); ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
} }
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->errmsg, awk->errmsg,
ASE_COUNTOF(awk->errmsg), ASE_COUNTOF(awk->errmsg),
errfmt, (int)len, tmp); errfmt, (int)len, tmp);
@ -288,8 +288,8 @@ void ase_awk_seterror (
} }
case 2: case 2:
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->errmsg, awk->errmsg,
ASE_COUNTOF(awk->errmsg), ASE_COUNTOF(awk->errmsg),
errfmt, errfmt,
@ -298,8 +298,8 @@ void ase_awk_seterror (
return; return;
case 3: case 3:
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->errmsg, awk->errmsg,
ASE_COUNTOF(awk->errmsg), ASE_COUNTOF(awk->errmsg),
errfmt, errfmt,
@ -309,8 +309,8 @@ void ase_awk_seterror (
return; return;
case 4: case 4:
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->errmsg, awk->errmsg,
ASE_COUNTOF(awk->errmsg), ASE_COUNTOF(awk->errmsg),
errfmt, errfmt,
@ -321,8 +321,8 @@ void ase_awk_seterror (
return; return;
case 5: case 5:
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->errmsg, awk->errmsg,
ASE_COUNTOF(awk->errmsg), ASE_COUNTOF(awk->errmsg),
errfmt, errfmt,
@ -403,8 +403,8 @@ void ase_awk_setrunerror (
case 0: case 0:
/* TODO: convert % to %% if the original % is not /* TODO: convert % to %% if the original % is not
* the first % of the %% sequence */ * the first % of the %% sequence */
run->awk->prmfns.misc.sprintf ( run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->errmsg, run->errmsg,
ASE_COUNTOF(run->errmsg), ASE_COUNTOF(run->errmsg),
errfmt); errfmt);
@ -434,8 +434,8 @@ void ase_awk_setrunerror (
ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len); ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
} }
run->awk->prmfns.misc.sprintf ( run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->errmsg, run->errmsg,
ASE_COUNTOF(run->errmsg), ASE_COUNTOF(run->errmsg),
errfmt, len, tmp); errfmt, len, tmp);
@ -443,8 +443,8 @@ void ase_awk_setrunerror (
} }
case 2: case 2:
run->awk->prmfns.misc.sprintf ( run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->errmsg, run->errmsg,
ASE_COUNTOF(run->errmsg), ASE_COUNTOF(run->errmsg),
errfmt, errfmt,
@ -453,8 +453,8 @@ void ase_awk_setrunerror (
return; return;
case 3: case 3:
run->awk->prmfns.misc.sprintf ( run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->errmsg, run->errmsg,
ASE_COUNTOF(run->errmsg), ASE_COUNTOF(run->errmsg),
errfmt, errfmt,
@ -464,8 +464,8 @@ void ase_awk_setrunerror (
return; return;
case 4: case 4:
run->awk->prmfns.misc.sprintf ( run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->errmsg, run->errmsg,
ASE_COUNTOF(run->errmsg), ASE_COUNTOF(run->errmsg),
errfmt, errfmt,
@ -476,8 +476,8 @@ void ase_awk_setrunerror (
return; return;
case 5: case 5:
run->awk->prmfns.misc.sprintf ( run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->errmsg, run->errmsg,
ASE_COUNTOF(run->errmsg), ASE_COUNTOF(run->errmsg),
errfmt, errfmt,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: jni.c 237 2008-07-09 13:20:08Z baconevi $ * $Id: jni.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -86,9 +86,6 @@ typedef struct run_data_t run_data_t;
struct awk_data_t struct awk_data_t
{ {
int debug; int debug;
#if defined(_WIN32) && defined(__DMC__)
HANDLE heap;
#endif
}; };
struct srcio_data_t struct srcio_data_t
@ -133,102 +130,6 @@ struct run_data_t
jobject context_object; jobject context_object;
}; };
static void* awk_malloc (void* custom, ase_size_t n)
{
#if defined(_WIN32) && defined(__DMC__)
return HeapAlloc ((HANDLE)custom, 0, n);
#else
return malloc (n);
#endif
}
static void* awk_realloc (void* custom, void* ptr, ase_size_t n)
{
#if defined(_WIN32) && defined(__DMC__)
if (ptr == ASE_NULL)
return HeapAlloc ((HANDLE)custom, 0, n);
else
return HeapReAlloc ((HANDLE)custom, 0, ptr, n);
#else
return realloc (ptr, n);
#endif
}
static void awk_free (void* custom, void* ptr)
{
#if defined(_WIN32) && defined(__DMC__)
HeapFree ((HANDLE)custom, 0, ptr);
#else
free (ptr);
#endif
}
/* custom character class functions */
static ase_bool_t awk_isupper (void* custom, ase_cint_t c)
{
return ase_isupper (c);
}
static ase_bool_t awk_islower (void* custom, ase_cint_t c)
{
return ase_islower (c);
}
static ase_bool_t awk_isalpha (void* custom, ase_cint_t c)
{
return ase_isalpha (c);
}
static ase_bool_t awk_isdigit (void* custom, ase_cint_t c)
{
return ase_isdigit (c);
}
static ase_bool_t awk_isxdigit (void* custom, ase_cint_t c)
{
return ase_isxdigit (c);
}
static ase_bool_t awk_isalnum (void* custom, ase_cint_t c)
{
return ase_isalnum (c);
}
static ase_bool_t awk_isspace (void* custom, ase_cint_t c)
{
return ase_isspace (c);
}
static ase_bool_t awk_isprint (void* custom, ase_cint_t c)
{
return ase_isprint (c);
}
static ase_bool_t awk_isgraph (void* custom, ase_cint_t c)
{
return ase_isgraph (c);
}
static ase_bool_t awk_iscntrl (void* custom, ase_cint_t c)
{
return ase_iscntrl (c);
}
static ase_bool_t awk_ispunct (void* custom, ase_cint_t c)
{
return ase_ispunct (c);
}
static ase_cint_t awk_toupper (void* custom, ase_cint_t c)
{
return ase_toupper (c);
}
static ase_cint_t awk_tolower (void* custom, ase_cint_t c)
{
return ase_tolower (c);
}
static ase_real_t awk_pow (void* custom, ase_real_t x, ase_real_t y) static ase_real_t awk_pow (void* custom, ase_real_t x, ase_real_t y)
{ {
return pow (x, y); return pow (x, y);
@ -406,7 +307,7 @@ static void throw_exception (
static jboolean is_debug (ase_awk_t* awk) static jboolean is_debug (ase_awk_t* awk)
{ {
awk_data_t* awk_data = (awk_data_t*)ase_awk_getassocdata (awk); awk_data_t* awk_data = (awk_data_t*)ase_awk_getextension (awk);
return awk_data->debug? JNI_TRUE: JNI_FALSE; return awk_data->debug? JNI_TRUE: JNI_FALSE;
} }
@ -418,9 +319,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
ase_awk_prmfns_t prmfns; ase_awk_prmfns_t prmfns;
awk_data_t* awk_data; awk_data_t* awk_data;
int opt; int opt;
#if defined(_WIN32) && defined(__DMC__)
HANDLE heap;
#endif
#if defined(_WIN32) && defined(_DEBUG) #if defined(_WIN32) && defined(_DEBUG)
OutputDebugStringW (L"<<<OPENING AWK>>>\n"); OutputDebugStringW (L"<<<OPENING AWK>>>\n");
@ -429,80 +327,22 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
#endif #endif
#endif #endif
#if defined(_WIN32) && defined(__DMC__) awk = ase_awk_open (ASE_GETMMGR(), ASE_SIZEOF(awk_data_t));
heap = HeapCreate (0, 0, 0);
if (heap == ASE_NULL)
{
THROW_NOMEM_EXCEPTION (env);
return;
}
#endif
memset (&prmfns, 0, sizeof(prmfns));
prmfns.mmgr.malloc = awk_malloc;
prmfns.mmgr.realloc = awk_realloc;
prmfns.mmgr.free = awk_free;
#if defined(_WIN32) && defined(__DMC__)
prmfns.mmgr.custom_data = (void*)heap;
#else
prmfns.mmgr.custom_data = ASE_NULL;
#endif
prmfns.ccls.is_upper = awk_isupper;
prmfns.ccls.is_lower = awk_islower;
prmfns.ccls.is_alpha = awk_isalpha;
prmfns.ccls.is_digit = awk_isdigit;
prmfns.ccls.is_xdigit = awk_isxdigit;
prmfns.ccls.is_alnum = awk_isalnum;
prmfns.ccls.is_space = awk_isspace;
prmfns.ccls.is_print = awk_isprint;
prmfns.ccls.is_graph = awk_isgraph;
prmfns.ccls.is_cntrl = awk_iscntrl;
prmfns.ccls.is_punct = awk_ispunct;
prmfns.ccls.to_upper = awk_toupper;
prmfns.ccls.to_lower = awk_tolower;
prmfns.ccls.custom_data = ASE_NULL;
prmfns.misc.pow = awk_pow;
prmfns.misc.sprintf = awk_sprintf;
prmfns.misc.dprintf = awk_dprintf;
prmfns.misc.custom_data = ASE_NULL;
#if defined(_WIN32) && defined(__DMC__)
awk_data = (awk_data_t*) awk_malloc (heap, sizeof(awk_data_t));
#else
awk_data = (awk_data_t*) awk_malloc (ASE_NULL, sizeof(awk_data_t));
#endif
if (awk_data == ASE_NULL)
{
#if defined(_WIN32) && defined(__DMC__)
HeapDestroy (heap);
#endif
THROW_NOMEM_EXCEPTION (env);
return;
}
memset (awk_data, 0, sizeof(awk_data_t));
awk_data->debug = 0;
#if defined(_WIN32) && defined(__DMC__)
awk_data->heap = heap;
#endif
awk = ase_awk_open (&prmfns);
if (awk == ASE_NULL) if (awk == ASE_NULL)
{ {
#if defined(_WIN32) && defined(__DMC__)
awk_free (heap, awk_data);
HeapDestroy (heap);
#else
awk_free (ASE_NULL, awk_data);
#endif
THROW_NOMEM_EXCEPTION (env); THROW_NOMEM_EXCEPTION (env);
return; return;
} }
ase_awk_setassocdata (awk, awk_data); awk_data = (awk_data_t*) ase_awk_getextension (awk);
awk_data->debug = 0;
awk_data->prmfns.pow = awk_pow;
awk_data->prmfns.sprintf = awk_sprintf;
awk_data->prmfns.dprintf = awk_dprintf;
awk_data->prmfns.custom_data = ASE_NULL;
ase_awk_setccls (awk, ASE_GETCCLS());
ase_awk_setprmfns (awk, &awk_data->prmfns);
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J"); handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
@ -552,7 +392,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj, jlong a
OutputDebugStringW (L"<<<CLOSING AWK>>>\n"); OutputDebugStringW (L"<<<CLOSING AWK>>>\n");
#endif #endif
tmp = (awk_data_t*)ase_awk_getassocdata (awk); tmp = (awk_data_t*)ase_awk_getextension (awk);
#if defined(_WIN32) && defined(__DMC__) #if defined(_WIN32) && defined(__DMC__)
HANDLE heap = tmp->heap; HANDLE heap = tmp->heap;
#endif #endif
@ -1939,7 +1779,7 @@ JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug (JNIEnv* env, jobject obj,
{ {
ase_awk_t* awk = (ase_awk_t*)awkid; ase_awk_t* awk = (ase_awk_t*)awkid;
EXCEPTION_ON_ASE_NULL_AWK_RETURNING (env, awk, JNI_FALSE); EXCEPTION_ON_ASE_NULL_AWK_RETURNING (env, awk, JNI_FALSE);
return ((awk_data_t*)ase_awk_getassocdata(awk))->debug? JNI_TRUE: JNI_FALSE; return ((awk_data_t*)ase_awk_getextension(awk))->debug? JNI_TRUE: JNI_FALSE;
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
@ -1947,7 +1787,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
{ {
ase_awk_t* awk = (ase_awk_t*)awkid; ase_awk_t* awk = (ase_awk_t*)awkid;
EXCEPTION_ON_ASE_NULL_AWK (env, awk); EXCEPTION_ON_ASE_NULL_AWK (env, awk);
((awk_data_t*)ase_awk_getassocdata(awk))->debug = debug; ((awk_data_t*)ase_awk_getextension(awk))->debug = debug;
} }
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_getword ( JNIEXPORT jstring JNICALL Java_ase_awk_Awk_getword (

View File

@ -1,5 +1,5 @@
/* /*
* $Id: misc.c 270 2008-07-20 05:53:29Z baconevi $ * $Id: misc.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -949,7 +949,7 @@ int ase_awk_matchrex (
int err, x; int err, x;
x = ase_matchrex ( x = ase_matchrex (
awk->mmgr, &awk->prmfns.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 = ASE_AWK_REXERRTOERR(err); if (x < 0) *errnum = ASE_AWK_REXERRTOERR(err);
return x; return x;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 270 2008-07-20 05:53:29Z baconevi $ * $Id: parse.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -472,6 +472,9 @@ int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios)
{ {
int n; int n;
ASE_ASSERTX (awk->ccls != ASE_NULL, "Call ase_setccls() first");
ASE_ASSERTX (awk->prmfns != ASE_NULL, "Call ase_setprmfns() first");
ASE_ASSERTX ( ASE_ASSERTX (
srcios != ASE_NULL && srcios->in != ASE_NULL, srcios != ASE_NULL && srcios->in != ASE_NULL,
"the source code input stream must be provided at least"); "the source code input stream must be provided at least");

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c 270 2008-07-20 05:53:29Z baconevi $ * $Id: run.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -17,6 +17,7 @@
#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))
@ -618,6 +619,9 @@ int ase_awk_run (ase_awk_t* awk,
ase_awk_run_t* run; ase_awk_run_t* run;
int n; int n;
ASE_ASSERTX (awk->ccls != ASE_NULL, "Call ase_setccls() first");
ASE_ASSERTX (awk->prmfns != ASE_NULL, "Call ase_setprmfns() first");
/* clear the awk error code */ /* clear the awk error code */
ase_awk_seterror (awk, ASE_AWK_ENOERR, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOERR, 0, ASE_NULL, 0);
@ -4034,7 +4038,7 @@ static int __cmp_int_str (
str, len, str, len,
((ase_awk_val_str_t*)right)->buf, ((ase_awk_val_str_t*)right)->buf,
((ase_awk_val_str_t*)right)->len, ((ase_awk_val_str_t*)right)->len,
&run->awk->prmfns.ccls); CCLS(run));
} }
else else
{ {
@ -4106,7 +4110,7 @@ static int __cmp_real_str (
str, len, str, len,
((ase_awk_val_str_t*)right)->buf, ((ase_awk_val_str_t*)right)->buf,
((ase_awk_val_str_t*)right)->len, ((ase_awk_val_str_t*)right)->len,
&run->awk->prmfns.ccls); CCLS(run));
} }
else else
{ {
@ -4150,8 +4154,7 @@ static int __cmp_str_str (
if (run->global.ignorecase) if (run->global.ignorecase)
{ {
n = ase_strxncasecmp ( n = ase_strxncasecmp (
ls->buf, ls->len, rs->buf, rs->len, ls->buf, ls->len, rs->buf, rs->len, CCLS(run));
&run->awk->prmfns.ccls);
} }
else else
{ {
@ -4529,7 +4532,7 @@ static ase_awk_val_t* eval_binop_exp (
ase_real_t r1, r2; ase_real_t r1, r2;
ase_awk_val_t* res; ase_awk_val_t* res;
ASE_ASSERTX (run->awk->prmfns.misc.pow != ASE_NULL, ASE_ASSERTX (run->awk->prmfns->pow != ASE_NULL,
"the pow function should be provided when the awk object is created to make the exponentiation work properly."); "the pow function should be provided when the awk object is created to make the exponentiation work properly.");
n1 = ase_awk_valtonum (run, left, &l1, &r1); n1 = ase_awk_valtonum (run, left, &l1, &r1);
@ -4590,8 +4593,8 @@ static ase_awk_val_t* eval_binop_exp (
{ {
/* left - int, right - real */ /* left - int, right - real */
res = ase_awk_makerealval (run, res = ase_awk_makerealval (run,
run->awk->prmfns.misc.pow ( run->awk->prmfns->pow (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
(ase_real_t)l1,(ase_real_t)r2)); (ase_real_t)l1,(ase_real_t)r2));
} }
else else
@ -4599,8 +4602,8 @@ static ase_awk_val_t* eval_binop_exp (
/* left - real, right - real */ /* left - real, right - real */
ASE_ASSERT (n3 == 3); ASE_ASSERT (n3 == 3);
res = ase_awk_makerealval (run, res = ase_awk_makerealval (run,
run->awk->prmfns.misc.pow( run->awk->prmfns->pow(
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
(ase_real_t)r1,(ase_real_t)r2)); (ase_real_t)r1,(ase_real_t)r2));
} }
@ -6660,8 +6663,8 @@ ase_char_t* ase_awk_format (
do do
{ {
n = run->awk->prmfns.misc.sprintf ( n = run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->format.tmp.ptr, run->format.tmp.ptr,
run->format.tmp.len, run->format.tmp.len,
#if ASE_SIZEOF_LONG_LONG > 0 #if ASE_SIZEOF_LONG_LONG > 0
@ -6766,8 +6769,8 @@ ase_char_t* ase_awk_format (
do do
{ {
n = run->awk->prmfns.misc.sprintf ( n = run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->format.tmp.ptr, run->format.tmp.ptr,
run->format.tmp.len, run->format.tmp.len,
#if ASE_SIZEOF_LONG_LONG > 0 #if ASE_SIZEOF_LONG_LONG > 0
@ -6887,8 +6890,8 @@ ase_char_t* ase_awk_format (
do do
{ {
n = run->awk->prmfns.misc.sprintf ( n = run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->format.tmp.ptr, run->format.tmp.ptr,
run->format.tmp.len, run->format.tmp.len,
ASE_STR_BUF(fbu), ASE_STR_BUF(fbu),
@ -6975,8 +6978,8 @@ ase_char_t* ase_awk_format (
do do
{ {
n = run->awk->prmfns.misc.sprintf ( n = run->awk->prmfns->sprintf (
run->awk->prmfns.misc.custom_data, run->awk->prmfns->custom_data,
run->format.tmp.ptr, run->format.tmp.ptr,
run->format.tmp.len, run->format.tmp.len,
ASE_STR_BUF(fbu), ASE_STR_BUF(fbu),

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c 192 2008-06-06 10:33:44Z baconevi $ * $Id: tree.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -263,13 +263,13 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
if (((ase_awk_nde_real_t*)nde)->str == ASE_NULL) if (((ase_awk_nde_real_t*)nde)->str == ASE_NULL)
{ {
#if (ASE_SIZEOF_LONG_DOUBLE != 0) #if (ASE_SIZEOF_LONG_DOUBLE != 0)
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%Lf"), awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%Lf"),
(long double)((ase_awk_nde_real_t*)nde)->val); (long double)((ase_awk_nde_real_t*)nde)->val);
#elif (ASE_SIZEOF_DOUBLE != 0) #elif (ASE_SIZEOF_DOUBLE != 0)
awk->prmfns.misc.sprintf ( awk->prmfns->sprintf (
awk->prmfns.misc.custom_data, awk->prmfns->custom_data,
awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%f"), awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%f"),
(double)((ase_awk_nde_real_t*)nde)->val); (double)((ase_awk_nde_real_t*)nde)->val);
#else #else

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c 270 2008-07-20 05:53:29Z baconevi $ * $Id: val.c 271 2008-07-20 12:42:39Z baconevi $
* *
* {License} * {License}
*/ */
@ -1059,8 +1059,8 @@ int ase_awk_strtonum (
return 0; /* long */ return 0; /* long */
} }
#define DPRINTF run->awk->prmfns.misc.dprintf #define DPRINTF run->awk->prmfns->dprintf
#define DCUSTOM run->awk->prmfns.misc.custom_data #define DCUSTOM run->awk->prmfns->custom_data
static int print_pair (ase_pair_t* pair, void* arg) static int print_pair (ase_pair_t* pair, void* arg)
{ {