diff --git a/ase/awk/run.c b/ase/awk/run.c index 5b26f631..c397f816 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.348 2007-04-15 15:26:57 bacon Exp $ + * $Id: run.c,v 1.349 2007-04-21 12:40:44 bacon Exp $ * * {License} */ @@ -1177,8 +1177,7 @@ static int run_main ( return -1; } - if (runarg == ASE_NULL) nrunargs = 0; - else if (__build_runarg (run, runarg, &nrunargs) == -1) + if (__build_runarg (run, runarg, &nrunargs) == -1) { /* it can simply restore the top of the stack this way * because the values pused onto the stack so far are @@ -1212,7 +1211,7 @@ static int run_main ( if (!(run->awk->option & ASE_AWK_ARGSTOMAIN)) { /* if the option is not set, the arguments - * arenot passed to the main function as + * are not passed to the main function as * parameters */ nrunargs = 0; } diff --git a/ase/com/Awk.cpp b/ase/com/Awk.cpp index 3604539b..eb68e43a 100644 --- a/ase/com/Awk.cpp +++ b/ase/com/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.34 2007-04-15 15:26:57 bacon Exp $ + * $Id: Awk.cpp,v 1.35 2007-04-21 12:40:44 bacon Exp $ * * {License} */ @@ -748,9 +748,11 @@ static ase_ssize_t __process_extio ( return -1; } -HRESULT CAwk::Run (VARIANT_BOOL* ret) +HRESULT CAwk::Run (VARIANT argarray, VARIANT_BOOL* ret) { const ase_char_t* entry = NULL; + ase_awk_runarg_t* runarg; + long nrunargs; if (handle == NULL) { @@ -772,7 +774,79 @@ HRESULT CAwk::Run (VARIANT_BOOL* ret) if (entry_point != NULL && SysStringLen(entry_point) > 0) entry = entry_point; - if (ase_awk_run (handle, entry, &runios, NULL, NULL, this) == -1) + if (argarray.vt == VT_EMPTY || argarray.vt == VT_NULL) + { + /* no run-time argument specified */ + runarg = NULL; + } + else if (argarray.vt == (VT_ARRAY|VT_BSTR)) + { + SAFEARRAY* sa = argarray.parray; + UINT dim = SafeArrayGetDim (sa); + if (dim != 1) + { + /* arguments should not be multi-dimensional */ + errnum = ASE_AWK_EINTERN; + errlin = 0; + _tcscpy (errmsg, _T("multi-dimensional run-time argument array not allowed")); + + *ret = VARIANT_FALSE; + return S_OK; + } + + long lbound, ubound; + SafeArrayGetLBound (sa, 1, &lbound); + SafeArrayGetUBound (sa, 1, &ubound); + + nrunargs = ubound - lbound + 1; + runarg = (ase_awk_runarg_t*) malloc (sizeof(*runarg) * (nrunargs+1)); + if (runarg == NULL) + { + errnum = ASE_AWK_ENOMEM; + errlin = 0; + ase_strxcpy ( + errmsg, ASE_COUNTOF(errmsg), + ase_awk_geterrstr(NULL, errnum)); + + *ret = VARIANT_FALSE; + return S_OK; + } + + for (long i = lbound, j = 0; i <= ubound; i++, j++) + { + BSTR bstr; + HRESULT hr = SafeArrayGetElement (sa, &i, (void**)&bstr); + if (FAILED(hr)) + { + errnum = ASE_AWK_EINTERN; + errlin = 0; + _tcscpy (errmsg, _T("cannot get run-time argument array element")); + + for (long i = 0; i < j; i++) SysFreeString (runarg[i].ptr); + free (runarg); + + *ret = VARIANT_FALSE; + return S_OK; + } + + runarg[j].ptr = bstr; + runarg[j].len = SysStringLen (bstr); + } + + runarg[j].ptr = NULL; + runarg[j].len = 0; + } + else + { + errnum = ASE_AWK_EINTERN; + errlin = 0; + _tcscpy (errmsg, _T("invalid arguments")); + + *ret = VARIANT_FALSE; + return S_OK; + } + + if (ase_awk_run (handle, entry, &runios, NULL, runarg, this) == -1) { const ase_char_t* msg; @@ -780,11 +854,25 @@ HRESULT CAwk::Run (VARIANT_BOOL* ret) ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg); DBGOUT (_T("cannot run the program")); + + if (runarg != NULL) + { + for (long j = 0; j < nrunargs; j++) SysFreeString (runarg[j].ptr); + free (runarg); + } + *ret = VARIANT_FALSE; return S_OK; } else DBGOUT (_T("run the program successfully")); + + if (runarg != NULL) + { + for (long j = 0; j < nrunargs; j++) SysFreeString (runarg[j].ptr); + free (runarg); + } + *ret = VARIANT_TRUE; return S_OK; } @@ -1103,14 +1191,14 @@ STDMETHODIMP CAwk::put_UseCrlf(VARIANT_BOOL newVal) return S_OK; } -STDMETHODIMP CAwk::get_ArgsToMain(VARIANT_BOOL *pVal) +STDMETHODIMP CAwk::get_ArgumentsToEntryPoint(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) +STDMETHODIMP CAwk::put_ArgumentsToEntryPoint(VARIANT_BOOL newVal) { if (newVal) option = option | ASE_AWK_ARGSTOMAIN; else option = option & ~ASE_AWK_ARGSTOMAIN; diff --git a/ase/com/Awk.h b/ase/com/Awk.h index 1b4a7317..d02d4079 100644 --- a/ase/com/Awk.h +++ b/ase/com/Awk.h @@ -1,5 +1,5 @@ /* - * $Id: Awk.h,v 1.21 2007-04-15 15:26:58 bacon Exp $ + * $Id: Awk.h,v 1.22 2007-04-21 12:40:44 bacon Exp $ * * {License} */ @@ -124,8 +124,8 @@ public: STDMETHOD(put_MaxDepthForBlockRun)(/*[in]*/ int newVal); STDMETHOD(get_MaxDepthForBlockParse)(/*[out, retval]*/ int *pVal); STDMETHOD(put_MaxDepthForBlockParse)(/*[in]*/ int newVal); - STDMETHOD(get_ArgsToMain)(/*[out, retval]*/ VARIANT_BOOL *pVal); - STDMETHOD(put_ArgsToMain)(/*[in]*/ VARIANT_BOOL newVal); + STDMETHOD(get_ArgumentsToEntryPoint)(/*[out, retval]*/ VARIANT_BOOL *pVal); + STDMETHOD(put_ArgumentsToEntryPoint)(/*[in]*/ VARIANT_BOOL newVal); STDMETHOD(get_UseCrlf)(/*[out, retval]*/ VARIANT_BOOL *pVal); STDMETHOD(put_UseCrlf)(/*[in]*/ VARIANT_BOOL newVal); STDMETHOD(get_Nextofile)(/*[out, retval]*/ VARIANT_BOOL *pVal); @@ -156,6 +156,7 @@ public: STDMETHOD(get_ErrorLine)(/*[out, retval]*/ int *pVal); STDMETHOD(get_ErrorCode)(/*[out, retval]*/ int *pVal); + HRESULT __stdcall DeleteFunction ( /*[in]*/ BSTR name, /*[out, retval]*/ VARIANT_BOOL* ret); HRESULT __stdcall AddFunction ( @@ -163,7 +164,8 @@ public: /*[in]*/ int maxArgs, /*[out, retval]*/ VARIANT_BOOL* ret); HRESULT __stdcall Parse (/*[out, retval]*/ VARIANT_BOOL* ret); - HRESULT __stdcall Run (/*[out, retval]*/ VARIANT_BOOL* ret); + HRESULT __stdcall Run ( + /*[in]*/ VARIANT argarray, /*[out, retval]*/ VARIANT_BOOL* ret); }; #endif diff --git a/ase/com/asecom.idl b/ase/com/asecom.idl index f79844a7..8b4eed7d 100644 --- a/ase/com/asecom.idl +++ b/ase/com/asecom.idl @@ -1,5 +1,5 @@ /* - * $Id: asecom.idl,v 1.5 2007-04-15 15:26:58 bacon Exp $ + * $Id: asecom.idl,v 1.6 2007-04-21 12:40:44 bacon Exp $ */ import "oaidl.idl"; @@ -19,7 +19,7 @@ interface IAwk : IDispatch HRESULT Parse([out,retval] VARIANT_BOOL* ret); [id(2), helpstring("method Run")] - HRESULT Run([out,retval] VARIANT_BOOL* ret); + HRESULT Run([in] VARIANT argarray, [out,retval] VARIANT_BOOL* ret); [id(3), helpstring("method AddFunction")] HRESULT AddFunction([in] BSTR name, [in] int minArgs, [in] int maxArgs, [out,retval] VARIANT_BOOL* ret); @@ -101,10 +101,10 @@ interface IAwk : IDispatch [propput, id(20), helpstring("property UseCrlf")] HRESULT UseCrlf([in] VARIANT_BOOL newVal); - [propget, id(21), helpstring("property ArgsToMain")] - HRESULT ArgsToMain([out,retval] VARIANT_BOOL *pVal); - [propput, id(21), helpstring("property ArgsToMain")] - HRESULT ArgsToMain([in] VARIANT_BOOL newVal); + [propget, id(21), helpstring("property ArgumentsToEntryPoint")] + HRESULT ArgumentsToEntryPoint([out,retval] VARIANT_BOOL *pVal); + [propput, id(21), helpstring("property ArgumentsToEntryPoint")] + HRESULT ArgumentsToEntryPoint([in] VARIANT_BOOL newVal); [propget, id(22), helpstring("property MaxDepthForBlockParse")] HRESULT MaxDepthForBlockParse([out,retval] int *pVal); diff --git a/ase/test/com/AwkForm.frm b/ase/test/com/AwkForm.frm index 90533ffc..a3a1f44c 100644 --- a/ase/test/com/AwkForm.frm +++ b/ase/test/com/AwkForm.frm @@ -1,22 +1,53 @@ VERSION 5.00 Begin VB.Form AwkForm Caption = "ASE.COM.AWK" - ClientHeight = 7635 + ClientHeight = 8100 ClientLeft = 60 ClientTop = 345 - ClientWidth = 10335 + ClientWidth = 12900 LinkTopic = "AwkForm" - ScaleHeight = 7635 - ScaleWidth = 10335 + MaxButton = 0 'False + ScaleHeight = 8100 + ScaleWidth = 12900 StartUpPosition = 3 'Windows Default + Begin VB.CommandButton btnClearAll + Caption = "Clear All" + Height = 375 + Left = 240 + TabIndex = 14 + Top = 4560 + Width = 2295 + End + Begin VB.CommandButton btnAddArgument + Caption = "Add" + Height = 375 + Left = 1920 + TabIndex = 12 + Top = 4080 + Width = 615 + End + Begin VB.TextBox txtArgument + Height = 375 + Left = 240 + TabIndex = 11 + Top = 4080 + Width = 1575 + End + Begin VB.ListBox lstArguments + Height = 2595 + Left = 240 + TabIndex = 10 + Top = 1320 + Width = 2295 + End Begin VB.ComboBox EntryPoint Height = 315 ItemData = "AwkForm.frx":0000 - Left = 1080 + Left = 240 List = "AwkForm.frx":0007 TabIndex = 9 - Top = 120 - Width = 3495 + Top = 480 + Width = 2295 End Begin VB.TextBox ConsoleIn BeginProperty Font @@ -28,12 +59,12 @@ Begin VB.Form AwkForm Italic = 0 'False Strikethrough = 0 'False EndProperty - Height = 2895 - Left = 120 + Height = 3735 + Left = 2760 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 2 - Top = 3960 + Top = 4320 Width = 5055 End Begin VB.TextBox SourceIn @@ -46,12 +77,12 @@ Begin VB.Form AwkForm Italic = 0 'False Strikethrough = 0 'False EndProperty - Height = 2775 - Left = 120 + Height = 3615 + Left = 2760 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 0 - Top = 840 + Top = 360 Width = 5055 End Begin VB.TextBox SourceOut @@ -64,21 +95,21 @@ Begin VB.Form AwkForm Italic = 0 'False Strikethrough = 0 'False EndProperty - Height = 2775 - Left = 5280 + Height = 3615 + Left = 7920 Locked = -1 'True MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 1 - Top = 840 + Top = 360 Width = 4935 End - Begin VB.CommandButton Execute + Begin VB.CommandButton btnExecute Caption = "Execute" Height = 375 - Left = 9000 + Left = 1440 TabIndex = 5 - Top = 7080 + Top = 7680 Width = 1215 End Begin VB.TextBox ConsoleOut @@ -91,52 +122,68 @@ Begin VB.Form AwkForm Italic = 0 'False Strikethrough = 0 'False EndProperty - Height = 2895 - Left = 5280 + Height = 3735 + Left = 7920 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 3 - Top = 3960 + Top = 4320 Width = 4935 End - Begin VB.Label Label5 - Caption = "Entry Point:" - Height = 255 + Begin VB.Frame Frame1 + Caption = "Arguments" + Height = 4335 Left = 120 - TabIndex = 10 + TabIndex = 13 + Top = 1080 + Width = 2535 + Begin VB.CheckBox chkPassToEntryPoint + Caption = "Pass To Entry Point" + Height = 255 + Left = 360 + TabIndex = 16 + Top = 3960 + Width = 1815 + End + End + Begin VB.Frame Frame2 + Caption = "Entry Point" + Height = 855 + Left = 120 + TabIndex = 15 Top = 120 - Width = 1455 + Width = 2535 End Begin VB.Label Label4 Caption = "Console Out" Height = 255 - Left = 5280 + Left = 7920 TabIndex = 8 - Top = 3720 + Top = 4080 Width = 3735 End Begin VB.Label Label3 Caption = "Console In" Height = 255 - Left = 120 + Left = 2760 TabIndex = 7 - Top = 3720 + Top = 4080 Width = 3735 End Begin VB.Label Label2 Caption = "Source Out" Height = 255 - Left = 5280 + Left = 7920 TabIndex = 6 - Top = 600 + Top = 120 Width = 3735 End Begin VB.Label Label1 Caption = "Source In" Height = 255 - Left = 120 + Left = 2760 TabIndex = 4 - Top = 600 + Top = 120 Width = 2415 End End @@ -146,11 +193,27 @@ Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit +Option Base 0 Dim source_first As Boolean Public WithEvents Awk As ASELib.Awk Attribute Awk.VB_VarHelpID = -1 -Private Sub Execute_Click() +Private Sub btnAddArgument_Click() + Dim arg As String + + arg = txtArgument.Text + If Len(arg) > 0 Then + lstArguments.AddItem (arg) + txtArgument.Text = "" + txtArgument.SetFocus + End If +End Sub + +Private Sub btnClearAll_Click() + lstArguments.Clear +End Sub + +Private Sub btnExecute_Click() source_first = True @@ -191,8 +254,26 @@ Private Sub Execute_Click() If Not Awk.Parse() Then MsgBox "PARSE ERROR [" + Str(Awk.ErrorLine) + "]" + Awk.ErrorMessage Else + Dim n As Boolean + Awk.EntryPoint = Trim(EntryPoint.Text) - If Not Awk.Run() Then + + If lstArguments.ListCount = 0 Then + n = Awk.Run(Null) + Else + ReDim Args(lstArguments.ListCount - 1) As String + Dim i As Integer + + Awk.ArgumentsToEntryPoint = chkPassToEntryPoint.value + + For i = 0 To lstArguments.ListCount - 1 + Args(i) = lstArguments.List(i) + Next i + + n = Awk.Run(Args) + End If + + If Not n Then MsgBox "RUN ERROR [" + Str(Awk.ErrorLine) + "]" + Awk.ErrorMessage End If End If @@ -409,42 +490,42 @@ ErrorTrap: Exit Function End Function -Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal args As Variant) As Variant +Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal Args As Variant) As Variant If name = "sin" Then - If IsNull(args(0)) Then + If IsNull(Args(0)) Then Awk_HandleBuiltinFunction = Sin(0) - ElseIf IsNumeric(args(0)) Then - Awk_HandleBuiltinFunction = Sin(args(0)) + ElseIf IsNumeric(Args(0)) Then + Awk_HandleBuiltinFunction = Sin(Args(0)) Else - Awk_HandleBuiltinFunction = Sin(Val(args(0))) + Awk_HandleBuiltinFunction = Sin(Val(Args(0))) End If ElseIf name = "cos" Then - If TypeName(args(0)) = "Long" Or TypeName(args(0)) = "Double" Then - Awk_HandleBuiltinFunction = Cos(args(0)) - ElseIf TypeName(args(0)) = "String" Then - Awk_HandleBuiltinFunction = Cos(Val(args(0))) - ElseIf TypeName(args(0)) = "Null" Then + If TypeName(Args(0)) = "Long" Or TypeName(Args(0)) = "Double" Then + Awk_HandleBuiltinFunction = Cos(Args(0)) + ElseIf TypeName(Args(0)) = "String" Then + Awk_HandleBuiltinFunction = Cos(Val(Args(0))) + ElseIf TypeName(Args(0)) = "Null" Then Awk_HandleBuiltinFunction = Cos(0) End If ElseIf name = "tan" Then - If TypeName(args(0)) = "Long" Or TypeName(args(0)) = "Double" Then - Awk_HandleBuiltinFunction = Tan(args(0)) - ElseIf TypeName(args(0)) = "String" Then - Awk_HandleBuiltinFunction = Tan(Val(args(0))) - ElseIf TypeName(args(0)) = "Null" Then + If TypeName(Args(0)) = "Long" Or TypeName(Args(0)) = "Double" Then + Awk_HandleBuiltinFunction = Tan(Args(0)) + ElseIf TypeName(Args(0)) = "String" Then + Awk_HandleBuiltinFunction = Tan(Val(Args(0))) + ElseIf TypeName(Args(0)) = "Null" Then Awk_HandleBuiltinFunction = Tan(0) End If ElseIf name = "sqrt" Then - If IsNull(args(0)) Then + If IsNull(Args(0)) Then Awk_HandleBuiltinFunction = Sqr(0) - ElseIf IsNumeric(args(0)) Then - Awk_HandleBuiltinFunction = Sqr(args(0)) + ElseIf IsNumeric(Args(0)) Then + Awk_HandleBuiltinFunction = Sqr(Args(0)) Else - Awk_HandleBuiltinFunction = Sqr(Val(args(0))) + Awk_HandleBuiltinFunction = Sqr(Val(Args(0))) End If ElseIf name = "trim" Then - Awk_HandleBuiltinFunction = Trim(args(0)) + Awk_HandleBuiltinFunction = Trim(Args(0)) End If 'Dim i As Integer @@ -459,6 +540,7 @@ Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal args As Variant) 'MsgBox xxx End Function + Private Sub Form_Load() SourceIn.Text = "" SourceOut.Text = "" diff --git a/ase/test/com/ase.vbw b/ase/test/com/ase.vbw index f5ccef48..a068e5db 100644 --- a/ase/test/com/ase.vbw +++ b/ase/test/com/ase.vbw @@ -1,2 +1,2 @@ -AwkForm = 13, 12, 735, 661, C, 22, 22, 753, 640, C +AwkForm = 13, 12, 735, 661, , 22, 22, 753, 640, C AwkExtioConsole = 0, 0, 547, 460, C