зеркало из https://github.com/mozilla/pjs.git
Added code to parse a script from a file
Changed some "tstring &" refs to "TCHAR *"
This commit is contained in:
Родитель
23ad32bc5b
Коммит
295963af15
|
@ -17,7 +17,8 @@
|
|||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "ActiveScriptSite.h"
|
||||
|
||||
|
||||
|
@ -91,14 +92,14 @@ HRESULT CActiveScriptSite::AttachJScript()
|
|||
}
|
||||
|
||||
|
||||
HRESULT CActiveScriptSite::AddNamedObject(const tstring &szName, IUnknown *pObject, BOOL bGlobalMembers)
|
||||
HRESULT CActiveScriptSite::AddNamedObject(const TCHAR *szName, IUnknown *pObject, BOOL bGlobalMembers)
|
||||
{
|
||||
if (m_spIActiveScript == NULL)
|
||||
{
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (pObject == NULL || szName.empty())
|
||||
if (pObject == NULL || szName == NULL)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
@ -122,8 +123,7 @@ HRESULT CActiveScriptSite::AddNamedObject(const tstring &szName, IUnknown *pObje
|
|||
dwFlags |= SCRIPTITEM_GLOBALMEMBERS;
|
||||
}
|
||||
|
||||
|
||||
hr = m_spIActiveScript->AddNamedItem(T2OLE(szName.c_str()), dwFlags);
|
||||
hr = m_spIActiveScript->AddNamedItem(T2OLE(szName), dwFlags);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
@ -135,7 +135,41 @@ HRESULT CActiveScriptSite::AddNamedObject(const tstring &szName, IUnknown *pObje
|
|||
}
|
||||
|
||||
|
||||
HRESULT CActiveScriptSite::ParseScriptText(const tstring &szScript)
|
||||
HRESULT CActiveScriptSite::ParseScriptFile(const TCHAR *szFile)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
const char *pszFileName = T2CA(szFile);
|
||||
|
||||
// Stat the file and get its length;
|
||||
struct _stat cStat;
|
||||
_stat(pszFileName, &cStat);
|
||||
|
||||
// Allocate a buffer
|
||||
size_t nBufSize = cStat.st_size + 1;
|
||||
char *pBuffer = (char *) malloc(nBufSize);
|
||||
if (pBuffer == NULL)
|
||||
{
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
memset(pBuffer, 0, nBufSize);
|
||||
|
||||
// Read the script into the buffer and parse it
|
||||
HRESULT hr = E_FAIL;
|
||||
FILE *f = fopen(pszFileName, "rb");
|
||||
if (f)
|
||||
{
|
||||
fread(pBuffer, 1, nBufSize - 1, f);
|
||||
hr = ParseScriptText(A2T(pBuffer));
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
free(pBuffer);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CActiveScriptSite::ParseScriptText(const TCHAR *szScript)
|
||||
{
|
||||
if (m_spIActiveScript == NULL)
|
||||
{
|
||||
|
@ -154,7 +188,7 @@ HRESULT CActiveScriptSite::ParseScriptText(const tstring &szScript)
|
|||
HRESULT hr;
|
||||
|
||||
hr = spIActiveScriptParse->ParseScriptText(
|
||||
T2OLE(szScript.c_str()),
|
||||
T2OLE(szScript),
|
||||
NULL, NULL, NULL, dwCookie, 0, dwFlags,
|
||||
&vResult, &cExcepInfo);
|
||||
|
||||
|
|
|
@ -41,22 +41,30 @@ END_COM_MAP()
|
|||
|
||||
// Attach to the specified script engine
|
||||
virtual HRESULT Attach(CLSID clsidScriptEngine);
|
||||
// Attach to the VBScript engine
|
||||
// Helper to attach to the VBScript engine
|
||||
virtual HRESULT AttachVBScript();
|
||||
// Attach to the JScript engine
|
||||
// Helper to attach to the JScript engine
|
||||
virtual HRESULT AttachJScript();
|
||||
// Detach from the script engine
|
||||
virtual HRESULT Detach();
|
||||
// Return the current state of the script engine
|
||||
virtual SCRIPTSTATE GetScriptState() const
|
||||
{
|
||||
return m_ssScriptState;
|
||||
}
|
||||
|
||||
// Parse the specified script
|
||||
virtual HRESULT ParseScriptText(const tstring &szScript);
|
||||
virtual HRESULT ParseScriptText(const TCHAR *szScript);
|
||||
// Parse the specified script from a file
|
||||
virtual HRESULT ParseScriptFile(const TCHAR *szFile);
|
||||
// Add object to script address space
|
||||
virtual HRESULT AddNamedObject(const tstring &szName, IUnknown *pObject, BOOL bGlobalMembers = FALSE);
|
||||
virtual HRESULT AddNamedObject(const TCHAR *szName, IUnknown *pObject, BOOL bGlobalMembers = FALSE);
|
||||
// Play the script
|
||||
virtual HRESULT PlayScript();
|
||||
// Stop the script
|
||||
virtual HRESULT StopScript();
|
||||
|
||||
public:
|
||||
// IActiveScriptSite
|
||||
virtual HRESULT STDMETHODCALLTYPE GetLCID(/* [out] */ LCID __RPC_FAR *plcid);
|
||||
virtual HRESULT STDMETHODCALLTYPE GetItemInfo(/* [in] */ LPCOLESTR pstrName, /* [in] */ DWORD dwReturnMask, /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem, /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppti);
|
||||
|
|
Загрузка…
Ссылка в новой задаче