Added some c++ code to implment missing features from the std(c) implementation. not completed yet

This commit is contained in:
hyung-hwan 2012-08-06 14:38:09 +00:00
parent 785c95b1e6
commit 17a8a3039d
4 changed files with 50 additions and 30 deletions

View File

@ -126,14 +126,14 @@ protected:
const char_t* name, size_t len); const char_t* name, size_t len);
int system (Run& run, Value& ret, const Value* args, size_t nargs, int system (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len); const char_t* name, size_t len);
int time (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len);
#if defined(QSE_CHAR_IS_WCHAR)
qse_cmgr_t* getcmgr (const char_t* ioname); qse_cmgr_t* getcmgr (const char_t* ioname);
int setenc (Run& run, Value& ret, const Value* args, size_t nargs, int setioattr (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len); const char_t* name, size_t len);
int unsetenc (Run& run, Value& ret, const Value* args, size_t nargs, int getioattr (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len); const char_t* name, size_t len);
#endif
// pipe io handlers // pipe io handlers
int openPipe (Pipe& io); int openPipe (Pipe& io);
@ -183,6 +183,12 @@ protected:
qse_htb_t cmgrtab; qse_htb_t cmgrtab;
bool cmgrtab_inited; bool cmgrtab_inited;
/* global variables */
int gbl_argc;
int gbl_argv;
int gbl_environ;
int gbl_procinfo;
/* standard input console - reuse runarg */ /* standard input console - reuse runarg */
size_t runarg_index; size_t runarg_index;
size_t runarg_count; size_t runarg_count;

View File

