summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c69
1 files changed, 57 insertions, 12 deletions
diff --git a/config.c b/config.c
index 8b5c454f..53b70262 100644
--- a/config.c
+++ b/config.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: config.c 1.83 2002/02/10 11:39:00 kls Exp $
+ * $Id: config.c 1.84 2002/02/17 11:37:05 kls Exp $
*/
#include "config.h"
@@ -338,6 +338,7 @@ cTimer::cTimer(bool Instant)
priority = Setup.DefaultPriority;
lifetime = Setup.DefaultLifetime;
*file = 0;
+ firstday = 0;
summary = NULL;
if (Instant && ch)
snprintf(file, sizeof(file), "%s%s", Setup.MarkInstantRecord ? "@" : "", *Setup.NameInstantRecord ? Setup.NameInstantRecord : ch->name);
@@ -367,6 +368,7 @@ cTimer::cTimer(const cEventInfo *EventInfo)
const char *Title = EventInfo->GetTitle();
if (!isempty(Title))
strn0cpy(file, EventInfo->GetTitle(), sizeof(file));
+ firstday = 0;
summary = NULL;
}
@@ -395,7 +397,7 @@ const char *cTimer::ToText(cTimer *Timer)
delete buffer;
strreplace(Timer->file, ':', '|');
strreplace(Timer->summary, '\n', '|');
- asprintf(&buffer, "%d:%d:%s:%04d:%04d:%d:%d:%s:%s\n", Timer->active, Timer->channel, PrintDay(Timer->day), Timer->start, Timer->stop, Timer->priority, Timer->lifetime, Timer->file, Timer->summary ? Timer->summary : "");
+ asprintf(&buffer, "%d:%d:%s:%04d:%04d:%d:%d:%s:%s\n", Timer->active, Timer->channel, PrintDay(Timer->day, Timer->firstday), Timer->start, Timer->stop, Timer->priority, Timer->lifetime, Timer->file, Timer->summary ? Timer->summary : "");
strreplace(Timer->summary, '|', '\n');
strreplace(Timer->file, '|', ':');
return buffer;
@@ -411,20 +413,38 @@ int cTimer::TimeToInt(int t)
return (t / 100 * 60 + t % 100) * 60;
}
-int cTimer::ParseDay(const char *s)
+int cTimer::ParseDay(const char *s, time_t *FirstDay)
{
char *tail;
int d = strtol(s, &tail, 10);
+ if (FirstDay)
+ *FirstDay = 0;
if (tail && *tail) {
d = 0;
if (tail == s) {
- if (strlen(s) == 7) {
+ const char *first = strchr(s, '@');
+ int l = first ? first - s : strlen(s);
+ if (l == 7) {
for (const char *p = s + 6; p >= s; p--) {
- d <<= 1;
- d |= (*p != '-');
- }
+ d <<= 1;
+ d |= (*p != '-');
+ }
d |= 0x80000000;
}
+ if (FirstDay && first) {
+ ++first;
+ if (strlen(first) == 10) {
+ struct tm tm_r;
+ if (3 == sscanf(first, "%d-%d-%d", &tm_r.tm_year, &tm_r.tm_mon, &tm_r.tm_mday)) {
+ tm_r.tm_year -= 1900;
+ tm_r.tm_mon--;
+ tm_r.tm_hour = tm_r.tm_min = tm_r.tm_sec = 0;
+ *FirstDay = mktime(&tm_r);
+ }
+ }
+ else
+ d = 0;
+ }
}
}
else if (d < 1 || d > 31)
@@ -432,24 +452,40 @@ int cTimer::ParseDay(const char *s)
return d;
}
-const char *cTimer::PrintDay(int d)
+const char *cTimer::PrintDay(int d, time_t FirstDay)
{
- static char buffer[8];
+#define DAYBUFFERSIZE 32
+ static char buffer[DAYBUFFERSIZE];
if ((d & 0x80000000) != 0) {
char *b = buffer;
const char *w = tr("MTWTFSS");
- *b = 0;
while (*w) {
*b++ = (d & 1) ? *w : '-';
d >>= 1;
w++;
}
+ if (FirstDay) {
+ struct tm tm_r;
+ localtime_r(&FirstDay, &tm_r);
+ b += strftime(b, DAYBUFFERSIZE - (b - buffer), "@%Y-%m-%d", &tm_r);
+ }
+ *b = 0;
}
else
sprintf(buffer, "%d", d);
return buffer;
}
+const char *cTimer::PrintFirstDay(void)
+{
+ if (firstday) {
+ const char *s = PrintDay(day, firstday);
+ if (strlen(s) == 18)
+ return s + 8;
+ }
+ return ""; // not NULL, so the caller can always use the result
+}
+
bool cTimer::Parse(const char *s)
{
char *buffer1 = NULL;
@@ -477,7 +513,7 @@ bool cTimer::Parse(const char *s)
summary = NULL;
}
//TODO add more plausibility checks
- day = ParseDay(buffer1);
+ day = ParseDay(buffer1, &firstday);
strn0cpy(file, buffer2, MaxFileName);
strreplace(file, '|', ':');
strreplace(summary, '|', '\n');
@@ -563,13 +599,17 @@ bool cTimer::Matches(time_t t)
if (DayMatches(t0)) {
time_t a = SetTime(t0, begin);
time_t b = a + length;
- if (t <= b) {
+ if ((!firstday || a >= firstday) && t <= b) {
startTime = a;
stopTime = b;
+ if (t >= firstday)
+ firstday = 0;
break;
}
}
}
+ if (!startTime)
+ startTime = firstday; // just to have something that's more than a week in the future
return active && startTime <= t && t < stopTime; // must stop *before* stopTime to allow adjacent timers
}
@@ -598,6 +638,11 @@ void cTimer::SetPending(bool Pending)
pending = Pending;
}
+void cTimer::SkipToday(void)
+{
+ firstday = IncDay(SetTime(recording ? StartTime() : time(NULL), 0), 1);
+}
+
// --- cCommand -------------------------------------------------------------
char *cCommand::result = NULL;