changed the module loader to attempt to find '_load' and 'load_' as in addition to 'load'.

added the stat field to qse_awk_val_t.
added DLL loading for DOS32/CauseWay
deprecated PROCINFO. you can use various sys::xxxx() functions to get equivalent information.
migrated time() to sys::gettime() and added sys::settime().
This commit is contained in:
hyung-hwan 2012-11-05 05:20:12 +00:00
parent 3f456d0f94
commit 2179278c41
23 changed files with 862 additions and 573 deletions

View File

@ -1,6 +1,6 @@
pkgincludedir = $(includedir)/qse/awk pkgincludedir = $(includedir)/qse/awk
pkginclude_HEADERS = awk.h std.h mpi.h pkginclude_HEADERS = awk.h std.h
if ENABLE_CXX if ENABLE_CXX
pkginclude_HEADERS += Awk.hpp StdAwk.hpp pkginclude_HEADERS += Awk.hpp StdAwk.hpp

View File

@ -52,7 +52,7 @@ CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES = CONFIG_CLEAN_VPATH_FILES =
SOURCES = SOURCES =
DIST_SOURCES = DIST_SOURCES =
am__pkginclude_HEADERS_DIST = awk.h std.h mpi.h Awk.hpp StdAwk.hpp am__pkginclude_HEADERS_DIST = awk.h std.h Awk.hpp StdAwk.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \ am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -257,7 +257,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
pkginclude_HEADERS = awk.h std.h mpi.h $(am__append_1) pkginclude_HEADERS = awk.h std.h $(am__append_1)
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:

View File

