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

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/tree/KviKvsTreeNodeSpecialCommandSwitch.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 : KviKvsTreeNodeSpecialCommandSwitch.cpp
 
4
//   Creation date : Fri 02 Jan 2004 14:09:00 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc IRC client distribution
 
7
//   Copyright (C) 2004-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 "KviKvsTreeNodeSpecialCommandSwitch.h"
 
26
#include "KviKvsTreeNodeExpression.h"
 
27
#include "KviKvsTreeNodeInstruction.h"
 
28
#include "KviKvsRunTimeContext.h"
 
29
#include "KviLocale.h"
 
30
 
 
31
#include <QRegExp>
 
32
 
 
33
KviKvsTreeNodeSpecialCommandSwitchLabel::KviKvsTreeNodeSpecialCommandSwitchLabel(const QChar * pLocation)
 
34
: KviKvsTreeNode(pLocation)
 
35
{
 
36
        m_pParameter = 0;
 
37
        m_pInstruction = 0;
 
38
        m_bHasTerminatingBreak = false;
 
39
}
 
40
 
 
41
KviKvsTreeNodeSpecialCommandSwitchLabel::~KviKvsTreeNodeSpecialCommandSwitchLabel()
 
42
{
 
43
        if(m_pParameter)delete m_pParameter;
 
44
        if(m_pInstruction)delete m_pInstruction;
 
45
}
 
46
 
 
47
void KviKvsTreeNodeSpecialCommandSwitchLabel::setParameter(KviKvsTreeNodeData * pParameter)
 
48
{
 
49
        if(m_pParameter)delete m_pParameter;
 
50
        m_pParameter = pParameter;
 
51
        if(m_pParameter)m_pParameter->setParent(this);
 
52
}
 
53
 
 
54
void KviKvsTreeNodeSpecialCommandSwitchLabel::setInstruction(KviKvsTreeNodeInstruction * pInstruction)
 
55
{
 
56
        if(m_pInstruction)delete m_pInstruction;
 
57
        m_pInstruction = pInstruction;
 
58
        if(m_pInstruction)m_pInstruction->setParent(this);
 
59
}
 
60
 
 
61
 
 
62
KviKvsTreeNodeSpecialCommandSwitchLabelCase::KviKvsTreeNodeSpecialCommandSwitchLabelCase(const QChar * pLocation)
 
63
: KviKvsTreeNodeSpecialCommandSwitchLabel(pLocation)
 
64
{
 
65
}
 
66
 
 
67
KviKvsTreeNodeSpecialCommandSwitchLabelCase::~KviKvsTreeNodeSpecialCommandSwitchLabelCase()
 
68
{
 
69
}
 
70
 
 
71
void KviKvsTreeNodeSpecialCommandSwitchLabelCase::contextDescription(QString &szBuffer)
 
72
{
 
73
        szBuffer = "Label \"case\" For Special Command \"switch\"";
 
74
}
 
75
 
 
76
void KviKvsTreeNodeSpecialCommandSwitchLabelCase::dump(const char * prefix)
 
77
{
 
78
        qDebug("%s SpecialCommandSwitchLabelCase",prefix);
 
79
        QString tmp = prefix;
 
80
        tmp.append("  ");
 
81
        if(m_pParameter)m_pParameter->dump(tmp.toUtf8().data());
 
82
        if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
 
83
}
 
84
 
 
85
bool KviKvsTreeNodeSpecialCommandSwitchLabelCase::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
 
86
{
 
87
        if(!(*bPassThrough))
 
88
        {
 
89
                KviKvsVariant v;
 
90
                if(!m_pParameter->evaluateReadOnly(c,&v))return false;
 
91
 
 
92
                KviKvsNumber num;
 
93
                if(pRealParameter->asNumber(num))
 
94
                {
 
95
                        KviKvsNumber num2;
 
96
                        if(!v.asNumber(num2))return true; // a number and a non number can't match
 
97
                        if(num.isInteger())
 
98
                        {
 
99
                                if(num2.isInteger())
 
100
                                {
 
101
                                        if(num.integer() != num2.integer())return true;
 
102
                                } else {
 
103
                                        if(((double)(num.integer())) != num2.real())return true;
 
104
                                }
 
105
                        } else {
 
106
                                if(num2.isInteger())
 
107
                                {
 
108
                                        if(num.real() != ((double)(num2.integer())))return true;
 
109
                                } else {
 
110
                                        if(num.real() != num2.real())return true;
 
111
                                }
 
112
                        }
 
113
                } else {
 
114
                        // string comparision, case insensitive
 
115
                        QString reg;
 
116
                        v.asString(reg);
 
117
 
 
118
                        QString val;
 
119
                        pRealParameter->asString(val);
 
120
 
 
121
                        if(reg.toLower() != val.toLower())return true;
 
122
                }
 
123
        }
 
124
 
 
125
        *bPassThrough = true;
 
126
 
 
127
        if(m_pInstruction)
 
128
        {
 
129
                if(!m_pInstruction->execute(c))return false; // might be a break too
 
130
        }
 
131
        if(m_bHasTerminatingBreak)
 
132
        {
 
133
                c->setBreakPending();
 
134
                return false;
 
135
        }
 
136
        return true;
 
137
}
 
