qse/ase/com/Awk.cpp

1303 lines
28 KiB
C++
Raw Normal View History

2006-12-09 11:50:08 +00:00
/*
2007-04-15 15:26:58 +00:00
* $Id: Awk.cpp,v 1.34 2007-04-15 15:26:57 bacon Exp $
2007-02-03 10:52:36 +00:00
*
* {License}
2006-12-09 11:50:08 +00:00
*/
#include "stdafx.h"
2007-03-24 05:18:32 +00:00
#include "asecom.h"
2006-12-09 11:50:08 +00:00
#include "Awk.h"
2006-12-09 17:36:27 +00:00
#include "AwkExtio.h"
2006-12-09 11:50:08 +00:00
#include "Buffer.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <wctype.h>
#include <stdio.h>
2007-02-23 15:34:26 +00:00
#include <ase/cmn/str.h>
#include <ase/utl/stdio.h>
#include <ase/utl/ctype.h>
2007-01-11 03:56:02 +00:00
#define DBGOUT(x) do { if (debug) OutputDebugString (x); } while(0)
#define DBGOUT2(awk,x) do { if (awk->debug) OutputDebugString (x); } while(0)
2006-12-09 11:50:08 +00:00
STDMETHODIMP CAwk::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IAwk,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (/*Inline*/IsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
2007-01-03 09:51:53 +00:00
CAwk::CAwk ():
2007-01-10 14:30:44 +00:00
handle (NULL),
read_src_buf (NULL),
write_src_buf (NULL),
write_extio_buf (NULL),
2007-01-16 14:20:43 +00:00
bfn_list (NULL),
2007-01-11 03:56:02 +00:00
entry_point (NULL),
2007-01-16 06:09:07 +00:00
debug (FALSE),
use_longlong (FALSE)
2007-01-10 14:30:44 +00:00
{
2006-12-11 14:58:25 +00:00
/* TODO: what is the best default option? */
2007-01-06 15:45:50 +00:00
option =
ASE_AWK_IMPLICIT |
ASE_AWK_EXPLICIT |
ASE_AWK_UNIQUEFN |
ASE_AWK_IDIV |
ASE_AWK_SHADING |
ASE_AWK_SHIFT |
ASE_AWK_EXTIO |
ASE_AWK_BLOCKLESS |
2007-01-25 14:14:56 +00:00
ASE_AWK_STRBASEONE |
2007-01-06 15:45:50 +00:00
ASE_AWK_STRIPSPACES |
ASE_AWK_NEXTOFILE |
ASE_AWK_CRLF;
memset (&max_depth, 0, sizeof(max_depth));
errnum = 0;
errlin = 0;
2007-01-10 14:30:44 +00:00
errmsg[0] = ASE_T('\0');
2006-12-09 11:50:08 +00:00
}
CAwk::~CAwk ()
{
2007-04-15 13:15:35 +00:00
2007-01-16 14:20:43 +00:00
while (bfn_list != NULL)
{
bfn_t* next = bfn_list->next;
free (bfn_list->name.ptr);
free (bfn_list);
bfn_list = next;
}
2007-01-10 14:30:44 +00:00
if (entry_point != NULL) SysFreeString (entry_point);
2006-12-09 11:50:08 +00:00
2007-01-10 14:30:44 +00:00
if (write_extio_buf != NULL) write_extio_buf->Release ();
if (write_src_buf != NULL) write_src_buf->Release ();
if (read_src_buf != NULL) read_src_buf->Release ();
2006-12-09 11:50:08 +00:00
if (handle != NULL)
{
ase_awk_close (handle);
handle = NULL;
2007-01-11 03:56:02 +00:00
DBGOUT (_T("closed awk"));
2006-12-09 11:50:08 +00:00
}
}
2007-03-06 14:58:00 +00:00
#ifndef NDEBUG
2007-03-19 05:39:44 +00:00
void ase_assert_abort (void)
2007-03-06 14:58:00 +00:00
{
abort ();
}
2007-03-19 05:39:44 +00:00
void ase_assert_printf (const ase_char_t* fmt, ...)
2007-03-06 14:58:00 +00:00
{
va_list ap;
int n;
ase_char_t buf[1024];
va_start (ap, fmt);
n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap);
if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0');
MessageBox (NULL, buf, ASE_T("Assertion Failure"), MB_OK|MB_ICONERROR);
va_end (ap);
}
#endif
2007-02-24 14:32:44 +00:00
static void* custom_awk_malloc (void* custom, ase_size_t n)
2006-12-09 11:50:08 +00:00
{
return malloc (n);
}
2007-02-24 14:32:44 +00:00
static void* custom_awk_realloc (void* custom, void* ptr, ase_size_t n)
2006-12-09 11:50:08 +00:00
{
return realloc (ptr, n);
}
2007-02-24 14:32:44 +00:00
static void custom_awk_free (void* custom, void* ptr)
2006-12-09 11:50:08 +00:00
{
free (ptr);
}
2007-02-24 14:32:44 +00:00
ase_bool_t custom_awk_isupper (void* custom, ase_cint_t c)
{
return ase_isupper (c);
}
ase_bool_t custom_awk_islower (void* custom, ase_cint_t c)
{
return ase_islower (c);
}
ase_bool_t custom_awk_isalpha (void* custom, ase_cint_t c)
{
return ase_isalpha (c);
}
ase_bool_t custom_awk_isdigit (void* custom, ase_cint_t c)
{
return ase_isdigit (c);
}
ase_bool_t custom_awk_isxdigit (void* custom, ase_cint_t c)
{
return ase_isxdigit (c);
}
ase_bool_t custom_awk_isalnum (void* custom, ase_cint_t c)
{
return ase_isalnum (c);
}
ase_bool_t custom_awk_isspace (void* custom, ase_cint_t c)
{
return ase_isspace (c);
}
ase_bool_t custom_awk_isprint (void* custom, ase_cint_t c)
{
return ase_isprint (c);
}
ase_bool_t custom_awk_isgraph (void* custom, ase_cint_t c)
{
return ase_isgraph (c);
}
ase_bool_t custom_awk_iscntrl (void* custom, ase_cint_t c)
{
return ase_iscntrl (c);
}
ase_bool_t custom_awk_ispunct (void* custom, ase_cint_t c)
{
return ase_ispunct (c);
}
ase_cint_t custom_awk_toupper (void* custom, ase_cint_t c)
{
return ase_toupper (c);
}
ase_cint_t custom_awk_tolower (void* custom, ase_cint_t c)
{
return ase_tolower (c);
}
static ase_real_t custom_awk_pow (void* custom, ase_real_t x, ase_real_t y)
2006-12-09 11:50:08 +00:00
{
return pow (x, y);
}
2007-02-24 14:32:44 +00:00
static int custom_awk_sprintf (
void* custom, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = ase_vsprintf (buf, size, fmt, ap);
va_end (ap);
return n;
2007-01-03 09:51:53 +00:00
}
2007-02-24 14:32:44 +00:00
static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...)
2006-12-09 11:50:08 +00:00
{
va_list ap;
va_start (ap, fmt);
_vftprintf (stderr, fmt, ap);
va_end (ap);
}
static ase_ssize_t __read_source (
int cmd, void* arg, ase_char_t* data, ase_size_t count)
{
CAwk* awk = (CAwk*)arg;
if (cmd == ASE_AWK_IO_OPEN)
{
2007-04-15 13:15:35 +00:00
return (ase_ssize_t)awk->Fire_OpenSource (AWK_SOURCE_READ);
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
2007-04-15 13:15:35 +00:00
return (ase_ssize_t)awk->Fire_CloseSource (AWK_SOURCE_READ);
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_READ)
{
2006-12-11 06:29:19 +00:00
if (awk->read_src_buf == NULL)
2006-12-09 11:50:08 +00:00
{
2006-12-10 05:59:52 +00:00
HRESULT hr = CoCreateInstance (
2006-12-09 11:50:08 +00:00
CLSID_Buffer, NULL, CLSCTX_ALL,
2006-12-11 06:29:19 +00:00
IID_IBuffer, (void**)&awk->read_src_buf);
2007-01-11 03:56:02 +00:00
if (FAILED(hr))
{
DBGOUT2 (awk, _T("cannot create source input buffer"));
return -1;
}
2006-12-09 11:50:08 +00:00
2006-12-11 06:29:19 +00:00
awk->read_src_pos = 0;
awk->read_src_len = 0;
2006-12-09 11:50:08 +00:00
}
2006-12-11 06:29:19 +00:00
CBuffer* tmp = (CBuffer*)awk->read_src_buf;
2006-12-10 05:59:52 +00:00
2006-12-11 06:29:19 +00:00
if (awk->read_src_pos >= awk->read_src_len)
2006-12-09 11:50:08 +00:00
{
2006-12-11 06:29:19 +00:00
INT n = awk->Fire_ReadSource (awk->read_src_buf);
2006-12-09 11:50:08 +00:00
if (n <= 0) return (ase_ssize_t)n;
2006-12-10 16:13:50 +00:00
if (SysStringLen(tmp->str) < (UINT)n) return -1;
2006-12-11 06:29:19 +00:00
awk->read_src_pos = 0;
awk->read_src_len = n;
2006-12-09 11:50:08 +00:00
}
2006-12-10 05:59:52 +00:00
2007-03-06 14:58:00 +00:00
ASE_ASSERT (awk->read_src_pos < awk->read_src_len);
2006-12-09 11:50:08 +00:00
2006-12-10 16:13:50 +00:00
BSTR str = tmp->str;
2006-12-11 06:29:19 +00:00
INT left = awk->read_src_len - awk->read_src_pos;
2006-12-09 11:50:08 +00:00
if (left > (ase_ssize_t)count)
{
memcpy (data,
2006-12-11 06:29:19 +00:00
((TCHAR*)str)+awk->read_src_pos,
2006-12-09 11:50:08 +00:00
count * ASE_SIZEOF(ase_char_t));
2006-12-11 06:29:19 +00:00
awk->read_src_pos += count;
2006-12-09 11:50:08 +00:00
return count;
}
else
{
memcpy (data,
2006-12-11 06:29:19 +00:00
((TCHAR*)str)+awk->read_src_pos,
2006-12-09 11:50:08 +00:00
left * ASE_SIZEOF(ase_char_t));
2006-12-11 06:29:19 +00:00
awk->read_src_pos = 0;
awk->read_src_len = 0;
2006-12-09 11:50:08 +00:00
return (ase_ssize_t)left;
}
}
return -1;
}
static ase_ssize_t __write_source (
int cmd, void* arg, ase_char_t* data, ase_size_t count)
{
CAwk* awk = (CAwk*)arg;
if (cmd == ASE_AWK_IO_OPEN)
{
2007-04-15 13:15:35 +00:00
return (ase_ssize_t)awk->Fire_OpenSource (AWK_SOURCE_WRITE);
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
2007-04-15 13:15:35 +00:00
return (ase_ssize_t)awk->Fire_CloseSource (AWK_SOURCE_WRITE);
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_WRITE)
{
HRESULT hr;
2006-12-11 06:29:19 +00:00
if (awk->write_src_buf == NULL)
2006-12-09 11:50:08 +00:00
{
hr = CoCreateInstance (
CLSID_Buffer, NULL, CLSCTX_ALL,
2006-12-11 06:29:19 +00:00
IID_IBuffer, (void**)&awk->write_src_buf);
2007-01-11 03:56:02 +00:00
if (FAILED(hr))
{
DBGOUT2 (awk, _T("cannot create source output buffer"));
return -1;
}
2006-12-09 11:50:08 +00:00
}
2006-12-11 06:29:19 +00:00
CBuffer* tmp = (CBuffer*)awk->write_src_buf;
2007-01-11 03:56:02 +00:00
if (tmp->PutValue (data, count) == FALSE)
{
DBGOUT2 (awk, _T("cannot set source output buffer"));
return -1;
}
2006-12-10 05:59:52 +00:00
2006-12-11 06:29:19 +00:00
INT n = awk->Fire_WriteSource (awk->write_src_buf);
2006-12-09 17:36:27 +00:00
if (n > (INT)count) return -1;
2006-12-09 11:50:08 +00:00
return (ase_ssize_t)n;
}
return -1;
}
2007-01-14 15:08:01 +00:00
static int __handle_bfn (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
{
CAwk* awk = (CAwk*)ase_awk_getruncustomdata (run);
long nargs = (long)ase_awk_getnargs (run);
ase_awk_val_t* v;
SAFEARRAY* aa;
SAFEARRAYBOUND bound[1];
bound[0].lLbound = 0;
bound[0].cElements = nargs;
aa = SafeArrayCreate (VT_VARIANT, ASE_COUNTOF(bound), bound);
if (aa == NULL)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("out of memory in creating argument array for '%.*s'"),
2007-01-14 15:08:01 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-14 15:08:01 +00:00
return -1;
}
for (long i = 0; i < nargs; i++)
{
VARIANT arg;
VariantInit (&arg);
v = ase_awk_getarg (run, i);
if (v->type == ASE_AWK_VAL_INT)
{
2007-01-16 06:09:07 +00:00
if (awk->use_longlong)
{
arg.vt = VT_I8;
arg.llVal = ((ase_awk_val_int_t*)v)->val;
}
else
{
arg.vt = VT_I4;
arg.lVal = (LONG)((ase_awk_val_int_t*)v)->val;
}
2007-01-14 15:08:01 +00:00
}
else if (v->type == ASE_AWK_VAL_REAL)
{
arg.vt = VT_R8;
arg.dblVal = ((ase_awk_val_real_t*)v)->val;
}
else if (v->type == ASE_AWK_VAL_STR)
{
BSTR tmp = SysAllocStringLen (
((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len);
if (arg.bstrVal == NULL)
{
VariantClear (&arg);
SafeArrayDestroy (aa);
2007-01-16 06:09:07 +00:00
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("out of memory in handling '%.*s'"),
2007-01-16 06:09:07 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-14 15:08:01 +00:00
return -1;
}
arg.vt = VT_BSTR;
arg.bstrVal = tmp;
}
else if (v->type == ASE_AWK_VAL_NIL)
{
2007-01-17 14:09:49 +00:00
arg.vt = VT_NULL;
2007-01-14 15:08:01 +00:00
}
HRESULT hr = SafeArrayPutElement (aa, &i, &arg);
if (hr != S_OK)
{
VariantClear (&arg);
SafeArrayDestroy (aa);
2007-01-16 06:09:07 +00:00
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("out of memory in handling '%.*s'"),
2007-01-16 06:09:07 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-14 15:08:01 +00:00
return -1;
}
VariantClear (&arg);
}
BSTR name = SysAllocStringLen (fnm, fnl);
if (name == NULL)
{
SafeArrayDestroy (aa);
2007-01-16 06:09:07 +00:00
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("out of memory in handling '%.*s'"),
2007-01-16 06:09:07 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-16 06:09:07 +00:00
2007-01-14 15:08:01 +00:00
return -1;
}
2007-01-16 06:09:07 +00:00
ase_awk_val_t* ret;
2007-04-14 15:30:14 +00:00
int n = awk->Fire_HandleFunction (run, name, aa, &ret);
2007-01-16 06:09:07 +00:00
if (n == 1)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("out of memory in handling '%.*s'"),
2007-01-16 06:09:07 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-16 06:09:07 +00:00
return -1;
}
else if (n == 2)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("no handler for '%.*s'"),
2007-01-16 06:09:07 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-16 06:09:07 +00:00
return -1;
}
else if (n == 3)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
2007-03-19 03:33:54 +00:00
_T("return value not supported for '%.*s'"),
2007-01-16 06:09:07 +00:00
fnl, fnm);
2007-03-19 05:39:44 +00:00
//TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
2007-01-16 06:09:07 +00:00
return -1;
}
2007-01-14 15:08:01 +00:00
2007-04-14 15:30:14 +00:00
/* name and aa are destroyed in HandleFunction */
2007-01-14 15:08:01 +00:00
//SafeArrayDestroy (aa);
//SysFreeString (name);
2007-01-16 06:09:07 +00:00
ase_awk_setretval (run, ret);
2007-01-14 15:08:01 +00:00
return 0;
}
2007-04-15 14:25:35 +00:00
HRESULT CAwk::Parse (VARIANT_BOOL* ret)
2006-12-09 11:50:08 +00:00
{
if (handle == NULL)
{
2007-02-01 08:38:24 +00:00
ase_awk_prmfns_t prmfns;
memset (&prmfns, 0, sizeof(prmfns));
2007-02-23 15:34:26 +00:00
2007-02-24 14:32:44 +00:00
prmfns.mmgr.malloc = custom_awk_malloc;
prmfns.mmgr.realloc = custom_awk_realloc;
prmfns.mmgr.free = custom_awk_free;
prmfns.ccls.is_upper = custom_awk_isupper;
prmfns.ccls.is_lower = custom_awk_islower;
prmfns.ccls.is_alpha = custom_awk_isalpha;
prmfns.ccls.is_digit = custom_awk_isdigit;
prmfns.ccls.is_xdigit = custom_awk_isxdigit;
prmfns.ccls.is_alnum = custom_awk_isalnum;
prmfns.ccls.is_space = custom_awk_isspace;
prmfns.ccls.is_print = custom_awk_isprint;
prmfns.ccls.is_graph = custom_awk_isgraph;
prmfns.ccls.is_cntrl = custom_awk_iscntrl;
prmfns.ccls.is_punct = custom_awk_ispunct;
prmfns.ccls.to_upper = custom_awk_toupper;
prmfns.ccls.to_lower = custom_awk_tolower;
prmfns.misc.pow = custom_awk_pow;
prmfns.misc.sprintf = custom_awk_sprintf;
prmfns.misc.dprintf = custom_awk_dprintf;
2007-02-01 08:38:24 +00:00
2007-03-19 03:33:54 +00:00
handle = ase_awk_open (&prmfns, NULL);
2006-12-09 11:50:08 +00:00
if (handle == NULL)
{
2007-01-03 09:51:53 +00:00
errlin = 0;
2007-02-23 15:34:26 +00:00
ase_strxcpy (
2007-01-03 09:51:53 +00:00
errmsg, ASE_COUNTOF(errmsg),
2007-03-19 03:33:54 +00:00
ase_awk_geterrstr(NULL, ASE_AWK_ENOMEM));
2007-01-03 09:51:53 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2007-01-11 03:56:02 +00:00
DBGOUT (_T("cannot open awk"));
2006-12-09 11:50:08 +00:00
return S_OK;
}
2007-01-11 03:56:02 +00:00
else DBGOUT (_T("opened awk successfully"));
2006-12-09 11:50:08 +00:00
2007-01-07 07:30:40 +00:00
ase_awk_setoption (handle, option);
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_BLOCK_PARSE, max_depth.block.parse);
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_BLOCK_RUN, max_depth.block.run);
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_EXPR_PARSE, max_depth.expr.parse);
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_EXPR_RUN, max_depth.expr.run);
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_REX_BUILD, max_depth.rex.build);
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_REX_MATCH, max_depth.rex.match);
2006-12-09 11:50:08 +00:00
}
2007-01-17 03:45:59 +00:00
ase_awk_clrbfn (handle);
2007-01-16 14:20:43 +00:00
for (bfn_t* bfn = bfn_list; bfn != NULL; bfn = bfn->next)
2007-01-14 15:08:01 +00:00
{
2007-01-16 14:20:43 +00:00
if (ase_awk_addbfn (
handle, bfn->name.ptr, bfn->name.len, 0,
bfn->min_args, bfn->max_args, NULL,
__handle_bfn) == NULL)
{
const ase_char_t* msg;
DBGOUT (_T("cannot add the builtin function"));
ase_awk_geterror (handle, &errnum, &errlin, &msg);
2007-02-23 15:34:26 +00:00
ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg);
2007-01-16 14:20:43 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2007-01-16 14:20:43 +00:00
return S_OK;
}
2007-01-14 15:08:01 +00:00
}
2006-12-09 11:50:08 +00:00
ase_awk_srcios_t srcios;
srcios.in = __read_source;
srcios.out = __write_source;
srcios.custom_data = this;
if (ase_awk_parse (handle, &srcios) == -1)
{
2007-01-03 09:51:53 +00:00
const ase_char_t* msg;
ase_awk_geterror (handle, &errnum, &errlin, &msg);
2007-02-23 15:34:26 +00:00
ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg);
2007-01-03 09:51:53 +00:00
2007-01-11 03:56:02 +00:00
DBGOUT (_T("cannot parse the source code"));
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2006-12-09 11:50:08 +00:00
return S_OK;
}
2007-01-11 03:56:02 +00:00
else DBGOUT (_T("parsed the source code successfully"));
2006-12-09 11:50:08 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_TRUE;
2006-12-09 11:50:08 +00:00
return S_OK;
}
static ase_ssize_t __process_extio (
int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
CAwk* awk = (CAwk*)epa->custom_data;
if (cmd == ASE_AWK_IO_OPEN)
{
2006-12-09 17:36:27 +00:00
IAwkExtio* extio;
CAwkExtio* extio2;
2006-12-11 06:29:19 +00:00
IBuffer* read_buf;
2006-12-09 17:36:27 +00:00
HRESULT hr = CoCreateInstance (
CLSID_AwkExtio, NULL, CLSCTX_ALL,
IID_IAwkExtio, (void**)&extio);
2007-01-11 03:56:02 +00:00
if (FAILED(hr))
{
DBGOUT2 (awk, _T("cannot create extio"));
return -1;
}
2006-12-09 17:36:27 +00:00
2006-12-11 06:29:19 +00:00
hr = CoCreateInstance (
CLSID_Buffer, NULL, CLSCTX_ALL,
IID_IBuffer, (void**)&read_buf);
if (FAILED(hr))
{
2007-01-11 03:56:02 +00:00
DBGOUT2 (awk, _T("cannot create extio input buffer"));
2006-12-11 06:29:19 +00:00
extio->Release ();
return -1;
}
2006-12-10 16:13:50 +00:00
extio2 = (CAwkExtio*)extio;
if (extio2->PutName (epa->name) == FALSE)
2006-12-10 05:59:52 +00:00
{
2006-12-11 06:29:19 +00:00
read_buf->Release ();
2006-12-10 05:59:52 +00:00
extio->Release ();
2007-01-11 03:56:02 +00:00
DBGOUT2 (awk, _T("cannot set the name of the extio input buffer"));
2007-01-10 14:30:44 +00:00
return -1;
2006-12-10 05:59:52 +00:00
}
2007-04-15 13:15:35 +00:00
extio2->type = (AwkExtioType)(epa->type & 0xFF);
extio2->mode = (AwkExtioMode)(epa->mode);
2006-12-09 17:36:27 +00:00
2006-12-11 06:29:19 +00:00
read_buf->AddRef ();
extio2->read_buf = read_buf;
extio2->read_buf_pos = 0;
extio2->read_buf_len = 0;
2006-12-09 17:36:27 +00:00
INT n = awk->Fire_OpenExtio (extio);
if (n >= 0)
{
extio->AddRef ();
epa->handle = extio;
}
2006-12-11 06:29:19 +00:00
read_buf->Release ();
2006-12-09 17:36:27 +00:00
extio->Release ();
return n;
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
2006-12-11 06:29:19 +00:00
IAwkExtio* extio;
CAwkExtio* extio2;
extio = (IAwkExtio*)epa->handle;
extio2 = (CAwkExtio*)extio;
2007-03-06 14:58:00 +00:00
ASE_ASSERT (extio != NULL);
2006-12-09 17:36:27 +00:00
INT n = awk->Fire_CloseExtio (extio);
if (n >= 0)
{
2006-12-11 06:29:19 +00:00
extio2->read_buf->Release();
2006-12-09 17:36:27 +00:00
extio->Release();
epa->handle = NULL;
}
2006-12-11 06:29:19 +00:00
2006-12-09 17:36:27 +00:00
return n;
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_READ)
{
2006-12-11 06:29:19 +00:00
IAwkExtio* extio;
CAwkExtio* extio2;
extio = (IAwkExtio*)epa->handle;
extio2 = (CAwkExtio*)extio;
2007-03-06 14:58:00 +00:00
ASE_ASSERT (extio != NULL);
2006-12-09 17:36:27 +00:00
2006-12-11 06:29:19 +00:00
CBuffer* tmp = (CBuffer*)extio2->read_buf;
if (extio2->read_buf_pos >= extio2->read_buf_len)
2006-12-09 17:36:27 +00:00
{
2006-12-11 08:44:52 +00:00
INT n = awk->Fire_ReadExtio (extio, extio2->read_buf);
2006-12-11 06:29:19 +00:00
if (n <= 0) return (ase_ssize_t)n;
if (SysStringLen(tmp->str) < (UINT)n) return -1;
extio2->read_buf_pos = 0;
extio2->read_buf_len = n;
2006-12-09 17:36:27 +00:00
}
2007-03-06 14:58:00 +00:00
ASE_ASSERT (extio2->read_buf_pos < extio2->read_buf_len);
2006-12-11 06:29:19 +00:00
BSTR str = tmp->str;
INT left = extio2->read_buf_len - extio2->read_buf_pos;
if (left > (ase_ssize_t)size)
{
memcpy (data,
((TCHAR*)str)+extio2->read_buf_pos,
size * ASE_SIZEOF(ase_char_t));
extio2->read_buf_pos += size;
return size;
}
else
{
memcpy (data,
((TCHAR*)str)+extio2->read_buf_pos,
left * ASE_SIZEOF(ase_char_t));
extio2->read_buf_pos = 0;
extio2->read_buf_len = 0;
return (ase_ssize_t)left;
}
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_WRITE)
{
2006-12-10 05:59:52 +00:00
HRESULT hr;
2006-12-09 17:36:27 +00:00
IAwkExtio* extio = (IAwkExtio*)epa->handle;
2007-03-06 14:58:00 +00:00
ASE_ASSERT (extio != NULL);
2006-12-09 17:36:27 +00:00
if (awk->write_extio_buf == NULL)
{
2006-12-10 05:59:52 +00:00
hr = CoCreateInstance (
2006-12-09 17:36:27 +00:00
CLSID_Buffer, NULL, CLSCTX_ALL,
IID_IBuffer, (void**)&awk->write_extio_buf);
2007-01-11 03:56:02 +00:00
if (FAILED(hr))
{
DBGOUT2 (awk, _T("cannot create extio output buffer"));
return -1;
}
2006-12-09 17:36:27 +00:00
}
2006-12-10 16:13:50 +00:00
CBuffer* tmp = (CBuffer*)awk->write_extio_buf;
2007-01-10 14:30:44 +00:00
if (tmp->PutValue (data, size) == FALSE) return -1;
2006-12-10 05:59:52 +00:00
2006-12-09 17:36:27 +00:00
INT n = awk->Fire_WriteExtio (extio, awk->write_extio_buf);
if (n > (INT)size) return -1;
return (ase_ssize_t)n;
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_FLUSH)
{
2006-12-11 14:58:25 +00:00
IAwkExtio* extio = (IAwkExtio*)epa->handle;
2007-03-06 14:58:00 +00:00
ASE_ASSERT (extio != NULL);
2006-12-11 14:58:25 +00:00
return awk->Fire_FlushExtio (extio);
2006-12-09 11:50:08 +00:00
}
else if (cmd == ASE_AWK_IO_NEXT)
{
2006-12-11 14:58:25 +00:00
IAwkExtio* extio = (IAwkExtio*)epa->handle;
2007-03-06 14:58:00 +00:00
ASE_ASSERT (extio != NULL);
2006-12-11 14:58:25 +00:00
return awk->Fire_NextExtio (extio);
2006-12-09 11:50:08 +00:00
}
return -1;
}
2007-04-15 14:25:35 +00:00
HRESULT CAwk::Run (VARIANT_BOOL* ret)
2006-12-09 11:50:08 +00:00
{
2007-01-10 14:30:44 +00:00
const ase_char_t* entry = NULL;
2006-12-09 11:50:08 +00:00
if (handle == NULL)
{
2007-01-10 14:30:44 +00:00
errnum = ASE_AWK_EINTERN;
errlin = 0;
_tcscpy (errmsg, _T("parse not called yet"));
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2006-12-09 11:50:08 +00:00
return S_OK;
}
ase_awk_runios_t runios;
2006-12-09 17:36:27 +00:00
runios.pipe = NULL;
2006-12-09 11:50:08 +00:00
runios.coproc = NULL;
2006-12-15 06:47:09 +00:00
runios.file = __process_extio;
2006-12-09 17:36:27 +00:00
runios.console = __process_extio;
2006-12-09 11:50:08 +00:00
runios.custom_data = this;
2007-01-10 14:30:44 +00:00
if (entry_point != NULL &&
SysStringLen(entry_point) > 0) entry = entry_point;
if (ase_awk_run (handle, entry, &runios, NULL, NULL, this) == -1)
2006-12-09 11:50:08 +00:00
{
2007-01-03 09:51:53 +00:00
const ase_char_t* msg;
ase_awk_geterror (handle, &errnum, &errlin, &msg);
2007-02-23 15:34:26 +00:00
ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg);
2007-01-03 09:51:53 +00:00
2007-01-11 03:56:02 +00:00
DBGOUT (_T("cannot run the program"));
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2006-12-09 11:50:08 +00:00
return S_OK;
}
2007-01-11 03:56:02 +00:00
else DBGOUT (_T("run the program successfully"));
2006-12-09 11:50:08 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_TRUE;
2006-12-09 11:50:08 +00:00
return S_OK;
}
2006-12-11 14:58:25 +00:00
2007-04-14 15:30:14 +00:00
STDMETHODIMP CAwk::AddFunction (
2007-04-15 15:26:58 +00:00
BSTR name, int minArgs, int maxArgs, VARIANT_BOOL* ret)
2007-01-14 15:08:01 +00:00
{
2007-01-17 03:45:59 +00:00
bfn_t* bfn;
size_t name_len = SysStringLen(name);
for (bfn = bfn_list; bfn != NULL; bfn = bfn->next)
{
2007-02-23 15:34:26 +00:00
if (ase_strxncmp (
2007-01-17 03:45:59 +00:00
bfn->name.ptr, bfn->name.len,
name, name_len) == 0)
{
errnum = ASE_AWK_EEXIST;
errlin = 0;
_sntprintf (
errmsg, ASE_COUNTOF(errmsg),
2007-03-19 03:33:54 +00:00
_T("'%.*s' added already"),
2007-01-17 03:45:59 +00:00
bfn->name.len, bfn->name.ptr);
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2007-01-17 03:45:59 +00:00
return S_OK;
}
}
bfn = (bfn_t*)malloc (sizeof(bfn_t));
2007-01-16 14:20:43 +00:00
if (bfn == NULL)
{
errnum = ASE_AWK_ENOMEM;
errlin = 0;
2007-02-23 15:34:26 +00:00
ase_strxcpy (
2007-01-16 14:20:43 +00:00
errmsg, ASE_COUNTOF(errmsg),
2007-03-19 03:33:54 +00:00
ase_awk_geterrstr(NULL, errnum));
2007-01-16 14:20:43 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2007-01-16 14:20:43 +00:00
return S_OK;
}
2007-01-17 03:45:59 +00:00
bfn->name.len = name_len;
2007-01-16 14:20:43 +00:00
bfn->name.ptr = (TCHAR*)malloc (bfn->name.len * sizeof(TCHAR));
if (bfn->name.ptr == NULL)
{
free (bfn);
errnum = ASE_AWK_ENOMEM;
errlin = 0;
2007-02-23 15:34:26 +00:00
ase_strxcpy (
2007-01-16 14:20:43 +00:00
errmsg, ASE_COUNTOF(errmsg),
2007-03-19 03:33:54 +00:00
ase_awk_geterrstr(NULL, errnum));
2007-01-16 14:20:43 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2007-01-16 14:20:43 +00:00
return S_OK;
}
memcpy (bfn->name.ptr, name, sizeof(TCHAR) * bfn->name.len);
2007-04-15 15:26:58 +00:00
bfn->min_args = minArgs;
bfn->max_args = maxArgs;
2007-01-16 14:20:43 +00:00
bfn->next = bfn_list;
bfn_list = bfn;
2007-04-15 14:25:35 +00:00
*ret = VARIANT_TRUE;
2007-01-14 15:08:01 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::DeleteFunction (BSTR name, VARIANT_BOOL* ret)
2007-01-17 14:09:49 +00:00
{
size_t name_len = SysStringLen(name);
bfn_t* bfn, * next, * prev = NULL;
for (bfn = bfn_list; bfn != NULL; bfn = next)
{
next = bfn->next;
2007-02-23 15:34:26 +00:00
if (ase_strxncmp (
2007-01-17 14:09:49 +00:00
bfn->name.ptr, bfn->name.len,
name, name_len) == 0)
{
free (bfn->name.ptr);
free (bfn);
if (prev == NULL) bfn_list = next;
else prev->next = next;
2007-04-15 14:25:35 +00:00
*ret = VARIANT_TRUE;
2007-01-17 14:09:49 +00:00
return S_OK;
}
prev = bfn;
}
errnum = ASE_AWK_ENOENT;
errlin = 0;
2007-02-23 15:34:26 +00:00
ase_strxcpy (
2007-01-17 14:09:49 +00:00
errmsg, ASE_COUNTOF(errmsg),
2007-03-19 03:33:54 +00:00
ase_awk_geterrstr(NULL, errnum));
2007-01-17 14:09:49 +00:00
2007-04-15 14:25:35 +00:00
*ret = VARIANT_FALSE;
2007-01-17 14:09:49 +00:00
return S_OK;
}
2007-01-03 09:51:53 +00:00
STDMETHODIMP CAwk::get_ErrorCode(int *pVal)
{
*pVal = errnum;
return S_OK;
}
STDMETHODIMP CAwk::get_ErrorLine(int *pVal)
{
*pVal = errlin;
return S_OK;
}
STDMETHODIMP CAwk::get_ErrorMessage(BSTR *pVal)
{
BSTR tmp = SysAllocStringLen (errmsg, _tcslen(errmsg));
if (tmp == NULL) return E_OUTOFMEMORY;
*pVal = tmp;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_ImplicitVariable(VARIANT_BOOL *pVal)
2007-01-03 09:51:53 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-03 09:51:53 +00:00
*pVal = (option & ASE_AWK_IMPLICIT) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_ImplicitVariable(VARIANT_BOOL newVal)
2007-01-03 09:51:53 +00:00
{
if (newVal) option = option | ASE_AWK_IMPLICIT;
2007-01-05 06:29:46 +00:00
else option = option & ~ASE_AWK_IMPLICIT;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-03 09:51:53 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_ExplicitVariable(VARIANT_BOOL *pVal)
2007-01-03 09:51:53 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-03 09:51:53 +00:00
*pVal = (option & ASE_AWK_EXPLICIT) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_ExplicitVariable(VARIANT_BOOL newVal)
2007-01-03 09:51:53 +00:00
{
if (newVal) option = option | ASE_AWK_EXPLICIT;
2007-01-05 06:29:46 +00:00
else option = option & ~ASE_AWK_EXPLICIT;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-03 09:51:53 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_UniqueFunction(VARIANT_BOOL *pVal)
2007-01-03 09:51:53 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-03 09:51:53 +00:00
*pVal = (option & ASE_AWK_UNIQUEFN) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_UniqueFunction(VARIANT_BOOL newVal)
2007-01-03 09:51:53 +00:00
{
if (newVal) option = option | ASE_AWK_UNIQUEFN;
2007-01-05 06:29:46 +00:00
else option = option & ~ASE_AWK_UNIQUEFN;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-03 09:51:53 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_VariableShading(VARIANT_BOOL *pVal)
2007-01-03 09:51:53 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-03 09:51:53 +00:00
*pVal = (option & ASE_AWK_SHADING) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_VariableShading(VARIANT_BOOL newVal)
2007-01-03 09:51:53 +00:00
{
if (newVal) option = option | ASE_AWK_SHADING;
2007-01-05 06:29:46 +00:00
else option = option & ~ASE_AWK_SHADING;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-03 09:51:53 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_ShiftOperators(VARIANT_BOOL *pVal)
2007-01-03 09:51:53 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-03 09:51:53 +00:00
*pVal = (option & ASE_AWK_SHIFT) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_ShiftOperators(VARIANT_BOOL newVal)
2007-01-03 09:51:53 +00:00
{
if (newVal) option = option | ASE_AWK_SHIFT;
2007-01-05 06:29:46 +00:00
else option = option & ~ASE_AWK_SHIFT;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-03 09:51:53 +00:00
return S_OK;
}
2007-01-05 13:39:38 +00:00
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_IdivOperator(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_IDIV) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_IdivOperator(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_IDIV;
else option = option & ~ASE_AWK_IDIV;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_ConcatString(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_STRCONCAT) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_ConcatString(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_STRCONCAT;
else option = option & ~ASE_AWK_STRCONCAT;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_SupportExtio(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_EXTIO) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_SupportExtio(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_EXTIO;
else option = option & ~ASE_AWK_EXTIO;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_SupportBlockless(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_BLOCKLESS) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_SupportBlockless(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_BLOCKLESS;
else option = option & ~ASE_AWK_BLOCKLESS;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_StringBaseOne(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-25 14:14:56 +00:00
*pVal = (option & ASE_AWK_STRBASEONE) == 1;
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_StringBaseOne(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
2007-01-25 14:14:56 +00:00
if (newVal) option = option | ASE_AWK_STRBASEONE;
else option = option & ~ASE_AWK_STRBASEONE;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_StripSpaces(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_STRIPSPACES) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_StripSpaces(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_STRIPSPACES;
else option = option & ~ASE_AWK_STRIPSPACES;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_Nextofile(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_NEXTOFILE) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_Nextofile(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_NEXTOFILE;
else option = option & ~ASE_AWK_NEXTOFILE;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_UseCrlf(VARIANT_BOOL *pVal)
2007-01-05 13:39:38 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL) option = ase_awk_getoption (handle);
2007-01-05 13:39:38 +00:00
*pVal = (option & ASE_AWK_CRLF) == 1;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_UseCrlf(VARIANT_BOOL newVal)
2007-01-05 13:39:38 +00:00
{
if (newVal) option = option | ASE_AWK_CRLF;
else option = option & ~ASE_AWK_CRLF;
2007-01-07 07:30:40 +00:00
if (handle != NULL) ase_awk_setoption (handle, option);
2007-01-05 13:39:38 +00:00
return S_OK;
}
2007-04-15 15:26:58 +00:00
STDMETHODIMP CAwk::get_ArgsToMain(VARIANT_BOOL *pVal)
{
if (handle != NULL) option = ase_awk_getoption (handle);
*pVal = (option & ASE_AWK_ARGSTOMAIN) == 1;
return S_OK;
}
STDMETHODIMP CAwk::put_ArgsToMain(VARIANT_BOOL newVal)
{
if (newVal) option = option | ASE_AWK_ARGSTOMAIN;
else option = option & ~ASE_AWK_ARGSTOMAIN;
if (handle != NULL) ase_awk_setoption (handle, option);
return S_OK;
}
2007-01-06 15:45:50 +00:00
STDMETHODIMP CAwk::get_MaxDepthForBlockParse(int *pVal)
{
2007-01-07 07:30:40 +00:00
if (handle != NULL)
{
max_depth.block.parse =
ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_BLOCK_PARSE);
}
*pVal = max_depth.block.parse;
2007-01-06 15:45:50 +00:00
return S_OK;
}
STDMETHODIMP CAwk::put_MaxDepthForBlockParse(int newVal)
{
max_depth.block.parse = newVal;
if (handle != NULL)
{
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_BLOCK_PARSE, max_depth.block.parse);
}
return S_OK;
}
STDMETHODIMP CAwk::get_MaxDepthForBlockRun(int *pVal)
{
2007-01-07 07:30:40 +00:00
if (handle != NULL)
{
max_depth.block.run =
ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_BLOCK_RUN);
}
*pVal = max_depth.block.run;
2007-01-06 15:45:50 +00:00
return S_OK;
}
STDMETHODIMP CAwk::put_MaxDepthForBlockRun(int newVal)
{
max_depth.block.run = newVal;
if (handle != NULL)
{
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_BLOCK_RUN, max_depth.block.run);
}
return S_OK;
}
2007-01-10 14:30:44 +00:00
STDMETHODIMP CAwk::get_MaxDepthForExprParse(int *pVal)
2007-01-06 15:45:50 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL)
{
max_depth.expr.parse =
ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_EXPR_PARSE);
}
*pVal = max_depth.expr.parse;
2007-01-06 15:45:50 +00:00
return S_OK;
}
2007-01-10 14:30:44 +00:00
STDMETHODIMP CAwk::put_MaxDepthForExprParse(int newVal)
2007-01-06 15:45:50 +00:00
{
max_depth.expr.parse = newVal;
if (handle != NULL)
{
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_EXPR_PARSE, max_depth.expr.parse);
}
return S_OK;
}
2007-01-10 14:30:44 +00:00
STDMETHODIMP CAwk::get_MaxDepthForExprRun(int *pVal)
2007-01-06 15:45:50 +00:00
{
2007-01-07 07:30:40 +00:00
if (handle != NULL)
{
max_depth.expr.run =
ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_EXPR_RUN);
}
*pVal = max_depth.expr.run;
2007-01-06 15:45:50 +00:00
return S_OK;
}
2007-01-10 14:30:44 +00:00
STDMETHODIMP CAwk::put_MaxDepthForExprRun(int newVal)
2007-01-06 15:45:50 +00:00
{
max_depth.expr.run = newVal;
if (handle != NULL)
{
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_EXPR_RUN, max_depth.expr.run);
}
return S_OK;
}
STDMETHODIMP CAwk::get_MaxDepthForRexBuild(int *pVal)
{
2007-01-07 07:30:40 +00:00
if (handle != NULL)
{
max_depth.rex.build =
ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_REX_BUILD);
}
*pVal = max_depth.rex.build;
2007-01-06 15:45:50 +00:00
return S_OK;
}
STDMETHODIMP CAwk::put_MaxDepthForRexBuild(int newVal)
{
max_depth.rex.build = newVal;
if (handle != NULL)
{
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_REX_BUILD, max_depth.rex.build);
}
return S_OK;
}
STDMETHODIMP CAwk::get_MaxDepthForRexMatch(int *pVal)
{
2007-01-07 07:30:40 +00:00
if (handle != NULL)
{
max_depth.rex.match =
ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_REX_MATCH);
}
*pVal = max_depth.rex.match;
2007-01-06 15:45:50 +00:00
return S_OK;
}
STDMETHODIMP CAwk::put_MaxDepthForRexMatch(int newVal)
{
max_depth.rex.match = newVal;
if (handle != NULL)
{
ase_awk_setmaxdepth (handle,
ASE_AWK_DEPTH_REX_MATCH, max_depth.rex.match);
}
return S_OK;
}
2007-01-10 14:30:44 +00:00
STDMETHODIMP CAwk::get_EntryPoint(BSTR *pVal)
{
if (entry_point == NULL) *pVal = NULL;
else
{
BSTR tmp = SysAllocStringLen (
entry_point, SysStringLen(entry_point));
if (tmp == NULL) return E_OUTOFMEMORY;
*pVal = tmp;
}
return S_OK;
}
STDMETHODIMP CAwk::put_EntryPoint(BSTR newVal)
{
if (entry_point != NULL) SysFreeString (entry_point);
if (newVal == NULL) entry_point = newVal;
else
{
entry_point = SysAllocStringLen (newVal, SysStringLen(newVal));
if (entry_point == NULL) return E_OUTOFMEMORY;
}
return S_OK;
}
2007-01-11 03:56:02 +00:00
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_Debug(VARIANT_BOOL *pVal)
2007-01-11 03:56:02 +00:00
{
*pVal = debug;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_Debug(VARIANT_BOOL newVal)
2007-01-11 03:56:02 +00:00
{
debug = newVal;
return S_OK;
}
2007-01-16 06:09:07 +00:00
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::get_UseLongLong(VARIANT_BOOL *pVal)
2007-01-16 06:09:07 +00:00
{
*pVal = use_longlong;
return S_OK;
}
2007-04-15 14:25:35 +00:00
STDMETHODIMP CAwk::put_UseLongLong(VARIANT_BOOL newVal)
2007-01-16 06:09:07 +00:00
{
use_longlong = newVal;
return S_OK;
}