blob: dfcee305eb13c70e1726345cdf99d98ab3fa2e8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* tools.h: Tools for handling configure files and strings
*
* See the README file for copyright information and how to reach the author.
*
*/
#ifndef __EPGFIXER_TOOLS_H_
#define __EPGFIXER_TOOLS_H_
#include <vdr/epg.h>
#include <vdr/tools.h>
#include <unistd.h>
#include <stdio.h>
#define error(x...) esyslog("EPGFixer: " x);
#define FREE(x) { free(x); x = NULL; }
char *striphtml(char *str);
class cListItem : public cListObject
{
protected:
bool enabled;
char *string;
int *channels_num;
char **channels_str;
int numchannels;
void Free();
const char *GetChannelID(int index);
int GetChannelNum(int index);
int LoadChannelsFromString(const char *string);
bool IsActive(tChannelID ChannelID);
public:
cListItem();
virtual ~cListItem();
virtual bool Apply(cEvent *Event) { return 0; }
void SetFromString(char *string, bool Enabled);
const char *GetString() { return string; }
bool Enabled(void) { return enabled; }
void ToggleEnabled(void);
virtual void PrintConfigLineToFIle(FILE *f) {}
};
template<class T> class cEpgfixerList : public cList<T>
{
protected:
char *fileName;
bool LoadConfigFile(const char *FileName = NULL, bool AllowComments = true)
{
bool result = false;
if (FileName && access(FileName, F_OK) == 0) {
FILE *f = fopen(FileName, "r");
if (f) {
char *s;
cReadLine ReadLine;
while ((s = ReadLine.Read(f)) != NULL) {
if (!isempty(s)) {
Add(new T());
cList<T>::Last()->SetFromString(s, true);
}
}
fclose(f);
}
else {
LOG_ERROR_STR(FileName);
result = false;
}
}
return result;
}
public:
cEpgfixerList() { fileName = NULL; }
~cEpgfixerList() { free(fileName); }
void Clear(void) { cList<T>::Clear(); }
bool ReloadConfigFile(bool AllowComments = true)
{
Clear();
return LoadConfigFile(fileName, AllowComments);
}
bool Apply(cEvent *Event)
{
int res = false;
T *item = (T *)(cList<T>::First());
while (item) {
if (item->Enabled()) {
int ret = item->Apply(Event);
if (ret && !res)
res = true;
}
item = (T *)(item->Next());
}
return res;
}
void SetConfigFile(const char *FileName) { fileName = strdup(FileName); }
const char *GetConfigFile() { return fileName; }
};
#endif //__EPGFIXER_TOOLS_H_
|