*** empty log message ***

This commit is contained in:
hyung-hwan 2006-12-11 06:29:19 +00:00
parent 2ab6aca24e
commit 108ec7863b
4 changed files with 110 additions and 59 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.4 2006-12-10 16:13:50 bacon Exp $ * $Id: Awk.cpp,v 1.5 2006-12-11 06:29:18 bacon Exp $
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -29,7 +29,7 @@ STDMETHODIMP CAwk::InterfaceSupportsErrorInfo(REFIID riid)
} }
CAwk::CAwk (): handle(NULL), CAwk::CAwk (): handle(NULL),
read_source_buf(NULL), write_source_buf(NULL), read_src_buf(NULL), write_src_buf(NULL),
write_extio_buf(NULL) write_extio_buf(NULL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -52,14 +52,14 @@ CAwk::~CAwk ()
write_extio_buf->Release (); write_extio_buf->Release ();
} }
if (write_source_buf != NULL) if (write_src_buf != NULL)
{ {
write_source_buf->Release (); write_src_buf->Release ();
} }
if (read_source_buf != NULL) if (read_src_buf != NULL)
{ {
read_source_buf->Release (); read_src_buf->Release ();
} }
if (handle != NULL) if (handle != NULL)
@ -172,53 +172,53 @@ static ase_ssize_t __read_source (
} }
else if (cmd == ASE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
if (awk->read_source_buf == NULL) if (awk->read_src_buf == NULL)
{ {
HRESULT hr = CoCreateInstance ( HRESULT hr = CoCreateInstance (
CLSID_Buffer, NULL, CLSCTX_ALL, CLSID_Buffer, NULL, CLSCTX_ALL,
IID_IBuffer, (void**)&awk->read_source_buf); IID_IBuffer, (void**)&awk->read_src_buf);
if (FAILED(hr)) if (FAILED(hr))
{ {
MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK); MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK);
return -1; return -1;
} }
awk->read_source_pos = 0; awk->read_src_pos = 0;
awk->read_source_len = 0; awk->read_src_len = 0;
} }
CBuffer* tmp = (CBuffer*)awk->read_source_buf; CBuffer* tmp = (CBuffer*)awk->read_src_buf;
if (awk->read_source_pos >= awk->read_source_len) if (awk->read_src_pos >= awk->read_src_len)
{ {
INT n = awk->Fire_ReadSource (awk->read_source_buf); INT n = awk->Fire_ReadSource (awk->read_src_buf);
if (n <= 0) return (ase_ssize_t)n; if (n <= 0) return (ase_ssize_t)n;
if (SysStringLen(tmp->str) < (UINT)n) return -1; if (SysStringLen(tmp->str) < (UINT)n) return -1;
awk->read_source_pos = 0; awk->read_src_pos = 0;
awk->read_source_len = n; awk->read_src_len = n;
} }
ASE_AWK_ASSERT (awk->handle, ASE_AWK_ASSERT (awk->handle,
awk->read_source_pos < awk->read_source_len); awk->read_src_pos < awk->read_src_len);
BSTR str = tmp->str; BSTR str = tmp->str;
INT left = awk->read_source_len - awk->read_source_pos; INT left = awk->read_src_len - awk->read_src_pos;
if (left > (ase_ssize_t)count) if (left > (ase_ssize_t)count)
{ {
memcpy (data, memcpy (data,
((TCHAR*)str)+awk->read_source_pos, ((TCHAR*)str)+awk->read_src_pos,
count * ASE_SIZEOF(ase_char_t)); count * ASE_SIZEOF(ase_char_t));
awk->read_source_pos += count; awk->read_src_pos += count;
return count; return count;
} }
else else
{ {
memcpy (data, memcpy (data,
((TCHAR*)str)+awk->read_source_pos, ((TCHAR*)str)+awk->read_src_pos,
left * ASE_SIZEOF(ase_char_t)); left * ASE_SIZEOF(ase_char_t));
awk->read_source_pos = 0; awk->read_src_pos = 0;
awk->read_source_len = 0; awk->read_src_len = 0;
return (ase_ssize_t)left; return (ase_ssize_t)left;
} }
} }
@ -243,11 +243,11 @@ static ase_ssize_t __write_source (
{ {
HRESULT hr; HRESULT hr;
if (awk->write_source_buf == NULL) if (awk->write_src_buf == NULL)
{ {
hr = CoCreateInstance ( hr = CoCreateInstance (
CLSID_Buffer, NULL, CLSCTX_ALL, CLSID_Buffer, NULL, CLSCTX_ALL,
IID_IBuffer, (void**)&awk->write_source_buf); IID_IBuffer, (void**)&awk->write_src_buf);
if (FAILED(hr)) if (FAILED(hr))
{ {
MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK); MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK);
@ -255,17 +255,10 @@ MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK);
} }
} }
/* CBuffer* tmp = (CBuffer*)awk->write_src_buf;
BSTR bstr = SysAllocStringLen (data, count);
if (bstr == NULL) return -1;
hr = awk->write_source_buf->put_Value (bstr);
SysFreeString (bstr);
if (FAILED(hr)) return -1;
*/
CBuffer* tmp = (CBuffer*)awk->write_source_buf;
if (tmp->PutValue (data, count) == FALSE) return -1; /* TODO: better error handling */ if (tmp->PutValue (data, count) == FALSE) return -1; /* TODO: better error handling */
INT n = awk->Fire_WriteSource (awk->write_source_buf); INT n = awk->Fire_WriteSource (awk->write_src_buf);
if (n > (INT)count) return -1; if (n > (INT)count) return -1;
return (ase_ssize_t)n; return (ase_ssize_t)n;
} }
@ -355,21 +348,37 @@ static ase_ssize_t __process_extio (
{ {
IAwkExtio* extio; IAwkExtio* extio;
CAwkExtio* extio2; CAwkExtio* extio2;
IBuffer* read_buf;
HRESULT hr = CoCreateInstance ( HRESULT hr = CoCreateInstance (
CLSID_AwkExtio, NULL, CLSCTX_ALL, CLSID_AwkExtio, NULL, CLSCTX_ALL,
IID_IAwkExtio, (void**)&extio); IID_IAwkExtio, (void**)&extio);
if (FAILED(hr)) return -1; /* TODO: better error handling.. */ if (FAILED(hr)) return -1; /* TODO: better error handling.. */
hr = CoCreateInstance (
CLSID_Buffer, NULL, CLSCTX_ALL,
IID_IBuffer, (void**)&read_buf);
if (FAILED(hr))
{
extio->Release ();
return -1;
}
extio2 = (CAwkExtio*)extio; extio2 = (CAwkExtio*)extio;
if (extio2->PutName (epa->name) == FALSE) if (extio2->PutName (epa->name) == FALSE)
{ {
read_buf->Release ();
extio->Release (); extio->Release ();
return -1; /* TODO: better error handling */ return -1; /* TODO: better error handling */
} }
extio2->type = epa->type & 0xFF; extio2->type = epa->type & 0xFF;
extio2->mode = epa->mode; extio2->mode = epa->mode;
read_buf->AddRef ();
extio2->read_buf = read_buf;
extio2->read_buf_pos = 0;
extio2->read_buf_len = 0;
INT n = awk->Fire_OpenExtio (extio); INT n = awk->Fire_OpenExtio (extio);
if (n >= 0) if (n >= 0)
{ {
@ -377,40 +386,73 @@ static ase_ssize_t __process_extio (
epa->handle = extio; epa->handle = extio;
} }
read_buf->Release ();
extio->Release (); extio->Release ();
return n; return n;
} }
else if (cmd == ASE_AWK_IO_CLOSE) else if (cmd == ASE_AWK_IO_CLOSE)
{ {
IAwkExtio* extio = (IAwkExtio*)epa->handle; IAwkExtio* extio;
CAwkExtio* extio2;
extio = (IAwkExtio*)epa->handle;
extio2 = (CAwkExtio*)extio;
ASE_AWK_ASSERT (ase_awk_getrunawk(epa->run), extio != NULL); ASE_AWK_ASSERT (ase_awk_getrunawk(epa->run), extio != NULL);
INT n = awk->Fire_CloseExtio (extio); INT n = awk->Fire_CloseExtio (extio);
if (n >= 0) if (n >= 0)
{ {
extio2->read_buf->Release();
extio->Release(); extio->Release();
epa->handle = NULL; epa->handle = NULL;
} }
return n; return n;
} }
else if (cmd == ASE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
/* IAwkExtio* extio;
IAwkExtio* extio = (IAwkExtio*)epa->handle; CAwkExtio* extio2;
extio = (IAwkExtio*)epa->handle;
extio2 = (CAwkExtio*)extio;
ASE_AWK_ASSERT (ase_awk_getrunawk(epa->run), extio != NULL); ASE_AWK_ASSERT (ase_awk_getrunawk(epa->run), extio != NULL);
if (awk->write_extio_buf == NULL) CBuffer* tmp = (CBuffer*)extio2->read_buf;
if (extio2->read_buf_pos >= extio2->read_buf_len)
{ {
HRESULT hr = CoCreateInstance ( INT n = awk->Fire_ReadSource (extio2->read_buf);
CLSID_Buffer, NULL, CLSCTX_ALL, if (n <= 0) return (ase_ssize_t)n;
IID_IBuffer, (void**)&awk->write_extio_buf);
if (FAILED(hr)) return -1; if (SysStringLen(tmp->str) < (UINT)n) return -1;
extio2->read_buf_pos = 0;
extio2->read_buf_len = n;
} }
INT n = awk->Fire_ReadExtio (extio, awk->write_extio_buf); ASE_AWK_ASSERT (awk->handle,
if (n > (INT)size) return -1; extio2->read_buf_pos < extio2->read_buf_len);
return (ase_ssize_t)n;
*/ 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;
}
} }
else if (cmd == ASE_AWK_IO_WRITE) else if (cmd == ASE_AWK_IO_WRITE)
{ {
@ -426,13 +468,6 @@ static ase_ssize_t __process_extio (
if (FAILED(hr)) return -1; if (FAILED(hr)) return -1;
} }
/*
BSTR bstr = SysAllocStringLen (data, size);
if (bstr == NULL) return -1;
hr = awk->write_extio_buf->put_Value (bstr);
SysFreeString (bstr);
if (FAILED(hr)) return -1;
*/
CBuffer* tmp = (CBuffer*)awk->write_extio_buf; CBuffer* tmp = (CBuffer*)awk->write_extio_buf;
if (tmp->PutValue (data, size) == FALSE) return -1; /* TODO: better error handling */ if (tmp->PutValue (data, size) == FALSE) return -1; /* TODO: better error handling */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.h,v 1.2 2006-12-09 17:36:27 bacon Exp $ * $Id: Awk.h,v 1.3 2006-12-11 06:29:19 bacon Exp $
*/ */
#ifndef _ASE_COM_AWK_H_ #ifndef _ASE_COM_AWK_H_
@ -31,10 +31,10 @@ class CAwk :
public: public:
ase_awk_t* handle; ase_awk_t* handle;
IBuffer* read_source_buf; IBuffer* read_src_buf;
IBuffer* write_source_buf; IBuffer* write_src_buf;
ase_size_t read_source_pos; ase_size_t read_src_pos;
ase_size_t read_source_len; ase_size_t read_src_len;
IBuffer* write_extio_buf; IBuffer* write_extio_buf;
public: public:

View File

@ -1,5 +1,5 @@
/* /*
* $Id: AwkExtio.h,v 1.4 2006-12-10 16:13:50 bacon Exp $ * $Id: AwkExtio.h,v 1.5 2006-12-11 06:29:19 bacon Exp $
*/ */
#ifndef _ASE_COM_AWKEXTIO_H_ #ifndef _ASE_COM_AWKEXTIO_H_
@ -20,6 +20,10 @@ public:
int mode; int mode;
CComVariant handle; CComVariant handle;
IBuffer* read_buf;
ase_size_t read_buf_pos;
ase_size_t read_buf_len;
BOOL PutName (const TCHAR* val); BOOL PutName (const TCHAR* val);
CAwkExtio (); CAwkExtio ();

View File

@ -97,6 +97,8 @@ Public WithEvents abc As ASELib.Awk
Attribute abc.VB_VarHelpID = -1 Attribute abc.VB_VarHelpID = -1
Private first As Boolean Private first As Boolean
Private extio_first As Boolean
Private Sub Execute_Click() Private Sub Execute_Click()
Dim a As Long Dim a As Long
Dim x As Object Dim x As Object
@ -157,6 +159,7 @@ End Function
Function abc_OpenExtio(ByVal extio As ASELib.AwkExtio) As Long Function abc_OpenExtio(ByVal extio As ASELib.AwkExtio) As Long
MsgBox "abc_OpenExtio" MsgBox "abc_OpenExtio"
extio_first = True
abc_OpenExtio = 1 abc_OpenExtio = 1
End Function End Function
@ -166,7 +169,16 @@ MsgBox "abc_CloseExtio"
End Function End Function
Function abc_ReadExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long Function abc_ReadExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long
abc_ReadExtio = 0 Dim value As String
If extio_first Then
value = ConsoleIn.Text
extio_first = False
buf.value = value
abc_ReadExtio = Len(value)
Else
abc_ReadExtio = 0
End If
End Function End Function
Function abc_WriteExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long Function abc_WriteExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long