138
 
 
139
 
 
140
KviKvsTreeNodeSpecialCommandSwitchLabelMatch::KviKvsTreeNodeSpecialCommandSwitchLabelMatch(const QChar * pLocation)
 
141
: KviKvsTreeNodeSpecialCommandSwitchLabel(pLocation)
 
142
{
 
143
}
 
144
 
 
145
KviKvsTreeNodeSpecialCommandSwitchLabelMatch::~KviKvsTreeNodeSpecialCommandSwitchLabelMatch()
 
146
{
 
147
}
 
148
 
 
149
void KviKvsTreeNodeSpecialCommandSwitchLabelMatch::contextDescription(QString &szBuffer)
 
150
{
 
151
        szBuffer = "Label \"match\" For Special Command \"switch\"";
 
152
}
 
153
 
 
154
void KviKvsTreeNodeSpecialCommandSwitchLabelMatch::dump(const char * prefix)
 
155
{
 
156
        qDebug("%s SpecialCommandSwitchLabelMatch",prefix);
 
157
        QString tmp = prefix;
 
158
        tmp.append("  ");
 
159
        if(m_pParameter)m_pParameter->dump(tmp.toUtf8().data());
 
160
        if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
 
161
}
 
162
 
 
163
bool KviKvsTreeNodeSpecialCommandSwitchLabelMatch::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
 
164
{
 
165
        if(!(*bPassThrough))
 
166
        {
 
167
                KviKvsVariant v;
 
168
                if(!m_pParameter->evaluateReadOnly(c,&v))return false;
 
169
 
 
170
                QString reg;
 
171
                v.asString(reg);
 
172
 
 
173
                //QRegExp rx(reg,false,true);
 
174
                QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::Wildcard);
 
175
                QString val;
 
176
                pRealParameter->asString(val);
 
177
 
 
178
                if(!rx.exactMatch(val))return true; // no match
 
179
        }
 
180
 
 
181
        *bPassThrough = true;
 
182
 
 
183
        if(m_pInstruction)
 
184
        {
 
185
                if(!m_pInstruction->execute(c))return false; // might be a break too
 
186
        }
 
187
        if(m_bHasTerminatingBreak)
 
188
        {
 
189
                c->setBreakPending();
 
190
                return false;
 
191
        }
 
192
        return true;
 
193
}
 
194
 
 
195
 
 
196
KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::KviKvsTreeNodeSpecialCommandSwitchLabelRegexp(const QChar * pLocation)
 
197
: KviKvsTreeNodeSpecialCommandSwitchLabel(pLocation)
 
198
{
 
199
}
 
200
 
 
201
KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::~KviKvsTreeNodeSpecialCommandSwitchLabelRegexp()
 
202
{
 
203
}
 
204
 
 
205
void KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::contextDescription(QString &szBuffer)
 
206
{
 
207
        szBuffer = "Label \"regexp\" For Special Command \"switch\"";
 
208
}
 
209
 
 
210
void KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::dump(const char * prefix)
 
211
{
 
212
        qDebug("%s SpecialCommandSwitchLabelRegexp",prefix);
 
213
        QString tmp = prefix;
 
214
        tmp.append("  ");
 
215
        if(m_pParameter)m_pParameter->dump(tmp.toUtf8().data());
 
216
        if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
 
217
}
 
218
 
 
219
bool KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
 
220
{
 
221
        if(!(*bPassThrough))
 
222
        {
 
223
                KviKvsVariant v;
 
224
                if(!m_pParameter->evaluateReadOnly(c,&v))return false;
 
225
 
 
226
                QString reg;
 
227
                v.asString(reg);
 
228
 
 
229
        //      QRegExp rx(reg,false,false);
 
230
                QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::RegExp);
 
231
                QString val;
 
232
                pRealParameter->asString(val);
 
233
 
 
234
                if(!rx.exactMatch(val))return true; // no match
 
235
        }
 
236
 
 
237
        *bPassThrough = true;
 
238
 
 
239
        if(m_pInstruction)
 
240
        {
 
241
                if(!m_pInstruction->execute(c))return false; // might be a break too
 
242
        }
 
243
        if(m_bHasTerminatingBreak)
 
244
        {
 
245
                c->setBreakPending();
 
246
                return false;
 
247
        }
 
248
        return true;
 
249
}
 
250
 
 
251
 
 
252
KviKvsTreeNodeSpecialCommandSwitchLabelDefault::KviKvsTreeNodeSpecialCommandSwitchLabelDefault(const QChar * pLocation)
 
