1
//=============================================================================
3
// File : kvi_kvs_runtimecontext.cpp
4
// Creation date : Tue 07 Oct 2003 01:49:40 by Szymon Stefanek
6
// This file is part of the KVIrc IRC client distribution
7
// Copyright (C) 2003-2008 Szymon Stefanek <pragma at kvirc dot net>
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#include "kvi_kvs_runtimecontext.h"
26
#include "kvi_kvs_script.h"
27
#include "kvi_kvs_kernel.h"
28
#include "kvi_kvs_report.h"
29
#include "kvi_console.h"
30
#include "kvi_kvs_treenode_base.h"
31
#include "kvi_locale.h"
33
#include "kvi_kvs_object.h"
35
KviKvsExtendedRunTimeData::~KviKvsExtendedRunTimeData()
39
if(m_pExtendedScopeVariables) delete m_pExtendedScopeVariables;
40
if(m_pAliasSwitchList) delete m_pAliasSwitchList;
41
if(m_pThisObject) delete m_pThisObject;
42
if(m_pScriptFilePath) delete m_pScriptFilePath;
46
KviKvsRunTimeContext::KviKvsRunTimeContext(KviKvsScript * pScript,KviWindow * pWnd,KviKvsVariantList * pParams,KviKvsVariant * pRetVal,KviKvsExtendedRunTimeData * pExtData)
50
m_pParameterList = pParams;
52
m_pLocalVariables = new KviKvsHash();
53
m_pReturnValue = pRetVal;
55
m_pExtendedData = pExtData;
56
m_pDefaultReportLocation = 0;
59
KviKvsRunTimeContext::~KviKvsRunTimeContext()
61
delete m_pLocalVariables;
64
KviKvsHash * KviKvsRunTimeContext::globalVariables()
66
return KviKvsKernel::instance()->globalVariables();
69
void KviKvsRunTimeContext::enterBlockingSection()
74
bool KviKvsRunTimeContext::leaveBlockingSection()
76
if(g_pApp->closingDown())return false; // application quitting
77
if(!g_pApp->windowExists(m_pWindow))return false; // window lost
81
KviKvsVariant * KviKvsRunTimeContext::swapReturnValuePointer(KviKvsVariant * pNewPointer)
83
KviKvsVariant * pAux = m_pReturnValue;
84
m_pReturnValue = pNewPointer;
88
void KviKvsRunTimeContext::report(bool bError,KviKvsTreeNode * pNode,const QString &szMsgFmt,kvi_va_list va)
91
KviQString::vsprintf(szMsg,szMsgFmt,va);
93
KviPointerList<QString> * pCodeListing = 0;
94
KviPointerList<QString> * pCallStack = 0;
99
if(pNode->location() && m_pScript)
101
pCodeListing = new KviPointerList<QString>;
102
pCodeListing->setAutoDelete(true);
106
KviKvsReport::findLineColAndListing(m_pScript->buffer(),pNode->location(),iLine,iCol,pCodeListing);
108
KviQString::sprintf(szLocation,__tr2qs_ctx("line %d, near character %d","kvs"),iLine,iCol);
111
// create the call stack
114
pCallStack = new KviPointerList<QString>;
115
pCallStack->setAutoDelete(true);
117
while(pNode && (iFrame < 12))
119
QString * pString = new QString();
121
pNode->contextDescription(szTmp);
122
KviQString::sprintf(*pString,"#%d %Q",iFrame,&szTmp);
123
if(pNode->location())
126
KviKvsReport::findLineAndCol(m_pScript->buffer(),pNode->location(),iLine,iCol);
128
KviQString::sprintf(tmpi," [line %d, near character %d]",iLine,iCol);
131
pCallStack->append(pString);
133
pNode = pNode->parent();
136
pCallStack->append(new QString("#12 ..."));
139
QString szContext = m_pScript ? m_pScript->name() : "kvirc core code";
140
KviKvsReport rep(bError ? KviKvsReport::RunTimeError : KviKvsReport::RunTimeWarning,szContext,szMsg,szLocation,m_pWindow);
141
if(pCodeListing)rep.setCodeListing(pCodeListing);
142
if(pCallStack)rep.setCallStack(pCallStack);
144
KviKvsReport::report(&rep,m_pWindow);
147
void KviKvsRunTimeContext::error(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
152
kvi_va_start_by_reference(va,szMsgFmt);
153
report(true,pNode,szMsgFmt,va);
157
void KviKvsRunTimeContext::warning(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
160
kvi_va_start_by_reference(va,szMsgFmt);
161
report(false,pNode,szMsgFmt,va);
165
void KviKvsRunTimeContext::error(const QString &szMsgFmt,...)
170
kvi_va_start_by_reference(va,szMsgFmt);
171
report(true,m_pDefaultReportLocation,szMsgFmt,va);
175
void KviKvsRunTimeContext::warning(const QString &szMsgFmt,...)
178
kvi_va_start_by_reference(va,szMsgFmt);
179
report(false,m_pDefaultReportLocation,szMsgFmt,va);
183
bool KviKvsRunTimeContext::errorNoIrcContext()
185
error(m_pDefaultReportLocation,__tr2qs_ctx("This command can be used only in windows bound to an IRC context","kvs"));
189
bool KviKvsRunTimeContext::warningNoIrcConnection()
191
warning(m_pDefaultReportLocation,__tr2qs_ctx("You're not connected to an IRC server","kvs"));
195
bool KviKvsRunTimeContext::warningMissingParameter()
197
warning(m_pDefaultReportLocation,__tr2qs_ctx("Missing parameter","kvs"));
201
void KviKvsRunTimeContext::setDefaultReportLocation(KviKvsTreeNode * pNode)
203
m_pDefaultReportLocation = pNode;