*** empty log message ***
This commit is contained in:
parent
12468e6d64
commit
7a8bac5a3b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.92 2006-11-27 15:10:34 bacon Exp $
|
||||
* $Id: awk.c,v 1.93 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
@ -148,6 +148,7 @@ ase_awk_t* ase_awk_open (const ase_awk_syscas_t* syscas)
|
||||
int ase_awk_close (ase_awk_t* awk)
|
||||
{
|
||||
if (ase_awk_clear (awk) == -1) return -1;
|
||||
ase_awk_clrbfn (awk);
|
||||
|
||||
ASE_AWK_ASSERT (awk, awk->run.count == 0 && awk->run.ptr == ASE_NULL);
|
||||
|
||||
@ -228,7 +229,6 @@ int ase_awk_clear (ase_awk_t* awk)
|
||||
awk->tree.chain_tail = ASE_NULL;
|
||||
awk->tree.chain_size = 0;
|
||||
|
||||
ase_awk_clrbfn (awk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h,v 1.153 2006-11-27 04:33:22 bacon Exp $
|
||||
* $Id: awk.h,v 1.154 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_AWK_H_
|
||||
@ -276,7 +276,7 @@ enum
|
||||
ASE_AWK_EDIVBYZERO, /* divide by zero */
|
||||
ASE_AWK_EOPERAND, /* invalid operand */
|
||||
ASE_AWK_EPOSIDX, /* wrong position index */
|
||||
ASE_AWK_ENOSUCHFUNC, /* no such function */
|
||||
ASE_AWK_ENOSUCHFN, /* no such function */
|
||||
ASE_AWK_ENOTASSIGNABLE, /* value not assignable */
|
||||
ASE_AWK_ENOTINDEXABLE, /* not indexable variable */
|
||||
ASE_AWK_ENOTDELETABLE, /* not deletable variable */
|
||||
@ -394,7 +394,8 @@ 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);
|
||||
ase_awk_runarg_t* runarg,
|
||||
void* custom_data);
|
||||
|
||||
int ase_awk_stop (ase_awk_t* awk, ase_awk_run_t* run);
|
||||
void ase_awk_stopall (ase_awk_t* awk);
|
||||
@ -411,14 +412,31 @@ int ase_awk_setfilename (
|
||||
int ase_awk_setofilename (
|
||||
ase_awk_run_t* run, const ase_char_t* name, ase_size_t len);
|
||||
|
||||
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk);
|
||||
void* ase_awk_getruncustomdata (ase_awk_run_t* awk);
|
||||
int ase_awk_getrunerrnum (ase_awk_run_t* run);
|
||||
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum);
|
||||
|
||||
/* functions to manipulate built-in functions */
|
||||
void* ase_awk_addbfn (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len,
|
||||
int when_valid, ase_size_t min_args, ase_size_t max_args,
|
||||
const ase_char_t* arg_spec,
|
||||
int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t));
|
||||
|
||||
int ase_awk_delbfn (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len);
|
||||
|
||||
void ase_awk_clrbfn (ase_awk_t* awk);
|
||||
|
||||
/* record and field functions */
|
||||
int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line);
|
||||
int ase_awk_setrec (ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len);
|
||||
|
||||
/* utility functions exported by awk.h */
|
||||
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size);
|
||||
void ase_awk_free (ase_awk_t* awk, void* ptr);
|
||||
|
||||
ase_long_t ase_awk_strxtolong (
|
||||
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
|
||||
int base, const ase_char_t** endptr);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk_i.h,v 1.85 2006-11-25 15:51:30 bacon Exp $
|
||||
* $Id: awk_i.h,v 1.86 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_AWKI_H_
|
||||
@ -295,8 +295,9 @@ struct ase_awk_run_t
|
||||
} format;
|
||||
|
||||
int errnum;
|
||||
|
||||
void* custom_data;
|
||||
ase_awk_t* awk;
|
||||
|
||||
ase_awk_run_t* prev;
|
||||
ase_awk_run_t* next;
|
||||
};
|
||||
|
@ -1,26 +1,25 @@
|
||||
/*
|
||||
* $Id: func.c,v 1.78 2006-11-27 15:10:34 bacon Exp $
|
||||
* $Id: func.c,v 1.79 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
|
||||
static int __bfn_close (ase_awk_run_t* run);
|
||||
static int __bfn_fflush (ase_awk_run_t* run);
|
||||
static int __bfn_index (ase_awk_run_t* run);
|
||||
static int __bfn_length (ase_awk_run_t* run);
|
||||
static int __bfn_substr (ase_awk_run_t* run);
|
||||
static int __bfn_split (ase_awk_run_t* run);
|
||||
static int __bfn_tolower (ase_awk_run_t* run);
|
||||
static int __bfn_toupper (ase_awk_run_t* run);
|
||||
static int __bfn_gsub (ase_awk_run_t* run);
|
||||
static int __bfn_sub (ase_awk_run_t* run);
|
||||
static int __bfn_match (ase_awk_run_t* run);
|
||||
static int __bfn_sprintf (ase_awk_run_t* run);
|
||||
static int __bfn_close (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_fflush (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_index (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_length (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_substr (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_split (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_tolower (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_toupper (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_gsub (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_sub (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_match (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
static int __bfn_sprintf (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
|
||||
#undef MAX
|
||||
#define MAX ASE_TYPE_MAX(ase_size_t)
|
||||
|
||||
/* TODO: move it under the awk structure... */
|
||||
static ase_awk_bfn_t __sys_bfn[] =
|
||||
{
|
||||
/* io functions */
|
||||
@ -42,10 +41,11 @@ static ase_awk_bfn_t __sys_bfn[] =
|
||||
{ {ASE_NULL, 0}, 0, 0, 0, ASE_NULL, ASE_NULL}
|
||||
};
|
||||
|
||||
ase_awk_bfn_t* ase_awk_addbfn (
|
||||
void* ase_awk_addbfn (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len,
|
||||
int when_valid, ase_size_t min_args, ase_size_t max_args,
|
||||
const ase_char_t* arg_spec, int (*handler)(ase_awk_run_t*))
|
||||
const ase_char_t* arg_spec,
|
||||
int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t))
|
||||
{
|
||||
ase_awk_bfn_t* p;
|
||||
|
||||
@ -132,7 +132,7 @@ void ase_awk_clrbfn (ase_awk_t* awk)
|
||||
}
|
||||
|
||||
ase_awk_bfn_t* ase_awk_getbfn (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
|
||||
{
|
||||
ase_awk_bfn_t* p;
|
||||
|
||||
@ -142,8 +142,7 @@ ase_awk_bfn_t* ase_awk_getbfn (
|
||||
(awk->option & p->valid) == 0) continue;
|
||||
|
||||
if (ase_awk_strxncmp (
|
||||
p->name.ptr, p->name.len,
|
||||
name, name_len) == 0) return p;
|
||||
p->name.ptr, p->name.len, name, len) == 0) return p;
|
||||
}
|
||||
|
||||
for (p = awk->bfn.user; p != ASE_NULL; p = p->next)
|
||||
@ -152,14 +151,14 @@ ase_awk_bfn_t* ase_awk_getbfn (
|
||||
(awk->option & p->valid) == 0) continue;
|
||||
|
||||
if (ase_awk_strxncmp (
|
||||
p->name.ptr, p->name.len,
|
||||
name, name_len) == 0) return p;
|
||||
p->name.ptr, p->name.len, name, len) == 0) return p;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
static int __bfn_close (ase_awk_run_t* run)
|
||||
static int __bfn_close (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* v, * a0;
|
||||
@ -262,7 +261,8 @@ static int __flush_extio (
|
||||
return n;
|
||||
}
|
||||
|
||||
static int __bfn_fflush (ase_awk_run_t* run)
|
||||
static int __bfn_fflush (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* a0;
|
||||
@ -355,7 +355,8 @@ skip_flush:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_index (ase_awk_run_t* run)
|
||||
static int __bfn_index (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* a0, * a1;
|
||||
@ -417,7 +418,8 @@ static int __bfn_index (ase_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_length (ase_awk_run_t* run)
|
||||
static int __bfn_length (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* v;
|
||||
@ -451,7 +453,8 @@ static int __bfn_length (ase_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_substr (ase_awk_run_t* run)
|
||||
static int __bfn_substr (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* a0, * a1, * a2, * r;
|
||||
@ -521,7 +524,8 @@ static int __bfn_substr (ase_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_split (ase_awk_run_t* run)
|
||||
static int __bfn_split (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* a0, * a1, * a2, * t1, * t2, ** a1_ref;
|
||||
@ -772,7 +776,8 @@ static int __bfn_split (ase_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_tolower (ase_awk_run_t* run)
|
||||
static int __bfn_tolower (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_char_t* str;
|
||||
@ -811,7 +816,8 @@ static int __bfn_tolower (ase_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_toupper (ase_awk_run_t* run)
|
||||
static int __bfn_toupper (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_char_t* str;
|
||||
@ -1140,17 +1146,20 @@ static int __substitute (ase_awk_run_t* run, ase_long_t max_count)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_gsub (ase_awk_run_t* run)
|
||||
static int __bfn_gsub (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
return __substitute (run, 0);
|
||||
}
|
||||
|
||||
static int __bfn_sub (ase_awk_run_t* run)
|
||||
static int __bfn_sub (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
return __substitute (run, 1);
|
||||
}
|
||||
|
||||
static int __bfn_match (ase_awk_run_t* run)
|
||||
static int __bfn_match (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* a0, * a1;
|
||||
@ -1268,7 +1277,8 @@ static int __bfn_match (ase_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bfn_sprintf (ase_awk_run_t* run)
|
||||
static int __bfn_sprintf (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
ase_size_t nargs;
|
||||
ase_awk_val_t* a0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: func.h,v 1.16 2006-11-27 15:10:34 bacon Exp $
|
||||
* $Id: func.h,v 1.17 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_FUNC_H_
|
||||
@ -27,13 +27,8 @@ struct ase_awk_bfn_t
|
||||
ase_size_t max;
|
||||
ase_char_t* spec;
|
||||
} arg;
|
||||
/*
|
||||
ase_size_t min_args;
|
||||
ase_size_t max_args;
|
||||
ase_char_t* arg_spec;
|
||||
*/
|
||||
|
||||
int (*handler) (ase_awk_run_t* run);
|
||||
int (*handler) (ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
|
||||
ase_awk_bfn_t* next;
|
||||
};
|
||||
@ -42,17 +37,8 @@ struct ase_awk_bfn_t
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ase_awk_bfn_t* ase_awk_addbfn (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len,
|
||||
int when_valid, ase_size_t min_args, ase_size_t max_args,
|
||||
const ase_char_t* arg_spec, int (*handler)(ase_awk_run_t*));
|
||||
|
||||
int ase_awk_delbfn (ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len);
|
||||
|
||||
void ase_awk_clrbfn (ase_awk_t* awk);
|
||||
|
||||
ase_awk_bfn_t* ase_awk_getbfn (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len);
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: jni.c,v 1.28 2006-11-27 15:10:34 bacon Exp $
|
||||
* $Id: jni.c,v 1.29 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/jni.h>
|
||||
@ -40,6 +40,7 @@ static ase_ssize_t __process_extio (
|
||||
|
||||
typedef struct srcio_data_t srcio_data_t;
|
||||
typedef struct runio_data_t runio_data_t;
|
||||
typedef struct run_data_t run_data_t;
|
||||
|
||||
struct srcio_data_t
|
||||
{
|
||||
@ -53,6 +54,12 @@ struct runio_data_t
|
||||
jobject obj;
|
||||
};
|
||||
|
||||
struct run_data_t
|
||||
{
|
||||
JNIEnv* env;
|
||||
jobject obj;
|
||||
};
|
||||
|
||||
static void* __awk_malloc (ase_size_t n, void* custom_data)
|
||||
{
|
||||
return malloc (n);
|
||||
@ -320,6 +327,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
|
||||
ase_awk_t* awk;
|
||||
ase_awk_runios_t runios;
|
||||
runio_data_t runio_data;
|
||||
run_data_t run_data;
|
||||
|
||||
class = (*env)->GetObjectClass (env, obj);
|
||||
|
||||
@ -332,6 +340,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
|
||||
|
||||
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, fid_handle);
|
||||
|
||||
run_data.env = env;
|
||||
run_data.obj = obj;
|
||||
|
||||
runio_data.env = env;
|
||||
runio_data.obj = obj;
|
||||
|
||||
@ -343,7 +354,8 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
|
||||
|
||||
//depth = __java_get_max_depth (env, obj, "getMaxRunDepth");
|
||||
|
||||
if (ase_awk_run (awk, ASE_NULL, &runios, ASE_NULL, ASE_NULL) == -1)
|
||||
if (ase_awk_run (awk,
|
||||
ASE_NULL, &runios, ASE_NULL, ASE_NULL, &run_data) == -1)
|
||||
{
|
||||
char msg[256];
|
||||
int n;
|
||||
@ -910,22 +922,59 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_setofilename (
|
||||
return n;
|
||||
}
|
||||
|
||||
static int __handle_bfn (ase_awk_run_t* run)
|
||||
static int __handle_bfn (
|
||||
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
||||
{
|
||||
jclass class;
|
||||
jmethodID mid;
|
||||
jstring name;
|
||||
jthrowable thrown;
|
||||
char* buf;
|
||||
ase_awk_t* awk;
|
||||
run_data_t* run_data;
|
||||
JNIEnv* env;
|
||||
jobject obj;
|
||||
|
||||
awk = ase_awk_getrunawk (run);
|
||||
run_data = ase_awk_getruncustomdata (run);
|
||||
|
||||
env = run_data->env;
|
||||
obj = run_data->obj;
|
||||
|
||||
buf = ase_awk_malloc (awk, fnl * 5);
|
||||
if (buf == NULL)
|
||||
{
|
||||
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = (*env)->NewString (env, fnm, fnl);
|
||||
if (name == NULL)
|
||||
{
|
||||
ase_awk_free (awk, buf);
|
||||
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*env)->GetStringUTFRegion (env, name, 0, fnl, buf);
|
||||
thrown = (*env)->ExceptionOccurred (env);
|
||||
if (thrown)
|
||||
{
|
||||
(*env)->ExceptionClear (env);
|
||||
ase_awk_free (awk, buf);
|
||||
ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*env)->DeleteLocalRef (env, name);
|
||||
|
||||
printf ("BFN CALLED.....\n");
|
||||
/*
|
||||
class = (*env)->GetObjectClass(env, obj);
|
||||
|
||||
mid = (*env)->GetMethodID (env, class, funtion_name...., "(I)I");
|
||||
mid = (*env)->GetMethodID (env, class, buf, "()I");
|
||||
if (mid == NULL)
|
||||
{
|
||||
(*env)->DeleteLocalRef (env, class);
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
CreateObjectArray...
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* $Id: misc.c,v 1.40 2006-11-27 04:33:22 bacon Exp $
|
||||
* $Id: misc.c,v 1.41 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
|
||||
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size)
|
||||
{
|
||||
return ASE_AWK_MALLOC (awk, size);
|
||||
}
|
||||
|
||||
void ase_awk_free (ase_awk_t* awk, void* ptr)
|
||||
{
|
||||
return ASE_AWK_FREE (awk, ptr);
|
||||
}
|
||||
|
||||
void* ase_awk_memcpy (void* dst, const void* src, ase_size_t n)
|
||||
{
|
||||
void* p = dst;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.212 2006-11-27 15:10:34 bacon Exp $
|
||||
* $Id: parse.c,v 1.213 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -175,7 +175,8 @@ static ase_awk_nde_t* __parse_primary_ident (ase_awk_t* awk);
|
||||
static ase_awk_nde_t* __parse_hashidx (
|
||||
ase_awk_t* awk, ase_char_t* name, ase_size_t name_len);
|
||||
static ase_awk_nde_t* __parse_fncall (
|
||||
ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, ase_awk_bfn_t* bfn);
|
||||
ase_awk_t* awk, ase_char_t* name, ase_size_t name_len,
|
||||
ase_awk_bfn_t* bfn);
|
||||
static ase_awk_nde_t* __parse_if (ase_awk_t* awk);
|
||||
static ase_awk_nde_t* __parse_while (ase_awk_t* awk);
|
||||
static ase_awk_nde_t* __parse_for (ase_awk_t* awk);
|
||||
@ -2727,7 +2728,8 @@ static ase_awk_nde_t* __parse_hashidx (
|
||||
}
|
||||
|
||||
static ase_awk_nde_t* __parse_fncall (
|
||||
ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, ase_awk_bfn_t* bfn)
|
||||
ase_awk_t* awk, ase_char_t* name, ase_size_t name_len,
|
||||
ase_awk_bfn_t* bfn)
|
||||
{
|
||||
ase_awk_nde_t* head, * curr, * nde;
|
||||
ase_awk_nde_call_t* call;
|
||||
@ -2788,7 +2790,8 @@ static ase_awk_nde_t* __parse_fncall (
|
||||
|
||||
}
|
||||
|
||||
call = (ase_awk_nde_call_t*) ASE_AWK_MALLOC (awk, ase_sizeof(ase_awk_nde_call_t));
|
||||
call = (ase_awk_nde_call_t*)
|
||||
ASE_AWK_MALLOC (awk, ase_sizeof(ase_awk_nde_call_t));
|
||||
if (call == ASE_NULL)
|
||||
{
|
||||
if (head != ASE_NULL) ase_awk_clrpt (awk, head);
|
||||
|
109
ase/awk/run.c
109
ase/awk/run.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.285 2006-11-27 15:10:35 bacon Exp $
|
||||
* $Id: run.c,v 1.286 2006-11-28 04:30:21 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -54,7 +54,8 @@ static void __add_run (ase_awk_t* awk, ase_awk_run_t* run);
|
||||
static void __del_run (ase_awk_t* awk, ase_awk_run_t* run);
|
||||
|
||||
static int __init_run (
|
||||
ase_awk_run_t* run, ase_awk_runios_t* runios, int* errnum);
|
||||
ase_awk_run_t* run, ase_awk_runios_t* runios,
|
||||
void* custom_data, int* errnum);
|
||||
static void __deinit_run (ase_awk_run_t* run);
|
||||
|
||||
static int __build_runarg (ase_awk_run_t* run, ase_awk_runarg_t* runarg);
|
||||
@ -526,6 +527,16 @@ int ase_awk_setofilename (
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* run)
|
||||
{
|
||||
return run->awk;
|
||||
}
|
||||
|
||||
void* ase_awk_getruncustomdata (ase_awk_run_t* run)
|
||||
{
|
||||
return run->custom_data;
|
||||
}
|
||||
|
||||
int ase_awk_getrunerrnum (ase_awk_run_t* run)
|
||||
{
|
||||
return run->errnum;
|
||||
@ -540,7 +551,8 @@ 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)
|
||||
ase_awk_runarg_t* runarg,
|
||||
void* custom_data)
|
||||
{
|
||||
ase_awk_run_t* run;
|
||||
int n, errnum;
|
||||
@ -558,7 +570,7 @@ int ase_awk_run (ase_awk_t* awk,
|
||||
|
||||
__add_run (awk, run);
|
||||
|
||||
if (__init_run (run, runios, &errnum) == -1)
|
||||
if (__init_run (run, runios, custom_data, &errnum) == -1)
|
||||
{
|
||||
awk->errnum = errnum;
|
||||
__del_run (awk, run);
|
||||
@ -684,8 +696,12 @@ static void __del_run (ase_awk_t* awk, ase_awk_run_t* run)
|
||||
ASE_AWK_UNLOCK (awk);
|
||||
}
|
||||
|
||||
static int __init_run (ase_awk_run_t* run, ase_awk_runios_t* runios, int* errnum)
|
||||
static int __init_run (
|
||||
ase_awk_run_t* run, ase_awk_runios_t* runios,
|
||||
void* custom_data, int* errnum)
|
||||
{
|
||||
run->custom_data = custom_data;
|
||||
|
||||
run->stack = ASE_NULL;
|
||||
run->stack_top = 0;
|
||||
run->stack_base = 0;
|
||||
@ -4575,12 +4591,14 @@ static ase_awk_val_t* __eval_bfn (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
||||
/* built-in function */
|
||||
if (call->nargs < call->what.bfn.arg.min)
|
||||
{
|
||||
PANIC (run, ASE_AWK_ETOOFEWARGS);
|
||||
run->errnum = ASE_AWK_ETOOFEWARGS;
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
if (call->nargs > call->what.bfn.arg.max)
|
||||
{
|
||||
PANIC (run, ASE_AWK_ETOOMANYARGS);
|
||||
run->errnum = ASE_AWK_ETOOMANYARGS;
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return __eval_call (run, nde, call->what.bfn.arg.spec, ASE_NULL);
|
||||
@ -4594,15 +4612,21 @@ static ase_awk_val_t* __eval_afn (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
||||
|
||||
pair = ase_awk_map_get (&run->awk->tree.afns,
|
||||
call->what.afn.name.ptr, call->what.afn.name.len);
|
||||
if (pair == ASE_NULL) PANIC (run, ASE_AWK_ENOSUCHFUNC);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
run->errnum = ASE_AWK_ENOSUCHFN;
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
afn = (ase_awk_afn_t*)pair->val;
|
||||
ASE_AWK_ASSERT (run->awk, afn != ASE_NULL);
|
||||
|
||||
if (call->nargs > afn->nargs)
|
||||
{
|
||||
/* TODO: is this correct? what if i want to allow arbitarary numbers of arguments? */
|
||||
PANIC (run, ASE_AWK_ETOOMANYARGS);
|
||||
/* TODO: is this correct? what if i want to
|
||||
* allow arbitarary numbers of arguments? */
|
||||
run->errnum = ASE_AWK_ETOOMANYARGS;
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return __eval_call (run, nde, ASE_NULL, afn);
|
||||
@ -4712,13 +4736,16 @@ static ase_awk_val_t* __eval_call (
|
||||
PANIC (run, ASE_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
nargs = 0;
|
||||
p = call->args;
|
||||
/*
|
||||
nargs = 0; p = call->args;
|
||||
while (p != ASE_NULL)
|
||||
*/
|
||||
for (p = call->args, nargs = 0; p != ASE_NULL; p = p->next, nargs++)
|
||||
{
|
||||
ASE_AWK_ASSERT (run->awk, bfn_arg_spec == ASE_NULL ||
|
||||
(bfn_arg_spec != ASE_NULL &&
|
||||
ase_awk_strlen(bfn_arg_spec) > nargs));
|
||||
ASE_AWK_ASSERT (run->awk,
|
||||
bfn_arg_spec == ASE_NULL ||
|
||||
(bfn_arg_spec != ASE_NULL &&
|
||||
ase_awk_strlen(bfn_arg_spec) > nargs));
|
||||
|
||||
if (bfn_arg_spec != ASE_NULL &&
|
||||
bfn_arg_spec[nargs] == ASE_T('r'))
|
||||
@ -4753,43 +4780,6 @@ static ase_awk_val_t* __eval_call (
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (bfn_arg_spec != ASE_NULL &&
|
||||
bfn_arg_spec[nargs] == ASE_T('r'))
|
||||
{
|
||||
ase_awk_val_t** ref;
|
||||
ase_awk_val_t* tmp;
|
||||
|
||||
ref = __get_reference (run, p);
|
||||
if (ref == ASE_NULL)
|
||||
{
|
||||
ase_awk_refupval (run, v);
|
||||
ase_awk_refdownval (run, v);
|
||||
|
||||
UNWIND_RUN_STACK (run, nargs);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
/* p->type-ASE_AWK_NDE_NAMED assumes that the
|
||||
* derived value matches ASE_AWK_VAL_REF_XXX */
|
||||
tmp = ase_awk_makerefval (
|
||||
run, p->type-ASE_AWK_NDE_NAMED, ref);
|
||||
if (tmp == ASE_NULL)
|
||||
{
|
||||
ase_awk_refupval (run, v);
|
||||
ase_awk_refdownval (run, v);
|
||||
|
||||
UNWIND_RUN_STACK (run, nargs);
|
||||
PANIC (run, ASE_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, v);
|
||||
ase_awk_refdownval (run, v);
|
||||
|
||||
v = tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (__raw_push(run,v) == -1)
|
||||
{
|
||||
/* ugly - v needs to be freed if it doesn't have
|
||||
@ -4805,8 +4795,7 @@ static ase_awk_val_t* __eval_call (
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, v);
|
||||
nargs++;
|
||||
p = p->next;
|
||||
/*nargs++; p = p->next;*/
|
||||
}
|
||||
|
||||
ASE_AWK_ASSERT (run->awk, nargs == call->nargs);
|
||||
@ -4844,11 +4833,17 @@ static ase_awk_val_t* __eval_call (
|
||||
n = 0;
|
||||
|
||||
/* built-in function */
|
||||
ASE_AWK_ASSERT (run->awk, call->nargs >= call->what.bfn.arg.min &&
|
||||
call->nargs <= call->what.bfn.arg.max);
|
||||
ASE_AWK_ASSERT (run->awk,
|
||||
call->nargs >= call->what.bfn.arg.min &&
|
||||
call->nargs <= call->what.bfn.arg.max);
|
||||
|
||||
if (call->what.bfn.handler != ASE_NULL)
|
||||
n = call->what.bfn.handler (run);
|
||||
{
|
||||
n = call->what.bfn.handler (
|
||||
run,
|
||||
call->what.bfn.name.ptr,
|
||||
call->what.bfn.name.len);
|
||||
}
|
||||
}
|
||||
|
||||
/*run->awk->syscas.dprintf (ASE_T("block run complete\n")); */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.h,v 1.82 2006-11-27 15:10:35 bacon Exp $
|
||||
* $Id: tree.h,v 1.83 2006-11-28 04:30:22 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_TREE_H_
|
||||
@ -270,9 +270,9 @@ struct ase_awk_nde_call_t
|
||||
const ase_char_t* spec;
|
||||
} arg;
|
||||
|
||||
int (*handler) (ase_awk_run_t* awk);
|
||||
int (*handler) (
|
||||
ase_awk_run_t*, const ase_char_t*, ase_size_t);
|
||||
} bfn;
|
||||
/* ase_awk_bfn_t* bfn; */
|
||||
} what;
|
||||
ase_awk_nde_t* args;
|
||||
ase_size_t nargs;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.java,v 1.13 2006-11-27 15:11:14 bacon Exp $
|
||||
* $Id: Awk.java,v 1.14 2006-11-28 04:30:57 bacon Exp $
|
||||
*/
|
||||
|
||||
package ase.test.awk;
|
||||
@ -19,8 +19,10 @@ public class Awk extends ase.awk.StdAwk
|
||||
addBuiltinFunction ("sin", 1, 1);
|
||||
}
|
||||
|
||||
public void bfn_sin ()
|
||||
public int sin ()
|
||||
{
|
||||
System.out.println ("BFN_SIN....");
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected String[] getInputConsoleNames ()
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.128 2006-11-27 15:11:14 bacon Exp $
|
||||
* $Id: awk.c,v 1.129 2006-11-28 04:30:57 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk.h>
|
||||
@ -896,7 +896,7 @@ ase_awk_addbfn (awk, ASE_T("bufa"), 4, 0,
|
||||
runarg[3].ptr = ASE_NULL;
|
||||
runarg[3].len = 0;
|
||||
|
||||
if (ase_awk_run (awk, mfn, &runios, &runcbs, runarg) == -1)
|
||||
if (ase_awk_run (awk, mfn, &runios, &runcbs, runarg, ASE_NULL) == -1)
|
||||
{
|
||||
int errnum = ase_awk_geterrnum(awk);
|
||||
xp_printf (
|
||||
|
@ -27,7 +27,7 @@ END {
|
||||
arr[0] = "xxx";
|
||||
#print split ("abc def abc", arr);
|
||||
print split ("abc def kkk", j);
|
||||
print split ("abc def kkk", $0);
|
||||
print split ("abc def kkk", $0); # error
|
||||
|
||||
#xyz = 20;
|
||||
#print xyz;
|
||||
|
Loading…
Reference in New Issue
Block a user