summaryrefslogtreecommitdiff
path: root/ledsconf.c
diff options
context:
space:
mode:
authorhorchi <vdr@jwendel.de>2012-11-28 09:17:32 +0100
committerhorchi <vdr@jwendel.de>2012-11-28 09:17:32 +0100
commit0197b5c98cdeec3740644655963e1f100d73998e (patch)
tree029168cfc6a31cb3bb6309f2b8ae577302307d8d /ledsconf.c
downloadvdr-plugin-seduatmo-0197b5c98cdeec3740644655963e1f100d73998e.tar.gz
vdr-plugin-seduatmo-0197b5c98cdeec3740644655963e1f100d73998e.tar.bz2
initial Release of vdr-plugin-seduatmo
Diffstat (limited to 'ledsconf.c')
-rw-r--r--ledsconf.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/ledsconf.c b/ledsconf.c
new file mode 100644
index 0000000..5cbd98a
--- /dev/null
+++ b/ledsconf.c
@@ -0,0 +1,127 @@
+/*
+ * ledsconf.c: A plugin for the Video Disk Recorder
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id: ledsconf.c,v 1.18 2012/11/20 19:04:09 wendel Exp $
+ */
+
+#include <ctype.h>
+
+#include "common.h"
+#include "config.h"
+#include "ledsconf.h"
+
+//***************************************************************************
+// cLedConf
+//***************************************************************************
+//***************************************************************************
+// Object
+//***************************************************************************
+
+cLedConf::cLedConf()
+{
+ x = na;
+ toX = na;
+ y = na;
+ toY = na;
+ lp = na;
+}
+
+//***************************************************************************
+// Parse like like "led 0-1 14-17"
+//***************************************************************************
+
+bool cLedConf::Parse(const char* s)
+{
+ const char* p = s;
+
+ p = skipWs(p);
+
+ // check keyword
+
+ if (strncasecmp(p, "led ", 4) != 0)
+ return false;
+
+ p += 4;
+ skipWs(p);
+
+ // LED Position
+
+ if (strncasecmp(p, "top ", 4) == 0)
+ lp = lpTop;
+ else if (strncasecmp(p, "left ", 5) == 0)
+ lp = lpLeft;
+ else if (strncasecmp(p, "bot ", 4) == 0)
+ lp = lpBottom;
+ else if (strncasecmp(p, "bottom ", 7) == 0)
+ lp = lpBottom;
+ else if (strncasecmp(p, "right ", 6) == 0)
+ lp = lpRight;
+ else
+ return error("Missing location {top,left,bot(tom),right}");
+
+ // skip to delemiter
+
+ while (*p && *p != ' ' && *p != '\t')
+ p++;
+
+ // check
+
+ if (!*p)
+ return false;
+
+ skipWs(p);
+
+ // parse X
+
+ if (!parseRange(p, x, toX))
+ return false;
+
+ // parse Y
+
+ if (!parseRange(p, y, toY))
+ return false;
+
+ return true;
+}
+
+//***************************************************************************
+// Parse Range like "12-26"
+//***************************************************************************
+
+bool cLedConf::parseRange(const char*& p, int& from, int& to)
+{
+ p = skipWs(p);
+
+ if (!isdigit(*p))
+ return false;
+
+ from = to = strtol(p, (char**)&p, 0);
+
+ p = skipWs(p);
+
+ if (*p != '-')
+ return true;
+
+ p++;
+
+ if (!isdigit(*p))
+ return false;
+
+ to = strtol(p, (char**)&p, 0);
+
+ return true;
+}
+
+//***************************************************************************
+// Skip Whitespaces
+//***************************************************************************
+
+const char* cLedConf::skipWs(const char* p)
+{
+ while (*p && (*p == ' ' || *p == '\t'))
+ p++;
+
+ return p;
+}