diff --git a/qse/include/qse/awk/Makefile.am b/qse/include/qse/awk/Makefile.am index f15436dc..6da35883 100644 --- a/qse/include/qse/awk/Makefile.am +++ b/qse/include/qse/awk/Makefile.am @@ -1,6 +1,6 @@ pkgincludedir = $(includedir)/qse/awk -pkginclude_HEADERS = awk.h std.h mpi.h +pkginclude_HEADERS = awk.h std.h if ENABLE_CXX pkginclude_HEADERS += Awk.hpp StdAwk.hpp diff --git a/qse/include/qse/awk/Makefile.in b/qse/include/qse/awk/Makefile.in index 45f7c723..dbbd1e59 100644 --- a/qse/include/qse/awk/Makefile.in +++ b/qse/include/qse/awk/Makefile.in @@ -52,7 +52,7 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = 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 = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -257,7 +257,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ 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 .SUFFIXES: diff --git a/qse/include/qse/awk/StdAwk.hpp b/qse/include/qse/awk/StdAwk.hpp index 09867fc8..043e0a02 100644 --- a/qse/include/qse/awk/StdAwk.hpp +++ b/qse/include/qse/awk/StdAwk.hpp @@ -139,7 +139,6 @@ protected: int build_argcv (Run* run); int build_environ (Run* run); int __build_environ (Run* run, void* envptr); - int build_procinfo (Run* run); // intrinsic functions int rand (Run& run, Value& ret, const Value* args, size_t nargs, @@ -148,8 +147,6 @@ protected: const char_t* name, size_t len); int system (Run& run, Value& ret, const Value* args, size_t nargs, 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); @@ -216,7 +213,6 @@ protected: int gbl_argc; int gbl_argv; int gbl_environ; - int gbl_procinfo; // standard input console - reuse runarg size_t runarg_index; diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 33d99ce7..ef5df3fe 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -139,12 +139,14 @@ typedef struct qse_awk_loc_t qse_awk_loc_t; #if QSE_SIZEOF_INT == 2 # define QSE_AWK_VAL_HDR \ unsigned int type: 3; \ - unsigned int ref: 11; \ + unsigned int ref: 10; \ + unsigned int stat: 1; \ unsigned int nstr: 2 #else # define QSE_AWK_VAL_HDR \ unsigned int type: 3; \ - unsigned int ref: 27; \ + unsigned int ref: 26; \ + unsigned int stat: 1; \ unsigned int nstr: 2 #endif @@ -753,8 +755,8 @@ struct qse_awk_fnc_spec_t /** parameter specification */ struct { - int min; /**< min. numbers of argument for a function */ - int max; /**< max. numbers of argument for a function */ + qse_size_t min; /**< min. numbers of argument for a function */ + qse_size_t max; /**< max. numbers of argument for a function */ const qse_char_t* spec; } arg; diff --git a/qse/include/qse/awk/mpi.h b/qse/include/qse/awk/mpi.h deleted file mode 100644 index 4d51347d..00000000 --- a/qse/include/qse/awk/mpi.h +++ /dev/null @@ -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 . - */ - -#ifndef _QSE_AWK_MPI_H_ -#define _QSE_AWK_MPI_H_ - -#include - -/** @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 diff --git a/qse/include/qse/cmn/mbwc.h b/qse/include/qse/cmn/mbwc.h index 8df936e4..2a5411b6 100644 --- a/qse/include/qse/cmn/mbwc.h +++ b/qse/include/qse/cmn/mbwc.h @@ -208,7 +208,7 @@ qse_mchar_t* qse_wcstombsdupwithcmgr ( qse_cmgr_t* cmgr ); -qse_mchar_t* qse_wcntombsdupwithcmgr ( +qse_mchar_t* qse_wcsntombsdupwithcmgr ( const qse_wchar_t* wcs, qse_size_t wcslen, qse_size_t* mbslen, diff --git a/qse/lib/awk/Makefile.am b/qse/lib/awk/Makefile.am index b9327482..556da465 100644 --- a/qse/lib/awk/Makefile.am +++ b/qse/lib/awk/Makefile.am @@ -8,9 +8,9 @@ AM_CPPFLAGS = \ if WIN32 # you must adjust the value of DEFAULT_MODPOSTFIX according to # -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 -AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\" +AM_CPPFLAGS += -DQSE_AWK_DEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"\" endif lib_LTLIBRARIES = libqseawk.la diff --git a/qse/lib/awk/Makefile.in b/qse/lib/awk/Makefile.in index fa938066..b5e51f53 100644 --- a/qse/lib/awk/Makefile.in +++ b/qse/lib/awk/Makefile.in @@ -37,8 +37,8 @@ host_triplet = @host@ # you must adjust the value of DEFAULT_MODPOSTFIX according to # -version-info in ../../mod/awk/Makefile.am -@WIN32_TRUE@am__append_1 = -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\" -@WIN32_FALSE@am__append_2 = -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\" +@WIN32_TRUE@am__append_1 = -DQSE_AWK_DEFAULT_MODPREFIX=\"libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"-1\" +@WIN32_FALSE@am__append_2 = -DQSE_AWK_DEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DQSE_AWK_DEFAULT_MODPOSTFIX=\"\" @ENABLE_CXX_TRUE@am__append_3 = libqseawkxx.la subdir = lib/awk DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 9c282dfb..d3f3255d 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -41,11 +41,12 @@ # define USE_LTDL # endif #elif defined(__OS2__) +# define INCL_DOSMODULEMGR # define INCL_DOSPROCESS # define INCL_DOSERRORS # include #elif defined(__DOS__) - /* anything ? */ +# include #else # include # include @@ -133,11 +134,9 @@ int StdAwk::open () this->gbl_argc = addGlobal (QSE_T("ARGC")); this->gbl_argv = addGlobal (QSE_T("ARGV")); 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) + this->gbl_environ <= -1) { goto oops; } @@ -145,7 +144,6 @@ int StdAwk::open () 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("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("getioattr"), 2, 2, (FunctionHandler)&StdAwk::getioattr, QSE_AWK_RIO) <= -1) { @@ -342,81 +340,10 @@ int StdAwk::build_environ (Run* run) 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) { if (build_argcv (run) <= -1 || - build_environ (run) <= -1 || - build_procinfo (run) <= -1) return -1; + build_environ (run) <= -1) return -1; return 0; } @@ -478,16 +405,6 @@ int StdAwk::system (Run& run, Value& ret, const Value* args, size_t nargs, #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_ASSERT (this->cmgrtab_inited == true); @@ -1429,7 +1346,7 @@ void* StdAwk::modopen (const mod_spec_t* spec) #elif defined(_WIN32) HMODULE h; - qse_char_t* path; + qse_char_t* modpath; const qse_char_t* tmp[4]; int count; @@ -1439,16 +1356,16 @@ void* StdAwk::modopen (const mod_spec_t* spec) if (spec->postfix) tmp[count++] = spec->postfix; tmp[count] = QSE_NULL; - path = qse_stradup (tmp, QSE_NULL, this->getMmgr()); - if (!path) + modpath = qse_stradup (tmp, QSE_NULL, this->getMmgr()); + if (!modpath) { this->setError (QSE_AWK_ENOMEM); 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*)); return h; @@ -1487,9 +1404,35 @@ void* StdAwk::modopen (const mod_spec_t* spec) #elif defined(__DOS__) - /*TODO: implemente this */ - this->setError (QSE_AWK_ENOIMPL); - return QSE_NULL; + void* h; + qse_mchar_t* modpath; + 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 this->setError (QSE_AWK_ENOIMPL); @@ -1507,7 +1450,7 @@ void StdAwk::modclose (void* handle) #elif defined(__OS2__) DosFreeModule ((HMODULE)handle); #elif defined(__DOS__) - /*TODO: implemente this */ + FreeModule (handle); #else /* nothing to do */ #endif @@ -1536,8 +1479,7 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name) #elif defined(__OS2__) if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL; #elif defined(__DOS__) - /*TODO: implemente this */ - s = QSE_NULL; + s = GetProcAddress (handle, mname); #else s = QSE_NULL; #endif diff --git a/qse/lib/awk/fnc.c b/qse/lib/awk/fnc.c index 0dfbe9bf..b8f7f74f 100644 --- a/qse/lib/awk/fnc.c +++ b/qse/lib/awk/fnc.c @@ -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; 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->spec = *spec; diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index e53aa490..fb543f70 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -6437,14 +6437,14 @@ static qse_awk_mod_t* query_module ( if (awk->opt.mod[0].len > 0) spec.prefix = awk->opt.mod[0].ptr; - #if defined(DEFAULT_MODPREFIX) - else spec.prefix = QSE_T(DEFAULT_MODPREFIX); + #if defined(QSE_AWK_DEFAULT_MODPREFIX) + else spec.prefix = QSE_T(QSE_AWK_DEFAULT_MODPREFIX); #endif if (awk->opt.mod[1].len > 0) spec.postfix = awk->opt.mod[1].ptr; - #if defined(DEFAULT_MODPOSTFIX) - else spec.postfix = QSE_T(DEFAULT_MODPOSTFIX); + #if defined(QSE_AWK_DEFAULT_MODPOSTFIX) + else spec.postfix = QSE_T(QSE_AWK_DEFAULT_MODPOSTFIX); #endif QSE_MEMSET (&md, 0, QSE_SIZEOF(md)); @@ -6464,15 +6464,22 @@ static qse_awk_mod_t* query_module ( } 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"); - ea.len = 4; - qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL); - - awk->prm.modclose (awk, md.handle); - return QSE_NULL; + awk->prm.modclose (awk, md.handle); + return QSE_NULL; + } + } } /* i copy-insert 'md' into the table before calling 'load'. diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index e63ea0a3..59e5b6ef 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -5771,6 +5771,7 @@ static qse_awk_val_t* __eval_call ( #ifdef DEBUG_RUN qse_dprintf (QSE_T("block run complete nargs = %d\n"), (int)nargs); #endif + for (i = 0; i < nargs; i++) { qse_awk_rtx_refdownval (run, STACK_ARG(run,i)); diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 9847423a..1d710045 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -50,7 +50,7 @@ # define INCL_DOSERRORS # include #elif defined(__DOS__) - /* anything ? */ +# include #else # include # include @@ -115,7 +115,6 @@ typedef struct xtn_t int gbl_argc; int gbl_argv; int gbl_environ; - int gbl_procinfo; qse_awk_ecb_t ecb; } 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) HMODULE h; - qse_char_t* path; + qse_char_t* modpath; const qse_char_t* tmp[4]; 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; tmp[count] = QSE_NULL; - path = qse_stradup (tmp, QSE_NULL, awk->mmgr); - if (!path) + modpath = qse_stradup (tmp, QSE_NULL, awk->mmgr); + if (!modpath) { qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, 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*)); 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__) - /*TODO: implemente this */ - qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL); - return -1; + void* h; + qse_mchar_t* modpath; + 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 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__) DosFreeModule ((HMODULE)handle); #elif defined(__DOS__) - /*TODO: implemente this */ + FreeModule (handle); #else /* nothing to do */ #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; #elif defined(__DOS__) - /*TODO: implemente this */ - s = QSE_NULL; + s = GetProcAddress (handle, mname); + #else s = QSE_NULL; #endif @@ -1788,7 +1812,7 @@ static int build_argcv ( return 0; } - + static int __build_environ ( qse_awk_rtx_t* rtx, int gbl_id, qse_env_char_t* envarr[]) { @@ -1940,122 +1964,12 @@ static int build_environ (qse_awk_rtx_t* rtx, int gbl_id) 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 ( qse_awk_rtx_t* rtx, xtn_t* xtn, const qse_char_t* id, const qse_char_t*const icf[]) { if (build_argcv (rtx, xtn->gbl_argc, xtn->gbl_argv, id, icf) <= -1 || - build_environ (rtx, xtn->gbl_environ) <= -1 || - build_procinfo (rtx, xtn->gbl_procinfo) <= -1) return -1; + build_environ (rtx, xtn->gbl_environ) <= -1) return -1; return 0; } @@ -2282,20 +2196,6 @@ skip_system: 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) { 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_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 || - xtn->gbl_environ <= -1 || xtn->gbl_procinfo <= -1) return -1; + if (xtn->gbl_argc <= -1 || xtn->gbl_argv <= -1) return -1; + + xtn->gbl_environ = add_global (awk, QSE_T("ENVIRON"), 7); + if (xtn->gbl_environ <= -1) return -1; return 0; } @@ -2621,7 +2521,6 @@ static struct fnctab_t fnctab[] = { {QSE_T("rand"), 4}, { {0, 0, QSE_NULL}, fnc_rand, 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("time"), 4}, { {0, 0, QSE_NULL}, fnc_time, 0 } }, { {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 } } }; diff --git a/qse/lib/awk/val.c b/qse/lib/awk/val.c index 7f29ed95..f03e38b3 100644 --- a/qse/lib/awk/val.c +++ b/qse/lib/awk/val.c @@ -27,36 +27,36 @@ #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_str_t awk_zls = { QSE_AWK_VAL_STR, 0, 0, { QSE_T(""), 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, 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_zls = (qse_awk_val_t*)&awk_zls; static qse_awk_val_int_t awk_int[] = { - { QSE_AWK_VAL_INT, 0, 0, -1, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 0, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 1, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 2, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 3, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 4, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 5, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 6, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 7, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 8, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 9, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 10, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 11, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 12, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 13, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 14, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 15, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 16, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 17, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 18, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 19, QSE_NULL }, - { QSE_AWK_VAL_INT, 0, 0, 20, QSE_NULL } + { QSE_AWK_VAL_INT, 0, 1, 0, -1, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 0, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 1, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 2, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 3, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 4, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 5, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 6, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 7, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 8, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 9, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 10, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 11, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 12, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 13, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 14, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 15, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 16, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 17, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 18, QSE_NULL }, + { QSE_AWK_VAL_INT, 0, 1, 0, 19, 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]; @@ -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->ref = 0; + val->stat = 0; val->nstr = 0; val->val = v; 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->ref = 0; + val->stat = 0; val->nstr = 0; val->val = v; val->nde = QSE_NULL; @@ -322,6 +324,7 @@ init: #endif val->type = QSE_AWK_VAL_STR; val->ref = 0; + val->stat = 0; val->nstr = 0; val->val.len = str->len; val->val.ptr = (qse_char_t*)(val + 1); @@ -380,6 +383,7 @@ init: #endif val->type = QSE_AWK_VAL_STR; val->ref = 0; + val->stat = 0; val->nstr = 0; val->val.len = len1 + len2; 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->ref = 0; + val->stat = 0; val->nstr = 0; 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->ref = 0; + val->stat = 0; val->nstr = 0; val->map = qse_htb_open ( 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->ref = 0; + val->stat = 0; val->nstr = 0; 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->ref = 0; + val->stat = 0; val->nstr = 0; val->id = id; val->adr = adr; @@ -722,6 +730,15 @@ qse_awk_val_t* qse_awk_rtx_makerefval ( 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) \ ((val) == QSE_NULL || \ (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_t*)&awk_int[0] && \ (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) { @@ -853,8 +872,8 @@ void qse_awk_rtx_refdownval (qse_awk_rtx_t* rtx, qse_awk_val_t* val) #endif QSE_ASSERTX (val->ref > 0, - "the reference count of a value should be greater than zero for it" - " to be decremented. check the source code for any bugs"); + "the reference count of a value should be greater than zero for it " + "to be decremented. check the source code for any bugs"); val->ref--; if (val->ref <= 0) diff --git a/qse/mod/awk/mpi.c b/qse/mod/awk/mpi.c index bf7c7cf9..4a82ca73 100644 --- a/qse/mod/awk/mpi.c +++ b/qse/mod/awk/mpi.c @@ -153,12 +153,12 @@ struct inttab_t static fnctab_t fnctab[] = { - { QSE_T("assign"), { { 1, 1, QSE_NULL }, fnc_assign }, 0 }, - { QSE_T("barrier"), { { 0, 0, QSE_NULL }, fnc_barrier }, 0 }, - { QSE_T("hash"), { { 1, 1, QSE_NULL }, fnc_hash }, 0 }, - { QSE_T("rank"), { { 0, 0, QSE_NULL }, fnc_rank }, 0 }, - { QSE_T("reduce"), { { 2, 2, QSE_NULL }, fnc_reduce }, 0 }, - { QSE_T("size"), { { 0, 0, QSE_NULL }, fnc_size }, 0 } + { QSE_T("assign"), { { 1, 1, QSE_NULL }, fnc_assign, 0 } }, + { QSE_T("barrier"), { { 0, 0, QSE_NULL }, fnc_barrier, 0 } }, + { QSE_T("hash"), { { 1, 1, QSE_NULL }, fnc_hash, 0 } }, + { QSE_T("rank"), { { 0, 0, QSE_NULL }, fnc_rank, 0 } }, + { QSE_T("reduce"), { { 2, 2, QSE_NULL }, fnc_reduce, 0 } }, + { QSE_T("size"), { { 0, 0, QSE_NULL }, fnc_size, 0 } } }; static inttab_t inttab[] = diff --git a/qse/mod/awk/sys.c b/qse/mod/awk/sys.c index 2f2cbfdb..bc648b70 100644 --- a/qse/mod/awk/sys.c +++ b/qse/mod/awk/sys.c @@ -1,5 +1,6 @@ #include #include +#include #if defined(_WIN32) # include @@ -12,12 +13,15 @@ #elif defined(__DOS__) # include #else -# include -# include -# include -# include +# include "../../lib/cmn/syscall.h" +# if defined(HAVE_SYS_SYSCALL_H) +# include +# endif #endif +#include /* getenv */ + + static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { 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; } -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) { 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; } +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) { 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; } +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) { @@ -221,34 +294,56 @@ static int fnc_getgid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) 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; - 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; + /* TOOD: implement this*/ + uid = -1; + #elif defined(__OS2__) - /* TOOD: implement this*/ - rx = -1; + /* TOOD: implement this*/ + uid = -1; + #elif defined(__DOS__) - /* TOOD: implement this*/ - rx = -1; -#else - rx = kill (pid, sig); -#endif - } + /* TOOD: implement this*/ + uid = -1; - retv = qse_awk_rtx_makeintval (rtx, rx); +#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; 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; } +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; struct fnctab_t { @@ -302,12 +455,18 @@ struct inttab_t static fnctab_t fnctab[] = { { 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("getpgrp"), { { 0, 0, QSE_NULL }, fnc_getpgrp, 0 } }, { QSE_T("getpid"), { { 0, 0, QSE_NULL }, fnc_getpid, 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("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("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; } +#if defined(__DOS__) +/* kind of DllMain() for Causeway DLL */ +int main (int eax) { return 0; } +#endif diff --git a/qse/watcom/debug/dos32/cmd/awk/qseawk.tgt b/qse/watcom/debug/dos32/cmd/awk/qseawk.tgt index 9522b788..dc360250 100755 --- a/qse/watcom/debug/dos32/cmd/awk/qseawk.tgt +++ b/qse/watcom/debug/dos32/cmd/awk/qseawk.tgt @@ -12,7 +12,7 @@ EXE 3 WString 5 -dr2eo +dw2eo 1 0 1 @@ -67,79 +67,88 @@ qsecmn qseawk 0 17 WVList +1 +18 +ActionStates +19 +WString +5 +&Make +20 +WVList 0 -1 1 1 0 -18 +21 WPickList 2 -19 +22 MItem 3 *.c -20 +23 WString 4 COBJ -21 +24 WVList 2 -22 +25 MVState -23 +26 WString 3 WCC -24 +27 WString 25 d????Include directories: 1 -25 +28 WString 37 "$(%watcom)/h;../../../../../include" 0 -26 +29 MVState -27 +30 WString 3 WCC -28 +31 WString 23 ?????Macro definitions: 1 -29 +32 WString 15 QSE_BUILD_DEBUG 0 -30 +33 WVList 0 -1 1 1 0 -31 +34 MItem 28 ../../../../../cmd/awk/awk.c -32 +35 WString 4 COBJ -33 +36 WVList 0 -34 +37 WVList 0 -19 +22 1 1 0 diff --git a/qse/watcom/debug/dos32/cmd/sed/qsesed.tgt b/qse/watcom/debug/dos32/cmd/sed/qsesed.tgt index 6b3249b7..3fc7c8a6 100755 --- a/qse/watcom/debug/dos32/cmd/sed/qsesed.tgt +++ b/qse/watcom/debug/dos32/cmd/sed/qsesed.tgt @@ -12,7 +12,7 @@ EXE 3 WString 5 -dr2eo +dw2eo 1 0 1 diff --git a/qse/watcom/debug/dos32/lib/awk/qseawk.tgt b/qse/watcom/debug/dos32/lib/awk/qseawk.tgt index 6d28d0b6..d2b57856 100755 --- a/qse/watcom/debug/dos32/lib/awk/qseawk.tgt +++ b/qse/watcom/debug/dos32/lib/awk/qseawk.tgt @@ -83,8 +83,8 @@ WString 1 21 WString -15 -QSE_BUILD_DEBUG +78 +QSE_BUILD_DEBUG QSE_AWK_DEFAULT_MODPREFIX="awk-" QSE_AWK_DEFAULT_MODPOSTFIX="" 0 22 WVList diff --git a/qse/watcom/debug/dos32/mod/awk/awk-sys.tgt b/qse/watcom/debug/dos32/mod/awk/awk-sys.tgt new file mode 100755 index 00000000..b5839f06 --- /dev/null +++ b/qse/watcom/debug/dos32/mod/awk/awk-sys.tgt @@ -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 diff --git a/qse/watcom/debug/os2/lib/awk/qseawk.tgt b/qse/watcom/debug/os2/lib/awk/qseawk.tgt index cc16ef25..b183fa8f 100755 --- a/qse/watcom/debug/os2/lib/awk/qseawk.tgt +++ b/qse/watcom/debug/os2/lib/awk/qseawk.tgt @@ -83,8 +83,8 @@ WString 1 21 WString -15 -QSE_BUILD_DEBUG +78 +QSE_BUILD_DEBUG QSE_AWK_DEFAULT_MODPREFIX="awk-" QSE_AWK_DEFAULT_MODPOSTFIX="" 0 22 MCState diff --git a/qse/watcom/debug/os2/mod/awk/awk-sys.tgt b/qse/watcom/debug/os2/mod/awk/awk-sys.tgt new file mode 100755 index 00000000..2048639d --- /dev/null +++ b/qse/watcom/debug/os2/mod/awk/awk-sys.tgt @@ -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 diff --git a/qse/watcom/qse.wpj b/qse/watcom/qse.wpj index 258fb028..14802286 100755 --- a/qse/watcom/qse.wpj +++ b/qse/watcom/qse.wpj @@ -4,8 +4,8 @@ projectIdent VpeMain 1 WRect -790 -200 +520 +120 9320 9680 2 @@ -16,7 +16,7 @@ MCommand 4 MCommand 0 -13 +15 5 WFileName 30 @@ -70,11 +70,19 @@ WFileName 30 debug/dos32/cmd/sed/qsesed.tgt 18 -WVList -13 +WFileName +31 +debug/dos32/mod/awk/awk-sys.tgt 19 -VComponent +WFileName +29 +debug/os2/mod/awk/awk-sys.tgt 20 +WVList +15 +21 +VComponent +22 WRect 1070 2520 @@ -82,15 +90,15 @@ WRect 4240 1 0 -21 +23 WFileName 30 release/os2/lib/cmn/qsecmn.tgt 0 5 -22 +24 VComponent -23 +25 WRect 90 1240 @@ -98,15 +106,15 @@ WRect 4240 1 0 -24 +26 WFileName 30 release/os2/lib/sed/qsesed.tgt 0 0 -25 +27 VComponent -26 +28 WRect 2100 1400 @@ -114,15 +122,15 @@ WRect 4240 1 0 -27 +29 WFileName 30 release/os2/cmd/sed/qsesed.tgt 0 1 -28 +30 VComponent -29 +31 WRect 780 480 @@ -130,15 +138,15 @@ WRect 4240 1 0 -30 +32 WFileName 28 debug/os2/lib/cmn/qsecmn.tgt 45 48 -31 +33 VComponent -32 +34 WRect 1050 2360 @@ -146,31 +154,31 @@ WRect 4240 1 0 -33 +35 WFileName 28 debug/os2/lib/sed/qsesed.tgt 0 3 -34 +36 VComponent -35 +37 WRect -2910 -2440 +420 +333 5700 4240 1 0 -36 +38 WFileName 28 debug/os2/lib/awk/qseawk.tgt 0 0 -37 +39 VComponent -38 +40 WRect 330 400 @@ -178,47 +186,47 @@ WRect 4240 1 0 -39 +41 WFileName 28 debug/os2/cmd/awk/qseawk.tgt 0 1 -40 +42 VComponent -41 +43 WRect -2660 +2670 40 5700 4240 1 0 -42 +44 WFileName 30 debug/dos32/lib/cmn/qsecmn.tgt -18 -25 -43 +0 +0 +45 VComponent -44 +46 WRect -1640 +1620 1360 5700 4240 1 0 -45 +47 WFileName 30 debug/dos32/lib/awk/qseawk.tgt 0 0 -46 +48 VComponent -47 +49 WRect 0 200 @@ -226,15 +234,15 @@ WRect 4240 1 0 -48 +50 WFileName 30 debug/dos32/cmd/awk/qseawk.tgt 0 0 -49 +51 VComponent -50 +52 WRect 0 0 @@ -242,42 +250,74 @@ WRect 4240 1 0 -51 +53 WFileName 30 debug/dos32/lib/sed/qsesed.tgt 0 5 -52 +54 VComponent -53 +55 WRect 580 560 5700 4240 +1 0 -0 -54 +56 WFileName 30 debug/dos32/cmd/sed/qsesed.tgt 0 1 -55 +57 VComponent -56 +58 WRect 0 0 5700 4240 +1 0 -0 -57 +59 WFileName 28 debug/os2/cmd/sed/qsesed.tgt 0 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