just a temporary commit while changing code for new convention

This commit is contained in:
hyung-hwan 2008-09-25 05:07:24 +00:00
parent 327fd11974
commit 3dcab112d9
7 changed files with 200 additions and 179 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: macros.h 354 2008-08-31 10:57:24Z baconevi $ * $Id: macros.h 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -66,8 +66,10 @@
} \ } \
} while (0); } while (0);
#define ASE_NCHARS_TO_NBYTES(x) ((x)*sizeof(ase_char_t)) /* number of characters to number of bytes */
#define ASE_NBYTES_TO_NCHARS(x) ((x)/sizeof(ase_char_t)) #define ASE_NCTONB(x) ((x)*sizeof(ase_char_t))
/* number of bytes to number of characters */
#define ASE_NBTONC(x) ((x)/sizeof(ase_char_t))
#define ASE_MQ_I(val) #val #define ASE_MQ_I(val) #val
#define ASE_MQ(val) ASE_MQ_I(val) #define ASE_MQ(val) ASE_MQ_I(val)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c 380 2008-09-24 08:16:41Z baconevi $ * $Id: awk.c 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -61,7 +61,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_MEMSET (awk, 0, ASE_SIZEOF(ase_awk_t) + ext); ASE_MEMSET (awk, 0, ASE_SIZEOF(ase_awk_t) + ext);
awk->mmgr = mmgr; awk->mmgr = mmgr;
if (ase_str_open (&awk->token.name, 128, mmgr) == ASE_NULL) if (ase_str_init (&awk->token.name, mmgr, 128) == ASE_NULL)
{ {
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
@ -82,7 +82,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
if (awk->rwtab == ASE_NULL) if (awk->rwtab == ASE_NULL)
{ {
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -97,7 +97,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
{ {
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -111,11 +111,12 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.afns) = awk; *(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.afns) = awk;
ase_map_setcopier (awk->parse.afns, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
/*awk->parse.named = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);*/ /*awk->parse.named = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);*/
awk->parse.named = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70); awk->parse.named = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
@ -125,11 +126,12 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.named) = awk; *(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.named) = awk;
ase_map_setcopier (awk->parse.named, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL) if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{ {
@ -138,7 +140,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -151,7 +153,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -165,7 +167,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -215,7 +217,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -246,7 +248,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -273,7 +275,7 @@ int ase_awk_close (ase_awk_t* awk)
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
ase_str_close (&awk->token.name); ase_str_fini (&awk->token.name);
for (i = 0; i < ASE_COUNTOF(awk->errstr); i++) for (i = 0; i < ASE_COUNTOF(awk->errstr); i++)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 372 2008-09-23 09:51:24Z baconevi $ * $Id: parse.c 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -226,7 +226,7 @@ static int is_plain_var (ase_awk_nde_t* nde);
static int is_var (ase_awk_nde_t* nde); static int is_var (ase_awk_nde_t* nde);
static int deparse (ase_awk_t* awk); static int deparse (ase_awk_t* awk);
static int deparse_func (ase_map_pair_t* pair, void* arg); static ase_map_walk_t deparse_func (ase_map_t* map, ase_map_pair_t* pair, void* arg);
static int put_char (ase_awk_t* awk, ase_char_t c); static int put_char (ase_awk_t* awk, ase_char_t c);
static int flush_out (ase_awk_t* awk); static int flush_out (ase_awk_t* awk);
@ -464,11 +464,11 @@ ase_cstr_t* ase_awk_getkw (ase_awk_t* awk, int id, ase_cstr_t* s)
s->ptr = kwtab[id].name; s->ptr = kwtab[id].name;
s->len = kwtab[id].name_len; s->len = kwtab[id].name_len;
p = ase_map_search (awk->wtab, s->ptr, ASE_NCHARS_TO_NBYTES(s->len)); p = ase_map_search (awk->wtab, s->ptr, ASE_NCTONB(s->len));
if (p != ASE_NULL) if (p != ASE_NULL)
{ {
s->ptr = ASE_MAP_VPTR(p); s->ptr = ASE_MAP_VPTR(p);
s->len = ASE_NBYTES_TO_NCHARS(ASE_MAP_VLEN(p)); s->len = ASE_MAP_VCLEN(p);
} }
return s; return s;
@ -555,12 +555,10 @@ static int parse (ase_awk_t* awk)
ASE_MAP_KPTR(p), ASE_MAP_KLEN(p)) == ASE_NULL) ASE_MAP_KPTR(p), ASE_MAP_KLEN(p)) == ASE_NULL)
{ {
/* TODO: set better error no & line */ /* TODO: set better error no & line */
/* this line number might be truncated as
* sizeof(line) could be > sizeof(void*) */
SETERRARG (awk, ASE_AWK_EFNNONE, SETERRARG (awk, ASE_AWK_EFNNONE,
(ase_size_t)p->val, *(ase_size_t*)ASE_MAP_VPTR(p),
ASE_MAP_KPTR(p), ASE_MAP_KPTR(p),
ASE_NBYTES_TO_NCHARS(ASE_MAP_KELN(p))); ASE_MAP_KCLEN(p));
EXIT_PARSE(-1); EXIT_PARSE(-1);
} }
@ -1077,8 +1075,8 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
return ASE_NULL; return ASE_NULL;
} }
afn->name = ASE_NULL; /* function name set below */ afn->name.ptr = ASE_NULL; /* function name is set below */
afn->name_len = 0; afn->name.len = 0;
afn->nargs = nargs; afn->nargs = nargs;
afn->body = body; afn->body = body;
@ -1096,12 +1094,14 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
/* duplicate functions should have been detected previously */ /* duplicate functions should have been detected previously */
ASE_ASSERT (n != 0); ASE_ASSERT (n != 0);
afn->name = ASE_PAIR_KEYPTR(pair); /* do some trick to save a string. */ /* do some trick to save a string. make it back-point at the key part
afn->name_len = ASE_PAIR_KEYLEN(pair); * of the pair */
afn->name.ptr = ASE_MAP_KPTR(pair);
afn->name.len = ASE_MAP_KCLEN(pair);
ASE_AWK_FREE (awk, name_dup); ASE_AWK_FREE (awk, name_dup);
/* remove the undefined function call entries from parse.afn table */ /* remove an undefined function call entry from the parse.afn table */
ase_map_remove (awk->parse.afns, afn->name, name_len); ase_map_remove (awk->parse.afns, afn->name.ptr, ASE_NCTONB(name_len));
return body; return body;
} }
@ -1487,7 +1487,7 @@ static int add_global (
/* check if it conflict with a function name /* check if it conflict with a function name
* caught in the function call table */ * caught in the function call table */
if (ase_map_search (awk->parse.afns, name, len) != ASE_NULL) if (ase_map_search (awk->parse.afns, name, ASE_NCTONB(len)) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EAFNRED, line, awk, ASE_AWK_EAFNRED, line,
@ -1627,8 +1627,7 @@ static ase_awk_t* collect_globals (ase_awk_t* awk)
static ase_awk_t* collect_locals ( static ase_awk_t* collect_locals (
ase_awk_t* awk, ase_size_t nlocals, ase_bool_t istop) ase_awk_t* awk, ase_size_t nlocals, ase_bool_t istop)
{ {
ase_char_t* local; ase_xstr_t local;
ase_size_t local_len;
ase_size_t n; ase_size_t n;
while (1) while (1)
@ -1639,8 +1638,8 @@ static ase_awk_t* collect_locals (
return ASE_NULL; return ASE_NULL;
} }
local = ASE_STR_PTR(&awk->token.name); local.ptr = ASE_STR_PTR(&awk->token.name);
local_len = ASE_STR_LEN(&awk->token.name); local.len = ASE_STR_LEN(&awk->token.name);
#if 0 #if 0
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
@ -1650,11 +1649,11 @@ static ase_awk_t* collect_locals (
/* check if it conflict with a builtin function name /* check if it conflict with a builtin function name
* function f() { local length; } */ * function f() { local length; } */
if (ase_awk_getbfn (awk, local, local_len) != ASE_NULL) if (ase_awk_getbfn (awk, local.ptr, local.len) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EBFNRED, awk->token.line, awk, ASE_AWK_EBFNRED, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
@ -1664,24 +1663,25 @@ static ase_awk_t* collect_locals (
{ {
iscur = (ase_strxncmp ( iscur = (ase_strxncmp (
awk->tree.cur_afn.ptr, awk->tree.cur_afn.len, awk->tree.cur_afn.ptr, awk->tree.cur_afn.len,
local, local_len) == 0); local.ptr, local.len) == 0);
} }
if (iscur || ase_map_search (awk->tree.afns, local, local_len) != ASE_NULL) if (iscur || ase_map_search (awk->tree.afns, local.ptr, local.len) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EAFNRED, awk->token.line, awk, ASE_AWK_EAFNRED, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
/* check if it conflict with a function name /* check if it conflict with a function name
* caught in the function call table */ * caught in the function call table */
if (ase_map_search (awk->parse.afns, local, local_len) != ASE_NULL) if (ase_map_search (awk->parse.afns,
local.ptr, ASE_NCTONB(local.len)) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EAFNRED, awk->token.line, awk, ASE_AWK_EAFNRED, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
} }
@ -1690,12 +1690,12 @@ static ase_awk_t* collect_locals (
if (istop) if (istop)
{ {
/* check if it conflicts with a paremeter name */ /* check if it conflicts with a paremeter name */
n = ase_awk_tab_find (&awk->parse.params, 0, local, local_len); n = ase_awk_tab_find (&awk->parse.params, 0, local.ptr, local.len);
if (n != (ase_size_t)-1) if (n != (ase_size_t)-1)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EPARRED, awk->token.line, awk, ASE_AWK_EPARRED, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
} }
@ -1704,17 +1704,17 @@ static ase_awk_t* collect_locals (
n = ase_awk_tab_find ( n = ase_awk_tab_find (
&awk->parse.locals, &awk->parse.locals,
nlocals, /*((awk->option&ASE_AWK_SHADING)? nlocals:0)*/ nlocals, /*((awk->option&ASE_AWK_SHADING)? nlocals:0)*/
local, local_len); local.ptr, local.len);
if (n != (ase_size_t)-1) if (n != (ase_size_t)-1)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line, awk, ASE_AWK_EDUPLCL, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
/* check if it conflicts with global variable names */ /* check if it conflicts with global variable names */
n = find_global (awk, local, local_len); n = find_global (awk, local.ptr, local.len);
if (n != (ase_size_t)-1) if (n != (ase_size_t)-1)
{ {
if (n < awk->tree.nbglobals) if (n < awk->tree.nbglobals)
@ -1722,7 +1722,7 @@ static ase_awk_t* collect_locals (
/* conflicting with a static global variable */ /* conflicting with a static global variable */
SETERRARG ( SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line, awk, ASE_AWK_EDUPLCL, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
@ -1732,7 +1732,7 @@ static ase_awk_t* collect_locals (
/* conflicting with a normal global variable */ /* conflicting with a normal global variable */
SETERRARG ( SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line, awk, ASE_AWK_EDUPLCL, awk->token.line,
local, local_len); local.ptr, local.len);
return ASE_NULL; return ASE_NULL;
} }
#endif #endif
@ -1745,7 +1745,7 @@ static ase_awk_t* collect_locals (
} }
if (ase_awk_tab_add ( if (ase_awk_tab_add (
&awk->parse.locals, local, local_len) == (ase_size_t)-1) &awk->parse.locals, local.ptr, local.len) == (ase_size_t)-1)
{ {
SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line);
return ASE_NULL; return ASE_NULL;
@ -3179,9 +3179,9 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
nde->type = ASE_AWK_NDE_LOCAL; nde->type = ASE_AWK_NDE_LOCAL;
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL;*/ /*nde->id.name.ptr = ASE_NULL;*/
nde->id.name = name_dup; nde->id.name.ptr = name_dup;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = ASE_NULL; nde->idx = ASE_NULL;
@ -3215,8 +3215,8 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL;*/ /*nde->id.name = ASE_NULL;*/
nde->id.name = name_dup; nde->id.name.ptr = name_dup;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = ASE_NULL; nde->idx = ASE_NULL;
@ -3250,8 +3250,8 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL;*/ /*nde->id.name = ASE_NULL;*/
nde->id.name = name_dup; nde->id.name.ptr = name_dup;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = ASE_NULL; nde->idx = ASE_NULL;
@ -3264,7 +3264,8 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
if (awk->option & ASE_AWK_IMPLICIT) if (awk->option & ASE_AWK_IMPLICIT)
{ {
if (ase_map_search (awk->parse.named, name_dup, name_len) != ASE_NULL) if (ase_map_search (awk->parse.named,
name_dup, ASE_NCTONB(name_len)) != ASE_NULL)
{ {
/* a function call conflicts with a named variable */ /* a function call conflicts with a named variable */
SETERRARG (awk, ASE_AWK_EVARRED, line, name_dup, name_len); SETERRARG (awk, ASE_AWK_EVARRED, line, name_dup, name_len);
@ -3322,7 +3323,8 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
goto exit_func; goto exit_func;
} }
if (ase_map_search (awk->parse.afns, name_dup, name_len) != ASE_NULL) if (ase_map_search (awk->parse.afns,
name_dup, ASE_NCTONB(name_len)) != ASE_NULL)
{ {
/* is it one of the function calls found so far? */ /* is it one of the function calls found so far? */
SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len); SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len);
@ -3335,14 +3337,15 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
nde->type = ASE_AWK_NDE_NAMED; nde->type = ASE_AWK_NDE_NAMED;
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
nde->id.name = name_dup; nde->id.name.ptr = name_dup;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = (ase_size_t)-1; nde->id.idxa = (ase_size_t)-1;
nde->idx = ASE_NULL; nde->idx = ASE_NULL;
/* collect unique instances of a named variables for reference */ /* collect unique instances of a named variables for reference */
if (ase_map_upsert (awk->parse.named, if (ase_map_upsert (awk->parse.named,
name_dup, name_len, (void*)line) == ASE_NULL) name_dup, ASE_NCTONB(name_len),
&line, ASE_SIZEOF(line)) == ASE_NULL)
{ {
SETERRLIN (awk, ASE_AWK_ENOMEM, line); SETERRLIN (awk, ASE_AWK_ENOMEM, line);
goto exit_func; goto exit_func;
@ -3433,8 +3436,8 @@ static ase_awk_nde_t* parse_hashidx (
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL; */ /*nde->id.name = ASE_NULL; */
nde->id.name = name; nde->id.name.ptr = name;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = idx; nde->idx = idx;
@ -3449,8 +3452,8 @@ static ase_awk_nde_t* parse_hashidx (
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL; */ /*nde->id.name = ASE_NULL; */
nde->id.name = name; nde->id.name.ptr = name;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = idx; nde->idx = idx;
@ -3465,8 +3468,8 @@ static ase_awk_nde_t* parse_hashidx (
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL;*/ /*nde->id.name = ASE_NULL;*/
nde->id.name = name; nde->id.name.ptr = name;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = idx; nde->idx = idx;
@ -3503,7 +3506,9 @@ static ase_awk_nde_t* parse_hashidx (
goto exit_func; goto exit_func;
} }
if (ase_map_search (awk->parse.afns, name, name_len) != ASE_NULL) if (ase_map_search (
awk->parse.afns,
name, ASE_NCTONB(name_len)) != ASE_NULL)
{ {
/* is it one of the function calls found so far? */ /* is it one of the function calls found so far? */
SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len); SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len);
@ -3516,8 +3521,8 @@ static ase_awk_nde_t* parse_hashidx (
nde->type = ASE_AWK_NDE_NAMEDIDX; nde->type = ASE_AWK_NDE_NAMEDIDX;
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
nde->id.name = name; nde->id.name.ptr = name;
nde->id.name_len = name_len; nde->id.name.len = name_len;
nde->id.idxa = (ase_size_t)-1; nde->id.idxa = (ase_size_t)-1;
nde->idx = idx; nde->idx = idx;
@ -3653,10 +3658,11 @@ static ase_awk_nde_t* parse_fncall (
{ {
#endif #endif
/* this line number might be truncated as /* store a non-builtin function call into the parse.afns table */
* sizeof(line) could be > sizeof(void*) */ if (ase_map_upsert (
if (ase_map_upsert (awk->parse.afns, awk->parse.afns,
name, name_len, (void*)line) == ASE_NULL) name, ASE_NCTONB(name_len),
&line, ASE_SIZEOF(line)) == ASE_NULL)
{ {
ASE_AWK_FREE (awk, call); ASE_AWK_FREE (awk, call);
if (head != ASE_NULL) ase_awk_clrpt (awk, head); if (head != ASE_NULL) ase_awk_clrpt (awk, head);
@ -5521,8 +5527,8 @@ static int deparse (ase_awk_t* awk)
ASE_ASSERT (awk->tree.nglobals > 0); ASE_ASSERT (awk->tree.nglobals > 0);
ase_awk_getkw (ase, KW_GLOBAL, &kw); ase_awk_getkw (awk, KW_GLOBAL, &kw);
if (ase_awk_putsrcstrx(awk,kw.ptr,kw.len)) == -1) if (ase_awk_putsrcstrx(awk,kw.ptr,kw.len) == -1)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
@ -5610,8 +5616,11 @@ static int deparse (ase_awk_t* awk)
for (nde = awk->tree.begin; nde != ASE_NULL; nde = nde->next) for (nde = awk->tree.begin; nde != ASE_NULL; nde = nde->next)
{ {
const ase_char_t* kw = ase_awk_getkw(awk,ASE_T("BEGIN")); ase_cstr_t kw;
if (ase_awk_putsrcstr(awk,kw) == -1) EXIT_DEPARSE ();
ase_awk_getkw (awk, KW_BEGIN, &kw);
if (ase_awk_putsrcstrx (awk, kw.ptr, kw.len) == -1) EXIT_DEPARSE ();
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE (); if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE ();
if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE (); if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE ();
@ -5669,8 +5678,11 @@ static int deparse (ase_awk_t* awk)
for (nde = awk->tree.end; nde != ASE_NULL; nde = nde->next) for (nde = awk->tree.end; nde != ASE_NULL; nde = nde->next)
{ {
const ase_char_t* kw = ase_awk_getkw(awk,ASE_T("END")); ase_cstr_t kw;
if (ase_awk_putsrcstr(awk,kw) == -1) EXIT_DEPARSE ();
ase_awk_getkw (awk, KW_END, &kw);
if (ase_awk_putsrcstrx (awk, kw.ptr, kw.len) == -1) EXIT_DEPARSE ();
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE (); if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE ();
if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE (); if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE ();
@ -5703,15 +5715,15 @@ exit_deparse:
static int deparse_func (ase_map_pair_t* pair, void* arg) static ase_map_walk_t deparse_func (ase_map_t* map, ase_map_pair_t* pair, void* arg)
{ {
struct deparse_func_t* df = (struct deparse_func_t*)arg; struct deparse_func_t* df = (struct deparse_func_t*)arg;
/* CHECK: */ /* CHECK: */
ase_awk_afn_t* afn = (ase_awk_afn_t*)pair->vptr; ase_awk_afn_t* afn = (ase_awk_afn_t*)ASE_MAP_VPTR(pair);
ase_size_t i, n; ase_size_t i, n;
ase_cstr_t kw; ase_cstr_t kw;
ASE_ASSERT (ase_strxncmp (ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair), afn->name, afn->name_len) == 0); ASE_ASSERT (ase_strxncmp (ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair), afn->name.ptr, afn->name.len) == 0);
#define PUT_C(x,c) \ #define PUT_C(x,c) \
if (put_char(x->awk,c)==-1) { \ if (put_char(x->awk,c)==-1) { \
@ -5729,10 +5741,10 @@ static int deparse_func (ase_map_pair_t* pair, void* arg)
} }
ase_awk_getkw (df->awk, KW_FUNCTION, &kw); ase_awk_getkw (df->awk, KW_FUNCTION, &kw);
PUT_SX (df, kw->ptr, kw->len)); PUT_SX (df, kw.ptr, kw.len);
PUT_C (df, ASE_T(' ')); PUT_C (df, ASE_T(' '));
PUT_S (df, afn->name); PUT_SX (df, afn->name.ptr, afn->name.len);
PUT_S (df, ASE_T(" (")); PUT_S (df, ASE_T(" ("));
for (i = 0; i < afn->nargs; ) for (i = 0; i < afn->nargs; )

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c 372 2008-09-23 09:51:24Z baconevi $ * $Id: run.c 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -264,8 +264,8 @@ static int set_global (
/* global variable */ /* global variable */
ase_cstr_t errarg; ase_cstr_t errarg;
errarg.ptr = var->id.name; errarg.ptr = var->id.name.ptr;
errarg.len = var->id.name_len; errarg.len = var->id.name.len;
ase_awk_setrunerror (run, ase_awk_setrunerror (run,
ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1);
@ -768,24 +768,24 @@ static int init_run (
run->inrec.nflds = 0; run->inrec.nflds = 0;
run->inrec.maxflds = 0; run->inrec.maxflds = 0;
run->inrec.d0 = ase_awk_val_nil; run->inrec.d0 = ase_awk_val_nil;
if (ase_str_open ( if (ase_str_init (
&run->inrec.line, DEF_BUF_CAPA, MMGR(run)) == ASE_NULL) &run->inrec.line, MMGR(run), DEF_BUF_CAPA) == ASE_NULL)
{ {
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
if (ase_str_open (&run->format.out, 256, MMGR(run)) == ASE_NULL) if (ase_str_init (&run->format.out, MMGR(run), 256) == ASE_NULL)
{ {
ase_str_close (&run->inrec.line); ase_str_fini (&run->inrec.line);
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
if (ase_str_open (&run->format.fmt, 256, MMGR(run)) == ASE_NULL) if (ase_str_init (&run->format.fmt, MMGR(run), 256) == ASE_NULL)
{ {
ase_str_close (&run->format.out); ase_str_fini (&run->format.out);
ase_str_close (&run->inrec.line); ase_str_fini (&run->inrec.line);
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
@ -794,9 +794,9 @@ static int init_run (
run, 1024, 70, free_namedval, same_namedval, MMGR(run)); run, 1024, 70, free_namedval, same_namedval, MMGR(run));
if (run->named == ASE_NULL) if (run->named == ASE_NULL)
{ {
ase_str_close (&run->format.fmt); ase_str_fini (&run->format.fmt);
ase_str_close (&run->format.out); ase_str_fini (&run->format.out);
ase_str_close (&run->inrec.line); ase_str_fini (&run->inrec.line);
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
@ -806,9 +806,9 @@ static int init_run (
if (run->format.tmp.ptr == ASE_NULL) if (run->format.tmp.ptr == ASE_NULL)
{ {
ase_map_close (run->named); ase_map_close (run->named);
ase_str_close (&run->format.fmt); ase_str_fini (&run->format.fmt);
ase_str_close (&run->format.out); ase_str_fini (&run->format.out);
ase_str_close (&run->inrec.line); ase_str_fini (&run->inrec.line);
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
@ -823,9 +823,9 @@ static int init_run (
{ {
ASE_AWK_FREE (run->awk, run->format.tmp.ptr); ASE_AWK_FREE (run->awk, run->format.tmp.ptr);
ase_map_close (run->named); ase_map_close (run->named);
ase_str_close (&run->format.fmt); ase_str_fini (&run->format.fmt);
ase_str_close (&run->format.out); ase_str_fini (&run->format.out);
ase_str_close (&run->inrec.line); ase_str_fini (&run->inrec.line);
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
@ -923,8 +923,8 @@ static void deinit_run (ase_awk_run_t* run)
ASE_AWK_FREE (run->awk, run->format.tmp.ptr); ASE_AWK_FREE (run->awk, run->format.tmp.ptr);
run->format.tmp.ptr = ASE_NULL; run->format.tmp.ptr = ASE_NULL;
run->format.tmp.len = 0; run->format.tmp.len = 0;
ase_str_close (&run->format.fmt); ase_str_fini (&run->format.fmt);
ase_str_close (&run->format.out); ase_str_fini (&run->format.out);
/* destroy input record. ase_awk_clrrec should be called /* destroy input record. ase_awk_clrrec should be called
* before the run stack has been destroyed because it may try * before the run stack has been destroyed because it may try
@ -936,7 +936,7 @@ static void deinit_run (ase_awk_run_t* run)
run->inrec.flds = ASE_NULL; run->inrec.flds = ASE_NULL;
run->inrec.maxflds = 0; run->inrec.maxflds = 0;
} }
ase_str_close (&run->inrec.line); ase_str_fini (&run->inrec.line);
/* destroy run stack */ /* destroy run stack */
if (run->stack != ASE_NULL) if (run->stack != ASE_NULL)
@ -2449,7 +2449,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
"if a named variable has an index part and a named indexed variable doesn't have an index part, the program is definitely wrong"); "if a named variable has an index part and a named indexed variable doesn't have an index part, the program is definitely wrong");
pair = ase_map_search ( pair = ase_map_search (
run->named, var->id.name, var->id.name_len); run->named, var->id.name.ptr, var->id.name.len);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
ase_awk_val_t* tmp; ase_awk_val_t* tmp;
@ -2466,7 +2466,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
} }
pair = ase_map_upsert (run->named, pair = ase_map_upsert (run->named,
var->id.name, var->id.name_len, tmp); var->id.name.ptr, var->id.name.len, tmp);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
ase_awk_refupval (run, tmp); ase_awk_refupval (run, tmp);
@ -2495,7 +2495,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
ase_cstr_t errarg; ase_cstr_t errarg;
errarg.ptr = var->id.name; errarg.ptr = var->id.name;
errarg.len = var->id.name_len; errarg.len = var->id.name.len;
ase_awk_setrunerror ( ase_awk_setrunerror (
run, ASE_AWK_ENOTDEL, var->line, run, ASE_AWK_ENOTDEL, var->line,
@ -2619,7 +2619,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
ase_cstr_t errarg; ase_cstr_t errarg;
errarg.ptr = var->id.name; errarg.ptr = var->id.name;
errarg.len = var->id.name_len; errarg.len = var->id.name.len;
ase_awk_setrunerror ( ase_awk_setrunerror (
run, ASE_AWK_ENOTDEL, var->line, run, ASE_AWK_ENOTDEL, var->line,
@ -2701,7 +2701,7 @@ static int run_reset (ase_awk_run_t* run, ase_awk_nde_reset_t* nde)
/* a named variable can be reset if removed from a internal map /* a named variable can be reset if removed from a internal map
to manage it */ to manage it */
ase_map_remove (run->named, var->id.name, var->id.name_len); ase_map_remove (run->named, var->id.name.ptr, var->id.name.len);
} }
else if (var->type == ASE_AWK_NDE_GLOBAL || else if (var->type == ASE_AWK_NDE_GLOBAL ||
var->type == ASE_AWK_NDE_LOCAL || var->type == ASE_AWK_NDE_LOCAL ||
@ -3328,7 +3328,7 @@ static ase_awk_val_t* do_assignment_scalar (
int n; int n;
pair = ase_map_search ( pair = ase_map_search (
run->named, var->id.name, var->id.name_len); run->named, var->id.name.ptr, var->id.name.len);
if (pair != ASE_NULL && if (pair != ASE_NULL &&
((ase_awk_val_t*)pair->val)->type == ASE_AWK_VAL_MAP) ((ase_awk_val_t*)pair->val)->type == ASE_AWK_VAL_MAP)
{ {
@ -3337,7 +3337,7 @@ static ase_awk_val_t* do_assignment_scalar (
ase_cstr_t errarg; ase_cstr_t errarg;
errarg.ptr = var->id.name; errarg.ptr = var->id.name;
errarg.len = var->id.name_len; errarg.len = var->id.name.len;
ase_awk_setrunerror (run, ase_awk_setrunerror (run,
ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1);
@ -3345,7 +3345,7 @@ static ase_awk_val_t* do_assignment_scalar (
} }
n = ase_map_upsertx (run->named, n = ase_map_upsertx (run->named,
var->id.name, var->id.name_len, val, ASE_NULL); var->id.name.ptr, var->id.name.len, val, ASE_NULL);
if (n < 0) if (n < 0)
{ {
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -3374,7 +3374,7 @@ static ase_awk_val_t* do_assignment_scalar (
ase_cstr_t errarg; ase_cstr_t errarg;
errarg.ptr = var->id.name; errarg.ptr = var->id.name;
errarg.len = var->id.name_len; errarg.len = var->id.name.len;
ase_awk_setrunerror (run, ase_awk_setrunerror (run,
ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1);
@ -3395,7 +3395,7 @@ static ase_awk_val_t* do_assignment_scalar (
ase_cstr_t errarg; ase_cstr_t errarg;
errarg.ptr = var->id.name; errarg.ptr = var->id.name;
errarg.len = var->id.name_len; errarg.len = var->id.name.len;
ase_awk_setrunerror (run, ase_awk_setrunerror (run,
ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1);
@ -3430,7 +3430,7 @@ static ase_awk_val_t* do_assignment_map (
{ {
ase_map_pair_t* pair; ase_map_pair_t* pair;
pair = ase_map_search ( pair = ase_map_search (
run->named, var->id.name, var->id.name_len); run->named, var->id.name.ptr, var->id.name.len);
map = (pair == ASE_NULL)? map = (pair == ASE_NULL)?
(ase_awk_val_map_t*)ase_awk_val_nil: (ase_awk_val_map_t*)ase_awk_val_nil:
(ase_awk_val_map_t*)pair->val; (ase_awk_val_map_t*)pair->val;
@ -3463,7 +3463,7 @@ static ase_awk_val_t* do_assignment_map (
* of the previous value here as it is done by * of the previous value here as it is done by
* ase_map_upsert */ * ase_map_upsert */
if (ase_map_upsert (run->named, if (ase_map_upsert (run->named,
var->id.name, var->id.name_len, tmp) == ASE_NULL) var->id.name.ptr, var->id.name.len, tmp) == ASE_NULL)
{ {
ase_awk_refupval (run, tmp); ase_awk_refupval (run, tmp);
ase_awk_refdownval (run, tmp); ase_awk_refdownval (run, tmp);
@ -5738,15 +5738,15 @@ static int get_reference (
ase_map_pair_t* pair; ase_map_pair_t* pair;
pair = ase_map_search ( pair = ase_map_search (
run->named, tgt->id.name, tgt->id.name_len); run->named, tgt->id.name.ptr, tgt->id.name.len);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
/* it is bad that the named variable has to be /* it is bad that the named variable has to be
* created in the function named "__get_refernce". * created in the function named "__get_refernce".
* would there be any better ways to avoid this? */ * would there be any better ways to avoid this? */
pair = ase_map_upsert ( pair = ase_map_upsert (
run->named, tgt->id.name, run->named, tgt->id.name.ptr,
tgt->id.name_len, ase_awk_val_nil); tgt->id.name.len, ase_awk_val_nil);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -5783,12 +5783,12 @@ static int get_reference (
ase_map_pair_t* pair; ase_map_pair_t* pair;
pair = ase_map_search ( pair = ase_map_search (
run->named, tgt->id.name, tgt->id.name_len); run->named, tgt->id.name.ptr, tgt->id.name.len);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
pair = ase_map_upsert ( pair = ase_map_upsert (
run->named, tgt->id.name, run->named, tgt->id.name.ptr,
tgt->id.name_len, ase_awk_val_nil); tgt->id.name.len, ase_awk_val_nil);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -5997,8 +5997,8 @@ static ase_awk_val_t* eval_named (ase_awk_run_t* run, ase_awk_nde_t* nde)
ase_map_pair_t* pair; ase_map_pair_t* pair;
pair = ase_map_search (run->named, pair = ase_map_search (run->named,
((ase_awk_nde_var_t*)nde)->id.name, ((ase_awk_nde_var_t*)nde)->id.name.ptr,
((ase_awk_nde_var_t*)nde)->id.name_len); ((ase_awk_nde_var_t*)nde)->id.name.len);
return (pair == ASE_NULL)? ase_awk_val_nil: pair->val; return (pair == ASE_NULL)? ase_awk_val_nil: pair->val;
} }
@ -6071,11 +6071,11 @@ static ase_awk_val_t* eval_namedidx (ase_awk_run_t* run, ase_awk_nde_t* nde)
ase_awk_nde_var_t* tgt = (ase_awk_nde_var_t*)nde; ase_awk_nde_var_t* tgt = (ase_awk_nde_var_t*)nde;
ase_map_pair_t* pair; ase_map_pair_t* pair;
pair = ase_map_search (run->named, tgt->id.name, tgt->id.name_len); pair = ase_map_search (run->named, tgt->id.name.ptr, tgt->id.name.len);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
pair = ase_map_upsert (run->named, pair = ase_map_upsert (run->named,
tgt->id.name, tgt->id.name_len, ase_awk_val_nil); tgt->id.name.ptr, tgt->id.name.len, ase_awk_val_nil);
if (pair == ASE_NULL) if (pair == ASE_NULL)
{ {
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -6207,7 +6207,7 @@ static ase_awk_val_t* eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde)
dst = (in == ASE_NULL)? ASE_T(""): in; dst = (in == ASE_NULL)? ASE_T(""): in;
/* TODO: optimize the line buffer management */ /* TODO: optimize the line buffer management */
if (ase_str_open (&buf, DEF_BUF_CAPA, MMGR(run)) == ASE_NULL) if (ase_str_init (&buf, MMGR(run), DEF_BUF_CAPA) == ASE_NULL)
{ {
if (in != ASE_NULL) ASE_AWK_FREE (run->awk, in); if (in != ASE_NULL) ASE_AWK_FREE (run->awk, in);
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -6233,11 +6233,11 @@ static ase_awk_val_t* eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde)
ASE_STR_PTR(&buf), ASE_STR_PTR(&buf),
ASE_STR_LEN(&buf)) == -1) ASE_STR_LEN(&buf)) == -1)
{ {
ase_str_close (&buf); ase_str_fini (&buf);
return ASE_NULL; return ASE_NULL;
} }
ase_str_close (&buf); ase_str_fini (&buf);
} }
else else
{ {
@ -6245,7 +6245,7 @@ static ase_awk_val_t* eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde)
v = ase_awk_makestrval (run, v = ase_awk_makestrval (run,
ASE_STR_PTR(&buf), ASE_STR_LEN(&buf)); ASE_STR_PTR(&buf), ASE_STR_LEN(&buf));
ase_str_close (&buf); ase_str_fini (&buf);
if (v == ASE_NULL) if (v == ASE_NULL)
{ {
run->errlin = nde->line; run->errlin = nde->line;
@ -6263,7 +6263,7 @@ static ase_awk_val_t* eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde)
} }
else else
{ {
ase_str_close (&buf); ase_str_fini (&buf);
} }
skip_read: skip_read:
@ -6386,8 +6386,8 @@ static int shorten_record (ase_awk_run_t* run, ase_size_t nflds)
} }
} }
if (ase_str_open ( if (ase_str_init (
&tmp, ASE_STR_LEN(&run->inrec.line), MMGR(run)) == ASE_NULL) &tmp, MMGR(run), ASE_STR_LEN(&run->inrec.line)) == ASE_NULL)
{ {
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1; return -1;
@ -6429,7 +6429,7 @@ static int shorten_record (ase_awk_run_t* run, ase_size_t nflds)
ase_awk_refupval (run, run->inrec.d0); ase_awk_refupval (run, run->inrec.d0);
ase_str_swap (&tmp, &run->inrec.line); ase_str_swap (&tmp, &run->inrec.line);
ase_str_close (&tmp); ase_str_fini (&tmp);
for (i = nflds; i < run->inrec.nflds; i++) for (i = nflds; i < run->inrec.nflds; i++)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c 363 2008-09-04 10:58:08Z baconevi $ * $Id: tree.c 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -372,7 +372,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
ASE_ASSERT (px->id.idxa == (ase_size_t)-1); ASE_ASSERT (px->id.idxa == (ase_size_t)-1);
ASE_ASSERT (px->idx == ASE_NULL); ASE_ASSERT (px->idx == ASE_NULL);
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
break; break;
} }
@ -382,7 +382,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
ASE_ASSERT (px->id.idxa == (ase_size_t)-1); ASE_ASSERT (px->id.idxa == (ase_size_t)-1);
ASE_ASSERT (px->idx != ASE_NULL); ASE_ASSERT (px->idx != ASE_NULL);
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
PUT_SRCSTR (awk, ASE_T("[")); PUT_SRCSTR (awk, ASE_T("["));
PRINT_EXPRESSION_LIST (awk, px->idx); PRINT_EXPRESSION_LIST (awk, px->idx);
PUT_SRCSTR (awk, ASE_T("]")); PUT_SRCSTR (awk, ASE_T("]"));
@ -401,12 +401,12 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
{ {
/* no implicit(named) variable is allowed. /* no implicit(named) variable is allowed.
* use the actual name */ * use the actual name */
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
} }
else if (px->id.idxa < awk->tree.nbglobals) else if (px->id.idxa < awk->tree.nbglobals)
{ {
/* static global variables */ /* static global variables */
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
} }
else else
{ {
@ -422,7 +422,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
} }
ASE_ASSERT (px->idx == ASE_NULL); ASE_ASSERT (px->idx == ASE_NULL);
break; break;
@ -439,12 +439,12 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
{ {
/* no implicit(named) variable is allowed. /* no implicit(named) variable is allowed.
* use the actual name */ * use the actual name */
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
} }
else if (px->id.idxa < awk->tree.nbglobals) else if (px->id.idxa < awk->tree.nbglobals)
{ {
/* static global variables */ /* static global variables */
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
} }
else else
{ {
@ -461,7 +461,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
PUT_SRCSTR (awk, ASE_T("[")); PUT_SRCSTR (awk, ASE_T("["));
} }
ASE_ASSERT (px->idx != ASE_NULL); ASE_ASSERT (px->idx != ASE_NULL);
@ -485,7 +485,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
} }
ASE_ASSERT (px->idx == ASE_NULL); ASE_ASSERT (px->idx == ASE_NULL);
break; break;
@ -507,7 +507,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
} }
else else
{ {
PUT_SRCSTRX (awk, px->id.name, px->id.name_len); PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
PUT_SRCSTR (awk, ASE_T("[")); PUT_SRCSTR (awk, ASE_T("["));
} }
ASE_ASSERT (px->idx != ASE_NULL); ASE_ASSERT (px->idx != ASE_NULL);
@ -1217,8 +1217,8 @@ void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree)
{ {
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p; ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p;
ASE_ASSERT (px->idx == ASE_NULL); ASE_ASSERT (px->idx == ASE_NULL);
if (px->id.name != ASE_NULL) if (px->id.name.ptr != ASE_NULL)
ASE_AWK_FREE (awk, px->id.name); ASE_AWK_FREE (awk, px->id.name.ptr);
ASE_AWK_FREE (awk, p); ASE_AWK_FREE (awk, p);
break; break;
} }
@ -1231,8 +1231,8 @@ void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree)
ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p; ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p;
ASE_ASSERT (px->idx != ASE_NULL); ASE_ASSERT (px->idx != ASE_NULL);
ase_awk_clrpt (awk, px->idx); ase_awk_clrpt (awk, px->idx);
if (px->id.name != ASE_NULL) if (px->id.name.ptr != ASE_NULL)
ASE_AWK_FREE (awk, px->id.name); ASE_AWK_FREE (awk, px->id.name.ptr);
ASE_AWK_FREE (awk, p); ASE_AWK_FREE (awk, p);
break; break;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.h 363 2008-09-04 10:58:08Z baconevi $ * $Id: tree.h 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -129,8 +129,7 @@ typedef struct ase_awk_nde_print_t ase_awk_nde_print_t;
struct ase_awk_afn_t struct ase_awk_afn_t
{ {
ase_char_t* name; ase_xstr_t name;
ase_size_t name_len;
ase_size_t nargs; ase_size_t nargs;
ase_awk_nde_t* body; ase_awk_nde_t* body;
}; };
@ -239,8 +238,7 @@ struct ase_awk_nde_var_t
ASE_AWK_NDE_HDR; ASE_AWK_NDE_HDR;
struct struct
{ {
ase_char_t* name; ase_xstr_t name;
ase_size_t name_len;
ase_size_t idxa; ase_size_t idxa;
} id; } id;
ase_awk_nde_t* idx; /* ASE_NULL for non-XXXXIDX */ ase_awk_nde_t* idx; /* ASE_NULL for non-XXXXIDX */
@ -254,30 +252,18 @@ struct ase_awk_nde_call_t
{ {
struct struct
{ {
struct ase_xstr_t name;
{
ase_char_t* ptr;
ase_size_t len;
} name;
} afn; } afn;
/* minimum information of a intrinsic function /* minimum information of a intrinsic function
* needed during run-time. */ * needed during run-time. */
struct struct
{ {
struct ase_xstr_t name;
{
ase_char_t* ptr;
ase_size_t len;
} name;
/* original name. if ase_awk_setword has been /* original name. if ase_awk_setword has been
* invoked, oname can be different from name */ * invoked, oname can be different from name */
struct ase_xstr_t oname;
{
ase_char_t* ptr;
ase_size_t len;
} oname;
struct struct
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c 380 2008-09-24 08:16:41Z baconevi $ * $Id: val.c 381 2008-09-24 11:07:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -457,6 +457,8 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
{ {
ase_awk_val_map_t* val; ase_awk_val_map_t* val;
/* CHECK */
/*
val = (ase_awk_val_map_t*) ASE_AWK_ALLOC ( val = (ase_awk_val_map_t*) ASE_AWK_ALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_map_t) ); run->awk, ASE_SIZEOF(ase_awk_val_map_t) );
if (val == ASE_NULL) if (val == ASE_NULL)
@ -467,8 +469,6 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
val->type = ASE_AWK_VAL_MAP; val->type = ASE_AWK_VAL_MAP;
val->ref = 0; val->ref = 0;
/* CHECK */
/*
val->map = ase_map_open ( val->map = ase_map_open (
run, 256, 70, free_mapval, same_mapval, run->awk->mmgr); run, 256, 70, free_mapval, same_mapval, run->awk->mmgr);
if (val->map == ASE_NULL) if (val->map == ASE_NULL)
@ -478,7 +478,23 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
return ASE_NULL; return ASE_NULL;
} }
*/ */
val->map = ase_map_open (run->awk->mmgr, ASE_SIZEOF(run), 256, 70);
val = (ase_awk_val_map_t*) ASE_AWK_ALLOC (
run->awk,
ASE_SIZEOF(ase_awk_val_map_t) +
ASE_SIZEOF(ase_map_t) +
ASE_SIZEOF(run));
if (val == ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL;
}
val->type = ASE_AWK_VAL_MAP;
val->ref = 0;
val->map = (ase_map_t*)(val + 1);
val->map = ase_map_init (val->map, run->awk->mmgr, 256, 70);
if (val->map == ASE_NULL) if (val->map == ASE_NULL)
{ {
ASE_AWK_FREE (run->awk, val); ASE_AWK_FREE (run->awk, val);
@ -613,7 +629,10 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
} }
else if (val->type == ASE_AWK_VAL_MAP) else if (val->type == ASE_AWK_VAL_MAP)
{ {
ase_map_close (((ase_awk_val_map_t*)val)->map); /* CHECK */
/* ase_map_close (((ase_awk_val_map_t*)val)->map);*/
ase_map_fini (((ase_awk_val_map_t*)val)->map);
/* END CHECK */
ASE_AWK_FREE (run->awk, val); ASE_AWK_FREE (run->awk, val);
} }
else if (val->type == ASE_AWK_VAL_REF) else if (val->type == ASE_AWK_VAL_REF)