1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Made several functions threadsafe (cont'd)

This commit is contained in:
Klaus Schmidinger 2004-12-26 12:45:22 +01:00
parent f97b1069c6
commit 286af66cfb
26 changed files with 295 additions and 322 deletions

39
HISTORY
View File

@ -3160,7 +3160,7 @@ Video Disk Recorder Revision History
right day of week for timers in the future. right day of week for timers in the future.
- Some improvements to cPoller (thanks to Marco Schlüßler). - Some improvements to cPoller (thanks to Marco Schlüßler).
2004-12-24: Version 1.3.18 2004-12-26: Version 1.3.18
- Removed an unused variable from cTimer::GetWDayFromMDay() (thanks to Wayne Keer - Removed an unused variable from cTimer::GetWDayFromMDay() (thanks to Wayne Keer
for reporting this one). for reporting this one).
@ -3215,12 +3215,37 @@ Video Disk Recorder Revision History
the actual buffering. In particular these are: the actual buffering. In particular these are:
readdir() -> cReadDir readdir() -> cReadDir
readline() -> cReadLine readline() -> cReadLine
strescape() -> cStrEscape - Several formerly non-threadsafe functions now have a return type of cString:
AddDirectory() -> cAddDirectory cChannel::ToText()
ctime() -> cCtime tChannelID::ToString()
itoa() -> cItoa cEvent::GetDateString()
WeekDayName() -> cWeekDayName cEvent::GetTimeString()
DayDateTime() -> cDayDateTime cEvent::GetEndTimeString()
cEvent::GetVpsString()
cMark::ToText()
cTimer::ToText()
cSource::ToString()
cTimer::PrintDay()
cTimer::PrintFirstDay()
PrefixVideoFileName()
IndexToHMSF()
ChannelString()
strescape()
AddDirectory()
itoa()
WeekDayName()
DayDateTime()
When using these functions in a 'const char *' context there is nothing special
to consider, except that you can no longer have a pointer to the return value,
as in
const char *date = DayDateTime();
Although this will compile without error message, the resulting 'date' will not
be valid after this line. Use this instead:
cString date = DayDateTime();
In a 'const void *' context (as in printf() etc.) the result needs to be
dereferenced with a '*', as in
printf("%s", *DayDateTime());
to make it a 'const char *'.
- Removed delay_ms(), using cCondWait::SleepMs() instead. - Removed delay_ms(), using cCondWait::SleepMs() instead.
- Replaced time_ms() with a threadsafe and non-overflowing cTimeMs (thanks to Rainer - Replaced time_ms() with a threadsafe and non-overflowing cTimeMs (thanks to Rainer
Zocholl for pointing out this problem). Zocholl for pointing out this problem).

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: skincurses.c 1.2 2004/05/31 14:57:40 kls Exp $ * $Id: skincurses.c 1.3 2004/12/26 11:36:35 kls Exp $
*/ */
#include <ncurses.h> #include <ncurses.h>
@ -11,7 +11,7 @@
#include <vdr/plugin.h> #include <vdr/plugin.h>
#include <vdr/skins.h> #include <vdr/skins.h>
static const char *VERSION = "0.0.2"; static const char *VERSION = "0.0.3";
static const char *DESCRIPTION = "A text only skin"; static const char *DESCRIPTION = "A text only skin";
static const char *MAINMENUENTRY = NULL; static const char *MAINMENUENTRY = NULL;
@ -252,7 +252,7 @@ void cSkinCursesDisplayChannel::SetMessage(eMessageType Type, const char *Text)
void cSkinCursesDisplayChannel::Flush(void) void cSkinCursesDisplayChannel::Flush(void)
{ {
if (!message) { if (!message) {
const char *date = DayDateTime(); cString date = DayDateTime();
osd->DrawText(OsdWidth - strlen(date), 0, date, clrWhite, clrBackground, &Font); osd->DrawText(OsdWidth - strlen(date), 0, date, clrWhite, clrBackground, &Font);
} }
osd->Flush(); osd->Flush();
@ -382,11 +382,11 @@ void cSkinCursesDisplayMenu::SetEvent(const cEvent *Event)
int y = 2; int y = 2;
cTextScroller ts; cTextScroller ts;
char t[32]; char t[32];
snprintf(t, sizeof(t), "%s %s - %s", Event->GetDateString(), Event->GetTimeString(), Event->GetEndTimeString()); snprintf(t, sizeof(t), "%s %s - %s", *Event->GetDateString(), *Event->GetTimeString(), *Event->GetEndTimeString());
ts.Set(osd, 0, y, OsdWidth, OsdHeight - y - 2, t, &Font, clrYellow, clrBackground); ts.Set(osd, 0, y, OsdWidth, OsdHeight - y - 2, t, &Font, clrYellow, clrBackground);
if (Event->Vps() && Event->Vps() != Event->StartTime()) { if (Event->Vps() && Event->Vps() != Event->StartTime()) {
char *buffer; char *buffer;
asprintf(&buffer, " VPS: %s", Event->GetVpsString()); asprintf(&buffer, " VPS: %s", *Event->GetVpsString());
osd->DrawText(OsdWidth - strlen(buffer), y, buffer, clrBlack, clrYellow, &Font); osd->DrawText(OsdWidth - strlen(buffer), y, buffer, clrBlack, clrYellow, &Font);
free(buffer); free(buffer);
} }
@ -418,7 +418,7 @@ void cSkinCursesDisplayMenu::SetText(const char *Text, bool FixedFont)
void cSkinCursesDisplayMenu::Flush(void) void cSkinCursesDisplayMenu::Flush(void)
{ {
const char *date = DayDateTime(); cString date = DayDateTime();
osd->DrawText(OsdWidth - strlen(date) - 2, 0, date, clrBlack, clrCyan, &Font); osd->DrawText(OsdWidth - strlen(date) - 2, 0, date, clrBlack, clrCyan, &Font);
osd->Flush(); osd->Flush();
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: sky.c 1.10 2004/12/19 17:21:52 kls Exp $ * $Id: sky.c 1.11 2004/12/26 12:45:22 kls Exp $
*/ */
#include <sys/socket.h> #include <sys/socket.h>
@ -273,7 +273,7 @@ bool cPluginSky::Initialize(void)
// Initialize any background activities the plugin shall perform. // Initialize any background activities the plugin shall perform.
const char *ConfigDir = ConfigDirectory(Name()); const char *ConfigDir = ConfigDirectory(Name());
if (ConfigDir) { if (ConfigDir) {
if (SkyChannels.Load(*cAddDirectory(ConfigDir, "channels.conf.sky"), true)) { if (SkyChannels.Load(AddDirectory(ConfigDir, "channels.conf.sky"), true)) {
new cDigiboxDevice; new cDigiboxDevice;
return true; return true;
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: channels.c 1.32 2004/12/19 11:24:51 kls Exp $ * $Id: channels.c 1.33 2004/12/26 12:34:52 kls Exp $
*/ */
#include "channels.h" #include "channels.h"
@ -146,10 +146,10 @@ tChannelID tChannelID::FromString(const char *s)
return tChannelID::InvalidID; return tChannelID::InvalidID;
} }
const char *tChannelID::ToString(void) cString tChannelID::ToString(void)
{ {
static char buffer[256]; char buffer[256];
snprintf(buffer, sizeof(buffer), rid ? "%s-%d-%d-%d-%d" : "%s-%d-%d-%d", cSource::ToString(source), nid, tid, sid, rid); snprintf(buffer, sizeof(buffer), rid ? "%s-%d-%d-%d-%d" : "%s-%d-%d-%d", *cSource::ToString(source), nid, tid, sid, rid);
return buffer; return buffer;
} }
@ -162,8 +162,6 @@ tChannelID &tChannelID::ClrPolarization(void)
// -- cChannel --------------------------------------------------------------- // -- cChannel ---------------------------------------------------------------
char *cChannel::buffer = NULL;
cChannel::cChannel(void) cChannel::cChannel(void)
{ {
name = strdup(""); name = strdup("");
@ -289,7 +287,7 @@ bool cChannel::SetSatTransponderData(int Source, int Frequency, char Polarizatio
if (source != Source || frequency != Frequency || polarization != Polarization || srate != Srate || coderateH != CoderateH) { if (source != Source || frequency != Frequency || polarization != Polarization || srate != Srate || coderateH != CoderateH) {
if (Number()) { if (Number()) {
dsyslog("changing transponder data of channel %d from %s:%d:%c:%d:%d to %s:%d:%c:%d:%d", Number(), cSource::ToString(source), frequency, polarization, srate, coderateH, cSource::ToString(Source), Frequency, Polarization, Srate, CoderateH); dsyslog("changing transponder data of channel %d from %s:%d:%c:%d:%d to %s:%d:%c:%d:%d", Number(), *cSource::ToString(source), frequency, polarization, srate, coderateH, *cSource::ToString(Source), Frequency, Polarization, Srate, CoderateH);
modification |= CHANNELMOD_TRANSP; modification |= CHANNELMOD_TRANSP;
Channels.SetModified(); Channels.SetModified();
} }
@ -307,7 +305,7 @@ bool cChannel::SetCableTransponderData(int Source, int Frequency, int Modulation
{ {
if (source != Source || frequency != Frequency || modulation != Modulation || srate != Srate || coderateH != CoderateH) { if (source != Source || frequency != Frequency || modulation != Modulation || srate != Srate || coderateH != CoderateH) {
if (Number()) { if (Number()) {
dsyslog("changing transponder data of channel %d from %s:%d:%d:%d:%d to %s:%d:%d:%d:%d", Number(), cSource::ToString(source), frequency, modulation, srate, coderateH, cSource::ToString(Source), Frequency, Modulation, Srate, CoderateH); dsyslog("changing transponder data of channel %d from %s:%d:%d:%d:%d to %s:%d:%d:%d:%d", Number(), *cSource::ToString(source), frequency, modulation, srate, coderateH, *cSource::ToString(Source), Frequency, Modulation, Srate, CoderateH);
modification |= CHANNELMOD_TRANSP; modification |= CHANNELMOD_TRANSP;
Channels.SetModified(); Channels.SetModified();
} }
@ -324,7 +322,7 @@ bool cChannel::SetTerrTransponderData(int Source, int Frequency, int Bandwidth,
{ {
if (source != Source || frequency != Frequency || bandwidth != Bandwidth || modulation != Modulation || hierarchy != Hierarchy || coderateH != CoderateH || coderateL != CoderateL || guard != Guard || transmission != Transmission) { if (source != Source || frequency != Frequency || bandwidth != Bandwidth || modulation != Modulation || hierarchy != Hierarchy || coderateH != CoderateH || coderateL != CoderateL || guard != Guard || transmission != Transmission) {
if (Number()) { if (Number()) {
dsyslog("changing transponder data of channel %d from %s:%d:%d:%d:%d:%d:%d:%d:%d to %s:%d:%d:%d:%d:%d:%d:%d:%d", Number(), cSource::ToString(source), frequency, bandwidth, modulation, hierarchy, coderateH, coderateL, guard, transmission, cSource::ToString(Source), Frequency, Bandwidth, Modulation, Hierarchy, CoderateH, CoderateL, Guard, Transmission); dsyslog("changing transponder data of channel %d from %s:%d:%d:%d:%d:%d:%d:%d:%d to %s:%d:%d:%d:%d:%d:%d:%d:%d", Number(), *cSource::ToString(source), frequency, bandwidth, modulation, hierarchy, coderateH, coderateL, guard, transmission, *cSource::ToString(Source), Frequency, Bandwidth, Modulation, Hierarchy, CoderateH, CoderateL, Guard, Transmission);
modification |= CHANNELMOD_TRANSP; modification |= CHANNELMOD_TRANSP;
Channels.SetModified(); Channels.SetModified();
} }
@ -540,13 +538,13 @@ static int PrintParameter(char *p, char Name, int Value)
return Value >= 0 && Value != 999 ? sprintf(p, "%c%d", Name, Value) : 0; return Value >= 0 && Value != 999 ? sprintf(p, "%c%d", Name, Value) : 0;
} }
const char *cChannel::ParametersToString(void) const cString cChannel::ParametersToString(void) const
{ {
char type = *cSource::ToString(source); char type = **cSource::ToString(source);
if (isdigit(type)) if (isdigit(type))
type = 'S'; type = 'S';
#define ST(s) if (strchr(s, type)) #define ST(s) if (strchr(s, type))
static char buffer[64]; char buffer[64];
char *q = buffer; char *q = buffer;
*q = 0; *q = 0;
ST(" S ") q += sprintf(q, "%c", polarization); ST(" S ") q += sprintf(q, "%c", polarization);
@ -600,7 +598,7 @@ bool cChannel::StringToParameters(const char *s)
return true; return true;
} }
const char *cChannel::ToText(const cChannel *Channel) cString cChannel::ToText(const cChannel *Channel)
{ {
char FullName[strlen(Channel->name) + 1 + strlen(Channel->shortName) + 1 + strlen(Channel->provider) + 1 + 10]; // +10: paranoia char FullName[strlen(Channel->name) + 1 + strlen(Channel->shortName) + 1 + strlen(Channel->provider) + 1 + 10]; // +10: paranoia
char *q = FullName; char *q = FullName;
@ -611,7 +609,7 @@ const char *cChannel::ToText(const cChannel *Channel)
q += sprintf(q, ";%s", Channel->provider); q += sprintf(q, ";%s", Channel->provider);
*q = 0; *q = 0;
strreplace(FullName, ':', '|'); strreplace(FullName, ':', '|');
free(buffer); char *buffer;
if (Channel->groupSep) { if (Channel->groupSep) {
if (Channel->number) if (Channel->number)
asprintf(&buffer, ":@%d %s\n", Channel->number, FullName); asprintf(&buffer, ":@%d %s\n", Channel->number, FullName);
@ -637,12 +635,12 @@ const char *cChannel::ToText(const cChannel *Channel)
q = caidbuf; q = caidbuf;
q += IntArrayToString(q, Channel->caids, 16); q += IntArrayToString(q, Channel->caids, 16);
*q = 0; *q = 0;
asprintf(&buffer, "%s:%d:%s:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d\n", FullName, Channel->frequency, Channel->ParametersToString(), cSource::ToString(Channel->source), Channel->srate, vpidbuf, apidbuf, Channel->tpid, caidbuf, Channel->sid, Channel->nid, Channel->tid, Channel->rid); asprintf(&buffer, "%s:%d:%s:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d\n", FullName, Channel->frequency, *Channel->ParametersToString(), *cSource::ToString(Channel->source), Channel->srate, vpidbuf, apidbuf, Channel->tpid, caidbuf, Channel->sid, Channel->nid, Channel->tid, Channel->rid);
} }
return buffer; return buffer;
} }
const char *cChannel::ToText(void) const cString cChannel::ToText(void) const
{ {
return ToText(this); return ToText(this);
} }
@ -800,7 +798,7 @@ bool cChannel::Parse(const char *s, bool AllowNonUniqueID)
bool cChannel::Save(FILE *f) bool cChannel::Save(FILE *f)
{ {
return fprintf(f, ToText()) > 0; return fprintf(f, "%s", *ToText()) > 0;
} }
// -- cChannels -------------------------------------------------------------- // -- cChannels --------------------------------------------------------------
@ -939,7 +937,7 @@ int cChannels::Modified(void)
cChannel *cChannels::NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid) cChannel *cChannels::NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid)
{ {
if (Transponder) { if (Transponder) {
dsyslog("creating new channel '%s,%s;%s' on %s transponder %d with id %d-%d-%d-%d", Name, ShortName, Provider, cSource::ToString(Transponder->Source()), Transponder->Transponder(), Nid, Tid, Sid, Rid); dsyslog("creating new channel '%s,%s;%s' on %s transponder %d with id %d-%d-%d-%d", Name, ShortName, Provider, *cSource::ToString(Transponder->Source()), Transponder->Transponder(), Nid, Tid, Sid, Rid);
cChannel *NewChannel = new cChannel(*Transponder); cChannel *NewChannel = new cChannel(*Transponder);
NewChannel->SetId(Nid, Tid, Sid, Rid); NewChannel->SetId(Nid, Tid, Sid, Rid);
NewChannel->SetName(Name, ShortName, Provider); NewChannel->SetName(Name, ShortName, Provider);
@ -950,9 +948,9 @@ cChannel *cChannels::NewChannel(const cChannel *Transponder, const char *Name, c
return NULL; return NULL;
} }
const char *ChannelString(const cChannel *Channel, int Number) cString ChannelString(const cChannel *Channel, int Number)
{ {
static char buffer[256]; char buffer[256];
if (Channel) { if (Channel) {
if (Channel->GroupSep()) if (Channel->GroupSep())
snprintf(buffer, sizeof(buffer), "%s", Channel->Name()); snprintf(buffer, sizeof(buffer), "%s", Channel->Name());

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: channels.h 1.23 2004/12/05 13:49:04 kls Exp $ * $Id: channels.h 1.24 2004/12/26 12:15:52 kls Exp $
*/ */
#ifndef __CHANNELS_H #ifndef __CHANNELS_H
@ -67,7 +67,7 @@ public:
tChannelID &ClrRid(void) { rid = 0; return *this; } tChannelID &ClrRid(void) { rid = 0; return *this; }
tChannelID &ClrPolarization(void); tChannelID &ClrPolarization(void);
static tChannelID FromString(const char *s); static tChannelID FromString(const char *s);
const char *ToString(void); cString ToString(void);
static const tChannelID InvalidID; static const tChannelID InvalidID;
}; };
@ -87,8 +87,7 @@ class cLinkChannels : public cList<cLinkChannel> {
class cChannel : public cListObject { class cChannel : public cListObject {
friend class cMenuEditChannel; friend class cMenuEditChannel;
private: private:
static char *buffer; static cString ToText(const cChannel *Channel);
static const char *ToText(const cChannel *Channel);
char *name; char *name;
char *shortName; char *shortName;
char *provider; char *provider;
@ -124,14 +123,14 @@ private:
int modification; int modification;
cLinkChannels *linkChannels; cLinkChannels *linkChannels;
cChannel *refChannel; cChannel *refChannel;
const char *ParametersToString(void) const; cString ParametersToString(void) const;
bool StringToParameters(const char *s); bool StringToParameters(const char *s);
public: public:
cChannel(void); cChannel(void);
cChannel(const cChannel &Channel); cChannel(const cChannel &Channel);
~cChannel(); ~cChannel();
cChannel& operator= (const cChannel &Channel); cChannel& operator= (const cChannel &Channel);
const char *ToText(void) const; cString ToText(void) const;
bool Parse(const char *s, bool AllowNonUniqueID = false); bool Parse(const char *s, bool AllowNonUniqueID = false);
bool Save(FILE *f); bool Save(FILE *f);
const char *Name(void) const { return name; } const char *Name(void) const { return name; }
@ -216,6 +215,6 @@ public:
extern cChannels Channels; extern cChannels Channels;
const char *ChannelString(const cChannel *Channel, int Number); cString ChannelString(const cChannel *Channel, int Number);
#endif //__CHANNELS_H #endif //__CHANNELS_H

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbplayer.c 1.28 2004/12/11 17:02:40 kls Exp $ * $Id: dvbplayer.c 1.29 2004/12/26 11:45:34 kls Exp $
*/ */
#include "dvbplayer.h" #include "dvbplayer.h"
@ -366,7 +366,7 @@ void cDvbPlayer::Action(void)
readIndex = Resume(); readIndex = Resume();
if (readIndex >= 0) if (readIndex >= 0)
isyslog("resuming replay at index %d (%s)", readIndex, IndexToHMSF(readIndex, true)); isyslog("resuming replay at index %d (%s)", readIndex, *IndexToHMSF(readIndex, true));
nonBlockingFileReader = new cNonBlockingFileReader; nonBlockingFileReader = new cNonBlockingFileReader;
int Length = 0; int Length = 0;

6
eit.c
View File

@ -8,7 +8,7 @@
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
* Adapted to 'libsi' for VDR 1.3.0 by Marcel Wiesweg <marcel.wiesweg@gmx.de>. * Adapted to 'libsi' for VDR 1.3.0 by Marcel Wiesweg <marcel.wiesweg@gmx.de>.
* *
* $Id: eit.c 1.100 2004/10/31 12:56:24 kls Exp $ * $Id: eit.c 1.101 2004/12/26 10:38:46 kls Exp $
*/ */
#include "eit.h" #include "eit.h"
@ -245,8 +245,8 @@ cTDT::cTDT(const u_char *Data)
if (abs(sattim - loctim) > 2) { if (abs(sattim - loctim) > 2) {
mutex.Lock(); mutex.Lock();
isyslog("System Time = %s (%ld)\n", ctime(&loctim), loctim); isyslog("System Time = %s (%ld)\n", *TimeToString(loctim), loctim);
isyslog("Local Time = %s (%ld)\n", ctime(&sattim), sattim); isyslog("Local Time = %s (%ld)\n", *TimeToString(sattim), sattim);
if (stime(&sattim) < 0) if (stime(&sattim) < 0)
esyslog("ERROR while setting system time: %m"); esyslog("ERROR while setting system time: %m");
mutex.Unlock(); mutex.Unlock();

31
epg.c
View File

@ -7,7 +7,7 @@
* Original version (as used in VDR before 1.3.0) written by * Original version (as used in VDR before 1.3.0) written by
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
* *
* $Id: epg.c 1.22 2004/11/07 10:43:30 kls Exp $ * $Id: epg.c 1.23 2004/12/26 11:32:01 kls Exp $
*/ */
#include "epg.h" #include "epg.h"
@ -66,7 +66,7 @@ void cEvent::SetRunningStatus(int RunningStatus, cChannel *Channel)
{ {
if (Channel && runningStatus != RunningStatus && (RunningStatus > SI::RunningStatusNotRunning || runningStatus > SI::RunningStatusUndefined)) if (Channel && runningStatus != RunningStatus && (RunningStatus > SI::RunningStatusNotRunning || runningStatus > SI::RunningStatusUndefined))
if (Channel->Number() <= 30)//XXX maybe log only those that have timers??? if (Channel->Number() <= 30)//XXX maybe log only those that have timers???
isyslog("channel %d (%s) event %s '%s' status %d", Channel->Number(), Channel->Name(), GetTimeString(), Title(), RunningStatus); isyslog("channel %d (%s) event %s '%s' status %d", Channel->Number(), Channel->Name(), *GetTimeString(), Title(), RunningStatus);
runningStatus = RunningStatus; runningStatus = RunningStatus;
} }
@ -119,9 +119,9 @@ bool cEvent::IsRunning(bool OrAboutToStart) const
return runningStatus >= (OrAboutToStart ? SI::RunningStatusStartsInAFewSeconds : SI::RunningStatusPausing); return runningStatus >= (OrAboutToStart ? SI::RunningStatusStartsInAFewSeconds : SI::RunningStatusPausing);
} }
const char *cEvent::GetDateString(void) const cString cEvent::GetDateString(void) const
{ {
static char buf[32]; char buf[32];
struct tm tm_r; struct tm tm_r;
tm *tm = localtime_r(&startTime, &tm_r); tm *tm = localtime_r(&startTime, &tm_r);
char *p = stpcpy(buf, WeekDayName(tm->tm_wday)); char *p = stpcpy(buf, WeekDayName(tm->tm_wday));
@ -130,26 +130,26 @@ const char *cEvent::GetDateString(void) const
return buf; return buf;
} }
const char *cEvent::GetTimeString(void) const cString cEvent::GetTimeString(void) const
{ {
static char buf[25]; char buf[25];
struct tm tm_r; struct tm tm_r;
strftime(buf, sizeof(buf), "%R", localtime_r(&startTime, &tm_r)); strftime(buf, sizeof(buf), "%R", localtime_r(&startTime, &tm_r));
return buf; return buf;
} }
const char *cEvent::GetEndTimeString(void) const cString cEvent::GetEndTimeString(void) const
{ {
static char buf[25]; char buf[25];
time_t EndTime = startTime + duration; time_t EndTime = startTime + duration;
struct tm tm_r; struct tm tm_r;
strftime(buf, sizeof(buf), "%R", localtime_r(&EndTime, &tm_r)); strftime(buf, sizeof(buf), "%R", localtime_r(&EndTime, &tm_r));
return buf; return buf;
} }
const char *cEvent::GetVpsString(void) const cString cEvent::GetVpsString(void) const
{ {
static char buf[25]; char buf[25];
struct tm tm_r; struct tm tm_r;
strftime(buf, sizeof(buf), "%d.%m %R", localtime_r(&vps, &tm_r)); strftime(buf, sizeof(buf), "%d.%m %R", localtime_r(&vps, &tm_r));
return buf; return buf;
@ -179,7 +179,8 @@ bool cEvent::Read(FILE *f, cSchedule *Schedule)
if (Schedule) { if (Schedule) {
cEvent *Event = NULL; cEvent *Event = NULL;
char *s; char *s;
while ((s = readline(f)) != NULL) { cReadLine ReadLine;
while ((s = ReadLine.Read(f)) != NULL) {
char *t = skipspace(s + 1); char *t = skipspace(s + 1);
switch (*s) { switch (*s) {
case 'E': if (!Event) { case 'E': if (!Event) {
@ -604,7 +605,7 @@ void cSchedule::Dump(FILE *f, const char *Prefix, eDumpMode DumpMode, time_t AtT
{ {
cChannel *channel = Channels.GetByChannelID(channelID, true); cChannel *channel = Channels.GetByChannelID(channelID, true);
if (channel) { if (channel) {
fprintf(f, "%sC %s %s\n", Prefix, channel->GetChannelID().ToString(), channel->Name()); fprintf(f, "%sC %s %s\n", Prefix, *channel->GetChannelID().ToString(), channel->Name());
const cEvent *p; const cEvent *p;
switch (DumpMode) { switch (DumpMode) {
case dmAll: { case dmAll: {
@ -635,8 +636,9 @@ void cSchedule::Dump(FILE *f, const char *Prefix, eDumpMode DumpMode, time_t AtT
bool cSchedule::Read(FILE *f, cSchedules *Schedules) bool cSchedule::Read(FILE *f, cSchedules *Schedules)
{ {
if (Schedules) { if (Schedules) {
cReadLine ReadLine;
char *s; char *s;
while ((s = readline(f)) != NULL) { while ((s = ReadLine.Read(f)) != NULL) {
if (*s == 'C') { if (*s == 'C') {
s = skipspace(s + 1); s = skipspace(s + 1);
char *p = strchr(s, ' '); char *p = strchr(s, ' ');
@ -698,8 +700,7 @@ const cSchedules *cSchedules::Schedules(cSchedulesLock &SchedulesLock)
void cSchedules::SetEpgDataFileName(const char *FileName) void cSchedules::SetEpgDataFileName(const char *FileName)
{ {
delete epgDataFileName; delete epgDataFileName;
if (FileName) epgDataFileName = FileName ? strdup(FileName) : NULL;
epgDataFileName = strdup(FileName);
} }
void cSchedules::SetModified(cSchedule *Schedule) void cSchedules::SetModified(cSchedule *Schedule)

10
epg.h
View File

@ -7,7 +7,7 @@
* Original version (as used in VDR before 1.3.0) written by * Original version (as used in VDR before 1.3.0) written by
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
* *
* $Id: epg.h 1.17 2004/10/31 16:17:10 kls Exp $ * $Id: epg.h 1.18 2004/12/26 11:31:27 kls Exp $
*/ */
#ifndef __EPG_H #ifndef __EPG_H
@ -56,10 +56,10 @@ public:
time_t Seen(void) const { return seen; } time_t Seen(void) const { return seen; }
bool HasTimer(void) const; bool HasTimer(void) const;
bool IsRunning(bool OrAboutToStart = false) const; bool IsRunning(bool OrAboutToStart = false) const;
const char *GetDateString(void) const; cString GetDateString(void) const;
const char *GetTimeString(void) const; cString GetTimeString(void) const;
const char *GetEndTimeString(void) const; cString GetEndTimeString(void) const;
const char *GetVpsString(void) const; cString GetVpsString(void) const;
void SetEventID(u_int16_t EventID); void SetEventID(u_int16_t EventID);
void SetTableID(uchar TableID); void SetTableID(uchar TableID);
void SetVersion(uchar Version); void SetVersion(uchar Version);

20
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.c 1.322 2004/12/19 17:59:47 kls Exp $ * $Id: menu.c 1.323 2004/12/26 12:18:29 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -116,7 +116,7 @@ void cMenuEditSrcItem::Set(void)
{ {
if (source) { if (source) {
char *buffer = NULL; char *buffer = NULL;
asprintf(&buffer, "%s - %s", cSource::ToString(source->Code()), source->Description()); asprintf(&buffer, "%s - %s", *cSource::ToString(source->Code()), source->Description());
SetValue(buffer); SetValue(buffer);
free(buffer); free(buffer);
} }
@ -249,7 +249,7 @@ cMenuEditChannel::cMenuEditChannel(cChannel *Channel, bool New)
void cMenuEditChannel::Setup(void) void cMenuEditChannel::Setup(void)
{ {
int current = Current(); int current = Current();
char type = *cSource::ToString(data.source); char type = **cSource::ToString(data.source);
#define ST(s) if (strchr(s, type)) #define ST(s) if (strchr(s, type))
Clear(); Clear();
@ -300,7 +300,7 @@ eOSState cMenuEditChannel::ProcessKey(eKeys Key)
data.name = strcpyrealloc(data.name, name); data.name = strcpyrealloc(data.name, name);
if (channel) { if (channel) {
*channel = data; *channel = data;
isyslog("edited channel %d %s", channel->Number(), data.ToText()); isyslog("edited channel %d %s", channel->Number(), *data.ToText());
state = osBack; state = osBack;
} }
else { else {
@ -308,7 +308,7 @@ eOSState cMenuEditChannel::ProcessKey(eKeys Key)
*channel = data; *channel = data;
Channels.Add(channel); Channels.Add(channel);
Channels.ReNumber(); Channels.ReNumber();
isyslog("added channel %d %s", channel->Number(), data.ToText()); isyslog("added channel %d %s", channel->Number(), *data.ToText());
state = osUser1; state = osUser1;
} }
Channels.SetModified(true); Channels.SetModified(true);
@ -737,9 +737,9 @@ void cMenuTimerItem::Set(void)
asprintf(&buffer, "%c\t%d\t%s%s%s\t%02d:%02d\t%02d:%02d\t%s", asprintf(&buffer, "%c\t%d\t%s%s%s\t%02d:%02d\t%02d:%02d\t%s",
!(timer->HasFlags(tfActive)) ? ' ' : timer->FirstDay() ? '!' : timer->Recording() ? '#' : '>', !(timer->HasFlags(tfActive)) ? ' ' : timer->FirstDay() ? '!' : timer->Recording() ? '#' : '>',
timer->Channel()->Number(), timer->Channel()->Number(),
timer->IsSingleEvent() ? WeekDayName(timer->StartTime()) : "", timer->IsSingleEvent() ? *WeekDayName(timer->StartTime()) : "",
timer->IsSingleEvent() ? " " : "", timer->IsSingleEvent() ? " " : "",
timer->PrintDay(timer->Day()), *timer->PrintDay(timer->Day()),
timer->Start() / 100, timer->Start() / 100,
timer->Start() % 100, timer->Start() % 100,
timer->Stop() / 100, timer->Stop() / 100,
@ -795,7 +795,7 @@ eOSState cMenuTimers::OnOff(void)
RefreshCurrent(); RefreshCurrent();
DisplayCurrent(true); DisplayCurrent(true);
if (timer->FirstDay()) if (timer->FirstDay())
isyslog("timer %d first day set to %s", timer->Index() + 1, timer->PrintFirstDay()); isyslog("timer %d first day set to %s", timer->Index() + 1, *timer->PrintFirstDay());
else else
isyslog("timer %d %sactivated", timer->Index() + 1, timer->HasFlags(tfActive) ? "" : "de"); isyslog("timer %d %sactivated", timer->Index() + 1, timer->HasFlags(tfActive) ? "" : "de");
Timers.SetModified(); Timers.SetModified();
@ -969,7 +969,7 @@ cMenuWhatsOnItem::cMenuWhatsOnItem(const cEvent *Event, cChannel *Channel)
char t = Timers.GetMatch(Event, &TimerMatch) ? (TimerMatch == tmFull) ? 'T' : 't' : ' '; char t = Timers.GetMatch(Event, &TimerMatch) ? (TimerMatch == tmFull) ? 'T' : 't' : ' ';
char v = event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' '; char v = event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' ';
char r = event->IsRunning() ? '*' : ' '; char r = event->IsRunning() ? '*' : ' ';
asprintf(&buffer, "%d\t%.*s\t%s\t%c%c%c\t%s", channel->Number(), 6, channel->ShortName(true), event->GetTimeString(), t, v, r, event->Title()); asprintf(&buffer, "%d\t%.*s\t%s\t%c%c%c\t%s", channel->Number(), 6, channel->ShortName(true), *event->GetTimeString(), t, v, r, event->Title());
SetText(buffer, false); SetText(buffer, false);
} }
@ -1087,7 +1087,7 @@ cMenuScheduleItem::cMenuScheduleItem(const cEvent *Event)
char t = Timers.GetMatch(Event, &TimerMatch) ? (TimerMatch == tmFull) ? 'T' : 't' : ' '; char t = Timers.GetMatch(Event, &TimerMatch) ? (TimerMatch == tmFull) ? 'T' : 't' : ' ';
char v = event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' '; char v = event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' ';
char r = event->IsRunning() ? '*' : ' '; char r = event->IsRunning() ? '*' : ' ';
asprintf(&buffer, "%.*s\t%s\t%c%c%c\t%s", 6, event->GetDateString(), event->GetTimeString(), t, v, r, event->Title()); asprintf(&buffer, "%.*s\t%s\t%c%c%c\t%s", 6, *event->GetDateString(), *event->GetTimeString(), t, v, r, event->Title());
SetText(buffer, false); SetText(buffer, false);
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: recording.c 1.93 2004/12/19 15:44:42 kls Exp $ * $Id: recording.c 1.94 2004/12/26 11:55:24 kls Exp $
*/ */
#include "recording.h" #include "recording.h"
@ -157,7 +157,7 @@ cResumeFile::cResumeFile(const char *FileName)
fileName = MALLOC(char, strlen(FileName) + strlen(RESUMEFILESUFFIX) + 1); fileName = MALLOC(char, strlen(FileName) + strlen(RESUMEFILESUFFIX) + 1);
if (fileName) { if (fileName) {
strcpy(fileName, FileName); strcpy(fileName, FileName);
sprintf(fileName + strlen(fileName), RESUMEFILESUFFIX, Setup.ResumeID ? "." : "", Setup.ResumeID ? *cItoa(Setup.ResumeID) : ""); sprintf(fileName + strlen(fileName), RESUMEFILESUFFIX, Setup.ResumeID ? "." : "", Setup.ResumeID ? *itoa(Setup.ResumeID) : "");
} }
else else
esyslog("ERROR: can't allocate memory for resume file name"); esyslog("ERROR: can't allocate memory for resume file name");
@ -541,8 +541,8 @@ const char *cRecording::Title(char Delimiter, bool NewIndicator, int Level) cons
const char *cRecording::PrefixFileName(char Prefix) const char *cRecording::PrefixFileName(char Prefix)
{ {
const char *p = PrefixVideoFileName(FileName(), Prefix); cString p = PrefixVideoFileName(FileName(), Prefix);
if (p) { if (*p) {
free(fileName); free(fileName);
fileName = strdup(p); fileName = strdup(p);
return fileName; return fileName;
@ -665,7 +665,7 @@ void cRecordings::ScanVideoDir(const char *DirName)
bool cRecordings::NeedsUpdate(void) bool cRecordings::NeedsUpdate(void)
{ {
return lastUpdate <= LastModifiedTime(*cAddDirectory(VideoDirectory, ".update")); return lastUpdate <= LastModifiedTime(AddDirectory(VideoDirectory, ".update"));
} }
bool cRecordings::Load(void) bool cRecordings::Load(void)
@ -704,8 +704,6 @@ void cRecordings::DelByName(const char *FileName)
// --- cMark ----------------------------------------------------------------- // --- cMark -----------------------------------------------------------------
char *cMark::buffer = NULL;
cMark::cMark(int Position, const char *Comment) cMark::cMark(int Position, const char *Comment)
{ {
position = Position; position = Position;
@ -717,10 +715,10 @@ cMark::~cMark()
free(comment); free(comment);
} }
const char *cMark::ToText(void) cString cMark::ToText(void)
{ {
free(buffer); char *buffer;
asprintf(&buffer, "%s%s%s\n", IndexToHMSF(position, true), comment ? " " : "", comment ? comment : ""); asprintf(&buffer, "%s%s%s\n", *IndexToHMSF(position, true), comment ? " " : "", comment ? comment : "");
return buffer; return buffer;
} }
@ -747,7 +745,7 @@ bool cMark::Save(FILE *f)
bool cMarks::Load(const char *RecordingFileName) bool cMarks::Load(const char *RecordingFileName)
{ {
if (cConfig<cMark>::Load(*cAddDirectory(RecordingFileName, MARKSFILESUFFIX))) { if (cConfig<cMark>::Load(AddDirectory(RecordingFileName, MARKSFILESUFFIX))) {
Sort(); Sort();
return true; return true;
} }
@ -811,7 +809,7 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi
{ {
if (command) { if (command) {
char *cmd; char *cmd;
asprintf(&cmd, "%s %s \"%s\"", command, State, *cStrEscape(RecordingFileName, "\"$")); asprintf(&cmd, "%s %s \"%s\"", command, State, *strescape(RecordingFileName, "\"$"));
isyslog("executing '%s'", cmd); isyslog("executing '%s'", cmd);
SystemExec(cmd); SystemExec(cmd);
free(cmd); free(cmd);
@ -1152,9 +1150,9 @@ int cFileName::NextFile(void)
// --- Index stuff ----------------------------------------------------------- // --- Index stuff -----------------------------------------------------------
const char *IndexToHMSF(int Index, bool WithFrame) cString IndexToHMSF(int Index, bool WithFrame)
{ {
static char buffer[16]; char buffer[16];
int f = (Index % FRAMESPERSEC) + 1; int f = (Index % FRAMESPERSEC) + 1;
int s = (Index / FRAMESPERSEC); int s = (Index / FRAMESPERSEC);
int m = s / 60 % 60; int m = s / 60 % 60;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: recording.h 1.32 2004/10/31 16:24:38 kls Exp $ * $Id: recording.h 1.33 2004/12/26 11:47:35 kls Exp $
*/ */
#ifndef __RECORDING_H #ifndef __RECORDING_H
@ -86,14 +86,12 @@ public:
extern cRecordings Recordings; extern cRecordings Recordings;
class cMark : public cListObject { class cMark : public cListObject {
private:
static char *buffer;
public: public:
int position; int position;
char *comment; char *comment;
cMark(int Position = 0, const char *Comment = NULL); cMark(int Position = 0, const char *Comment = NULL);
~cMark(); ~cMark();
const char *ToText(void); cString ToText(void);
bool Parse(const char *s); bool Parse(const char *s);
bool Save(FILE *f); bool Save(FILE *f);
}; };
@ -176,7 +174,7 @@ public:
int NextFile(void); int NextFile(void);
}; };
const char *IndexToHMSF(int Index, bool WithFrame = false); cString IndexToHMSF(int Index, bool WithFrame = false);
// Converts the given index to a string, optionally containing the frame number. // Converts the given index to a string, optionally containing the frame number.
int HMSFToIndex(const char *HMSF); int HMSFToIndex(const char *HMSF);
// Converts the given string (format: "hh:mm:ss.ff") to an index. // Converts the given string (format: "hh:mm:ss.ff") to an index.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: skinclassic.c 1.8 2004/12/19 15:46:09 kls Exp $ * $Id: skinclassic.c 1.9 2004/12/26 11:33:53 kls Exp $
*/ */
#include "skinclassic.h" #include "skinclassic.h"
@ -141,8 +141,8 @@ void cSkinClassicDisplayChannel::SetMessage(eMessageType Type, const char *Text)
void cSkinClassicDisplayChannel::Flush(void) void cSkinClassicDisplayChannel::Flush(void)
{ {
if (!message) { if (!message) {
cDayDateTime date; cString date = DayDateTime();
osd->DrawText(osd->Width() - cFont::GetFont(fontSml)->Width(*date) - 2, 0, *date, Theme.Color(clrChannelDate), Theme.Color(clrBackground), cFont::GetFont(fontSml)); osd->DrawText(osd->Width() - cFont::GetFont(fontSml)->Width(date) - 2, 0, date, Theme.Color(clrChannelDate), Theme.Color(clrBackground), cFont::GetFont(fontSml));
} }
osd->Flush(); osd->Flush();
} }
@ -299,11 +299,11 @@ void cSkinClassicDisplayMenu::SetEvent(const cEvent *Event)
int y = y2; int y = y2;
cTextScroller ts; cTextScroller ts;
char t[32]; char t[32];
snprintf(t, sizeof(t), "%s %s - %s", Event->GetDateString(), Event->GetTimeString(), Event->GetEndTimeString()); snprintf(t, sizeof(t), "%s %s - %s", *Event->GetDateString(), *Event->GetTimeString(), *Event->GetEndTimeString());
ts.Set(osd, xl, y, x1 - xl, y3 - y, t, font, Theme.Color(clrMenuEventTime), Theme.Color(clrBackground)); ts.Set(osd, xl, y, x1 - xl, y3 - y, t, font, Theme.Color(clrMenuEventTime), Theme.Color(clrBackground));
if (Event->Vps() && Event->Vps() != Event->StartTime()) { if (Event->Vps() && Event->Vps() != Event->StartTime()) {
char *buffer; char *buffer;
asprintf(&buffer, " VPS: %s", Event->GetVpsString()); asprintf(&buffer, " VPS: %s", *Event->GetVpsString());
const cFont *font = cFont::GetFont(fontSml); const cFont *font = cFont::GetFont(fontSml);
osd->DrawText(x1 - font->Width(buffer), y, buffer, Theme.Color(clrMenuEventVpsFg), Theme.Color(clrMenuEventVpsBg), font); osd->DrawText(x1 - font->Width(buffer), y, buffer, Theme.Color(clrMenuEventVpsFg), Theme.Color(clrMenuEventVpsBg), font);
free(buffer); free(buffer);
@ -338,9 +338,9 @@ void cSkinClassicDisplayMenu::SetText(const char *Text, bool FixedFont)
void cSkinClassicDisplayMenu::Flush(void) void cSkinClassicDisplayMenu::Flush(void)
{ {
cDayDateTime date; cString date = DayDateTime();
const cFont *font = cFont::GetFont(fontOsd); const cFont *font = cFont::GetFont(fontOsd);
osd->DrawText(x1 - font->Width(*date) - 2, y0, *date, Theme.Color(clrMenuDate), Theme.Color(clrMenuTitleBg), font); osd->DrawText(x1 - font->Width(date) - 2, y0, date, Theme.Color(clrMenuDate), Theme.Color(clrMenuTitleBg), font);
osd->Flush(); osd->Flush();
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: skins.h 1.3 2004/05/29 13:13:21 kls Exp $ * $Id: skins.h 1.4 2004/12/26 11:57:54 kls Exp $
*/ */
#ifndef __SKINS_H #ifndef __SKINS_H
@ -99,7 +99,7 @@ protected:
///< Returns the offset of the given tab from the left border of the ///< Returns the offset of the given tab from the left border of the
///< item display area. The value returned is in pixel.//XXX ncurses??? ///< item display area. The value returned is in pixel.//XXX ncurses???
const char *GetTabbedText(const char *s, int Tab); const char *GetTabbedText(const char *s, int Tab);
///< Returns the that part of the given string, that follows the given ///< Returns the part of the given string that follows the given
///< Tab (where 0 indicates the beginning of the string). If no such ///< Tab (where 0 indicates the beginning of the string). If no such
///< part can be found, NULL will be returned. ///< part can be found, NULL will be returned.
public: public:

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: skinsttng.c 1.8 2004/12/19 15:48:55 kls Exp $ * $Id: skinsttng.c 1.9 2004/12/26 11:34:29 kls Exp $
*/ */
// Star Trek: The Next Generation® is a registered trademark of Paramount Pictures // Star Trek: The Next Generation® is a registered trademark of Paramount Pictures
@ -289,9 +289,9 @@ void cSkinSTTNGDisplayChannel::Flush(void)
{ {
if (withInfo) { if (withInfo) {
if (!message) { if (!message) {
cDayDateTime date; cString date = DayDateTime();
const cFont *font = cFont::GetFont(fontSml); const cFont *font = cFont::GetFont(fontSml);
osd->DrawText(x4 - font->Width(*date) - 2, y7 - font->Height(*date), *date, Theme.Color(clrChannelDate), frameColor, font); osd->DrawText(x4 - font->Width(date) - 2, y7 - font->Height(date), date, Theme.Color(clrChannelDate), frameColor, font);
} }
int seen = 0; int seen = 0;
@ -456,11 +456,11 @@ void cSkinSTTNGDisplayMenu::SetTitle(const char *Title)
void cSkinSTTNGDisplayMenu::SetButtons(const char *Red, const char *Green, const char *Yellow, const char *Blue) void cSkinSTTNGDisplayMenu::SetButtons(const char *Red, const char *Green, const char *Yellow, const char *Blue)
{ {
cDayDateTime date; cString date = DayDateTime();
const cFont *font = cFont::GetFont(fontSml); const cFont *font = cFont::GetFont(fontSml);
int d = 10; int d = 10;
int d2 = d / 2; int d2 = d / 2;
int t4 = x4 - font->Width(*date) - 2; int t4 = x4 - font->Width(date) - 2;
int w = t4 - x3; int w = t4 - x3;
int t0 = x3 + d2; int t0 = x3 + d2;
int t1 = x3 + w / 4; int t1 = x3 + w / 4;
@ -533,11 +533,11 @@ void cSkinSTTNGDisplayMenu::SetEvent(const cEvent *Event)
int y = y3; int y = y3;
cTextScroller ts; cTextScroller ts;
char t[32]; char t[32];
snprintf(t, sizeof(t), "%s %s - %s", Event->GetDateString(), Event->GetTimeString(), Event->GetEndTimeString()); snprintf(t, sizeof(t), "%s %s - %s", *Event->GetDateString(), *Event->GetTimeString(), *Event->GetEndTimeString());
ts.Set(osd, xl, y, x4 - xl, y4 - y, t, font, Theme.Color(clrMenuEventTime), Theme.Color(clrBackground)); ts.Set(osd, xl, y, x4 - xl, y4 - y, t, font, Theme.Color(clrMenuEventTime), Theme.Color(clrBackground));
if (Event->Vps() && Event->Vps() != Event->StartTime()) { if (Event->Vps() && Event->Vps() != Event->StartTime()) {
char *buffer; char *buffer;
asprintf(&buffer, " VPS: %s", Event->GetVpsString()); asprintf(&buffer, " VPS: %s", *Event->GetVpsString());
const cFont *font = cFont::GetFont(fontSml); const cFont *font = cFont::GetFont(fontSml);
osd->DrawText(x4 - font->Width(buffer), y, buffer, Theme.Color(clrMenuEventVps), frameColor, font); osd->DrawText(x4 - font->Width(buffer), y, buffer, Theme.Color(clrMenuEventVps), frameColor, font);
int yb = y + font->Height(); int yb = y + font->Height();
@ -583,9 +583,9 @@ void cSkinSTTNGDisplayMenu::SetText(const char *Text, bool FixedFont)
void cSkinSTTNGDisplayMenu::Flush(void) void cSkinSTTNGDisplayMenu::Flush(void)
{ {
if (!message) { if (!message) {
cDayDateTime date; cString date = DayDateTime();
const cFont *font = cFont::GetFont(fontSml); const cFont *font = cFont::GetFont(fontSml);
osd->DrawText(x4 - font->Width(*date) - 2, y7 - font->Height(*date), *date, Theme.Color(clrMenuDate), frameColor, font); osd->DrawText(x4 - font->Width(date) - 2, y7 - font->Height(date), date, Theme.Color(clrMenuDate), frameColor, font);
} }
osd->Flush(); osd->Flush();
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: sources.c 1.2 2004/01/11 10:36:57 kls Exp $ * $Id: sources.c 1.3 2004/12/26 11:58:52 kls Exp $
*/ */
#include "sources.h" #include "sources.h"
@ -32,9 +32,9 @@ bool cSource::Parse(const char *s)
return code != stNone && description && *description; return code != stNone && description && *description;
} }
const char *cSource::ToString(int Code) cString cSource::ToString(int Code)
{ {
static char buffer[16]; char buffer[16];
char *q = buffer; char *q = buffer;
switch (Code & st_Mask) { switch (Code & st_Mask) {
case stCable: *q++ = 'C'; break; case stCable: *q++ = 'C'; break;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: sources.h 1.2 2004/01/11 10:35:36 kls Exp $ * $Id: sources.h 1.3 2004/12/26 11:59:21 kls Exp $
*/ */
#ifndef __SOURCES_H #ifndef __SOURCES_H
@ -32,7 +32,7 @@ public:
int Code(void) const { return code; } int Code(void) const { return code; }
const char *Description(void) const { return description; } const char *Description(void) const { return description; }
bool Parse(const char *s); bool Parse(const char *s);
static const char *ToString(int Code); static cString ToString(int Code);
static int FromString(const char *s); static int FromString(const char *s);
static int FromData(eSourceType SourceType, int Position = 0, bool East = false); static int FromData(eSourceType SourceType, int Position = 0, bool East = false);
}; };

34
svdrp.c
View File

@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured * and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection. * graphical interface that sits on top of an SVDRP connection.
* *
* $Id: svdrp.c 1.66 2004/12/19 13:52:34 kls Exp $ * $Id: svdrp.c 1.67 2004/12/26 12:23:55 kls Exp $
*/ */
#include "svdrp.h" #include "svdrp.h"
@ -673,7 +673,7 @@ void cSVDRP::CmdLSTC(const char *Option)
if (isnumber(Option)) { if (isnumber(Option)) {
cChannel *channel = Channels.GetByNumber(strtol(Option, NULL, 10)); cChannel *channel = Channels.GetByNumber(strtol(Option, NULL, 10));
if (channel) if (channel)
Reply(250, "%d %s", channel->Number(), channel->ToText()); Reply(250, "%d %s", channel->Number(), *channel->ToText());
else else
Reply(501, "Channel \"%s\" not defined", Option); Reply(501, "Channel \"%s\" not defined", Option);
} }
@ -685,7 +685,7 @@ void cSVDRP::CmdLSTC(const char *Option)
if (channel) { if (channel) {
if (strcasestr(channel->Name(), Option)) { if (strcasestr(channel->Name(), Option)) {
if (next) if (next)
Reply(-250, "%d %s", next->Number(), next->ToText()); Reply(-250, "%d %s", next->Number(), *next->ToText());
next = channel; next = channel;
} }
} }
@ -696,7 +696,7 @@ void cSVDRP::CmdLSTC(const char *Option)
i = channel->Number() + 1; i = channel->Number() + 1;
} }
if (next) if (next)
Reply(250, "%d %s", next->Number(), next->ToText()); Reply(250, "%d %s", next->Number(), *next->ToText());
else else
Reply(501, "Channel \"%s\" not defined", Option); Reply(501, "Channel \"%s\" not defined", Option);
} }
@ -706,7 +706,7 @@ void cSVDRP::CmdLSTC(const char *Option)
while (i <= Channels.MaxNumber()) { while (i <= Channels.MaxNumber()) {
cChannel *channel = Channels.GetByNumber(i, 1); cChannel *channel = Channels.GetByNumber(i, 1);
if (channel) if (channel)
Reply(channel->Number() < Channels.MaxNumber() ? -250 : 250, "%d %s", channel->Number(), channel->ToText()); Reply(channel->Number() < Channels.MaxNumber() ? -250 : 250, "%d %s", channel->Number(), *channel->ToText());
else else
Reply(501, "Channel \"%d\" not found", i); Reply(501, "Channel \"%d\" not found", i);
i = channel->Number() + 1; i = channel->Number() + 1;
@ -830,7 +830,7 @@ void cSVDRP::CmdLSTT(const char *Option)
if (isnumber(Option)) { if (isnumber(Option)) {
cTimer *timer = Timers.Get(strtol(Option, NULL, 10) - 1); cTimer *timer = Timers.Get(strtol(Option, NULL, 10) - 1);
if (timer) if (timer)
Reply(250, "%d %s", timer->Index() + 1, timer->ToText()); Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
else else
Reply(501, "Timer \"%s\" not defined", Option); Reply(501, "Timer \"%s\" not defined", Option);
} }
@ -841,7 +841,7 @@ void cSVDRP::CmdLSTT(const char *Option)
for (int i = 0; i < Timers.Count(); i++) { for (int i = 0; i < Timers.Count(); i++) {
cTimer *timer = Timers.Get(i); cTimer *timer = Timers.Get(i);
if (timer) if (timer)
Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText()); Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, *timer->ToText());
else else
Reply(501, "Timer \"%d\" not found", i + 1); Reply(501, "Timer \"%d\" not found", i + 1);
} }
@ -879,8 +879,8 @@ void cSVDRP::CmdMODC(const char *Option)
*channel = ch; *channel = ch;
Channels.ReNumber(); Channels.ReNumber();
Channels.SetModified(true); Channels.SetModified(true);
isyslog("modifed channel %d %s", channel->Number(), channel->ToText()); isyslog("modifed channel %d %s", channel->Number(), *channel->ToText());
Reply(250, "%d %s", channel->Number(), channel->ToText()); Reply(250, "%d %s", channel->Number(), *channel->ToText());
} }
else else
Reply(501, "Channel settings are not unique"); Reply(501, "Channel settings are not unique");
@ -919,7 +919,7 @@ void cSVDRP::CmdMODT(const char *Option)
*timer = t; *timer = t;
Timers.SetModified(); Timers.SetModified();
isyslog("timer %d modified (%s)", timer->Index() + 1, timer->HasFlags(tfActive) ? "active" : "inactive"); isyslog("timer %d modified (%s)", timer->Index() + 1, timer->HasFlags(tfActive) ? "active" : "inactive");
Reply(250, "%d %s", timer->Index() + 1, timer->ToText()); Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
} }
else else
Reply(501, "Timer \"%d\" not defined", n); Reply(501, "Timer \"%d\" not defined", n);
@ -954,8 +954,8 @@ void cSVDRP::CmdNEWC(const char *Option)
Channels.Add(channel); Channels.Add(channel);
Channels.ReNumber(); Channels.ReNumber();
Channels.SetModified(true); Channels.SetModified(true);
isyslog("new channel %d %s", channel->Number(), channel->ToText()); isyslog("new channel %d %s", channel->Number(), *channel->ToText());
Reply(250, "%d %s", channel->Number(), channel->ToText()); Reply(250, "%d %s", channel->Number(), *channel->ToText());
} }
else else
Reply(501, "Channel settings are not unique"); Reply(501, "Channel settings are not unique");
@ -977,11 +977,11 @@ void cSVDRP::CmdNEWT(const char *Option)
Timers.Add(timer); Timers.Add(timer);
Timers.SetModified(); Timers.SetModified();
isyslog("timer %d added", timer->Index() + 1); isyslog("timer %d added", timer->Index() + 1);
Reply(250, "%d %s", timer->Index() + 1, timer->ToText()); Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
return; return;
} }
else else
Reply(550, "Timer already defined: %d %s", t->Index() + 1, t->ToText()); Reply(550, "Timer already defined: %d %s", t->Index() + 1, *t->ToText());
} }
else else
Reply(501, "Error in timer settings"); Reply(501, "Error in timer settings");
@ -998,7 +998,7 @@ void cSVDRP::CmdNEXT(const char *Option)
time_t Start = t->StartTime(); time_t Start = t->StartTime();
int Number = t->Index() + 1; int Number = t->Index() + 1;
if (!*Option) if (!*Option)
Reply(250, "%d %s", Number, *cCtime(Start)); Reply(250, "%d %s", Number, *TimeToString(Start));
else if (strcasecmp(Option, "ABS") == 0) else if (strcasecmp(Option, "ABS") == 0)
Reply(250, "%d %ld", Number, Start); Reply(250, "%d %ld", Number, Start);
else if (strcasecmp(Option, "REL") == 0) else if (strcasecmp(Option, "REL") == 0)
@ -1057,7 +1057,7 @@ void cSVDRP::CmdUPDT(const char *Option)
isyslog("timer %d added", timer->Index() + 1); isyslog("timer %d added", timer->Index() + 1);
} }
Timers.SetModified(); Timers.SetModified();
Reply(250, "%d %s", timer->Index() + 1, timer->ToText()); Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
return; return;
} }
else else
@ -1151,7 +1151,7 @@ bool cSVDRP::Process(void)
char buffer[BUFSIZ]; char buffer[BUFSIZ];
gethostname(buffer, sizeof(buffer)); gethostname(buffer, sizeof(buffer));
time_t now = time(NULL); time_t now = time(NULL);
Reply(220, "%s SVDRP VideoDiskRecorder %s; %s", buffer, VDRVERSION, *cCtime(now)); Reply(220, "%s SVDRP VideoDiskRecorder %s; %s", buffer, VDRVERSION, *TimeToString(now));
} }
if (NewConnection) if (NewConnection)
lastActivity = time(NULL); lastActivity = time(NULL);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: themes.c 1.4 2004/12/19 15:49:49 kls Exp $ * $Id: themes.c 1.5 2004/12/24 17:00:41 kls Exp $
*/ */
#include "themes.h" #include "themes.h"
@ -248,7 +248,7 @@ bool cThemes::Load(const char *SkinName)
while ((e = d.Next()) != NULL) { while ((e = d.Next()) != NULL) {
if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
if (strstr(e->d_name, SkinName) == e->d_name && e->d_name[strlen(SkinName)] == '-') { if (strstr(e->d_name, SkinName) == e->d_name && e->d_name[strlen(SkinName)] == '-') {
cAddDirectory FileName(themesDirectory, e->d_name); cString FileName = AddDirectory(themesDirectory, e->d_name);
cTheme Theme; cTheme Theme;
if (Theme.Load(*FileName, true)) { if (Theme.Load(*FileName, true)) {
names = (char **)realloc(names, (numThemes + 1) * sizeof(char *)); names = (char **)realloc(names, (numThemes + 1) * sizeof(char *));

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: timers.c 1.20 2004/12/19 14:11:29 kls Exp $ * $Id: timers.c 1.21 2004/12/26 12:35:33 kls Exp $
*/ */
#include "timers.h" #include "timers.h"
@ -19,8 +19,6 @@
// -- cTimer ----------------------------------------------------------------- // -- cTimer -----------------------------------------------------------------
char *cTimer::buffer = NULL;
cTimer::cTimer(bool Instant, bool Pause) cTimer::cTimer(bool Instant, bool Pause)
{ {
startTime = stopTime = 0; startTime = stopTime = 0;
@ -106,12 +104,12 @@ int cTimer::Compare(const cListObject &ListObject) const
return r; return r;
} }
const char *cTimer::ToText(bool UseChannelID) cString cTimer::ToText(bool UseChannelID)
{ {
free(buffer); char *buffer;
strreplace(file, ':', '|'); strreplace(file, ':', '|');
strreplace(summary, '\n', '|'); strreplace(summary, '\n', '|');
asprintf(&buffer, "%d:%s:%s:%04d:%04d:%d:%d:%s:%s\n", flags, UseChannelID ? Channel()->GetChannelID().ToString() : *cItoa(Channel()->Number()), PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : ""); asprintf(&buffer, "%d:%s:%s:%04d:%04d:%d:%d:%s:%s\n", flags, UseChannelID ? *Channel()->GetChannelID().ToString() : *itoa(Channel()->Number()), *PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
strreplace(summary, '|', '\n'); strreplace(summary, '|', '\n');
strreplace(file, '|', ':'); strreplace(file, '|', ':');
return buffer; return buffer;
@ -162,10 +160,10 @@ int cTimer::ParseDay(const char *s, time_t *FirstDay)
return d; return d;
} }
const char *cTimer::PrintDay(int d, time_t FirstDay) cString cTimer::PrintDay(int d, time_t FirstDay)
{ {
#define DAYBUFFERSIZE 32 #define DAYBUFFERSIZE 32
static char buffer[DAYBUFFERSIZE]; char buffer[DAYBUFFERSIZE];
if ((d & 0x80000000) != 0) { if ((d & 0x80000000) != 0) {
char *b = buffer; char *b = buffer;
const char *w = tr("MTWTFSS"); const char *w = tr("MTWTFSS");
@ -186,12 +184,12 @@ const char *cTimer::PrintDay(int d, time_t FirstDay)
return buffer; return buffer;
} }
const char *cTimer::PrintFirstDay(void) cString cTimer::PrintFirstDay(void)
{ {
if (firstday) { if (firstday) {
const char *s = PrintDay(day, firstday); cString s = PrintDay(day, firstday);
if (strlen(s) == 18) if (strlen(s) == 18)
return s + 8; return *s + 8;
} }
return ""; // not NULL, so the caller can always use the result return ""; // not NULL, so the caller can always use the result
} }
@ -248,7 +246,7 @@ bool cTimer::Parse(const char *s)
bool cTimer::Save(FILE *f) bool cTimer::Save(FILE *f)
{ {
return fprintf(f, ToText(true)) > 0; return fprintf(f, "%s", *ToText(true)) > 0;
} }
bool cTimer::IsSingleEvent(void) const bool cTimer::IsSingleEvent(void) const
@ -397,8 +395,8 @@ void cTimer::SetEvent(const cEvent *Event)
if (Event) { if (Event) {
char vpsbuf[64] = ""; char vpsbuf[64] = "";
if (Event->Vps()) if (Event->Vps())
sprintf(vpsbuf, "(VPS: %s) ", Event->GetVpsString()); sprintf(vpsbuf, "(VPS: %s) ", *Event->GetVpsString());
isyslog("timer %d (%d %04d-%04d '%s') set to event %s %s-%s %s'%s'", Index() + 1, Channel()->Number(), start, stop, file, Event->GetDateString(), Event->GetTimeString(), Event->GetEndTimeString(), vpsbuf, Event->Title()); isyslog("timer %d (%d %04d-%04d '%s') set to event %s %s-%s %s'%s'", Index() + 1, Channel()->Number(), start, stop, file, *Event->GetDateString(), *Event->GetTimeString(), *Event->GetEndTimeString(), vpsbuf, Event->Title());
} }
else else
isyslog("timer %d (%d %04d-%04d '%s') set to no event", Index() + 1, Channel()->Number(), start, stop, file); isyslog("timer %d (%d %04d-%04d '%s') set to no event", Index() + 1, Channel()->Number(), start, stop, file);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: timers.h 1.12 2004/11/21 12:37:33 kls Exp $ * $Id: timers.h 1.13 2004/12/26 12:21:29 kls Exp $
*/ */
#ifndef __TIMERS_H #ifndef __TIMERS_H
@ -27,7 +27,6 @@ class cTimer : public cListObject {
friend class cMenuEditTimer; friend class cMenuEditTimer;
private: private:
mutable time_t startTime, stopTime; mutable time_t startTime, stopTime;
static char *buffer;
bool recording, pending, inVpsMargin; bool recording, pending, inVpsMargin;
int flags; int flags;
cChannel *channel; cChannel *channel;
@ -59,7 +58,7 @@ public:
const char *File(void) { return file; } const char *File(void) { return file; }
time_t FirstDay(void) { return firstday; } time_t FirstDay(void) { return firstday; }
const char *Summary(void) { return summary; } const char *Summary(void) { return summary; }
const char *ToText(bool UseChannelID = false); cString ToText(bool UseChannelID = false);
const cEvent *Event(void) { return event; } const cEvent *Event(void) { return event; }
bool Parse(const char *s); bool Parse(const char *s);
bool Save(FILE *f); bool Save(FILE *f);
@ -85,10 +84,10 @@ public:
bool HasFlags(int Flags) const; bool HasFlags(int Flags) const;
void Skip(void); void Skip(void);
void OnOff(void); void OnOff(void);
const char *PrintFirstDay(void); cString PrintFirstDay(void);
static int TimeToInt(int t); static int TimeToInt(int t);
static int ParseDay(const char *s, time_t *FirstDay = NULL); static int ParseDay(const char *s, time_t *FirstDay = NULL);
static const char *PrintDay(int d, time_t FirstDay = 0); static cString PrintDay(int d, time_t FirstDay = 0);
}; };
class cTimers : public cConfig<cTimer> { class cTimers : public cConfig<cTimer> {

146
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 1.85 2004/12/19 18:06:16 kls Exp $ * $Id: tools.c 1.86 2004/12/26 11:23:35 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -155,6 +155,29 @@ char *compactspace(char *s)
return s; return s;
} }
cString strescape(const char *s, const char *chars)
{
char *buffer;
const char *p = s;
char *t = NULL;
while (*p) {
if (strchr(chars, *p)) {
if (!t) {
buffer = MALLOC(char, 2 * strlen(s) + 1);
t = buffer + (p - s);
s = strcpy(buffer, s);
}
*t++ = '\\';
}
if (t)
*t++ = *p;
p++;
}
if (t)
*t = 0;
return s;
}
bool startswith(const char *s, const char *p) bool startswith(const char *s, const char *p)
{ {
while (*p) { while (*p) {
@ -199,6 +222,20 @@ bool isnumber(const char *s)
return true; return true;
} }
cString AddDirectory(const char *DirName, const char *FileName)
{
char *buf;
asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName);
return buf;
}
cString itoa(int n)
{
char buf[16];
snprintf(buf, sizeof(buf), "%d", n);
return buf;
}
int FreeDiskSpaceMB(const char *Directory, int *UsedMB) int FreeDiskSpaceMB(const char *Directory, int *UsedMB)
{ {
if (UsedMB) if (UsedMB)
@ -450,106 +487,63 @@ uint64 cTimeMs::Elapsed(void)
return Now() - begin; return Now() - begin;
} }
// --- cBufferedStringFunction ----------------------------------------------- // --- cString ---------------------------------------------------------------
cBufferedStringFunction::cBufferedStringFunction(void) cString::cString(const char *S)
{ {
buffer = NULL; s = S ? strdup(S) : NULL;
result = ""; // makes sure dereferencing it doesn't hurt
} }
cBufferedStringFunction::~cBufferedStringFunction() cString::~cString()
{ {
free(buffer); free(s);
} }
// --- cAddDirectory --------------------------------------------------------- cString &cString::operator=(const cString &String)
cAddDirectory::cAddDirectory(const char *DirName, const char *FileName)
{ {
asprintf(&buffer, "%s/%s", DirName && *DirName ? DirName : ".", FileName); s = String.s ? strdup(String.s) : NULL;
result = buffer; return *this;
} }
// --- cStrEscape ------------------------------------------------------------ cString WeekDayName(int WeekDay)
cStrEscape::cStrEscape(const char *s, const char *chars)
{
buffer = NULL;
const char *p = s;
char *t = NULL;
while (*p) {
if (strchr(chars, *p)) {
if (!t) {
buffer = (char *)realloc(buffer, 2 * strlen(s) + 1);
t = buffer + (p - s);
s = strcpy(buffer, s);
}
*t++ = '\\';
}
if (t)
*t++ = *p;
p++;
}
if (t)
*t = 0;
result = s;
}
// --- cCtime ----------------------------------------------------------------
cCtime::cCtime(time_t Time)
{
if (ctime_r(&Time, buffer)) {
buffer[strlen(buffer) - 1] = 0; // strip trailing newline
result = buffer;
}
}
// --- cItoa -----------------------------------------------------------------
cItoa::cItoa(int n)
{
snprintf(buffer, sizeof(buffer), "%d", n);
result = buffer;
}
// --- cWeekDayName ----------------------------------------------------------
cWeekDayName::cWeekDayName(int WeekDay)
{
WeekDayName(WeekDay);
}
cWeekDayName::cWeekDayName(time_t t)
{
struct tm tm_r;
WeekDayName(localtime_r(&t, &tm_r)->tm_wday);
}
void cWeekDayName::WeekDayName(int WeekDay)
{ {
char buffer[4];
WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with monday==0! WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with monday==0!
if (0 <= WeekDay && WeekDay <= 6) { if (0 <= WeekDay && WeekDay <= 6) {
const char *day = tr("MonTueWedThuFriSatSun"); const char *day = tr("MonTueWedThuFriSatSun");
day += WeekDay * 3; day += WeekDay * 3;
strn0cpy(buffer, day, sizeof(buffer)); strn0cpy(buffer, day, sizeof(buffer));
result = buffer; return buffer;
} }
else else
result = "???"; return "???";
} }
// --- cDayDateTime ---------------------------------------------------------- cString WeekDayName(time_t t)
cDayDateTime::cDayDateTime(time_t t)
{ {
struct tm tm_r;
return WeekDayName(localtime_r(&t, &tm_r)->tm_wday);
}
cString DayDateTime(time_t t)
{
char buffer[32];
if (t == 0) if (t == 0)
time(&t); time(&t);
struct tm tm_r; struct tm tm_r;
tm *tm = localtime_r(&t, &tm_r); tm *tm = localtime_r(&t, &tm_r);
snprintf(buffer, sizeof(buffer), "%s %2d.%02d %02d:%02d", *cWeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min); snprintf(buffer, sizeof(buffer), "%s %2d.%02d %02d:%02d", *WeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min);
result = buffer; return buffer;
}
cString TimeToString(time_t t)
{
char buffer[32];
if (ctime_r(&t, buffer)) {
buffer[strlen(buffer) - 1] = 0; // strip trailing newline
return buffer;
}
return "???";
} }
// --- cReadLine ------------------------------------------------------------- // --- cReadLine -------------------------------------------------------------

72
tools.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.h 1.61 2004/12/19 18:06:10 kls Exp $ * $Id: tools.h 1.62 2004/12/26 10:26:09 kls Exp $
*/ */
#ifndef __TOOLS_H #ifndef __TOOLS_H
@ -57,6 +57,17 @@ template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
#define BCDCHARTOINT(x) (10 * ((x & 0xF0) >> 4) + (x & 0xF)) #define BCDCHARTOINT(x) (10 * ((x & 0xF0) >> 4) + (x & 0xF))
int BCD2INT(int x); int BCD2INT(int x);
class cString {
private:
char *s;
public:
cString(const char *S = NULL);
virtual ~cString();
operator const char * () const { return s; } // for use in (const char *) context
const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.)
cString &operator=(const cString &String);
};
ssize_t safe_read(int filedes, void *buffer, size_t size); ssize_t safe_read(int filedes, void *buffer, size_t size);
ssize_t safe_write(int filedes, const void *buffer, size_t size); ssize_t safe_write(int filedes, const void *buffer, size_t size);
void writechar(int filedes, char c); void writechar(int filedes, char c);
@ -67,11 +78,14 @@ char *strreplace(char *s, const char *s1, const char *s2); ///< re-allocates 's'
char *skipspace(const char *s); char *skipspace(const char *s);
char *stripspace(char *s); char *stripspace(char *s);
char *compactspace(char *s); char *compactspace(char *s);
cString strescape(const char *s, const char *chars);
bool startswith(const char *s, const char *p); bool startswith(const char *s, const char *p);
bool endswith(const char *s, const char *p); bool endswith(const char *s, const char *p);
bool isempty(const char *s); bool isempty(const char *s);
int numdigits(int n); int numdigits(int n);
bool isnumber(const char *s); bool isnumber(const char *s);
cString itoa(int n);
cString AddDirectory(const char *DirName, const char *FileName);
int FreeDiskSpaceMB(const char *Directory, int *UsedMB = NULL); int FreeDiskSpaceMB(const char *Directory, int *UsedMB = NULL);
bool DirectoryOk(const char *DirName, bool LogErrors = false); bool DirectoryOk(const char *DirName, bool LogErrors = false);
bool MakeDirs(const char *FileName, bool IsDirectory = false); bool MakeDirs(const char *FileName, bool IsDirectory = false);
@ -80,6 +94,10 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false);
char *ReadLink(const char *FileName); char *ReadLink(const char *FileName);
bool SpinUpDisk(const char *FileName); bool SpinUpDisk(const char *FileName);
time_t LastModifiedTime(const char *FileName); time_t LastModifiedTime(const char *FileName);
cString WeekDayName(int WeekDay);
cString WeekDayName(time_t t);
cString DayDateTime(time_t t = 0);
cString TimeToString(time_t t);
class cTimeMs { class cTimeMs {
private: private:
@ -92,58 +110,6 @@ public:
uint64 Elapsed(void); uint64 Elapsed(void);
}; };
class cBufferedStringFunction {
protected:
char *buffer;
const char *result;
public:
cBufferedStringFunction(void);
virtual ~cBufferedStringFunction();
const char * operator * () { return result; }
};
template<int size> class cBufferedStringFunctionFix : public cBufferedStringFunction {
protected:
char buffer[size];
const char *result;
public:
cBufferedStringFunctionFix(void) { result = ""; } // makes sure dereferencing it doesn't hurt
const char * operator * () { return result; }
};
class cAddDirectory : public cBufferedStringFunction {
public:
cAddDirectory(const char *DirName, const char *FileName);
};
class cStrEscape : public cBufferedStringFunction {
public:
cStrEscape(const char *s, const char *chars);
};
class cCtime : public cBufferedStringFunctionFix<32> {
public:
cCtime(time_t Time);
};
class cItoa : public cBufferedStringFunctionFix<16> {
public:
cItoa(int n);
};
class cWeekDayName : public cBufferedStringFunctionFix<4> {
private:
void WeekDayName(int WeekDay);
public:
cWeekDayName(int WeekDay);
cWeekDayName(time_t t);
};
class cDayDateTime : public cBufferedStringFunctionFix<32> {
public:
cDayDateTime(time_t t = 0);
};
class cReadLine { class cReadLine {
private: private:
char buffer[MAXPARSEBUFFER]; char buffer[MAXPARSEBUFFER];

32
vdr.c
View File

@ -22,7 +22,7 @@
* *
* The project's page is at http://www.cadsoft.de/vdr * The project's page is at http://www.cadsoft.de/vdr
* *
* $Id: vdr.c 1.195 2004/12/19 15:28:34 kls Exp $ * $Id: vdr.c 1.196 2004/12/26 10:30:30 kls Exp $
*/ */
#include <getopt.h> #include <getopt.h>
@ -384,19 +384,19 @@ int main(int argc, char *argv[])
ConfigDirectory = VideoDirectory; ConfigDirectory = VideoDirectory;
cPlugin::SetConfigDirectory(ConfigDirectory); cPlugin::SetConfigDirectory(ConfigDirectory);
cThemes::SetThemesDirectory(*cAddDirectory(ConfigDirectory, "themes")); cThemes::SetThemesDirectory(AddDirectory(ConfigDirectory, "themes"));
Setup.Load(*cAddDirectory(ConfigDirectory, "setup.conf")); Setup.Load(AddDirectory(ConfigDirectory, "setup.conf"));
if (!(Sources.Load(*cAddDirectory(ConfigDirectory, "sources.conf"), true, true) && if (!(Sources.Load(AddDirectory(ConfigDirectory, "sources.conf"), true, true) &&
Diseqcs.Load(*cAddDirectory(ConfigDirectory, "diseqc.conf"), true, Setup.DiSEqC) && Diseqcs.Load(AddDirectory(ConfigDirectory, "diseqc.conf"), true, Setup.DiSEqC) &&
Channels.Load(*cAddDirectory(ConfigDirectory, "channels.conf"), false, true) && Channels.Load(AddDirectory(ConfigDirectory, "channels.conf"), false, true) &&
Timers.Load(*cAddDirectory(ConfigDirectory, "timers.conf")) && Timers.Load(AddDirectory(ConfigDirectory, "timers.conf")) &&
Commands.Load(*cAddDirectory(ConfigDirectory, "commands.conf"), true) && Commands.Load(AddDirectory(ConfigDirectory, "commands.conf"), true) &&
RecordingCommands.Load(*cAddDirectory(ConfigDirectory, "reccmds.conf"), true) && RecordingCommands.Load(AddDirectory(ConfigDirectory, "reccmds.conf"), true) &&
SVDRPhosts.Load(*cAddDirectory(ConfigDirectory, "svdrphosts.conf"), true) && SVDRPhosts.Load(AddDirectory(ConfigDirectory, "svdrphosts.conf"), true) &&
CaDefinitions.Load(*cAddDirectory(ConfigDirectory, "ca.conf"), true) && CaDefinitions.Load(AddDirectory(ConfigDirectory, "ca.conf"), true) &&
Keys.Load(*cAddDirectory(ConfigDirectory, "remote.conf")) && Keys.Load(AddDirectory(ConfigDirectory, "remote.conf")) &&
KeyMacros.Load(*cAddDirectory(ConfigDirectory, "keymacros.conf"), true) KeyMacros.Load(AddDirectory(ConfigDirectory, "keymacros.conf"), true)
)) ))
EXIT(2); EXIT(2);
@ -412,7 +412,7 @@ int main(int argc, char *argv[])
} }
else if (*EpgDataFileName != '/' && *EpgDataFileName != '.') else if (*EpgDataFileName != '/' && *EpgDataFileName != '.')
EpgDirectory = VideoDirectory; EpgDirectory = VideoDirectory;
cSchedules::SetEpgDataFileName(*cAddDirectory(EpgDirectory, EpgDataFileName)); cSchedules::SetEpgDataFileName(AddDirectory(EpgDirectory, EpgDataFileName));
cSchedules::Read(); cSchedules::Read();
} }
@ -870,7 +870,7 @@ int main(int argc, char *argv[])
if (!Next || Delta > Setup.MinEventTimeout * 60 || ForceShutdown) { if (!Next || Delta > Setup.MinEventTimeout * 60 || ForceShutdown) {
ForceShutdown = false; ForceShutdown = false;
if (timer) if (timer)
dsyslog("next timer event at %s", *cCtime(Next)); dsyslog("next timer event at %s", *TimeToString(Next));
if (WatchdogTimeout > 0) if (WatchdogTimeout > 0)
signal(SIGALRM, SIG_IGN); signal(SIGALRM, SIG_IGN);
if (Interface->Confirm(tr("Press any key to cancel shutdown"), UserShutdown ? 5 : SHUTDOWNWAIT, true)) { if (Interface->Confirm(tr("Press any key to cancel shutdown"), UserShutdown ? 5 : SHUTDOWNWAIT, true)) {
@ -878,7 +878,7 @@ int main(int argc, char *argv[])
const char *File = timer ? timer->File() : ""; const char *File = timer ? timer->File() : "";
Delta = Next - time(NULL); // compensates for Confirm() timeout Delta = Next - time(NULL); // compensates for Confirm() timeout
char *cmd; char *cmd;
asprintf(&cmd, "%s %ld %ld %d \"%s\" %d", Shutdown, Next, Delta, Channel, *cStrEscape(File, "\"$"), UserShutdown); asprintf(&cmd, "%s %ld %ld %d \"%s\" %d", Shutdown, Next, Delta, Channel, *strescape(File, "\"$"), UserShutdown);
isyslog("executing '%s'", cmd); isyslog("executing '%s'", cmd);
SystemExec(cmd); SystemExec(cmd);
free(cmd); free(cmd);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: videodir.c 1.10 2003/08/02 13:43:28 kls Exp $ * $Id: videodir.c 1.11 2004/12/26 11:52:12 kls Exp $
*/ */
#include "videodir.h" #include "videodir.h"
@ -197,13 +197,10 @@ int VideoDiskSpace(int *FreeMB, int *UsedMB)
return (free + used) ? used * 100 / (free + used) : 0; return (free + used) ? used * 100 / (free + used) : 0;
} }
const char *PrefixVideoFileName(const char *FileName, char Prefix) cString PrefixVideoFileName(const char *FileName, char Prefix)
{ {
static char *PrefixedName = NULL; char PrefixedName[strlen(FileName) + 2];
if (!PrefixedName || strlen(PrefixedName) <= strlen(FileName))
PrefixedName = (char *)realloc(PrefixedName, strlen(FileName) + 2);
if (PrefixedName) {
const char *p = FileName + strlen(FileName); // p points at the terminating 0 const char *p = FileName + strlen(FileName); // p points at the terminating 0
int n = 2; int n = 2;
while (p-- > FileName && n > 0) { while (p-- > FileName && n > 0) {
@ -217,7 +214,6 @@ const char *PrefixVideoFileName(const char *FileName, char Prefix)
} }
} }
} }
}
return NULL; return NULL;
} }

View File

@ -4,13 +4,14 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: videodir.h 1.4 2002/01/27 12:37:20 kls Exp $ * $Id: videodir.h 1.5 2004/12/26 11:52:56 kls Exp $
*/ */
#ifndef __VIDEODIR_H #ifndef __VIDEODIR_H
#define __VIDEODIR_H #define __VIDEODIR_H
#include <stdlib.h> #include <stdlib.h>
#include "tools.h"
extern const char *VideoDirectory; extern const char *VideoDirectory;
@ -20,7 +21,7 @@ bool RenameVideoFile(const char *OldName, const char *NewName);
bool RemoveVideoFile(const char *FileName); bool RemoveVideoFile(const char *FileName);
bool VideoFileSpaceAvailable(int SizeMB); bool VideoFileSpaceAvailable(int SizeMB);
int VideoDiskSpace(int *FreeMB = NULL, int *UsedMB = NULL); // returns the used disk space in percent int VideoDiskSpace(int *FreeMB = NULL, int *UsedMB = NULL); // returns the used disk space in percent
const char *PrefixVideoFileName(const char *FileName, char Prefix); cString PrefixVideoFileName(const char *FileName, char Prefix);
void RemoveEmptyVideoDirectories(void); void RemoveEmptyVideoDirectories(void);
#endif //__VIDEODIR_H #endif //__VIDEODIR_H