253
: KviKvsTreeNodeSpecialCommandSwitchLabel(pLocation)
 
254
{
 
255
}
 
256
 
 
257
KviKvsTreeNodeSpecialCommandSwitchLabelDefault::~KviKvsTreeNodeSpecialCommandSwitchLabelDefault()
 
258
{
 
259
}
 
260
 
 
261
void KviKvsTreeNodeSpecialCommandSwitchLabelDefault::contextDescription(QString &szBuffer)
 
262
{
 
263
        szBuffer = "Label \"default\" For Special Command \"switch\"";
 
264
}
 
265
 
 
266
void KviKvsTreeNodeSpecialCommandSwitchLabelDefault::dump(const char * prefix)
 
267
{
 
268
        qDebug("%s SpecialCommandSwitchLabelDefault",prefix);
 
269
        QString tmp = prefix;
 
270
        tmp.append("  ");
 
271
        if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
 
272
}
 
273
 
 
274
bool KviKvsTreeNodeSpecialCommandSwitchLabelDefault::execute(KviKvsRunTimeContext * c,KviKvsVariant *, bool * bPassThrough)
 
275
{
 
276
        *bPassThrough = true;
 
277
 
 
278
        if(m_pInstruction)
 
279
        {
 
280
                if(!m_pInstruction->execute(c))return false; // might be a break too
 
281
        }
 
282
        if(m_bHasTerminatingBreak)
 
283
        {
 
284
                c->setBreakPending();
 
285
                return false;
 
286
        }
 
287
        return true;
 
288
}
 
289
 
 
290
 
 
291
KviKvsTreeNodeSpecialCommandSwitch::KviKvsTreeNodeSpecialCommandSwitch(const QChar * pLocation,KviKvsTreeNodeExpression * e)
 
292
: KviKvsTreeNodeSpecialCommand(pLocation,"switch")
 
293
{
 
294
        m_pExpression = e;
 
295
        m_pExpression->setParent(this);
 
296
        m_pLabels = new KviPointerList<KviKvsTreeNodeSpecialCommandSwitchLabel>;
 
297
        m_pLabels->setAutoDelete(true);
 
298
}
 
299
 
 
300
KviKvsTreeNodeSpecialCommandSwitch::~KviKvsTreeNodeSpecialCommandSwitch()
 
301
{
 
302
        delete m_pExpression;
 
303
        delete m_pLabels;
 
304
}
 
305
 
 
306
void KviKvsTreeNodeSpecialCommandSwitch::addLabel(KviKvsTreeNodeSpecialCommandSwitchLabel * l)
 
307
{
 
308
        m_pLabels->append(l);
 
309
        l->setParent(this);
 
310
}
 
311
 
 
312
void KviKvsTreeNodeSpecialCommandSwitch::contextDescription(QString &szBuffer)
 
313
{
 
314
        szBuffer = "Special Command \"switch\"";
 
315
}
 
316
 
 
317
void KviKvsTreeNodeSpecialCommandSwitch::dump(const char * prefix)
 
318
{
 
319
        qDebug("%s SpecialCommandSwitch",prefix);
 
320
        QString tmp = prefix;
 
321
        tmp.append("  ");
 
322
        m_pExpression->dump(tmp.toUtf8().data());
 
323
        for(KviKvsTreeNodeSpecialCommandSwitchLabel * l = m_pLabels->first();l;l = m_pLabels->next())
 
324
                l->dump(tmp.toUtf8().data());
 
325
}
 
326
 
 
327
bool KviKvsTreeNodeSpecialCommandSwitch::execute(KviKvsRunTimeContext * c)
 
328
{
 
329
        KviKvsVariant v;
 
330
        if(!m_pExpression->evaluateReadOnly(c,&v))return false;
 
331
 
 
332
        KviKvsSwitchList swl;
 
333
        if(m_pSwitches)
 
334
        {
 
335
                if(!(m_pSwitches->evaluate(c,&swl)))return false;
 
336
        }
 
337
 
 
338
        bool bUsePassThrough = swl.find('p',"--passthrough");
 
339
        bool bPassThrough = false;
 
340
        for(KviKvsTreeNodeSpecialCommandSwitchLabel * l = m_pLabels->first();l;l = m_pLabels->next())
 
341
        {
 
342
                if(!l->execute(c,&v, &bPassThrough))
 
343
                {
 
344
                        if(c->error())return false;
 
345
                        // break ?
 
346
                        if(c->breakPending())
 
347
                        {
 
348
                                c->handleBreak();
 
349
                                return true;
 
350
                        }
 
351
                        return false;
 
352
                }
 
353
                if(!bUsePassThrough)
 
354
                        bPassThrough = false;
 
355
        }
 
356
        return true;
 
357
}