summaryrefslogtreecommitdiff
path: root/brdclocks.c
blob: 402ea0388fc507eddc09bc7b66fca5f50fe7cf78 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * pin.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * Date: 25.01.06 - 02.02.07, horchi
 */

//***************************************************************************
// Includes
//***************************************************************************

#include "locks.h"
#include "def.h"

//***************************************************************************
// Object
//***************************************************************************

cLockedBroadcast::cLockedBroadcast()
   : cLockItem(yes)
{
   hasRange = no;
}

cLockedBroadcast::cLockedBroadcast(const char* aName)
   : cLockItem(aName, yes)
{
   hasRange = no;
}

cLockedBroadcast::~cLockedBroadcast()
{
   // nothicng yet ...
}

//***************************************************************************
// Parse
//***************************************************************************

bool cLockedBroadcast::Parse(char* line)
{
   int fields;

   char* aName = 0;
   char* aPattern = 0;
   char* aSearchMode = 0;
   char* aActive = 0;

   fields = sscanf(line, "%m[^:]:%m[^:]:%m[^:]:%m[^\n]",
                   &aName, &aPattern, &aSearchMode, &aActive);

   if (fields == 4)
   {
      if (name) free(name);
      name = aName;

      if (pattern) free(pattern);
      pattern = aPattern;

      for (int i = 0; i < smCount; i++)
      {
         if (aSearchMode && strcmp(searchModes[i], aSearchMode) == 0)
         {
            searchMode = i;
            break;
         }
      }

      if (aActive)
         active = strcmp(aActive, "yes") == 0;
   }

   if (aSearchMode) free(aSearchMode);
   if (aActive) free(aActive);

   return fields == 4;
}

//***************************************************************************
// Save
//***************************************************************************

bool cLockedBroadcast::Save(FILE* file)
{
   // Format: "<name>:<pattern>:<searchMode>:<active>"

   return fprintf(file, "%s:%s:%s:%s\n",
                  name,
                  pattern,
                  searchModes[searchMode],
                  active ? "yes" : "no") > 0;
}

//***************************************************************************
// Locked
//***************************************************************************

int cLockedBroadcast::Locked(long /*startTime*/)
{
   return active;
}

//***************************************************************************
// Class cLockedBroadcasts
//***************************************************************************
//***************************************************************************
// Locked
//***************************************************************************

int cLockedBroadcasts::Locked(const char* aName, long /*startTime*/)
{
   cLockedBroadcast* broadcast;

   if (!aName)
      return no;

   for (broadcast = First(); broadcast; broadcast = Next(broadcast))
   {
      if (broadcast->MatchPattern(aName))
         if (broadcast->Locked())
            return yes;
   }

   return no;
}