@ -139,7 +139,6 @@ protected:
int build_argcv (Run* run); int build_argcv (Run* run);
int build_environ (Run* run); int build_environ (Run* run);
int __build_environ (Run* run, void* envptr); int __build_environ (Run* run, void* envptr);
int build_procinfo (Run* run);
// intrinsic functions // intrinsic functions
int rand (Run& run, Value& ret, const Value* args, size_t nargs, int rand (Run& run, Value& ret, const Value* args, size_t nargs,
@ -148,8 +147,6 @@ 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);
qse_cmgr_t* getcmgr (const char_t* ioname); qse_cmgr_t* getcmgr (const char_t* ioname);
@ -216,7 +213,6 @@ protected:
int gbl_argc; int gbl_argc;
int gbl_argv; int gbl_argv;
int gbl_environ; int gbl_environ;
int gbl_procinfo;
// standard input console - reuse runarg // standard input console - reuse runarg
size_t runarg_index; size_t runarg_index;

View File

@ -139,12 +139,14 @@ typedef struct qse_awk_loc_t qse_awk_loc_t;
#if QSE_SIZEOF_INT == 2 #if QSE_SIZEOF_INT == 2
# define QSE_AWK_VAL_HDR \ # define QSE_AWK_VAL_HDR \
unsigned int type: 3; \ unsigned int type: 3; \
unsigned int ref: 11; \ unsigned int ref: 10; \
unsigned int stat: 1; \
unsigned int nstr: 2 unsigned int nstr: 2
#else #else
# define QSE_AWK_VAL_HDR \ # define QSE_AWK_VAL_HDR \
unsigned int type: 3; \ unsigned int type: 3; \
unsigned int ref: 27; \ unsigned int ref: 26; \
unsigned int stat: 1; \
unsigned int nstr: 2 unsigned int nstr: 2
#endif #endif
@ -753,8 +755,8 @@ struct qse_awk_fnc_spec_t
/** parameter specification */ /** parameter specification */
struct struct
{ {
int min; /**< min. numbers of argument for a function */ qse_size_t min; /**< min. numbers of argument for a function */
int max; /**< max. numbers of argument for a function */ qse_size_t max; /**< max. numbers of argument for a function */
const qse_char_t* spec; const qse_char_t* spec;
} arg; } arg;

View File

@ -1,140 +0,0 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _QSE_AWK_MPI_H_
#define _QSE_AWK_MPI_H_
#include <qse/awk/std.h>
/** @file
* This file defines functions and data types for parallel processing.
*/
enum qse_awk_parsempi_type_t
{
QSE_AWK_PARSEMPI_NULL = QSE_AWK_PARSESTD_NULL,
QSE_AWK_PARSEMPI_FILE = QSE_AWK_PARSESTD_FILE,
QSE_AWK_PARSEMPI_STR = QSE_AWK_PARSESTD_STR
};
typedef enum qse_awk_parsempi_type_t qse_awk_parsempi_type_t;
typedef qse_awk_parsestd_t qse_awk_parsempi_t;
#ifdef __cplusplus
extern "C" {
#endif
/**
* The qse_awk_openmpi() function creates an awk object using the default
* memory manager and primitive functions. Besides, it adds a set of
* standard intrinsic functions like atan, system, etc. Use this function
* over qse_awk_open() if you don't need finer-grained customization.
*/
qse_awk_t* qse_awk_openmpi (
qse_size_t xtnsize /**< extension size in bytes */
);
/**
* The qse_awk_openmpiwithmmgr() function creates an awk object with a
* user-defined memory manager. It is equivalent to qse_awk_openmpi(),
* except that you can specify your own memory manager.
*/
qse_awk_t* qse_awk_openmpiwithmmgr (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
);
/**
* The qse_awk_getxtnmpi() gets the pointer to extension space.
* Note that you must not call qse_awk_getxtn() for an awk object
* created with qse_awk_openmpi() and qse_awk_openmpiwithmmgr().
*/
void* qse_awk_getxtnmpi (
qse_awk_t* awk
);
/**
* The qse_awk_parsempi() functions parses source script.
* The code below shows how to parse a literal string 'BEGIN { print 10; }'
* and deparses it out to a buffer 'buf'.
* @code
* int n;
* qse_awk_parsempi_t in;
* qse_awk_parsempi_t out;
*
* in.type = QSE_AWK_PARSESTD_STR;
* in.u.str.ptr = QSE_T("BEGIN { print 10; }");
* in.u.str.len = qse_strlen(in.u.str.ptr);
* out.type = QSE_AWK_PARSESTD_STR;
* n = qse_awk_parsempi (awk, &in, &out);
* if (n >= 0)
* {
* qse_printf (QSE_T("%s\n"), out.u.str.ptr);
* QSE_MMGR_FREE (out.u.str.ptr);
* }
* @endcode
*/
int qse_awk_parsempi (
qse_awk_t* awk,
qse_awk_parsempi_t* in,
qse_awk_parsempi_t* out
);
/**
* The qse_awk_rtx_openmpi() function creates a standard runtime context.
* The caller should keep the contents of @a icf and @a ocf valid throughout
* the lifetime of the runtime context created. The @a cmgr is set to the
* streams created with @a icf and @a ocf if it is not #QSE_NULL.
*/
qse_awk_rtx_t* qse_awk_rtx_openmpi (
qse_awk_t* awk,
qse_size_t xtn,
const qse_char_t* id,
const qse_char_t*const icf[],
const qse_char_t*const ocf[],
qse_cmgr_t* cmgr
);
/**
* The qse_awk_rtx_getxtnmpi() function gets the pointer to extension space.
*/
void* qse_awk_rtx_getxtnmpi (
qse_awk_rtx_t* rtx
);
/**
* The qse_awk_rtx_getcmgrmpi() function gets the current character
* manager associated with a particular I/O target indicated by the name
* @a ioname if #QSE_CHAR_IS_WCHAR is defined. It always returns #QSE_NULL
* if #QSE_CHAR_IS_MCHAR is defined.
*/
qse_cmgr_t* qse_awk_rtx_getcmgrmpi (
qse_awk_rtx_t* rtx,
const qse_char_t* ioname
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -208,7 +208,7 @@ qse_mchar_t* qse_wcstombsdupwithcmgr (
qse_cmgr_t* cmgr qse_cmgr_t* cmgr
); );
qse_mchar_t* qse_wcntombsdupwithcmgr ( qse_mchar_t* qse_wcsntombsdupwithcmgr (
const qse_wchar_t* wcs, const qse_wchar_t* wcs,
qse_size_t wcslen, qse_size_t wcslen,
qse_size_t* mbslen, qse_size_t* mbslen,

View File

@ -8,9 +8,9 @@ AM_CPPFLAGS = \
if WIN32 if WIN32
# you must adjust the value of DEFAULT_MODPOSTFIX according to # you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../mod/awk/Makefile.am # -version-info in ../../mod/awk/Makefile.am
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\" AM_CPPFLAGS += -DQSE_AWK_DEFAULT_MODPREFIX=\"libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"-1\"
else else
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\" AM_CPPFLAGS += -DQSE_AWK_DEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"\"
endif endif
lib_LTLIBRARIES = libqseawk.la lib_LTLIBRARIES = libqseawk.la

View File

@ -37,8 +37,8 @@ host_triplet = @host@
# you must adjust the value of DEFAULT_MODPOSTFIX according to # you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../mod/awk/Makefile.am # -version-info in ../../mod/awk/Makefile.am
@WIN32_TRUE@am__append_1 = -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\" @WIN32_TRUE@am__append_1 = -DQSE_AWK_DEFAULT_MODPREFIX=\"libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"-1\"
@WIN32_FALSE@am__append_2 = -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\" @WIN32_FALSE@am__append_2 = -DQSE_AWK_DEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"\"
@ENABLE_CXX_TRUE@am__append_3 = libqseawkxx.la @ENABLE_CXX_TRUE@am__append_3 = libqseawkxx.la
subdir = lib/awk subdir = lib/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in

View File

@ -41,11 +41,12 @@
# define USE_LTDL # define USE_LTDL
# endif # endif
#elif defined(__OS2__) #elif defined(__OS2__)
# define INCL_DOSMODULEMGR
# define INCL_DOSPROCESS # define INCL_DOSPROCESS
# define INCL_DOSERRORS # define INCL_DOSERRORS
# include <os2.h> # include <os2.h>
#elif defined(__DOS__) #elif defined(__DOS__)
/* anything ? */ # include <cwdllfnc.h>
#else #else
# include <unistd.h> # include <unistd.h>
# include <ltdl.h> # include <ltdl.h>
@ -133,11 +134,9 @@ int StdAwk::open ()
this->gbl_argc = addGlobal (QSE_T("ARGC")); this->gbl_argc = addGlobal (QSE_T("ARGC"));
this->gbl_argv = addGlobal (QSE_T("ARGV")); this->gbl_argv = addGlobal (QSE_T("ARGV"));
this->gbl_environ = addGlobal (QSE_T("ENVIRON")); this->gbl_environ = addGlobal (QSE_T("ENVIRON"));
this->gbl_procinfo = addGlobal (QSE_T("PROCINFO"));
if (this->gbl_argc <= -1 || if (this->gbl_argc <= -1 ||
this->gbl_argv <= -1 || this->gbl_argv <= -1 ||
this->gbl_environ <= -1 || this->gbl_environ <= -1)
this->gbl_procinfo <= -1)
{ {
goto oops; goto oops;
} }
@ -145,7 +144,6 @@ int StdAwk::open ()
if (addFunction (QSE_T("rand"), 0, 0, (FunctionHandler)&StdAwk::rand, 0) <= -1 || if (addFunction (QSE_T("rand"), 0, 0, (FunctionHandler)&StdAwk::rand, 0) <= -1 ||
addFunction (QSE_T("srand"), 0, 1, (FunctionHandler)&StdAwk::srand, 0) <= -1 || addFunction (QSE_T("srand"), 0, 1, (FunctionHandler)&StdAwk::srand, 0) <= -1 ||
addFunction (QSE_T("system"), 1, 1, (FunctionHandler)&StdAwk::system, 0) <= -1 || addFunction (QSE_T("system"), 1, 1, (FunctionHandler)&StdAwk::system, 0) <= -1 ||
addFunction (QSE_T("time"), 0, 0, (FunctionHandler)&StdAwk::time, 0) <= -1 ||
addFunction (QSE_T("setioattr"), 3, 3, (FunctionHandler)&StdAwk::setioattr, QSE_AWK_RIO) <= -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) addFunction (QSE_T("getioattr"), 2, 2, (FunctionHandler)&StdAwk::getioattr, QSE_AWK_RIO) <= -1)
{ {
@ -342,81 +340,10 @@ int StdAwk::build_environ (Run* run)
return xret; return xret;
} }
int StdAwk::build_procinfo (Run* run)
{
static qse_cstr_t names[] =
{
{ QSE_T("pid"), 3 },
{ QSE_T("ppid"), 5 },
{ QSE_T("pgrp"), 4 },
{ QSE_T("uid"), 3 },
{ QSE_T("gid"), 3 },
{ QSE_T("euid"), 4 },
{ QSE_T("egid"), 4 },
{ QSE_T("tid"), 3 }
};
#if defined(__OS2__)
PTIB tib;
PPIB pib;
if (DosGetInfoBlocks (&tib, &pib) != NO_ERROR)
{
tib = QSE_NULL;
pib = QSE_NULL;
}
#endif
Value v_procinfo (run);
for (size_t i = 0; i < QSE_COUNTOF(names); i++)
{
qse_long_t val = -99931; /* -99931 randomly chosen */
#if defined(_WIN32)
switch (i)
{
case 0: val = GetCurrentProcessId(); break;
case 7: val = GetCurrentThreadId(); break;
}
#elif defined(__OS2__)
switch (i)
{
case 0: if (pib) val = pib->pib_ulpid; break;
case 7: if (tib && tib->tib_ptib2) val = tib->tib_ptib2->tib2_ultid; break;
}
#elif defined(__DOS__)
/* TODO: */
#else
switch (i)
{
case 0: val = getpid(); break;
case 1: val = getppid(); break;
case 2: val = getpgrp(); break;
case 3: val = getuid(); break;
case 4: val = getgid(); break;
case 5: val = geteuid(); break;
case 6: val = getegid(); break;
#if defined(HAVE_GETTID)
case 7: val = gettid(); break;
#endif
}
#endif
if (val == -99931) continue;
if (v_procinfo.setIndexedInt (
Value::Index (names[i].ptr, names[i].len), val) <= -1) return -1;
}
return run->setGlobal (this->gbl_procinfo, v_procinfo);
}
int StdAwk::make_additional_globals (Run* run) int StdAwk::make_additional_globals (Run* run)
{ {
if (build_argcv (run) <= -1 || if (build_argcv (run) <= -1 ||
build_environ (run) <= -1 || build_environ (run) <= -1) return -1;
build_procinfo (run) <= -1) return -1;
return 0; return 0;
} }
@ -478,16 +405,6 @@ int StdAwk::system (Run& run, Value& ret, const Value* args, size_t nargs,
#endif #endif
} }
int StdAwk::time (Run& run, Value& ret, const Value* args, size_t nargs,
const char_t* name, size_t len)
{
qse_ntime_t now;
if (qse_gettime (&now) <= -1) now = 0;
return ret.setInt (now);
}
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);
@ -1429,7 +1346,7 @@ void* StdAwk::modopen (const mod_spec_t* spec)
#elif defined(_WIN32) #elif defined(_WIN32)
HMODULE h; HMODULE h;
qse_char_t* path; qse_char_t* modpath;
const qse_char_t* tmp[4]; const qse_char_t* tmp[4];
int count; int count;
@ -1439,16 +1356,16 @@ void* StdAwk::modopen (const mod_spec_t* spec)
if (spec->postfix) tmp[count++] = spec->postfix; if (spec->postfix) tmp[count++] = spec->postfix;
tmp[count] = QSE_NULL; tmp[count] = QSE_NULL;
path = qse_stradup (tmp, QSE_NULL, this->getMmgr()); modpath = qse_stradup (tmp, QSE_NULL, this->getMmgr());
if (!path) if (!modpath)
{ {
this->setError (QSE_AWK_ENOMEM); this->setError (QSE_AWK_ENOMEM);
return QSE_NULL; return QSE_NULL;
} }
h = LoadLibrary (path); h = LoadLibrary (modpath);
QSE_MMGR_FREE (awk->mmgr, path); QSE_MMGR_FREE (awk->mmgr, modpath);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*)); QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h; return h;
@ -1487,9 +1404,35 @@ void* StdAwk::modopen (const mod_spec_t* spec)
#elif defined(__DOS__) #elif defined(__DOS__)
/*TODO: implemente this */ void* h;
this->setError (QSE_AWK_ENOIMPL); qse_mchar_t* modpath;
return QSE_NULL; const qse_char_t* tmp[4];
int count;
count = 0;
if (spec->prefix) tmp[count++] = spec->prefix;
tmp[count++] = spec->name;
if (spec->postfix) tmp[count++] = spec->postfix;
tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr);
#else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr);
#endif
if (!modpath)
{
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL;
}
h = LoadModule (modpath);
QSE_MMGR_FREE (awk->mmgr, modpath);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h;
#else #else
this->setError (QSE_AWK_ENOIMPL); this->setError (QSE_AWK_ENOIMPL);
@ -1507,7 +1450,7 @@ void StdAwk::modclose (void* handle)
#elif defined(__OS2__) #elif defined(__OS2__)
DosFreeModule ((HMODULE)handle); DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__) #elif defined(__DOS__)
/*TODO: implemente this */ FreeModule (handle);
#else #else
/* nothing to do */ /* nothing to do */
#endif #endif
@ -1536,8 +1479,7 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name)
#elif defined(__OS2__) #elif defined(__OS2__)
if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL; if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL;
#elif defined(__DOS__) #elif defined(__DOS__)
/*TODO: implemente this */ s = GetProcAddress (handle, mname);
s = QSE_NULL;
#else #else
s = QSE_NULL; s = QSE_NULL;
#endif #endif

