1
//=============================================================================
3
// File : KviKvsReport.cpp
4
// Creation date : Thu 25 Sep 2003 05.12 CEST by Szymon Stefanek
6
// This file is part of the KVIrc irc client distribution
7
// Copyright (C) 2003-2010 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 "KviKvsReport.h"
26
#include "KviControlCodes.h"
27
#include "KviWindow.h"
29
#include "KviApplication.h"
30
#include "KviLocale.h"
31
#include "KviDebugWindow.h"
32
#include "KviOptions.h"
34
KviKvsReport::KviKvsReport(Type t,const QString &szContext,const QString &szMessage,const QString &szLocation,KviWindow * pWindow)
35
: m_eType(t), m_szContext(szContext), m_szMessage(szMessage), m_szLocation(szLocation), m_pWindow(pWindow)
41
KviKvsReport::~KviKvsReport()
43
if(m_pCallStack)delete m_pCallStack;
44
if(m_pCodeListing)delete m_pCodeListing;
47
void KviKvsReport::findLineAndCol(const QChar * pBegin,const QChar * pPoint,int &iLine,int &iCol)
51
const QChar * pLineBegin = pBegin;
53
unsigned short us = pBegin->unicode();
55
while(us && (pBegin < pPoint))
65
us = pBegin->unicode();
68
iCol = (pBegin - pLineBegin) + 1;
73
void KviKvsReport::findLineColAndListing(const QChar * pBegin,const QChar * pPoint,int &iLine,int &iCol,KviPointerList<QString> * pListing)
77
const QChar * pBufferBegin = pBegin;
78
const QChar * pPrevLine = 0;
79
const QChar * pLineBegin = pBegin;
81
unsigned short us = pBegin->unicode();
83
while(us && (pBegin < pPoint))
87
pPrevLine = pLineBegin;
94
us = pBegin->unicode();
97
iCol = (pBegin - pLineBegin) + 1;
102
// there would be yet another line before
103
if(pPrevLine > pBufferBegin)
105
QString * pListingStrZ = new QString(QString("%1 ...").arg(iLine - 2));
106
pListing->append(pListingStrZ);
109
QString * pListingStr = new QString(QString("%1 ").arg(iLine - 1));
110
*pListingStr += QString(pPrevLine,pLineBegin - pPrevLine);
111
pListingStr->replace("\n","");
112
pListing->append(pListingStr);
118
us = pBegin->unicode();
119
while(us && (us != '\n'))
122
us = pBegin->unicode();
127
QString * pListingStr = new QString(QString("%1%2 ").arg(QChar(KviControlCodes::Bold)).arg(iLine));
128
*pListingStr += QString(pLineBegin,pBegin - pLineBegin);
129
pListingStr->replace("\n","");
130
pListing->append(pListingStr);
138
us = pBegin->unicode();
139
while(us && (us != '\n'))
142
us = pBegin->unicode();
147
QString * pListingStr = new QString(QString("%1 ").arg(iLine + 1));
148
*pListingStr += QString(pLineBegin,pBegin - pLineBegin);
149
pListingStr->replace("\n","");
150
pListing->append(pListingStr);
153
// there would be yet another line
156
QString * pListingStr = new QString(QString("%1 ...").arg(iLine + 2));
157
pListing->append(pListingStr);
162
////////////////////////////////////////////////////////////////////////////////
165
void KviKvsReport::report(KviKvsReport * r,KviWindow * pOutput)
170
if(!g_pApp->windowExists(pOutput))
172
if(KVI_OPTION_BOOL(KviOption_boolScriptErrorsToDebugWindow))
174
// rethrow to the debug window
175
report(r,KviDebugWindow::getInstance());
176
} // else window lost: unrecoverable
180
// make sure that the output window still exists!
186
case KviKvsReport::ParserWarning:
187
out = KVI_OUT_PARSERWARNING;
188
pOutput->output(out,__tr2qs_ctx("[KVS]%c Warning: %Q","kvs"),KviControlCodes::Bold,&(r->message()));
190
case KviKvsReport::ParserError:
191
out = KVI_OUT_PARSERERROR;
192
pOutput->output(out,__tr2qs_ctx("[KVS]%c Compilation Error: %Q","kvs"),KviControlCodes::Bold,&(r->message()));
194
case KviKvsReport::RunTimeWarning:
195
out = KVI_OUT_PARSERWARNING;
196
pOutput->output(out,__tr2qs_ctx("[KVS]%c Warning: %Q","kvs"),KviControlCodes::Bold,&(r->message()));
198
case KviKvsReport::RunTimeError:
199
out = KVI_OUT_PARSERERROR;
200
pOutput->output(out,__tr2qs_ctx("[KVS]%c Runtime Error: %Q","kvs"),KviControlCodes::Bold,&(r->message()));
204
if(r->location().isEmpty())
205
pOutput->output(out,__tr2qs_ctx("[KVS] in script context \"%Q\"","kvs"),&(r->context()));
207
pOutput->output(out,__tr2qs_ctx("[KVS] in script context \"%Q\", %Q","kvs"),&(r->context()),&(r->location()));
209
if(pOutput == KviDebugWindow::instance())
211
KviPointerList<QString> * l;
212
if( (l = r->codeListing()) )
214
pOutput->outputNoFmt(out,__tr2qs_ctx("[KVS] Code listing:","kvs"));
215
for(QString * s = l->first();s;s = l->next())
216
pOutput->output(out,"[KVS] %Q",s);
219
pOutput->output(out,__tr2qs_ctx("[KVS] Window:","kvs"));
220
if(g_pApp->windowExists(r->window()))
221
pOutput->output(out,"[KVS] %Q [id: %u]",&(r->window()->windowName()),r->window()->numericId());
223
pOutput->output(out,__tr2qs_ctx("[KVS] Destroyed window with pointer %x","kvs"),r->window());
225
if( (l = r->callStack()) )
227
pOutput->outputNoFmt(out,__tr2qs_ctx("[KVS] Call stack:","kvs"));
228
for(QString * s = l->first();s;s = l->next())
229
pOutput->output(out,"[KVS] %Q",s);
232
pOutput->outputNoFmt(out,"[KVS]");
234
if(KVI_OPTION_BOOL(KviOption_boolScriptErrorsToDebugWindow))
236
// rethrow to the debug window
237
if(pOutput != KviDebugWindow::getInstance())
238
report(r,KviDebugWindow::getInstance());