- added Awk::setGlobal & Awk::getGlobal

- fixed a bug in parsing getline
This commit is contained in:
2009-07-15 02:06:14 +00:00
parent af6831ed3c
commit f5e3e53290
15 changed files with 546 additions and 545 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp 231 2009-07-13 10:03:53Z hyunghwan.chung $
* $Id: Awk.cpp 232 2009-07-14 08:06:14Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -1000,7 +1000,6 @@ int Awk::Run::setGlobal (int id, const char_t* ptr, size_t len)
int Awk::Run::setGlobal (int id, const Value& gbl)
{
QSE_ASSERT (this->rtx != QSE_NULL);
return qse_awk_rtx_setgbl (this->rtx, id, (val_t*)gbl);
}
@ -1531,7 +1530,7 @@ int Awk::addGlobal (const char_t* name)
QSE_ASSERT (awk != QSE_NULL);
int n = qse_awk_addgbl (awk, name, qse_strlen(name));
if (n == -1) retrieveError ();
if (n <= -1) retrieveError ();
return n;
}
@ -1539,7 +1538,33 @@ int Awk::deleteGlobal (const char_t* name)
{
QSE_ASSERT (awk != QSE_NULL);
int n = qse_awk_delgbl (awk, name, qse_strlen(name));
if (n == -1) retrieveError ();
if (n <= -1) retrieveError ();
return n;
}
int Awk::setGlobal (int id, const Value& v)
{
QSE_ASSERT (awk != QSE_NULL);
QSE_ASSERT (runctx.rtx != QSE_NULL);
if (v.run != &runctx)
{
setError (ERR_INVAL);
return -1;
}
int n = runctx.setGlobal (id, v);
if (n <= -1) retrieveError ();
return n;
}
int Awk::getGlobal (int id, Value& v)
{
QSE_ASSERT (awk != QSE_NULL);
QSE_ASSERT (runctx.rtx != QSE_NULL);
int n = runctx.getGlobal (id, v);
if (n <= -1) retrieveError ();
return n;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 212 2009-06-25 07:39:27Z hyunghwan.chung $
* $Id: awk.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -54,6 +54,27 @@ static void free_fnc (qse_map_t* map, void* vptr, qse_size_t vlen)
QSE_AWK_FREE (awk, f);
}
static int init_token (qse_mmgr_t* mmgr, qse_awk_token_t* token)
{
token->name = qse_str_open (mmgr, 0, 128);
if (token->name == QSE_NULL) return -1;
token->type = 0;
token->line = 0;
token->column = 0;
return 0;
}
static void fini_token (qse_awk_token_t* token)
{
if (token->name != QSE_NULL)
{
qse_str_close (token->name);
token->name = QSE_NULL;
}
}
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
{
qse_awk_t* awk;
@ -91,8 +112,8 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
}
awk->prm = *prm;
awk->token.name = qse_str_open (mmgr, 0, 128);
if (awk->token.name == QSE_NULL) goto oops;
if (init_token (mmgr, &awk->token) == -1) goto oops;
if (init_token (mmgr, &awk->atoken) == -1) goto oops;
awk->wtab = qse_map_open (mmgr, QSE_SIZEOF(awk), 512, 70);
if (awk->wtab == QSE_NULL) goto oops;
@ -170,12 +191,9 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
awk->tree.chain_tail = QSE_NULL;
awk->tree.chain_size = 0;
awk->token.prev.type = 0;
awk->token.prev.line = 0;
awk->token.prev.column = 0;
awk->token.type = 0;
awk->token.line = 0;
awk->token.column = 0;
awk->ptoken.type = 0;
awk->ptoken.line = 0;
awk->ptoken.column = 0;
awk->src.lex.curc = QSE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
@ -218,7 +236,8 @@ oops:
if (awk->tree.funs) qse_map_close (awk->tree.funs);
if (awk->rwtab) qse_map_close (awk->rwtab);
if (awk->wtab) qse_map_close (awk->wtab);
if (awk->token.name) qse_str_close (awk->token.name);
fini_token (&awk->atoken);
fini_token (&awk->token);
QSE_AWK_FREE (awk, awk);
return QSE_NULL;
@ -240,7 +259,8 @@ int qse_awk_close (qse_awk_t* awk)
qse_map_close (awk->rwtab);
qse_map_close (awk->wtab);
qse_str_close (awk->token.name);
fini_token (&awk->atoken);
fini_token (&awk->token);
/* QSE_AWK_ALLOC, QSE_AWK_FREE, etc can not be used
* from the next line onwards */

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 212 2009-06-25 07:39:27Z hyunghwan.chung $
* $Id: awk.h 232 2009-07-14 08:06:14Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -96,6 +96,15 @@ struct qse_awk_tree_t
int ok;
};
typedef struct qse_awk_token_t qse_awk_token_t;
struct qse_awk_token_t
{
int type;
qse_str_t* name;
qse_size_t line;
qse_size_t column;
};
struct qse_awk_t
{
QSE_DEFINE_COMMON_FIELDS (sed)
@ -188,21 +197,17 @@ struct qse_awk_t
} shared;
} src;
/* token */
struct
/* previous token info excluding name */
struct
{
struct
{
int type;
qse_size_t line;
qse_size_t column;
} prev;
int type;
qse_str_t* name;
int type;
qse_size_t line;
qse_size_t column;
} token;
} ptoken;
/* current token */
qse_awk_token_t token;
qse_awk_token_t atoken;
/* intrinsic functions */
struct

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c 220 2009-07-01 13:14:39Z hyunghwan.chung $
* $Id: err.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -107,6 +107,7 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
QSE_T("'nextfile' illegal in the END block"),
QSE_T("'printf' not followed by argument"),
QSE_T("both prefix and postfix increment/decrement operator present"),
QSE_T("illegal operand for increment/decrement operator"),
QSE_T("divide by zero"),
QSE_T("invalid operand"),

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c 230 2009-07-13 08:51:23Z hyunghwan.chung $
* $Id: run.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -4021,7 +4021,8 @@ static int __cmp_int_str (
qse_awk_rtx_valtostr_out_t out;
int n;
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr > 0)
/* SCO CC doesn't seem to handle right->nstr > 0 properly */
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr /*> 0*/)
{
qse_long_t ll;
qse_real_t rr;
@ -4107,7 +4108,8 @@ static int __cmp_real_str (
qse_awk_rtx_valtostr_out_t out;
int n;
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr > 0)
/* SCO CC doesn't seem to handle right->nstr > 0 properly */
if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr /*> 0*/)
{
const qse_char_t* end;
qse_real_t rr;

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c 210 2009-06-24 08:29:33Z hyunghwan.chung $
* $Id: tree.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -552,6 +552,9 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
case QSE_AWK_NDE_GETLINE:
{
qse_awk_nde_getline_t* px = (qse_awk_nde_getline_t*)nde;
PUT_SRCSTR (awk, QSE_T("("));
if (px->in != QSE_NULL &&
(px->in_type == QSE_AWK_IN_PIPE ||
px->in_type == QSE_AWK_IN_RWPIPE))
@ -578,6 +581,8 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
PUT_SRCSTR (awk, QSE_T(" "));
PRINT_EXPRESSION (awk, px->in);
}
PUT_SRCSTR (awk, QSE_T(")"));
break;
}