From a00c29b744c8f94a95326382ed94800c8e6b17ab Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 9 Dec 2006 12:09:42 +0000 Subject: [PATCH] *** empty log message *** --- ase/com/awk_cp.h | 107 ++++++++++++++++++++++++++++++------------- ase/test/com/awk.js | 54 ++++++++++++++++++++++ ase/test/com/awk.vbs | 30 ++++++++++++ 3 files changed, 159 insertions(+), 32 deletions(-) create mode 100644 ase/test/com/awk.js create mode 100644 ase/test/com/awk.vbs diff --git a/ase/com/awk_cp.h b/ase/com/awk_cp.h index d98ed659..77bcfdb1 100644 --- a/ase/com/awk_cp.h +++ b/ase/com/awk_cp.h @@ -1,5 +1,5 @@ /* - * $Id: awk_cp.h,v 1.1 2006-12-09 11:50:08 bacon Exp $ + * $Id: awk_cp.h,v 1.2 2006-12-09 12:09:42 bacon Exp $ */ #ifndef _AWK_CP_H_ @@ -10,60 +10,102 @@ template class CProxyIAwkEvents : public IConnectionPointImpl { - //Warning this class may be recreated by the wizard. public: LONG Fire_OpenSource(LONG mode) { - CComVariant varResult; T* pT = static_cast(this); - int nConnectionIndex; - CComVariant* pvars = new CComVariant[1]; - int nConnections = m_vec.GetSize(); + int i, nconns = m_vec.GetSize(); + CComVariant args[1], ret; - for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) + for (i = 0; i < nconns; i++) { pT->Lock(); - CComPtr sp = m_vec.GetAt(nConnectionIndex); + CComPtr sp = m_vec.GetAt(i); pT->Unlock(); - IDispatch* pDispatch = reinterpret_cast(sp.p); - if (pDispatch != NULL) + + IDispatch* pDispatch = + reinterpret_cast(sp.p); + if (pDispatch == NULL) continue; + + VariantClear (&ret); + VariantClear (&args[0]); + + args[0] = mode; + + DISPPARAMS disp = { args, NULL, 1, 0 }; + HRESULT hr = pDispatch->Invoke ( + 0x1, IID_NULL, LOCALE_USER_DEFAULT, + DISPATCH_METHOD, &disp, &ret, NULL, NULL); + if (FAILED(hr)) continue; + + if (ret.vt == VT_EMPTY) { - VariantClear(&varResult); - pvars[0] = mode; - DISPPARAMS disp = { pvars, NULL, 1, 0 }; - pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); + /* probably, the handler has not been implemeted*/ + continue; } + + hr = ret.ChangeType (VT_I4); + if (FAILED(hr)) + { + /* TODO: set the error code properly... */ + /* invalid value returned... */ + return -1; + } + + return ret.lVal; } - delete[] pvars; - return varResult.lVal; - + + return -1; } + LONG Fire_CloseSource(LONG mode) { - CComVariant varResult; T* pT = static_cast(this); - int nConnectionIndex; - CComVariant* pvars = new CComVariant[1]; - int nConnections = m_vec.GetSize(); + int i, nconns = m_vec.GetSize(); + CComVariant args[1], ret; - for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) + for (i = 0; i < nconns; i++) { pT->Lock(); - CComPtr sp = m_vec.GetAt(nConnectionIndex); + CComPtr sp = m_vec.GetAt(i); pT->Unlock(); - IDispatch* pDispatch = reinterpret_cast(sp.p); - if (pDispatch != NULL) + + IDispatch* pDispatch = + reinterpret_cast(sp.p); + if (pDispatch == NULL) continue; + + + VariantClear (&ret); + VariantClear (&args[0]); + + args[0] = mode; + + DISPPARAMS disp = { args, NULL, 1, 0 }; + HRESULT hr = pDispatch->Invoke ( + 0x2, IID_NULL, LOCALE_USER_DEFAULT, + DISPATCH_METHOD, &disp, &ret, NULL, NULL); + if (FAILED(hr)) continue; + + if (ret.vt == VT_EMPTY) { - VariantClear(&varResult); - pvars[0] = mode; - DISPPARAMS disp = { pvars, NULL, 1, 0 }; - pDispatch->Invoke(0x2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); + /* probably, the handler has not been implemeted*/ + continue; } + + hr = ret.ChangeType (VT_I4); + if (FAILED(hr)) + { + /* TODO: set the error code properly... */ + /* invalid value returned... */ + return -1; + } + + return ret.lVal; } - delete[] pvars; - return varResult.lVal; - + + return -1; } + LONG Fire_ReadSource (IBuffer* buf) { T* pT = static_cast(this); @@ -171,4 +213,5 @@ public: return bstr.Length(); } }; + #endif diff --git a/ase/test/com/awk.js b/ase/test/com/awk.js new file mode 100644 index 00000000..04194909 --- /dev/null +++ b/ase/test/com/awk.js @@ -0,0 +1,54 @@ +var awk, first, n + +first = true + +function awk_OpenSource (mode) +{ + WScript.echo ("OpenSource - mode:" + mode); + return 1; +} + +function awk_CloseSource (mode) +{ + WScript.echo ("CloseSource - mode:" + mode); + return 0; +} + +function awk_ReadSource (buf) +{ + WScript.echo ("ReadSource - buf: [" + buf.Value + "]"); + if (first) + { + buf.Value = "BEGIN {print 1; print 2; print 3 > \"x\";}" + first = false + return buf.Value.length; + } + else return 0; +} + +function awk_WriteSource (buf) +{ + //WScript.echo ("WriteSource - cnt: " + cnt) + WScript.echo (buf.Value); + return buf.Value.length; +} + +awk = WScript.CreateObject("ASE.Awk"); +WScript.ConnectObject (awk, "awk_"); + + +n = awk.Parse(); +if (n == -1) +{ + WScript.echo ("parse failed"); + WScript.quit (1); +} + +n = awk.Run (); +if (n == -1) +{ + WScript.echo ("run failed"); + WScript.quit (1); +} + + diff --git a/ase/test/com/awk.vbs b/ase/test/com/awk.vbs new file mode 100644 index 00000000..c3a4c077 --- /dev/null +++ b/ase/test/com/awk.vbs @@ -0,0 +1,30 @@ +dim awk, first + +first = true + +function awk_OpenSource (mode) + WScript.echo ("OpenSource - mode:" & mode) + awk_OpenSource = 1 +end function + +function awk_CloseSource (mode) + WScript.echo ("CloseSource - mode:" & mode) + awk_CloseSource = 0 +end function + +function awk_ReadSource (buf, cnt) + WScript.echo ("ReadSource - cnt: " & cnt) + if first then + buf.Value = "BEGIN {print 1;}" + first = false + awk_ReadSource = len(buf.Value) + else + awk_ReadSource = 0 + end if +end function + +set awk = WScript.CreateObject("ASE.Awk") +call WScript.ConnectObject (awk, "awk_") + +WScript.echo awk.Parse +set awk = nothing