*** empty log message ***

This commit is contained in:
hyung-hwan 2006-12-15 14:58:37 +00:00
parent f5c8c110cb
commit 4818807837
6 changed files with 59 additions and 41 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.98 2006-12-13 14:13:06 bacon Exp $ * $Id: awk.c,v 1.99 2006-12-15 14:58:14 bacon Exp $
*/ */
#if defined(__BORLANDC__) #if defined(__BORLANDC__)
@ -11,16 +11,14 @@
static void __free_afn (void* awk, void* afn); static void __free_afn (void* awk, void* afn);
ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns) ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum)
{ {
ase_awk_t* awk; ase_awk_t* awk;
if (sysfns == ASE_NULL) return ASE_NULL; if (sysfns == ASE_NULL ||
sysfns->malloc == ASE_NULL ||
if (sysfns->malloc == ASE_NULL || sysfns->free == ASE_NULL ||
sysfns->free == ASE_NULL) return ASE_NULL; sysfns->is_upper == ASE_NULL ||
if (sysfns->is_upper == ASE_NULL ||
sysfns->is_lower == ASE_NULL || sysfns->is_lower == ASE_NULL ||
sysfns->is_alpha == ASE_NULL || sysfns->is_alpha == ASE_NULL ||
sysfns->is_digit == ASE_NULL || sysfns->is_digit == ASE_NULL ||
@ -32,14 +30,16 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
sysfns->is_cntrl == ASE_NULL || sysfns->is_cntrl == ASE_NULL ||
sysfns->is_punct == ASE_NULL || sysfns->is_punct == ASE_NULL ||
sysfns->to_upper == ASE_NULL || sysfns->to_upper == ASE_NULL ||
sysfns->to_lower == ASE_NULL) return ASE_NULL; sysfns->to_lower == ASE_NULL ||
sysfns->pow == ASE_NULL ||
if (sysfns->sprintf == ASE_NULL || sysfns->sprintf == ASE_NULL ||
sysfns->aprintf == ASE_NULL || sysfns->aprintf == ASE_NULL ||
sysfns->dprintf == ASE_NULL || sysfns->dprintf == ASE_NULL ||
sysfns->abort == ASE_NULL) return ASE_NULL; sysfns->abort == ASE_NULL)
{
if (sysfns->pow == ASE_NULL) return ASE_NULL; *errnum = ASE_AWK_ESYSFNS;
return ASE_NULL;
}
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) #if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
awk = (ase_awk_t*) malloc (ASE_SIZEOF(ase_awk_t)); awk = (ase_awk_t*) malloc (ASE_SIZEOF(ase_awk_t));
@ -47,7 +47,11 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
awk = (ase_awk_t*) sysfns->malloc ( awk = (ase_awk_t*) sysfns->malloc (
ASE_SIZEOF(ase_awk_t), sysfns->custom_data); ASE_SIZEOF(ase_awk_t), sysfns->custom_data);
#endif #endif
if (awk == ASE_NULL) return ASE_NULL; if (awk == ASE_NULL)
{
*errnum = ASE_AWK_ENOMEM;
return ASE_NULL;
}
/* it uses the built-in ase_awk_memset because awk is not /* it uses the built-in ase_awk_memset because awk is not
* fully initialized yet */ * fully initialized yet */
@ -64,6 +68,7 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
if (ase_awk_str_open (&awk->token.name, 128, awk) == ASE_NULL) if (ase_awk_str_open (&awk->token.name, 128, awk) == ASE_NULL)
{ {
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
*errnum = ASE_AWK_ENOMEM;
return ASE_NULL; return ASE_NULL;
} }
@ -73,6 +78,7 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
{ {
ase_awk_str_close (&awk->token.name); ase_awk_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
*errnum = ASE_AWK_ENOMEM;
return ASE_NULL; return ASE_NULL;
} }
@ -81,6 +87,7 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
ase_awk_str_close (&awk->token.name); ase_awk_str_close (&awk->token.name);
ase_awk_map_close (&awk->tree.afns); ase_awk_map_close (&awk->tree.afns);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
*errnum = ASE_AWK_ENOMEM;
return ASE_NULL; return ASE_NULL;
} }
@ -90,6 +97,7 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
ase_awk_map_close (&awk->tree.afns); ase_awk_map_close (&awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals); ase_awk_tab_close (&awk->parse.globals);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
*errnum = ASE_AWK_ENOMEM;
return ASE_NULL; return ASE_NULL;
} }
@ -100,6 +108,7 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns)
ase_awk_tab_close (&awk->parse.globals); ase_awk_tab_close (&awk->parse.globals);
ase_awk_tab_close (&awk->parse.locals); ase_awk_tab_close (&awk->parse.locals);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
*errnum = ASE_AWK_ENOMEM;
return ASE_NULL; return ASE_NULL;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.165 2006-12-14 07:55:51 bacon Exp $ * $Id: awk.h,v 1.166 2006-12-15 14:58:14 bacon Exp $
*/ */
#ifndef _ASE_AWK_AWK_H_ #ifndef _ASE_AWK_AWK_H_
@ -19,22 +19,22 @@ typedef struct ase_awk_runios_t ase_awk_runios_t;
typedef struct ase_awk_runcbs_t ase_awk_runcbs_t; typedef struct ase_awk_runcbs_t ase_awk_runcbs_t;
typedef struct ase_awk_runarg_t ase_awk_runarg_t; typedef struct ase_awk_runarg_t ase_awk_runarg_t;
typedef void* (*ase_awk_malloc_t) (ase_size_t n, void* custom_data); typedef void* (*ase_awk_malloc_t) (ase_size_t n, void* custom_data);
typedef void* (*ase_awk_realloc_t) (void* ptr, ase_size_t n, void* custom_data); typedef void* (*ase_awk_realloc_t) (void* ptr, ase_size_t n, void* custom_data);
typedef void (*ase_awk_free_t) (void* ptr, void* custom_data); typedef void (*ase_awk_free_t) (void* ptr, void* custom_data);
typedef void* (*ase_awk_memcpy_t) (void* dst, const void* src, ase_size_t n); typedef void* (*ase_awk_memcpy_t) (void* dst, const void* src, ase_size_t n);
typedef void* (*ase_awk_memset_t) (void* dst, int val, ase_size_t n); typedef void* (*ase_awk_memset_t) (void* dst, int val, ase_size_t n);
typedef ase_bool_t (*ase_awk_isctype_t) (ase_cint_t c); typedef ase_bool_t (*ase_awk_isctype_t) (ase_cint_t c);
typedef ase_cint_t (*ase_awk_toctype_t) (ase_cint_t c); typedef ase_cint_t (*ase_awk_toctype_t) (ase_cint_t c);
typedef ase_real_t (*ase_awk_pow_t) (ase_real_t x, ase_real_t y); typedef ase_real_t (*ase_awk_pow_t) (ase_real_t x, ase_real_t y);
typedef int (*ase_awk_sprintf_t) ( typedef int (*ase_awk_sprintf_t) (
ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...);
typedef void (*ase_awk_aprintf_t) (const ase_char_t* fmt, ...); typedef void (*ase_awk_aprintf_t) (const ase_char_t* fmt, ...);
typedef void (*ase_awk_dprintf_t) (const ase_char_t* fmt, ...); typedef void (*ase_awk_dprintf_t) (const ase_char_t* fmt, ...);
typedef void (*ase_awk_abort_t) (void); typedef void (*ase_awk_abort_t) (void);
typedef void (*ase_awk_lock_t) (ase_awk_t* awk, void* custom_data);
typedef void (*ase_awk_lock_t) (ase_awk_t* awk, void* custom_data);
typedef ase_ssize_t (*ase_awk_io_t) ( typedef ase_ssize_t (*ase_awk_io_t) (
int cmd, void* arg, ase_char_t* data, ase_size_t count); int cmd, void* arg, ase_char_t* data, ase_size_t count);
@ -183,11 +183,14 @@ enum
/* support getline and print */ /* support getline and print */
ASE_AWK_EXTIO = (1 << 8), ASE_AWK_EXTIO = (1 << 8),
/* support co-process */
ASE_AWK_COPROC = (1 << 9),
/* support blockless patterns */ /* support blockless patterns */
ASE_AWK_BLOCKLESS = (1 << 9), ASE_AWK_BLOCKLESS = (1 << 10),
/* use 1 as the start index for string operations */ /* use 1 as the start index for string operations */
ASE_AWK_STRINDEXONE = (1 << 10), ASE_AWK_STRINDEXONE = (1 << 11),
/* strip off leading and trailing spaces when splitting a record /* strip off leading and trailing spaces when splitting a record
* into fields with a regular expression. * into fields with a regular expression.
@ -202,13 +205,13 @@ enum
* The program splits " a b c " into [a], [b], [c] when this * The program splits " a b c " into [a], [b], [c] when this
* option is on while into [], [a], [b], [c], [] when it is off. * option is on while into [], [a], [b], [c], [] when it is off.
*/ */
ASE_AWK_STRIPSPACES = (1 << 11), ASE_AWK_STRIPSPACES = (1 << 12),
/* enable the nextoutfile keyword */ /* enable the nextoutfile keyword */
ASE_AWK_NEXTOFILE = (1 << 12), ASE_AWK_NEXTOFILE = (1 << 13),
/* a newline terminates a statement */ /* a newline terminates a statement */
ASE_AWK_NEWLINE = (1 << 13) ASE_AWK_NEWLINE = (1 << 14)
}; };
/* error code */ /* error code */
@ -220,10 +223,12 @@ enum
ASE_AWK_EEXIST, /* existing data found */ ASE_AWK_EEXIST, /* existing data found */
ASE_AWK_ENOENT, /* no such data entry found */ ASE_AWK_ENOENT, /* no such data entry found */
ASE_AWK_EACCES, /* access denied */ ASE_AWK_EACCES, /* access denied */
ASE_AWK_ERUNTIME, /* run-time error */ ASE_AWK_ERUNTIME, /* run-time error */
ASE_AWK_ERUNNING, /* there are running instances */ ASE_AWK_ERUNNING, /* there are running instances */
ASE_AWK_ETOOMANYRUNS, /* too many running instances */ ASE_AWK_ETOOMANYRUNS, /* too many running instances */
ASE_AWK_ERECURSION, /* recursion too deep */ ASE_AWK_ERECURSION, /* recursion too deep */
ASE_AWK_ESYSFNS, /* system functions not proper */
ASE_AWK_ESRCINOPEN, ASE_AWK_ESRCINOPEN,
ASE_AWK_ESRCINCLOSE, ASE_AWK_ESRCINCLOSE,
@ -383,7 +388,7 @@ enum
extern "C" { extern "C" {
#endif #endif
ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns); ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum);
int ase_awk_close (ase_awk_t* awk); int ase_awk_close (ase_awk_t* awk);
int ase_awk_clear (ase_awk_t* awk); int ase_awk_clear (ase_awk_t* awk);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c,v 1.58 2006-12-12 05:16:29 bacon Exp $ * $Id: err.c,v 1.59 2006-12-15 14:58:14 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
@ -23,6 +23,7 @@ const ase_char_t* ase_awk_geterrstr (int errnum)
ASE_T("one or more running instances"), ASE_T("one or more running instances"),
ASE_T("too many running instances"), ASE_T("too many running instances"),
ASE_T("recursion too deep"), ASE_T("recursion too deep"),
ASE_T("system functions not provided or not proper"),
ASE_T("cannot open source input"), ASE_T("cannot open source input"),
ASE_T("cannot close source input"), ASE_T("cannot close source input"),