View File

@ -131,7 +131,7 @@ void* qse_awk_addfnc (qse_awk_t* awk, const qse_cstr_t* name, const qse_awk_fnc_
qse_char_t* tmp; qse_char_t* tmp;
tmp = (qse_char_t*)(fnc + 1); tmp = (qse_char_t*)(fnc + 1);
fnc->name.len = qse_strxncpy (tmp, name->len+1, name, name->len); fnc->name.len = qse_strxncpy (tmp, name->len+1, name->ptr, name->len);
fnc->name.ptr = tmp; fnc->name.ptr = tmp;
fnc->spec = *spec; fnc->spec = *spec;

View File

@ -6437,14 +6437,14 @@ static qse_awk_mod_t* query_module (
if (awk->opt.mod[0].len > 0) if (awk->opt.mod[0].len > 0)
spec.prefix = awk->opt.mod[0].ptr; spec.prefix = awk->opt.mod[0].ptr;
#if defined(DEFAULT_MODPREFIX) #if defined(QSE_AWK_DEFAULT_MODPREFIX)
else spec.prefix = QSE_T(DEFAULT_MODPREFIX); else spec.prefix = QSE_T(QSE_AWK_DEFAULT_MODPREFIX);
#endif #endif
if (awk->opt.mod[1].len > 0) if (awk->opt.mod[1].len > 0)
spec.postfix = awk->opt.mod[1].ptr; spec.postfix = awk->opt.mod[1].ptr;
#if defined(DEFAULT_MODPOSTFIX) #if defined(QSE_AWK_DEFAULT_MODPOSTFIX)
else spec.postfix = QSE_T(DEFAULT_MODPOSTFIX); else spec.postfix = QSE_T(QSE_AWK_DEFAULT_MODPOSTFIX);
#endif #endif
QSE_MEMSET (&md, 0, QSE_SIZEOF(md)); QSE_MEMSET (&md, 0, QSE_SIZEOF(md));
@ -6466,13 +6466,20 @@ static qse_awk_mod_t* query_module (
load = awk->prm.modsym (awk, md.handle, QSE_T("load")); load = awk->prm.modsym (awk, md.handle, QSE_T("load"));
if (!load) if (!load)
{ {
load = awk->prm.modsym (awk, md.handle, QSE_T("_load"));
if (!load)
{
load = awk->prm.modsym (awk, md.handle, QSE_T("load_"));
if (!load)
{
ea.ptr = QSE_T("load");
ea.len = 4;
qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL);
ea.ptr = QSE_T("load"); awk->prm.modclose (awk, md.handle);
ea.len = 4; return QSE_NULL;
qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL); }
}
awk->prm.modclose (awk, md.handle);
return QSE_NULL;
} }
/* i copy-insert 'md' into the table before calling 'load'. /* i copy-insert 'md' into the table before calling 'load'.

View File

@ -5771,6 +5771,7 @@ static qse_awk_val_t* __eval_call (
#ifdef DEBUG_RUN #ifdef DEBUG_RUN
qse_dprintf (QSE_T("block run complete nargs = %d\n"), (int)nargs); qse_dprintf (QSE_T("block run complete nargs = %d\n"), (int)nargs);
#endif #endif
for (i = 0; i < nargs; i++) for (i = 0; i < nargs; i++)
{ {
qse_awk_rtx_refdownval (run, STACK_ARG(run,i)); qse_awk_rtx_refdownval (run, STACK_ARG(run,i));

View File

@ -50,7 +50,7 @@
# define INCL_DOSERRORS # define INCL_DOSERRORS
# include <os2.h> # include <os2.h>
#elif defined(__DOS__) #elif defined(__DOS__)
/* anything ? */ # include <cwdllfnc.h>
#else #else
# include <unistd.h> # include <unistd.h>
# include <ltdl.h> # include <ltdl.h>
@ -115,7 +115,6 @@ typedef struct xtn_t
int gbl_argc; int gbl_argc;
int gbl_argv; int gbl_argv;
int gbl_environ; int gbl_environ;
int gbl_procinfo;
qse_awk_ecb_t ecb; qse_awk_ecb_t ecb;
} xtn_t; } xtn_t;
@ -349,7 +348,7 @@ static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
#elif defined(_WIN32) #elif defined(_WIN32)
HMODULE h; HMODULE h;
qse_char_t* path; qse_char_t* modpath;
const qse_char_t* tmp[4]; const qse_char_t* tmp[4];
int count; int count;
@ -359,16 +358,16 @@ static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
if (spec->postfix) tmp[count++] = spec->postfix; if (spec->postfix) tmp[count++] = spec->postfix;
tmp[count] = QSE_NULL; tmp[count] = QSE_NULL;
path = qse_stradup (tmp, QSE_NULL, awk->mmgr); modpath = qse_stradup (tmp, QSE_NULL, awk->mmgr);
if (!path) if (!modpath)
{ {
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
h = LoadLibrary (path); h = LoadLibrary (modpath);
QSE_MMGR_FREE (awk->mmgr, path); QSE_MMGR_FREE (awk->mmgr, modpath);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*)); QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h; return h;
@ -407,9 +406,34 @@ static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
#elif defined(__DOS__) #elif defined(__DOS__)
/*TODO: implemente this */ void* h;
qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL); qse_mchar_t* modpath;
return -1; const qse_char_t* tmp[4];
int count;
count = 0;
if (spec->prefix) tmp[count++] = spec->prefix;
tmp[count++] = spec->name;
if (spec->postfix) tmp[count++] = spec->postfix;
tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr);
#else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr);
#endif
if (!modpath)
{
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL;
}
h = LoadModule (modpath);
QSE_MMGR_FREE (awk->mmgr, modpath);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h;
#else #else
qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL); qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL);
@ -426,7 +450,7 @@ static void custom_awk_modclose (qse_awk_t* awk, void* handle)
#elif defined(__OS2__) #elif defined(__OS2__)
DosFreeModule ((HMODULE)handle); DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__) #elif defined(__DOS__)
/*TODO: implemente this */ FreeModule (handle);
#else #else
/* nothing to do */ /* nothing to do */
#endif #endif
@ -458,8 +482,8 @@ static void* custom_awk_modsym (qse_awk_t* awk, void* handle, const qse_char_t*
if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL; if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL;
#elif defined(__DOS__) #elif defined(__DOS__)
/*TODO: implemente this */ s = GetProcAddress (handle, mname);
s = QSE_NULL;
#else #else
s = QSE_NULL; s = QSE_NULL;
#endif #endif
@ -1940,122 +1964,12 @@ static int build_environ (qse_awk_rtx_t* rtx, int gbl_id)
return xret; return xret;
} }
static int build_procinfo (qse_awk_rtx_t* rtx, int gbl_id)
{
qse_awk_val_t* v_info;
qse_awk_val_t* v_tmp;
qse_size_t i;
#if defined(__OS2__)
PTIB tib;
PPIB pib;
#endif
static qse_cstr_t names[] =
{
{ QSE_T("pid"), 3 },
{ QSE_T("ppid"), 5 },
{ QSE_T("pgrp"), 4 },
{ QSE_T("uid"), 3 },
{ QSE_T("gid"), 3 },
{ QSE_T("euid"), 4 },
{ QSE_T("egid"), 4 },
{ QSE_T("tid"), 3 }
};
v_info = qse_awk_rtx_makemapval (rtx);
if (v_info == QSE_NULL) return -1;
qse_awk_rtx_refupval (rtx, v_info);
#if defined(__OS2__)
if (DosGetInfoBlocks (&tib, &pib) != NO_ERROR)
{
tib = QSE_NULL;
pib = QSE_NULL;
}
#endif
for (i = 0; i < QSE_COUNTOF(names); i++)
{
qse_long_t val = -99931; /* -99931 randomly chosen */
#if defined(_WIN32)
switch (i)
{
case 0: val = GetCurrentProcessId(); break;
case 7: val = GetCurrentThreadId(); break;
}
#elif defined(__OS2__)
switch (i)
{
case 0: if (pib) val = pib->pib_ulpid; break;
case 7: if (tib && tib->tib_ptib2) val = tib->tib_ptib2->tib2_ultid; break;
}
#elif defined(__DOS__)
/* TODO: */
#else
switch (i)
{
case 0: val = getpid(); break;
case 1: val = getppid(); break;
case 2: val = getpgrp(); break;
case 3: val = getuid(); break;
case 4: val = getgid(); break;
case 5: val = geteuid(); break;
case 6: val = getegid(); break;
#if defined(HAVE_GETTID)
case 7: val = gettid(); break;
#endif
}
#endif
if (val == -99931) continue;
v_tmp = qse_awk_rtx_makeintval (rtx, val);
if (v_tmp == QSE_NULL)
{
qse_awk_rtx_refdownval (rtx, v_info);
return -1;
}
/* increment reference count of v_tmp in advance as if
* it has successfully been assigned into ARGV. */
qse_awk_rtx_refupval (rtx, v_tmp);
if (qse_htb_upsert (
((qse_awk_val_map_t*)v_info)->map,
(void*)names[i].ptr, names[i].len, v_tmp, 0) == QSE_NULL)
{
/* if the assignment operation fails, decrements
* the reference of v_tmp to free it */
qse_awk_rtx_refdownval (rtx, v_tmp);
/* the values previously assigned into the
* map will be freeed when v_env is freed */
qse_awk_rtx_refdownval (rtx, v_info);
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
return -1;
}
}
if (qse_awk_rtx_setgbl (rtx, gbl_id, v_info) == -1)
{
qse_awk_rtx_refdownval (rtx, v_info);
return -1;
}
qse_awk_rtx_refdownval (rtx, v_info);
return 0;
}
static int make_additional_globals ( static int make_additional_globals (
qse_awk_rtx_t* rtx, xtn_t* xtn, qse_awk_rtx_t* rtx, xtn_t* xtn,
const qse_char_t* id, const qse_char_t*const icf[]) const qse_char_t* id, const qse_char_t*const icf[])
{ {
if (build_argcv (rtx, xtn->gbl_argc, xtn->gbl_argv, id, icf) <= -1 || if (build_argcv (rtx, xtn->gbl_argc, xtn->gbl_argv, id, icf) <= -1 ||
build_environ (rtx, xtn->gbl_environ) <= -1 || build_environ (rtx, xtn->gbl_environ) <= -1) return -1;
build_procinfo (rtx, xtn->gbl_procinfo) <= -1) return -1;
return 0; return 0;
} }
@ -2282,20 +2196,6 @@ skip_system:
return 0; return 0;
} }
static int fnc_time (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_awk_val_t* r;
qse_ntime_t now;
if (qse_gettime (&now) <= -1) now = 0;
r = qse_awk_rtx_makeintval (rtx, now);
if (r == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, r);
return 0;
}
static int timeout_code (const qse_char_t* name) static int timeout_code (const qse_char_t* name)
{ {
if (qse_strcasecmp (name, QSE_T("rtimeout")) == 0) return 0; if (qse_strcasecmp (name, QSE_T("rtimeout")) == 0) return 0;
@ -2600,11 +2500,11 @@ static int add_globals (qse_awk_t* awk)
xtn->gbl_argc = add_global (awk, QSE_T("ARGC"), 4); xtn->gbl_argc = add_global (awk, QSE_T("ARGC"), 4);
xtn->gbl_argv = add_global (awk, QSE_T("ARGV"), 4); xtn->gbl_argv = add_global (awk, QSE_T("ARGV"), 4);
xtn->gbl_environ = add_global (awk, QSE_T("ENVIRON"), 7);
xtn->gbl_procinfo = add_global (awk, QSE_T("PROCINFO"), 8);
if (xtn->gbl_argc <= -1 || xtn->gbl_argv <= -1 || if (xtn->gbl_argc <= -1 || xtn->gbl_argv <= -1) return -1;
xtn->gbl_environ <= -1 || xtn->gbl_procinfo <= -1) return -1;
xtn->gbl_environ = add_global (awk, QSE_T("ENVIRON"), 7);
if (xtn->gbl_environ <= -1) return -1;
return 0; return 0;
} }
@ -2621,7 +2521,6 @@ static struct fnctab_t fnctab[] =
{ {QSE_T("rand"), 4}, { {0, 0, QSE_NULL}, fnc_rand, 0 } }, { {QSE_T("rand"), 4}, { {0, 0, QSE_NULL}, fnc_rand, 0 } },
{ {QSE_T("srand"), 5}, { {0, 1, QSE_NULL}, fnc_srand, 0 } }, { {QSE_T("srand"), 5}, { {0, 1, QSE_NULL}, fnc_srand, 0 } },
{ {QSE_T("system"), 6}, { {1, 1, QSE_NULL}, fnc_system , 0 } }, { {QSE_T("system"), 6}, { {1, 1, QSE_NULL}, fnc_system , 0 } },
{ {QSE_T("time"), 4}, { {0, 0, QSE_NULL}, fnc_time, 0 } },
{ {QSE_T("setioattr"), 9}, { {3, 3, QSE_NULL}, fnc_setioattr, QSE_AWK_RIO } }, { {QSE_T("setioattr"), 9}, { {3, 3, QSE_NULL}, fnc_setioattr, QSE_AWK_RIO } },
{ {QSE_T("getioattr"), 9}, { {2, 2, QSE_NULL}, fnc_getioattr, QSE_AWK_RIO } } { {QSE_T("getioattr"), 9}, { {2, 2, QSE_NULL}, fnc_getioattr, QSE_AWK_RIO } }
}; };

