adding time functions

This commit is contained in:
2008-12-18 02:39:15 +00:00
parent d45b0c3127
commit 3d9fbd489f
7 changed files with 195 additions and 50 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.cpp 499 2008-12-16 09:42:48Z baconevi $
* $Id: StdAwk.cpp 501 2008-12-17 08:39:15Z baconevi $
*
* {License}
*/
@ -67,7 +67,7 @@ int StdAwk::open ()
int StdAwk::run (const char_t* main, const char_t** args, size_t nargs)
{
ase_time_t now;
ase_ntime_t now;
if (ase_gettime(&now) == -1) this->seed = 0;
else this->seed = (unsigned int)now;
@ -224,7 +224,7 @@ int StdAwk::srand (Run& run, Return& ret, const Argument* args, size_t nargs,
if (nargs == 0)
{
ase_time_t now;
ase_ntime_t now;
if (ase_gettime (&now) == -1)
this->seed = (unsigned int)now;
@ -249,9 +249,12 @@ int StdAwk::srand (Run& run, Return& ret, const Argument* args, size_t nargs,
int StdAwk::systime (Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
ase_time_t now;
if (ase_gettime (&now) == -1) now = 0;
return ret.set ((long_t)now / ASE_MSEC_IN_SEC);
ase_ntime_t now;
if (ase_gettime(&now) == -1)
return ret.set (ASE_TYPE_MIN(long_t));
else
return ret.set ((long_t)now / ASE_MSEC_IN_SEC);
}
int StdAwk::strftime (Run& run, Return& ret, const Argument* args, size_t nargs,

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 496 2008-12-15 09:56:48Z baconevi $
* $Id: awk.c 501 2008-12-17 08:39:15Z baconevi $
*
* {License}
*/
@ -454,6 +454,7 @@ int ase_awk_setword (ase_awk_t* awk,
return 0;
}
/* TODO: XXXX */
int ase_awk_setrexfns (ase_awk_t* awk, ase_awk_rexfns_t* rexfns)
{
if (rexfns->build == ASE_NULL ||

View File

@ -708,7 +708,7 @@ int ase_awk_runsimple (ase_awk_t* awk, ase_char_t** icf, ase_awk_runcbs_t* cbs)
ase_awk_runios_t ios;
runio_data_t rd;
rxtn_t rxtn;
ase_time_t now;
ase_ntime_t now;
rd.ic.files = icf;
rd.ic.index = 0;
@ -1033,7 +1033,7 @@ static int bfn_srand (ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
}
else
{
ase_time_t now;
ase_ntime_t now;
if (ase_gettime(&now) == -1) rxtn->seed >>= 1;
else rxtn->seed = (unsigned int)now;
@ -1055,12 +1055,14 @@ static int bfn_srand (ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
static int bfn_systime (ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
{
ase_awk_val_t* r;
ase_time_t now;
ase_ntime_t now;
int n;
if (ase_gettime(&now) == -1) now = 0;
if (ase_gettime(&now) == -1)
r = ase_awk_makeintval (run, ASE_TYPE_MIN(ase_long_t));
else
r = ase_awk_makeintval (run, now / ASE_MSEC_IN_SEC);
r = ase_awk_makeintval (run, now / ASE_MSEC_IN_SEC);
if (r == ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);