~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/KviKvsReport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviKvsReport.cpp
 
4
//   Creation date : Thu 25 Sep 2003 05.12 CEST by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2003-2010 Szymon Stefanek (pragma at kvirc dot net)
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#include "KviKvsReport.h"
 
26
#include "KviControlCodes.h"
 
27
#include "KviWindow.h"
 
28
#include "kvi_out.h"
 
29
#include "KviApplication.h"
 
30
#include "KviLocale.h"
 
31
#include "KviDebugWindow.h"
 
32
#include "KviOptions.h"
 
33
 
 
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)
 
36
{
 
37
        m_pCallStack = 0;
 
38
        m_pCodeListing = 0;
 
39
}
 
40
 
 
41
KviKvsReport::~KviKvsReport()
 
42
{
 
43
        if(m_pCallStack)delete m_pCallStack;
 
44
        if(m_pCodeListing)delete m_pCodeListing;
 
45
}
 
46
 
 
47
void KviKvsReport::findLineAndCol(const QChar * pBegin,const QChar * pPoint,int &iLine,int &iCol)
 
48
{
 
49
        iLine = 1;
 
50
 
 
51
        const QChar * pLineBegin = pBegin;
 
52
 
 
53
        unsigned short us = pBegin->unicode();
 
54
 
 
55
        while(us && (pBegin < pPoint))
 
56
        {
 
57
                if(us == '\n')
 
58
                {
 
59
                        pBegin++;
 
60
                        pLineBegin = pBegin;
 
61
                        iLine++;
 
62
                } else {
 
63
                        pBegin++;
 
64
                }
 
65
                us = pBegin->unicode();
 
66
        }
 
67
 
 
68
        iCol = (pBegin - pLineBegin) + 1;
 
69
}
 
70
 
 
71
 
 
72
 
 
73
void KviKvsReport::findLineColAndListing(const QChar * pBegin,const QChar * pPoint,int &iLine,int &iCol,KviPointerList<QString> * pListing)
 
74
{
 
75
        iLine = 1;
 
76
 
 
77
        const QChar * pBufferBegin = pBegin;
 
78
        const QChar * pPrevLine = 0;
 
79
        const QChar * pLineBegin = pBegin;
 
80
 
 
81
        unsigned short us = pBegin->unicode();
 
82
 
 
83
        while(us && (pBegin < pPoint))
 
84
        {
 
85
                if(us == '\n')
 
86
                {
 
87
                        pPrevLine = pLineBegin;
 
88
                        pBegin++;
 
89
                        pLineBegin = pBegin;
 
90
                        iLine++;
 
91
                } else {
 
92
                        pBegin++;
 
93
                }
 
94
                us = pBegin->unicode();
 
95
        }
 
96
 
 
97
        iCol = (pBegin - pLineBegin) + 1;
 
98
 
 
99
        // previous line
 
100
        if(pPrevLine)
 
101
        {
 
102
                // there would be yet another line before
 
103
                if(pPrevLine > pBufferBegin)
 
104
                {
 
105
                        QString * pListingStrZ = new QString(QString("%1 ...").arg(iLine - 2));
 
106
                        pListing->append(pListingStrZ);
 
107
                }
 
108
 
 
109
                QString * pListingStr = new QString(QString("%1 ").arg(iLine - 1));
 
110
                *pListingStr += QString(pPrevLine,pLineBegin - pPrevLine);
 
111
                pListingStr->replace("\n","");
 
112
                pListing->append(pListingStr);
 
113
        }
 
114
 
 
115
        // current line
 
116
        pBegin = pLineBegin;
 
117
 
 
118
        us = pBegin->unicode();
 
119
        while(us && (us != '\n'))
 
120
        {
 
121
                pBegin++;
 
122
                us = pBegin->unicode();
 
123
        }
 
124
        if(us)pBegin++;
 
125
 
 
126
        {
 
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);
 
131
        }
 
132
 
 
133
        if(us)
 