View File

@ -27,36 +27,36 @@
#define CHUNKSIZE QSE_AWK_VAL_CHUNK_SIZE #define CHUNKSIZE QSE_AWK_VAL_CHUNK_SIZE
static qse_awk_val_nil_t awk_nil = { QSE_AWK_VAL_NIL, 0, 0 }; static qse_awk_val_nil_t awk_nil = { QSE_AWK_VAL_NIL, 0, 1, 0 };
static qse_awk_val_str_t awk_zls = { QSE_AWK_VAL_STR, 0, 0, { QSE_T(""), 0 } }; static qse_awk_val_str_t awk_zls = { QSE_AWK_VAL_STR, 0, 1, 0, { QSE_T(""), 0 } };
qse_awk_val_t* qse_awk_val_nil = (qse_awk_val_t*)&awk_nil; qse_awk_val_t* qse_awk_val_nil = (qse_awk_val_t*)&awk_nil;
qse_awk_val_t* qse_awk_val_zls = (qse_awk_val_t*)&awk_zls; qse_awk_val_t* qse_awk_val_zls = (qse_awk_val_t*)&awk_zls;
static qse_awk_val_int_t awk_int[] = static qse_awk_val_int_t awk_int[] =
{ {
{ QSE_AWK_VAL_INT, 0, 0, -1, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, -1, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 0, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 0, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 1, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 1, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 2, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 2, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 3, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 3, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 4, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 4, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 5, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 5, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 6, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 6, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 7, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 7, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 8, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 8, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 9, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 9, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 10, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 10, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 11, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 11, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 12, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 12, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 13, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 13, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 14, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 14, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 15, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 15, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 16, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 16, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 17, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 17, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 18, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 18, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 19, QSE_NULL }, { QSE_AWK_VAL_INT, 0, 1, 0, 19, QSE_NULL },
{ QSE_AWK_VAL_INT, 0, 0, 20, QSE_NULL } { QSE_AWK_VAL_INT, 0, 1, 0, 20, QSE_NULL }
}; };
qse_awk_val_t* qse_awk_val_negone = (qse_awk_val_t*)&awk_int[0]; qse_awk_val_t* qse_awk_val_negone = (qse_awk_val_t*)&awk_int[0];
@ -123,6 +123,7 @@ qse_awk_val_t* qse_awk_rtx_makeintval (qse_awk_rtx_t* rtx, qse_long_t v)
val->type = QSE_AWK_VAL_INT; val->type = QSE_AWK_VAL_INT;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->val = v; val->val = v;
val->nde = QSE_NULL; val->nde = QSE_NULL;
@ -178,6 +179,7 @@ qse_awk_val_t* qse_awk_rtx_makefltval (qse_awk_rtx_t* rtx, qse_flt_t v)
val->type = QSE_AWK_VAL_FLT; val->type = QSE_AWK_VAL_FLT;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->val = v; val->val = v;
val->nde = QSE_NULL; val->nde = QSE_NULL;
@ -322,6 +324,7 @@ init:
#endif #endif
val->type = QSE_AWK_VAL_STR; val->type = QSE_AWK_VAL_STR;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->val.len = str->len; val->val.len = str->len;
val->val.ptr = (qse_char_t*)(val + 1); val->val.ptr = (qse_char_t*)(val + 1);
@ -380,6 +383,7 @@ init:
#endif #endif
val->type = QSE_AWK_VAL_STR; val->type = QSE_AWK_VAL_STR;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->val.len = len1 + len2; val->val.len = len1 + len2;
val->val.ptr = (qse_char_t*)(val + 1); val->val.ptr = (qse_char_t*)(val + 1);
@ -436,6 +440,7 @@ qse_awk_val_t* qse_awk_rtx_makerexval (
val->type = QSE_AWK_VAL_REX; val->type = QSE_AWK_VAL_REX;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->str.len = str->len; val->str.len = str->len;
@ -506,6 +511,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
val->type = QSE_AWK_VAL_MAP; val->type = QSE_AWK_VAL_MAP;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->map = qse_htb_open ( val->map = qse_htb_open (
run, 256, 70, free_mapval, same_mapval, run->awk->mmgr); run, 256, 70, free_mapval, same_mapval, run->awk->mmgr);
@ -530,6 +536,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
val->type = QSE_AWK_VAL_MAP; val->type = QSE_AWK_VAL_MAP;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->map = (qse_htb_t*)(val + 1); val->map = (qse_htb_t*)(val + 1);
@ -715,6 +722,7 @@ qse_awk_val_t* qse_awk_rtx_makerefval (
val->type = QSE_AWK_VAL_REF; val->type = QSE_AWK_VAL_REF;
val->ref = 0; val->ref = 0;
val->stat = 0;
val->nstr = 0; val->nstr = 0;
val->id = id; val->id = id;
val->adr = adr; val->adr = adr;
@ -722,6 +730,15 @@ qse_awk_val_t* qse_awk_rtx_makerefval (
return (qse_awk_val_t*)val; return (qse_awk_val_t*)val;
} }
/*
* if shared objects link a static library, statically defined objects
* in the static library will be instatiated in the multiple shared objects.
*
* so equality check with a value pointer doesn't work
* if the code crosses the library boundaries. instead, i decided to
* add a field to indicate if a value is static.
*
#define IS_STATICVAL(val) \ #define IS_STATICVAL(val) \
((val) == QSE_NULL || \ ((val) == QSE_NULL || \
(val) == qse_awk_val_nil || \ (val) == qse_awk_val_nil || \
@ -730,6 +747,8 @@ qse_awk_val_t* qse_awk_rtx_makerefval (
(val) == qse_awk_val_one || \ (val) == qse_awk_val_one || \
((val) >= (qse_awk_val_t*)&awk_int[0] && \ ((val) >= (qse_awk_val_t*)&awk_int[0] && \
(val) <= (qse_awk_val_t*)&awk_int[QSE_COUNTOF(awk_int)-1])) (val) <= (qse_awk_val_t*)&awk_int[QSE_COUNTOF(awk_int)-1]))
*/
#define IS_STATICVAL(val) ((val)->stat)
int qse_awk_rtx_isstaticval (qse_awk_rtx_t* rtx, qse_awk_val_t* val) int qse_awk_rtx_isstaticval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
{ {
@ -853,8 +872,8 @@ void qse_awk_rtx_refdownval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
#endif #endif
QSE_ASSERTX (val->ref > 0, QSE_ASSERTX (val->ref > 0,
"the reference count of a value should be greater than zero for it" "the reference count of a value should be greater than zero for it "
" to be decremented. check the source code for any bugs"); "to be decremented. check the source code for any bugs");
val->ref--; val->ref--;
if (val->ref <= 0) if (val->ref <= 0)

View File

@ -153,12 +153,12 @@ struct inttab_t
static fnctab_t fnctab[] = static fnctab_t fnctab[] =
{ {
{ QSE_T("assign"), { { 1, 1, QSE_NULL }, fnc_assign }, 0 }, { QSE_T("assign"), { { 1, 1, QSE_NULL }, fnc_assign, 0 } },
{ QSE_T("barrier"), { { 0, 0, QSE_NULL }, fnc_barrier }, 0 }, { QSE_T("barrier"), { { 0, 0, QSE_NULL }, fnc_barrier, 0 } },
{ QSE_T("hash"), { { 1, 1, QSE_NULL }, fnc_hash }, 0 }, { QSE_T("hash"), { { 1, 1, QSE_NULL }, fnc_hash, 0 } },
{ QSE_T("rank"), { { 0, 0, QSE_NULL }, fnc_rank }, 0 }, { QSE_T("rank"), { { 0, 0, QSE_NULL }, fnc_rank, 0 } },
{ QSE_T("reduce"), { { 2, 2, QSE_NULL }, fnc_reduce }, 0 }, { QSE_T("reduce"), { { 2, 2, QSE_NULL }, fnc_reduce, 0 } },
{ QSE_T("size"), { { 0, 0, QSE_NULL }, fnc_size }, 0 } { QSE_T("size"), { { 0, 0, QSE_NULL }, fnc_size, 0 } }
}; };
static inttab_t inttab[] = static inttab_t inttab[] =

View File

@ -1,5 +1,6 @@
#include <qse/awk/awk.h> #include <qse/awk/awk.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/time.h>
#if defined(_WIN32) #if defined(_WIN32)
# include <windows.h> # include <windows.h>
@ -12,12 +13,15 @@
#elif defined(__DOS__) #elif defined(__DOS__)
# include <dos.h> # include <dos.h>
#else #else
# include <unistd.h> # include "../../lib/cmn/syscall.h"
# include <signal.h> # if defined(HAVE_SYS_SYSCALL_H)
# include <sys/wait.h> # include <sys/syscall.h>
# include <errno.h> # endif
#endif #endif
#include <stdlib.h> /* getenv */
static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t pid; qse_long_t pid;
@ -46,36 +50,6 @@ static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
return 0; return 0;
} }
static int fnc_getpid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t pid;
qse_awk_val_t* retv;
#if defined(_WIN32)
pid = GetCurrentProcessId();
#elif defined(__OS2__)
PTIB tib;
PPIB pib;
pid = (DosGetInfoBlocks (&tib, &pib) == NO_ERROR)?
pib->pib_ulpid: -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
pid = -1;
#else
pid = getpid ();
#endif
retv = qse_awk_rtx_makeintval (rtx, pid);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t pid; qse_long_t pid;
@ -108,6 +82,40 @@ static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
return 0; return 0;
} }
static int fnc_kill (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t pid, sig;
qse_awk_val_t* retv;
int rx;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &pid) <= -1 ||
qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 1), &sig) <= -1)
{
rx = -1;
}
else
{
#if defined(_WIN32)
/* TOOD: implement this*/
rx = -1;
#elif defined(__OS2__)
/* TOOD: implement this*/
rx = -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
rx = -1;
#else
rx = kill (pid, sig);
#endif
}
retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_getpgrp (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_getpgrp (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t pid; qse_long_t pid;
@ -136,6 +144,71 @@ static int fnc_getpgrp (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
return 0; return 0;
} }
static int fnc_getpid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t pid;
qse_awk_val_t* retv;
#if defined(_WIN32)
pid = GetCurrentProcessId();
#elif defined(__OS2__)
PTIB tib;
PPIB pib;
pid = (DosGetInfoBlocks (&tib, &pib) == NO_ERROR)?
pib->pib_ulpid: -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
pid = -1;
#else
pid = getpid ();
#endif
retv = qse_awk_rtx_makeintval (rtx, pid);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_gettid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t pid;
qse_awk_val_t* retv;
#if defined(_WIN32)
pid = GetCurrentThreadId();
#elif defined(__OS2__)
PTIB tib;
PPIB pib;
pid = (DosGetInfoBlocks (&tib, &pib) == NO_ERROR && tib->tib_ptib2)?
tib->tib_ptib2->tib2_ultid: -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
pid = -1;
#else
#if defined(SYS_gettid) && defined(QSE_SYSCALL0)
QSE_SYSCALL0 (pid, SYS_gettid);
#elif defined(SYS_gettid)
pid = syscall (SYS_gettid);
#else
pid = -1;
#endif
#endif
retv = qse_awk_rtx_makeintval (rtx, pid);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_getppid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_getppid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
@ -221,34 +294,56 @@ static int fnc_getgid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
return 0; return 0;
} }
static int fnc_kill (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_geteuid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_long_t pid, sig; qse_long_t uid;
qse_awk_val_t* retv; qse_awk_val_t* retv;
int rx;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &pid) <= -1 ||
qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 1), &sig) <= -1)
{
rx = -1;
}
else
{
#if defined(_WIN32) #if defined(_WIN32)
/* TOOD: implement this*/ /* TOOD: implement this*/
rx = -1; uid = -1;
#elif defined(__OS2__)
/* TOOD: implement this*/
rx = -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
rx = -1;
#else
rx = kill (pid, sig);
#endif
}
retv = qse_awk_rtx_makeintval (rtx, rx); #elif defined(__OS2__)
/* TOOD: implement this*/
uid = -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
uid = -1;
#else
uid = geteuid ();
#endif
retv = qse_awk_rtx_makeintval (rtx, uid);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_getegid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_long_t gid;
qse_awk_val_t* retv;
#if defined(_WIN32)
/* TOOD: implement this*/
gid = -1;
#elif defined(__OS2__)
/* TOOD: implement this*/
gid = -1;
#elif defined(__DOS__)
/* TOOD: implement this*/
gid = -1;
#else
gid = getegid ();
#endif
retv = qse_awk_rtx_makeintval (rtx, gid);
if (retv == QSE_NULL) return -1; if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
@ -285,6 +380,64 @@ static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
return 0; return 0;
} }
static int fnc_gettime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_awk_val_t* retv;
qse_ntime_t now;
if (qse_gettime (&now) <= -1) now = 0;
retv = qse_awk_rtx_makeintval (rtx, now);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_settime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_awk_val_t* retv;
qse_long_t now;
int rx;
if (qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &now) <= -1 ||
qse_settime (now) <= -1) rx = -1;
else rx = 0;
retv = qse_awk_rtx_makeintval (rtx, rx);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_getenv (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
qse_mchar_t* var;
qse_size_t len;
qse_awk_val_t* retv;
var = qse_awk_rtx_valtombsdup (
rtx, qse_awk_rtx_getarg (rtx, 0), &len);
if (var)
{
qse_mchar_t* val;
val = getenv (var);
if (val)
{
retv = qse_awk_rtx_makestrvalwithmbs (rtx, val);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
}
qse_awk_rtx_freemem (rtx, var);
}
return 0;
}
typedef struct fnctab_t fnctab_t; typedef struct fnctab_t fnctab_t;
struct fnctab_t struct fnctab_t
{ {
@ -302,12 +455,18 @@ struct inttab_t
static fnctab_t fnctab[] = static fnctab_t fnctab[] =
{ {
{ QSE_T("fork"), { { 0, 0, QSE_NULL }, fnc_fork, 0 } }, { QSE_T("fork"), { { 0, 0, QSE_NULL }, fnc_fork, 0 } },
{ QSE_T("getegid"), { { 0, 0, QSE_NULL }, fnc_getegid, 0 } },
{ QSE_T("getenv"), { { 1, 1, QSE_NULL }, fnc_getenv, 0 } },
{ QSE_T("geteuid"), { { 0, 0, QSE_NULL }, fnc_geteuid, 0 } },
{ QSE_T("getgid"), { { 0, 0, QSE_NULL }, fnc_getgid, 0 } }, { QSE_T("getgid"), { { 0, 0, QSE_NULL }, fnc_getgid, 0 } },
{ QSE_T("getpgrp"), { { 0, 0, QSE_NULL }, fnc_getpgrp, 0 } }, { QSE_T("getpgrp"), { { 0, 0, QSE_NULL }, fnc_getpgrp, 0 } },
{ QSE_T("getpid"), { { 0, 0, QSE_NULL }, fnc_getpid, 0 } }, { QSE_T("getpid"), { { 0, 0, QSE_NULL }, fnc_getpid, 0 } },
{ QSE_T("getppid"), { { 0, 0, QSE_NULL }, fnc_getppid, 0 } }, { QSE_T("getppid"), { { 0, 0, QSE_NULL }, fnc_getppid, 0 } },
{ QSE_T("gettid"), { { 0, 0, QSE_NULL }, fnc_gettid, 0 } },
{ QSE_T("gettime"), { { 0, 0, QSE_NULL }, fnc_gettime, 0 } },
{ QSE_T("getuid"), { { 0, 0, QSE_NULL }, fnc_getuid, 0 } }, { QSE_T("getuid"), { { 0, 0, QSE_NULL }, fnc_getuid, 0 } },
{ QSE_T("kill"), { { 2, 2, QSE_NULL }, fnc_kill, 0 } }, { QSE_T("kill"), { { 2, 2, QSE_NULL }, fnc_kill, 0 } },
{ QSE_T("settime"), { { 1, 1, QSE_NULL }, fnc_settime, 0 } },
{ QSE_T("sleep"), { { 1, 1, QSE_NULL }, fnc_sleep, 0 } }, { QSE_T("sleep"), { { 1, 1, QSE_NULL }, fnc_sleep, 0 } },
{ QSE_T("wait"), { { 1, 1, QSE_NULL }, fnc_wait, 0 } } { QSE_T("wait"), { { 1, 1, QSE_NULL }, fnc_wait, 0 } }
}; };
@ -419,3 +578,7 @@ QSE_EXPORT int load (qse_awk_mod_t* mod, qse_awk_t* awk)
return 0; return 0;
} }
#if defined(__DOS__)
/* kind of DllMain() for Causeway DLL */
int main (int eax) { return 0; }
#endif

