2007-05-02 01:07:00 +00:00
|
|
|
/*
|
2012-08-16 03:47:55 +00:00
|
|
|
* $Id$
|
2009-09-16 04:01:02 +00:00
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2009-09-16 04:01:02 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2009-09-16 04:01:02 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-05-02 01:07:00 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
#include <qse/awk/Awk.hpp>
|
|
|
|
#include <qse/cmn/str.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include "../cmn/mem-prv.h"
|
|
|
|
#include "awk-prv.h"
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
/////////////////////////////////
|
2008-12-30 04:49:25 +00:00
|
|
|
QSE_BEGIN_NAMESPACE(QSE)
|
2007-09-11 22:42:00 +00:00
|
|
|
/////////////////////////////////
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk::Source
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-02-15 08:38:00 +00:00
|
|
|
struct xtn_t
|
|
|
|
{
|
|
|
|
Awk* awk;
|
2015-03-12 02:08:51 +00:00
|
|
|
qse_awk_ecb_t ecb;
|
2009-02-15 08:38:00 +00:00
|
|
|
};
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
struct rxtn_t
|
|
|
|
{
|
|
|
|
Awk::Run* run;
|
|
|
|
};
|
|
|
|
|
2009-07-14 04:03:53 +00:00
|
|
|
Awk::NoSource Awk::Source::NONE;
|
|
|
|
|
2019-06-24 08:53:49 +00:00
|
|
|
#if defined(QSE_HAVE_INLINE)
|
|
|
|
static QSE_INLINE xtn_t* GET_XTN(qse_awk_t* awk) { return (xtn_t*)((qse_uint8_t*)qse_awk_getxtn(awk) - QSE_SIZEOF(xtn_t)); }
|
|
|
|
static QSE_INLINE rxtn_t* GET_RXTN(qse_awk_rtx_t* rtx) { return (rxtn_t*)((qse_uint8_t*)qse_awk_rtx_getxtn(rtx) - QSE_SIZEOF(rxtn_t)); }
|
|
|
|
#else
|
|
|
|
#define GET_XTN(awk) ((xtn_t*)((qse_uint8_t*)qse_awk_getxtn(awk) - QSE_SIZEOF(xtn_t)))
|
|
|
|
#define GET_RXTN(rtx) ((rxtn_t*)((qse_uint8_t*)qse_awk_rtx_getxtn(rtx) - QSE_SIZEOF(rxtn_t)))
|
|
|
|
#endif
|
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2009-02-16 08:31:34 +00:00
|
|
|
// Awk::RIO
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Awk::RIOBase::RIOBase (Run* run, rio_arg_t* riod): run (run), riod (riod)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
const Awk::char_t* Awk::RIOBase::getName () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
return this->riod->name;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
const void* Awk::RIOBase::getHandle () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
return this->riod->handle;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
void Awk::RIOBase::setHandle (void* handle)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
this->riod->handle = handle;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2012-08-09 10:15:11 +00:00
|
|
|
int Awk::RIOBase::getUflags () const
|
|
|
|
{
|
|
|
|
return this->riod->uflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Awk::RIOBase::setUflags (int uflags)
|
|
|
|
{
|
|
|
|
this->riod->uflags = uflags;
|
|
|
|
}
|
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
Awk::RIOBase::operator Awk* () const
|
2009-01-17 08:57:27 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
return this->run->awk;
|
2009-01-17 08:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
Awk::RIOBase::operator Awk::awk_t* () const
|
2009-01-17 08:57:27 +00:00
|
|
|
{
|
2012-12-13 13:07:16 +00:00
|
|
|
QSE_ASSERT (qse_awk_rtx_getawk(this->run->rtx) == this->run->awk->getHandle());
|
|
|
|
return this->run->awk->getHandle();
|
2009-01-17 08:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
Awk::RIOBase::operator Awk::rio_arg_t* () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
return this->riod;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-15 01:21:00 +00:00
|
|
|
|
2009-07-08 07:05:10 +00:00
|
|
|
Awk::RIOBase::operator Awk::Run* () const
|
|
|
|
{
|
|
|
|
return this->run;
|
|
|
|
}
|
|
|
|
|
2009-06-26 01:39:27 +00:00
|
|
|
Awk::RIOBase::operator Awk::rtx_t* () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
return this->run->rtx;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-09-07 23:14:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk::Pipe
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2007-09-07 23:14:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Awk::Pipe::Pipe (Run* run, rio_arg_t* riod): RIOBase (run, riod)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
Awk::Pipe::Mode Awk::Pipe::getMode () const
|
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
return (Mode)riod->mode;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-08-29 03:48:02 +00:00
|
|
|
Awk::Pipe::CloseMode Awk::Pipe::getCloseMode () const
|
|
|
|
{
|
|
|
|
return (CloseMode)riod->rwcmode;
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk::File
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Awk::File::File (Run* run, rio_arg_t* riod): RIOBase (run, riod)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
Awk::File::Mode Awk::File::getMode () const
|
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
return (Mode)riod->mode;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk::Console
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Awk::Console::Console (Run* run, rio_arg_t* riod):
|
|
|
|
RIOBase (run, riod), filename (QSE_NULL)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
Awk::Console::~Console ()
|
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (filename != QSE_NULL)
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_freemem ((awk_t*)this, filename);
|
2007-05-15 01:21:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-15 01:21:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
int Awk::Console::setFileName (const char_t* name)
|
|
|
|
{
|
2009-07-08 07:05:10 +00:00
|
|
|
if (this->getMode() == READ)
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
2009-01-31 22:03:05 +00:00
|
|
|
return qse_awk_rtx_setfilename (
|
2009-07-07 06:37:25 +00:00
|
|
|
this->run->rtx, name, qse_strlen(name));
|
2007-05-15 01:21:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
else
|
2007-05-06 19:44:00 +00:00
|
|
|
{
|
2009-01-31 22:03:05 +00:00
|
|
|
return qse_awk_rtx_setofilename (
|
2009-07-07 06:37:25 +00:00
|
|
|
this->run->rtx, name, qse_strlen(name));
|
2007-05-06 19:44:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Console::setFNR (int_t fnr)
|
2007-10-30 00:20:00 +00:00
|
|
|
{
|
2009-07-11 08:05:51 +00:00
|
|
|
val_t* tmp;
|
2007-10-30 00:20:00 +00:00
|
|
|
int n;
|
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
tmp = qse_awk_rtx_makeintval (this->run->rtx, fnr);
|
2008-12-21 21:35:07 +00:00
|
|
|
if (tmp == QSE_NULL) return -1;
|
2007-10-30 00:20:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
qse_awk_rtx_refupval (this->run->rtx, tmp);
|
|
|
|
n = qse_awk_rtx_setgbl (this->run->rtx, QSE_AWK_GBL_FNR, tmp);
|
|
|
|
qse_awk_rtx_refdownval (this->run->rtx, tmp);
|
2007-10-30 00:20:00 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
Awk::Console::Mode Awk::Console::getMode () const
|
|
|
|
{
|
2009-02-16 08:31:34 +00:00
|
|
|
return (Mode)riod->mode;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-11 08:05:51 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk::Value
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-07-14 02:51:23 +00:00
|
|
|
Awk::Value::IndexIterator Awk::Value::IndexIterator::END;
|
|
|
|
|
2012-12-13 13:07:16 +00:00
|
|
|
const Awk::char_t* Awk::Value::getEmptyStr()
|
|
|
|
{
|
|
|
|
static const Awk::char_t* EMPTY_STRING = QSE_T("");
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
const qse_mchar_t* Awk::Value::getEmptyMbs()
|
|
|
|
{
|
|
|
|
static const qse_mchar_t* EMPTY_STRING = QSE_MT("");
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
2012-12-13 13:07:16 +00:00
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
Awk::Value::IntIndex::IntIndex (int_t x)
|
2009-07-14 02:51:23 +00:00
|
|
|
{
|
|
|
|
ptr = buf;
|
|
|
|
len = 0;
|
|
|
|
|
2011-11-09 00:54:27 +00:00
|
|
|
#define NTOC(n) (QSE_T("0123456789")[n])
|
2009-07-14 02:51:23 +00:00
|
|
|
|
|
|
|
int base = 10;
|
2013-11-05 14:16:45 +00:00
|
|
|
int_t last = x % base;
|
|
|
|
int_t y = 0;
|
2011-11-09 00:54:27 +00:00
|
|
|
int dig = 0;
|
2009-07-14 02:51:23 +00:00
|
|
|
|
|
|
|
if (x < 0) buf[len++] = QSE_T('-');
|
|
|
|
|
|
|
|
x = x / base;
|
|
|
|
if (x < 0) x = -x;
|
|
|
|
|
|
|
|
while (x > 0)
|
|
|
|
{
|
|
|
|
y = y * base + (x % base);
|
|
|
|
x = x / base;
|
|
|
|
dig++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (y > 0)
|
|
|
|
{
|
|
|
|
buf[len++] = NTOC (y % base);
|
|
|
|
y = y / base;
|
|
|
|
dig--;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (dig > 0)
|
|
|
|
{
|
|
|
|
dig--;
|
|
|
|
buf[len++] = QSE_T('0');
|
|
|
|
}
|
|
|
|
if (last < 0) last = -last;
|
|
|
|
buf[len++] = NTOC(last);
|
|
|
|
|
|
|
|
buf[len] = QSE_T('\0');
|
|
|
|
|
|
|
|
#undef NTOC
|
|
|
|
}
|
2009-07-13 07:06:01 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
#if defined(QSE_AWK_VALUE_USE_IN_CLASS_PLACEMENT_NEW)
|
2009-07-13 07:06:01 +00:00
|
|
|
void* Awk::Value::operator new (size_t n, Run* run) throw ()
|
|
|
|
{
|
2011-07-21 10:17:16 +00:00
|
|
|
void* ptr = qse_awk_rtx_allocmem (run->rtx, QSE_SIZEOF(run) + n);
|
2009-07-13 07:06:01 +00:00
|
|
|
if (ptr == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
*(Run**)ptr = run;
|
2015-03-11 13:33:23 +00:00
|
|
|
return (char*)ptr + QSE_SIZEOF(run);
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void* Awk::Value::operator new[] (size_t n, Run* run) throw ()
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2011-07-21 10:17:16 +00:00
|
|
|
void* ptr = qse_awk_rtx_allocmem (run->rtx, QSE_SIZEOF(run) + n);
|
2009-07-13 07:06:01 +00:00
|
|
|
if (ptr == QSE_NULL) return QSE_NULL;
|
|
|
|
|
|
|
|
*(Run**)ptr = run;
|
2015-03-11 13:33:23 +00:00
|
|
|
return (char*)ptr + QSE_SIZEOF(run);
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 13:07:16 +00:00
|
|
|
#if !defined(__BORLANDC__) && !defined(__WATCOMC__)
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::Value::operator delete (void* ptr, Run* run)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2014-06-08 12:46:04 +00:00
|
|
|
// this placement delete is to be called when the constructor
|
|
|
|
// throws an exception and it's caught by the caller.
|
2015-03-11 13:33:23 +00:00
|
|
|
qse_awk_rtx_freemem (run->rtx, (char*)ptr - QSE_SIZEOF(run));
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::Value::operator delete[] (void* ptr, Run* run)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2014-06-08 12:46:04 +00:00
|
|
|
// this placement delete is to be called when the constructor
|
|
|
|
// throws an exception and it's caught by the caller.
|
2015-03-11 13:33:23 +00:00
|
|
|
qse_awk_rtx_freemem (run->rtx, (char*)ptr - QSE_SIZEOF(run));
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::Value::operator delete (void* ptr)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2014-06-08 12:46:04 +00:00
|
|
|
// this delete is to be called for normal destruction.
|
2015-03-11 13:33:23 +00:00
|
|
|
void* p = (char*)ptr - QSE_SIZEOF(Run*);
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_rtx_freemem ((*(Run**)p)->rtx, p);
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::Value::operator delete[] (void* ptr)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2014-06-08 12:46:04 +00:00
|
|
|
// this delete is to be called for normal destruction.
|
2015-03-11 13:33:23 +00:00
|
|
|
void* p = (char*)ptr - QSE_SIZEOF(Run*);
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_rtx_freemem ((*(Run**)p)->rtx, p);
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
2015-03-11 13:33:23 +00:00
|
|
|
#endif
|
2009-07-13 07:06:01 +00:00
|
|
|
|
2019-08-29 02:19:41 +00:00
|
|
|
Awk::Value::Value (): run (QSE_NULL), val (qse_get_awk_nil_val())
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
2019-08-29 03:13:57 +00:00
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 02:19:41 +00:00
|
|
|
Awk::Value::Value (Run& run): run (&run), val (qse_get_awk_nil_val())
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
2019-08-29 03:13:57 +00:00
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 02:19:41 +00:00
|
|
|
Awk::Value::Value (Run* run): run (run), val (qse_get_awk_nil_val())
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
2019-08-29 03:13:57 +00:00
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
Awk::Value::Value (const Value& v): run(v.run), val(v.val)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
if (run) qse_awk_rtx_refupval (run->rtx, val);
|
2009-07-13 07:06:01 +00:00
|
|
|
|
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
2019-08-29 03:13:57 +00:00
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Awk::Value::~Value ()
|
|
|
|
{
|
|
|
|
if (run != QSE_NULL)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2009-07-11 08:05:51 +00:00
|
|
|
qse_awk_rtx_refdownval (run->rtx, val);
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.str.ptr) qse_awk_rtx_freemem (run->rtx, cached.str.ptr);
|
|
|
|
if (cached.mbs.ptr) qse_awk_rtx_freemem (run->rtx, cached.mbs.ptr);
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Awk::Value& Awk::Value::operator= (const Value& v)
|
|
|
|
{
|
2009-07-13 07:06:01 +00:00
|
|
|
if (this == &v) return *this;
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
if (run)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2009-07-11 08:05:51 +00:00
|
|
|
qse_awk_rtx_refdownval (run->rtx, val);
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.str.ptr)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_rtx_freemem (run->rtx, cached.str.ptr);
|
2009-07-13 07:06:01 +00:00
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.mbs.ptr)
|
|
|
|
{
|
|
|
|
qse_awk_rtx_freemem (run->rtx, cached.mbs.ptr);
|
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
|
|
|
}
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
run = v.run;
|
|
|
|
val = v.val;
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
if (run) qse_awk_rtx_refupval (run->rtx, val);
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
|
2009-07-11 08:05:51 +00:00
|
|
|
void Awk::Value::clear ()
|
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
if (run)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
qse_awk_rtx_refdownval (run->rtx, val);
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.str.ptr)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_rtx_freemem (run->rtx, cached.str.ptr);
|
2009-07-13 07:06:01 +00:00
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.mbs.ptr)
|
|
|
|
{
|
|
|
|
qse_awk_rtx_freemem (run->rtx, cached.mbs.ptr);
|
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
|
|
|
}
|
2009-07-13 07:06:01 +00:00
|
|
|
|
2009-07-11 08:05:51 +00:00
|
|
|
run = QSE_NULL;
|
2019-08-29 02:19:41 +00:00
|
|
|
val = qse_get_awk_nil_val();
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
Awk::Value::operator Awk::int_t () const
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2013-11-05 14:16:45 +00:00
|
|
|
int_t v;
|
2019-08-29 03:13:57 +00:00
|
|
|
if (this->getInt(&v) <= -1) v = 0;
|
2009-07-11 21:01:36 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
Awk::Value::operator Awk::flt_t () const
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2011-11-22 05:03:31 +00:00
|
|
|
flt_t v;
|
2019-08-29 03:13:57 +00:00
|
|
|
if (this->getFlt(&v) <= -1) v = 0.0;
|
2009-07-11 21:01:36 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::Value::operator const Awk::char_t* () const
|
|
|
|
{
|
2009-08-21 05:28:03 +00:00
|
|
|
const Awk::char_t* ptr;
|
2009-07-11 21:01:36 +00:00
|
|
|
size_t len;
|
2019-08-29 03:13:57 +00:00
|
|
|
if (Awk::Value::getStr(&ptr, &len) <= -1) ptr = getEmptyStr();
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_WCHAR)
|
|
|
|
Awk::Value::operator const qse_mchar_t* () const
|
|
|
|
{
|
|
|
|
const qse_mchar_t* ptr;
|
|
|
|
size_t len;
|
|
|
|
if (Awk::Value::getMbs(&ptr, &len) <= -1) ptr = getEmptyMbs();
|
2009-07-11 21:01:36 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
#endif
|
2009-07-11 21:01:36 +00:00
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Value::getInt (int_t* v) const
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2013-11-05 14:16:45 +00:00
|
|
|
int_t lv = 0;
|
2009-07-11 21:01:36 +00:00
|
|
|
|
2012-11-11 16:07:34 +00:00
|
|
|
QSE_ASSERT (this->val != QSE_NULL);
|
2009-07-13 07:06:01 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
if (this->run)
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = qse_awk_rtx_valtoint(this->run->rtx, this->val, &lv);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2012-11-11 16:07:34 +00:00
|
|
|
run->awk->retrieveError (this->run);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 21:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*v = lv;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
int Awk::Value::getFlt (flt_t* v) const
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2011-11-22 05:03:31 +00:00
|
|
|
flt_t rv = 0;
|
2009-07-11 21:01:36 +00:00
|
|
|
|
2012-11-11 16:07:34 +00:00
|
|
|
QSE_ASSERT (this->val != QSE_NULL);
|
2009-07-13 07:06:01 +00:00
|
|
|
|
2012-11-11 16:07:34 +00:00
|
|
|
if (this->run)
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = qse_awk_rtx_valtoflt(this->run->rtx, this->val, &rv);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2012-11-11 16:07:34 +00:00
|
|
|
run->awk->retrieveError (this->run);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 21:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*v = rv;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Value::getNum (int_t* lv, flt_t* fv) const
|
2012-11-11 16:07:34 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (this->val != QSE_NULL);
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
if (this->run)
|
2012-11-11 16:07:34 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = qse_awk_rtx_valtonum(this->run->rtx, this->val, lv, fv);
|
2012-11-11 16:07:34 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
|
|
|
run->awk->retrieveError (this->run);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lv = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
int Awk::Value::getStr (const char_t** str, size_t* len) const
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2012-12-13 13:07:16 +00:00
|
|
|
const char_t* p = getEmptyStr();
|
2009-07-13 07:06:01 +00:00
|
|
|
size_t l = 0;
|
2009-07-11 21:01:36 +00:00
|
|
|
|
2012-11-11 16:07:34 +00:00
|
|
|
QSE_ASSERT (this->val != QSE_NULL);
|
2009-07-11 21:01:36 +00:00
|
|
|
|
2014-10-22 17:05:45 +00:00
|
|
|
if (this->run)
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
if (QSE_AWK_RTX_GETVALTYPE(this->run->rtx, this->val) == QSE_AWK_VAL_STR)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2012-11-11 16:07:34 +00:00
|
|
|
p = ((qse_awk_val_str_t*)this->val)->val.ptr;
|
|
|
|
l = ((qse_awk_val_str_t*)this->val)->val.len;
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
if (!cached.str.ptr)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
|
|
|
qse_awk_rtx_valtostr_out_t out;
|
|
|
|
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
2019-08-29 03:13:57 +00:00
|
|
|
if (qse_awk_rtx_valtostr(this->run->rtx, this->val, &out) <= -1)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2012-11-11 16:07:34 +00:00
|
|
|
run->awk->retrieveError (this->run);
|
2009-07-13 07:06:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = out.u.cpldup.ptr;
|
|
|
|
l = out.u.cpldup.len;
|
|
|
|
|
|
|
|
cached.str.ptr = out.u.cpldup.ptr;
|
|
|
|
cached.str.len = out.u.cpldup.len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = cached.str.ptr;
|
|
|
|
l = cached.str.len;
|
|
|
|
}
|
|
|
|
}
|
2009-07-11 21:01:36 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
*str = p;
|
|
|
|
*len = l;
|
|
|
|
|
2009-07-11 21:01:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
int Awk::Value::getMbs (const qse_mchar_t** str, size_t* len) const
|
|
|
|
{
|
|
|
|
const qse_mchar_t* p = getEmptyMbs();
|
|
|
|
size_t l = 0;
|
|
|
|
|
|
|
|
QSE_ASSERT (this->val != QSE_NULL);
|
|
|
|
|
|
|
|
if (this->run)
|
|
|
|
{
|
|
|
|
if (QSE_AWK_RTX_GETVALTYPE(this->run->rtx, this->val) == QSE_AWK_VAL_MBS)
|
|
|
|
{
|
|
|
|
p = ((qse_awk_val_mbs_t*)this->val)->val.ptr;
|
|
|
|
l = ((qse_awk_val_mbs_t*)this->val)->val.len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!cached.mbs.ptr)
|
|
|
|
{
|
|
|
|
p = qse_awk_rtx_valtombsdup(this->run->rtx, this->val, &l);
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
run->awk->retrieveError (this->run);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cached.mbs.ptr = (qse_mchar_t*)p;
|
|
|
|
cached.mbs.len = l;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = cached.mbs.ptr;
|
|
|
|
l = cached.mbs.len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*str = p;
|
|
|
|
*len = l;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
int Awk::Value::setVal (val_t* v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run == QSE_NULL)
|
|
|
|
{
|
|
|
|
/* no runtime context assoicated. unfortunately, i can't
|
|
|
|
* set an error number for the same reason */
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setVal(this->run, v);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
int Awk::Value::setVal (Run* r, val_t* v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run != QSE_NULL)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
qse_awk_rtx_refdownval (this->run->rtx, val);
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.str.ptr)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_rtx_freemem (this->run->rtx, cached.str.ptr);
|
2009-07-13 07:06:01 +00:00
|
|
|
cached.str.ptr = QSE_NULL;
|
|
|
|
cached.str.len = 0;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
if (cached.mbs.ptr)
|
|
|
|
{
|
|
|
|
qse_awk_rtx_freemem (this->run->rtx, cached.mbs.ptr);
|
|
|
|
cached.mbs.ptr = QSE_NULL;
|
|
|
|
cached.mbs.len = 0;
|
|
|
|
}
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSE_ASSERT (cached.str.ptr == QSE_NULL);
|
2019-08-29 03:13:57 +00:00
|
|
|
QSE_ASSERT (cached.mbs.ptr == QSE_NULL);
|
2009-07-11 08:05:51 +00:00
|
|
|
qse_awk_rtx_refupval (r->rtx, v);
|
|
|
|
|
2011-05-13 22:06:55 +00:00
|
|
|
this->run = r;
|
|
|
|
this->val = v;
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Value::setInt (int_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run == QSE_NULL)
|
|
|
|
{
|
|
|
|
/* no runtime context assoicated. unfortunately, i can't
|
|
|
|
* set an error number for the same reason */
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setInt(this->run, v);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Value::setInt (Run* r, int_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
val_t* tmp;
|
2019-08-29 03:13:57 +00:00
|
|
|
tmp = qse_awk_rtx_makeintval(r->rtx, v);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setVal(r, tmp);
|
2009-07-11 08:05:51 +00:00
|
|
|
QSE_ASSERT (n == 0);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
int Awk::Value::setFlt (flt_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run == QSE_NULL)
|
|
|
|
{
|
|
|
|
/* no runtime context assoicated. unfortunately, i can't
|
|
|
|
* set an error number for the same reason */
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setFlt(this->run, v);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
int Awk::Value::setFlt (Run* r, flt_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
val_t* tmp;
|
2019-08-29 03:13:57 +00:00
|
|
|
tmp = qse_awk_rtx_makefltval(r->rtx, v);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
|
|
|
|
int n = this->setVal(r, tmp);
|
2009-07-11 08:05:51 +00:00
|
|
|
QSE_ASSERT (n == 0);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setStr (const char_t* str, size_t len, bool numeric)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run == QSE_NULL)
|
|
|
|
{
|
|
|
|
/* no runtime context assoicated. unfortunately, i can't
|
|
|
|
* set an error number for the same reason */
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setStr(this->run, str, len, numeric);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setStr (Run* r, const char_t* str, size_t len, bool numeric)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
val_t* tmp;
|
2013-05-29 08:46:23 +00:00
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
cstr_t cstr;
|
2014-07-02 12:28:58 +00:00
|
|
|
cstr.ptr = (char_t*)str;
|
2013-05-29 08:46:23 +00:00
|
|
|
cstr.len = len;
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
tmp = numeric? qse_awk_rtx_makenstrvalwithcstr(r->rtx, &cstr):
|
|
|
|
qse_awk_rtx_makestrvalwithcstr(r->rtx, &cstr);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setVal(r, tmp);
|
2009-07-11 21:01:36 +00:00
|
|
|
QSE_ASSERT (n == 0);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setStr (const char_t* str, bool numeric)
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run == QSE_NULL) return -1;
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setStr(this->run, str, numeric);
|
2009-07-11 21:01:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setStr (Run* r, const char_t* str, bool numeric)
|
2009-07-11 21:01:36 +00:00
|
|
|
{
|
|
|
|
val_t* tmp;
|
2019-08-29 03:13:57 +00:00
|
|
|
tmp = numeric? qse_awk_rtx_makenstrvalwithstr(r->rtx, str):
|
|
|
|
qse_awk_rtx_makestrvalwithstr(r->rtx, str);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 21:01:36 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setVal(r, tmp);
|
|
|
|
QSE_ASSERT (n == 0);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Awk::Value::setMbs (const qse_mchar_t* str, size_t len)
|
|
|
|
{
|
|
|
|
if (this->run == QSE_NULL)
|
|
|
|
{
|
|
|
|
/* no runtime context assoicated. unfortunately, i can't
|
|
|
|
* set an error number for the same reason */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return this->setMbs(this->run, str, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Value::setMbs (Run* r, const qse_mchar_t* str, size_t len)
|
|
|
|
{
|
|
|
|
val_t* tmp;
|
|
|
|
|
|
|
|
qse_mcstr_t cstr;
|
|
|
|
cstr.ptr = (qse_mchar_t*)str;
|
|
|
|
cstr.len = len;
|
|
|
|
|
|
|
|
tmp = qse_awk_rtx_makembsvalwithmcstr(r->rtx, &cstr);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
r->awk->retrieveError (r);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int n = this->setVal(r, tmp);
|
|
|
|
QSE_ASSERT (n == 0);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Value::setMbs (const qse_mchar_t* str)
|
|
|
|
{
|
|
|
|
if (this->run == QSE_NULL) return -1;
|
|
|
|
return this->setMbs(this->run, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Value::setMbs (Run* r, const qse_mchar_t* str)
|
|
|
|
{
|
|
|
|
val_t* tmp;
|
|
|
|
tmp = qse_awk_rtx_makembsval(r->rtx, str, qse_mbslen(str));
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
r->awk->retrieveError (r);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int n = this->setVal(r, tmp);
|
2009-07-11 08:05:51 +00:00
|
|
|
QSE_ASSERT (n == 0);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-07-14 02:51:23 +00:00
|
|
|
int Awk::Value::setIndexedVal (const Index& idx, val_t* v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run == QSE_NULL) return -1;
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setIndexedVal (this->run, idx, v);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 02:51:23 +00:00
|
|
|
int Awk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2009-07-14 02:51:23 +00:00
|
|
|
QSE_ASSERT (r != QSE_NULL);
|
|
|
|
|
2019-05-08 07:15:17 +00:00
|
|
|
if (QSE_AWK_RTX_GETVALTYPE (r->rtx, this->val) != QSE_AWK_VAL_MAP)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 10:16:57 +00:00
|
|
|
// the previous value is not a map.
|
|
|
|
// a new map value needs to be created first.
|
2019-08-29 03:13:57 +00:00
|
|
|
val_t* map = qse_awk_rtx_makemapval(r->rtx);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (map == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, map);
|
|
|
|
|
2011-05-13 10:16:57 +00:00
|
|
|
// update the map with a given value
|
2019-05-08 07:15:17 +00:00
|
|
|
if (qse_awk_rtx_setmapvalfld(r->rtx, map, idx.ptr, idx.len, v) == QSE_NULL)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
qse_awk_rtx_refdownval (r->rtx, map);
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-11 08:05:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-13 10:16:57 +00:00
|
|
|
// free the previous value
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run)
|
|
|
|
{
|
|
|
|
// if val is not nil, this->run can't be NULL
|
2019-05-08 07:15:17 +00:00
|
|
|
qse_awk_rtx_refdownval (this->run->rtx, this->val);
|
2011-05-13 22:06:55 +00:00
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
2011-05-13 22:06:55 +00:00
|
|
|
this->run = r;
|
|
|
|
this->val = map;
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QSE_ASSERT (run != QSE_NULL);
|
|
|
|
|
|
|
|
// if the previous value is a map, things are a bit simpler
|
|
|
|
// however it needs to check if the runtime context matches
|
|
|
|
// with the previous one.
|
2011-05-13 22:06:55 +00:00
|
|
|
if (this->run != r)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
// it can't span across multiple runtime contexts
|
2011-05-13 22:06:55 +00:00
|
|
|
this->run->setError (QSE_AWK_EINVAL);
|
|
|
|
this->run->awk->retrieveError (run);
|
2009-07-11 08:05:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-13 10:16:57 +00:00
|
|
|
// update the map with a given value
|
2019-05-08 07:15:17 +00:00
|
|
|
if (qse_awk_rtx_setmapvalfld(r->rtx, val, idx.ptr, idx.len, v) == QSE_NULL)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 10:16:57 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-11 08:05:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Value::setIndexedInt (const Index& idx, int_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
if (run == QSE_NULL) return -1;
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setIndexedInt (run, idx, v);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Value::setIndexedInt (Run* r, const Index& idx, int_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2011-05-13 10:16:57 +00:00
|
|
|
val_t* tmp = qse_awk_rtx_makeintval (r->rtx, v);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, tmp);
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setIndexedVal(r, idx, tmp);
|
2009-07-11 08:05:51 +00:00
|
|
|
qse_awk_rtx_refdownval (r->rtx, tmp);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
int Awk::Value::setIndexedFlt (const Index& idx, flt_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
if (run == QSE_NULL) return -1;
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setIndexedFlt(run, idx, v);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
int Awk::Value::setIndexedFlt (Run* r, const Index& idx, flt_t v)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
val_t* tmp = qse_awk_rtx_makefltval(r->rtx, v);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, tmp);
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setIndexedVal(r, idx, tmp);
|
2009-07-11 08:05:51 +00:00
|
|
|
qse_awk_rtx_refdownval (r->rtx, tmp);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setIndexedStr (const Index& idx, const char_t* str, size_t len, bool numeric)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
if (run == QSE_NULL) return -1;
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setIndexedStr(run, idx, str, len, numeric);
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
int Awk::Value::setIndexedStr (
|
2013-05-29 08:46:23 +00:00
|
|
|
Run* r, const Index& idx, const char_t* str, size_t len, bool numeric)
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
val_t* tmp;
|
2013-05-29 08:46:23 +00:00
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
cstr_t cstr;
|
2014-07-02 12:28:58 +00:00
|
|
|
cstr.ptr = (char_t*)str;
|
2013-05-29 08:46:23 +00:00
|
|
|
cstr.len = len;
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
tmp = numeric? qse_awk_rtx_makenstrvalwithcstr(r->rtx, &cstr):
|
|
|
|
qse_awk_rtx_makestrvalwithcstr(r->rtx, &cstr);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-11 08:05:51 +00:00
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, tmp);
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setIndexedVal(r, idx, tmp);
|
2009-07-13 07:06:01 +00:00
|
|
|
qse_awk_rtx_refdownval (r->rtx, tmp);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setIndexedStr (const Index& idx, const char_t* str, bool numeric)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
|
|
|
if (run == QSE_NULL) return -1;
|
2019-08-29 03:13:57 +00:00
|
|
|
return this->setIndexedStr(run, idx, str, numeric);
|
2009-07-13 07:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 08:46:23 +00:00
|
|
|
int Awk::Value::setIndexedStr (Run* r, const Index& idx, const char_t* str, bool numeric)
|
2009-07-13 07:06:01 +00:00
|
|
|
{
|
|
|
|
val_t* tmp;
|
2019-08-29 03:13:57 +00:00
|
|
|
tmp = numeric? qse_awk_rtx_makenstrvalwithstr(r->rtx, str):
|
|
|
|
qse_awk_rtx_makestrvalwithstr(r->rtx, str);
|
2009-07-14 02:51:23 +00:00
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
r->awk->retrieveError (r);
|
2009-07-14 02:51:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-13 07:06:01 +00:00
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, tmp);
|
2019-08-29 03:13:57 +00:00
|
|
|
int n = this->setIndexedVal(r, idx, tmp);
|
2009-07-11 08:05:51 +00:00
|
|
|
qse_awk_rtx_refdownval (r->rtx, tmp);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
int Awk::Value::setIndexedMbs (const Index& idx, const qse_mchar_t* str, size_t len)
|
|
|
|
{
|
|
|
|
if (run == QSE_NULL) return -1;
|
|
|
|
return this->setIndexedMbs(run, idx, str, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Value::setIndexedMbs (Run* r, const Index& idx, const qse_mchar_t* str, size_t len)
|
|
|
|
{
|
|
|
|
val_t* tmp;
|
|
|
|
|
|
|
|
qse_mcstr_t cstr;
|
|
|
|
cstr.ptr = (qse_mchar_t*)str;
|
|
|
|
cstr.len = len;
|
|
|
|
|
|
|
|
tmp = qse_awk_rtx_makembsvalwithmcstr(r->rtx, &cstr);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
r->awk->retrieveError (r);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, tmp);
|
|
|
|
int n = this->setIndexedVal(r, idx, tmp);
|
|
|
|
qse_awk_rtx_refdownval (r->rtx, tmp);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Value::setIndexedMbs (const Index& idx, const qse_mchar_t* str)
|
|
|
|
{
|
|
|
|
if (run == QSE_NULL) return -1;
|
|
|
|
return this->setIndexedMbs(run, idx, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Value::setIndexedMbs (Run* r, const Index& idx, const qse_mchar_t* str)
|
|
|
|
{
|
|
|
|
val_t* tmp;
|
|
|
|
tmp = qse_awk_rtx_makembsval(r->rtx, str, qse_mbslen(str));
|
|
|
|
if (tmp == QSE_NULL)
|
|
|
|
{
|
|
|
|
r->awk->retrieveError (r);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_awk_rtx_refupval (r->rtx, tmp);
|
|
|
|
int n = this->setIndexedVal(r, idx, tmp);
|
|
|
|
qse_awk_rtx_refdownval (r->rtx, tmp);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 08:05:51 +00:00
|
|
|
bool Awk::Value::isIndexed () const
|
|
|
|
{
|
|
|
|
QSE_ASSERT (val != QSE_NULL);
|
2019-08-29 03:13:57 +00:00
|
|
|
return QSE_AWK_RTX_GETVALTYPE(this->run->rtx, val) == QSE_AWK_VAL_MAP;
|
2009-07-11 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 02:51:23 +00:00
|
|
|
int Awk::Value::getIndexed (const Index& idx, Value* v) const
|
2009-07-11 08:05:51 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (val != QSE_NULL);
|
|
|
|
|
|
|
|
// not a map. v is just nil. not an error
|
2019-08-29 03:13:57 +00:00
|
|
|
if (QSE_AWK_RTX_GETVALTYPE(this->run->rtx, val) != QSE_AWK_VAL_MAP)
|
2014-10-22 17:05:45 +00:00
|
|
|
{
|
2009-07-14 02:51:23 +00:00
|
|
|
v->clear ();
|
2009-07-11 08:05:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the value from the map.
|
2019-08-29 03:13:57 +00:00
|
|
|
val_t* fv = qse_awk_rtx_getmapvalfld(this->run->rtx, val, (char_t*)idx.ptr, idx.len);
|
2011-05-13 08:55:53 +00:00
|
|
|
|
|
|
|
// the key is not found. it is not an error. v is just nil
|
|
|
|
if (fv == QSE_NULL)
|
|
|
|
{
|
|
|
|
v->clear ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if v.set fails, it should return an error
|
2011-05-13 22:06:55 +00:00
|
|
|
return v->setVal (this->run, fv);
|
2009-07-14 02:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Awk::Value::IndexIterator Awk::Value::getFirstIndex (Index* idx) const
|
|
|
|
{
|
2011-05-13 22:06:55 +00:00
|
|
|
QSE_ASSERT (this->val != QSE_NULL);
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2014-10-23 09:30:22 +00:00
|
|
|
if (QSE_AWK_RTX_GETVALTYPE (this->run->rtx, this->val) != QSE_AWK_VAL_MAP) return IndexIterator::END;
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2011-05-13 22:06:55 +00:00
|
|
|
QSE_ASSERT (this->run != QSE_NULL);
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2011-05-13 22:06:55 +00:00
|
|
|
Awk::Value::IndexIterator itr;
|
|
|
|
qse_awk_val_map_itr_t* iptr;
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
iptr = qse_awk_rtx_getfirstmapvalitr(this->run->rtx, this->val, &itr);
|
2011-05-13 22:06:55 +00:00
|
|
|
if (iptr == QSE_NULL) return IndexIterator::END; // no more key
|
|
|
|
|
2011-05-24 22:22:40 +00:00
|
|
|
idx->set (QSE_AWK_VAL_MAP_ITR_KEY(iptr));
|
2011-05-13 22:06:55 +00:00
|
|
|
|
|
|
|
return itr;
|
2009-07-14 02:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Awk::Value::IndexIterator Awk::Value::getNextIndex (
|
2011-05-13 22:06:55 +00:00
|
|
|
Index* idx, const IndexIterator& curitr) const
|
2009-07-14 02:51:23 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (val != QSE_NULL);
|
|
|
|
|
2014-10-23 09:30:22 +00:00
|
|
|
if (QSE_AWK_RTX_GETVALTYPE (this->run->rtx, val) != QSE_AWK_VAL_MAP) return IndexIterator::END;
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2011-05-13 22:06:55 +00:00
|
|
|
QSE_ASSERT (this->run != QSE_NULL);
|
|
|
|
|
|
|
|
Awk::Value::IndexIterator itr (curitr);
|
|
|
|
qse_awk_val_map_itr_t* iptr;
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
iptr = qse_awk_rtx_getnextmapvalitr(this->run->rtx, this->val, &itr);
|
2011-05-13 22:06:55 +00:00
|
|
|
if (iptr == QSE_NULL) return IndexIterator::END; // no more key
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2011-05-24 22:22:40 +00:00
|
|
|
idx->set (QSE_AWK_VAL_MAP_ITR_KEY(iptr));
|
2009-07-14 02:51:23 +00:00
|
|
|
|
2011-05-13 22:06:55 +00:00
|
|
|
return itr;
|
2007-10-04 23:26:00 +00:00
|
|
|
}
|
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk::Run
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2007-05-11 10:07:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Awk::Run::Run (Awk* awk): awk (awk), rtx (QSE_NULL)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-12 19:14:00 +00:00
|
|
|
|
2009-07-09 07:01:45 +00:00
|
|
|
Awk::Run::Run (Awk* awk, rtx_t* rtx): awk (awk), rtx (rtx)
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2007-09-25 00:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Awk::Run::~Run ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-10 16:03:00 +00:00
|
|
|
Awk::Run::operator Awk* () const
|
|
|
|
{
|
|
|
|
return this->awk;
|
|
|
|
}
|
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
Awk::Run::operator Awk::rtx_t* () const
|
2007-10-10 16:03:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
return this->rtx;
|
2007-10-10 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 07:55:32 +00:00
|
|
|
void Awk::Run::halt () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2019-11-12 07:55:32 +00:00
|
|
|
qse_awk_rtx_halt (this->rtx);
|
2007-10-12 00:13:00 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 07:55:32 +00:00
|
|
|
bool Awk::Run::isHalt () const
|
2007-10-12 00:13:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2019-11-12 07:55:32 +00:00
|
|
|
return qse_awk_rtx_ishalt (this->rtx)? true: false;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-11 10:07:00 +00:00
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
Awk::errnum_t Awk::Run::getErrorNumber () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2009-09-16 04:01:02 +00:00
|
|
|
return qse_awk_rtx_geterrnum (this->rtx);
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2009-08-26 03:50:07 +00:00
|
|
|
Awk::loc_t Awk::Run::getErrorLocation () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2009-08-26 03:50:07 +00:00
|
|
|
return *qse_awk_rtx_geterrloc (this->rtx);
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-21 01:22:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
const Awk::char_t* Awk::Run::getErrorMessage () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
|
|
|
return qse_awk_rtx_geterrmsg (this->rtx);
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
void Awk::Run::setError (errnum_t code, const cstr_t* args, const loc_t* loc)
|
2007-10-10 22:33:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2009-09-16 04:01:02 +00:00
|
|
|
qse_awk_rtx_seterror (this->rtx, code, args, loc);
|
2007-10-02 00:22:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
void Awk::Run::setErrorWithMessage (
|
2009-09-16 04:01:02 +00:00
|
|
|
errnum_t code, const char_t* msg, const loc_t* loc)
|
2007-10-02 00:22:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2009-06-15 02:40:52 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
errinf_t errinf;
|
2009-06-15 02:40:52 +00:00
|
|
|
|
2009-08-26 03:50:07 +00:00
|
|
|
QSE_MEMSET (&errinf, 0, QSE_SIZEOF(errinf));
|
2009-09-16 04:01:02 +00:00
|
|
|
errinf.num = code;
|
2009-08-26 03:50:07 +00:00
|
|
|
if (loc == QSE_NULL) errinf.loc = *loc;
|
2009-06-15 02:40:52 +00:00
|
|
|
qse_strxcpy (errinf.msg, QSE_COUNTOF(errinf.msg), msg);
|
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
qse_awk_rtx_seterrinf (this->rtx, &errinf);
|
2007-10-02 00:22:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:45 +00:00
|
|
|
int Awk::Run::setGlobal (int id, int_t v)
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2009-07-11 08:05:51 +00:00
|
|
|
val_t* tmp = qse_awk_rtx_makeintval (this->rtx, v);
|
2008-12-21 21:35:07 +00:00
|
|
|
if (tmp == QSE_NULL) return -1;
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
qse_awk_rtx_refupval (this->rtx, tmp);
|
|
|
|
int n = qse_awk_rtx_setgbl (this->rtx, id, tmp);
|
|
|
|
qse_awk_rtx_refdownval (this->rtx, tmp);
|
2007-09-25 00:12:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
int Awk::Run::setGlobal (int id, flt_t v)
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
val_t* tmp = qse_awk_rtx_makefltval (this->rtx, v);
|
2008-12-21 21:35:07 +00:00
|
|
|
if (tmp == QSE_NULL) return -1;
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
qse_awk_rtx_refupval (this->rtx, tmp);
|
|
|
|
int n = qse_awk_rtx_setgbl (this->rtx, id, tmp);
|
|
|
|
qse_awk_rtx_refdownval (this->rtx, tmp);
|
2007-09-25 00:12:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::Run::setGlobal (int id, const char_t* ptr, size_t len)
|
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2009-07-11 08:05:51 +00:00
|
|
|
val_t* tmp = qse_awk_rtx_makestrval (this->rtx, ptr, len);
|
2008-12-21 21:35:07 +00:00
|
|
|
if (tmp == QSE_NULL) return -1;
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
qse_awk_rtx_refupval (this->rtx, tmp);
|
|
|
|
int n = qse_awk_rtx_setgbl (this->rtx, id, tmp);
|
|
|
|
qse_awk_rtx_refdownval (this->rtx, tmp);
|
2007-09-25 00:12:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
int Awk::Run::setGlobal (int id, const Value& gbl)
|
2007-10-08 18:50:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2009-07-13 07:06:01 +00:00
|
|
|
return qse_awk_rtx_setgbl (this->rtx, id, (val_t*)gbl);
|
2007-10-08 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
int Awk::Run::getGlobal (int id, Value& g) const
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2009-07-07 06:37:25 +00:00
|
|
|
QSE_ASSERT (this->rtx != QSE_NULL);
|
2009-07-13 07:06:01 +00:00
|
|
|
return g.setVal ((Run*)this, qse_awk_rtx_getgbl (this->rtx, id));
|
2007-10-08 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Awk
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-12-19 06:34:42 +00:00
|
|
|
Awk::Awk (Mmgr* mmgr):
|
2015-03-11 13:33:23 +00:00
|
|
|
Mmged (mmgr), awk (QSE_NULL),
|
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
functionMap (QSE_NULL),
|
|
|
|
#else
|
|
|
|
functionMap (this),
|
|
|
|
#endif
|
2012-06-06 14:41:21 +00:00
|
|
|
source_reader (QSE_NULL), source_writer (QSE_NULL),
|
|
|
|
pipe_handler (QSE_NULL), file_handler (QSE_NULL),
|
|
|
|
console_handler (QSE_NULL), runctx (this)
|
2007-09-11 22:42:00 +00:00
|
|
|
|
|
|
|
{
|
2009-08-26 03:50:07 +00:00
|
|
|
QSE_MEMSET (&errinf, 0, QSE_SIZEOF(errinf));
|
2009-09-16 04:01:02 +00:00
|
|
|
errinf.num = QSE_AWK_ENOERR;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-21 01:22:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
Awk::operator Awk::awk_t* () const
|
2007-10-10 16:03:00 +00:00
|
|
|
{
|
|
|
|
return this->awk;
|
|
|
|
}
|
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
const Awk::char_t* Awk::getErrorString (errnum_t num) const
|
2009-07-15 08:08:48 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
QSE_ASSERT (dflerrstr != QSE_NULL);
|
2009-09-16 04:01:02 +00:00
|
|
|
return dflerrstr (awk, num);
|
2009-07-15 08:08:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-24 08:53:49 +00:00
|
|
|
const Awk::char_t* Awk::xerrstr (awk_t* a, errnum_t num)
|
2009-07-15 08:08:48 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
Awk* awk = *(Awk**)GET_XTN(a);
|
2009-09-16 04:01:02 +00:00
|
|
|
return awk->getErrorString (num);
|
2009-07-15 08:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
Awk::errnum_t Awk::getErrorNumber () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-09-16 04:01:02 +00:00
|
|
|
return this->errinf.num;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-26 03:50:07 +00:00
|
|
|
Awk::loc_t Awk::getErrorLocation () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-08-26 03:50:07 +00:00
|
|
|
return this->errinf.loc;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
const Awk::char_t* Awk::getErrorMessage () const
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-07-16 04:43:31 +00:00
|
|
|
return this->errinf.msg;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 14:30:42 +00:00
|
|
|
void Awk::setError (errnum_t code, const cstr_t* args, const loc_t* loc)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (awk != QSE_NULL)
|
2007-05-21 01:22:00 +00:00
|
|
|
{
|
2009-09-16 04:01:02 +00:00
|
|
|
qse_awk_seterror (awk, code, args, loc);
|
2015-03-12 06:39:16 +00:00
|
|
|
this->retrieveError ();
|
2007-05-21 01:22:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
else
|
2007-05-21 01:22:00 +00:00
|
|
|
{
|
2009-08-26 03:50:07 +00:00
|
|
|
QSE_MEMSET (&errinf, 0, QSE_SIZEOF(errinf));
|
2009-09-16 04:01:02 +00:00
|
|
|
errinf.num = code;
|
2009-08-26 03:50:07 +00:00
|
|
|
if (loc != QSE_NULL) errinf.loc = *loc;
|
2009-07-16 04:43:31 +00:00
|
|
|
qse_strxcpy (errinf.msg, QSE_COUNTOF(errinf.msg),
|
2009-06-02 03:34:34 +00:00
|
|
|
QSE_T("not ready to set an error message"));
|
2007-05-16 01:03:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
void Awk::setErrorWithMessage (errnum_t code, const char_t* msg, const loc_t* loc)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2009-08-26 03:50:07 +00:00
|
|
|
QSE_MEMSET (&errinf, 0, QSE_SIZEOF(errinf));
|
|
|
|
|
2009-09-16 04:01:02 +00:00
|
|
|
errinf.num = code;
|
2009-08-26 03:50:07 +00:00
|
|
|
if (loc != QSE_NULL) errinf.loc = *loc;
|
|
|
|
qse_strxcpy (errinf.msg, QSE_COUNTOF(errinf.msg), msg);
|
|
|
|
|
|
|
|
if (awk != QSE_NULL) qse_awk_seterrinf (awk, &errinf);
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Awk::clearError ()
|
|
|
|
{
|
2009-08-26 03:50:07 +00:00
|
|
|
QSE_MEMSET (&errinf, 0, QSE_SIZEOF(errinf));
|
2009-09-16 04:01:02 +00:00
|
|
|
errinf.num = QSE_AWK_ENOERR;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
void Awk::retrieveError ()
|
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
if (this->awk == QSE_NULL)
|
2007-05-19 01:30:00 +00:00
|
|
|
{
|
2007-09-11 22:42:00 +00:00
|
|
|
clearError ();
|
2007-05-19 01:30:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
else
|
2007-05-19 01:30:00 +00:00
|
|
|
{
|
2009-07-16 04:43:31 +00:00
|
|
|
qse_awk_geterrinf (this->awk, &errinf);
|
2007-05-19 01:30:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-19 01:30:00 +00:00
|
|
|
|
2009-07-15 08:08:48 +00:00
|
|
|
void Awk::retrieveError (Run* run)
|
2009-02-15 08:38:00 +00:00
|
|
|
{
|
2009-07-15 08:08:48 +00:00
|
|
|
QSE_ASSERT (run != QSE_NULL);
|
|
|
|
if (run->rtx == QSE_NULL) return;
|
2009-07-16 04:43:31 +00:00
|
|
|
qse_awk_rtx_geterrinf (run->rtx, &errinf);
|
|
|
|
}
|
2009-07-15 08:08:48 +00:00
|
|
|
|
2015-03-12 02:08:51 +00:00
|
|
|
static void fini_xtn (qse_awk_t* awk)
|
|
|
|
{
|
2019-08-29 02:19:41 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2015-03-12 06:39:16 +00:00
|
|
|
xtn->awk->uponClosing ();
|
2015-03-12 02:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_xtn (qse_awk_t* awk)
|
|
|
|
{
|
2019-08-29 02:19:41 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2015-03-12 06:39:16 +00:00
|
|
|
xtn->awk->uponClearing ();
|
2015-03-12 02:08:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::open ()
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
QSE_ASSERT (this->awk == QSE_NULL);
|
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
QSE_ASSERT (this->functionMap == QSE_NULL);
|
|
|
|
#endif
|
2007-09-11 22:42:00 +00:00
|
|
|
|
2009-02-17 02:11:31 +00:00
|
|
|
qse_awk_prm_t prm;
|
2011-09-01 09:43:46 +00:00
|
|
|
|
|
|
|
QSE_MEMSET (&prm, 0, QSE_SIZEOF(prm));
|
2011-05-18 08:56:54 +00:00
|
|
|
prm.math.pow = pow;
|
2011-07-24 03:03:48 +00:00
|
|
|
prm.math.mod = mod;
|
2012-10-31 13:51:32 +00:00
|
|
|
prm.modopen = modopen;
|
|
|
|
prm.modclose = modclose;
|
2015-03-12 06:39:16 +00:00
|
|
|
prm.modsym = modsym;
|
2009-02-17 02:11:31 +00:00
|
|
|
|
2014-07-11 14:17:00 +00:00
|
|
|
qse_awk_errnum_t errnum;
|
2019-06-24 08:53:49 +00:00
|
|
|
this->awk = qse_awk_open(this->getMmgr(), QSE_SIZEOF(xtn_t), &prm, &errnum);
|
2015-06-12 13:11:50 +00:00
|
|
|
if (!this->awk)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2014-07-11 14:17:00 +00:00
|
|
|
this->setError (errnum);
|
2007-09-11 22:42:00 +00:00
|
|
|
return -1;
|
2007-05-21 01:22:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-24 08:53:49 +00:00
|
|
|
this->awk->_instsize += QSE_SIZEOF(xtn_t);
|
|
|
|
|
2009-02-15 08:38:00 +00:00
|
|
|
// associate this Awk object with the underlying awk object
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = (xtn_t*)GET_XTN(this->awk);
|
2009-02-15 08:38:00 +00:00
|
|
|
xtn->awk = this;
|
2015-03-12 02:08:51 +00:00
|
|
|
xtn->ecb.close = fini_xtn;
|
|
|
|
xtn->ecb.clear = clear_xtn;
|
2009-02-15 08:38:00 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
dflerrstr = qse_awk_geterrstr (this->awk);
|
|
|
|
qse_awk_seterrstr (this->awk, xerrstr);
|
2009-06-02 03:34:34 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
this->functionMap = qse_htb_open (
|
|
|
|
qse_awk_getmmgr(this->awk), QSE_SIZEOF(this), 512, 70,
|
2010-10-28 06:54:37 +00:00
|
|
|
QSE_SIZEOF(qse_char_t), 1
|
|
|
|
);
|
2015-03-11 13:33:23 +00:00
|
|
|
if (this->functionMap == QSE_NULL)
|
2007-05-19 01:30:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
qse_awk_close (this->awk);
|
|
|
|
this->awk = QSE_NULL;
|
2007-05-21 01:22:00 +00:00
|
|
|
|
2014-07-11 14:17:00 +00:00
|
|
|
this->setError (QSE_AWK_ENOMEM);
|
2007-09-11 22:42:00 +00:00
|
|
|
return -1;
|
2007-05-19 01:30:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
*(Awk**)QSE_XTN(this->functionMap) = this;
|
2010-10-28 06:54:37 +00:00
|
|
|
|
2013-03-11 16:34:41 +00:00
|
|
|
static qse_htb_style_t style =
|
2010-10-28 06:54:37 +00:00
|
|
|
{
|
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
QSE_HTB_COPIER_DEFAULT, // keep the key pointer only
|
|
|
|
QSE_HTB_COPIER_INLINE // copy the value into the pair
|
2010-10-28 06:54:37 +00:00
|
|
|
},
|
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
QSE_HTB_FREEER_DEFAULT, // free nothing
|
|
|
|
QSE_HTB_FREEER_DEFAULT // free nothing
|
2010-10-28 06:54:37 +00:00
|
|
|
},
|
|
|
|
QSE_HTB_COMPER_DEFAULT,
|
|
|
|
QSE_HTB_KEEPER_DEFAULT,
|
2010-10-30 07:54:36 +00:00
|
|
|
QSE_HTB_SIZER_DEFAULT,
|
|
|
|
QSE_HTB_HASHER_DEFAULT
|
2010-10-28 06:54:37 +00:00
|
|
|
};
|
2015-03-11 13:33:23 +00:00
|
|
|
qse_htb_setstyle (this->functionMap, &style);
|
|
|
|
|
|
|
|
#endif
|
2008-09-28 03:51:23 +00:00
|
|
|
|
2015-03-12 02:08:51 +00:00
|
|
|
// push the call back after everything else is ok.
|
|
|
|
qse_awk_pushecb (this->awk, &xtn->ecb);
|
2007-09-11 22:42:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::close ()
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
this->fini_runctx ();
|
|
|
|
this->clearArguments ();
|
2009-07-02 07:14:39 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
if (this->functionMap)
|
2007-08-26 23:33:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
qse_htb_close (this->functionMap);
|
|
|
|
this->functionMap = QSE_NULL;
|
2007-08-26 23:33:00 +00:00
|
|
|
}
|
2015-03-11 13:33:23 +00:00
|
|
|
#else
|
|
|
|
this->functionMap.clear ();
|
|
|
|
#endif
|
2007-08-26 23:33:00 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
if (this->awk)
|
2007-05-19 01:30:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
qse_awk_close (this->awk);
|
|
|
|
this->awk = QSE_NULL;
|
2007-05-21 01:22:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
this->clearError ();
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-19 01:30:00 +00:00
|
|
|
|
2019-04-23 15:32:23 +00:00
|
|
|
qse_cmgr_t* Awk::getCmgr () const
|
|
|
|
{
|
|
|
|
if (!this->awk) return QSE_NULL;
|
2019-06-24 08:53:49 +00:00
|
|
|
return qse_awk_getcmgr(this->awk);
|
2019-04-23 15:32:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 06:39:16 +00:00
|
|
|
void Awk::uponClosing ()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
void Awk::uponClearing ()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
Awk::Run* Awk::parse (Source& in, Source& out)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2007-08-26 23:33:00 +00:00
|
|
|
|
2009-07-14 04:03:53 +00:00
|
|
|
if (&in == &Source::NONE)
|
|
|
|
{
|
2015-03-12 06:39:16 +00:00
|
|
|
this->setError (QSE_AWK_EINVAL);
|
2009-07-14 04:03:53 +00:00
|
|
|
return QSE_NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-12 02:08:51 +00:00
|
|
|
this->fini_runctx ();
|
2007-06-24 20:14:00 +00:00
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
source_reader = ∈
|
|
|
|
source_writer = (&out == &Source::NONE)? QSE_NULL: &out;
|
2009-07-10 06:46:14 +00:00
|
|
|
|
2009-07-09 07:01:45 +00:00
|
|
|
qse_awk_sio_t sio;
|
2009-07-10 06:46:14 +00:00
|
|
|
sio.in = readSource;
|
2012-06-06 14:41:21 +00:00
|
|
|
sio.out = (source_writer == QSE_NULL)? QSE_NULL: writeSource;
|
2007-06-19 23:59:00 +00:00
|
|
|
|
2019-09-03 16:46:57 +00:00
|
|
|
int n = qse_awk_parse(awk, &sio);
|
2009-07-09 07:01:45 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2015-03-12 06:39:16 +00:00
|
|
|
this->retrieveError ();
|
2009-07-09 07:01:45 +00:00
|
|
|
return QSE_NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-03 16:46:57 +00:00
|
|
|
if (this->init_runctx() <= -1) return QSE_NULL;
|
2012-08-07 09:56:53 +00:00
|
|
|
return &this->runctx;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-06-19 23:59:00 +00:00
|
|
|
|
2012-06-05 12:56:41 +00:00
|
|
|
Awk::Run* Awk::resetRunContext ()
|
|
|
|
{
|
|
|
|
if (this->runctx.rtx)
|
|
|
|
{
|
2015-03-12 02:08:51 +00:00
|
|
|
this->fini_runctx ();
|
|
|
|
if (this->init_runctx() <= -1) return QSE_NULL;
|
2012-06-05 12:56:41 +00:00
|
|
|
return &this->runctx;
|
|
|
|
}
|
|
|
|
else return QSE_NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-17 02:27:53 +00:00
|
|
|
int Awk::loop (Value* ret)
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
2012-08-07 09:56:53 +00:00
|
|
|
QSE_ASSERT (this->awk != QSE_NULL);
|
|
|
|
QSE_ASSERT (this->runctx.rtx != QSE_NULL);
|
2009-07-16 04:43:31 +00:00
|
|
|
|
2012-08-07 09:56:53 +00:00
|
|
|
val_t* rv = qse_awk_rtx_loop (this->runctx.rtx);
|
2009-07-17 02:27:53 +00:00
|
|
|
if (rv == QSE_NULL)
|
|
|
|
{
|
2015-03-12 06:39:16 +00:00
|
|
|
this->retrieveError (&this->runctx);
|
2009-07-17 02:27:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-08-07 09:56:53 +00:00
|
|
|
ret->setVal (&this->runctx, rv);
|
|
|
|
qse_awk_rtx_refdownval (this->runctx.rtx, rv);
|
2009-07-17 02:27:53 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-07-16 04:43:31 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 02:19:41 +00:00
|
|
|
int Awk::call (const qse_mchar_t* name, Value* ret, const Value* args, size_t nargs)
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
2012-08-07 09:56:53 +00:00
|
|
|
QSE_ASSERT (this->awk != QSE_NULL);
|
|
|
|
QSE_ASSERT (this->runctx.rtx != QSE_NULL);
|
2009-07-16 04:43:31 +00:00
|
|
|
|
|
|
|
val_t* buf[16];
|
|
|
|
val_t** ptr = QSE_NULL;
|
|
|
|
|
|
|
|
if (args != QSE_NULL)
|
|
|
|
{
|
|
|
|
if (nargs <= QSE_COUNTOF(buf)) ptr = buf;
|
|
|
|
else
|
|
|
|
{
|
2019-08-27 14:52:19 +00:00
|
|
|
ptr = (val_t**)qse_awk_allocmem(awk, QSE_SIZEOF(val_t*) * nargs);
|
2009-07-16 04:43:31 +00:00
|
|
|
if (ptr == QSE_NULL)
|
|
|
|
{
|
2012-08-07 09:56:53 +00:00
|
|
|
this->runctx.setError (QSE_AWK_ENOMEM);
|
2015-03-12 06:39:16 +00:00
|
|
|
this->retrieveError (&this->runctx);
|
2009-07-16 04:43:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < nargs; i++) ptr[i] = (val_t*)args[i];
|
|
|
|
}
|
|
|
|
|
2019-08-29 02:19:41 +00:00
|
|
|
val_t* rv = qse_awk_rtx_callwithmbs(this->runctx.rtx, name, ptr, nargs);
|
|
|
|
|
|
|
|
if (ptr != QSE_NULL && ptr != buf) qse_awk_freemem (awk, ptr);
|
|
|
|
|
|
|
|
if (rv == QSE_NULL)
|
|
|
|
{
|
|
|
|
this->retrieveError (&this->runctx);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->setVal (&this->runctx, rv);
|
|
|
|
|
|
|
|
qse_awk_rtx_refdownval (this->runctx.rtx, rv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::call (const qse_wchar_t* name, Value* ret, const Value* args, size_t nargs)
|
|
|
|
{
|
|
|
|
QSE_ASSERT (this->awk != QSE_NULL);
|
|
|
|
QSE_ASSERT (this->runctx.rtx != QSE_NULL);
|
|
|
|
|
|
|
|
val_t* buf[16];
|
|
|
|
val_t** ptr = QSE_NULL;
|
|
|
|
|
|
|
|
if (args != QSE_NULL)
|
|
|
|
{
|
|
|
|
if (nargs <= QSE_COUNTOF(buf)) ptr = buf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr = (val_t**)qse_awk_allocmem(awk, QSE_SIZEOF(val_t*) * nargs);
|
|
|
|
if (ptr == QSE_NULL)
|
|
|
|
{
|
|
|
|
this->runctx.setError (QSE_AWK_ENOMEM);
|
|
|
|
this->retrieveError (&this->runctx);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < nargs; i++) ptr[i] = (val_t*)args[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
val_t* rv = qse_awk_rtx_callwithwcs(this->runctx.rtx, name, ptr, nargs);
|
2009-07-16 04:43:31 +00:00
|
|
|
|
2011-07-21 10:17:16 +00:00
|
|
|
if (ptr != QSE_NULL && ptr != buf) qse_awk_freemem (awk, ptr);
|
2009-07-16 04:43:31 +00:00
|
|
|
|
|
|
|
if (rv == QSE_NULL)
|
|
|
|
{
|
2015-03-12 06:39:16 +00:00
|
|
|
this->retrieveError (&this->runctx);
|
2009-07-16 04:43:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-08-07 09:56:53 +00:00
|
|
|
ret->setVal (&this->runctx, rv);
|
2009-07-16 04:43:31 +00:00
|
|
|
|
2012-08-07 09:56:53 +00:00
|
|
|
qse_awk_rtx_refdownval (this->runctx.rtx, rv);
|
2009-07-16 04:43:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-12 07:55:32 +00:00
|
|
|
void Awk::halt ()
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2019-11-12 07:55:32 +00:00
|
|
|
qse_awk_haltall (awk);
|
2009-07-16 04:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::init_runctx ()
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2012-06-05 12:56:41 +00:00
|
|
|
if (this->runctx.rtx) return 0;
|
2007-06-29 20:40:00 +00:00
|
|
|
|
2009-02-12 04:46:24 +00:00
|
|
|
qse_awk_rio_t rio;
|
2007-10-08 00:27:00 +00:00
|
|
|
|
2009-02-12 04:46:24 +00:00
|
|
|
rio.pipe = pipeHandler;
|
|
|
|
rio.file = fileHandler;
|
|
|
|
rio.console = consoleHandler;
|
2007-06-29 20:40:00 +00:00
|
|
|
|
2019-06-09 05:55:36 +00:00
|
|
|
rtx_t* rtx = qse_awk_rtx_open(awk, QSE_SIZEOF(rxtn_t), &rio);
|
2009-02-13 04:55:25 +00:00
|
|
|
if (rtx == QSE_NULL)
|
|
|
|
{
|
2015-03-12 06:39:16 +00:00
|
|
|
this->retrieveError();
|
2009-07-09 07:01:45 +00:00
|
|
|
return -1;
|
2009-02-13 04:55:25 +00:00
|
|
|
}
|
2009-02-16 08:31:34 +00:00
|
|
|
|
2019-09-03 16:46:57 +00:00
|
|
|
rtx->_instsize += QSE_SIZEOF(rxtn_t);
|
2009-07-09 07:01:45 +00:00
|
|
|
runctx.rtx = rtx;
|
|
|
|
|
2019-06-24 08:53:49 +00:00
|
|
|
rxtn_t* rxtn = GET_RXTN(rtx);
|
2009-07-09 07:01:45 +00:00
|
|
|
rxtn->run = &runctx;
|
2009-02-13 04:55:25 +00:00
|
|
|
|
2009-07-09 07:01:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::fini_runctx ()
|
2009-07-09 07:01:45 +00:00
|
|
|
{
|
2012-06-05 12:56:41 +00:00
|
|
|
if (this->runctx.rtx)
|
2009-07-09 07:01:45 +00:00
|
|
|
{
|
2012-06-05 12:56:41 +00:00
|
|
|
qse_awk_rtx_close (this->runctx.rtx);
|
|
|
|
this->runctx.rtx = QSE_NULL;
|
2009-02-13 04:55:25 +00:00
|
|
|
}
|
2009-07-09 07:01:45 +00:00
|
|
|
}
|
2009-02-13 04:55:25 +00:00
|
|
|
|
2012-10-21 16:19:03 +00:00
|
|
|
int Awk::getTrait () const
|
2009-07-09 07:01:45 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2012-10-21 16:19:03 +00:00
|
|
|
int val;
|
|
|
|
qse_awk_getopt (awk, QSE_AWK_TRAIT, &val);
|
|
|
|
return val;
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2012-10-21 16:19:03 +00:00
|
|
|
void Awk::setTrait (int trait)
|
2009-07-09 07:01:45 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2012-10-21 16:19:03 +00:00
|
|
|
qse_awk_setopt (awk, QSE_AWK_TRAIT, &trait);
|
2009-07-16 04:43:31 +00:00
|
|
|
}
|
2009-07-13 07:06:01 +00:00
|
|
|
|
2012-10-21 16:19:03 +00:00
|
|
|
Awk::size_t Awk::getMaxDepth (depth_t id) const
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2012-10-21 16:19:03 +00:00
|
|
|
|
|
|
|
size_t depth;
|
|
|
|
qse_awk_getopt (awk, (qse_awk_opt_t)id, &depth);
|
|
|
|
return depth;
|
2009-07-09 07:01:45 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 16:19:03 +00:00
|
|
|
void Awk::setMaxDepth (depth_t id, size_t depth)
|
2007-10-12 00:13:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2012-10-21 16:19:03 +00:00
|
|
|
qse_awk_setopt (awk, (qse_awk_opt_t)id, &depth);
|
2007-10-12 00:13:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 17:08:56 +00:00
|
|
|
int Awk::dispatch_function (Run* run, const fnc_info_t* fi)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2013-01-07 08:33:48 +00:00
|
|
|
bool has_ref_arg = false;
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
qse_htb_pair_t* pair;
|
|
|
|
pair = qse_htb_search (this->functionMap, fi->name.ptr, fi->name.len);
|
2008-12-21 21:35:07 +00:00
|
|
|
if (pair == QSE_NULL)
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2014-07-02 12:28:58 +00:00
|
|
|
run->setError (QSE_AWK_EFUNNF, &fi->name);
|
2007-09-25 00:12:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-03-11 13:33:23 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
FunctionHandler handler;
|
2015-03-10 09:00:21 +00:00
|
|
|
handler = *(FunctionHandler*)QSE_HTB_VPTR(pair);
|
2015-03-11 13:33:23 +00:00
|
|
|
#else
|
|
|
|
FunctionMap::Pair* pair = this->functionMap.search (Cstr(fi->name.ptr, fi->name.len));
|
|
|
|
if (pair == QSE_NULL)
|
|
|
|
{
|
|
|
|
run->setError (QSE_AWK_EFUNNF, &fi->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionHandler handler;
|
|
|
|
handler = pair->value;
|
|
|
|
#endif
|
2007-05-09 00:09:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
size_t i, nargs = qse_awk_rtx_getnargs(run->rtx);
|
2007-09-11 22:42:00 +00:00
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
Value buf[16];
|
|
|
|
Value* args;
|
|
|
|
if (nargs <= QSE_COUNTOF(buf)) args = buf;
|
|
|
|
else
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
#if defined(AWK_VALUE_USE_IN_CLASS_PLACEMENT_NEW)
|
2009-07-13 07:06:01 +00:00
|
|
|
args = new(run) Value[nargs];
|
|
|
|
if (args == QSE_NULL)
|
|
|
|
{
|
2009-09-16 04:01:02 +00:00
|
|
|
run->setError (QSE_AWK_ENOMEM);
|
2009-07-13 07:06:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-03-11 13:33:23 +00:00
|
|
|
#else
|
2015-03-23 15:14:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
//args = (Value*)::operator new (QSE_SIZEOF(Value) * nargs, this->getMmgr());
|
2019-08-29 03:13:57 +00:00
|
|
|
args = (Value*)this->getMmgr()->allocate(QSE_SIZEOF(Value) * nargs);
|
2015-03-23 15:14:43 +00:00
|
|
|
}
|
2015-03-11 13:33:23 +00:00
|
|
|
catch (...) { args = QSE_NULL; }
|
|
|
|
if (args == QSE_NULL)
|
|
|
|
{
|
|
|
|
run->setError (QSE_AWK_ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
{
|
|
|
|
// call the default constructor on the space allocated above.
|
|
|
|
// no exception handling is implemented here as i know
|
|
|
|
// that Value::Value() doesn't throw an exception
|
|
|
|
new((QSE::Mmgr*)QSE_NULL, (void*)&args[i]) Value ();
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-25 00:12:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
{
|
2013-01-07 08:33:48 +00:00
|
|
|
int xx;
|
2009-07-07 06:37:25 +00:00
|
|
|
val_t* v = qse_awk_rtx_getarg (run->rtx, i);
|
2013-01-07 08:33:48 +00:00
|
|
|
|
2014-10-23 09:30:22 +00:00
|
|
|
if (QSE_AWK_RTX_GETVALTYPE (run->rtx, v) == QSE_AWK_VAL_REF)
|
2009-07-17 02:27:53 +00:00
|
|
|
{
|
2013-01-07 08:33:48 +00:00
|
|
|
qse_awk_val_ref_t* ref = (qse_awk_val_ref_t*)v;
|
|
|
|
|
2013-04-16 15:30:37 +00:00
|
|
|
switch (ref->id)
|
2013-01-07 08:33:48 +00:00
|
|
|
{
|
2013-04-16 15:30:37 +00:00
|
|
|
case qse_awk_val_ref_t::QSE_AWK_VAL_REF_POS:
|
2013-01-07 08:33:48 +00:00
|
|
|
{
|
2013-04-16 15:30:37 +00:00
|
|
|
qse_size_t idx = (qse_size_t)ref->adr;
|
|
|
|
|
|
|
|
if (idx == 0)
|
|
|
|
{
|
|
|
|
xx = args[i].setStr (run,
|
|
|
|
QSE_STR_PTR(&run->rtx->inrec.line),
|
|
|
|
QSE_STR_LEN(&run->rtx->inrec.line));
|
|
|
|
}
|
|
|
|
else if (idx <= run->rtx->inrec.nflds)
|
|
|
|
{
|
|
|
|
xx = args[i].setStr (run,
|
|
|
|
run->rtx->inrec.flds[idx-1].ptr,
|
|
|
|
run->rtx->inrec.flds[idx-1].len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-29 08:46:23 +00:00
|
|
|
xx = args[i].setStr (run, QSE_T(""), (size_t)0);
|
2013-04-16 15:30:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-01-07 08:33:48 +00:00
|
|
|
}
|
2013-04-16 15:30:37 +00:00
|
|
|
|
|
|
|
case qse_awk_val_ref_t::QSE_AWK_VAL_REF_GBL:
|
2013-01-07 08:33:48 +00:00
|
|
|
{
|
2013-04-16 15:30:37 +00:00
|
|
|
qse_size_t idx = (qse_size_t)ref->adr;
|
2019-08-29 03:13:57 +00:00
|
|
|
qse_awk_val_t* val = (qse_awk_val_t*)RTX_STACK_GBL(run->rtx, idx);
|
2013-04-16 15:30:37 +00:00
|
|
|
xx = args[i].setVal (run, val);
|
|
|
|
break;
|
2013-01-07 08:33:48 +00:00
|
|
|
}
|
2015-03-11 13:33:23 +00:00
|
|
|
|
2013-04-16 15:30:37 +00:00
|
|
|
default:
|
|
|
|
xx = args[i].setVal (run, *(ref->adr));
|
|
|
|
break;
|
2013-01-07 08:33:48 +00:00
|
|
|
}
|
|
|
|
has_ref_arg = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xx = args[i].setVal (run, v);
|
2009-07-17 02:27:53 +00:00
|
|
|
}
|
2013-01-07 08:33:48 +00:00
|
|
|
|
|
|
|
if (xx <= -1)
|
2007-05-09 00:09:00 +00:00
|
|
|
{
|
2009-09-16 04:01:02 +00:00
|
|
|
run->setError (QSE_AWK_ENOMEM);
|
2009-07-13 07:06:01 +00:00
|
|
|
if (args != buf) delete[] args;
|
2007-09-11 22:42:00 +00:00
|
|
|
return -1;
|
2007-05-09 00:09:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
Value ret (run);
|
2007-09-25 00:12:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int n;
|
|
|
|
|
2012-10-23 17:08:56 +00:00
|
|
|
try { n = (this->*handler) (*run, ret, args, nargs, fi); }
|
2009-07-16 04:43:31 +00:00
|
|
|
catch (...) { n = -1; }
|
2007-09-11 22:42:00 +00:00
|
|
|
|
2013-01-07 08:33:48 +00:00
|
|
|
if (n >= 0 && has_ref_arg)
|
2009-07-17 02:27:53 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
{
|
|
|
|
QSE_ASSERTX (args[i].run == run,
|
2013-01-07 08:33:48 +00:00
|
|
|
"Do NOT change the run field from function handler");
|
2009-07-17 02:27:53 +00:00
|
|
|
|
2019-08-29 03:13:57 +00:00
|
|
|
val_t* v = qse_awk_rtx_getarg(run->rtx, i);
|
|
|
|
if (QSE_AWK_RTX_GETVALTYPE(run->rtx, v) == QSE_AWK_VAL_REF)
|
2013-01-07 08:33:48 +00:00
|
|
|
{
|
2019-08-29 03:13:57 +00:00
|
|
|
if (qse_awk_rtx_setrefval(run->rtx, (qse_awk_val_ref_t*)v, args[i].toVal()) <= -1)
|
2013-01-07 08:33:48 +00:00
|
|
|
{
|
|
|
|
n = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 02:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-07 08:33:48 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
if (args != buf)
|
|
|
|
{
|
|
|
|
#if defined(AWK_VALUE_USE_IN_CLASS_PLACEMENT_NEW)
|
|
|
|
delete[] args;
|
|
|
|
#else
|
|
|
|
for (i = nargs; i > 0; )
|
|
|
|
{
|
|
|
|
--i;
|
2015-03-23 15:14:43 +00:00
|
|
|
args[i].Value::~Value ();
|
2015-03-11 13:33:23 +00:00
|
|
|
}
|
2015-03-23 15:14:43 +00:00
|
|
|
|
|
|
|
//::operator delete (args, this->getMmgr());
|
|
|
|
this->getMmgr()->dispose (args);
|
2015-03-11 13:33:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
2007-05-09 00:09:00 +00:00
|
|
|
|
2007-09-25 00:12:00 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
|
|
|
/* this is really the handler error. the underlying engine
|
|
|
|
* will take care of the error code. */
|
|
|
|
return -1;
|
|
|
|
}
|
2007-05-09 00:09:00 +00:00
|
|
|
|
2009-07-13 07:06:01 +00:00
|
|
|
qse_awk_rtx_setretval (run->rtx, ret.toVal());
|
2007-09-11 22:42:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::xstrs_t::add (awk_t* awk, const char_t* arg, size_t len)
|
2009-07-02 07:14:39 +00:00
|
|
|
{
|
2009-07-08 07:05:10 +00:00
|
|
|
if (this->len >= this->capa)
|
2009-07-02 07:14:39 +00:00
|
|
|
{
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_cstr_t* ptr;
|
2009-07-08 07:05:10 +00:00
|
|
|
size_t capa = this->capa;
|
2009-07-02 07:14:39 +00:00
|
|
|
|
|
|
|
capa += 64;
|
2019-08-29 03:13:57 +00:00
|
|
|
ptr = (qse_cstr_t*)qse_awk_reallocmem(awk, this->ptr, QSE_SIZEOF(qse_cstr_t)*(capa+1));
|
2009-07-08 07:05:10 +00:00
|
|
|
if (ptr == QSE_NULL) return -1;
|
2009-07-02 07:14:39 +00:00
|
|
|
|
2009-07-08 07:05:10 +00:00
|
|
|
this->ptr = ptr;
|
|
|
|
this->capa = capa;
|
2009-07-02 07:14:39 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 07:05:10 +00:00
|
|
|
this->ptr[this->len].len = len;
|
2019-08-29 03:13:57 +00:00
|
|
|
this->ptr[this->len].ptr = qse_awk_strxdup(awk, arg, len);
|
2009-07-08 07:05:10 +00:00
|
|
|
if (this->ptr[this->len].ptr == QSE_NULL) return -1;
|
2009-07-02 07:14:39 +00:00
|
|
|
|
2009-07-08 07:05:10 +00:00
|
|
|
this->len++;
|
|
|
|
this->ptr[this->len].len = 0;
|
|
|
|
this->ptr[this->len].ptr = QSE_NULL;
|
2009-07-02 07:14:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::xstrs_t::clear (awk_t* awk)
|
2009-07-08 07:05:10 +00:00
|
|
|
{
|
|
|
|
if (this->ptr != QSE_NULL)
|
|
|
|
{
|
2009-07-09 07:01:45 +00:00
|
|
|
while (this->len > 0)
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_freemem (awk, this->ptr[--this->len].ptr);
|
2009-07-09 07:01:45 +00:00
|
|
|
|
2011-07-21 10:17:16 +00:00
|
|
|
qse_awk_freemem (awk, this->ptr);
|
2009-07-08 07:05:10 +00:00
|
|
|
this->ptr = QSE_NULL;
|
|
|
|
this->capa = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::addArgument (const char_t* arg, size_t len)
|
2009-07-08 07:05:10 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2019-08-28 14:01:28 +00:00
|
|
|
int n = runarg.add(awk, arg, len);
|
2015-03-12 06:39:16 +00:00
|
|
|
if (n <= -1) this->setError (QSE_AWK_ENOMEM);
|
2009-07-08 07:05:10 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::addArgument (const char_t* arg)
|
2009-07-02 07:14:39 +00:00
|
|
|
{
|
2019-08-28 14:01:28 +00:00
|
|
|
return addArgument(arg, qse_strlen(arg));
|
2009-07-02 07:14:39 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
void Awk::clearArguments ()
|
2009-07-02 07:14:39 +00:00
|
|
|
{
|
2009-07-08 07:05:10 +00:00
|
|
|
runarg.clear (awk);
|
2009-07-02 07:14:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 14:01:28 +00:00
|
|
|
int Awk::addGlobal(const qse_mchar_t* name)
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2019-08-28 14:01:28 +00:00
|
|
|
int n = qse_awk_addgblwithmbs(awk, name);
|
2015-03-12 06:39:16 +00:00
|
|
|
if (n <= -1) this->retrieveError ();
|
2007-09-25 00:12:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-08-28 14:01:28 +00:00
|
|
|
int Awk::addGlobal(const qse_wchar_t* name)
|
2007-09-25 00:12:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2019-08-28 14:01:28 +00:00
|
|
|
int n = qse_awk_addgblwithwcs(awk, name);
|
2015-03-12 06:39:16 +00:00
|
|
|
if (n <= -1) this->retrieveError ();
|
2009-07-15 02:06:14 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-08-28 14:01:28 +00:00
|
|
|
int Awk::deleteGlobal (const qse_mchar_t* name)
|
2010-07-09 00:58:44 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2019-08-28 14:01:28 +00:00
|
|
|
int n = qse_awk_delgblwithmbs(awk, name);
|
|
|
|
if (n <= -1) this->retrieveError ();
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::deleteGlobal (const qse_wchar_t* name)
|
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
int n = qse_awk_delgblwithwcs(awk, name);
|
|
|
|
if (n <= -1) this->retrieveError ();
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Awk::findGlobal (const qse_mchar_t* name)
|
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
int n = qse_awk_findgblwithmbs(awk, name);
|
|
|
|
if (n <= -1) this->retrieveError ();
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::findGlobal (const qse_wchar_t* name)
|
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
int n = qse_awk_findgblwithwcs(awk, name);
|
2015-03-12 06:39:16 +00:00
|
|
|
if (n <= -1) this->retrieveError ();
|
2010-07-09 00:58:44 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::setGlobal (int id, const Value& v)
|
2009-07-15 02:06:14 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
QSE_ASSERT (runctx.rtx != QSE_NULL);
|
|
|
|
|
|
|
|
if (v.run != &runctx)
|
|
|
|
{
|
2015-03-12 06:39:16 +00:00
|
|
|
this->setError (QSE_AWK_EINVAL);
|
2009-07-15 02:06:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int n = runctx.setGlobal (id, v);
|
2015-03-12 06:39:16 +00:00
|
|
|
if (n <= -1) this->retrieveError ();
|
2009-07-15 02:06:14 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::getGlobal (int id, Value& v)
|
2009-07-15 02:06:14 +00:00
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
QSE_ASSERT (runctx.rtx != QSE_NULL);
|
|
|
|
|
|
|
|
int n = runctx.getGlobal (id, v);
|
2015-03-12 06:39:16 +00:00
|
|
|
if (n <= -1) this->retrieveError ();
|
2007-09-25 00:12:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
int Awk::addFunction (
|
2019-08-28 14:01:28 +00:00
|
|
|
const qse_mchar_t* name, size_t minArgs, size_t maxArgs,
|
|
|
|
const qse_mchar_t* argSpec, FunctionHandler handler, int validOpts)
|
|
|
|
{
|
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
|
|
|
|
|
|
|
qse_awk_fnc_mspec_t spec;
|
|
|
|
|
|
|
|
QSE_MEMSET (&spec, 0, QSE_SIZEOF(spec));
|
|
|
|
spec.arg.min = minArgs;
|
|
|
|
spec.arg.max = maxArgs;
|
|
|
|
spec.arg.spec = argSpec;
|
|
|
|
spec.impl = this->functionHandler;
|
|
|
|
spec.trait = validOpts;
|
|
|
|
|
|
|
|
qse_awk_fnc_t* fnc = qse_awk_addfncwithmbs(awk, name, &spec);
|
|
|
|
if (fnc == QSE_NULL)
|
|
|
|
{
|
|
|
|
this->retrieveError ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
// handler is a pointer to a member function.
|
|
|
|
// sizeof(handler) is likely to be greater than sizeof(void*)
|
|
|
|
// copy the handler pointer into the table.
|
|
|
|
//
|
|
|
|
// the function name exists in the underlying function table.
|
|
|
|
// use the pointer to the name to maintain the hash table.
|
|
|
|
qse_htb_pair_t* pair = qse_htb_upsert(this->functionMap, (char_t*)fnc->name.ptr, fnc->name.len, &handler, QSE_SIZEOF(handler));
|
|
|
|
#else
|
|
|
|
FunctionMap::Pair* pair;
|
|
|
|
try { pair = this->functionMap.upsert(Cstr(fnc->name.ptr, fnc->name.len), handler); }
|
|
|
|
catch (...) { pair = QSE_NULL; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pair == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_awk_delfncwithmbs (awk, name);
|
|
|
|
this->setError (QSE_AWK_ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::addFunction (
|
|
|
|
const qse_wchar_t* name, size_t minArgs, size_t maxArgs,
|
|
|
|
const qse_wchar_t* argSpec, FunctionHandler handler, int validOpts)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2007-05-09 00:09:00 +00:00
|
|
|
|
2019-08-28 14:01:28 +00:00
|
|
|
qse_awk_fnc_wspec_t spec;
|
2012-11-03 17:44:23 +00:00
|
|
|
|
|
|
|
QSE_MEMSET (&spec, 0, QSE_SIZEOF(spec));
|
|
|
|
spec.arg.min = minArgs;
|
|
|
|
spec.arg.max = maxArgs;
|
2013-01-07 08:33:48 +00:00
|
|
|
spec.arg.spec = argSpec;
|
2014-07-11 07:42:28 +00:00
|
|
|
spec.impl = this->functionHandler;
|
2012-11-03 17:44:23 +00:00
|
|
|
spec.trait = validOpts;
|
|
|
|
|
2019-08-28 14:01:28 +00:00
|
|
|
qse_awk_fnc_t* fnc = qse_awk_addfncwithwcs(awk, name, &spec);
|
2012-11-06 04:30:35 +00:00
|
|
|
if (fnc == QSE_NULL)
|
2007-05-06 19:44:00 +00:00
|
|
|
{
|
2015-03-11 13:33:23 +00:00
|
|
|
this->retrieveError ();
|
2007-09-11 22:42:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-05-07 01:05:00 +00:00
|
|
|
|
2015-03-11 13:33:23 +00:00
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
// handler is a pointer to a member function.
|
|
|
|
// sizeof(handler) is likely to be greater than sizeof(void*)
|
|
|
|
// copy the handler pointer into the table.
|
|
|
|
//
|
|
|
|
// the function name exists in the underlying function table.
|
|
|
|
// use the pointer to the name to maintain the hash table.
|
2019-08-28 14:01:28 +00:00
|
|
|
qse_htb_pair_t* pair = qse_htb_upsert(this->functionMap, (char_t*)fnc->name.ptr, fnc->name.len, &handler, QSE_SIZEOF(handler));
|
2015-03-11 13:33:23 +00:00
|
|
|
#else
|
|
|
|
FunctionMap::Pair* pair;
|
2019-08-28 14:01:28 +00:00
|
|
|
try { pair = this->functionMap.upsert(Cstr(fnc->name.ptr, fnc->name.len), handler); }
|
2015-03-11 13:33:23 +00:00
|
|
|
catch (...) { pair = QSE_NULL; }
|
|
|
|
#endif
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
if (pair == QSE_NULL)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-08-28 14:01:28 +00:00
|
|
|
qse_awk_delfncwithwcs (awk, name);
|
2015-03-11 13:33:23 +00:00
|
|
|
this->setError (QSE_AWK_ENOMEM);
|
2007-09-11 22:42:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-05-07 01:05:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-05-07 01:05:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
int Awk::deleteFunction (const char_t* name)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
QSE_ASSERT (awk != QSE_NULL);
|
2007-05-21 01:22:00 +00:00
|
|
|
|
2019-08-28 14:01:28 +00:00
|
|
|
int n = qse_awk_delfnc(awk, name);
|
2015-03-11 13:33:23 +00:00
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
#if defined(QSE_AWK_USE_HTB_FOR_FUNCTION_MAP)
|
|
|
|
qse_htb_delete (this->functionMap, name, qse_strlen(name));
|
|
|
|
#else
|
2015-03-12 02:14:13 +00:00
|
|
|
this->functionMap.remove (Cstr(name));
|
2015-03-11 13:33:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else this->retrieveError ();
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
return n;
|
|
|
|
}
|
2007-05-07 01:05:00 +00:00
|
|
|
|
2009-07-10 06:46:14 +00:00
|
|
|
Awk::ssize_t Awk::readSource (
|
2009-07-27 20:31:58 +00:00
|
|
|
awk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
|
|
|
|
char_t* data, size_t count)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2009-08-10 21:29:59 +00:00
|
|
|
Source::Data sdat (xtn->awk, Source::READ, arg);
|
2007-05-21 01:22:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
switch (cmd)
|
2007-05-21 01:22:00 +00:00
|
|
|
{
|
2009-02-17 02:11:31 +00:00
|
|
|
case QSE_AWK_SIO_OPEN:
|
2012-06-06 14:41:21 +00:00
|
|
|
return xtn->awk->source_reader->open (sdat);
|
2009-02-17 02:11:31 +00:00
|
|
|
case QSE_AWK_SIO_CLOSE:
|
2012-06-06 14:41:21 +00:00
|
|
|
return xtn->awk->source_reader->close (sdat);
|
2009-02-17 02:11:31 +00:00
|
|
|
case QSE_AWK_SIO_READ:
|
2012-06-06 14:41:21 +00:00
|
|
|
return xtn->awk->source_reader->read (sdat, data, count);
|
2009-07-10 06:46:14 +00:00
|
|
|
default:
|
2009-02-17 02:11:31 +00:00
|
|
|
return -1;
|
2007-05-21 01:22:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2009-07-10 06:46:14 +00:00
|
|
|
Awk::ssize_t Awk::writeSource (
|
2009-07-27 20:31:58 +00:00
|
|
|
awk_t* awk, qse_awk_sio_cmd_t cmd, sio_arg_t* arg,
|
|
|
|
char_t* data, size_t count)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2009-08-10 21:29:59 +00:00
|
|
|
Source::Data sdat (xtn->awk, Source::WRITE, arg);
|
2007-05-04 20:30:00 +00:00
|
|
|
|
2007-09-11 22:42:00 +00:00
|
|
|
switch (cmd)
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2009-02-17 02:11:31 +00:00
|
|
|
case QSE_AWK_SIO_OPEN:
|
2012-06-06 14:41:21 +00:00
|
|
|
return xtn->awk->source_writer->open (sdat);
|
2009-02-17 02:11:31 +00:00
|
|
|
case QSE_AWK_SIO_CLOSE:
|
2012-06-06 14:41:21 +00:00
|
|
|
return xtn->awk->source_writer->close (sdat);
|
2009-02-17 02:11:31 +00:00
|
|
|
case QSE_AWK_SIO_WRITE:
|
2012-06-06 14:41:21 +00:00
|
|
|
return xtn->awk->source_writer->write (sdat, data, count);
|
2009-07-10 06:46:14 +00:00
|
|
|
default:
|
2009-02-17 02:11:31 +00:00
|
|
|
return -1;
|
2007-05-06 19:44:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2019-04-21 05:44:53 +00:00
|
|
|
Awk::ssize_t Awk::pipeHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, size_t count)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
rxtn_t* rxtn = GET_RXTN(rtx);
|
2009-02-16 08:31:34 +00:00
|
|
|
Awk* awk = rxtn->run->awk;
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_PIPE);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Pipe pipe (rxtn->run, riod);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
try
|
2019-04-21 05:44:53 +00:00
|
|
|
{
|
2012-06-06 14:41:21 +00:00
|
|
|
if (awk->pipe_handler)
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
2012-06-06 14:41:21 +00:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case QSE_AWK_RIO_OPEN:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->pipe_handler->open(pipe);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_CLOSE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->pipe_handler->close(pipe);
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_READ:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->pipe_handler->read(pipe, (qse_char_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_WRITE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->pipe_handler->write(pipe, (const qse_char_t*)data, count);
|
|
|
|
case QSE_AWK_RIO_WRITE_BYTES:
|
|
|
|
return awk->pipe_handler->writeBytes(pipe, (const qse_mchar_t*)data, count);
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_FLUSH:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->pipe_handler->flush(pipe);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case QSE_AWK_RIO_OPEN:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->openPipe(pipe);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_CLOSE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->closePipe(pipe);
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_READ:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->readPipe(pipe, (qse_char_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_WRITE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->writePipe(pipe, (const qse_char_t*)data, count);
|
|
|
|
case QSE_AWK_RIO_WRITE_BYTES:
|
|
|
|
return awk->writePipeBytes(pipe, (const qse_mchar_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
case QSE_AWK_RIO_FLUSH:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->flushPipe(pipe);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-16 04:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return -1;
|
2007-05-06 19:44:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2019-04-21 05:44:53 +00:00
|
|
|
Awk::ssize_t Awk::fileHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, size_t count)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
rxtn_t* rxtn = GET_RXTN(rtx);
|
2009-02-16 08:31:34 +00:00
|
|
|
Awk* awk = rxtn->run->awk;
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_FILE);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
File file (rxtn->run, riod);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
try
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2012-06-06 14:41:21 +00:00
|
|
|
if (awk->file_handler)
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
2012-06-06 14:41:21 +00:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case QSE_AWK_RIO_OPEN:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->file_handler->open(file);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_CLOSE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->file_handler->close(file);
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_READ:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->file_handler->read(file, (qse_char_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_WRITE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->file_handler->write(file, (const qse_char_t*)data, count);
|
|
|
|
case QSE_AWK_RIO_WRITE_BYTES:
|
|
|
|
return awk->file_handler->writeBytes(file, (const qse_mchar_t*)data, count);
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_FLUSH:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->file_handler->flush(file);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case QSE_AWK_RIO_OPEN:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->openFile(file);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_CLOSE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->closeFile(file);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_READ:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->readFile(file, (qse_char_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_WRITE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->writeFile(file, (const qse_char_t*)data, count);
|
|
|
|
case QSE_AWK_RIO_WRITE_BYTES:
|
|
|
|
return awk->writeFileBytes(file, (const qse_mchar_t*)data, count);
|
2007-05-16 01:03:00 +00:00
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_FLUSH:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->flushFile(file);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-16 04:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return -1;
|
2007-05-06 19:44:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2019-04-21 05:44:53 +00:00
|
|
|
Awk::ssize_t Awk::consoleHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, size_t count)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
rxtn_t* rxtn = GET_RXTN(rtx);
|
2009-02-16 08:31:34 +00:00
|
|
|
Awk* awk = rxtn->run->awk;
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-02-16 08:31:34 +00:00
|
|
|
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_CONSOLE);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-07 06:37:25 +00:00
|
|
|
Console console (rxtn->run, riod);
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2009-07-16 04:43:31 +00:00
|
|
|
try
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2012-06-06 14:41:21 +00:00
|
|
|
if (awk->console_handler)
|
2009-07-16 04:43:31 +00:00
|
|
|
{
|
2012-06-06 14:41:21 +00:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case QSE_AWK_RIO_OPEN:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->console_handler->open(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_CLOSE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->console_handler->close(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
case QSE_AWK_RIO_READ:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->console_handler->read(console, (qse_char_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_WRITE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->console_handler->write(console, (const qse_char_t*)data, count);
|
|
|
|
case QSE_AWK_RIO_WRITE_BYTES:
|
|
|
|
return awk->console_handler->writeBytes(console, (const qse_mchar_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
case QSE_AWK_RIO_FLUSH:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->console_handler->flush(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_NEXT:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->console_handler->next(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case QSE_AWK_RIO_OPEN:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->openConsole(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_CLOSE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->closeConsole(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
case QSE_AWK_RIO_READ:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->readConsole(console, (qse_char_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_WRITE:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->writeConsole(console, (const qse_char_t*)data, count);
|
|
|
|
case QSE_AWK_RIO_WRITE_BYTES:
|
|
|
|
return awk->writeConsoleBytes(console, (const qse_mchar_t*)data, count);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
case QSE_AWK_RIO_FLUSH:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->flushConsole(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
case QSE_AWK_RIO_NEXT:
|
2019-04-21 05:44:53 +00:00
|
|
|
return awk->nextConsole(console);
|
2012-06-06 14:41:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-16 04:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return -1;
|
2007-05-16 01:03:00 +00:00
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
2007-05-21 01:22:00 +00:00
|
|
|
|
2019-04-21 05:44:53 +00:00
|
|
|
int Awk::openPipe (Pipe& io)
|
2012-06-06 14:41:21 +00:00
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::closePipe (Pipe& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::ssize_t Awk::readPipe (Pipe& io, char_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::ssize_t Awk::writePipe (Pipe& io, const char_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-23 08:41:05 +00:00
|
|
|
Awk::ssize_t Awk::writePipeBytes (Pipe& io, const qse_mchar_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
int Awk::flushPipe (Pipe& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::openFile (File& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::closeFile (File& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::ssize_t Awk::readFile (File& io, char_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::ssize_t Awk::writeFile (File& io, const char_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-23 08:41:05 +00:00
|
|
|
Awk::ssize_t Awk::writeFileBytes (File& io, const qse_mchar_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
int Awk::flushFile (File& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::openConsole (Console& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::closeConsole (Console& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::ssize_t Awk::readConsole (Console& io, char_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Awk::ssize_t Awk::writeConsole (Console& io, const char_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-23 08:41:05 +00:00
|
|
|
Awk::ssize_t Awk::writeConsoleBytes (Console& io, const qse_mchar_t* buf, size_t len)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:41:21 +00:00
|
|
|
int Awk::flushConsole (Console& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Awk::nextConsole (Console& io)
|
|
|
|
{
|
|
|
|
((Run*)io)->setError (QSE_AWK_ENOIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-23 17:08:56 +00:00
|
|
|
int Awk::functionHandler (rtx_t* rtx, const fnc_info_t* fi)
|
2007-09-11 22:42:00 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
rxtn_t* rxtn = GET_RXTN(rtx);
|
2012-10-23 17:08:56 +00:00
|
|
|
return rxtn->run->awk->dispatch_function (rxtn->run, fi);
|
2007-09-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
Awk::flt_t Awk::pow (awk_t* awk, flt_t x, flt_t y)
|
2011-05-18 08:56:54 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2011-05-18 08:56:54 +00:00
|
|
|
return xtn->awk->pow (x, y);
|
|
|
|
}
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
Awk::flt_t Awk::mod (awk_t* awk, flt_t x, flt_t y)
|
2011-07-24 03:03:48 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2011-07-24 03:03:48 +00:00
|
|
|
return xtn->awk->mod (x, y);
|
|
|
|
}
|
|
|
|
|
2012-11-03 17:44:23 +00:00
|
|
|
void* Awk::modopen (awk_t* awk, const mod_spec_t* spec)
|
2012-10-31 13:51:32 +00:00
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2012-11-03 17:44:23 +00:00
|
|
|
return xtn->awk->modopen (spec);
|
2012-10-31 13:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Awk::modclose (awk_t* awk, void* handle)
|
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2012-10-31 13:51:32 +00:00
|
|
|
xtn->awk->modclose (handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* Awk::modsym (awk_t* awk, void* handle, const char_t* name)
|
|
|
|
{
|
2019-06-24 08:53:49 +00:00
|
|
|
xtn_t* xtn = GET_XTN(awk);
|
2012-10-31 13:51:32 +00:00
|
|
|
return xtn->awk->modsym (handle, name);
|
|
|
|
}
|
2007-09-11 22:42:00 +00:00
|
|
|
/////////////////////////////////
|
2008-12-30 04:49:25 +00:00
|
|
|
QSE_END_NAMESPACE(QSE)
|
2009-08-26 03:50:07 +00:00
|
|
|
/////////////////////////////////
|