aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-08-30 15:37:17 +0000
committerGravatar Fabio Bas2010-08-30 15:37:17 +0000
commitffb682ee6b67ab147aaa350e1b4fe5934b5834f7 (patch)
tree6fe65573c3efef3d989b227262fd839605be7340 /src
parentfix for a bug in $date(z) found by OmegaPhil (diff)
downloadKVIrc-ffb682ee6b67ab147aaa350e1b4fe5934b5834f7.tar.gz
KVIrc-ffb682ee6b67ab147aaa350e1b4fe5934b5834f7.tar.bz2
KVIrc-ffb682ee6b67ab147aaa350e1b4fe5934b5834f7.zip
implemented -p switch for the "switch" command
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4951 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
-rw-r--r--src/kvirc/kvs/kvi_kvs_parser_specialcommands.cpp22
-rw-r--r--src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.cpp123
-rw-r--r--src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.h10
3 files changed, 101 insertions, 54 deletions
diff --git a/src/kvirc/kvs/kvi_kvs_parser_specialcommands.cpp b/src/kvirc/kvs/kvi_kvs_parser_specialcommands.cpp
index 3fc26a36d..bfc44610d 100644
--- a/src/kvirc/kvs/kvi_kvs_parser_specialcommands.cpp
+++ b/src/kvirc/kvs/kvi_kvs_parser_specialcommands.cpp
@@ -1286,7 +1286,7 @@ KviKvsTreeNodeCommand * KviKvsParser::parseSpecialCommandSwitch()
@title:
switch
@syntax:
- switch(<expression>)
+ switch [-p] (<expression>)
{
case(<value>)[:]<command>
[break]
@@ -1305,6 +1305,9 @@ KviKvsTreeNodeCommand * KviKvsParser::parseSpecialCommandSwitch()
default[:]<command>
[break]
}
+ @switches:
+ !sw: -p | --passthrough
+ Use c-style 'break' flow control
@short:
Another flow control command
@description:
@@ -1322,6 +1325,8 @@ KviKvsTreeNodeCommand * KviKvsParser::parseSpecialCommandSwitch()
If <command> contains a [cmd]break[/cmd] statement inside or if [cmd]break[/cmd]
is specified just after the <command> then the execution of the switch is terminated
otherwise the nex label is evaluated.[br]
+ If the -p (--passthrough) option is enabled, than the switch command will execute all the istructions blocks
+ until a [cmd]break[/cmd] statement is found.
[b]match(<value>)[:]<command>[/b][br]
The <value> is expected to be a wildcard expression (containing '*' and '?' wildcards)
that is matched against <expression>.[br]
@@ -1367,6 +1372,21 @@ KviKvsTreeNodeCommand * KviKvsParser::parseSpecialCommandSwitch()
break;
}
[/example]
+ [comment]# An example of the -p switch[/comment]
+ [example]
+ %tmp = 1
+ switch -p (%tmp)
+ {
+ case(1):
+ echo \%tmp was 1!
+ case(2)
+ echo \%tmp was 1 or 2!
+ break;
+ default:
+ echo \%tmp was not 1 or 2 (%tmp)
+ break;
+ }
+ [/example]
[comment]# An example with strings[/comment]
[example]
%tmp = "This is a test"
diff --git a/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.cpp b/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.cpp
index f1ab71bd0..e17e424e1 100644
--- a/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.cpp
+++ b/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.cpp
@@ -82,43 +82,48 @@ void KviKvsTreeNodeSpecialCommandSwitchLabelCase::dump(const char * prefix)
if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
}
-bool KviKvsTreeNodeSpecialCommandSwitchLabelCase::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter)
+bool KviKvsTreeNodeSpecialCommandSwitchLabelCase::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
{
- KviKvsVariant v;
- if(!m_pParameter->evaluateReadOnly(c,&v))return false;
-
- KviKvsNumber num;
- if(pRealParameter->asNumber(num))
+ if(!(*bPassThrough))
{
- KviKvsNumber num2;
- if(!v.asNumber(num2))return true; // a number an a non number can't match
- if(num.isInteger())
+ KviKvsVariant v;
+ if(!m_pParameter->evaluateReadOnly(c,&v))return false;
+
+ KviKvsNumber num;
+ if(pRealParameter->asNumber(num))
{
- if(num2.isInteger())
+ KviKvsNumber num2;
+ if(!v.asNumber(num2))return true; // a number and a non number can't match
+ if(num.isInteger())
{
- if(num.integer() != num2.integer())return true;
+ if(num2.isInteger())
+ {
+ if(num.integer() != num2.integer())return true;
+ } else {
+ if(((double)(num.integer())) != num2.real())return true;
+ }
} else {
- if(((double)(num.integer())) != num2.real())return true;
+ if(num2.isInteger())
+ {
+ if(num.real() != ((double)(num2.integer())))return true;
+ } else {
+ if(num.real() != num2.real())return true;
+ }
}
} else {
- if(num2.isInteger())
- {
- if(num.real() != ((double)(num2.integer())))return true;
- } else {
- if(num.real() != num2.real())return true;
- }
- }
- } else {
- // string comparision, case insensitive
- QString reg;
- v.asString(reg);
+ // string comparision, case insensitive
+ QString reg;
+ v.asString(reg);
- QString val;
- pRealParameter->asString(val);
+ QString val;
+ pRealParameter->asString(val);
- if(reg.toLower() != val.toLower())return true;
+ if(reg.toLower() != val.toLower())return true;
+ }
}
+ *bPassThrough = true;
+
if(m_pInstruction)
{
if(!m_pInstruction->execute(c))return false; // might be a break too
@@ -155,20 +160,25 @@ void KviKvsTreeNodeSpecialCommandSwitchLabelMatch::dump(const char * prefix)
if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
}
-bool KviKvsTreeNodeSpecialCommandSwitchLabelMatch::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter)
+bool KviKvsTreeNodeSpecialCommandSwitchLabelMatch::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
{
- KviKvsVariant v;
- if(!m_pParameter->evaluateReadOnly(c,&v))return false;
+ if(!(*bPassThrough))
+ {
+ KviKvsVariant v;
+ if(!m_pParameter->evaluateReadOnly(c,&v))return false;
- QString reg;
- v.asString(reg);
+ QString reg;
+ v.asString(reg);
- //QRegExp rx(reg,false,true);
- QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::Wildcard);
- QString val;
- pRealParameter->asString(val);
+ //QRegExp rx(reg,false,true);
+ QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::Wildcard);
+ QString val;
+ pRealParameter->asString(val);
+
+ if(!rx.exactMatch(val))return true; // no match
+ }
- if(!rx.exactMatch(val))return true; // no match
+ *bPassThrough = true;
if(m_pInstruction)
{
@@ -206,20 +216,25 @@ void KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::dump(const char * prefix)
if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
}
-bool KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter)
+bool KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
{
- KviKvsVariant v;
- if(!m_pParameter->evaluateReadOnly(c,&v))return false;
+ if(!(*bPassThrough))
+ {
+ KviKvsVariant v;
+ if(!m_pParameter->evaluateReadOnly(c,&v))return false;
+
+ QString reg;
+ v.asString(reg);
- QString reg;
- v.asString(reg);
+ // QRegExp rx(reg,false,false);
+ QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::RegExp);
+ QString val;
+ pRealParameter->asString(val);
-// QRegExp rx(reg,false,false);
- QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::RegExp);
- QString val;
- pRealParameter->asString(val);
+ if(!rx.exactMatch(val))return true; // no match
+ }
- if(!rx.exactMatch(val))return true; // no match
+ *bPassThrough = true;
if(m_pInstruction)
{
@@ -256,8 +271,10 @@ void KviKvsTreeNodeSpecialCommandSwitchLabelDefault::dump(const char * prefix)
if(m_pInstruction)m_pInstruction->dump(tmp.toUtf8().data());
}
-bool KviKvsTreeNodeSpecialCommandSwitchLabelDefault::execute(KviKvsRunTimeContext * c,KviKvsVariant *)
+bool KviKvsTreeNodeSpecialCommandSwitchLabelDefault::execute(KviKvsRunTimeContext * c,KviKvsVariant *, bool * bPassThrough)
{
+ *bPassThrough = true;
+
if(m_pInstruction)
{
if(!m_pInstruction->execute(c))return false; // might be a break too
@@ -312,9 +329,17 @@ bool KviKvsTreeNodeSpecialCommandSwitch::execute(KviKvsRunTimeContext * c)
KviKvsVariant v;
if(!m_pExpression->evaluateReadOnly(c,&v))return false;
+ KviKvsSwitchList swl;
+ if(m_pSwitches)
+ {
+ if(!(m_pSwitches->evaluate(c,&swl)))return false;
+ }
+
+ bool bUsePassThrough = swl.find('p',"--passthrough");
+ bool bPassThrough = false;
for(KviKvsTreeNodeSpecialCommandSwitchLabel * l = m_pLabels->first();l;l = m_pLabels->next())
{
- if(!l->execute(c,&v))
+ if(!l->execute(c,&v, &bPassThrough))
{
if(c->error())return false;
// break ?
@@ -325,6 +350,8 @@ bool KviKvsTreeNodeSpecialCommandSwitch::execute(KviKvsRunTimeContext * c)
}
return false;
}
+ if(!bUsePassThrough)
+ bPassThrough = false;
}
return true;
}
diff --git a/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.h b/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.h
index 038aaa34e..70700076f 100644
--- a/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.h
+++ b/src/kvirc/kvs/kvi_kvs_treenode_specialcommandswitch.h
@@ -47,7 +47,7 @@ public:
void setParameter(KviKvsTreeNodeData * pParameter);
void setInstruction(KviKvsTreeNodeInstruction * pInstruction);
void setTerminatingBreak(bool b){ m_bHasTerminatingBreak = b; };
- virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter) = 0;
+ virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough) = 0;
};
@@ -59,7 +59,7 @@ public:
public:
virtual void contextDescription(QString &szBuffer);
virtual void dump(const char * prefix);
- virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter);
+ virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough);
};
@@ -71,7 +71,7 @@ public:
public:
virtual void contextDescription(QString &szBuffer);
virtual void dump(const char * prefix);
- virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter);
+ virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough);
};
class KVIRC_API KviKvsTreeNodeSpecialCommandSwitchLabelRegexp : public KviKvsTreeNodeSpecialCommandSwitchLabel
@@ -82,7 +82,7 @@ public:
public:
virtual void contextDescription(QString &szBuffer);
virtual void dump(const char * prefix);
- virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter);
+ virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough);
};
class KVIRC_API KviKvsTreeNodeSpecialCommandSwitchLabelDefault : public KviKvsTreeNodeSpecialCommandSwitchLabel
@@ -93,7 +93,7 @@ public:
public:
virtual void dump(const char * prefix);
virtual void contextDescription(QString &szBuffer);
- virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter);
+ virtual bool execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough);
};