View File

@ -12,7 +12,7 @@ EXE
3 3
WString WString
5 5
dr2eo dw2eo
1 1
0 0
1 1
@ -67,79 +67,88 @@ qsecmn qseawk
0 0
17 17
WVList WVList
1
18
ActionStates
19
WString
5
&Make
20
WVList
0 0
-1 -1
1 1
1 1
0 0
18 21
WPickList WPickList
2 2
19 22
MItem MItem
3 3
*.c *.c
20 23
WString WString
4 4
COBJ COBJ
21 24
WVList WVList
2 2
22 25
MVState MVState
23 26
WString WString
3 3
WCC WCC
24 27
WString WString
25 25
d????Include directories: d????Include directories:
1 1
25 28
WString WString
37 37
"$(%watcom)/h;../../../../../include" "$(%watcom)/h;../../../../../include"
0 0
26 29
MVState MVState
27 30
WString WString
3 3
WCC WCC
28 31
WString WString
23 23
?????Macro definitions: ?????Macro definitions:
1 1
29 32
WString WString
15 15
QSE_BUILD_DEBUG QSE_BUILD_DEBUG
0 0
30 33
WVList WVList
0 0
-1 -1
1 1
1 1
0 0
31 34
MItem MItem
28 28
../../../../../cmd/awk/awk.c ../../../../../cmd/awk/awk.c
32 35
WString WString
4 4
COBJ COBJ
33 36
WVList WVList
0 0
34 37
WVList WVList
0 0
19 22
1 1
1 1
0 0

