2002-10-06 10:25:42 +02:00
|
|
|
/*
|
|
|
|
* sources.c: Source handling
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2013-12-28 11:37:42 +01:00
|
|
|
* $Id: sources.c 3.5 2013/12/28 11:33:08 kls Exp $
|
2002-10-06 10:25:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sources.h"
|
|
|
|
|
2008-02-10 14:11:47 +01:00
|
|
|
// --- cSource ---------------------------------------------------------------
|
2002-10-06 10:25:42 +02:00
|
|
|
|
|
|
|
cSource::cSource(void)
|
|
|
|
{
|
|
|
|
code = stNone;
|
|
|
|
description = NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-28 12:19:50 +01:00
|
|
|
cSource::cSource(char Source, const char *Description)
|
|
|
|
{
|
|
|
|
code = int(Source) << 24;
|
|
|
|
description = strdup(Description);
|
|
|
|
}
|
|
|
|
|
2002-10-06 10:25:42 +02:00
|
|
|
cSource::~cSource()
|
|
|
|
{
|
|
|
|
free(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSource::Parse(const char *s)
|
|
|
|
{
|
|
|
|
char *codeBuf = NULL;
|
2013-12-28 11:37:42 +01:00
|
|
|
if (2 == sscanf(s, "%m[^ ] %m[^\n]", &codeBuf, &description))
|
2002-10-06 10:25:42 +02:00
|
|
|
code = FromString(codeBuf);
|
|
|
|
free(codeBuf);
|
|
|
|
return code != stNone && description && *description;
|
|
|
|
}
|
|
|
|
|
2013-08-21 11:02:52 +02:00
|
|
|
bool cSource::Matches(int Code1, int Code2)
|
|
|
|
{
|
|
|
|
if (Code1 == (stSat | st_Any))
|
|
|
|
return IsSat(Code2);
|
|
|
|
return Code1 == Code2;
|
|
|
|
}
|
|
|
|
|
2013-04-11 10:40:47 +02:00
|
|
|
int cSource::Position(int Code)
|
|
|
|
{
|
|
|
|
int n = (Code & st_Pos);
|
|
|
|
if (n > 0x00007FFF)
|
|
|
|
n |= 0xFFFF0000;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2004-12-26 12:45:22 +01:00
|
|
|
cString cSource::ToString(int Code)
|
2002-10-06 10:25:42 +02:00
|
|
|
{
|
2004-12-26 12:45:22 +01:00
|
|
|
char buffer[16];
|
2002-10-06 10:25:42 +02:00
|
|
|
char *q = buffer;
|
2010-02-28 12:19:50 +01:00
|
|
|
*q++ = (Code & st_Mask) >> 24;
|
2013-04-11 10:40:47 +02:00
|
|
|
if (int n = Position(Code)) {
|
2010-02-28 12:19:50 +01:00
|
|
|
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
|
2013-04-11 10:40:47 +02:00
|
|
|
*q++ = (n < 0) ? 'W' : 'E';
|
2010-02-28 12:19:50 +01:00
|
|
|
}
|
2002-10-06 10:25:42 +02:00
|
|
|
*q = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cSource::FromString(const char *s)
|
|
|
|
{
|
2010-02-28 15:18:31 +01:00
|
|
|
if (!isempty(s)) {
|
|
|
|
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;
|
2013-04-11 10:40:47 +02:00
|
|
|
case 'W': neg = true; // fall through to 'E'
|
|
|
|
case 'E': if (!dot)
|
2010-02-28 15:18:31 +01:00
|
|
|
pos *= 10;
|
|
|
|
break;
|
|
|
|
default: esyslog("ERROR: unknown source character '%c'", *s);
|
|
|
|
return stNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (neg)
|
|
|
|
pos = -pos;
|
|
|
|
code |= (pos & st_Pos);
|
|
|
|
}
|
|
|
|
return code;
|
2010-02-28 12:19:50 +01:00
|
|
|
}
|
2010-02-28 15:18:31 +01:00
|
|
|
else
|
2013-05-23 09:41:54 +02:00
|
|
|
esyslog("ERROR: unknown source key '%c'", *s);
|
2002-10-06 10:25:42 +02:00
|
|
|
}
|
2010-02-28 12:19:50 +01:00
|
|
|
return stNone;
|
2002-10-06 10:25:42 +02:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:54:37 +01:00
|
|
|
int cSource::FromData(eSourceType SourceType, int Position, bool East)
|
|
|
|
{
|
|
|
|
int code = SourceType;
|
|
|
|
if (SourceType == stSat) {
|
2013-04-11 10:40:47 +02:00
|
|
|
if (!East)
|
2010-02-28 12:19:50 +01:00
|
|
|
Position = -Position;
|
2013-04-09 11:10:30 +02:00
|
|
|
code |= (Position & st_Pos);
|
2004-01-11 15:54:37 +01:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2008-02-10 14:11:47 +01:00
|
|
|
// --- cSources --------------------------------------------------------------
|
2002-10-06 10:25:42 +02:00
|
|
|
|
|
|
|
cSources Sources;
|
|
|
|
|
|
|
|
cSource *cSources::Get(int Code)
|
|
|
|
{
|
|
|
|
for (cSource *p = First(); p; p = Next(p)) {
|
|
|
|
if (p->Code() == Code)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|