fixed bugs in ase_lda_t & replaced ase_awk_tab_t with ase_lda_t

This commit is contained in:
hyung-hwan 2008-10-11 05:16:31 +00:00
parent ba30f5cf12
commit 7a05ceea75
10 changed files with 335 additions and 888 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 404 2008-09-30 11:14:20Z baconevi $
* $Id: awk.c 415 2008-10-10 11:16:31Z baconevi $
*/
#include <ase/awk/awk.h>
@ -1272,7 +1272,7 @@ static int awk_main (int argc, ase_char_t* argv[])
app_awk = awk;
#if 0
/////////////////
srcios.in = awk_srcio_in;
srcios.out = deparse? awk_srcio_out: NULL;
srcios.data = &siod;
@ -1287,7 +1287,9 @@ static int awk_main (int argc, ase_char_t* argv[])
close_awk (awk);
return -1;
}
#endif
/////////////////
#if 0
if (ase_awk_parsefiles (awk, ASE_ARR_PTR(stab), ASE_ARR_LEN(stab)) == -1)
{
ase_printf (
@ -1298,6 +1300,7 @@ static int awk_main (int argc, ase_char_t* argv[])
close_awk (awk);
return -1;
}
#endif
#ifdef _WIN32

View File

@ -41,6 +41,8 @@ typedef struct ase_lda_node_t ase_lda_node_t;
#define ASE_LDA_KEEPER(lda) ((lda)->keeper)
#define ASE_LDA_SIZER(lda) ((lda)->sizer)
#define ASE_LDA_EXTENSION(lda) ((void*)(((ase_lda_t*)lda) + 1))
/****b* ase.cmn.lda/ase_lda_copier_t
* NAME
@ -300,7 +302,7 @@ ase_lda_copier_t ase_lda_getcopier (
* ase_lda_setcopier - specify how to clone an element
*
* DESCRIPTION
* A special copier ASE_MAP_COPIER_INLINE is provided. This copier enables
* A special copier ASE_LDA_COPIER_INLINE is provided. This copier enables
* you to copy the data inline to the internal node. No freeer is invoked
* when the node is freeed.
*
@ -370,13 +372,6 @@ ase_size_t ase_lda_rsearch (
ase_size_t dlen
);
ase_size_t ase_lda_rrsearch (
ase_lda_t* lda,
ase_size_t pos,
const void* dptr,
ase_size_t dlen
);
ase_size_t ase_lda_upsert (
ase_lda_t* lda,
ase_size_t index,
@ -418,35 +413,27 @@ ase_size_t ase_lda_delete (
);
/******/
ase_size_t ase_lda_add (
ase_lda_t* lda, ase_char_t* str, ase_size_t len);
ase_size_t ase_lda_adduniq (
ase_lda_t* lda, ase_char_t* str, ase_size_t len);
/****f* ase.cmn.lda/ase_lda_uplete
* NAME
* ase_lda_uplete - delete data node
*
* DESCRIPTION
* The ase_lda_uplete() function deletes data node without compaction.
*
* RETURN
* The ase_lda_uplete() function returns the number of data affected.
*
*/
ase_size_t ase_lda_uplete (
ase_lda_t* lda,
ase_size_t index,
ase_size_t count
);
/******/
ase_size_t ase_lda_find (
ase_lda_t* lda, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_lda_rfind (
ase_lda_t* lda, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_lda_rrfind (
ase_lda_t* lda, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_lda_findx (
ase_lda_t* lda, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_lda_rfindx (
ase_lda_t* lda, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_lda_rrfindx (
ase_lda_t* lda, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
void ase_lda_clear (ase_lda_t* lda);
void ase_lda_clear (
ase_lda_t* lda
);
void* ase_lda_copysimple (
ase_lda_t* lda /* a linear dynamic array */,

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 391 2008-09-27 09:51:23Z baconevi $
* $Id: awk.c 415 2008-10-10 11:16:31Z baconevi $
*
* {License}
*/
@ -61,19 +61,11 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_MEMSET (awk, 0, ASE_SIZEOF(ase_awk_t) + ext);
awk->mmgr = mmgr;
if (ase_str_init (&awk->token.name, mmgr, 128) == ASE_NULL)
{
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->token.name = ase_str_open (mmgr, 0, 128);
if (awk->token.name == ASE_NULL) goto oops;
awk->wtab = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->wtab == ASE_NULL)
{
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->wtab == ASE_NULL) goto oops;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->wtab) = awk;
ase_map_setcopier (awk->wtab, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->wtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
@ -81,13 +73,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ase_map_setscale (awk->wtab, ASE_MAP_VAL, ASE_SIZEOF(ase_char_t));
awk->rwtab = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->rwtab == ASE_NULL)
{
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->rwtab == ASE_NULL) goto oops;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->rwtab) = awk;
ase_map_setcopier (awk->rwtab, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->rwtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
@ -96,88 +82,45 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
/* TODO: initial map size?? */
awk->tree.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->tree.afns == ASE_NULL)
{
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->tree.afns == ASE_NULL) goto oops;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->tree.afns) = awk;
ase_map_setcopier (awk->tree.afns, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setfreeer (awk->tree.afns, ASE_MAP_VAL, free_afn);
ase_map_setscale (awk->tree.afns, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
awk->parse.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
if (awk->parse.afns == ASE_NULL)
{
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->parse.afns == ASE_NULL) goto oops;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.afns) = awk;
ase_map_setcopier (awk->parse.afns, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->parse.afns, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
ase_map_setscale (awk->parse.afns, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
awk->parse.named = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
if (awk->parse.named == ASE_NULL)
{
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->parse.named == ASE_NULL) goto oops;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.named) = awk;
ase_map_setcopier (awk->parse.named, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->parse.named, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
ase_map_setscale (awk->parse.named, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.globals = ase_lda_open (mmgr, ASE_SIZEOF(awk), 128);
awk->parse.locals = ase_lda_open (mmgr, ASE_SIZEOF(awk), 64);
awk->parse.params = ase_lda_open (mmgr, ASE_SIZEOF(awk), 32);
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->parse.globals == ASE_NULL ||
awk->parse.locals == ASE_NULL ||
awk->parse.params == ASE_NULL) goto oops;
if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ASE_LDA_EXTENSION(awk->parse.globals) = awk;
ase_lda_setcopier (awk->parse.globals, ASE_LDA_COPIER_INLINE);
ase_lda_setscale (awk->parse.globals, ASE_SIZEOF(ase_char_t));
*(ase_awk_t**)ASE_LDA_EXTENSION(awk->parse.locals) = awk;
ase_lda_setcopier (awk->parse.locals, ASE_LDA_COPIER_INLINE);
ase_lda_setscale (awk->parse.locals, ASE_SIZEOF(ase_char_t));
*(ase_awk_t**)ASE_LDA_EXTENSION(awk->parse.params) = awk;
ase_lda_setcopier (awk->parse.params, ASE_LDA_COPIER_INLINE);
ase_lda_setscale (awk->parse.params, ASE_SIZEOF(ase_char_t));
awk->option = 0;
awk->errnum = ASE_AWK_ENOERR;
@ -211,22 +154,8 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
awk->src.shared.buf_len = 0;
awk->bfn.sys = ASE_NULL;
/*awk->bfn.user = ASE_NULL;*/
awk->bfn.user = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->bfn.user == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (awk->bfn.user == ASE_NULL) goto oops;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->bfn.user) = awk;
ase_map_setcopier (awk->bfn.user, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setfreeer (awk->bfn.user, ASE_MAP_VAL, free_bfn);
@ -245,23 +174,25 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
awk->assoc_data = ASE_NULL;
if (ase_awk_initglobals (awk) == -1)
{
ase_map_close (awk->bfn.user);
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_initglobals (awk) == -1) goto oops;
return awk;
oops:
if (awk->bfn.user) ase_map_close (awk->bfn.user);
if (awk->parse.params) ase_lda_close (awk->parse.params);
if (awk->parse.locals) ase_lda_close (awk->parse.locals);
if (awk->parse.globals) ase_lda_close (awk->parse.globals);
if (awk->parse.named) ase_map_close (awk->parse.named);
if (awk->parse.afns) ase_map_close (awk->parse.afns);
if (awk->tree.afns) ase_map_close (awk->tree.afns);
if (awk->rwtab) ase_map_close (awk->rwtab);
if (awk->wtab) ase_map_close (awk->wtab);
if (awk->token.name) ase_str_close (awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
@ -273,9 +204,9 @@ int ase_awk_close (ase_awk_t* awk)
/*ase_awk_clrbfn (awk);*/
ase_map_close (awk->bfn.user);
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_lda_close (awk->parse.params);
ase_lda_close (awk->parse.locals);
ase_lda_close (awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
@ -283,7 +214,7 @@ int ase_awk_close (ase_awk_t* awk)
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_fini (&awk->token.name);
ase_str_close (awk->token.name);
for (i = 0; i < ASE_COUNTOF(awk->errstr); i++)
{
@ -312,14 +243,14 @@ int ase_awk_clear (ase_awk_t* awk)
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
/*ase_awk_tab_clear (&awk->parse.globals);*/
ASE_ASSERT (awk->parse.globals.size == awk->tree.nglobals);
ase_awk_tab_remove (
&awk->parse.globals, awk->tree.nbglobals,
awk->parse.globals.size - awk->tree.nbglobals);
ASE_ASSERT (ASE_LDA_SIZE(awk->parse.globals) == awk->tree.nglobals);
/* delete all non-builtin global variables */
ase_lda_delete (
awk->parse.globals, awk->tree.nbglobals,
ASE_LDA_SIZE(awk->parse.globals) - awk->tree.nbglobals);
ase_awk_tab_clear (&awk->parse.locals);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.locals);
ase_lda_clear (awk->parse.params);
ase_map_clear (awk->parse.named);
ase_map_clear (awk->parse.afns);

View File

@ -11,6 +11,7 @@
#include "../cmn/chr.h"
#include <ase/cmn/str.h>
#include <ase/cmn/map.h>
#include <ase/cmn/lda.h>
#include <ase/cmn/rex.h>
typedef struct ase_awk_chain_t ase_awk_chain_t;
@ -19,7 +20,6 @@ typedef struct ase_awk_tree_t ase_awk_tree_t;
#include <ase/awk/awk.h>
#include "tree.h"
#include "func.h"
#include "tab.h"
#include "parse.h"
#include "run.h"
#include "extio.h"
@ -130,13 +130,13 @@ struct ase_awk_t
ase_map_t* named;
/* global variables */
ase_awk_tab_t globals;
ase_lda_t* globals;
/* local variables */
ase_awk_tab_t locals;
ase_lda_t* locals;
/* parameters to a function */
ase_awk_tab_t params;
ase_lda_t* params;
/* maximum number of local variables */
ase_size_t nlocals_max;
@ -182,7 +182,7 @@ struct ase_awk_t
} prev;
int type;
ase_str_t name;
ase_str_t* name;
ase_size_t line;
ase_size_t column;
} token;

View File

@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = -I$(top_srcdir)/include
lib_LTLIBRARIES = libaseawk.la
libaseawk_la_SOURCES = awk.c err.c tree.c tab.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk_i.h extio.h func.h misc.h parse.h run.h tab.h tree.h
libaseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk_i.h extio.h func.h misc.h parse.h run.h tree.h
libaseawk_la_LDFLAGS= -L../cmn -version-info 1:0:0
libaseawk_la_LIBADD= -lasecmn

View File

@ -63,7 +63,7 @@ am__libaseawk___la_SOURCES_DIST = Awk.cpp StdAwk.cpp
libaseawk___la_OBJECTS = $(am_libaseawk___la_OBJECTS)
@ENABLE_CXX_TRUE@am_libaseawk___la_rpath = -rpath $(libdir)
libaseawk_la_DEPENDENCIES =
am_libaseawk_la_OBJECTS = awk.lo err.lo tree.lo tab.lo parse.lo run.lo \
am_libaseawk_la_OBJECTS = awk.lo err.lo tree.lo parse.lo run.lo \
rec.lo val.lo func.lo misc.lo extio.lo std.lo
libaseawk_la_OBJECTS = $(am_libaseawk_la_OBJECTS)
DEFAULT_INCLUDES =
@ -210,7 +210,7 @@ target_alias = @target_alias@
AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = -I$(top_srcdir)/include
lib_LTLIBRARIES = libaseawk.la $(am__append_1)
libaseawk_la_SOURCES = awk.c err.c tree.c tab.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk_i.h extio.h func.h misc.h parse.h run.h tab.h tree.h
libaseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk_i.h extio.h func.h misc.h parse.h run.h tree.h
libaseawk_la_LDFLAGS = -L../cmn -version-info 1:0:0
libaseawk_la_LIBADD = -lasecmn
@ENABLE_CXX_TRUE@libaseawk___la_SOURCES = Awk.cpp StdAwk.cpp
@ -298,7 +298,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rec.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/std.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tab.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tree.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/val.Plo@am__quote@

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c 391 2008-09-27 09:51:23Z baconevi $
* $Id: parse.c 415 2008-10-10 11:16:31Z baconevi $
*
* {License}
*/
@ -350,7 +350,7 @@ static global_t gtab[] =
#define ADD_TOKEN_CHAR(awk,c) \
do { \
if (ase_str_ccat(&(awk)->token.name,(c)) == (ase_size_t)-1) \
if (ase_str_ccat((awk)->token.name,(c)) == (ase_size_t)-1) \
{ \
ase_awk_seterror (awk, ASE_AWK_ENOMEM, (awk)->token.line, ASE_NULL, 0); \
return -1; \
@ -359,7 +359,7 @@ static global_t gtab[] =
#define ADD_TOKEN_STR(awk,s,l) \
do { \
if (ase_str_ncat(&(awk)->token.name,(s),(l)) == (ase_size_t)-1) \
if (ase_str_ncat((awk)->token.name,(s),(l)) == (ase_size_t)-1) \
{ \
ase_awk_seterror (awk, ASE_AWK_ENOMEM, (awk)->token.line, ASE_NULL, 0); \
return -1; \
@ -375,8 +375,8 @@ static global_t gtab[] =
#define SETERRTOK(awk,code) \
do { \
ase_cstr_t errarg; \
errarg.len = ASE_STR_LEN(&(awk)->token.name); \
errarg.ptr = ASE_STR_PTR(&(awk)->token.name); \
errarg.len = ASE_STR_LEN((awk)->token.name); \
errarg.ptr = ASE_STR_PTR((awk)->token.name); \
if (MATCH(awk,TOKEN_EOF)) \
ase_awk_seterror (awk, code, (awk)->token.prev.line, &errarg, 1); \
else \
@ -451,10 +451,10 @@ const ase_char_t* ase_awk_getglobalname (
return gtab[idx].name;
*/
ASE_ASSERT (idx < ase_awk_tab_getsize(&awk->parse.globals));
ASE_ASSERT (idx < ASE_LDA_SIZE(&awk->parse.globals));
*len = awk->parse.globals.buf[idx].name.len;
return awk->parse.globals.buf[idx].name.ptr;
*len = ASE_LDA_DLEN(awk->parse.globals,idx);
return ASE_LDA_DPTR(awk->parse.globals,idx);
}
ase_cstr_t* ase_awk_getkw (ase_awk_t* awk, int id, ase_cstr_t* s)
@ -616,13 +616,13 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
if (get_token(awk) == -1) return ASE_NULL;
ASE_ASSERT (awk->tree.nglobals == ase_awk_tab_getsize(&awk->parse.globals));
ASE_ASSERT (awk->tree.nglobals == ASE_LDA_SIZE(&awk->parse.globals));
nglobals = awk->tree.nglobals;
if (collect_globals (awk) == ASE_NULL)
{
ase_awk_tab_remove (
&awk->parse.globals, nglobals,
ase_awk_tab_getsize(&awk->parse.globals) - nglobals);
ase_lda_delete (
awk->parse.globals, nglobals,
ASE_LDA_SIZE(awk->parse.globals) - nglobals);
awk->tree.nglobals = nglobals;
return ASE_NULL;
}
@ -838,8 +838,8 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
return ASE_NULL;
}
name = ASE_STR_PTR(&awk->token.name);
name_len = ASE_STR_LEN(&awk->token.name);
name = ASE_STR_PTR(awk->token.name);
name_len = ASE_STR_LEN(awk->token.name);
/* check if it is a builtin function */
if (ase_awk_getbfn (awk, name, name_len) != ASE_NULL)
@ -859,7 +859,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
/* check if it coincides to be a global variable name */
g = find_global (awk, name, name_len);
if (g != (ase_size_t)-1)
if (g != ASE_LDA_INVALID)
{
SETERRARG (
awk, ASE_AWK_EGBLRED, awk->token.line,
@ -900,7 +900,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
}
/* make sure that parameter table is empty */
ASE_ASSERT (ase_awk_tab_getsize(&awk->parse.params) == 0);
ASE_ASSERT (ASE_LDA_SIZE(&awk->parse.params) == 0);
/* read parameter list */
if (MATCH(awk,TOKEN_RPAREN))
@ -922,13 +922,13 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (!MATCH(awk,TOKEN_IDENT))
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
SETERRTOK (awk, ASE_AWK_EBADPAR);
return ASE_NULL;
}
param = ASE_STR_PTR(&awk->token.name);
param_len = ASE_STR_LEN(&awk->token.name);
param = ASE_STR_PTR(awk->token.name);
param_len = ASE_STR_LEN(awk->token.name);
/* NOTE: the following is not a conflict.
* so the parameter is not checked against
@ -939,12 +939,11 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
*/
/* check if a parameter conflicts with other parameters */
if (ase_awk_tab_find (
&awk->parse.params,
0, param, param_len) != (ase_size_t)-1)
if (ase_lda_search (awk->parse.params,
0, param, param_len) != ASE_LDA_INVALID)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
SETERRARG (
awk, ASE_AWK_EDUPPAR, awk->token.line,
@ -954,22 +953,22 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
}
/* push the parameter to the parameter list */
if (ase_awk_tab_getsize (
&awk->parse.params) >= ASE_AWK_MAX_PARAMS)
if (ASE_LDA_SIZE(awk->parse.params) >= ASE_AWK_MAX_PARAMS)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
SETERRTOK (awk, ASE_AWK_EPARTM);
return ASE_NULL;
}
if (ase_awk_tab_add (
&awk->parse.params,
param, param_len) == (ase_size_t)-1)
if (ase_lda_insert (
awk->parse.params,
ASE_LDA_SIZE(awk->parse.params),
param, param_len) == ASE_LDA_INVALID)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line);
return ASE_NULL;
@ -978,7 +977,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (get_token (awk) == -1)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
return ASE_NULL;
}
@ -987,7 +986,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (!MATCH(awk,TOKEN_COMMA))
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
SETERRTOK (awk, ASE_AWK_ECOMMA);
return ASE_NULL;
@ -996,7 +995,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (get_token(awk) == -1)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
return ASE_NULL;
}
}
@ -1004,7 +1003,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (get_token(awk) == -1)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
return ASE_NULL;
}
}
@ -1018,7 +1017,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (get_token(awk) == -1)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
return ASE_NULL;
}
}
@ -1027,7 +1026,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (!MATCH(awk,TOKEN_LBRACE))
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
SETERRTOK (awk, ASE_AWK_ELBRACE);
return ASE_NULL;
@ -1035,7 +1034,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (get_token(awk) == -1)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
return ASE_NULL;
}
@ -1054,15 +1053,15 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
if (body == ASE_NULL)
{
ASE_AWK_FREE (awk, name_dup);
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
return ASE_NULL;
}
/* TODO: study furthur if the parameter names should be saved
* for some reasons - might be needed for deparsing output */
nargs = ase_awk_tab_getsize (&awk->parse.params);
nargs = ASE_LDA_SIZE(awk->parse.params);
/* parameter names are not required anymore. clear them */
ase_awk_tab_clear (&awk->parse.params);
ase_lda_clear (awk->parse.params);
afn = (ase_awk_afn_t*) ASE_AWK_ALLOC (awk, ASE_SIZEOF(ase_awk_afn_t));
if (afn == ASE_NULL)
@ -1204,7 +1203,7 @@ static ase_awk_nde_t* parse_block (
ase_awk_nde_blk_t* block;
ase_size_t nlocals, nlocals_max, tmp;
nlocals = ase_awk_tab_getsize(&awk->parse.locals);
nlocals = ASE_LDA_SIZE(awk->parse.locals);
nlocals_max = awk->parse.nlocals_max;
/* local variable declarations */
@ -1216,17 +1215,17 @@ static ase_awk_nde_t* parse_block (
if (get_token(awk) == -1)
{
ase_awk_tab_remove (
&awk->parse.locals, nlocals,
ase_awk_tab_getsize(&awk->parse.locals) - nlocals);
ase_lda_delete (
awk->parse.locals, nlocals,
ASE_LDA_SIZE(awk->parse.locals)-nlocals);
return ASE_NULL;
}
if (collect_locals (awk, nlocals, istop) == ASE_NULL)
{
ase_awk_tab_remove (
&awk->parse.locals, nlocals,
ase_awk_tab_getsize(&awk->parse.locals) - nlocals);
ase_lda_delete (
awk->parse.locals, nlocals,
ASE_LDA_SIZE(awk->parse.locals)-nlocals);
return ASE_NULL;
}
}
@ -1246,9 +1245,9 @@ static ase_awk_nde_t* parse_block (
/* if EOF is met before the right brace, this is an error */
if (MATCH(awk,TOKEN_EOF))
{
ase_awk_tab_remove (
&awk->parse.locals, nlocals,
ase_awk_tab_getsize(&awk->parse.locals) - nlocals);
ase_lda_delete (
awk->parse.locals, nlocals,
ASE_LDA_SIZE(awk->parse.locals) - nlocals);
if (head != ASE_NULL) ase_awk_clrpt (awk, head);
SETERRLIN (awk, ASE_AWK_EENDSRC, awk->token.prev.line);
@ -1260,9 +1259,9 @@ static ase_awk_nde_t* parse_block (
{
if (get_token(awk) == -1)
{
ase_awk_tab_remove (
&awk->parse.locals, nlocals,
ase_awk_tab_getsize(&awk->parse.locals)-nlocals);
ase_lda_delete (
awk->parse.locals, nlocals,
ASE_LDA_SIZE(awk->parse.locals)-nlocals);
if (head != ASE_NULL) ase_awk_clrpt (awk, head);
return ASE_NULL;
}
@ -1274,9 +1273,9 @@ static ase_awk_nde_t* parse_block (
nde = parse_statement (awk, awk->token.line);
if (nde == ASE_NULL)
{
ase_awk_tab_remove (
&awk->parse.locals, nlocals,
ase_awk_tab_getsize(&awk->parse.locals)-nlocals);
ase_lda_delete (
awk->parse.locals, nlocals,
ASE_LDA_SIZE(awk->parse.locals)-nlocals);
if (head != ASE_NULL) ase_awk_clrpt (awk, head);
return ASE_NULL;
}
@ -1304,20 +1303,20 @@ static ase_awk_nde_t* parse_block (
ASE_AWK_ALLOC (awk, ASE_SIZEOF(ase_awk_nde_blk_t));
if (block == ASE_NULL)
{
ase_awk_tab_remove (
&awk->parse.locals, nlocals,
ase_awk_tab_getsize(&awk->parse.locals)-nlocals);
ase_lda_delete (
awk->parse.locals, nlocals,
ASE_LDA_SIZE(awk->parse.locals)-nlocals);
ase_awk_clrpt (awk, head);
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return ASE_NULL;
}
tmp = ase_awk_tab_getsize(&awk->parse.locals);
tmp = ASE_LDA_SIZE(awk->parse.locals);
if (tmp > awk->parse.nlocals_max) awk->parse.nlocals_max = tmp;
/* remove all locals to move it up to the top level */
ase_awk_tab_remove (&awk->parse.locals, nlocals, tmp - nlocals);
ase_lda_delete (awk->parse.locals, nlocals, tmp - nlocals);
/* adjust the number of locals for a block without any statements */
/* if (head == ASE_NULL) tmp = 0; */
@ -1381,9 +1380,12 @@ int ase_awk_initglobals (ase_awk_t* awk)
{
ase_size_t g;
g = ase_awk_tab_add (&awk->parse.globals,
gtab[id].name, gtab[id].name_len);
if (g == (ase_size_t)-1) return -1;
g = ase_lda_insert (
awk->parse.globals,
ASE_LDA_SIZE(awk->parse.globals),
(ase_char_t*)gtab[id].name,
gtab[id].name_len);
if (g == ASE_LDA_INVALID) return -1;
ASE_ASSERT ((int)g == id);
@ -1408,34 +1410,13 @@ static void adjust_static_globals (ase_awk_t* awk)
if (gtab[id].valid != 0 &&
(awk->option & gtab[id].valid) != gtab[id].valid)
{
awk->parse.globals.buf[id].name.len = 0;
/*awk->parse.globals.buf[id].name.len = 0;*/
ASE_LDA_DLEN(awk->parse.globals,id) = 0;
}
else
{
awk->parse.globals.buf[id].name.len = gtab[id].name_len;
}
}
}
static void trans_global (
ase_size_t index, ase_cstr_t* word, void* arg)
{
ase_awk_tab_t* tab = (ase_awk_tab_t*)arg;
ase_awk_t* awk = tab->awk;
/*
if (index >= ASE_AWK_MIN_GLOBAL_ID &&
index <= ASE_AWK_MAX_GLOBAL_ID)
*/
if (index < awk->tree.nbglobals)
{
ase_map_pair_t* pair;
pair = ase_map_search (awk->wtab, word->ptr, word->len);
if (pair != ASE_NULL)
{
word->ptr = ((ase_cstr_t*)(pair->vptr))->ptr;
word->len = ((ase_cstr_t*)(pair->vptr))->len;
/*awk->parse.globals.buf[id].name.len = gtab[id].name_len;*/
ASE_LDA_DLEN(awk->parse.globals,id) = gtab[id].name_len;
}
}
}
@ -1443,17 +1424,76 @@ static void trans_global (
static ase_size_t get_global (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
{
return ase_awk_tab_rrfindx (
&awk->parse.globals, 0, name, len,
trans_global, &awk->parse.globals);
ase_size_t i;
/* return ase_lda_rsearch (
awk->parse.globals, ASE_LDA_SIZE(awk->parse.globals),
name, len); */
if (ASE_LDA_SIZE(awk->parse.globals) > 0)
{
for (i = ASE_LDA_SIZE(awk->parse.globals); i-- > 0; )
{
if (ASE_LDA_NODE(awk->parse.globals,i))
{
ase_cstr_t tmp;
tmp.ptr = ASE_LDA_DPTR(awk->parse.globals,i);
tmp.len = ASE_LDA_DLEN(awk->parse.globals,i);
if (i < awk->tree.nbglobals)
{
ase_map_pair_t* pair;
pair = ase_map_search (awk->wtab, tmp.ptr, tmp.len);
if (pair != ASE_NULL)
{
tmp.ptr = ((ase_cstr_t*)(pair->vptr))->ptr;
tmp.len = ((ase_cstr_t*)(pair->vptr))->len;
}
}
if (ase_strxncmp(tmp.ptr, tmp.len, name, len) == 0) return i;
}
}
}
return ASE_LDA_INVALID;
}
static ase_size_t find_global (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
{
return ase_awk_tab_findx (
&awk->parse.globals, 0, name, len,
trans_global, &awk->parse.globals);
ase_size_t i;
/* return ase_lda_search (awk->parse.globals, 0, name, len); */
for (i = 0; i < ASE_LDA_SIZE(awk->parse.globals); i++)
{
if (ASE_LDA_NODE(awk->parse.globals,i))
{
ase_cstr_t tmp;
tmp.ptr = ASE_LDA_DPTR(awk->parse.globals,i);
tmp.len = ASE_LDA_DLEN(awk->parse.globals,i);
if (i < awk->tree.nbglobals)
{
ase_map_pair_t* pair;
pair = ase_map_search (awk->wtab, tmp.ptr, tmp.len);
if (pair != ASE_NULL)
{
tmp.ptr = ((ase_cstr_t*)(pair->vptr))->ptr;
tmp.len = ((ase_cstr_t*)(pair->vptr))->len;
}
}
if (ase_strxncmp(tmp.ptr, tmp.len, name, len) == 0) return i;
}
}
return ASE_LDA_INVALID;
}
static int add_global (
@ -1498,30 +1538,34 @@ static int add_global (
#endif
/* check if it conflicts with other global variable names */
if (find_global (awk, name, len) != (ase_size_t)-1)
if (find_global (awk, name, len) != ASE_LDA_INVALID)
{
SETERRARG (awk, ASE_AWK_EDUPGBL, line, name, len);
return -1;
}
nglobals = ase_awk_tab_getsize (&awk->parse.globals);
nglobals = ASE_LDA_SIZE (awk->parse.globals);
if (nglobals >= ASE_AWK_MAX_GLOBALS)
{
SETERRLIN (awk, ASE_AWK_EGBLTM, line);
return -1;
}
if (ase_awk_tab_add (&awk->parse.globals, name, len) == (ase_size_t)-1)
if (ase_lda_insert (awk->parse.globals,
ASE_LDA_SIZE(awk->parse.globals),
(ase_char_t*)name, len) == ASE_LDA_INVALID)
{
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return -1;
}
ASE_ASSERT (nglobals == ASE_LDA_SIZE(awk->parse.globals) - 1);
/* the disabled item is inserted normally but
* the name length is reset to zero. */
if (disabled) awk->parse.globals.buf[nglobals].name.len = 0;
if (disabled) ASE_LDA_DLEN(awk->parse.globals,nglobals) = 0;
awk->tree.nglobals = ase_awk_tab_getsize (&awk->parse.globals);
awk->tree.nglobals = ASE_LDA_SIZE (awk->parse.globals);
ASE_ASSERT (nglobals == awk->tree.nglobals-1);
/* return the id which is the index to the global table. */
@ -1569,9 +1613,9 @@ int ase_awk_delglobal (
return -1;
}
n = ase_awk_tab_find (&awk->parse.globals,
n = ase_lda_search (awk->parse.globals,
ASE_AWK_NUM_STATIC_GLOBALS, name, len);
if (n == (ase_size_t)-1)
if (n == ASE_LDA_INVALID)
{
SETERRARG (awk, ASE_AWK_ENOENT, 0, name, len);
return -1;
@ -1582,8 +1626,12 @@ int ase_awk_delglobal (
* if ase_awk_addglobal is called with the same name
* again, the entry will be appended again.
* never call this funciton unless it is really required. */
awk->parse.globals.buf[n].name.ptr[0] = ASE_T('\0');;
/*
awk->parse.globals.buf[n].name.ptr[0] = ASE_T('\0');
awk->parse.globals.buf[n].name.len = 0;
*/
n = ase_lda_uplete (awk->parse.globals, n, 1);
ASE_ASSERT (n == 1);
return 0;
}
@ -1600,8 +1648,8 @@ static ase_awk_t* collect_globals (ase_awk_t* awk)
if (add_global (
awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name),
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name),
awk->token.line, 0) == -1) return ASE_NULL;
if (get_token(awk) == -1) return ASE_NULL;
@ -1637,8 +1685,8 @@ static ase_awk_t* collect_locals (
return ASE_NULL;
}
local.ptr = ASE_STR_PTR(&awk->token.name);
local.len = ASE_STR_LEN(&awk->token.name);
local.ptr = ASE_STR_PTR(awk->token.name);
local.len = ASE_STR_LEN(awk->token.name);
#if 0
if (awk->option & ASE_AWK_UNIQUEFN)
@ -1689,8 +1737,8 @@ static ase_awk_t* collect_locals (
if (istop)
{
/* check if it conflicts with a paremeter name */
n = ase_awk_tab_find (&awk->parse.params, 0, local.ptr, local.len);
if (n != (ase_size_t)-1)
n = ase_lda_search (awk->parse.params, 0, local.ptr, local.len);
if (n != ASE_LDA_INVALID)
{
SETERRARG (
awk, ASE_AWK_EPARRED, awk->token.line,
@ -1700,11 +1748,11 @@ static ase_awk_t* collect_locals (
}
/* check if it conflicts with other local variable names */
n = ase_awk_tab_find (
&awk->parse.locals,
n = ase_lda_search (
awk->parse.locals,
nlocals, /*((awk->option&ASE_AWK_SHADING)? nlocals:0)*/
local.ptr, local.len);
if (n != (ase_size_t)-1)
if (n != ASE_LDA_INVALID)
{
SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line,
@ -1714,7 +1762,7 @@ static ase_awk_t* collect_locals (
/* check if it conflicts with global variable names */
n = find_global (awk, local.ptr, local.len);
if (n != (ase_size_t)-1)
if (n != ASE_LDA_INVALID)
{
if (n < awk->tree.nbglobals)
{
@ -1737,14 +1785,16 @@ static ase_awk_t* collect_locals (
#endif
}
if (ase_awk_tab_getsize(&awk->parse.locals) >= ASE_AWK_MAX_LOCALS)
if (ASE_LDA_SIZE(awk->parse.locals) >= ASE_AWK_MAX_LOCALS)
{
SETERRLIN (awk, ASE_AWK_ELCLTM, awk->token.line);
return ASE_NULL;
}
if (ase_awk_tab_add (
&awk->parse.locals, local.ptr, local.len) == (ase_size_t)-1)
if (ase_lda_insert (
awk->parse.locals,
ASE_LDA_SIZE(awk->parse.locals),
local.ptr, local.len) == ASE_LDA_INVALID)
{
SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line);
return ASE_NULL;
@ -2757,21 +2807,21 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->line = line;
nde->next = ASE_NULL;
nde->val = ase_awk_strxtolong (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name), 0, ASE_NULL);
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name), 0, ASE_NULL);
nde->str = ASE_AWK_STRXDUP (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name));
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name));
if (nde->str == ASE_NULL)
{
ASE_AWK_FREE (awk, nde);
return ASE_NULL;
}
nde->len = ASE_STR_LEN(&awk->token.name);
nde->len = ASE_STR_LEN(awk->token.name);
ASE_ASSERT (
ASE_STR_LEN(&awk->token.name) ==
ase_strlen(ASE_STR_PTR(&awk->token.name)));
ASE_STR_LEN(awk->token.name) ==
ase_strlen(ASE_STR_PTR(awk->token.name)));
if (get_token(awk) == -1)
{
@ -2798,21 +2848,21 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->line = line;
nde->next = ASE_NULL;
nde->val = ase_awk_strxtoreal (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name), ASE_NULL);
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name), ASE_NULL);
nde->str = ASE_AWK_STRXDUP (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name));
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name));
if (nde->str == ASE_NULL)
{
ASE_AWK_FREE (awk, nde);
return ASE_NULL;
}
nde->len = ASE_STR_LEN(&awk->token.name);
nde->len = ASE_STR_LEN(awk->token.name);
ASE_ASSERT (
ASE_STR_LEN(&awk->token.name) ==
ase_strlen(ASE_STR_PTR(&awk->token.name)));
ASE_STR_LEN(awk->token.name) ==
ase_strlen(ASE_STR_PTR(awk->token.name)));
if (get_token(awk) == -1)
{
@ -2838,9 +2888,9 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->type = ASE_AWK_NDE_STR;
nde->line = line;
nde->next = ASE_NULL;
nde->len = ASE_STR_LEN(&awk->token.name);
nde->len = ASE_STR_LEN(awk->token.name);
nde->buf = ASE_AWK_STRXDUP (awk,
ASE_STR_PTR(&awk->token.name), nde->len);
ASE_STR_PTR(awk->token.name), nde->len);
if (nde->buf == ASE_NULL)
{
ASE_AWK_FREE (awk, nde);
@ -2866,7 +2916,7 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
* of the context-sensitivity of the slash symbol */
SET_TOKEN_TYPE (awk, TOKEN_REX);
ase_str_clear (&awk->token.name);
ase_str_clear (awk->token.name);
if (get_rexstr (awk) == -1) return ASE_NULL;
ASE_ASSERT (MATCH(awk,TOKEN_REX));
@ -2882,10 +2932,10 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->line = line;
nde->next = ASE_NULL;
nde->len = ASE_STR_LEN(&awk->token.name);
nde->len = ASE_STR_LEN(awk->token.name);
nde->buf = ASE_AWK_STRXDUP (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name));
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name));
if (nde->buf == ASE_NULL)
{
ASE_AWK_FREE (awk, nde);
@ -2894,8 +2944,8 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
}
nde->code = ASE_AWK_BUILDREX (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name),
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name),
&errnum);
if (nde->code == ASE_NULL)
{
@ -3108,14 +3158,14 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
ASE_ASSERT (MATCH(awk,TOKEN_IDENT));
name_dup = ASE_AWK_STRXDUP (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name));
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name));
if (name_dup == ASE_NULL)
{
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
return ASE_NULL;
}
name_len = ASE_STR_LEN(&awk->token.name);
name_len = ASE_STR_LEN(awk->token.name);
if (get_token(awk) == -1)
{
@ -3151,8 +3201,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup);
return (ase_awk_nde_t*)nde;
}
else if ((idxa = ase_awk_tab_rrfind (
&awk->parse.locals, 0, name_dup, name_len)) != (ase_size_t)-1)
else if ((idxa = ase_lda_rsearch (awk->parse.locals, ASE_LDA_SIZE(awk->parse.locals), name_dup, name_len)) != ASE_LDA_INVALID)
{
/* local variable */
@ -3186,8 +3235,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
return (ase_awk_nde_t*)nde;
}
else if ((idxa = ase_awk_tab_find (
&awk->parse.params, 0, name_dup, name_len)) != (ase_size_t)-1)
else if ((idxa = ase_lda_search (awk->parse.params, 0, name_dup, name_len)) != ASE_LDA_INVALID)
{
/* parameter */
@ -3221,8 +3269,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
return (ase_awk_nde_t*)nde;
}
else if ((idxa = get_global (
awk, name_dup, name_len)) != (ase_size_t)-1)
else if ((idxa = get_global (awk, name_dup, name_len)) != ASE_LDA_INVALID)
{
/* global variable */
@ -3428,8 +3475,8 @@ static ase_awk_nde_t* parse_hashidx (
}
/* search the local variable list */
idxa = ase_awk_tab_rrfind(&awk->parse.locals, 0, name, name_len);
if (idxa != (ase_size_t)-1)
idxa = ase_lda_rsearch (awk->parse.locals, ASE_LDA_SIZE(awk->parse.locals), name, name_len);
if (idxa != ASE_LDA_INVALID)
{
nde->type = ASE_AWK_NDE_LOCALIDX;
nde->line = line;
@ -3444,8 +3491,8 @@ static ase_awk_nde_t* parse_hashidx (
}
/* search the parameter name list */
idxa = ase_awk_tab_find (&awk->parse.params, 0, name, name_len);
if (idxa != (ase_size_t)-1)
idxa = ase_lda_search (awk->parse.params, 0, name, name_len);
if (idxa != ASE_LDA_INVALID)
{
nde->type = ASE_AWK_NDE_ARGIDX;
nde->line = line;
@ -3461,7 +3508,7 @@ static ase_awk_nde_t* parse_hashidx (
/* gets the global variable index */
idxa = get_global (awk, name, name_len);
if (idxa != (ase_size_t)-1)
if (idxa != ASE_LDA_INVALID)
{
nde->type = ASE_AWK_NDE_GLOBALIDX;
nde->line = line;
@ -4530,7 +4577,7 @@ static int get_token (ase_awk_t* awk)
}
while (n == 1);
ase_str_clear (&awk->token.name);
ase_str_clear (awk->token.name);
awk->token.line = awk->src.lex.line;
awk->token.column = awk->src.lex.column;
@ -4592,8 +4639,8 @@ static int get_token (ase_awk_t* awk)
c == ASE_T('_') || ASE_AWK_ISDIGIT(awk,c));
type = classify_ident (awk,
ASE_STR_PTR(&awk->token.name),
ASE_STR_LEN(&awk->token.name));
ASE_STR_PTR(awk->token.name),
ASE_STR_LEN(awk->token.name));
SET_TOKEN_TYPE (awk, type);
}
else if (c == ASE_T('\"'))
@ -4932,7 +4979,7 @@ static int get_number (ase_awk_t* awk)
{
ase_cint_t c;
ASE_ASSERT (ASE_STR_LEN(&awk->token.name) == 0);
ASE_ASSERT (ASE_STR_LEN(awk->token.name) == 0);
SET_TOKEN_TYPE (awk, TOKEN_INT);
c = awk->src.lex.curc;
@ -5542,8 +5589,8 @@ static int deparse (ase_awk_t* awk)
/* use the actual name if no named variable
* is allowed */
if (ase_awk_putsrcstrx (awk,
awk->parse.globals.buf[i].name.ptr,
awk->parse.globals.buf[i].name.len) == -1)
ASE_LDA_DPTR(awk->parse.globals,i),
ASE_LDA_DLEN(awk->parse.globals,i)) == -1)
{
EXIT_DEPARSE ();
}
@ -5567,8 +5614,8 @@ static int deparse (ase_awk_t* awk)
!(awk->option & ASE_AWK_IMPLICIT))
{
if (ase_awk_putsrcstrx (awk,
awk->parse.globals.buf[i].name.ptr,
awk->parse.globals.buf[i].name.len) == -1)
ASE_LDA_DPTR(awk->parse.globals,i),
ASE_LDA_DLEN(awk->parse.globals,i)) == -1)
{
EXIT_DEPARSE ();
}