View File

@ -12,7 +12,7 @@ EXE
3 3
WString WString
5 5
dr2eo dw2eo
1 1
0 0
1 1

View File

@ -83,8 +83,8 @@ WString
1 1
21 21
WString WString
15 78
QSE_BUILD_DEBUG QSE_BUILD_DEBUG QSE_AWK_DEFAULT_MODPREFIX="awk-" QSE_AWK_DEFAULT_MODPOSTFIX=""
0 0
22 22
WVList WVList

View File

@ -0,0 +1,194 @@
40
targetIdent
0
MProject
1
MComponent
0
2
WString
5
CWDLL
3
WString
5
dx2do
1
0
1
4
MCommand
0
5
MCommand
0
6
MItem
11
awk-sys.dll
7
WString
5
CWDLL
8
WVList
4
9
MVState
10
WString
5
WLINK
11
WString
28
?????Library directories(;):
1
12
WString
27
../../lib/cmn ../../lib/awk
0
13
MVState
14
WString
5
WLINK
15
WString
18
?????Libraries(,):
1
16
WString
13
qsecmn qseawk
0
17
MVState
18
WString
5
WLINK
19
WString
21
dx???Export names(,):
1
20
WString
5
load_
0
21
MCState
22
WString
5
WLINK
23
WString
24
?????Eliminate dead code
1
1
24
WVList
1
25
ActionStates
26
WString
5
&Make
27
WVList
0
-1
1
1
0
28
WPickList
2
29
MItem
3
*.c
30
WString
4
COBJ
31
WVList
3
32
MVState
33
WString
3
WCC
34
WString
25
d????Include directories:
1
35
WString
37
"$(%watcom)/h;../../../../../include"
0
36
MVState
37
WString
3
WCC
38
WString
23
?????Macro definitions:
1
39
WString
15
QSE_BUILD_DEBUG
0
40
MCState
41
WString
3
WCC
42
WString
33
?????Disable stack depth checking
1
1
43
WVList
0
-1
1
1
0
44
MItem
28
../../../../../mod/awk/sys.c
45
WString
4
COBJ
46
WVList
0
47
WVList
0
29
1
1
0

