vdr
2.0.2
Main Page
Namespaces
Classes
Files
File List
File Members
sources.c
Go to the documentation of this file.
1
/*
2
* sources.c: Source handling
3
*
4
* See the main source file 'vdr.c' for copyright information and
5
* how to reach the author.
6
*
7
* $Id: sources.c 2.2 2010/02/28 15:15:39 kls Exp $
8
*/
9
10
#include "
sources.h
"
11
12
// --- cSource ---------------------------------------------------------------
13
14
cSource::cSource
(
void
)
15
{
16
code
=
stNone
;
17
description
= NULL;
18
}
19
20
cSource::cSource
(
char
Source,
const
char
*Description)
21
{
22
code
= int(Source) << 24;
23
description
= strdup(Description);
24
}
25
26
cSource::~cSource
()
27
{
28
free(
description
);
29
}
30
31
bool
cSource::Parse
(
const
char
*s)
32
{
33
char
*codeBuf = NULL;
34
if
(2 == sscanf(s,
"%a[^ ] %a[^\n]"
, &codeBuf, &
description
))
35
code
=
FromString
(codeBuf);
36
free(codeBuf);
37
return
code
!=
stNone
&&
description
&& *
description
;
38
}
39
40
cString
cSource::ToString
(
int
Code)
41
{
42
char
buffer[16];
43
char
*q = buffer;
44
*q++ = (Code &
st_Mask
) >> 24;
45
int
n = (Code &
st_Pos
);
46
if
(n > 0x00007FFF)
47
n |= 0xFFFF0000;
48
if
(n) {
49
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
50
*q++ = (n < 0) ?
'E'
:
'W'
;
51
}
52
*q = 0;
53
return
buffer;
54
}
55
56
int
cSource::FromString
(
const
char
*s)
57
{
58
if
(!
isempty
(s)) {
59
if
(
'A'
<= *s && *s <=
'Z'
) {
60
int
code
= int(*s) << 24;
61
if
(code ==
stSat
) {
62
int
pos = 0;
63
bool
dot =
false
;
64
bool
neg =
false
;
65
while
(*++s) {
66
switch
(*s) {
67
case
'0'
...
'9'
: pos *= 10;
68
pos += *s -
'0'
;
69
break
;
70
case
'.'
: dot =
true
;
71
break
;
72
case
'E'
: neg =
true
;
// fall through to 'W'
73
case
'W'
:
if
(!dot)
74
pos *= 10;
75
break
;
76
default
:
esyslog
(
"ERROR: unknown source character '%c'"
, *s);
77
return
stNone
;
78
}
79
}
80
if
(neg)
81
pos = -pos;
82
code |= (pos &
st_Pos
);
83
}
84
return
code
;
85
}
86
else
87
esyslog
(
"ERROR: unknown source key '%c'"
, *s);
88
}
89
return
stNone
;
90
}
91
92
int
cSource::FromData
(
eSourceType
SourceType,
int
Position,
bool
East)
93
{
94
int
code
= SourceType;
95
if
(SourceType ==
stSat
) {
96
if
(East)
97
Position = -Position;
98
code |= (Position &
st_Pos
);;
99
}
100
return
code
;
101
}
102
103
// --- cSources --------------------------------------------------------------
104
105
cSources
Sources
;
106
107
cSource
*
cSources::Get
(
int
Code)
108
{
109
for
(
cSource
*p =
First
(); p; p =
Next
(p)) {
110
if
(p->Code() == Code)
111
return
p;
112
}
113
return
NULL;
114
}
115
Generated by
1.8.3.1