View File

@ -1,317 +0,0 @@
/*
* $Id: tab.c 337 2008-08-20 09:17:25Z baconevi $
*
* {License}
*/
#include "awk.h"
ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk)
{
if (tab == ASE_NULL)
{
tab = (ase_awk_tab_t*) ASE_AWK_ALLOC (
awk, ASE_SIZEOF(ase_awk_tab_t));
if (tab == ASE_NULL) return ASE_NULL;
tab->__dynamic = ASE_TRUE;
}
else tab->__dynamic = ASE_FALSE;
tab->awk = awk;
tab->buf = ASE_NULL;
tab->size = 0;
tab->capa = 0;
return tab;
}
void ase_awk_tab_close (ase_awk_tab_t* tab)
{
ase_awk_tab_clear (tab);
if (tab->buf != ASE_NULL)
{
ASE_AWK_FREE (tab->awk, tab->buf);
tab->buf = ASE_NULL;
tab->capa = 0;
}
if (tab->__dynamic) ASE_AWK_FREE (tab->awk, tab);
}
ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab)
{
return tab->size;
}
ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab)
{
return tab->capa;
}
ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa)
{
void* tmp;
if (tab->size > capa)
{
ase_awk_tab_remove (tab, capa, tab->size - capa);
ASE_ASSERT (tab->size <= capa);
}
if (capa > 0)
{
if (tab->awk->mmgr->realloc != ASE_NULL)
{
tmp = ASE_AWK_REALLOC (tab->awk,
tab->buf, ASE_SIZEOF(*tab->buf) * capa);
if (tmp == ASE_NULL) return ASE_NULL;
}
else
{
tmp = ASE_AWK_ALLOC (
tab->awk, ASE_SIZEOF(*tab->buf) * capa);
if (tmp == ASE_NULL) return ASE_NULL;
if (tab->buf != ASE_NULL)
{
ase_size_t x;
x = (capa > tab->capa)? tab->capa: capa;
ASE_MEMCPY (
tmp, tab->buf,
ASE_SIZEOF(*tab->buf) * x);
ASE_AWK_FREE (tab->awk, tab->buf);
}
}
}
else
{
if (tab->buf != ASE_NULL) ASE_AWK_FREE (tab->awk, tab->buf);
tmp = ASE_NULL;
}
tab->buf = tmp;
tab->capa = capa;
return tab;
}
void ase_awk_tab_clear (ase_awk_tab_t* tab)
{
ase_size_t i;
for (i = 0; i < tab->size; i++)
{
ASE_AWK_FREE (tab->awk, tab->buf[i].name.ptr);
tab->buf[i].name.ptr = ASE_NULL;
tab->buf[i].name.len = 0;
}
tab->size = 0;
}
ase_size_t ase_awk_tab_insert (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
ase_char_t* dup;
dup = ASE_AWK_STRXDUP (tab->awk, str, len);
if (dup == ASE_NULL) return (ase_size_t)-1;
if (index >= tab->capa)
{
ase_size_t capa;
if (tab->capa <= 0) capa = (index + 1);
else
{
do { capa = tab->capa * 2; } while (index >= capa);
}
if (ase_awk_tab_setcapa(tab,capa) == ASE_NULL)
{
ASE_AWK_FREE (tab->awk, dup);
return (ase_size_t)-1;
}
}
for (i = tab->size; i > index; i--) tab->buf[i] = tab->buf[i-1];
tab->buf[index].name.ptr = dup;
tab->buf[index].name.len = len;
if (index > tab->size) tab->size = index + 1;
else tab->size++;
return index;
}
ase_size_t ase_awk_tab_remove (
ase_awk_tab_t* tab, ase_size_t index, ase_size_t count)
{
ase_size_t i, j, k;
if (index >= tab->size) return 0;
if (count > tab->size - index) count = tab->size - index;
i = index;
j = index + count;
k = index + count;
while (i < k)
{
ASE_AWK_FREE (tab->awk, tab->buf[i].name.ptr);
if (j >= tab->size)
{
tab->buf[i].name.ptr = ASE_NULL;
tab->buf[i].name.len = 0;
i++;
}
else
{
tab->buf[i].name.ptr = tab->buf[j].name.ptr;
tab->buf[i].name.len = tab->buf[j].name.len;
i++; j++;
}
}
tab->size -= count;
return count;
}
ase_size_t ase_awk_tab_add (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len)
{
return ase_awk_tab_insert (tab, tab->size, str, len);
}
ase_size_t ase_awk_tab_adduniq (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
i = ase_awk_tab_find (tab, 0, str, len);
if (i != (ase_size_t)-1) return i; /* found. return the current index */
/* insert a new entry */
return ase_awk_tab_insert (tab, tab->size, str, len);
}
ase_size_t ase_awk_tab_find (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
for (i = index; i < tab->size; i++)
{
if (ase_strxncmp (
tab->buf[i].name.ptr, tab->buf[i].name.len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = index + 1; i-- > 0; )
{
if (ase_strxncmp (
tab->buf[i].name.ptr, tab->buf[i].name.len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rrfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = tab->size - index; i-- > 0; )
{
if (ase_strxncmp (
tab->buf[i].name.ptr, tab->buf[i].name.len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_findx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg)
{
ase_size_t i;
for (i = index; i < tab->size; i++)
{
ase_cstr_t x;
x.ptr = tab->buf[i].name.ptr;
x.len = tab->buf[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = index + 1; i-- > 0; )
{
ase_cstr_t x;
x.ptr = tab->buf[i].name.ptr;
x.len = tab->buf[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rrfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = tab->size - index; i-- > 0; )
{
ase_cstr_t x;
x.ptr = tab->buf[i].name.ptr;
x.len = tab->buf[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return (ase_size_t)-1;
}

View File

@ -1,87 +0,0 @@
/*
* $Id: tab.h 363 2008-09-04 10:58:08Z baconevi $
*
* {License}
*/
#ifndef _ASE_LIB_AWK_TAB_H_
#define _ASE_LIB_AWK_TAB_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
/* TODO: you have to turn this into a hash table.
as of now, this is an arrayed table. */
typedef struct ase_awk_tab_t ase_awk_tab_t;
struct ase_awk_tab_t
{
struct
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
}* buf;
ase_size_t size;
ase_size_t capa;
ase_awk_t* awk;
ase_bool_t __dynamic;
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk);
void ase_awk_tab_close (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab);
ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa);
void ase_awk_tab_clear (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_insert (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_remove (
ase_awk_tab_t* tab, ase_size_t index, ase_size_t count);
ase_size_t ase_awk_tab_add (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_adduniq (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_find (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_rfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_rrfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_findx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_awk_tab_rfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_awk_tab_rrfindx (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -272,6 +272,8 @@ size_t ase_lda_search (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
for (i = pos; i < lda->size; i++)
{
if (lda->node[i] == ASE_NULL) continue;
if (lda->comper (lda,
DPTR(lda->node[i]), DLEN(lda->node[i]),
dptr, dlen) == 0) return i;
@ -284,29 +286,18 @@ size_t ase_lda_rsearch (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
{
size_t i;
if (pos >= lda->size) return INVALID;
if (lda->size > 0)
{
if (pos >= lda->size) pos = lda->size - 1;
for (i = pos + 1; i-- > 0; )
{
if (lda->node[i] == ASE_NULL) continue;
if (lda->comper (lda,
DPTR(lda->node[i]), DLEN(lda->node[i]),
dptr, dlen) == 0) return i;
}
return INVALID;
}
size_t ase_lda_rrsearch (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
{
size_t i;
if (pos >= lda->size) return INVALID;
for (i = lda->size - pos; i-- > 0; )
{
if (lda->comper (lda,
DPTR(lda->node[i]), DLEN(lda->node[i]),
dptr, dlen) == 0) return i;
}
return INVALID;
@ -456,6 +447,32 @@ size_t ase_lda_delete (lda_t* lda, size_t index, size_t count)
return count;
}
size_t ase_lda_uplete (lda_t* lda, size_t index, size_t count)
{
size_t i;
if (index >= lda->size) return 0;
if (count > lda->size - index) count = lda->size - index;
i = index;
for (i = index; i < index + count; i++)
{
node_t* c = lda->node[i];
if (c != ASE_NULL)
{
if (lda->freeer != ASE_NULL)
lda->freeer (lda, DPTR(c), DLEN(c));
ASE_MMGR_FREE (lda->mmgr, c);
lda->node[i] = ASE_NULL;
}
}
return count;
}
void ase_lda_clear (lda_t* lda)
{
size_t i;
@ -475,139 +492,6 @@ void ase_lda_clear (lda_t* lda)
lda->size = 0;
}
size_t ase_lda_add (
lda_t* lda, ase_char_t* str, size_t len)
{
return ase_lda_insert (lda, lda->size, str, len);
}
size_t ase_lda_adduniq (
lda_t* lda, ase_char_t* str, size_t len)
{
size_t i;
i = ase_lda_search (lda, 0, str, len);
if (i != INVALID) return i; /* found. return the current index */
/* insert a new entry */
return ase_lda_insert (lda, lda->size, str, len);
}
#if 0
size_t ase_lda_find (lda_t* lda, size_t index, const ase_char_t* str, size_t len)
{
size_t i;
for (i = index; i < lda->size; i++)
{
if (ase_strxncmp (
lda->node[i].name.ptr, lda->node[i].name.len,
str, len) == 0) return i;
}
return INVALID;
}
size_t ase_lda_rfind (lda_t* lda, size_t index, const ase_char_t* str, size_t len)
{
size_t i;
if (index >= lda->size) return INVALID;
for (i = index + 1; i-- > 0; )
{
if (ase_strxncmp (
lda->node[i].name.ptr, lda->node[i].name.len,
str, len) == 0) return i;
}
return INVALID;
}
size_t ase_lda_rrfind (lda_t* lda, size_t index, const ase_char_t* str, size_t len)
{
size_t i;
if (index >= lda->size) return INVALID;
for (i = lda->size - index; i-- > 0; )
{
if (ase_strxncmp (
lda->node[i].name.ptr, lda->node[i].name.len,
str, len) == 0) return i;
}
return INVALID;
}
size_t ase_lda_findx (
lda_t* lda, size_t index,
const ase_char_t* str, size_t len,
void(*transform)(size_t, ase_cstr_t*,void*), void* arg)
{
size_t i;
for (i = index; i < lda->size; i++)
{
ase_cstr_t x;
x.ptr = lda->node[i].name.ptr;
x.len = lda->node[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return INVALID;
}
size_t ase_lda_rfindx (
lda_t* lda, size_t index,
const ase_char_t* str, size_t len,
void(*transform)(size_t, ase_cstr_t*,void*), void* arg)
{
size_t i;
if (index >= lda->size) return INVALID;
for (i = index + 1; i-- > 0; )
{
ase_cstr_t x;
x.ptr = lda->node[i].name.ptr;
x.len = lda->node[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return INVALID;
}
size_t ase_lda_rrfindx (
lda_t* lda, size_t index,
const ase_char_t* str, size_t len,
void(*transform)(size_t, ase_cstr_t*,void*), void* arg)
{
size_t i;
if (index >= lda->size) return INVALID;
for (i = lda->size - index; i-- > 0; )
{
ase_cstr_t x;
x.ptr = lda->node[i].name.ptr;
x.len = lda->node[i].name.len;
transform (i, &x, arg);
if (ase_strxncmp (x.ptr, x.len, str, len) == 0) return i;
}
return INVALID;
}
#endif
void* ase_lda_copysimple (lda_t* lda, void* dptr, size_t dlen)
{
return dptr;