added -v var=val to cmd/awk/awk.c

This commit is contained in:
2009-06-21 06:47:34 +00:00
parent cf606b6819
commit e66a372119
10 changed files with 348 additions and 346 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c 199 2009-06-14 08:40:52Z hyunghwan.chung $
* $Id: err.c 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -88,6 +88,7 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
QSE_T("END not followed by a left bracket on the same line"),
QSE_T("duplicate BEGIN"),
QSE_T("duplicate END"),
QSE_T("keyword '${0}' redefined"),
QSE_T("intrinsic function '${0}' redefined"),
QSE_T("function '${0}' redefined"),
QSE_T("global variable '${0}' redefined"),

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c 204 2009-06-18 12:08:06Z hyunghwan.chung $
* $Id: parse.c 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -1403,12 +1403,10 @@ static void adjust_static_globals (qse_awk_t* awk)
if (gtab[id].valid != 0 &&
(awk->option & gtab[id].valid) != gtab[id].valid)
{
/*awk->parse.gbls.buf[id].name.len = 0;*/
QSE_LDA_DLEN(awk->parse.gbls,id) = 0;
}
else
{
/*awk->parse.gbls.buf[id].name.len = gtab[id].name_len;*/
QSE_LDA_DLEN(awk->parse.gbls,id) = gtab[id].name_len;
}
}
@ -1487,6 +1485,15 @@ static int add_global (
{
qse_size_t ngbls;
/* check if it is a keyword */
if (classify_ident (awk, name, len) != TOKEN_IDENT)
{
SETERRARG (
awk, QSE_AWK_EKWRED, awk->token.line,
name, len);
return -1;
}
/* check if it conflict with a builtin function name */
if (qse_awk_getfnc (awk, name, len) != QSE_NULL)
{
@ -1563,14 +1570,14 @@ int qse_awk_addgbl (
if (awk->tree.ngbls > awk->tree.ngbls_base)
{
/* this function is not allow after qse_awk_parse is called */
/* this function is not allowed after qse_awk_parse is called */
SETERR (awk, QSE_AWK_ENOPER);
return -1;
}
n = add_global (awk, name, len, 0, 0);
/* update the count of the static gbls.
/* update the count of the static globals.
* the total global count has been updated inside add_global. */
if (n >= 0) awk->tree.ngbls_base++;
@ -4662,7 +4669,7 @@ static int get_token (qse_awk_t* awk)
}
*/
}
else if (QSE_AWK_ISALPHA (awk, c) || c == QSE_T('_'))
else if (c == QSE_T('_') || QSE_AWK_ISALPHA (awk, c))
{
int type;
@ -4672,8 +4679,9 @@ static int get_token (qse_awk_t* awk)
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
while (QSE_AWK_ISALPHA (awk, c) ||
c == QSE_T('_') || QSE_AWK_ISDIGIT(awk,c));
while (c == QSE_T('_') ||
QSE_AWK_ISALPHA (awk, c) ||
QSE_AWK_ISDIGIT (awk, c));
type = classify_ident (awk,
QSE_STR_PTR(awk->token.name),

View File

@ -1,5 +1,5 @@
/*
* $Id: rec.c 200 2009-06-14 13:22:00Z hyunghwan.chung $
* $Id: rec.c 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -31,10 +31,6 @@ int qse_awk_rtx_setrec (
if (idx == 0)
{
qse_long_t l;
qse_real_t r;
int x;
if (str == QSE_STR_PTR(&run->inrec.line) &&
len == QSE_STR_LEN(&run->inrec.line))
{
@ -53,8 +49,7 @@ int qse_awk_rtx_setrec (
}
}
x = qse_awk_rtx_strtonum (run, 1, str, len, &l, &r);
v = qse_awk_rtx_makestrval (run, str, len);
v = qse_awk_rtx_makenstrval (run, str, len);
if (v == QSE_NULL)
{
@ -62,14 +57,6 @@ int qse_awk_rtx_setrec (
return -1;
}
if (x >= 0)
{
/* set the numeric string flag if a string
* can be converted to a number */
QSE_ASSERT (x == 0 || x == 1);
v->nstr = x + 1; /* long -> 1, real -> 2 */
}
QSE_ASSERT (run->inrec.d0->type == QSE_AWK_VAL_NIL);
/* d0 should be cleared before the next line is reached
* as it doesn't call qse_awk_rtx_refdownval on run->inrec.d0 */
@ -215,10 +202,6 @@ static int split_record (qse_awk_rtx_t* run)
while (p != QSE_NULL)
{
qse_long_t l;
qse_real_t r;
int x;
if (fs_len <= 1)
{
p = qse_awk_rtx_strxntok (
@ -247,25 +230,18 @@ static int split_record (qse_awk_rtx_t* run)
run->inrec.flds[run->inrec.nflds].ptr = tok;
run->inrec.flds[run->inrec.nflds].len = tok_len;
x = qse_awk_rtx_strtonum (run, 1, tok, tok_len, &l, &r);
run->inrec.flds[run->inrec.nflds].val =
qse_awk_rtx_makestrval (run, tok, tok_len);
qse_awk_rtx_makenstrval (run, tok, tok_len);
if (run->inrec.flds[run->inrec.nflds].val == QSE_NULL)
{
if (fs_free != QSE_NULL) QSE_AWK_FREE (run->awk, fs_free);
if (fs_free != QSE_NULL)
QSE_AWK_FREE (run->awk, fs_free);
return -1;
}
if (x >= 0)
{
/* set the numeric string flags if a string
* can be converted to a number */
QSE_ASSERT (x == 0 || x == 1);
run->inrec.flds[run->inrec.nflds].val->nstr = x + 1;
}
qse_awk_rtx_refupval (run, run->inrec.flds[run->inrec.nflds].val);
qse_awk_rtx_refupval (
run, run->inrec.flds[run->inrec.nflds].val);
run->inrec.nflds++;
len = QSE_STR_LEN(&run->inrec.line) -

View File

@ -1,5 +1,5 @@
/*
* $Id: std.c 204 2009-06-18 12:08:06Z hyunghwan.chung $
* $Id: std.c 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -599,6 +599,7 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
qse_sio_t* sio;
const qse_char_t* file;
retry:
file = rxtn->c.in.files[rxtn->c.in.index];
if (file == QSE_NULL)
@ -726,6 +727,7 @@ static qse_ssize_t awk_rio_console (
qse_sio_t* sio;
const qse_char_t* file;
retry:
/* it has reached the end of the current file.
* open the next file if available */
if (rxtn->c.in.files == QSE_NULL ||

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c 200 2009-06-14 13:22:00Z hyunghwan.chung $
* $Id: val.c 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -348,6 +348,30 @@ init:
return (qse_awk_val_t*)val;
}
qse_awk_val_t* qse_awk_rtx_makenstrval (
qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t len)
{
int x;
qse_awk_val_t* v;
qse_long_t l;
qse_real_t r;
x = qse_awk_rtx_strtonum (run, 1, str, len, &l, &r);
v = qse_awk_rtx_makestrval (run, str, len);
if (v == QSE_NULL) return QSE_NULL;
if (x >= 0)
{
/* set the numeric string flag if a string
* can be converted to a number */
QSE_ASSERT (x == 0 || x == 1);
v->nstr = x + 1; /* long -> 1, real -> 2 */
}
return v;
}
qse_awk_val_t* qse_awk_rtx_makerexval (
qse_awk_rtx_t* run, const qse_char_t* buf, qse_size_t len, void* code)
{