134
        {
 
135
                // next line
 
136
                pLineBegin = pBegin;
 
137
 
 
138
                us = pBegin->unicode();
 
139
                while(us && (us != '\n'))
 
140
                {
 
141
                        pBegin++;
 
142
                        us = pBegin->unicode();
 
143
                }
 
144
                if(us)pBegin++;
 
145
 
 
146
                {
 
147
                        QString * pListingStr = new QString(QString("%1 ").arg(iLine + 1));
 
148
                        *pListingStr += QString(pLineBegin,pBegin - pLineBegin);
 
149
                        pListingStr->replace("\n","");
 
150
                        pListing->append(pListingStr);
 
151
                }
 
152
 
 
153
                // there would be yet another line
 
154
                if(us)
 
155
                {
 
156
                        QString * pListingStr = new QString(QString("%1 ...").arg(iLine + 2));
 
157
                        pListing->append(pListingStr);
 
158
                }
 
159
        }
 
160
}
 
161
 
 
162
////////////////////////////////////////////////////////////////////////////////
 
163
// ERROR REPORTING
 
164
 
 
165
void KviKvsReport::report(KviKvsReport * r,KviWindow * pOutput)
 
166
{
 
167
        if(!pOutput)
 
168
                return; // ?
 
169
 
 
170
        if(!g_pApp->windowExists(pOutput))
 
171
        {
 
172
                if(KVI_OPTION_BOOL(KviOption_boolScriptErrorsToDebugWindow))
 
173
                {
 
174
                        // rethrow to the debug window
 
175
                        report(r,KviDebugWindow::getInstance());
 
176
                } // else window lost: unrecoverable
 
177
                return;
 
178
        }
 
179
 
 
180
        // make sure that the output window still exists!
 
181
 
 
182
        int out=0;
 
183
 
 
184
        switch(r->type())
 
185
        {
 
186
                case KviKvsReport::ParserWarning:
 
187
                        out = KVI_OUT_PARSERWARNING;
 
188
                        pOutput->output(out,__tr2qs_ctx("[KVS]%c Warning: %Q","kvs"),KviControlCodes::Bold,&(r->message()));
 
189
                break;
 
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()));
 
193
                break;
 
194
                case KviKvsReport::RunTimeWarning:
 
195
                        out = KVI_OUT_PARSERWARNING;
 
196
                        pOutput->output(out,__tr2qs_ctx("[KVS]%c Warning: %Q","kvs"),KviControlCodes::Bold,&(r->message()));
 
197
                break;
 
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()));
 
201
                break;
 
202
        }
 
203
 
 
204
        if(r->location().isEmpty())
 
205
                pOutput->output(out,__tr2qs_ctx("[KVS]   in script context \"%Q\"","kvs"),&(r->context()));
 
206
        else
 
207
                pOutput->output(out,__tr2qs_ctx("[KVS]   in script context \"%Q\", %Q","kvs"),&(r->context()),&(r->location()));
 
208
 
 
209
        if(pOutput == KviDebugWindow::instance())
 
210
        {
 
211
                KviPointerList<QString> * l;
 
212
                if( (l = r->codeListing()) )
 
213
                {
 
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);
 
217
                }
 
218
 
 
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());
 
222
                        else
 
223
                                pOutput->output(out,__tr2qs_ctx("[KVS]   Destroyed window with pointer %x","kvs"),r->window());
 
224
 
 
225
                if( (l = r->callStack()) )
 
226
                {
 
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);
 
230
                }
 
231
 
 
232
                pOutput->outputNoFmt(out,"[KVS]");
 
233
        } else {
 
234
                if(KVI_OPTION_BOOL(KviOption_boolScriptErrorsToDebugWindow))
 
235
                {
 
236
                        // rethrow to the debug window
 
237
                        if(pOutput != KviDebugWindow::getInstance())
 
238
                                report(r,KviDebugWindow::getInstance());
 
239
                }
 
240
        }
 
241
}