summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Wieninger <cwieninger@gmx.de>2010-09-26 14:09:57 +0200
committerChristian Wieninger <cwieninger@gmx.de>2010-09-26 14:09:57 +0200
commit9efac7dc163ee573072fe1cdf64fb0dceb655982 (patch)
tree5d662f2a7d764fdabd704e52f11268dc5badf0f5
parent44fe54115300b604865789018b560ec28edfcf3f (diff)
downloadvdr-plugin-epgsearch-9efac7dc163ee573072fe1cdf64fb0dceb655982.tar.gz
vdr-plugin-epgsearch-9efac7dc163ee573072fe1cdf64fb0dceb655982.tar.bz2
new 'lenght' command for script language
-rw-r--r--HISTORY1
-rw-r--r--HISTORY.DE1
-rw-r--r--doc-src/en/epgsearch.4.txt11
-rw-r--r--uservars.c10
-rw-r--r--uservars.h2
-rw-r--r--varparser.c29
-rw-r--r--varparser.h16
7 files changed, 64 insertions, 6 deletions
diff --git a/HISTORY b/HISTORY
index 6d8d994..bd11096 100644
--- a/HISTORY
+++ b/HISTORY
@@ -44,6 +44,7 @@ new:
- new command 'connect' within internal variables: with this command you can connect to
a TCP service, pass data and assign the result to a variable. See the MANUAL for
details.
+- new command 'length' within internal variables: this returns the length of the given arguments
- in memory to pat: french translation update, thanks to Patrice Staudt
- italian translation update, thanks to Diego Pierotto
- finnish translation update, thanks to Rolf Ahrenberg and Ville Skyttä
diff --git a/HISTORY.DE b/HISTORY.DE
index 177ae77..441be05 100644
--- a/HISTORY.DE
+++ b/HISTORY.DE
@@ -44,6 +44,7 @@ neu:
- neues Kommando 'connect' innerhalb interner Variablen: damit kann eine Verbindung zu einem
TCP-Dienst aufgebaut werden, Daten übergeben und das Ergebnis einer Variable zugewiesen
werden. S. MANUAL für Details.
+- neues Kommando 'length' innerhalb interner Variablen: liefert die Länge des Arguments zurück.
- Im Gedenken an pat: Update der französischen Übersetzung, Danke an Patrice Staudt
- Update der italienischen Übersetzung, Danke an Diego Pierotto
- Update der finnischen Übersetzung, Danke an Rolf Ahrenberg und Ville Skyttä
diff --git a/doc-src/en/epgsearch.4.txt b/doc-src/en/epgsearch.4.txt
index 7bdfc82..7db3858 100644
--- a/doc-src/en/epgsearch.4.txt
+++ b/doc-src/en/epgsearch.4.txt
@@ -743,6 +743,17 @@ This will connect to <addr> through the given port and pass the optional given
data. <addr> can be an IP address or the domain name of the TCP service. The result
returned by the service must be terminated with a line feed.
+=head2 Get the length of an argument
+
+When passing any values to the connect or system command it can be helpful to have
+the length of an argument for simple parsing. This can be done with
+
+ %uservar%=length(<any arguments>)
+
+Sample:
+
+%length_title%=length(%title%)
+
=head2 Possible variables
for a list of already builtin variables refer to the section "Customizing the EPG menus"
diff --git a/uservars.c b/uservars.c
index d635c41..08d2a3d 100644
--- a/uservars.c
+++ b/uservars.c
@@ -42,7 +42,7 @@ cUserVar::cUserVar()
string cUserVar::Evaluate(const cEvent* e, bool escapeStrings)
{
- if (oldEvent && oldEvent == e && oldescapeStrings == escapeStrings)
+ if (oldEvent && oldEvent == e && oldescapeStrings == escapeStrings)
return oldResult;
usedVars.clear();
string result;
@@ -50,6 +50,8 @@ string cUserVar::Evaluate(const cEvent* e, bool escapeStrings)
result = EvaluateShellCmd(e);
else if (IsConnectCmd())
result = EvaluateConnectCmd(e);
+ else if (IsLengthCmd())
+ result = EvaluateLengthCmd(e);
else if (IsCondExpr())
result = EvaluateCondExpr(e);
else
@@ -126,6 +128,11 @@ string cUserVar::EvaluateConnectCmd(const cEvent* e)
return buffer;
}
+string cUserVar::EvaluateLengthCmd(const cEvent* e)
+{
+ return NumToString(EvaluateCompExpr(e, false).size());
+}
+
string cUserVar::EvaluateCondExpr(const cEvent* e, bool escapeStrings)
{
string condresult = "";
@@ -239,6 +246,7 @@ string cUserVar::EvaluateInternalTimerVars(const string& Expr, const cTimer* t)
{
string varName = tvar->second->Name();
int varPos = 0;
+
while((varPos = FindIgnoreCase(expr, varName)) >= 0)
{
expr.replace(varPos, varName.size(), tvar->second->Evaluate(t));
diff --git a/uservars.h b/uservars.h
index f9b4237..551a00f 100644
--- a/uservars.h
+++ b/uservars.h
@@ -49,6 +49,7 @@ class cUserVar : public cListObject {
string EvaluateCompExpr(const cEvent* e, bool escapeStrings = false);
string EvaluateShellCmd(const cEvent* e);
string EvaluateConnectCmd(const cEvent* e);
+ string EvaluateLengthCmd(const cEvent* e);
public:
cUserVar();
cVarParser varparser;
@@ -65,6 +66,7 @@ public:
virtual bool IsCondExpr() { return varparser.IsCondExpr(); }
virtual bool IsShellCmd() { return varparser.IsShellCmd(); }
virtual bool IsConnectCmd() { return varparser.IsConnectCmd(); }
+ virtual bool IsLengthCmd() { return varparser.IsLengthCmd(); }
bool DependsOnVar(const string& varName);
bool DependsOnVar(cUserVar* var);
bool AddDepVar(cUserVar* var);
diff --git a/varparser.c b/varparser.c
index d9ac6e8..09caca6 100644
--- a/varparser.c
+++ b/varparser.c
@@ -59,6 +59,10 @@ bool cVarParser::ParseExp(const string& input)
int conPos = input.find("connect");
if (conPos == 0)
return ParseConnectCmd(input);
+ // length command?
+ int lenPos = input.find("length");
+ if (lenPos == 0)
+ return ParseLengthCmd(input);
// conditional expression?
int varPos = Strip(input).find("%");
if (varPos == 0)
@@ -98,6 +102,7 @@ bool cVarParser::ParseShellCmd(const string& input)
cmd = NULL;
return false;
}
+ type = cVarParser::shellcmd;
return true;
}
@@ -124,6 +129,18 @@ bool cVarParser::ParseConnectCmd(const string& input)
LogFile.eSysLog("error parsing command: %s", input.c_str());
return false;
}
+ type = cVarParser::connectcmd;
+ return true;
+}
+
+bool cVarParser::ParseLengthCmd(const string& input)
+{
+ int startLen = input.find("(");
+ int endLen = input.find(")");
+ if (startLen == -1 || endLen == -1) return false;
+ string arg(input.begin() + startLen + 1, input.begin() + endLen);
+ compExpr = arg;
+ type = cVarParser::lengthcmd;
return true;
}
@@ -165,6 +182,7 @@ bool cVarParser::ParseCondExp(const string& input)
{
condvarTrue = Strip(truePart);
condvarFalse = Strip(falsePart);
+ type = cVarParser::condition;
return true;
}
}
@@ -202,15 +220,20 @@ bool cVarParser::ParseVar(const string& input)
bool cVarParser::IsCondExpr()
{
- return (condEqLeft != "");
+ return type == cVarParser::condition;
}
bool cVarParser::IsShellCmd()
{
- return (cmd != NULL);
+ return type == cVarParser::shellcmd;
}
bool cVarParser::IsConnectCmd()
{
- return (connectAddr != "" && connectPort != -1);
+ return type == cVarParser::connectcmd;
+}
+
+bool cVarParser::IsLengthCmd()
+{
+ return type == cVarParser::lengthcmd;
}
diff --git a/varparser.h b/varparser.h
index 3a018bc..0a9fc11 100644
--- a/varparser.h
+++ b/varparser.h
@@ -40,6 +40,15 @@ typedef enum
class cVarParser
{
+ typedef enum
+ {
+ composed=0,
+ condition,
+ shellcmd,
+ connectcmd,
+ lengthcmd
+ } exprType;
+
public:
string varName;
string condEqLeft;
@@ -53,18 +62,21 @@ class cVarParser
string cmdArgs;
string connectAddr;
- int connectPort;
+ int connectPort;
+ exprType type;
- cVarParser() : cmd(NULL), connectPort(-1) {}
+ cVarParser() : cmd(NULL), connectPort(-1), type(composed) {}
bool Parse(const string& input);
bool ParseExp(const string& input);
bool IsCondExpr();
bool IsShellCmd();
bool IsConnectCmd();
+ bool IsLengthCmd();
private:
bool ParseAssign(const string& input);
bool ParseShellCmd(const string& input);
bool ParseConnectCmd(const string& input);
+ bool ParseLengthCmd(const string& input);
bool ParseCondExp(const string& input);
bool ParseEquality(const string& input);
bool ParseVar(const string& input);