From 3cbefaa12c27d1eaad888cbe6f7f119d199db77f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 19 Aug 2008 05:21:48 +0000 Subject: [PATCH] --- ase/cmd/awk/awk.c | 349 +++++++++++++------------------------- ase/cmd/lsp/lsp.c | 8 +- ase/cmd/tgp/tgp.c | 2 +- ase/include/ase/awk/awk.h | 72 ++++---- ase/include/ase/cmn/dll.h | 45 +++-- ase/include/ase/cmn/mem.h | 21 ++- ase/include/ase/cmn/sll.h | 85 +++++----- ase/include/ase/lsp/lsp.h | 8 +- ase/include/ase/macros.h | 46 ++--- ase/include/ase/types.h | 6 +- ase/lib/awk/Awk.cpp | 26 +-- ase/lib/awk/awk.c | 37 ++-- ase/lib/awk/awk_i.h | 8 +- ase/lib/awk/err.c | 26 +-- ase/lib/awk/extio.c | 6 +- ase/lib/awk/jni.c | 18 +- ase/lib/awk/parse.c | 16 +- ase/lib/awk/rec.c | 4 +- ase/lib/awk/run.c | 46 ++--- ase/lib/awk/std.c | 10 +- ase/lib/awk/tab.c | 4 +- ase/lib/awk/tree.c | 6 +- ase/lib/awk/val.c | 6 +- ase/lib/cmn/dll.c | 32 +++- ase/lib/cmn/map.c | 3 +- ase/lib/cmn/rex.c | 8 +- ase/lib/cmn/sll.c | 42 ++--- ase/lib/cmn/str_bas.c | 6 +- ase/lib/cmn/str_cnv.c | 3 +- ase/lib/cmn/str_dyn.c | 6 +- ase/lib/lsp/err.c | 14 +- ase/lib/lsp/lsp.c | 8 +- ase/lib/lsp/lsp_i.h | 4 +- ase/lib/lsp/mem.c | 4 +- ase/lib/lsp/name.c | 4 +- ase/lib/lsp/print.c | 14 +- ase/lib/utl/http.c | 6 +- 37 files changed, 465 insertions(+), 544 deletions(-) diff --git a/ase/cmd/awk/awk.c b/ase/cmd/awk/awk.c index 3ad100f1..1b22e898 100644 --- a/ase/cmd/awk/awk.c +++ b/ase/cmd/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c 329 2008-08-16 14:08:53Z baconevi $ + * $Id: awk.c 332 2008-08-18 11:21:48Z baconevi $ */ #include @@ -25,16 +25,15 @@ #pragma warning (disable: 4296) #endif -#if defined(__linux) && defined(_DEBUG) -#include -#endif - #if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) #define _CRTDBG_MAP_ALLOC #include #endif -struct srcio_t +#define SRCIO_FILE 1 +#define SRCIO_STR 2 + +typedef struct srcio_data_t { int type; /* file or string */ @@ -45,20 +44,14 @@ struct srcio_t ase_char_t* ptr; ase_char_t* cur; } str; - struct { - int count; - const ase_char_t* name[128]; + struct + { + ase_sll_t* sll; + ase_sll_node_t* cur; FILE* handle; } file; } data; -}; - -#if defined(_WIN32) -struct mmgr_data_t -{ - HANDLE heap; -}; -#endif +} srcio_data_t; static void local_dprintf (const ase_char_t* fmt, ...) { @@ -80,7 +73,7 @@ static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...) static void* custom_awk_malloc (void* custom, ase_size_t n) { #ifdef _WIN32 - return HeapAlloc (((struct mmgr_data_t*)custom)->heap, 0, n); + return HeapAlloc ((HANDLE)custom, 0, n); #else return malloc (n); #endif @@ -90,10 +83,9 @@ static void* custom_awk_realloc (void* custom, void* ptr, ase_size_t n) { #ifdef _WIN32 /* HeapReAlloc behaves differently from realloc */ - if (ptr == NULL) - return HeapAlloc (((struct mmgr_data_t*)custom)->heap, 0, n); - else - return HeapReAlloc (((struct mmgr_data_t*)custom)->heap, 0, ptr, n); + return (ptr == NULL)? + HeapAlloc ((HANDLE)custom, 0, n): + HeapReAlloc ((HANDLE)custom, 0, ptr, n); #else return realloc (ptr, n); #endif @@ -102,7 +94,7 @@ static void* custom_awk_realloc (void* custom, void* ptr, ase_size_t n) static void custom_awk_free (void* custom, void* ptr) { #ifdef _WIN32 - HeapFree (((struct mmgr_data_t*)custom)->heap, 0, ptr); + HeapFree ((HANDLE)custom, 0, ptr); #else free (ptr); #endif @@ -132,7 +124,7 @@ static int custom_awk_sprintf ( static ase_ssize_t awk_srcio_in ( int cmd, void* arg, ase_char_t* data, ase_size_t size) { - struct srcio_t* srcio = (struct srcio_t*)arg; + struct srcio_data_t* srcio = (struct srcio_data_t*)arg; ase_cint_t c; #if 0 @@ -180,7 +172,7 @@ static ase_ssize_t awk_srcio_in ( static ase_ssize_t awk_srcio_out ( int cmd, void* arg, ase_char_t* data, ase_size_t size) { - /*struct srcio_t* srcio = (struct srcio_t*)arg;*/ + /*struct srcio_data_t* srcio = (struct srcio_data_t*)arg;*/ if (cmd == ASE_AWK_IO_OPEN) return 1; else if (cmd == ASE_AWK_IO_CLOSE) @@ -797,7 +789,7 @@ static void on_run_return ( local_dprintf (ASE_T("[END NAMED VARIABLES]\n")); } -static void on_run_end (ase_awk_run_t* run, int errnum, void* custom_data) +static void on_run_end (ase_awk_run_t* run, int errnum, void* data) { if (errnum != ASE_AWK_ENOERR) { @@ -857,13 +849,13 @@ static int run_awk (ase_awk_t* awk, runios.pipe = awk_extio_pipe; runios.file = awk_extio_file; runios.console = awk_extio_console; - runios.custom_data = ASE_NULL; + runios.data = ASE_NULL; runcbs.on_start = on_run_start; runcbs.on_statement = on_run_statement; runcbs.on_return = on_run_return; runcbs.on_end = on_run_end; - runcbs.custom_data = ASE_NULL; + runcbs.data = ASE_NULL; if (ase_awk_run (awk, mfn, &runios, &runcbs, runarg, ASE_NULL) == -1) { @@ -879,27 +871,6 @@ static int run_awk (ase_awk_t* awk, return 0; } -#if defined(_WIN32) && defined(TEST_THREAD) -typedef struct thr_arg_t thr_arg_t; -struct thr_arg_t -{ - ase_awk_t* awk; - const ase_char_t* mfn; - ase_awk_runarg_t* runarg; -}; - -static unsigned int __stdcall run_awk_thr (void* arg) -{ - int n; - thr_arg_t* x = (thr_arg_t*)arg; - - n = run_awk (x->awk, x->mfn, x->runarg); - - _endthreadex (n); - return 0; -} -#endif - static int bfn_sleep ( ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) { @@ -1057,14 +1028,9 @@ static void handle_args (argc, argv) } #endif -static int dump_sf (ase_sll_t* sll, ase_sll_node_t* n, void* arg) -{ - ase_printf (ASE_T("%s\n"), n->dptr); - return ASE_SLL_WALK_FORWARD; -} - -static int handle_args (int argc, ase_char_t* argv[], ase_sll_t* sf) +static int handle_args (int argc, ase_char_t* argv[], srcio_data_t* siod); { + ase_sll_t* sf; ase_cint_t c; static ase_opt_lng_t lng[] = { @@ -1090,7 +1056,6 @@ static int handle_args (int argc, ase_char_t* argv[], ase_sll_t* sf) { ASE_T(":assign"), ASE_T('v') }, { ASE_T("help"), ASE_T('h') } - }; static ase_opt_t opt = @@ -1117,24 +1082,21 @@ static int handle_args (int argc, ase_char_t* argv[], ase_sll_t* sf) ase_size_t sz = ase_strlen(opt.arg) + 1; sz *= ASE_SIZEOF(*opt.arg); - if (ase_sll_getsize(sf) % 2) + if (sf == NULL) { -wprintf (L"APPEND %S\n", opt.arg); + sf = ase_sll_open (ASE_NULL, 0, ASE_NULL); + if (sf == ASE_NULL) + { + out_of_memory (); + return -1; + } + } + if (ase_sll_pushtail(sf, opt.arg, sz) == ASE_NULL) { out_of_memory (); return -1; } - } - else - { -wprintf (L"PREPEND %S\n", opt.arg); - if (ase_sll_pushhead(sf, opt.arg, sz) == ASE_NULL) - { - out_of_memory (); - return -1; - } - } break; } @@ -1171,33 +1133,28 @@ wprintf (L"PREPEND %S\n", opt.arg); } } -ase_printf (ASE_T("[%d]\n"), (int)ase_sll_getsize(sf)); -ase_sll_walk (sf, dump_sf, ASE_NULL); -#if 0 - if (srcio->input_file == ASE_NULL) + if (ase_sll_getsize(sf) == 0) { - /* the first is the source code... */ + if (opt.ind >= argc) + { + /* no source code specified */ + return -1; + } + + siod->type = SRCIO_STR; + siod->data.str.ptr = opt.arg[opt.ind++]; + siod->data.str.cur = NULL; } else { - /* the remainings are data file names */ + /* read source code from the file */ + siod->type = SRCIO_FILE; + siod->data.file.sll = sf; + siod->data.file.cur = NULL; } -#endif - - while (opt.ind < argc) - { - ase_printf (ASE_T("RA => [%s]\n"), argv[opt.ind++]); - } -/* - if (opt.ind < argc) - { - ase_printf (ASE_T("Error: redundant argument - %s\n"), argv[opt.ind]); - print_usage (argv[0]); - return -1; - } -*/ + /* remaining args are input(console) file names */ return 0; } @@ -1209,120 +1166,114 @@ typedef struct extension_t } extension_t; -static void* fuser (void* org, void* space) +static void init_extension (ase_awk_t* awk) { - extension_t* ext = (extension_t*)space; - /* remember the memory manager into the extension */ - ext->mmgr = *(ase_mmgr_t*)org; - return &ext->mmgr; + extension_t* ext = ase_awk_getextension(awk); + + ext->mmgr = *ase_awk_getmmgr(awk); + ase_awk_setmmgr (awk, &ext->mmgr); + ase_awk_setccls (awk, ASE_GETCCLS()); + + ext->prmfns.pow = custom_awk_pow; + ext->prmfns.sprintf = custom_awk_sprintf; + ext->prmfns.dprintf = custom_awk_dprintf; + ext->prmfns.data = ASE_NULL; + ase_awk_setprmfns (awk, &ext->prmfns); } static ase_awk_t* open_awk (void) { ase_awk_t* awk; ase_mmgr_t mmgr; - extension_t* extension; memset (&mmgr, 0, ASE_SIZEOF(mmgr)); mmgr.malloc = custom_awk_malloc; mmgr.realloc = custom_awk_realloc; mmgr.free = custom_awk_free; + #ifdef _WIN32 - mmgr_data.heap = HeapCreate (0, 1000000, 1000000); - if (mmgr_data.heap == NULL) + mmgr.data = (void*)HeapCreate (0, 1000000, 1000000); /* TODO: get size from xxxx */ + if (mmgr.data == NULL) { ase_printf (ASE_T("Error: cannot create an awk heap\n")); - return -1; + return ASE_NULL; } - - mmgr.custom_data = &mmgr_data; #else - mmgr.custom_data = ASE_NULL; + mmgr.data = ASE_NULL; #endif - awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t), fuser); + awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t), init_extension); if (awk == ASE_NULL) { #ifdef _WIN32 - HeapDestroy (mmgr_data.heap); + HeapDestroy ((HANDLE)mmgr.data); #endif ase_printf (ASE_T("ERROR: cannot open awk\n")); return ASE_NULL; } - ase_awk_setccls (awk, ASE_GETCCLS()); + ase_awk_setoption (awk, + ASE_AWK_IMPLICIT | ASE_AWK_EXTIO | ASE_AWK_NEWLINE | + ASE_AWK_BASEONE | ASE_AWK_PABLOCK); - extension = (extension_t*) ase_awk_getextension (awk); - 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_setprmfns (awk, &extension->prmfns); + /* TODO: get depth from command line */ + ase_awk_setmaxdepth ( + awk, ASE_AWK_DEPTH_BLOCK_PARSE | ASE_AWK_DEPTH_EXPR_PARSE, 50); + ase_awk_setmaxdepth ( + awk, ASE_AWK_DEPTH_BLOCK_RUN | ASE_AWK_DEPTH_EXPR_RUN, 500); - ase_awk_setoption (awk, ASE_AWK_IMPLICIT | ASE_AWK_EXTIO | ASE_AWK_NEWLINE | ASE_AWK_BASEONE | ASE_AWK_PABLOCK); + /* + ase_awk_seterrstr (awk, ASE_AWK_EGBLRED, + ASE_T("\uC804\uC5ED\uBCC0\uC218 \'%.*s\'\uAC00 \uC7AC\uC815\uC758 \uB418\uC5C8\uC2B5\uB2C8\uB2E4")); + ase_awk_seterrstr (awk, ASE_AWK_EAFNRED, + ASE_T("\uD568\uC218 \'%.*s\'\uAC00 \uC7AC\uC815\uC758 \uB418\uC5C8\uC2B5\uB2C8\uB2E4")); + */ + /*ase_awk_setkeyword (awk, ASE_T("func"), 4, ASE_T("FX"), 2);*/ + + if (ase_awk_addfunc (awk, + ASE_T("sleep"), 5, 0, + 1, 1, ASE_NULL, bfn_sleep) == ASE_NULL) + { + ase_awk_close (awk); +#ifdef _WIN32 + HeapDestroy ((HANDLE)mmgr.data); +#endif + ase_printf (ASE_T("ERROR: cannot add function 'sleep'\n")); + return ASE_NULL; + } return awk; } -static int dump (ase_sll_t* sll, ase_sll_node_t* node, void* arg) +static void close_awk (ase_awk_t* awk) { - ase_printf (ASE_T("[%d]\n"), *(int*)node->dptr); - return ASE_SLL_WALK_FORWARD; + extension_t* ext = ase_awk_getextension(awk); + +#ifdef _WIN32 + HANDLE heap = (HANDLE)ext->mmgr->data; +#endif + + ase_awk_close (awk); + +#ifdef _WIN32 + HeapDestroy (heap); +#endif } + static int awk_main (int argc, ase_char_t* argv[]) { ase_awk_t* awk; - ase_mmgr_t mmgr; - extension_t* extension; + srcio_data_t siod; ase_awk_srcios_t srcios; - struct srcio_t srcio = { NULL, NULL }; int 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; - ase_sll_t* sf; - - sf = ase_sll_open (ASE_MMGR_GET()); - if (sf == ASE_NULL) - { - out_of_memory (); - return -1; - } -{ -// TODO: destroy sf.... -int i; - -ase_sll_setcopier (sf, ASE_SLL_COPIER_INLINE); -for (i = 0; i < 20; i++) -{ - /* - if (ASE_SLL_SIZE(sf) > 5) - ase_sll_insert (sf, sf->head->next->next, &i, sizeof(i)); - else - ase_sll_insert (sf, ASE_SLL_HEAD(sf), &i, sizeof(i)); - */ - ase_sll_insert (sf, ASE_NULL, &i, sizeof(i)); -} - -ase_sll_delete (sf, ASE_SLL_TAIL(sf)); -ase_sll_delete (sf, ASE_SLL_TAIL(sf)); -ase_sll_delete (sf, ASE_SLL_HEAD(sf)); -ase_printf (ASE_T("size = %d\n"), ASE_SLL_SIZE(sf)); -ase_sll_walk (sf, dump, ASE_NULL); -ase_sll_clear (sf); -ase_printf (ASE_T("size = %d\n"), ASE_SLL_SIZE(sf)); -ase_sll_close (sf); -return 0; -} - - i = handle_args (argc, argv, sf); + i = handle_args (argc, argv, &siod); if (i == -1) { print_usage (argv[0]); @@ -1334,47 +1285,14 @@ return 0; runarg[runarg_count].ptr = NULL; runarg[runarg_count].len = 0; -#if 0 - if (mode != 0 || srcio.input_file == NULL) - { - print_usage (argv[0]); - return -1; - } -#endif - - awk = open_awk (); if (awk == ASE_NULL) return -1; app_awk = awk; - if (ase_awk_addfunc (awk, - ASE_T("sleep"), 5, 0, - 1, 1, ASE_NULL, bfn_sleep) == ASE_NULL) - { - ase_awk_close (awk); -#ifdef _WIN32 - HeapDestroy (mmgr_data.heap); -#endif - return -1; - } - - - /* - ase_awk_seterrstr (awk, ASE_AWK_EGBLRED, ASE_T("\uC804\uC5ED\uBCC0\uC218 \'%.*s\'\uAC00 \uC7AC\uC815\uC758 \uB418\uC5C8\uC2B5\uB2C8\uB2E4")); - ase_awk_seterrstr (awk, ASE_AWK_EAFNRED, ASE_T("\uD568\uC218 \'%.*s\'\uAC00 \uC7AC\uC815\uC758 \uB418\uC5C8\uC2B5\uB2C8\uB2E4")); - */ - srcios.in = awk_srcio_in; srcios.out = deparse? awk_srcio_out: NULL; - srcios.custom_data = &srcio; - - ase_awk_setmaxdepth ( - awk, ASE_AWK_DEPTH_BLOCK_PARSE | ASE_AWK_DEPTH_EXPR_PARSE, 50); - ase_awk_setmaxdepth ( - awk, ASE_AWK_DEPTH_BLOCK_RUN | ASE_AWK_DEPTH_EXPR_RUN, 500); - - /*ase_awk_setkeyword (awk, ASE_T("func"), 4, ASE_T("FX"), 2);*/ + srcios.data = &siod; if (ase_awk_parse (awk, &srcios) == -1) { @@ -1383,59 +1301,26 @@ return 0; ase_awk_geterrnum(awk), (unsigned int)ase_awk_geterrlin(awk), ase_awk_geterrmsg(awk)); - ase_awk_close (awk); -#ifdef _WIN32 - HeapDestroy (mmgr_data.heap); -#endif + close_awk (awk); return -1; } +// TODO: close siod.... + #ifdef _WIN32 SetConsoleCtrlHandler (stop_run, TRUE); #else signal (SIGINT, stop_run); #endif -#if defined(_WIN32) && defined(TEST_THREAD) - { - unsigned int tid; - HANDLE thr[5]; - thr_arg_t arg; - int y; - - arg.awk = awk; - arg.mfn = mfn; - arg.runarg = runarg; - - for (y = 0; y < ASE_COUNTOF(thr); y++) - { - thr[y] = (HANDLE)_beginthreadex (NULL, 0, run_awk_thr, &arg, 0, &tid); - if (thr[y] == (HANDLE)0) - { - ase_printf (ASE_T("ERROR: cannot create a thread %d\n"), y); - } - } - - for (y = 0; y < ASE_COUNTOF(thr); y++) - { - if (thr[y]) WaitForSingleObject (thr[y], INFINITE); - } - } -#else if (run_awk (awk, mfn, runarg) == -1) { - ase_awk_close (awk); -#ifdef _WIN32 - HeapDestroy (mmgr_data.heap); -#endif + close_awk (awk); return -1; } -#endif - ase_awk_close (awk); -#ifdef _WIN32 - HeapDestroy (mmgr_data.heap); -#endif + close_awk (awk); + return 0; } @@ -1443,18 +1328,12 @@ int ase_main (int argc, ase_achar_t* argv[]) { int n; -#if defined(__linux) && defined(_DEBUG) - mtrace (); -#endif #if defined(_WIN32) && defined(_DEBUG) && defined(_MSC_VER) _CrtSetDbgFlag (_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF); #endif n = ase_runmain (argc, argv, awk_main); -#if defined(__linux) && defined(_DEBUG) - muntrace (); -#endif #if defined(_WIN32) && defined(_DEBUG) /*#if defined(_MSC_VER) _CrtDumpMemoryLeaks (); diff --git a/ase/cmd/lsp/lsp.c b/ase/cmd/lsp/lsp.c index b437099f..8a5c6be8 100644 --- a/ase/cmd/lsp/lsp.c +++ b/ase/cmd/lsp/lsp.c @@ -306,9 +306,9 @@ int lsp_main (int argc, ase_char_t* argv[]) return -1; } - prmfns.mmgr.custom_data = &prmfns_data; + prmfns.mmgr.data = &prmfns_data; #else - prmfns.mmgr.custom_data = ASE_NULL; + prmfns.mmgr.data = ASE_NULL; #endif prmfns.ccls.is_upper = custom_lsp_isupper; @@ -324,11 +324,11 @@ int lsp_main (int argc, ase_char_t* argv[]) prmfns.ccls.is_punct = custom_lsp_ispunct; prmfns.ccls.to_upper = custom_lsp_toupper; prmfns.ccls.to_lower = custom_lsp_tolower; - prmfns.ccls.custom_data = ASE_NULL; + prmfns.ccls.data = ASE_NULL; prmfns.misc.sprintf = custom_lsp_sprintf; prmfns.misc.dprintf = custom_lsp_dprintf; - prmfns.misc.custom_data = ASE_NULL; + prmfns.misc.data = ASE_NULL; lsp = ase_lsp_open (&prmfns, opt_memsize, opt_meminc); if (lsp == ASE_NULL) diff --git a/ase/cmd/tgp/tgp.c b/ase/cmd/tgp/tgp.c index 85ef8ee4..6f0b665b 100644 --- a/ase/cmd/tgp/tgp.c +++ b/ase/cmd/tgp/tgp.c @@ -171,7 +171,7 @@ int tgp_main (int argc, ase_char_t* argv[]) if (handle_args (argc, argv) == -1) return -1; - tgp = ase_tgp_open (ASE_GETMMGR()); + tgp = ase_tgp_open (ASE_MMGR_GETDFL()); if (tgp == ASE_NULL) { ase_fprintf (ASE_STDERR, diff --git a/ase/include/ase/awk/awk.h b/ase/include/ase/awk/awk.h index 455eea69..bc333aab 100644 --- a/ase/include/ase/awk/awk.h +++ b/ase/include/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h 313 2008-08-03 14:06:43Z baconevi $ + * $Id: awk.h 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -25,11 +25,11 @@ typedef struct ase_awk_runcbs_t ase_awk_runcbs_t; typedef struct ase_awk_runarg_t ase_awk_runarg_t; typedef struct ase_awk_rexfns_t ase_awk_rexfns_t; -typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y); +typedef ase_real_t (*ase_awk_pow_t) (void* data, ase_real_t x, ase_real_t y); typedef int (*ase_awk_sprintf_t) ( - void* custom, ase_char_t* buf, ase_size_t size, + void* data, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); -typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...); +typedef void (*ase_awk_dprintf_t) (void* data, const ase_char_t* fmt, ...); typedef ase_ssize_t (*ase_awk_io_t) ( int cmd, void* arg, ase_char_t* data, ase_size_t count); @@ -40,7 +40,7 @@ struct ase_awk_extio_t int type; /* [IN] console, file, coproc, pipe */ int mode; /* [IN] read, write, etc */ ase_char_t* name; /* [IN] */ - void* custom_data; /* [IN] */ + void* data; /* [IN] */ void* handle; /* [OUT] */ /* input */ @@ -70,14 +70,14 @@ struct ase_awk_prmfns_t ase_awk_dprintf_t dprintf; /* required in the debug mode */ /* user-defined data passed to the functions above */ - void* custom_data; /* optional */ + void* data; /* optional */ }; struct ase_awk_srcios_t { ase_awk_io_t in; ase_awk_io_t out; - void* custom_data; + void* data; }; struct ase_awk_runios_t @@ -86,24 +86,24 @@ struct ase_awk_runios_t ase_awk_io_t coproc; ase_awk_io_t file; ase_awk_io_t console; - void* custom_data; + void* data; }; struct ase_awk_runcbs_t { void (*on_start) ( - ase_awk_run_t* run, void* custom_data); + ase_awk_run_t* run, void* data); void (*on_statement) ( - ase_awk_run_t* run, ase_size_t line, void* custom_data); + ase_awk_run_t* run, ase_size_t line, void* data); void (*on_return) ( - ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data); + ase_awk_run_t* run, ase_awk_val_t* ret, void* data); void (*on_end) ( - ase_awk_run_t* run, int errnum, void* custom_data); + ase_awk_run_t* run, int errnum, void* data); - void* custom_data; + void* data; }; struct ase_awk_runarg_t @@ -562,50 +562,42 @@ struct ase_awk_val_ref_t extern "C" { #endif -/** @brief represents the nil value */ +/** represents the nil value */ extern ase_awk_val_t* ase_awk_val_nil; -/** @brief represents an empty string */ +/** represents an empty string */ extern ase_awk_val_t* ase_awk_val_zls; -/** @brief represents a numeric value -1 */ +/** represents a numeric value -1 */ extern ase_awk_val_t* ase_awk_val_negone; -/** @brief represents a numeric value 0 */ +/** represents a numeric value 0 */ extern ase_awk_val_t* ase_awk_val_zero; -/** @brief represents a numeric value 1 */ +/** represents a numeric value 1 */ extern ase_awk_val_t* ase_awk_val_one; /* - * create an ase_awk_t instance + * NAME: create an ase_awk_t instance * - * The ase_awk_open() function is used to create a new ase_awk_t instance. - * The instance created can be passed to other ase_awk_xxx() functions and - * is valid until it is successfully destroyed using the ase_ase_close() - * function. + * DESCRIPTION: + * The ase_awk_open() function creates a new ase_awk_t instance. + * The instance created can be passed to other ase_awk_xxx() functions and + * is valid until it is successfully destroyed using the ase_ase_close() + * function. * - * The mmgr_fuser() function is called if mmgr_fuser is not ASE_NULL. - * It is passed two parameters; the memory manager pointer as passed - * into the ase_awk_open() function and the pointer to the extension - * area allocated. It should return the pointer to the location of the - * memory manager fused into the extension area. - * - * RETURNS the pointer to an ase_awk_t instance on success, ASE_NULL on failure + * RETURNS: + * the pointer to an ase_awk_t instance on success. + * ASE_NULL on failure. */ ase_awk_t* ase_awk_open ( - /* memory manager */ - ase_mmgr_t* mmgr, - /* size of extension area to allocate in bytes */ - ase_size_t extension, - /* memory manager fuser */ - ase_fuser_t mmgr_fuser + ase_mmgr_t* mmgr /* memory manager */, + ase_size_t extension /* size of extension area in bytes */, + void (*initializer) (ase_awk_t*) /* extension area initializer */ ); -ase_awk_t* ase_awk_openstd (void); - /* - * destroy an ase_awk_instance + * destroy an ase_awk_t instance * * An ase_awk_t instance should be destroyed using the ase_awk_close() function * when finished being used. The instance passed is not valid any more once @@ -784,7 +776,7 @@ int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios); int ase_awk_run ( ase_awk_t* awk, const ase_char_t* main, ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs, - ase_awk_runarg_t* runarg, void* custom_data); + ase_awk_runarg_t* runarg, void* data); void ase_awk_stop (ase_awk_run_t* run); void ase_awk_stopall (ase_awk_t* awk); diff --git a/ase/include/ase/cmn/dll.h b/ase/include/ase/cmn/dll.h index fe3222d4..f4271c9c 100644 --- a/ase/include/ase/cmn/dll.h +++ b/ase/include/ase/cmn/dll.h @@ -11,7 +11,7 @@ #include /* - * Singly Linked List + * Doubly Linked List */ typedef struct ase_dll_t ase_dll_t; typedef struct ase_dll_node_t ase_dll_node_t; @@ -69,21 +69,31 @@ extern "C" { #endif /* - * NAME creates a new singly linked list - * RETURNS a pointer to a newly created singly linked list + * NAME: creates a doubly linked list with extension area + * + * DESCRIPTION: + * The ase_dll_open() function creates an empty doubly linked list. + * If the memory manager mmgr is ASE_NULL, the function gets the default + * memory manager with ASE_MMGR_GETMMGR() and uses it if it is not ASE_NULL. + * The extension area is allocated when the positive extension size extension + * is specified. It calls the extension initialization function initializer + * after initializing the main area. The extension initializer is passed + * the pointer to the doubly linked list created. + * + * RETURNS: + * the pointer to a newly created doubly linked list on success. + * ASE_NULL on failure. + * + * WARNING: + * In the debug build, it fails the assertion if ASE_MMGR_SETMMGR() returns + * ASE_NULL when ASE_NULL is passed as the first parameter. In the release + * build, it returns ASE_NULL if such a thing happens. */ -ase_dll_t* ase_dll_open ( - ase_mmgr_t* mmgr /* memory manager */ -); -/* - * NAME creates a new singly linked list with extension - * RETURNS a pointer to a newly created singly linked list - */ -ase_dll_t* ase_dll_openx ( +ase_dll_t* ase_dll_open ( ase_mmgr_t* mmgr /* memory manager */ , - ase_size_t extension /* size of extension in bytes */, - ase_fuser_t fuser + ase_size_t extension /* size of extension area in bytes */, + void (*initializer) (ase_dll_t*) /* extension initializer */ ); /* @@ -143,6 +153,15 @@ void* ase_dll_getextension ( ase_dll_t* dll /* a singly linked list */ ); +/* + * NAME: get the pointer to the memory manager in use + */ +ase_mmgr_t* ase_dll_getmmgr ( + ase_dll_t* dll /* a singly linked list */ +); + +void ase_dll_setmmgr (ase_dll_t* dll, ase_mmgr_t* mmgr); + /* * NAME Gets the number of elements held in a singly linked list * RETURN the number of elements the list holds diff --git a/ase/include/ase/cmn/mem.h b/ase/include/ase/cmn/mem.h index 676ab9c5..45fd796d 100644 --- a/ase/include/ase/cmn/mem.h +++ b/ase/include/ase/cmn/mem.h @@ -1,5 +1,5 @@ /* - * $Id: mem.h 331 2008-08-17 14:51:40Z baconevi $ + * $Id: mem.h 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -11,22 +11,31 @@ #include /* gets a pointer to the default memory manager */ -#define ASE_MMGR_GETDFLMMGR() (ase_mmgr) +#define ASE_MMGR_GETDFL() (ase_mmgr) /* sets a pointer to the default memory manager */ -#define ASE_MMGR_SETDFLMMGR(m) ((ase_mmgr)=(m)) +#define ASE_MMGR_SETDFL(m) ((ase_mmgr)=(m)) /* allocate a memory block */ #define ASE_MMGR_ALLOC(mmgr,size) \ - (mmgr)->malloc((mmgr)->custom_data,size) + (mmgr)->malloc((mmgr)->data,size) /* reallocate a memory block */ #define ASE_MMGR_REALLOC(mmgr,ptr,size) \ - (mmgr)->realloc((mmgr)->custom_data,ptr,size) + (mmgr)->realloc((mmgr)->data,ptr,size) /* free a memory block */ #define ASE_MMGR_FREE(mmgr,ptr) \ - (mmgr)->free((mmgr)->custom_data,ptr) + (mmgr)->free((mmgr)->data,ptr) + +/* define alias for ASE_MMGR_ALLOC */ +#define ASE_MALLOC(mmgr,size) ASE_MMGR_ALLOC(mmgr,size) + +/* define alias for ASE_MMGR_REALLOC */ +#define ASE_REALLOC(mmgr,ptr,size) ASE_MMGR_REALLOC(mmgr,ptr,size) + +/* define alias for ASE_MMGR_FREE */ +#define ASE_FREE(mmgr,ptr) ASE_MMGR_FREE(mmgr,ptr) #ifdef __cplusplus extern "C" { diff --git a/ase/include/ase/cmn/sll.h b/ase/include/ase/cmn/sll.h index fda5a859..a09a9f1c 100644 --- a/ase/include/ase/cmn/sll.h +++ b/ase/include/ase/cmn/sll.h @@ -68,57 +68,49 @@ extern "C" { #endif /* - * NAME: creates a singly linked list + * NAME: creates a singly linked list with extension area * * DESCRIPTION: - * The ase_sll_open() functions creates an empty singly linked list with - * the default memory manager. + * The ase_sll_open() function creates an empty singly linked list. + * If the memory manager mmgr is ASE_NULL, the function gets the default + * memory manager with ASE_MMGR_GETMMGR() and uses it if it is not ASE_NULL. + * The extension area is allocated when the positive extension size extension + * is specified. It calls the extension initialization function initializer + * after initializing the main area. The extension initializer is passed + * the pointer to the singly linked list created. * - * RETURNS: a pointer to a newly created singly linked list + * RETURNS: + * the pointer to a newly created singly linked list on success. + * ASE_NULL on failure. + * + * WARNING: + * In the debug build, it fails the assertion if ASE_MMGR_SETMMGR() returns + * ASE_NULL when ASE_NULL is passed as the first parameter. In the release + * build, it returns ASE_NULL if such a thing happens. */ -ase_sll_t* ase_sll_open (void); -/* - * NAME: create a singly linked list with a custom memory manager - */ -ase_sll_t* ase_sll_openm ( - ase_mmgr_t* mmgr /* memory manager */ -); - -/* - * NAME: create a singly linked list securing extension area - */ -ase_sll_t* ase_sll_openx ( - ase_size_t extension /* size of extension in bytes */, - ase_fuser_t initializer /* extension initializer */ -); - -/* - * NAME creates a new singly linked list with extension - * RETURNS a pointer to a newly created singly linked list - */ -ase_sll_t* ase_sll_openmx ( +ase_sll_t* ase_sll_open ( ase_mmgr_t* mmgr /* memory manager */ , - ase_size_t extension /* size of extension in bytes */, - ase_fuser_t initializer /* extension initializer */ + ase_size_t extension /* size of extension area in bytes */, + void (*initializer) (ase_sll_t*) /* extension initializer */ ); /* - * NAME destroys a singly linked list + * NAME: destroys a singly linked list */ void ase_sll_close ( ase_sll_t* sll /* a singly linked list */ ); /* - * NAME deletes all elements of a singly linked list + * NAME: deletes all elements of a singly linked list */ void ase_sll_clear ( ase_sll_t* sll /* a singly linked list */ ); /* - * NAME specifies how to clone an element + * NAME: specifies how to clone an element * * DESCRIPTION * A special copier ASE_SLL_COPIER_INLINE is provided. This copier enables @@ -138,7 +130,7 @@ ase_sll_copier_t ase_sll_getcopier ( ); /* - * NAME specifies how to destroy an element + * NAME: specifies how to destroy an element * * DESCRIPTION * The freeer is called when a node containing the element is destroyed. @@ -153,39 +145,48 @@ ase_sll_freeer_t ase_sll_getfreeer ( ); /* - * NAME Gets the pointer to the extension area - * RETURN the pointer to the extension area + * NAME: Gets the pointer to the extension area + * RETURN:: the pointer to the extension area */ void* ase_sll_getextension ( ase_sll_t* sll /* a singly linked list */ ); /* - * NAME Gets the number of elements held in a singly linked list - * RETURN the number of elements the list holds + * NAME: get the pointer to the memory manager in use + */ +ase_mmgr_t* ase_sll_getmmgr ( + ase_sll_t* sll /* a singly linked list */ +); + +void ase_sll_setmmgr (ase_sll_t* sll, ase_mmgr_t* mmgr); + +/* + * NAME: Gets the number of elements held in a singly linked list + * RETURN: the number of elements the list holds */ ase_size_t ase_sll_getsize ( ase_sll_t* sll /* a singly linked list */ ); /* - * NAME Gets the head(first) node - * RETURN the tail node of a singly linked list + * NAME: Gets the head(first) node + * RETURN: the tail node of a singly linked list */ ase_sll_node_t* ase_sll_gethead ( ase_sll_t* sll /* a singly linked list */ ); /* - * NAME Gets the tail(last) node - * RETURN the tail node of a singly linked list + * NAME: Gets the tail(last) node + * RETURN: the tail node of a singly linked list */ ase_sll_node_t* ase_sll_gettail ( ase_sll_t* sll /* a singly linked list */ ); /* - * NAME Inserts data before a positional node given + * NAME: Inserts data before a positional node given * * DESCRIPTION * There is performance penalty unless the positional node is neither @@ -226,9 +227,9 @@ void ase_sll_poptail ( ); /* - * NAME Traverses s singly linked list + * NAME: Traverses s singly linked list * - * DESCRIPTION + * DESCRIPTION: * A singly linked list allows uni-directional in-order traversal. * The ase_sll_walk() function traverses a singly linkked list from its * head node down to its tail node as long as the walker function returns diff --git a/ase/include/ase/lsp/lsp.h b/ase/include/ase/lsp/lsp.h index 6f6b888b..5434c347 100644 --- a/ase/include/ase/lsp/lsp.h +++ b/ase/include/ase/lsp/lsp.h @@ -18,11 +18,11 @@ typedef ase_ssize_t (*ase_lsp_io_t) ( int cmd, void* arg, ase_char_t* data, ase_size_t count); typedef ase_real_t (*ase_lsp_pow_t) ( - void* custom, ase_real_t x, ase_real_t y); + void* data, ase_real_t x, ase_real_t y); typedef int (*ase_lsp_sprintf_t) ( - void* custom, ase_char_t* buf, ase_size_t size, + void* data, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); -typedef void (*ase_lsp_dprintf_t) (void* custom, const ase_char_t* fmt, ...); +typedef void (*ase_lsp_dprintf_t) (void* data, const ase_char_t* fmt, ...); struct ase_lsp_prmfns_t { @@ -34,7 +34,7 @@ struct ase_lsp_prmfns_t { ase_lsp_sprintf_t sprintf; ase_lsp_dprintf_t dprintf; - void* custom_data; + void* data; } misc; }; diff --git a/ase/include/ase/macros.h b/ase/include/ase/macros.h index 7441262f..8eea3a5f 100644 --- a/ase/include/ase/macros.h +++ b/ase/include/ase/macros.h @@ -1,5 +1,5 @@ /* - * $Id: macros.h 229 2008-06-26 10:46:39Z baconevi $ + * $Id: macros.h 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -130,37 +130,19 @@ (ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0)) #endif -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - #include - #define _CRTDBG_MAP_ALLOC - #include - - #define ASE_MALLOC(mmgr,size) malloc (size) - #define ASE_REALLOC(mmgr,ptr,size) realloc (ptr, size) - #define ASE_FREE(mmgr,ptr) free (ptr) -#else - - #define ASE_MALLOC(mmgr,size) \ - (mmgr)->malloc((mmgr)->custom_data, size) - #define ASE_REALLOC(mmgr,ptr,size) \ - (mmgr)->realloc((mmgr)->custom_data, ptr, size) - #define ASE_FREE(mmgr,ptr) \ - (mmgr)->free((mmgr)->custom_data, ptr) -#endif - -#define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->custom_data,c) -#define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->custom_data,c) -#define ASE_ISALPHA(ccls,c) (ccls)->is_alpha((ccls)->custom_data,c) -#define ASE_ISDIGIT(ccls,c) (ccls)->is_digit((ccls)->custom_data,c) -#define ASE_ISXDIGIT(ccls,c) (ccls)->is_xdigit((ccls)->custom_data,c) -#define ASE_ISALNUM(ccls,c) (ccls)->is_alnum((ccls)->custom_data,c) -#define ASE_ISSPACE(ccls,c) (ccls)->is_space((ccls)->custom_data,c) -#define ASE_ISPRINT(ccls,c) (ccls)->is_print((ccls)->custom_data,c) -#define ASE_ISGRAPH(ccls,c) (ccls)->is_graph((ccls)->custom_data,c) -#define ASE_ISCNTRL(ccls,c) (ccls)->is_cntrl((ccls)->custom_data,c) -#define ASE_ISPUNCT(ccls,c) (ccls)->is_punct((ccls)->custom_data,c) -#define ASE_TOUPPER(ccls,c) (ccls)->to_upper((ccls)->custom_data,c) -#define ASE_TOLOWER(ccls,c) (ccls)->to_lower((ccls)->custom_data,c) +#define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->data,c) +#define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->data,c) +#define ASE_ISALPHA(ccls,c) (ccls)->is_alpha((ccls)->data,c) +#define ASE_ISDIGIT(ccls,c) (ccls)->is_digit((ccls)->data,c) +#define ASE_ISXDIGIT(ccls,c) (ccls)->is_xdigit((ccls)->data,c) +#define ASE_ISALNUM(ccls,c) (ccls)->is_alnum((ccls)->data,c) +#define ASE_ISSPACE(ccls,c) (ccls)->is_space((ccls)->data,c) +#define ASE_ISPRINT(ccls,c) (ccls)->is_print((ccls)->data,c) +#define ASE_ISGRAPH(ccls,c) (ccls)->is_graph((ccls)->data,c) +#define ASE_ISCNTRL(ccls,c) (ccls)->is_cntrl((ccls)->data,c) +#define ASE_ISPUNCT(ccls,c) (ccls)->is_punct((ccls)->data,c) +#define ASE_TOUPPER(ccls,c) (ccls)->to_upper((ccls)->data,c) +#define ASE_TOLOWER(ccls,c) (ccls)->to_lower((ccls)->data,c) #ifdef __cplusplus #define ASE_BEGIN_NAMESPACE(x) namespace x { diff --git a/ase/include/ase/types.h b/ase/include/ase/types.h index 89982a76..3f0136bd 100644 --- a/ase/include/ase/types.h +++ b/ase/include/ase/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h 281 2008-07-21 14:11:04Z baconevi $ + * $Id: types.h 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -347,7 +347,7 @@ struct ase_mmgr_t ase_malloc_t malloc; ase_realloc_t realloc; ase_free_t free; - void* custom_data; + void* data; }; struct ase_ccls_t @@ -365,7 +365,7 @@ struct ase_ccls_t ase_isccls_t is_punct; ase_toccls_t to_upper; ase_toccls_t to_lower; - void* custom_data; + void* data; }; #endif diff --git a/ase/lib/awk/Awk.cpp b/ase/lib/awk/Awk.cpp index 329a92ad..4f456088 100644 --- a/ase/lib/awk/Awk.cpp +++ b/ase/lib/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp 279 2008-07-21 05:27:34Z baconevi $ + * $Id: Awk.cpp 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -7,7 +7,7 @@ #include #include -#include +#include "../cmn/mem.h" ///////////////////////////////// ASE_BEGIN_NAMESPACE(ASE) @@ -1032,7 +1032,7 @@ Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL), mmgr.malloc = allocMem; mmgr.realloc = reallocMem; mmgr.free = freeMem; - mmgr.custom_data = this; + mmgr.data = this; ccls.is_upper = isUpper; ccls.is_lower = isLower; @@ -1047,12 +1047,12 @@ Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL), ccls.is_punct = isPunct; ccls.to_upper = toUpper; ccls.to_lower = toLower; - ccls.custom_data = this; + ccls.data = this; prmfns.pow = pow; prmfns.sprintf = sprintf; prmfns.dprintf = dprintf; - prmfns.custom_data = this; + prmfns.data = this; } Awk::~Awk () @@ -1289,7 +1289,7 @@ int Awk::parse () srcios.in = sourceReader; srcios.out = sourceWriter; - srcios.custom_data = this; + srcios.data = this; int n = ase_awk_parse (awk, &srcios); if (n == -1) retrieveError (); @@ -1312,9 +1312,9 @@ int Awk::run (const char_t* main, const char_t** args, size_t nargs) runios.coproc = ASE_NULL; runios.file = fileHandler; runios.console = consoleHandler; - runios.custom_data = this; + runios.data = this; - ase_memset (&runcbs, 0, ASE_SIZEOF(runcbs)); + ASE_MEMSET (&runcbs, 0, ASE_SIZEOF(runcbs)); runcbs.on_start = onRunStart; if (runCallback) { @@ -1322,7 +1322,7 @@ int Awk::run (const char_t* main, const char_t** args, size_t nargs) runcbs.on_return = onRunReturn; runcbs.on_statement = onRunStatement; } - runcbs.custom_data = &runctx; + runcbs.data = &runctx; if (nargs > 0) { @@ -1460,7 +1460,7 @@ int Awk::addFunction ( return -1; } - //ase_memcpy (tmp, &handler, ASE_SIZEOF(handler)); + //ASE_MEMCPY (tmp, &handler, ASE_SIZEOF(handler)); *tmp = handler; size_t nameLen = ase_strlen(name); @@ -1572,7 +1572,7 @@ Awk::ssize_t Awk::pipeHandler ( int cmd, void* arg, char_t* data, size_t count) { extio_t* extio = (extio_t*)arg; - Awk* awk = (Awk*)extio->custom_data; + Awk* awk = (Awk*)extio->data; ASE_ASSERT ((extio->type & 0xFF) == ASE_AWK_EXTIO_PIPE); @@ -1604,7 +1604,7 @@ Awk::ssize_t Awk::fileHandler ( int cmd, void* arg, char_t* data, size_t count) { extio_t* extio = (extio_t*)arg; - Awk* awk = (Awk*)extio->custom_data; + Awk* awk = (Awk*)extio->data; ASE_ASSERT ((extio->type & 0xFF) == ASE_AWK_EXTIO_FILE); @@ -1636,7 +1636,7 @@ Awk::ssize_t Awk::consoleHandler ( int cmd, void* arg, char_t* data, size_t count) { extio_t* extio = (extio_t*)arg; - Awk* awk = (Awk*)extio->custom_data; + Awk* awk = (Awk*)extio->data; ASE_ASSERT ((extio->type & 0xFF) == ASE_AWK_EXTIO_CONSOLE); diff --git a/ase/lib/awk/awk.c b/ase/lib/awk/awk.c index f8ff60ac..29c52834 100644 --- a/ase/lib/awk/awk.c +++ b/ase/lib/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c 279 2008-07-21 05:27:34Z baconevi $ + * $Id: awk.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -25,19 +25,25 @@ static void free_bfn (void* awk, void* afn); } while (0) ase_awk_t* ase_awk_open ( - ase_mmgr_t* mmgr, ase_size_t extension, ase_fuser_t mmgr_fuser) + ase_mmgr_t* mmgr, ase_size_t extension, + void (*initializer) (ase_awk_t*)) { ase_awk_t* awk; - ASE_ASSERT (mmgr != ASE_NULL); - ASE_ASSERT (mmgr->malloc != ASE_NULL); - ASE_ASSERT (mmgr->free != ASE_NULL); + if (mmgr == ASE_NULL) + { + mmgr = ASE_MMGR_GETDFL(); + + ASE_ASSERTX (mmgr != ASE_NULL, + "Set the memory manager with ASE_MMGR_SETDFL()"); + + if (mmgr == ASE_NULL) return ASE_NULL; + } awk = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_awk_t) + extension); if (awk == ASE_NULL) return ASE_NULL; - ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t) + extension); - if (mmgr_fuser) mmgr = mmgr_fuser (mmgr, awk + 1); + ASE_MEMSET (awk, 0, ASE_SIZEOF(ase_awk_t) + extension); awk->mmgr = mmgr; if (ase_str_open (&awk->token.name, 128, mmgr) == ASE_NULL) @@ -214,6 +220,7 @@ ase_awk_t* ase_awk_open ( return ASE_NULL; } + if (initializer) initializer (awk); return awk; } @@ -278,7 +285,7 @@ int ase_awk_clear (ase_awk_t* awk) { awk->stopall = ASE_FALSE; - ase_memset (&awk->src.ios, 0, ASE_SIZEOF(awk->src.ios)); + ASE_MEMSET (&awk->src.ios, 0, ASE_SIZEOF(awk->src.ios)); awk->src.lex.curc = ASE_CHAR_EOF; awk->src.lex.ungotc_count = 0; awk->src.lex.line = 1; @@ -347,14 +354,24 @@ int ase_awk_clear (ase_awk_t* awk) return 0; } +void* ase_awk_getextension (ase_awk_t* awk) +{ + return (void*)(awk + 1); +} + ase_mmgr_t* ase_awk_getmmgr (ase_awk_t* awk) { return awk->mmgr; } -void* ase_awk_getextension (ase_awk_t* awk) +void ase_awk_setmmgr (ase_awk_t* awk, ase_mmgr_t* mmgr) { - return (void*)(awk + 1); + awk->mmgr = mmgr; +} + +ase_ccls_t* ase_awk_getccls (ase_awk_t* awk) +{ + return awk->ccls; } void ase_awk_setccls (ase_awk_t* awk, ase_ccls_t* ccls) diff --git a/ase/lib/awk/awk_i.h b/ase/lib/awk/awk_i.h index 3e82f78f..0178e4a0 100644 --- a/ase/lib/awk/awk_i.h +++ b/ase/lib/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h 271 2008-07-20 12:42:39Z baconevi $ + * $Id: awk_i.h 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -7,7 +7,7 @@ #ifndef _ASE_AWK_AWKI_H_ #define _ASE_AWK_AWKI_H_ -#include +#include "../cmn/mem.h" #include #include #include @@ -328,7 +328,7 @@ struct ase_awk_run_t struct { ase_awk_io_t handler[ASE_AWK_EXTIO_NUM]; - void* custom_data; + void* data; ase_awk_extio_t* chain; } extio; @@ -364,7 +364,7 @@ struct ase_awk_run_t ase_size_t errlin; ase_char_t errmsg[256]; - void* custom_data; + void* data; ase_awk_t* awk; ase_awk_runcbs_t* cbs; diff --git a/ase/lib/awk/err.c b/ase/lib/awk/err.c index e80f72d9..7a6a122c 100644 --- a/ase/lib/awk/err.c +++ b/ase/lib/awk/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c 271 2008-07-20 12:42:39Z baconevi $ + * $Id: err.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -252,7 +252,7 @@ void ase_awk_seterror ( { case 0: awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->errmsg, ASE_COUNTOF(awk->errmsg), errfmt); @@ -280,7 +280,7 @@ void ase_awk_seterror ( } awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->errmsg, ASE_COUNTOF(awk->errmsg), errfmt, (int)len, tmp); @@ -289,7 +289,7 @@ void ase_awk_seterror ( case 2: awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->errmsg, ASE_COUNTOF(awk->errmsg), errfmt, @@ -299,7 +299,7 @@ void ase_awk_seterror ( case 3: awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->errmsg, ASE_COUNTOF(awk->errmsg), errfmt, @@ -310,7 +310,7 @@ void ase_awk_seterror ( case 4: awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->errmsg, ASE_COUNTOF(awk->errmsg), errfmt, @@ -322,7 +322,7 @@ void ase_awk_seterror ( case 5: awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->errmsg, ASE_COUNTOF(awk->errmsg), errfmt, @@ -404,7 +404,7 @@ void ase_awk_setrunerror ( /* TODO: convert % to %% if the original % is not * the first % of the %% sequence */ run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->errmsg, ASE_COUNTOF(run->errmsg), errfmt); @@ -435,7 +435,7 @@ void ase_awk_setrunerror ( } run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->errmsg, ASE_COUNTOF(run->errmsg), errfmt, len, tmp); @@ -444,7 +444,7 @@ void ase_awk_setrunerror ( case 2: run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->errmsg, ASE_COUNTOF(run->errmsg), errfmt, @@ -454,7 +454,7 @@ void ase_awk_setrunerror ( case 3: run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->errmsg, ASE_COUNTOF(run->errmsg), errfmt, @@ -465,7 +465,7 @@ void ase_awk_setrunerror ( case 4: run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->errmsg, ASE_COUNTOF(run->errmsg), errfmt, @@ -477,7 +477,7 @@ void ase_awk_setrunerror ( case 5: run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->errmsg, ASE_COUNTOF(run->errmsg), errfmt, diff --git a/ase/lib/awk/extio.c b/ase/lib/awk/extio.c index 1463c7d3..631793e2 100644 --- a/ase/lib/awk/extio.c +++ b/ase/lib/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c 270 2008-07-20 05:53:29Z baconevi $ + * $Id: extio.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -135,7 +135,7 @@ int ase_awk_readextio ( p->mode = extio_mode; p->handle = ASE_NULL; p->next = ASE_NULL; - p->custom_data = run->extio.custom_data; + p->data = run->extio.data; p->in.buf[0] = ASE_T('\0'); p->in.pos = 0; @@ -492,7 +492,7 @@ int ase_awk_writeextio_str ( p->mode = extio_mode; p->handle = ASE_NULL; p->next = ASE_NULL; - p->custom_data = run->extio.custom_data; + p->data = run->extio.data; p->out.eof = ASE_FALSE; p->out.eos = ASE_FALSE; diff --git a/ase/lib/awk/jni.c b/ase/lib/awk/jni.c index 1c37d26c..1dd8b6c0 100644 --- a/ase/lib/awk/jni.c +++ b/ase/lib/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c 329 2008-08-16 14:08:53Z baconevi $ + * $Id: jni.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -16,7 +16,7 @@ #include #include -#include +#include "../cmn/mem.h" #include #include @@ -327,7 +327,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) #endif #endif - awk = ase_awk_open (ASE_MMGR_GET(), ASE_SIZEOF(awk_data_t)); + awk = ase_awk_open (ASE_NULL, ASE_SIZEOF(awk_data_t), ASE_NULL); if (awk == ASE_NULL) { THROW_NOMEM_EXCEPTION (env); @@ -339,7 +339,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) 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; + awk_data->prmfns.data = ASE_NULL; ase_awk_setccls (awk, ASE_GETCCLS()); ase_awk_setprmfns (awk, &awk_data->prmfns); @@ -428,7 +428,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj, jlong a srcios.in = read_source; srcios.out = write_source; - srcios.custom_data = &srcio_data; + srcios.data = &srcio_data; if (ase_awk_parse (awk, &srcios) == -1) { @@ -592,12 +592,12 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk runios.coproc = ASE_NULL; runios.file = process_extio; runios.console = process_extio; - runios.custom_data = &runio_data; + runios.data = &runio_data; - ase_memset (&runcbs, 0, ASE_SIZEOF(runcbs)); + ASE_MEMSET (&runcbs, 0, ASE_SIZEOF(runcbs)); runcbs.on_start = on_run_start; runcbs.on_end = on_run_end; - runcbs.custom_data = ASE_NULL; + runcbs.data = ASE_NULL; if (mfn == ASE_NULL) { @@ -1345,7 +1345,7 @@ static ase_ssize_t process_extio ( int cmd, void* arg, ase_char_t* data, ase_size_t size) { ase_awk_extio_t* epa = (ase_awk_extio_t*)arg; - runio_data_t* runio_data = (runio_data_t*)epa->custom_data; + runio_data_t* runio_data = (runio_data_t*)epa->data; switch (cmd) { diff --git a/ase/lib/awk/parse.c b/ase/lib/awk/parse.c index 70e390bf..73f6306c 100644 --- a/ase/lib/awk/parse.c +++ b/ase/lib/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c 283 2008-07-22 13:12:56Z baconevi $ + * $Id: parse.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -482,7 +482,7 @@ int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios) ASE_ASSERT (awk->parse.depth.cur.expr == 0); ase_awk_clear (awk); - ase_memcpy (&awk->src.ios, srcios, ASE_SIZEOF(awk->src.ios)); + ASE_MEMCPY (&awk->src.ios, srcios, ASE_SIZEOF(awk->src.ios)); n = parse (awk); @@ -501,7 +501,7 @@ static int parse (ase_awk_t* awk) CLRERR (awk); op = awk->src.ios.in ( - ASE_AWK_IO_OPEN, awk->src.ios.custom_data, ASE_NULL, 0); + ASE_AWK_IO_OPEN, awk->src.ios.data, ASE_NULL, 0); if (op <= -1) { /* cannot open the source file. @@ -574,7 +574,7 @@ static int parse (ase_awk_t* awk) exit_parse: if (n == 0) CLRERR (awk); if (awk->src.ios.in ( - ASE_AWK_IO_CLOSE, awk->src.ios.custom_data, ASE_NULL, 0) != 0) + ASE_AWK_IO_CLOSE, awk->src.ios.data, ASE_NULL, 0) != 0) { if (n == 0) { @@ -5220,7 +5220,7 @@ static int get_char (ase_awk_t* awk) { CLRERR (awk); n = awk->src.ios.in ( - ASE_AWK_IO_READ, awk->src.ios.custom_data, + ASE_AWK_IO_READ, awk->src.ios.data, awk->src.shared.buf, ASE_COUNTOF(awk->src.shared.buf)); if (n <= -1) { @@ -5480,7 +5480,7 @@ static int deparse (ase_awk_t* awk) CLRERR (awk); op = awk->src.ios.out ( - ASE_AWK_IO_OPEN, awk->src.ios.custom_data, ASE_NULL, 0); + ASE_AWK_IO_OPEN, awk->src.ios.data, ASE_NULL, 0); if (op <= -1) { if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESOUTOP); @@ -5676,7 +5676,7 @@ static int deparse (ase_awk_t* awk) exit_deparse: if (n == 0) CLRERR (awk); if (awk->src.ios.out ( - ASE_AWK_IO_CLOSE, awk->src.ios.custom_data, ASE_NULL, 0) != 0) + ASE_AWK_IO_CLOSE, awk->src.ios.data, ASE_NULL, 0) != 0) { if (n == 0) { @@ -5749,7 +5749,7 @@ static int flush_out (ase_awk_t* awk) CLRERR (awk); n = awk->src.ios.out ( - ASE_AWK_IO_WRITE, awk->src.ios.custom_data, + ASE_AWK_IO_WRITE, awk->src.ios.data, &awk->src.shared.buf[awk->src.shared.buf_pos], awk->src.shared.buf_len - awk->src.shared.buf_pos); if (n <= 0) diff --git a/ase/lib/awk/rec.c b/ase/lib/awk/rec.c index 00442e8c..6c0fb564 100644 --- a/ase/lib/awk/rec.c +++ b/ase/lib/awk/rec.c @@ -1,5 +1,5 @@ /* - * $Id: rec.c 270 2008-07-20 05:53:29Z baconevi $ + * $Id: rec.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -320,7 +320,7 @@ static int recomp_record_fields ( } if (run->inrec.flds != ASE_NULL) { - ase_memcpy (tmp, run->inrec.flds, + ASE_MEMCPY (tmp, run->inrec.flds, ASE_SIZEOF(*run->inrec.flds)*run->inrec.maxflds); ASE_AWK_FREE (run->awk, run->inrec.flds); } diff --git a/ase/lib/awk/run.c b/ase/lib/awk/run.c index fdd6a228..53982fcd 100644 --- a/ase/lib/awk/run.c +++ b/ase/lib/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c 271 2008-07-20 12:42:39Z baconevi $ + * $Id: run.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -62,7 +62,7 @@ static int set_global ( static int init_run ( ase_awk_run_t* run, ase_awk_t* awk, - ase_awk_runios_t* runios, void* custom_data); + ase_awk_runios_t* runios, void* data); static void deinit_run (ase_awk_run_t* run); static int build_runarg ( @@ -601,7 +601,7 @@ ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* run) void* ase_awk_getruncustomdata (ase_awk_run_t* run) { - return run->custom_data; + return run->data; } ase_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* run) @@ -614,7 +614,7 @@ int ase_awk_run (ase_awk_t* awk, ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs, ase_awk_runarg_t* runarg, - void* custom_data) + void* data) { ase_awk_run_t* run; int n; @@ -648,10 +648,10 @@ int ase_awk_run (ase_awk_t* awk, } /* clear the run object space */ - ase_memset (run, 0, ASE_SIZEOF(ase_awk_run_t)); + ASE_MEMSET (run, 0, ASE_SIZEOF(ase_awk_run_t)); /* initialize the run object */ - if (init_run (run, awk, runios, custom_data) == -1) + if (init_run (run, awk, runios, data) == -1) { ASE_AWK_FREE (awk, run); return -1; @@ -667,7 +667,7 @@ int ase_awk_run (ase_awk_t* awk, /* execute the start callback if it exists */ if (runcbs != ASE_NULL && runcbs->on_start != ASE_NULL) { - runcbs->on_start (run, runcbs->custom_data); + runcbs->on_start (run, runcbs->data); } /* enter the main run loop */ @@ -702,7 +702,7 @@ int ase_awk_run (ase_awk_t* awk, runcbs->on_end (run, ((n == -1)? run->errnum: ASE_AWK_ENOERR), - runcbs->custom_data); + runcbs->data); /* when using callbacks, this function always returns 0 * after the start callbacks has been triggered */ @@ -738,10 +738,10 @@ static void same_namedval (void* run, void* val) static int init_run ( ase_awk_run_t* run, ase_awk_t* awk, - ase_awk_runios_t* runios, void* custom_data) + ase_awk_runios_t* runios, void* data) { run->awk = awk; - run->custom_data = custom_data; + run->data = data; run->stack = ASE_NULL; run->stack_top = 0; @@ -830,7 +830,7 @@ static int init_run ( return -1; } - ase_memset ( + ASE_MEMSET ( run->pattern_range_state, 0, run->awk->tree.chain_size * ASE_SIZEOF(ase_byte_t)); } @@ -842,7 +842,7 @@ static int init_run ( run->extio.handler[ASE_AWK_EXTIO_COPROC] = runios->coproc; run->extio.handler[ASE_AWK_EXTIO_FILE] = runios->file; run->extio.handler[ASE_AWK_EXTIO_CONSOLE] = runios->console; - run->extio.custom_data = runios->custom_data; + run->extio.data = runios->data; run->extio.chain = ASE_NULL; } @@ -1362,7 +1362,7 @@ static int run_main ( { if (run->cbs != ASE_NULL && run->cbs->on_return != ASE_NULL) { - run->cbs->on_return (run, crdata.val, run->cbs->custom_data); + run->cbs->on_return (run, crdata.val, run->cbs->data); } } else n = -1; @@ -1376,7 +1376,7 @@ static int run_main ( if (run->cbs != ASE_NULL && run->cbs->on_return != ASE_NULL) { - run->cbs->on_return (run, v, run->cbs->custom_data); + run->cbs->on_return (run, v, run->cbs->data); } ase_awk_refdownval (run, v); @@ -1533,7 +1533,7 @@ static int run_main ( { if (run->cbs != ASE_NULL && run->cbs->on_return != ASE_NULL) { - run->cbs->on_return (run, v, run->cbs->custom_data); + run->cbs->on_return (run, v, run->cbs->data); } } /* end the life of the global return value */ @@ -1847,7 +1847,7 @@ static int run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) (run)->cbs->on_statement != ASE_NULL) \ { \ (run)->cbs->on_statement ( \ - run, (nde)->line, (run)->cbs->custom_data); \ + run, (nde)->line, (run)->cbs->data); \ } static int run_statement (ase_awk_run_t* run, ase_awk_nde_t* nde) @@ -4594,7 +4594,7 @@ static ase_awk_val_t* eval_binop_exp ( /* left - int, right - real */ res = ase_awk_makerealval (run, run->awk->prmfns->pow ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, (ase_real_t)l1,(ase_real_t)r2)); } else @@ -4603,7 +4603,7 @@ static ase_awk_val_t* eval_binop_exp ( ASE_ASSERT (n3 == 3); res = ase_awk_makerealval (run, run->awk->prmfns->pow( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, (ase_real_t)r1,(ase_real_t)r2)); } @@ -6294,7 +6294,7 @@ static int __raw_push (ase_awk_run_t* run, void* val) if (tmp == ASE_NULL) return -1; if (run->stack != ASE_NULL) { - ase_memcpy ( + ASE_MEMCPY ( tmp, run->stack, run->stack_limit * ASE_SIZEOF(void*)); ASE_AWK_FREE (run->awk, run->stack); @@ -6664,7 +6664,7 @@ ase_char_t* ase_awk_format ( do { n = run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->format.tmp.ptr, run->format.tmp.len, #if ASE_SIZEOF_LONG_LONG > 0 @@ -6770,7 +6770,7 @@ ase_char_t* ase_awk_format ( do { n = run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->format.tmp.ptr, run->format.tmp.len, #if ASE_SIZEOF_LONG_LONG > 0 @@ -6891,7 +6891,7 @@ ase_char_t* ase_awk_format ( do { n = run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->format.tmp.ptr, run->format.tmp.len, ASE_STR_BUF(fbu), @@ -6979,7 +6979,7 @@ ase_char_t* ase_awk_format ( do { n = run->awk->prmfns->sprintf ( - run->awk->prmfns->custom_data, + run->awk->prmfns->data, run->format.tmp.ptr, run->format.tmp.len, ASE_STR_BUF(fbu), diff --git a/ase/lib/awk/std.c b/ase/lib/awk/std.c index d9eafe5f..9ead65ac 100644 --- a/ase/lib/awk/std.c +++ b/ase/lib/awk/std.c @@ -45,14 +45,14 @@ ase_awk_t* ase_awk_openstd (void) ase_awk_t* awk; ext_t* ext; - awk = ase_awk_open (ASE_MMGR_GET(), ASE_SIZEOF(ext_t), ASE_NULL); + awk = ase_awk_open (ASE_NULL, ASE_SIZEOF(ext_t), ASE_NULL); ase_awk_setccls (awk, ASE_GETCCLS()); ext = (ext_t*) ase_awk_getextension (awk); - ext->prmfns.pow = custom_awk_pow; - ext->prmfns.sprintf = custom_awk_sprintf; - ext->prmfns.dprintf = custom_awk_dprintf; - ext->prmfns.custom_data = ASE_NULL; + ext->prmfns.pow = custom_awk_pow; + ext->prmfns.sprintf = custom_awk_sprintf; + ext->prmfns.dprintf = custom_awk_dprintf; + ext->prmfns.data = ASE_NULL; ase_awk_setprmfns (awk, &ext->prmfns); ase_awk_setoption (awk, diff --git a/ase/lib/awk/tab.c b/ase/lib/awk/tab.c index 52de618d..48003717 100644 --- a/ase/lib/awk/tab.c +++ b/ase/lib/awk/tab.c @@ -1,5 +1,5 @@ /* - * $Id: tab.c 270 2008-07-20 05:53:29Z baconevi $ + * $Id: tab.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -75,7 +75,7 @@ ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa) { ase_size_t x; x = (capa > tab->capa)? tab->capa: capa; - ase_memcpy ( + ASE_MEMCPY ( tmp, tab->buf, ASE_SIZEOF(*tab->buf) * x); ASE_AWK_FREE (tab->awk, tab->buf); diff --git a/ase/lib/awk/tree.c b/ase/lib/awk/tree.c index b21e6482..99db1192 100644 --- a/ase/lib/awk/tree.c +++ b/ase/lib/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c 271 2008-07-20 12:42:39Z baconevi $ + * $Id: tree.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -264,12 +264,12 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde) { #if (ASE_SIZEOF_LONG_DOUBLE != 0) awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%Lf"), (long double)((ase_awk_nde_real_t*)nde)->val); #elif (ASE_SIZEOF_DOUBLE != 0) awk->prmfns->sprintf ( - awk->prmfns->custom_data, + awk->prmfns->data, awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%f"), (double)((ase_awk_nde_real_t*)nde)->val); #else diff --git a/ase/lib/awk/val.c b/ase/lib/awk/val.c index 99b12a37..12dc42cf 100644 --- a/ase/lib/awk/val.c +++ b/ase/lib/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c 271 2008-07-20 12:42:39Z baconevi $ + * $Id: val.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -400,7 +400,7 @@ ase_awk_val_t* ase_awk_makerexval ( } */ val->code = val->buf + len + 1; - ase_memcpy (val->code, code, ASE_REX_LEN(code)); + ASE_MEMCPY (val->code, code, ASE_REX_LEN(code)); return (ase_awk_val_t*)val; } @@ -1060,7 +1060,7 @@ int ase_awk_strtonum ( } #define DPRINTF run->awk->prmfns->dprintf -#define DCUSTOM run->awk->prmfns->custom_data +#define DCUSTOM run->awk->prmfns->data static int print_pair (ase_pair_t* pair, void* arg) { diff --git a/ase/lib/cmn/dll.c b/ase/lib/cmn/dll.c index 05c1bd96..14e15f20 100644 --- a/ase/lib/cmn/dll.c +++ b/ase/lib/cmn/dll.c @@ -13,22 +13,30 @@ void* ase_dll_copyinline (ase_dll_t* dll, void* dptr, ase_size_t dlen) return ASE_NULL; } -ase_dll_t* ase_dll_open (ase_mmgr_t* mmgr) -{ - return ase_dll_openx (mmgr, 0, ASE_NULL); -} - -ase_dll_t* ase_dll_openx (ase_mmgr_t* mmgr, ase_size_t extension, ase_fuser_t fuser) +ase_dll_t* ase_dll_open ( + ase_mmgr_t* mmgr, ase_size_t extension, + void (*initializer) (ase_dll_t*)) { ase_dll_t* dll; + if (mmgr == ASE_NULL) + { + mmgr = ASE_MMGR_GETDFL(); + + ASE_ASSERTX (mmgr != ASE_NULL, + "Set the memory manager with ASE_MMGR_SETDFL()"); + + if (mmgr == ASE_NULL) return ASE_NULL; + } + dll = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_dll_t) + extension); if (dll == ASE_NULL) return ASE_NULL; ASE_MEMSET (dll, 0, ASE_SIZEOF(ase_dll_t) + extension); - if (fuser != ASE_NULL) mmgr = fuser (mmgr, dll + 1); dll->mmgr = mmgr; + if (initializer) initializer (dll); + return dll; } @@ -49,6 +57,16 @@ void* ase_dll_getextension (ase_dll_t* dll) return dll + 1; } +ase_mmgr_t* ase_dll_getmmgr (ase_dll_t* dll) +{ + return dll->mmgr; +} + +void ase_dll_setmmgr (ase_dll_t* dll, ase_mmgr_t* mmgr) +{ + dll->mmgr = mmgr; +} + ase_size_t ase_dll_getsize (ase_dll_t* dll) { return dll->size; diff --git a/ase/lib/cmn/map.c b/ase/lib/cmn/map.c index 64857247..2cb397e7 100644 --- a/ase/lib/cmn/map.c +++ b/ase/lib/cmn/map.c @@ -1,11 +1,12 @@ /* - * $Id: map.c 156 2008-03-22 12:09:35Z baconevi $ + * $Id: map.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ #include #include +#include "mem.h" static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen); static int rehash (ase_map_t* map); diff --git a/ase/lib/cmn/rex.c b/ase/lib/cmn/rex.c index ffc130b7..99cb2b1e 100644 --- a/ase/lib/cmn/rex.c +++ b/ase/lib/cmn/rex.c @@ -1,11 +1,11 @@ /* - * $Id: rex.c 223 2008-06-26 06:44:41Z baconevi $ + * $Id: rex.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ #include -#include +#include "mem.h" #ifdef DEBUG_REX #include @@ -1108,7 +1108,7 @@ static int add_code (builder_t* builder, void* data, ase_size_t len) if (builder->code.buf != ASE_NULL) { - ase_memcpy (tmp, builder->code.buf, builder->code.capa); + ASE_MEMCPY (tmp, builder->code.buf, builder->code.capa); ASE_FREE (builder->mmgr, builder->code.buf); } } @@ -1117,7 +1117,7 @@ static int add_code (builder_t* builder, void* data, ase_size_t len) builder->code.capa = capa; } - ase_memcpy (&builder->code.buf[builder->code.size], data, len); + ASE_MEMCPY (&builder->code.buf[builder->code.size], data, len); builder->code.size += len; return 0; diff --git a/ase/lib/cmn/sll.c b/ase/lib/cmn/sll.c index da3f2ce3..0701bcfb 100644 --- a/ase/lib/cmn/sll.c +++ b/ase/lib/cmn/sll.c @@ -13,27 +13,21 @@ void* ase_sll_copyinline (ase_sll_t* sll, void* dptr, ase_size_t dlen) return ASE_NULL; } -ase_sll_t* ase_sll_open (void) -{ - return ase_sll_openx (ASE_MMGR_GETDFLMMGR(), 0, ASE_NULL); -} - -ase_sll_openm (ase_mmgr_t* mmgr) -{ - return ase_sll_openx (mmgr, 0, ASE_NULL); -} - -ase_sll_openx (ase_size_t extension, ase_fuser_t initializer) -{ - return ase_sll_openx (mmgr, 0, ASE_NULL); -} - -ase_sll_t* ase_sll_openmx ( - ase_mmgr_t* mmgr, ase_size_t extension, ase_fuser_t initializer) +ase_sll_t* ase_sll_open ( + ase_mmgr_t* mmgr, ase_size_t extension, + void (*initializer) (ase_sll_t*)) { ase_sll_t* sll; - if (mmgr == ASE_NULL) mmgr = ASE_MMGR_GET (); + if (mmgr == ASE_NULL) + { + mmgr = ASE_MMGR_GETDFL(); + + ASE_ASSERTX (mmgr != ASE_NULL, + "Set the memory manager with ASE_MMGR_SETDFL()"); + + if (mmgr == ASE_NULL) return ASE_NULL; + } sll = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_sll_t) + extension); if (sll == ASE_NULL) return ASE_NULL; @@ -41,7 +35,7 @@ ase_sll_t* ase_sll_openmx ( ASE_MEMSET (sll, 0, ASE_SIZEOF(ase_sll_t) + extension); sll->mmgr = mmgr; - if (initializer != ASE_NULL) mmgr = initializer (sll, sll + 1); + if (initializer) initializer (sll); return sll; } @@ -63,6 +57,16 @@ void* ase_sll_getextension (ase_sll_t* sll) return sll + 1; } +ase_mmgr_t* ase_sll_getmmgr (ase_sll_t* sll) +{ + return sll->mmgr; +} + +void ase_sll_setmmgr (ase_sll_t* sll, ase_mmgr_t* mmgr) +{ + sll->mmgr = mmgr; +} + ase_size_t ase_sll_getsize (ase_sll_t* sll) { return sll->size; diff --git a/ase/lib/cmn/str_bas.c b/ase/lib/cmn/str_bas.c index 4a3e1d4b..e9eebcf4 100644 --- a/ase/lib/cmn/str_bas.c +++ b/ase/lib/cmn/str_bas.c @@ -1,11 +1,11 @@ /* - * $Id: str_bas.c 197 2008-06-09 06:24:10Z baconevi $ + * $Id: str_bas.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ #include -#include +#include "mem.h" ase_size_t ase_strlen (const ase_char_t* str) { @@ -80,7 +80,7 @@ ase_size_t ase_strxncpy ( if (bsz <= 0) return 0; if ((n = bsz - 1) > len) n = len; - ase_memcpy (buf, str, n * ASE_SIZEOF(ase_char_t)); + ASE_MEMCPY (buf, str, n * ASE_SIZEOF(ase_char_t)); buf[n] = ASE_T('\0'); return n; diff --git a/ase/lib/cmn/str_cnv.c b/ase/lib/cmn/str_cnv.c index 6c395d64..e665718b 100644 --- a/ase/lib/cmn/str_cnv.c +++ b/ase/lib/cmn/str_cnv.c @@ -1,11 +1,10 @@ /* - * $Id: str_cnv.c 142 2008-03-18 06:29:25Z baconevi $ + * $Id: str_cnv.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ #include -#include int ase_strtoi (const ase_char_t* str) { diff --git a/ase/lib/cmn/str_dyn.c b/ase/lib/cmn/str_dyn.c index 3cc214c2..127a676c 100644 --- a/ase/lib/cmn/str_dyn.c +++ b/ase/lib/cmn/str_dyn.c @@ -1,11 +1,11 @@ /* - * $Id: str_dyn.c 197 2008-06-09 06:24:10Z baconevi $ + * $Id: str_dyn.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ #include -#include +#include "mem.h" ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr) { @@ -129,7 +129,7 @@ ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len) if (tmp == ASE_NULL) return (ase_size_t)-1; if (str->buf != ASE_NULL) { - ase_memcpy (tmp, str->buf, + ASE_MEMCPY (tmp, str->buf, ASE_SIZEOF(ase_char_t)*(str->capa+1)); ASE_FREE (str->mmgr, str->buf); } diff --git a/ase/lib/lsp/err.c b/ase/lib/lsp/err.c index 840ee92b..986858b8 100644 --- a/ase/lib/lsp/err.c +++ b/ase/lib/lsp/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c 215 2008-06-19 10:27:37Z baconevi $ + * $Id: err.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -64,7 +64,7 @@ void ase_lsp_seterror ( { case 0: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt); @@ -72,7 +72,7 @@ void ase_lsp_seterror ( case 1: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -81,7 +81,7 @@ void ase_lsp_seterror ( case 2: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -91,7 +91,7 @@ void ase_lsp_seterror ( case 3: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -102,7 +102,7 @@ void ase_lsp_seterror ( case 4: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -114,7 +114,7 @@ void ase_lsp_seterror ( case 5: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, diff --git a/ase/lib/lsp/lsp.c b/ase/lib/lsp/lsp.c index 15e17bf4..7bf0099d 100644 --- a/ase/lib/lsp/lsp.c +++ b/ase/lib/lsp/lsp.c @@ -1,5 +1,5 @@ /* - * $Id: lsp.c 232 2008-06-28 09:38:00Z baconevi $ + * $Id: lsp.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -46,14 +46,14 @@ ase_lsp_t* ase_lsp_open ( lsp = (ase_lsp_t*) malloc (ASE_SIZEOF(ase_lsp_t)); #else lsp = (ase_lsp_t*) prmfns->mmgr.malloc ( - prmfns->mmgr.custom_data, ASE_SIZEOF(ase_lsp_t)); + prmfns->mmgr.data, ASE_SIZEOF(ase_lsp_t)); #endif if (lsp == ASE_NULL) return ASE_NULL; /* it uses the built-in ase_lsp_memset because lsp is not * fully initialized yet */ - ase_memset (lsp, 0, ASE_SIZEOF(ase_lsp_t)); - ase_memcpy (&lsp->prmfns, prmfns, ASE_SIZEOF(lsp->prmfns)); + ASE_MEMSET (lsp, 0, ASE_SIZEOF(ase_lsp_t)); + ASE_MEMCPY (&lsp->prmfns, prmfns, ASE_SIZEOF(lsp->prmfns)); lsp->assoc_data = ASE_NULL; if (ase_lsp_name_open(&lsp->token.name, 0, lsp) == ASE_NULL) diff --git a/ase/lib/lsp/lsp_i.h b/ase/lib/lsp/lsp_i.h index a0efa1ba..66cbb277 100644 --- a/ase/lib/lsp/lsp_i.h +++ b/ase/lib/lsp/lsp_i.h @@ -1,5 +1,5 @@ /* - * $Id: lsp_i.h 232 2008-06-28 09:38:00Z baconevi $ + * $Id: lsp_i.h 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -7,7 +7,7 @@ #ifndef _ASE_LSP_LSPI_H_ #define _ASE_LSP_LSPI_H_ -#include +#include "../cmn/mem.h" #include #include diff --git a/ase/lib/lsp/mem.c b/ase/lib/lsp/mem.c index b811214b..5845835e 100644 --- a/ase/lib/lsp/mem.c +++ b/ase/lib/lsp/mem.c @@ -1,5 +1,5 @@ /* - * $Id: mem.c 215 2008-06-19 10:27:37Z baconevi $ + * $Id: mem.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -16,7 +16,7 @@ ase_lsp_mem_t* ase_lsp_openmem ( mem = (ase_lsp_mem_t*) ASE_LSP_MALLOC (lsp, ASE_SIZEOF(ase_lsp_mem_t)); if (mem == ASE_NULL) return ASE_NULL; - ase_memset (mem, 0, ASE_SIZEOF(ase_lsp_mem_t)); + ASE_MEMSET (mem, 0, ASE_SIZEOF(ase_lsp_mem_t)); mem->lsp = lsp; /* create a new root environment frame */ diff --git a/ase/lib/lsp/name.c b/ase/lib/lsp/name.c index f860cd46..b2b7445f 100644 --- a/ase/lib/lsp/name.c +++ b/ase/lib/lsp/name.c @@ -1,5 +1,5 @@ /* - * $Id: name.c 215 2008-06-19 10:27:37Z baconevi $ + * $Id: name.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -71,7 +71,7 @@ int ase_lsp_name_addc (ase_lsp_name_t* name, ase_cint_t c) if (space == ASE_NULL) return -1; /* don't need to copy up to the terminating null */ - ase_memcpy (space, name->buf, name->capa*ASE_SIZEOF(ase_char_t)); + ASE_MEMCPY (space, name->buf, name->capa*ASE_SIZEOF(ase_char_t)); } else { diff --git a/ase/lib/lsp/print.c b/ase/lib/lsp/print.c index b287ee67..4b619fa4 100644 --- a/ase/lib/lsp/print.c +++ b/ase/lib/lsp/print.c @@ -1,5 +1,5 @@ /* - * $Id: print.c 215 2008-06-19 10:27:37Z baconevi $ + * $Id: print.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ @@ -45,22 +45,22 @@ static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_con case ASE_LSP_OBJ_INT: #if ASE_SIZEOF_LONG_LONG > 0 lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, buf, ASE_COUNTOF(buf), ASE_T("%lld"), (long long)ASE_LSP_IVAL(obj)); #elif ASE_SIZEOF___INT64 > 0 lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, buf, ASE_COUNTOF(buf), ASE_T("%I64d"), (__int64)ASE_LSP_IVAL(obj)); #elif ASE_SIZEOF_LONG > 0 lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, buf, ASE_COUNTOF(buf), ASE_T("%ld"), (long)ASE_LSP_IVAL(obj)); #elif ASE_SIZEOF_INT > 0 lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, buf, ASE_COUNTOF(buf), ASE_T("%d"), (int)ASE_LSP_IVAL(obj)); #else @@ -71,7 +71,7 @@ static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_con case ASE_LSP_OBJ_REAL: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, buf, ASE_COUNTOF(buf), ASE_T("%Lf"), (long double)ASE_LSP_RVAL(obj)); @@ -135,7 +135,7 @@ static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_con default: lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, + lsp->prmfns.misc.data, buf, ASE_COUNTOF(buf), ASE_T("unknown object type: %d"), ASE_LSP_TYPE(obj)); OUTPUT_STR (lsp, buf); diff --git a/ase/lib/utl/http.c b/ase/lib/utl/http.c index c16c7d15..6550d6ea 100644 --- a/ase/lib/utl/http.c +++ b/ase/lib/utl/http.c @@ -1,12 +1,12 @@ /* - * $Id: http.c 186 2008-06-03 09:00:14Z baconevi $ + * $Id: http.c 332 2008-08-18 11:21:48Z baconevi $ * * {License} */ #include #include -#include +#include "../cmn/mem.h" static int is_http_space (ase_char_t c) { @@ -152,7 +152,7 @@ ase_char_t* ase_parsehttphdr (ase_char_t* buf, ase_http_hdr_t* hdr) if (*p == ASE_T('\0')) { /* no more header line */ - ase_memset (hdr, 0, ASE_SIZEOF(*hdr)); + ASE_MEMSET (hdr, 0, ASE_SIZEOF(*hdr)); return p; }