summaryrefslogtreecommitdiff
path: root/regexp.h
blob: 1062133633e96dacd39c6f6a7acc6c6f0d41ae04 (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
/*
 * regexp.h: Regular expression list
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#ifndef _REGEXP_H_
#define _REGEXP_H_

#include <vdr/tools.h>

#ifdef HAVE_PCREPOSIX
#include <pcre.h>
#endif

typedef enum { REGEXP_TITLE,REGEXP_SHORTTEXT,REGEXP_DESCRIPTION,REGEXP_UNDEFINED } sources;
extern const char *strSources[];

class cRegexp : public cListObject
{
private:
  bool enabled;
  char *error;
  int erroffset;
  char *regexp;
  char *string;
  int source;
  pcre *re;
  pcre_extra *sd;
  int numchannels;
  int *channels;
  void Free();
public:
  cRegexp();
  cRegexp(int Source, const char *Regex, bool Enabled, bool Precompile);
  virtual ~cRegexp();
  void SetFromString(char *string, bool Enabled, bool Precompile);
  const char *GetString() { return string; }
  void Compile();
  void FreeCompiled();
  bool Enabled(void) { return enabled; }
  void ToggleEnabled(void);
  int NumChannels() { return numchannels; }
  int GetChannel(int index);
  int GetSource(void) { return source; }
  pcre *GetRe(void) { return re; }
  pcre_extra *GetSd(void) { return sd; }
};

class cRegexpList : public cList<cRegexp>
{
public:
  void Clear(void)
  {
    cList<cRegexp>::Clear();
  }
  cRegexpList(void) {}
};

class cEpgfixerRegexps
{
private:
  bool LoadRegexps(const char *FileName = NULL, bool AllowComments = true, bool Precompile = true);
  char *fileName;
public:
  cRegexpList *regexps;

  cEpgfixerRegexps();
  ~cEpgfixerRegexps();
  void SetRegexpConfigFile(const char *FileName);
  const char *RegexpConfigFile();
  bool ReloadRegexps(bool AllowComments = true, bool Precompile = true);
};

// Global instance
extern cEpgfixerRegexps EpgfixerRegexps;

#endif //_REGEXP_H_