View File

@ -83,8 +83,8 @@ WString
1 1
21 21
WString WString
15 78
QSE_BUILD_DEBUG QSE_BUILD_DEBUG QSE_AWK_DEFAULT_MODPREFIX="awk-" QSE_AWK_DEFAULT_MODPOSTFIX=""
0 0
22 22
MCState MCState

View File

@ -0,0 +1,157 @@
40
targetIdent
0
MProject
1
MComponent
0
2
WString
4
ODLL
3
WString
5
o_2do
1
0
1
4
MCommand
0
5
MCommand
0
6
MItem
11
awk-sys.dll
7
WString
4
ODLL
8
WVList
4
9
MVState
10
WString
5
WLINK
11
WString
28
?????Library directories(;):
1
12
WString
27
../../lib/cmn ../../lib/awk
0
13
MVState
14
WString
5
WLINK
15
WString
18
?????Libraries(,):
1
16
WString
14
qsecmn qseawk
0
17
MVState
18
WString
5
WLINK
19
WString
21
o????Export names(,):
1
20
WString
5
load_
0
21
MCState
22
WString
5
WLINK
23
WString
24
?????Eliminate dead code
1
1
24
WVList
0
-1
1
1
0
25
WPickList
2
26
MItem
3
*.c
27
WString
4
COBJ
28
WVList
1
29
MVState
30
WString
3
WCC
31
WString
25
o?2??Include directories:
1
32
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;../../../../../include"
0
33
WVList
0
-1
1
1
0
34
MItem
28
../../../../../mod/awk/sys.c
35
WString
4
COBJ
36
WVList
0
37
WVList
0
26
1
1
0

