From 85a2b9c33bea7ad92f44cf26bac655c9e9c36413 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 12 Oct 2006 14:36:25 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.c | 10 +++++-- ase/awk/awk_i.h | 59 +++++++++++++++++------------------------ ase/awk/jni.c | 64 +++++++++++++++++++++++++++++++++++++++------ ase/awk/makefile.cl | 12 ++++----- ase/awk/misc.c | 6 ++--- ase/awk/rec.c | 4 +-- ase/awk/rex.c | 4 +-- ase/awk/run.c | 4 +-- ase/awk/str.c | 4 +-- ase/awk/tab.c | 4 +-- ase/awk/tree.c | 6 ++--- ase/awk/val.c | 4 +-- 12 files changed, 112 insertions(+), 69 deletions(-) diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 0a706a7b..e4ec471b 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.79 2006-10-12 04:17:30 bacon Exp $ + * $Id: awk.c,v 1.80 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -41,7 +41,13 @@ xp_awk_t* xp_awk_open (xp_awk_syscas_t* syscas) #endif if (awk == XP_NULL) return XP_NULL; - awk->syscas = syscas; + if (syscas->memcpy == XP_NULL) + { + xp_awk_memcpy (&awk->syscas, syscas, xp_sizeof(awk->syscas)); + awk->syscas.memcpy = xp_awk_memcpy; + } + else syscas->memcpy (&awk->syscas, syscas, xp_sizeof(awk->syscas)); + if (syscas->memset == XP_NULL) awk->syscas.memset = xp_awk_memset; if (xp_awk_str_open (&awk->token.name, 128, awk) == XP_NULL) { diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index f8a9f23f..f2d65237 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.64 2006-10-12 04:17:30 bacon Exp $ + * $Id: awk_i.h,v 1.65 2006-10-12 14:36:25 bacon Exp $ */ #ifndef _XP_AWK_AWKI_H_ @@ -45,52 +45,41 @@ typedef struct xp_awk_tree_t xp_awk_tree_t; #define XP_AWK_FREE(awk,ptr) free (ptr) #else #define XP_AWK_MALLOC(awk,size) \ - (awk)->syscas->malloc (size, (awk)->syscas->custom_data) + (awk)->syscas.malloc (size, (awk)->syscas.custom_data) #define XP_AWK_REALLOC(awk,ptr,size) \ - (awk)->syscas->realloc (ptr, size, (awk)->syscas->custom_data) + (awk)->syscas.realloc (ptr, size, (awk)->syscas.custom_data) #define XP_AWK_FREE(awk,ptr) \ - (awk)->syscas->free (ptr, (awk)->syscas->custom_data) + (awk)->syscas.free (ptr, (awk)->syscas.custom_data) #endif #define XP_AWK_LOCK(awk) \ do { \ - if ((awk)->syscas != XP_NULL && (awk)->syscas->lock != XP_NULL) \ - (awk)->syscas->lock (awk, (awk)->syscas->custom_data); \ + if ((awk)->syscas.lock != XP_NULL) \ + (awk)->syscas.lock (awk, (awk)->syscas.custom_data); \ } while (0) #define XP_AWK_UNLOCK(awk) \ do { \ - if ((awk)->syscas != XP_NULL && (awk)->syscas->unlock != XP_NULL) \ - (awk)->syscas->unlock (awk, (awk)->syscas->custom_data); \ + if ((awk)->syscas.unlock != XP_NULL) \ + (awk)->syscas.unlock (awk, (awk)->syscas.custom_data); \ } while (0) -#define XP_AWK_ISUPPER(awk,c) (awk)->syscas->is_upper(c) -#define XP_AWK_ISLOWER(awk,c) (awk)->syscas->is_lower(c) -#define XP_AWK_ISALPHA(awk,c) (awk)->syscas->is_alpha(c) -#define XP_AWK_ISDIGIT(awk,c) (awk)->syscas->is_digit(c) -#define XP_AWK_ISXDIGIT(awk,c) (awk)->syscas->is_xdigit(c) -#define XP_AWK_ISALNUM(awk,c) (awk)->syscas->is_alnum(c) -#define XP_AWK_ISSPACE(awk,c) (awk)->syscas->is_space(c) -#define XP_AWK_ISPRINT(awk,c) (awk)->syscas->is_print(c) -#define XP_AWK_ISGRAPH(awk,c) (awk)->syscas->is_graph(c) -#define XP_AWK_ISCNTRL(awk,c) (awk)->syscas->is_cntrl(c) -#define XP_AWK_ISPUNCT(awk,c) (awk)->syscas->is_punct(c) -#define XP_AWK_TOUPPER(awk,c) (awk)->syscas->to_upper(c) -#define XP_AWK_TOLOWER(awk,c) (awk)->syscas->to_lower(c) +#define XP_AWK_ISUPPER(awk,c) (awk)->syscas.is_upper(c) +#define XP_AWK_ISLOWER(awk,c) (awk)->syscas.is_lower(c) +#define XP_AWK_ISALPHA(awk,c) (awk)->syscas.is_alpha(c) +#define XP_AWK_ISDIGIT(awk,c) (awk)->syscas.is_digit(c) +#define XP_AWK_ISXDIGIT(awk,c) (awk)->syscas.is_xdigit(c) +#define XP_AWK_ISALNUM(awk,c) (awk)->syscas.is_alnum(c) +#define XP_AWK_ISSPACE(awk,c) (awk)->syscas.is_space(c) +#define XP_AWK_ISPRINT(awk,c) (awk)->syscas.is_print(c) +#define XP_AWK_ISGRAPH(awk,c) (awk)->syscas.is_graph(c) +#define XP_AWK_ISCNTRL(awk,c) (awk)->syscas.is_cntrl(c) +#define XP_AWK_ISPUNCT(awk,c) (awk)->syscas.is_punct(c) +#define XP_AWK_TOUPPER(awk,c) (awk)->syscas.to_upper(c) +#define XP_AWK_TOLOWER(awk,c) (awk)->syscas.to_lower(c) -#define XP_AWK_MEMCPY(awk,dst,src,len) \ - do { \ - if ((awk)->syscas->memcpy == XP_NULL) \ - xp_awk_memcpy (dst, src, len); \ - else (awk)->syscas->memcpy (dst, src, len); \ - } while (0) - -#define XP_AWK_MEMSET(awk,dst,val,len) \ - do { \ - if ((awk)->syscas->memset == XP_NULL) \ - xp_awk_memset (dst, val, len); \ - else (awk)->syscas->memset (dst, val, len); \ - } while (0) +#define XP_AWK_MEMCPY(awk,dst,src,len) (awk)->syscas.memcpy (dst, src, len) +#define XP_AWK_MEMSET(awk,dst,val,len) (awk)->syscas.memset (dst, val, len) struct xp_awk_tree_t { @@ -106,7 +95,7 @@ struct xp_awk_tree_t struct xp_awk_t { - xp_awk_syscas_t* syscas; + xp_awk_syscas_t syscas; /* options */ int option; diff --git a/ase/awk/jni.c b/ase/awk/jni.c index 8525fca3..3eda4caf 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,10 +1,14 @@ /* - * $Id: jni.c,v 1.4 2006-08-06 15:02:55 bacon Exp $ + * $Id: jni.c,v 1.5 2006-10-12 14:36:25 bacon Exp $ */ -#include "jni.h" -#include "awk.h" -#include "sa.h" +#include +#include +#include +#include +#include +#include +#include #define EXCEPTION_AWK "xpkit/xpj/awk/AwkException" #define FIELD_AWK "__awk" @@ -27,6 +31,20 @@ struct srcio_data_t jobject obj; }; +static void* __awk_malloc (xp_size_t n, void* custom_data) +{ + return malloc (n); +} + +static void* __awk_realloc (void* ptr, xp_size_t n, void* custom_data) +{ + return realloc (ptr, n); +} + +static void __awk_free (void* ptr, void* custom_data) +{ + free (ptr); +} JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_open (JNIEnv* env, jobject obj) { @@ -34,11 +52,38 @@ JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_open (JNIEnv* env, jobject obj) jfieldID fid; jthrowable except; xp_awk_t* awk; + xp_awk_syscas_t syscas; int opt; class = (*env)->GetObjectClass(env, obj); - awk = xp_awk_open (); + memset (&syscas, 0, sizeof(syscas)); + syscas.malloc = __awk_malloc; + syscas.realloc = __awk_realloc; + syscas.free = __awk_free; + + syscas.is_upper = iswupper; + syscas.is_lower = iswlower; + syscas.is_alpha = iswalpha; + syscas.is_digit = iswdigit; + syscas.is_xdigit = iswxdigit; + syscas.is_alnum = iswalnum; + syscas.is_space = iswspace; + syscas.is_print = iswprint; + syscas.is_graph = iswgraph; + syscas.is_cntrl = iswcntrl; + syscas.is_punct = iswpunct; + syscas.to_upper = towupper; + syscas.to_lower = towlower; + + syscas.memcpy = memcpy; + syscas.memset = memset; +/* TODO: */ + syscas.sprintf = _snwprintf; + syscas.dprintf = wprintf; + syscas.abort = abort; + + awk = xp_awk_open (&syscas); if (awk == NULL) { except = (*env)->FindClass (env, EXCEPTION_AWK); @@ -57,7 +102,7 @@ JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_open (JNIEnv* env, jobject obj) XP_AWK_EXTIO | XP_AWK_BLOCKLESS; xp_awk_setopt (awk, opt); -xp_printf (XP_T("__awk(native) done => %u, 0x%X\n"), awk, awk); +printf ("__awk(native) done => %u, 0x%X\n", awk, awk); } JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_close (JNIEnv* env, jobject obj) @@ -73,7 +118,7 @@ JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_close (JNIEnv* env, jobject obj) xp_awk_close ((xp_awk_t*) (*env)->GetLongField (env, obj, fid)); (*env)->SetLongField (env, obj, fid, (jlong)0); -xp_printf (XP_T("close (native) done\n")); +printf ("close (native) done\n"); } JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_parse (JNIEnv* env, jobject obj) @@ -100,12 +145,14 @@ JNIEXPORT void JNICALL Java_xpkit_xpj_awk_Awk_parse (JNIEnv* env, jobject obj) srcios.out = __write_source; srcios.custom_data = &srcio_data; +printf ("OK.......\n"); if (xp_awk_parse (awk, &srcios) == -1) { +printf ("parse error.......\n"); except = (*env)->FindClass (env, EXCEPTION_AWK); if (except == 0) return; (*env)->ThrowNew (env, except, "ERROR ...."); -xp_printf (XP_T("parse error -> line [%d] %s\n"), xp_awk_getsrcline(awk), xp_awk_geterrstr(awk)); +printf ("parse error -> line [%d] %S\n", xp_awk_getsrcline(awk), xp_awk_geterrstr(xp_awk_geterrnum(awk))); return; } } @@ -122,6 +169,7 @@ static xp_ssize_t __read_source ( srcio_data = (srcio_data_t*)arg; if (cmd == XP_AWK_IO_OPEN || cmd == XP_AWK_IO_CLOSE) return 0; + if (cmd == XP_AWK_IO_READ) { return __call_java_read_source ( diff --git a/ase/awk/makefile.cl b/ase/awk/makefile.cl index 898d8e35..fc3de79b 100644 --- a/ase/awk/makefile.cl +++ b/ase/awk/makefile.cl @@ -9,24 +9,24 @@ JAVA_INC = \ /I"C:\Program Files\IBM\Java141\Include\Win32" 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) +LD = link +CFLAGS = /nologo /O2 /MT /W3 /GR- /Za /D_WIN32_WINNT=0x0400 -I../.. -DXP_CHAR_IS_WCHAR $(JAVA_INC) all: lib lib: $(OBJS) - link /lib @<< + $(LD) /lib @<< /nologo /out:$(OUT).lib $(OBJS) << dll: $(OBJS) - link /dll /def:awk.def /subsystem:console /version:0.1 /release @<< + $(LD) /dll /def:awk.def /subsystem:console /version:0.1 /release @<< /nologo /out:$(OUT).dll $(OBJS) << jni: $(OBJS) jni.obj - link /dll /def:jni.def /subsystem:console /version:0.1 /release @<< -/nologo /out:$(OUT).dll $(OBJS) jni.obj + $(LD) /dll /def:jni.def /subsystem:console /version:0.1 /release @<< +/nologo /out:$(OUT).dll $(OBJS) jni.obj ..\bas\xpbas.lib << clean: diff --git a/ase/awk/misc.c b/ase/awk/misc.c index 102997bd..6c0aea81 100644 --- a/ase/awk/misc.c +++ b/ase/awk/misc.c @@ -1,5 +1,5 @@ /* - * $Id: misc.c,v 1.27 2006-10-12 04:17:31 bacon Exp $ + * $Id: misc.c,v 1.28 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -1063,9 +1063,9 @@ exit_loop: int xp_awk_abort (xp_awk_t* awk, const xp_char_t* expr, const xp_char_t* file, int line) { - awk->syscas->dprintf ( + awk->syscas.dprintf ( XP_T("ASSERTION FAILURE AT FILE %s, LINE %d\n%s\n"), file, line, expr); - awk->syscas->abort (); + awk->syscas.abort (); return 0; } diff --git a/ase/awk/rec.c b/ase/awk/rec.c index 47099c48..749f4b4c 100644 --- a/ase/awk/rec.c +++ b/ase/awk/rec.c @@ -1,5 +1,5 @@ /* - * $Id: rec.c,v 1.2 2006-10-12 04:17:31 bacon Exp $ + * $Id: rec.c,v 1.3 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -301,7 +301,7 @@ static int __recomp_record_fields ( * number of fields that the current record can hold, * the field spaces are resized */ - if (run->awk->syscas->realloc != XP_NULL) + if (run->awk->syscas.realloc != XP_NULL) { tmp = XP_AWK_REALLOC ( run->awk, run->inrec.flds, diff --git a/ase/awk/rex.c b/ase/awk/rex.c index 898fbfc8..28592429 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,5 +1,5 @@ /* - * $Id: rex.c,v 1.35 2006-10-12 04:17:31 bacon Exp $ + * $Id: rex.c,v 1.36 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -958,7 +958,7 @@ static int __add_code (__builder_t* builder, void* data, xp_size_t len) if (capa == 0) capa = DEF_CODE_CAPA; while (len > capa - builder->code.size) { capa = capa * 2; } - if (builder->awk->syscas->realloc != XP_NULL) + if (builder->awk->syscas.realloc != XP_NULL) { tmp = (xp_byte_t*) XP_AWK_REALLOC ( builder->awk, builder->code.buf, capa); diff --git a/ase/awk/run.c b/ase/awk/run.c index 82df838d..160561b6 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.233 2006-10-12 04:17:31 bacon Exp $ + * $Id: run.c,v 1.234 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -4885,7 +4885,7 @@ static int __raw_push (xp_awk_run_t* run, void* val) n = run->stack_limit + STACK_INCREMENT; - if (run->awk->syscas->realloc != XP_NULL) + if (run->awk->syscas.realloc != XP_NULL) { tmp = (void**) XP_AWK_REALLOC ( run->awk, run->stack, n * xp_sizeof(void*)); diff --git a/ase/awk/str.c b/ase/awk/str.c index 953de464..8b2fcceb 100644 --- a/ase/awk/str.c +++ b/ase/awk/str.c @@ -1,5 +1,5 @@ /* - * $Id: str.c,v 1.7 2006-09-28 06:56:30 bacon Exp $ + * $Id: str.c,v 1.8 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -106,7 +106,7 @@ xp_size_t xp_awk_str_ncat (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len) /* double the capa if necessary for concatenation */ if (capa < str->capa * 2) capa = str->capa * 2; - if (str->awk->syscas->realloc != XP_NULL) + if (str->awk->syscas.realloc != XP_NULL) { tmp = (xp_char_t*) XP_AWK_REALLOC ( str->awk, str->buf, diff --git a/ase/awk/tab.c b/ase/awk/tab.c index ead0a60c..138f8a7d 100644 --- a/ase/awk/tab.c +++ b/ase/awk/tab.c @@ -1,5 +1,5 @@ /* - * $Id: tab.c,v 1.20 2006-10-12 04:17:31 bacon Exp $ + * $Id: tab.c,v 1.21 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -58,7 +58,7 @@ xp_awk_tab_t* xp_awk_tab_setcapa (xp_awk_tab_t* tab, xp_size_t capa) if (capa > 0) { - if (tab->awk->syscas->realloc != XP_NULL) + if (tab->awk->syscas.realloc != XP_NULL) { tmp = XP_AWK_REALLOC (tab->awk, tab->buf, xp_sizeof(*tab->buf) * capa); diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 2fc36e19..4db3c051 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.79 2006-10-12 04:17:31 bacon Exp $ + * $Id: tree.c,v 1.80 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -248,11 +248,11 @@ static int __print_expression (xp_awk_t* awk, xp_awk_nde_t* nde) { xp_char_t tmp[128]; #if (XP_SIZEOF_LONG_DOUBLE != 0) - awk->syscas->sprintf ( + awk->syscas.sprintf ( tmp, xp_countof(tmp), XP_T("%Lf"), (long double)((xp_awk_nde_real_t*)nde)->val); #elif (XP_SIZEOF_DOUBLE != 0) - awk->syscas->sprintf ( + awk->syscas.sprintf ( tmp, xp_countof(tmp), XP_T("%f"), (double)((xp_awk_nde_real_t*)nde)->val); #else diff --git a/ase/awk/val.c b/ase/awk/val.c index 46386ac0..be1542da 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.72 2006-10-12 04:17:31 bacon Exp $ + * $Id: val.c,v 1.73 2006-10-12 14:36:25 bacon Exp $ */ #include @@ -572,7 +572,7 @@ static xp_char_t* __val_real_to_str ( /* TODO: need to use awk's own version of sprintf so that it would have * problems with handling long double or double... */ /* TODO: does it need to check if a null character is included in convfmt??? */ - run->awk->syscas->sprintf (tbuf, xp_countof(tbuf), tmp, (double)v->val); + run->awk->syscas.sprintf (tbuf, xp_countof(tbuf), tmp, (double)v->val); if (buf == XP_NULL) { tmp = xp_awk_strdup (run->awk, tbuf);