changed the way FILENAME and OFILENAME are set upon start-up

This commit is contained in:
hyung-hwan 2011-04-21 01:37:48 +00:00
parent c7020c00ca
commit 0ba21de0f1

View File

@ -1,5 +1,5 @@
/* /*
* $Id: std.c 436 2011-04-17 15:28:22Z hyunghwan.chung $ * $Id: std.c 439 2011-04-20 07:37:48Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -1194,32 +1194,21 @@ qse_awk_rtx_t* qse_awk_rtx_openstd (
rxtn->c.out.index = 0; rxtn->c.out.index = 0;
rxtn->c.out.count = 0; rxtn->c.out.count = 0;
if (icf && icf[0])
{ /* FILENAME can be set when the input console is opened.
/* If an explicit console file name is given, * so we skip setting it here even if an explicit console file
* set FILENAME in advance in case FILENAME printing * is specified. So the value of FILENAME is empty in the
* is the first output statement executed. FILENAME * BEGIN block unless getline is ever met.
* would be printed as an empty string without this *
* as FILENAME is resolved before the I/O handler is * However, OFILENAME is different. The output
* executed. * console is treated as if it's already open upon start-up.
*/ * otherwise, 'BEGIN { print OFILENAME; }' prints an empty
if (qse_awk_rtx_setfilename (rtx, icf[0], qse_strlen(icf[0])) <= -1) * string regardless of output console files specified.
{ * That's because OFILENAME is evaluated before the output
awk->errinf = rtx->errinf; /* transfer error info */ * console file is opened.
qse_awk_rtx_close (rtx); */
return QSE_NULL;
}
}
if (ocf && ocf[0]) if (ocf && ocf[0])
{ {
/* If an explicit console file name is given,
* set OFILENAME in advance in case OFILENAME printing
* is the first output statement executed. OFILENAME
* would be printed as an empty string without this
* as OFILENAME is resolved before the I/O handler is
* executed.
*/
if (qse_awk_rtx_setofilename (rtx, ocf[0], qse_strlen(ocf[0])) <= -1) if (qse_awk_rtx_setofilename (rtx, ocf[0], qse_strlen(ocf[0])) <= -1)
{ {
awk->errinf = rtx->errinf; /* transfer error info */ awk->errinf = rtx->errinf; /* transfer error info */
@ -1261,26 +1250,32 @@ static int fnc_math_1 (
a0 = qse_awk_rtx_getarg (run, 0); a0 = qse_awk_rtx_getarg (run, 0);
n = qse_awk_rtx_valtonum (run, a0, &lv, &rv); n = qse_awk_rtx_valtonum (run, a0, &lv, &rv);
if (n == -1) return -1; if (n <= -1) return -1;
if (n == 0) rv = (qse_real_t)lv; if (n == 0) rv = (qse_real_t)lv;
if (type == FNC_MATH_LD) switch (type)
{ {
long double (*rf) (long double) = case FNC_MATH_LD:
(long double(*)(long double))f; {
r = qse_awk_rtx_makerealval (run, rf(rv)); long double (*rf) (long double) =
} (long double(*)(long double))f;
else if (type == FNC_MATH_D) r = qse_awk_rtx_makerealval (run, rf(rv));
{ break;
double (*rf) (double) = (double(*)(double))f; }
r = qse_awk_rtx_makerealval (run, rf(rv)); case FNC_MATH_D:
} {
else double (*rf) (double) = (double(*)(double))f;
{ r = qse_awk_rtx_makerealval (run, rf(rv));
float (*rf) (float); break;
QSE_ASSERT (type == FNC_MATH_F); }
rf = (float(*)(float))f; default:
r = qse_awk_rtx_makerealval (run, rf(rv)); {
float (*rf) (float);
QSE_ASSERT (type == FNC_MATH_F);
rf = (float(*)(float))f;
r = qse_awk_rtx_makerealval (run, rf(rv));
break;
}
} }
if (r == QSE_NULL) return -1; if (r == QSE_NULL) return -1;
@ -1306,32 +1301,41 @@ static int fnc_math_2 (
a1 = qse_awk_rtx_getarg (run, 1); a1 = qse_awk_rtx_getarg (run, 1);
n = qse_awk_rtx_valtonum (run, a0, &lv0, &rv0); n = qse_awk_rtx_valtonum (run, a0, &lv0, &rv0);
if (n == -1) return -1; if (n <= -1) return -1;
if (n == 0) rv0 = (qse_real_t)lv0; if (n == 0) rv0 = (qse_real_t)lv0;
n = qse_awk_rtx_valtonum (run, a1, &lv1, &rv1); n = qse_awk_rtx_valtonum (run, a1, &lv1, &rv1);
if (n == -1) return -1; if (n <= -1) return -1;
if (n == 0) rv1 = (qse_real_t)lv1; if (n == 0) rv1 = (qse_real_t)lv1;
if (type == FNC_MATH_LD) switch (type)
{ {
long double (*rf) (long double,long double) = case FNC_MATH_LD:
(long double(*)(long double,long double))f; {
r = qse_awk_rtx_makerealval (run, rf(rv0,rv1)); long double (*rf) (long double,long double) =
(long double(*)(long double,long double))f;
r = qse_awk_rtx_makerealval (run, rf(rv0,rv1));
break;
}
case FNC_MATH_D:
{
double (*rf) (double,double) =
(double(*)(double,double))f;
r = qse_awk_rtx_makerealval (run, rf(rv0,rv1));
break;
}
default:
{
float (*rf) (float,float);
QSE_ASSERT (type == FNC_MATH_F);
rf = (float(*)(float,float))f;
r = qse_awk_rtx_makerealval (run, rf(rv0,rv1));
break;
}
} }
else if (type == FNC_MATH_D)
{
double (*rf) (double,double) = (double(*)(double,double))f;
r = qse_awk_rtx_makerealval (run, rf(rv0,rv1));
}
else
{
float (*rf) (float,float);
QSE_ASSERT (type == FNC_MATH_F);
rf = (float(*)(float,float))f;
r = qse_awk_rtx_makerealval (run, rf(rv0,rv1));
}
if (r == QSE_NULL) return -1; if (r == QSE_NULL) return -1;
qse_awk_rtx_setretval (run, r); qse_awk_rtx_setretval (run, r);