summaryrefslogtreecommitdiff
path: root/sources.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2010-02-28 12:19:50 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2010-02-28 12:19:50 +0100
commit1eb033576f1829b4466ac27825af91e662e7b17f (patch)
treee02d623302de293070fe381db71f712207372606 /sources.c
parentd255ad785d7a9f258097e6bba55c950d516b6a67 (diff)
downloadvdr-1eb033576f1829b4466ac27825af91e662e7b17f.tar.gz
vdr-1eb033576f1829b4466ac27825af91e662e7b17f.tar.bz2
Added plugin-defined sources
Diffstat (limited to 'sources.c')
-rw-r--r--sources.c93
1 files changed, 45 insertions, 48 deletions
diff --git a/sources.c b/sources.c
index 65002a5a..66d441d7 100644
--- a/sources.c
+++ b/sources.c
@@ -4,11 +4,10 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: sources.c 1.4 2008/02/10 14:07:26 kls Exp $
+ * $Id: sources.c 2.1 2010/02/28 12:00:31 kls Exp $
*/
#include "sources.h"
-#include <ctype.h>
// --- cSource ---------------------------------------------------------------
@@ -18,6 +17,12 @@ cSource::cSource(void)
description = NULL;
}
+cSource::cSource(char Source, const char *Description)
+{
+ code = int(Source) << 24;
+ description = strdup(Description);
+}
+
cSource::~cSource()
{
free(description);
@@ -36,58 +41,50 @@ cString cSource::ToString(int Code)
{
char buffer[16];
char *q = buffer;
- switch (Code & st_Mask) {
- case stCable: *q++ = 'C'; break;
- case stSat: *q++ = 'S';
- {
- int pos = Code & ~st_Mask;
- q += snprintf(q, sizeof(buffer) - 2, "%u.%u", (pos & ~st_Neg) / 10, (pos & ~st_Neg) % 10); // can't simply use "%g" here since the silly 'locale' messes up the decimal point
- *q++ = (Code & st_Neg) ? 'E' : 'W';
- }
- break;
- case stTerr: *q++ = 'T'; break;
- default: *q++ = Code + '0'; // backward compatibility
- }
+ *q++ = (Code & st_Mask) >> 24;
+ int n = (Code & st_Pos);
+ if (n > 0x00007FFF)
+ n |= 0xFFFF0000;
+ if (n) {
+ q += snprintf(q, sizeof(buffer) - 2, "%u.%u", abs(n) / 10, abs(n) % 10); // can't simply use "%g" here since the silly 'locale' messes up the decimal point
+ *q++ = (n < 0) ? 'E' : 'W';
+ }
*q = 0;
return buffer;
}
int cSource::FromString(const char *s)
{
- int type = stNone;
- switch (toupper(*s)) {
- case 'C': type = stCable; break;
- case 'S': type = stSat; break;
- case 'T': type = stTerr; break;
- case '0' ... '9': type = *s - '0'; break; // backward compatibility
- default: esyslog("ERROR: unknown source key '%c'", *s);
- return stNone;
- }
- int code = type;
- if (type == stSat) {
- int pos = 0;
- bool dot = false;
- bool neg = false;
- while (*++s) {
- switch (toupper(*s)) {
- case '0' ... '9': pos *= 10;
- pos += *s - '0';
- break;
- case '.': dot = true;
- break;
- case 'E': neg = true; // fall through to 'W'
- case 'W': if (!dot)
- pos *= 10;
- break;
- default: esyslog("ERROR: unknown source character '%c'", *s);
- return stNone;
- }
- }
- if (neg)
- pos |= st_Neg;
- code |= pos;
+ if ('A' <= *s && *s <= 'Z') {
+ int code = int(*s) << 24;
+ if (code == stSat) {
+ int pos = 0;
+ bool dot = false;
+ bool neg = false;
+ while (*++s) {
+ switch (*s) {
+ case '0' ... '9': pos *= 10;
+ pos += *s - '0';
+ break;
+ case '.': dot = true;
+ break;
+ case 'E': neg = true; // fall through to 'W'
+ case 'W': if (!dot)
+ pos *= 10;
+ break;
+ default: esyslog("ERROR: unknown source character '%c'", *s);
+ return stNone;
+ }
+ }
+ if (neg)
+ pos = -pos;
+ code |= (pos & st_Pos);
+ }
+ return code;
}
- return code;
+ else
+ esyslog("ERROR: unknown source key '%c'", *s);
+ return stNone;
}
int cSource::FromData(eSourceType SourceType, int Position, bool East)
@@ -95,7 +92,7 @@ int cSource::FromData(eSourceType SourceType, int Position, bool East)
int code = SourceType;
if (SourceType == stSat) {
if (East)
- code |= st_Neg;
+ Position = -Position;
code |= (Position & st_Pos);;
}
return code;