View File

@ -4,8 +4,8 @@ projectIdent
VpeMain VpeMain
1 1
WRect WRect
790 520
200 120
9320 9320
9680 9680
2 2
@ -16,7 +16,7 @@ MCommand
4 4
MCommand MCommand
0 0
13 15
5 5
WFileName WFileName
30 30
@ -70,11 +70,19 @@ WFileName
30 30
debug/dos32/cmd/sed/qsesed.tgt debug/dos32/cmd/sed/qsesed.tgt
18 18
WVList WFileName
13 31
debug/dos32/mod/awk/awk-sys.tgt
19 19
VComponent WFileName
29
debug/os2/mod/awk/awk-sys.tgt
20 20
WVList
15
21
VComponent
22
WRect WRect
1070 1070
2520 2520
@ -82,15 +90,15 @@ WRect
4240 4240
1 1
0 0
21 23
WFileName WFileName
30 30
release/os2/lib/cmn/qsecmn.tgt release/os2/lib/cmn/qsecmn.tgt
0 0
5 5
22 24
VComponent VComponent
23 25
WRect WRect
90 90
1240 1240
@ -98,15 +106,15 @@ WRect
4240 4240
1 1
0 0
24 26
WFileName WFileName
30 30
release/os2/lib/sed/qsesed.tgt release/os2/lib/sed/qsesed.tgt
0 0
0 0
25 27
VComponent VComponent
26 28
WRect WRect
2100 2100
1400 1400
@ -114,15 +122,15 @@ WRect
4240 4240
1 1
0 0
27 29
WFileName WFileName
30 30
release/os2/cmd/sed/qsesed.tgt release/os2/cmd/sed/qsesed.tgt
0 0
1 1
28 30
VComponent VComponent
29 31
WRect WRect
780 780
480 480
@ -130,15 +138,15 @@ WRect
4240 4240
1 1
0 0
30 32
WFileName WFileName
28 28
debug/os2/lib/cmn/qsecmn.tgt debug/os2/lib/cmn/qsecmn.tgt
45 45
48 48
31 33
VComponent VComponent
32 34
WRect WRect
1050 1050
2360 2360
@ -146,31 +154,31 @@ WRect
4240 4240
1 1
0 0
33 35
WFileName WFileName
28 28
debug/os2/lib/sed/qsesed.tgt debug/os2/lib/sed/qsesed.tgt
0 0
3 3
34 36
VComponent VComponent
35 37
WRect WRect
2910 420
2440 333
5700 5700
4240 4240
1 1
0 0
36 38
WFileName WFileName
28 28
debug/os2/lib/awk/qseawk.tgt debug/os2/lib/awk/qseawk.tgt
0 0
0 0
37 39
VComponent VComponent
38 40
WRect WRect
330 330
400 400
@ -178,47 +186,47 @@ WRect
4240 4240
1 1
0 0
39 41
WFileName WFileName
28 28
debug/os2/cmd/awk/qseawk.tgt debug/os2/cmd/awk/qseawk.tgt
0 0
1 1
40 42
VComponent VComponent
41 43
WRect WRect
2660 2670
40 40
5700 5700
4240 4240
1 1
0 0
42 44
WFileName WFileName
30 30
debug/dos32/lib/cmn/qsecmn.tgt debug/dos32/lib/cmn/qsecmn.tgt
18 0
25 0
43 45
VComponent VComponent
44 46
WRect WRect
1640 1620
1360 1360
5700 5700
4240 4240
1 1
0 0
45 47
WFileName WFileName
30 30
debug/dos32/lib/awk/qseawk.tgt debug/dos32/lib/awk/qseawk.tgt
0 0
0 0
46 48
VComponent VComponent
47 49
WRect WRect
0 0
200 200
@ -226,15 +234,15 @@ WRect
4240 4240
1 1
0 0
48 50
WFileName WFileName
30 30
debug/dos32/cmd/awk/qseawk.tgt debug/dos32/cmd/awk/qseawk.tgt
0 0
0 0
49 51
VComponent VComponent
50 52
WRect WRect
0 0
0 0
@ -242,42 +250,74 @@ WRect
4240 4240
1 1
0 0
51 53
WFileName WFileName
30 30
debug/dos32/lib/sed/qsesed.tgt debug/dos32/lib/sed/qsesed.tgt
0 0
5 5
52 54
VComponent VComponent
53 55
WRect WRect
580 580
560 560
5700 5700
4240 4240
1
0 0
0 56
54
WFileName WFileName
30 30
debug/dos32/cmd/sed/qsesed.tgt debug/dos32/cmd/sed/qsesed.tgt
0 0
1 1
55 57
VComponent VComponent
56 58
WRect WRect
0 0
0 0
5700 5700
4240 4240
1
0 0
0 59
57
WFileName WFileName
28 28
debug/os2/cmd/sed/qsesed.tgt debug/os2/cmd/sed/qsesed.tgt
0 0
1 1
55 60
VComponent
61
WRect
2610
1080
5700
4240
0
0
62
WFileName
31
debug/dos32/mod/awk/awk-sys.tgt
0
0
63
VComponent
64
WRect
290
280
5700
4240
0
0
65
WFileName
29
debug/os2/mod/awk/awk-sys.tgt
0
0
63