diff --git a/ase/awk/makefile.cl b/ase/awk/makefile.cl index 81538f5b..c16a4a3d 100644 --- a/ase/awk/makefile.cl +++ b/ase/awk/makefile.cl @@ -11,7 +11,7 @@ JAVA_INC = \ CC = cl #CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. -CFLAGS = /nologo /O2 /MT /W3 /GR- /Za /D_WIN32_WINNT=0x0400 -I../.. -DXP_AWK_STAND_ALONE -DXP_CHAR_IS_WCHAR $(JAVA_INC) +CFLAGS = /nologo /O2 /MT /W3 /GR- /Za /D_WIN32_WINNT=0x0400 -I../.. -DXP_AWK_STAND_ALONE -DXP_CHAR_IS_WCHAR $(JAVA_INC) all: lib diff --git a/ase/awk/rex.c b/ase/awk/rex.c index bf82f86b..7ea1f6dc 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,5 +1,5 @@ /* - * $Id: rex.c,v 1.21 2006-08-16 09:35:21 bacon Exp $ + * $Id: rex.c,v 1.22 2006-08-16 11:35:53 bacon Exp $ */ #include @@ -187,6 +187,7 @@ static const xp_byte_t* __match_boundary ( static xp_bool_t __test_charset ( const xp_byte_t* p, xp_size_t csc, xp_char_t c); +#ifndef XP_AWK_NTDDK static xp_bool_t __cc_isalnum (xp_char_t c); static xp_bool_t __cc_isalpha (xp_char_t c); static xp_bool_t __cc_isblank (xp_char_t c); @@ -199,11 +200,13 @@ static xp_bool_t __cc_ispunct (xp_char_t c); static xp_bool_t __cc_isspace (xp_char_t c); static xp_bool_t __cc_isupper (xp_char_t c); static xp_bool_t __cc_isxdigit (xp_char_t c); +#endif static const xp_byte_t* __print_pattern (const xp_byte_t* p); static const xp_byte_t* __print_branch (const xp_byte_t* p); static const xp_byte_t* __print_atom (const xp_byte_t* p); +#ifndef XP_AWK_NTDDK static struct __char_class_t { const xp_char_t* name; @@ -237,6 +240,7 @@ static struct __char_class_t __char_class [] = { XP_NULL, 0, XP_NULL } }; +#endif void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len, int* errnum) { @@ -340,10 +344,9 @@ int xp_awk_safematchrex (void* code, return (mat.matched)? 1: 0; } -void xp_awk_printrex (void* rex) +void xp_awk_freerex (void* code) { - __print_pattern (rex); - xp_printf (XP_T("\n")); + xp_free (code); } static int __build_pattern (__builder_t* builder) @@ -590,6 +593,7 @@ static int __build_charset (__builder_t* builder, struct __code_t* cmd) c1 = builder->ptn.curc.value; NEXT_CHAR(builder, LEVEL_CHARSET); +#ifndef XP_AWK_NTDDK if (c1 == XP_T('[') && builder->ptn.curc.type == CT_NORMAL && builder->ptn.curc.value == XP_T(':')) @@ -597,6 +601,7 @@ static int __build_charset (__builder_t* builder, struct __code_t* cmd) if (__build_cclass (builder, &c1) == -1) return -1; cc = cc | 1; } +#endif c2 = c1; if (builder->ptn.curc.type == CT_NORMAL && @@ -609,6 +614,7 @@ static int __build_charset (__builder_t* builder, struct __code_t* cmd) c2 = builder->ptn.curc.value; NEXT_CHAR (builder, LEVEL_CHARSET); +#ifndef XP_AWK_NTDDK if (c2 == XP_T('[') && builder->ptn.curc.type == CT_NORMAL && builder->ptn.curc.value == XP_T(':')) @@ -620,6 +626,7 @@ static int __build_charset (__builder_t* builder, struct __code_t* cmd) cc = cc | 2; } +#endif } else cc = cc | 4; } @@ -662,6 +669,7 @@ static int __build_charset (__builder_t* builder, struct __code_t* cmd) return 1; } +#ifndef XP_AWK_NTDDK static int __build_cclass (__builder_t* builder, xp_char_t* cc) { const struct __char_class_t* ccp = __char_class; @@ -708,6 +716,7 @@ static int __build_cclass (__builder_t* builder, xp_char_t* cc) *cc = (xp_char_t)(ccp - __char_class); return 1; } +#endif static int __build_boundary (__builder_t* builder, struct __code_t* cmd) { @@ -768,7 +777,8 @@ static int __build_range (__builder_t* builder, struct __code_t* cmd) // what if it is not in the raight format? convert it to ordinary characters?? bound = 0; while (builder->ptn.curc.type == CT_NORMAL && - xp_isdigit(builder->ptn.curc.value)) + (builder->ptn.curc.value >= XP_T('0') && + builder->ptn.curc.value <= XP_T('9'))) { bound = bound * 10 + builder->ptn.curc.value - XP_T('0'); NEXT_CHAR (builder, LEVEL_RANGE); @@ -783,7 +793,8 @@ static int __build_range (__builder_t* builder, struct __code_t* cmd) bound = 0; while (builder->ptn.curc.type == CT_NORMAL && - xp_isdigit(builder->ptn.curc.value)) + (builder->ptn.curc.value >= XP_T('0') && + builder->ptn.curc.value <= XP_T('9'))) { bound = bound * 10 + builder->ptn.curc.value - XP_T('0'); NEXT_CHAR (builder, LEVEL_RANGE); @@ -872,15 +883,29 @@ static int __add_code (__builder_t* builder, void* data, xp_size_t len) xp_size_t capa = builder->code.capa * 2; xp_byte_t* tmp; - if (capa == 0) capa = 1; + if (capa == 0) capa = 256; while (len > capa - builder->code.size) { capa = capa * 2; } +#ifndef XP_AWK_NTDDK tmp = (xp_byte_t*) xp_realloc (builder->code.buf, capa); if (tmp == XP_NULL) { builder->errnum = XP_AWK_ENOMEM; return -1; } +#else + tmp = (xp_byte_t*) xp_malloc (capa); + if (tmp == XP_NULL) + { + builder->errnum = XP_AWK_ENOMEM; + return -1; + } + if (builder->code.buf != XP_NULL) + { + xp_memcpy (tmp, builder->code.buf, builder->code.capa); + xp_free (builder->code.buf); + } +#endif builder->code.buf = tmp; builder->code.capa = capa; @@ -1454,11 +1479,13 @@ xp_bool_t __test_charset (const xp_byte_t* p, xp_size_t csc, xp_char_t c) if (c >= c1 && c <= c2) return xp_true; } +#ifndef XP_AWK_NTDDK else if (c0 == CHARSET_CLASS) { c1 = *(xp_char_t*)p; if (__char_class[c1].func (c)) return xp_true; } +#endif else { xp_assert (!"should never happen - invalid charset code"); @@ -1471,6 +1498,8 @@ xp_bool_t __test_charset (const xp_byte_t* p, xp_size_t csc, xp_char_t c) return xp_false; } +#ifndef XP_AWK_NTDDK + static xp_bool_t __cc_isalnum (xp_char_t c) { return xp_isalnum (c); @@ -1531,6 +1560,12 @@ static xp_bool_t __cc_isxdigit (xp_char_t c) return xp_isxdigit (c); } +void xp_awk_printrex (void* rex) +{ + __print_pattern (rex); + xp_printf (XP_T("\n")); +} + static const xp_byte_t* __print_pattern (const xp_byte_t* p) { xp_size_t nb, el, i; @@ -1660,3 +1695,5 @@ static const xp_byte_t* __print_atom (const xp_byte_t* p) return p; } + +#endif diff --git a/ase/awk/rex.h b/ase/awk/rex.h index e0b2aafb..4c9d9dc0 100644 --- a/ase/awk/rex.h +++ b/ase/awk/rex.h @@ -1,5 +1,5 @@ /* - * $Id: rex.h,v 1.12 2006-08-16 08:55:43 bacon Exp $ + * $Id: rex.h,v 1.13 2006-08-16 11:35:53 bacon Exp $ **/ #ifndef _XP_AWK_REX_H_ @@ -60,7 +60,11 @@ int xp_awk_safematchrex (void* code, const xp_char_t** match_ptr, xp_size_t* match_len, int max_depth, int* errnum); +void xp_awk_freerex (void* code); + +#ifndef XP_AWK_NTDDK void xp_awk_printrex (void* code); +#endif #ifdef __cplusplus } diff --git a/ase/awk/run.c b/ase/awk/run.c index f73fb4c8..1c583582 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.166 2006-08-13 16:04:32 bacon Exp $ + * $Id: run.c,v 1.167 2006-08-16 11:35:53 bacon Exp $ */ #include @@ -4248,13 +4248,25 @@ static int __raw_push (xp_awk_run_t* run, void* val) { if (run->stack_top >= run->stack_limit) { - void* tmp; + void** tmp; xp_size_t n; n = run->stack_limit + STACK_INCREMENT; - tmp = (void**) xp_realloc (run->stack, n * xp_sizeof(void*)); - if (tmp == XP_NULL) return -1; +#ifndef XP_AWK_NTDDK + tmp = (void**) xp_realloc ( + run->stack, n * xp_sizeof(void*)); + if (tmp == XP_NULL) return -1; +#else + tmp = (void**) xp_malloc (n * xp_sizeof(void*)); + if (tmp == XP_NULL) return -1; + if (run->stack != XP_NULL) + { + xp_memcpy (tmp, run->stack, + run->stack_limit * xp_sizeof(void*)); + xp_free (run->stack); + } +#endif run->stack = tmp; run->stack_limit = n; } @@ -4454,13 +4466,30 @@ static int __recomp_record_fields (xp_awk_run_t* run, nflds = run->inrec.nflds; if (max > run->inrec.maxflds) { - void* tmp = xp_realloc ( + void* tmp; + +#ifndef XP_AWK_NTDDK + tmp = xp_realloc ( run->inrec.flds, xp_sizeof(*run->inrec.flds) * max); if (tmp == XP_NULL) { *errnum = XP_AWK_ENOMEM; return -1; } +#else + tmp = xp_malloc (xp_sizeof(*run->inrec.flds) * max); + if (tmp == XP_NULL) + { + *errnum = XP_AWK_ENOMEM; + return -1; + } + if (run->inrec.flds != XP_NULL) + { + xp_memcpy (tmp, run->inrec.flds, + xp_sizeof(*run->inrec.flds) * run->inrec.maxflds); + xp_free (run->inrec.flds); + } +#endif run->inrec.flds = tmp; run->inrec.maxflds = max; diff --git a/ase/awk/sa.c b/ase/awk/sa.c index b4a1d2a4..e936a946 100644 --- a/ase/awk/sa.c +++ b/ase/awk/sa.c @@ -1,5 +1,5 @@ /* - * $Id: sa.c,v 1.29 2006-08-13 16:04:32 bacon Exp $ + * $Id: sa.c,v 1.30 2006-08-16 11:35:53 bacon Exp $ */ #include @@ -395,22 +395,34 @@ xp_size_t xp_str_cat (xp_str_t* str, const xp_char_t* s) xp_size_t xp_str_ncat (xp_str_t* str, const xp_char_t* s, xp_size_t len) { - xp_char_t* buf; - xp_size_t capa; - if (len > str->capa - str->size) { + xp_char_t* tmp; + xp_size_t capa; + capa = str->size + len; /* double the capa if necessary for concatenation */ if (capa < str->capa * 2) capa = str->capa * 2; - buf = (xp_char_t*) xp_realloc ( +#ifndef XP_AWK_NTDDK + tmp = (xp_char_t*) xp_realloc ( str->buf, xp_sizeof(xp_char_t) * (capa + 1)); - if (buf == XP_NULL) return (xp_size_t)-1; + if (tmp == XP_NULL) return (xp_size_t)-1; +#else + tmp = (xp_char_t*) xp_malloc ( + xp_sizeof(xp_char_t) * (capa + 1)); + if (tmp == XP_NULL) return (xp_size_t)-1; + if (str->buf != XP_NULL) + { + xp_memcpy (tmp, str->buf, + xp_sizeof(xp_char_t) * (str->capa + 1)); + xp_free (str->buf); + } +#endif str->capa = capa; - str->buf = buf; + str->buf = tmp; } str->size += xp_strncpy (&str->buf[str->size], s, len); diff --git a/ase/awk/sa.h b/ase/awk/sa.h index 80b45279..5f84b951 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.30 2006-08-16 09:35:21 bacon Exp $ + * $Id: sa.h,v 1.31 2006-08-16 11:35:54 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -17,23 +17,12 @@ #ifdef XP_AWK_NTDDK #include - #include #include - #include - - #ifdef XP_CHAR_IS_MCHAR - #include - #else - #include - #include - #endif #define xp_assert ASSERT - #define xp_malloc malloc - #define xp_calloc calloc - #define xp_realloc realloc - #define xp_free free + #define xp_malloc(size) ExAllocatePool(PagedPool,size) + #define xp_free(ptr) ExFreePool(ptr) #define xp_memset(dst,fill,len) RtlFillMemory(dst,len,fill) #define xp_memcpy(dst,src,len) RtlCopyMemory(dst,src,len) @@ -65,40 +54,39 @@ #define xp_memset(dst,fill,len) memset(dst,fill,len) #define xp_memcpy(dst,src,len) memcpy(dst,src,len) #define xp_memcmp(src1,src2,len) memcmp(src1,src2,len); + + #ifdef XP_CHAR_IS_MCHAR + #define xp_isdigit isdigit + #define xp_isxdigit isxdigit + #define xp_isalpha isalpha + #define xp_isalnum isalnum + #define xp_isspace isspace + #define xp_iscntrl iscntrl + #define xp_isgraph isgraph + #define xp_islower islower + #define xp_isupper isupper + #define xp_isprint isprint + #define xp_ispunct ispunct + #define xp_toupper toupper + #define xp_tolower tolower + #else + #define xp_isdigit iswdigit + #define xp_isxdigit iswxdigit + #define xp_isalpha iswalpha + #define xp_isalnum iswalnum + #define xp_isspace iswspace + #define xp_iscntrl iswcntrl + #define xp_isgraph iswgraph + #define xp_islower iswlower + #define xp_isupper iswupper + #define xp_isprint iswprint + #define xp_ispunct iswpunct + #define xp_toupper towupper + #define xp_tolower towlower + #endif + #endif - -#ifdef XP_CHAR_IS_MCHAR -#define xp_isdigit isdigit -#define xp_isxdigit isxdigit -#define xp_isalpha isalpha -#define xp_isalnum isalnum -#define xp_isspace isspace -#define xp_iscntrl iscntrl -#define xp_isgraph isgraph -#define xp_islower islower -#define xp_isupper isupper -#define xp_isprint isprint -#define xp_ispunct ispunct -#define xp_toupper toupper -#define xp_tolower tolower -#else -#define xp_isdigit iswdigit -#define xp_isxdigit iswxdigit -#define xp_isalpha iswalpha -#define xp_isalnum iswalnum -#define xp_isspace iswspace -#define xp_iscntrl iswcntrl -#define xp_isgraph iswgraph -#define xp_islower iswlower -#define xp_isupper iswupper -#define xp_isprint iswprint -#define xp_ispunct iswpunct -#define xp_toupper towupper -#define xp_tolower towlower -#endif - - #define xp_va_start(pvar,param) va_start(pvar,param) #define xp_va_list va_list #define xp_va_end(pvar) va_end(pvar) diff --git a/ase/awk/sources b/ase/awk/sources index 4d8a5212..cbfb8a1c 100644 --- a/ase/awk/sources +++ b/ase/awk/sources @@ -2,7 +2,7 @@ TARGETNAME=xpawk TARGETPATH=obj TARGETTYPE=DRIVER_LIBRARY -SOURCES=awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c func.c misc.c extio.c rex.c +SOURCES=rex.c err.c C_DEFINES=-D_UNICODE -DXP_AWK_STAND_ALONE -DXP_AWK_NTDDK INCLUDES=..\.. diff --git a/ase/awk/tab.c b/ase/awk/tab.c index 0912d7d7..ec6b746e 100644 --- a/ase/awk/tab.c +++ b/ase/awk/tab.c @@ -1,5 +1,5 @@ /* - * $Id: tab.c,v 1.10 2006-08-03 06:06:27 bacon Exp $ + * $Id: tab.c,v 1.11 2006-08-16 11:35:54 bacon Exp $ */ #include @@ -62,8 +62,20 @@ xp_awk_tab_t* xp_awk_tab_setcapa (xp_awk_tab_t* tab, xp_size_t capa) if (capa > 0) { +#ifndef XP_AWK_NTDDK tmp = xp_realloc (tab->buf, xp_sizeof(*tab->buf) * capa); if (tmp == XP_NULL) return XP_NULL; +#else + tmp = xp_malloc (xp_sizeof(*tab->buf) * capa); + if (tmp == XP_NULL) return XP_NULL; + if (tab->buf != XP_NULL) + { + xp_size_t x; + x = (capa > tab->capa)? tab->capa: capa; + xp_memcpy (tmp, tab->buf, xp_sizeof(*tab->buf) * x); + xp_free (tab->buf); + } +#endif } else { diff --git a/ase/awk/val.c b/ase/awk/val.c index 4b53edf6..b3056a5e 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.49 2006-08-03 05:05:48 bacon Exp $ + * $Id: val.c,v 1.50 2006-08-16 11:35:54 bacon Exp $ */ #include @@ -244,7 +244,7 @@ xp_printf (XP_T("\n"));*/ case XP_AWK_VAL_REX: xp_free (((xp_awk_val_rex_t*)val)->buf); - xp_free (((xp_awk_val_rex_t*)val)->code); + xp_awk_freerex (((xp_awk_val_rex_t*)val)->code); xp_free (val); return; diff --git a/ase/test/awk/t13.awk b/ase/test/awk/t13.awk index c1d75f37..ce7ab2e6 100644 --- a/ase/test/awk/t13.awk +++ b/ase/test/awk/t13.awk @@ -1,6 +1,5 @@ global a; -BEGIN -{ +BEGIN { local b; //a = 20;