added partial code to handle a numeric string better
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rec.c 198 2009-06-12 12:58:50Z hyunghwan.chung $
|
||||
* $Id: rec.c 200 2009-06-14 13:22:00Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -31,6 +31,10 @@ 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))
|
||||
{
|
||||
@ -49,13 +53,23 @@ int qse_awk_rtx_setrec (
|
||||
}
|
||||
}
|
||||
|
||||
x = qse_awk_rtx_strtonum (run, 1, str, len, &l, &r);
|
||||
v = qse_awk_rtx_makestrval (run, str, len);
|
||||
|
||||
if (v == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_clrrec (run, QSE_FALSE);
|
||||
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 */
|
||||
@ -233,13 +247,7 @@ 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;
|
||||
|
||||
/* this way of handling a record distorts a value.
|
||||
x = qse_awk_rtx_strtonum (run, 1, tok, tok_len, &l, &r);
|
||||
run->inrec.flds[run->inrec.nflds].val =
|
||||
(x <= -1)? qse_awk_rtx_makestrval (run, tok, tok_len):
|
||||
(x == 0)? qse_awk_rtx_makeintval (run, l):
|
||||
qse_awk_rtx_makerealval (run, r);
|
||||
*/
|
||||
run->inrec.flds[run->inrec.nflds].val =
|
||||
qse_awk_rtx_makestrval (run, tok, tok_len);
|
||||
|
||||
@ -249,6 +257,14 @@ static int split_record (qse_awk_rtx_t* run)
|
||||
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);
|
||||
run->inrec.nflds++;
|
||||
|
||||
|
Reference in New Issue
Block a user