@ -1272,8 +1272,7 @@ int Awk::init_runctx ()
rio.file = fileHandler; rio.file = fileHandler;
rio.console = consoleHandler; rio.console = consoleHandler;
rtx_t* rtx = qse_awk_rtx_open ( rtx_t* rtx = qse_awk_rtx_open (awk, QSE_SIZEOF(rxtn_t), &rio);
awk, QSE_SIZEOF(rxtn_t), &rio, (qse_cstr_t*)runarg.ptr);
if (rtx == QSE_NULL) if (rtx == QSE_NULL)
{ {
retrieveError(); retrieveError();

View File

@ -96,14 +96,29 @@ int StdAwk::open ()
int n = Awk::open (); int n = Awk::open ();
if (n == -1) return n; if (n == -1) return n;
ADDFNC (QSE_T("rand"), 0, 0, &StdAwk::rand, 0); this->gbl_argc = addGlobal (QSE_T("ARGC"));
ADDFNC (QSE_T("srand"), 0, 1, &StdAwk::srand, 0); this->gbl_argv = addGlobal (QSE_T("ARGV"));
ADDFNC (QSE_T("system"), 1, 1, &StdAwk::system, 0); this->gbl_environ = addGlobal (QSE_T("ENVIRON"));
this->gbl_procinfo = addGlobal (QSE_T("PROCINFO"));
if (this->gbl_argc <= -1 ||
this->gbl_argv <= -1 ||
this->gbl_environ <= -1 ||
this->gbl_procinfo <= -1)
{
Awk::close ();
return -1;
}
#if defined(QSE_CHAR_IS_WCHAR) if (addFunction (QSE_T("rand"), 0, 0, (FunctionHandler)&StdAwk::rand, 0) <= -1 ||
ADDFNC (QSE_T("setenc"), 2, 2, &StdAwk::setenc, QSE_AWK_RIO); addFunction (QSE_T("srand"), 0, 1, (FunctionHandler)&StdAwk::srand, 0) <= -1 ||
ADDFNC (QSE_T("unsetenc"), 1, 1, &StdAwk::unsetenc, QSE_AWK_RIO); addFunction (QSE_T("system"), 1, 1, (FunctionHandler)&StdAwk::system, 0) <= -1 ||
#endif addFunction (QSE_T("time"), 1, 1, (FunctionHandler)&StdAwk::time, 0) <= -1 ||
addFunction (QSE_T("setioattr"), 3, 3, (FunctionHandler)&StdAwk::setioattr, QSE_AWK_RIO) <= -1 ||
addFunction (QSE_T("getioattr"), 2, 2, (FunctionHandler)&StdAwk::getioattr, QSE_AWK_RIO) <= -1)
{
Awk::close ();
return -1;
}
qse_ntime_t now; qse_ntime_t now;
@ -197,7 +212,7 @@ int StdAwk::system (Run& run, Value& ret, const Value* args, size_t nargs,
size_t l; size_t l;
const char_t* ptr = args[0].toStr(&l); const char_t* ptr = args[0].toStr(&l);
#ifdef _WIN32 #if defined(_WIN32)
return ret.setInt ((long_t)::_tsystem(ptr)); return ret.setInt ((long_t)::_tsystem(ptr));
#elif defined(QSE_CHAR_IS_MCHAR) #elif defined(QSE_CHAR_IS_MCHAR)
return ret.setInt ((long_t)::system(ptr)); return ret.setInt ((long_t)::system(ptr));
@ -212,7 +227,13 @@ int StdAwk::system (Run& run, Value& ret, const Value* args, size_t nargs,
#endif #endif
} }
#if defined(QSE_CHAR_IS_WCHAR) int StdAwk::time (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len)
{
/* TODO: */
return 0;
}
qse_cmgr_t* StdAwk::getcmgr (const char_t* ioname) qse_cmgr_t* StdAwk::getcmgr (const char_t* ioname)
{ {
QSE_ASSERT (this->cmgrtab_inited == true); QSE_ASSERT (this->cmgrtab_inited == true);
@ -222,7 +243,7 @@ qse_cmgr_t* StdAwk::getcmgr (const char_t* ioname)
return QSE_NULL; return QSE_NULL;
} }
int StdAwk::setenc (Run& run, Value& ret, const Value* args, size_t nargs, int StdAwk::setioattr (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len) const char_t* name, size_t len)
{ {
QSE_ASSERT (this->cmgrtab_inited == true); QSE_ASSERT (this->cmgrtab_inited == true);
@ -248,7 +269,7 @@ int StdAwk::setenc (Run& run, Value& ret, const Value* args, size_t nargs,
return ret.setInt ((long_t)(pair? 0: -1)); return ret.setInt ((long_t)(pair? 0: -1));
} }
int StdAwk::unsetenc (Run& run, Value& ret, const Value* args, size_t nargs, int StdAwk::getioattr (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len) const char_t* name, size_t len)
{ {
QSE_ASSERT (this->cmgrtab_inited == true); QSE_ASSERT (this->cmgrtab_inited == true);
@ -257,7 +278,6 @@ int StdAwk::unsetenc (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* ptr = args[0].toStr(&l); const char_t* ptr = args[0].toStr(&l);
return ret.setInt ((long_t)qse_htb_delete (&this->cmgrtab, ptr, l)); return ret.setInt ((long_t)qse_htb_delete (&this->cmgrtab, ptr, l));
} }
#endif
int StdAwk::openPipe (Pipe& io) int StdAwk::openPipe (Pipe& io)
{ {
@ -490,7 +510,7 @@ int StdAwk::open_console_in (Console& io)
* 'BEGIN { ARGV[1]="file3"; } * 'BEGIN { ARGV[1]="file3"; }
* { print $0; }' file1 file2 * { print $0; }' file1 file2
*/ */
argv = qse_awk_rtx_getgbl (rtx, QSE_AWK_GBL_ARGV); argv = qse_awk_rtx_getgbl (rtx, this->gbl_argv);
QSE_ASSERT (argv != QSE_NULL); QSE_ASSERT (argv != QSE_NULL);
QSE_ASSERT (argv->type == QSE_AWK_VAL_MAP); QSE_ASSERT (argv->type == QSE_AWK_VAL_MAP);

View File

@ -2416,18 +2416,13 @@ static int add_globals (qse_awk_t* awk)
return 0; return 0;
} }
#define ADDFNC(awk,name,min,max,fnc,valid) \
if (qse_awk_addfnc (\
(awk), (name), qse_strlen(name), \
valid, (min), (max), QSE_NULL, (fnc)) == QSE_NULL) return -1;
static int add_functions (qse_awk_t* awk) static int add_functions (qse_awk_t* awk)
{ {
ADDFNC (awk, QSE_T("rand"), 0, 0, fnc_rand, 0); if (qse_awk_addfnc (awk, QSE_T("rand"), 4, 0, 0, 0, QSE_NULL, fnc_rand) <= -1 ||
ADDFNC (awk, QSE_T("srand"), 0, 1, fnc_srand, 0); qse_awk_addfnc (awk, QSE_T("srand"), 5, 0, 0, 1, QSE_NULL, fnc_srand) <= -1 ||
ADDFNC (awk, QSE_T("system"), 1, 1, fnc_system, 0); qse_awk_addfnc (awk, QSE_T("system"), 6, 0, 1, 1, QSE_NULL, fnc_system) <= -1 ||
ADDFNC (awk, QSE_T("time"), 0, 0, fnc_time, 0); qse_awk_addfnc (awk, QSE_T("time"), 4, 0, 0, 0, QSE_NULL, fnc_time) <= -1 ||
ADDFNC (awk, QSE_T("setioattr"), 3, 3, fnc_setioattr, QSE_AWK_RIO); qse_awk_addfnc (awk, QSE_T("setioattr"), 9, QSE_AWK_RIO, 3, 3, QSE_NULL, fnc_setioattr) <= -1 ||
ADDFNC (awk, QSE_T("getioattr"), 2, 2, fnc_getioattr, QSE_AWK_RIO); qse_awk_addfnc (awk, QSE_T("getioattr"), 9, QSE_AWK_RIO, 2, 2, QSE_NULL, fnc_getioattr) <= -1) return -1;
return 0; return 0;
} }