View File

@ -1,5 +1,5 @@
/* /*
* $Id: jni.c,v 1.40 2006-12-13 14:16:12 bacon Exp $ * $Id: jni.c,v 1.41 2006-12-15 14:58:15 bacon Exp $
*/ */
#include <stdio.h> #include <stdio.h>
@ -182,7 +182,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
jthrowable except; jthrowable except;
ase_awk_t* awk; ase_awk_t* awk;
ase_awk_sysfns_t sysfns; ase_awk_sysfns_t sysfns;
int opt; int opt, errnum;
memset (&sysfns, 0, sizeof(sysfns)); memset (&sysfns, 0, sizeof(sysfns));
sysfns.malloc = __awk_malloc; sysfns.malloc = __awk_malloc;
@ -211,7 +211,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
sysfns.dprintf = __awk_dprintf; sysfns.dprintf = __awk_dprintf;
sysfns.abort = abort; sysfns.abort = abort;
awk = ase_awk_open (&sysfns); awk = ase_awk_open (&sysfns, &errnum);
if (awk == NULL) if (awk == NULL)
{ {
except = (*env)->FindClass (env, CLASS_EXCEPTION); except = (*env)->FindClass (env, CLASS_EXCEPTION);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.221 2006-12-12 05:16:30 bacon Exp $ * $Id: parse.c,v 1.222 2006-12-15 14:58:15 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
@ -3608,7 +3608,7 @@ static int __get_token (ase_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR (awk); GET_CHAR (awk);
} }
else if (c == ASE_T('&')) else if ((awk->option & ASE_AWK_COPROC) && c == ASE_T('&'))
{ {
SET_TOKEN_TYPE (awk, TOKEN_BORAND); SET_TOKEN_TYPE (awk, TOKEN_BORAND);
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.136 2006-12-13 14:17:01 bacon Exp $ * $Id: awk.c,v 1.137 2006-12-15 14:58:37 bacon Exp $
*/ */
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -739,7 +739,7 @@ static int __main (int argc, ase_char_t* argv[])
ase_awk_runarg_t runarg[10]; ase_awk_runarg_t runarg[10];
ase_awk_sysfns_t sysfns; ase_awk_sysfns_t sysfns;
struct src_io src_io = { NULL, NULL }; struct src_io src_io = { NULL, NULL };
int opt, i, file_count = 0; int opt, i, file_count = 0, errnum;
#ifdef _WIN32 #ifdef _WIN32
sysfns_data_t sysfns_data; sysfns_data_t sysfns_data;
#endif #endif
@ -753,6 +753,7 @@ static int __main (int argc, ase_char_t* argv[])
ASE_AWK_SHADING | ASE_AWK_SHADING |
ASE_AWK_SHIFT | ASE_AWK_SHIFT |
ASE_AWK_EXTIO | ASE_AWK_EXTIO |
/*ASE_AWK_COPROC |*/
ASE_AWK_BLOCKLESS | ASE_AWK_BLOCKLESS |
ASE_AWK_STRINDEXONE | ASE_AWK_STRINDEXONE |
ASE_AWK_STRIPSPACES | ASE_AWK_STRIPSPACES |
@ -829,12 +830,14 @@ static int __main (int argc, ase_char_t* argv[])
sysfns.custom_data = &sysfns_data; sysfns.custom_data = &sysfns_data;
#endif #endif
if ((awk = ase_awk_open(&sysfns)) == ASE_NULL) if ((awk = ase_awk_open(&sysfns, &errnum)) == ASE_NULL)
{ {
#ifdef _WIN32 #ifdef _WIN32
HeapDestroy (sysfns_data.heap); HeapDestroy (sysfns_data.heap);
#endif #endif
xp_printf (ASE_T("Error: cannot open awk\n")); xp_printf (
ASE_T("ERROR: cannot parse awk [%d] %s\n"),
errnum, ase_awk_geterrstr(errnum));
return -1; return -1;
} }