From 2ab6aca24ebb13f723ecc0c8d13c0f4d07f53cb8 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 10 Dec 2006 16:13:50 +0000 Subject: [PATCH] *** empty log message *** --- ase/com/Awk.cpp | 53 ++++------- ase/com/AwkExtio.cpp | 25 +++-- ase/com/AwkExtio.h | 6 +- ase/com/Buffer.cpp | 10 +- ase/com/Buffer.h | 4 +- ase/test/com/AwkForm.frm | 197 +++++++++++++++++++++++++++++++++++++++ ase/test/com/ase.vbp | 32 +++++++ ase/test/com/ase.vbw | 1 + 8 files changed, 282 insertions(+), 46 deletions(-) create mode 100644 ase/test/com/AwkForm.frm create mode 100644 ase/test/com/ase.vbp create mode 100644 ase/test/com/ase.vbw diff --git a/ase/com/Awk.cpp b/ase/com/Awk.cpp index c8800e18..1580aa5c 100644 --- a/ase/com/Awk.cpp +++ b/ase/com/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.3 2006-12-10 05:59:52 bacon Exp $ + * $Id: Awk.cpp,v 1.4 2006-12-10 16:13:50 bacon Exp $ */ #include "stdafx.h" @@ -193,24 +193,16 @@ MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK); { INT n = awk->Fire_ReadSource (awk->read_source_buf); if (n <= 0) return (ase_ssize_t)n; - //if (n > (INT)tmp->str.Length()) return -1; - if (n > (INT)SysStringLen(tmp->str)) return -1; + if (SysStringLen(tmp->str) < (UINT)n) return -1; awk->read_source_pos = 0; awk->read_source_len = n; } - BSTR str = tmp->str; - if (str == NULL) - { - /* it can't be emptry here ... */ - return -1; - } - ASE_AWK_ASSERT (awk->handle, awk->read_source_pos < awk->read_source_len); - + BSTR str = tmp->str; INT left = awk->read_source_len - awk->read_source_pos; if (left > (ase_ssize_t)count) { @@ -263,16 +255,15 @@ MessageBox (NULL, _T("COCREATEINSTANCE FAILED"), _T("FUCK"), MB_OK); } } + /* BSTR bstr = SysAllocStringLen (data, count); - if (bstr == NULL) return -1; /* TODO: bettter error handling */ - + if (bstr == NULL) return -1; hr = awk->write_source_buf->put_Value (bstr); -SysFreeString (bstr); - if (FAILED(hr)) - { -//SysFreeString (bstr); - return -1; - } + 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 */ INT n = awk->Fire_WriteSource (awk->write_source_buf); if (n > (INT)count) return -1; @@ -370,19 +361,14 @@ static ase_ssize_t __process_extio ( IID_IAwkExtio, (void**)&extio); if (FAILED(hr)) return -1; /* TODO: better error handling.. */ - BSTR bstr = SysAllocString (epa->name); - if (bstr == NULL) + extio2 = (CAwkExtio*)extio; + if (extio2->PutName (epa->name) == FALSE) { extio->Release (); return -1; /* TODO: better error handling */ } - - extio2 = (CAwkExtio*)extio; - extio2->name.Empty (); - extio2->name.Attach (bstr); extio2->type = epa->type & 0xFF; extio2->mode = epa->mode; - VariantClear (&extio2->handle); INT n = awk->Fire_OpenExtio (extio); if (n >= 0) @@ -440,16 +426,15 @@ static ase_ssize_t __process_extio ( if (FAILED(hr)) return -1; } + /* BSTR bstr = SysAllocStringLen (data, size); - if (bstr == NULL) return -1; /* TODO: error code */ - + if (bstr == NULL) return -1; hr = awk->write_extio_buf->put_Value (bstr); -SysFreeString (bstr); - if (FAILED(hr)) - { -// SysFreeString (bstr); - return -1; - } + SysFreeString (bstr); + if (FAILED(hr)) return -1; + */ + CBuffer* tmp = (CBuffer*)awk->write_extio_buf; + if (tmp->PutValue (data, size) == FALSE) return -1; /* TODO: better error handling */ INT n = awk->Fire_WriteExtio (extio, awk->write_extio_buf); if (n > (INT)size) return -1; diff --git a/ase/com/AwkExtio.cpp b/ase/com/AwkExtio.cpp index 04d80bd6..b3bed5e2 100644 --- a/ase/com/AwkExtio.cpp +++ b/ase/com/AwkExtio.cpp @@ -1,5 +1,5 @@ /* - * $Id: AwkExtio.cpp,v 1.2 2006-12-09 17:36:27 bacon Exp $ + * $Id: AwkExtio.cpp,v 1.3 2006-12-10 16:13:50 bacon Exp $ */ #include "stdafx.h" @@ -10,7 +10,7 @@ ///////////////////////////////////////////////////////////////////////////// // CAwkExtio -CAwkExtio::CAwkExtio () +CAwkExtio::CAwkExtio (): name (NULL) { #ifdef _DEBUG TCHAR x[128]; @@ -26,15 +26,29 @@ CAwkExtio::~CAwkExtio () _sntprintf (x, 128, _T("CAwkExtio::~CAwkExtio %p"), this); MessageBox (NULL, x, x, MB_OK); #endif + if (name != NULL) SysFreeString (name); } -STDMETHODIMP CAwkExtio::get_Name(BSTR *pVal) +STDMETHODIMP CAwkExtio::get_Name (BSTR *pVal) { + if (name == NULL) *pVal = name; + else + { + BSTR tmp = SysAllocStringLen (name, SysStringLen(name)); + if (tmp = NULL) return E_OUTOFMEMORY; + *pVal = tmp; + } - *pVal = name; return S_OK; } +BOOL CAwkExtio::PutName (const TCHAR* val) +{ + if (name != NULL) SysFreeString (name); + name = SysAllocString (val); + return (name == NULL)? FALSE: TRUE; +} + STDMETHODIMP CAwkExtio::get_Type(int *pVal) { *pVal = type; @@ -43,8 +57,7 @@ STDMETHODIMP CAwkExtio::get_Type(int *pVal) STDMETHODIMP CAwkExtio::get_Mode(int *pVal) { - // TODO: Add your implementation code here - + *pVal = mode; return S_OK; } diff --git a/ase/com/AwkExtio.h b/ase/com/AwkExtio.h index 01ff66c6..dfecab8e 100644 --- a/ase/com/AwkExtio.h +++ b/ase/com/AwkExtio.h @@ -1,5 +1,5 @@ /* - * $Id: AwkExtio.h,v 1.3 2006-12-09 17:36:27 bacon Exp $ + * $Id: AwkExtio.h,v 1.4 2006-12-10 16:13:50 bacon Exp $ */ #ifndef _ASE_COM_AWKEXTIO_H_ @@ -15,11 +15,13 @@ class ATL_NO_VTABLE CAwkExtio : public IDispatchImpl { public: - CComBSTR name; + BSTR name; int type; int mode; CComVariant handle; + BOOL PutName (const TCHAR* val); + CAwkExtio (); ~CAwkExtio (); diff --git a/ase/com/Buffer.cpp b/ase/com/Buffer.cpp index 19fa1950..3ed56735 100644 --- a/ase/com/Buffer.cpp +++ b/ase/com/Buffer.cpp @@ -1,5 +1,5 @@ /* - * $Id: Buffer.cpp,v 1.3 2006-12-10 05:59:52 bacon Exp $ + * $Id: Buffer.cpp,v 1.4 2006-12-10 16:13:50 bacon Exp $ */ #include "stdafx.h" @@ -40,7 +40,6 @@ STDMETHODIMP CBuffer::get_Value (BSTR *pVal) STDMETHODIMP CBuffer::put_Value (BSTR newVal) { - if (str != NULL) SysFreeString (str); if (newVal == NULL) str = newVal; else @@ -51,3 +50,10 @@ STDMETHODIMP CBuffer::put_Value (BSTR newVal) return S_OK; } + +BOOL CBuffer::PutValue (const TCHAR* val, SIZE_T len) +{ + if (str != NULL) SysFreeString (str); + str = SysAllocStringLen (val, len); + return (str == NULL)? FALSE: TRUE; +} diff --git a/ase/com/Buffer.h b/ase/com/Buffer.h index 86352b41..bbcdd69e 100644 --- a/ase/com/Buffer.h +++ b/ase/com/Buffer.h @@ -1,5 +1,5 @@ /* - * $Id: Buffer.h,v 1.3 2006-12-10 05:59:52 bacon Exp $ + * $Id: Buffer.h,v 1.4 2006-12-10 16:13:50 bacon Exp $ */ #ifndef _ASE_COM_BUFFER_H_ @@ -14,8 +14,8 @@ class ATL_NO_VTABLE CBuffer : public IDispatchImpl { public: - //CComBSTR str; BSTR str; + BOOL PutValue (const TCHAR* val, SIZE_T len); public: CBuffer (); diff --git a/ase/test/com/AwkForm.frm b/ase/test/com/AwkForm.frm new file mode 100644 index 00000000..087cc522 --- /dev/null +++ b/ase/test/com/AwkForm.frm @@ -0,0 +1,197 @@ +VERSION 5.00 +Begin VB.Form AwkForm + Caption = "ASE COM AWK" + ClientHeight = 7695 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 9435 + LinkTopic = "AwkForm" + ScaleHeight = 7695 + ScaleWidth = 9435 + StartUpPosition = 3 'Windows Default + Begin VB.TextBox ConsoleIn + BeginProperty Font + Name = "Courier New" + Size = 8.25 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 2895 + Left = 360 + MultiLine = -1 'True + TabIndex = 4 + Top = 3600 + Width = 4095 + End + Begin VB.TextBox SourceIn + BeginProperty Font + Name = "Courier New" + Size = 8.25 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 2775 + Left = 480 + MultiLine = -1 'True + TabIndex = 3 + Top = 480 + Width = 3975 + End + Begin VB.TextBox SourceOut + BeginProperty Font + Name = "Courier New" + Size = 8.25 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 2775 + Left = 4680 + MultiLine = -1 'True + TabIndex = 2 + Top = 480 + Width = 4095 + End + Begin VB.CommandButton Execute + Caption = "Execute" + Height = 375 + Left = 7080 + TabIndex = 1 + Top = 6840 + Width = 1215 + End + Begin VB.TextBox ConsoleOut + BeginProperty Font + Name = "Courier New" + Size = 8.25 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 2895 + Left = 4680 + MultiLine = -1 'True + TabIndex = 0 + Top = 3600 + Width = 4095 + End +End +Attribute VB_Name = "AwkForm" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Public WithEvents abc As ASELib.Awk +Attribute abc.VB_VarHelpID = -1 +Private first As Boolean + +Private Sub Execute_Click() + Dim a As Long + Dim x As Object + + first = True + + ConsoleOut.Text = "" + SourceOut.Text = "" + + Set abc = New ASELib.Awk + Call abc.Parse + Call abc.Run + Set abc = Nothing +End Sub + +Function abc_OpenSource(ByVal mode As Long) As Long + abc_OpenSource = 1 +End Function + +Function abc_CloseSource(ByVal mode As Long) As Long + abc_CloseSource = 0 +End Function + +Function abc_ReadSource(ByVal buf As ASELib.Buffer) As Long + If first Then + buf.value = SourceIn.Text + abc_ReadSource = Len(buf.value) + first = False + Else + abc_ReadSource = 0 + End If +End Function + +Function abc_WriteSource(ByVal buf As ASELib.Buffer) As Long + Dim value As String, value2 As String, c As String + Dim i As Integer, l As Integer + + value = buf.value + If value = vbLf Then + SourceOut.Text = SourceOut.Text + vbCrLf + abc_WriteSource = 1 + Else + l = Len(value) + For i = 1 To l + c = Mid(value, i, 1) + If c = vbLf Then + value2 = value2 + vbCrLf + Else + value2 = value2 + c + End If + Next i + + SourceOut.Text = SourceOut.Text + value2 + abc_WriteSource = l + End If + +End Function + +Function abc_OpenExtio(ByVal extio As ASELib.AwkExtio) As Long +MsgBox "abc_OpenExtio" + abc_OpenExtio = 1 +End Function + +Function abc_CloseExtio(ByVal extio As ASELib.AwkExtio) As Long +MsgBox "abc_CloseExtio" + abc_CloseExtio = 0 +End Function + +Function abc_ReadExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long + abc_ReadExtio = 0 +End Function + +Function abc_WriteExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long + Dim value As String, i As Long, value2 As String + + value = buf.value + + 'For i = 0 To 5000000 + ' value2 = "abc" + ' buf.value = "abdkjsdfsafas" + 'Next i + + If value = vbLf Then + ConsoleOut.Text = ConsoleOut.Text + vbCrLf + abc_WriteExtio = 1 + Else + ConsoleOut.Text = ConsoleOut.Text + value + abc_WriteExtio = Len(value) + End If +End Function + +Private Sub Form_Load() + SourceIn.Text = "BEGIN { print 123.12; print 995; print 5432.1; }" + SourceOut.Text = "" + ConsoleIn.Text = "" + ConsoleOut.Text = "" +End Sub + diff --git a/ase/test/com/ase.vbp b/ase/test/com/ase.vbp new file mode 100644 index 00000000..cea7f90a --- /dev/null +++ b/ase/test/com/ase.vbp @@ -0,0 +1,32 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\System32\stdole2.tlb#OLE Automation +Reference=*\G{F9C69806-16A1-4162-998A-876B33C470BF}#1.0#0#..\..\debug\win32\vs60\ase.dll#ASE Awk 1.0 Type Library +Form=AwkForm.frm +Startup="AwkForm" +Command32="" +Name="ASE COM" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/ase/test/com/ase.vbw b/ase/test/com/ase.vbw new file mode 100644 index 00000000..8c170ebf --- /dev/null +++ b/ase/test/com/ase.vbw @@ -0,0 +1 @@ +AwkForm = 44, 44, 591, 504, , 22, 22, 738, 641, C