From 286af66cfb787b76ee7289c920a75a3dd21ce795 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 26 Dec 2004 12:45:22 +0100 Subject: [PATCH] Made several functions threadsafe (cont'd) --- HISTORY | 39 ++++++-- PLUGINS/src/skincurses/skincurses.c | 12 +-- PLUGINS/src/sky/sky.c | 4 +- channels.c | 38 ++++---- channels.h | 13 ++- dvbplayer.c | 4 +- eit.c | 6 +- epg.c | 31 +++--- epg.h | 10 +- menu.c | 20 ++-- recording.c | 26 +++-- recording.h | 8 +- skinclassic.c | 14 +-- skins.h | 4 +- skinsttng.c | 18 ++-- sources.c | 6 +- sources.h | 4 +- svdrp.c | 34 +++---- themes.c | 4 +- timers.c | 26 +++-- timers.h | 9 +- tools.c | 146 +++++++++++++--------------- tools.h | 72 ++++---------- vdr.c | 32 +++--- videodir.c | 32 +++--- videodir.h | 5 +- 26 files changed, 295 insertions(+), 322 deletions(-) diff --git a/HISTORY b/HISTORY index 48e36e25..09f602f3 100644 --- a/HISTORY +++ b/HISTORY @@ -3160,7 +3160,7 @@ Video Disk Recorder Revision History right day of week for timers in the future. - 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 for reporting this one). @@ -3215,12 +3215,37 @@ Video Disk Recorder Revision History the actual buffering. In particular these are: readdir() -> cReadDir readline() -> cReadLine - strescape() -> cStrEscape - AddDirectory() -> cAddDirectory - ctime() -> cCtime - itoa() -> cItoa - WeekDayName() -> cWeekDayName - DayDateTime() -> cDayDateTime +- Several formerly non-threadsafe functions now have a return type of cString: + cChannel::ToText() + tChannelID::ToString() + cEvent::GetDateString() + cEvent::GetTimeString() + 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. - Replaced time_ms() with a threadsafe and non-overflowing cTimeMs (thanks to Rainer Zocholl for pointing out this problem). diff --git a/PLUGINS/src/skincurses/skincurses.c b/PLUGINS/src/skincurses/skincurses.c index e2b218da..eeae1ef0 100644 --- a/PLUGINS/src/skincurses/skincurses.c +++ b/PLUGINS/src/skincurses/skincurses.c @@ -3,7 +3,7 @@ * * 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 @@ -11,7 +11,7 @@ #include #include -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 *MAINMENUENTRY = NULL; @@ -252,7 +252,7 @@ void cSkinCursesDisplayChannel::SetMessage(eMessageType Type, const char *Text) void cSkinCursesDisplayChannel::Flush(void) { if (!message) { - const char *date = DayDateTime(); + cString date = DayDateTime(); osd->DrawText(OsdWidth - strlen(date), 0, date, clrWhite, clrBackground, &Font); } osd->Flush(); @@ -382,11 +382,11 @@ void cSkinCursesDisplayMenu::SetEvent(const cEvent *Event) int y = 2; cTextScroller ts; 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); if (Event->Vps() && Event->Vps() != Event->StartTime()) { char *buffer; - asprintf(&buffer, " VPS: %s", Event->GetVpsString()); + asprintf(&buffer, " VPS: %s", *Event->GetVpsString()); osd->DrawText(OsdWidth - strlen(buffer), y, buffer, clrBlack, clrYellow, &Font); free(buffer); } @@ -418,7 +418,7 @@ void cSkinCursesDisplayMenu::SetText(const char *Text, bool FixedFont) void cSkinCursesDisplayMenu::Flush(void) { - const char *date = DayDateTime(); + cString date = DayDateTime(); osd->DrawText(OsdWidth - strlen(date) - 2, 0, date, clrBlack, clrCyan, &Font); osd->Flush(); } diff --git a/PLUGINS/src/sky/sky.c b/PLUGINS/src/sky/sky.c index 4e934f73..bf4fa428 100644 --- a/PLUGINS/src/sky/sky.c +++ b/PLUGINS/src/sky/sky.c @@ -3,7 +3,7 @@ * * 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 @@ -273,7 +273,7 @@ bool cPluginSky::Initialize(void) // Initialize any background activities the plugin shall perform. const char *ConfigDir = ConfigDirectory(Name()); if (ConfigDir) { - if (SkyChannels.Load(*cAddDirectory(ConfigDir, "channels.conf.sky"), true)) { + if (SkyChannels.Load(AddDirectory(ConfigDir, "channels.conf.sky"), true)) { new cDigiboxDevice; return true; } diff --git a/channels.c b/channels.c index 67949e24..9403ef52 100644 --- a/channels.c +++ b/channels.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -146,10 +146,10 @@ tChannelID tChannelID::FromString(const char *s) return tChannelID::InvalidID; } -const char *tChannelID::ToString(void) +cString tChannelID::ToString(void) { - static char buffer[256]; - snprintf(buffer, sizeof(buffer), rid ? "%s-%d-%d-%d-%d" : "%s-%d-%d-%d", cSource::ToString(source), nid, tid, sid, rid); + char buffer[256]; + snprintf(buffer, sizeof(buffer), rid ? "%s-%d-%d-%d-%d" : "%s-%d-%d-%d", *cSource::ToString(source), nid, tid, sid, rid); return buffer; } @@ -162,8 +162,6 @@ tChannelID &tChannelID::ClrPolarization(void) // -- cChannel --------------------------------------------------------------- -char *cChannel::buffer = NULL; - cChannel::cChannel(void) { 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 (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; 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 (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; 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 (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; 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; } -const char *cChannel::ParametersToString(void) const +cString cChannel::ParametersToString(void) const { - char type = *cSource::ToString(source); + char type = **cSource::ToString(source); if (isdigit(type)) type = 'S'; #define ST(s) if (strchr(s, type)) - static char buffer[64]; + char buffer[64]; char *q = buffer; *q = 0; ST(" S ") q += sprintf(q, "%c", polarization); @@ -600,7 +598,7 @@ bool cChannel::StringToParameters(const char *s) 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 *q = FullName; @@ -611,7 +609,7 @@ const char *cChannel::ToText(const cChannel *Channel) q += sprintf(q, ";%s", Channel->provider); *q = 0; strreplace(FullName, ':', '|'); - free(buffer); + char *buffer; if (Channel->groupSep) { if (Channel->number) asprintf(&buffer, ":@%d %s\n", Channel->number, FullName); @@ -637,12 +635,12 @@ const char *cChannel::ToText(const cChannel *Channel) q = caidbuf; q += IntArrayToString(q, Channel->caids, 16); *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; } -const char *cChannel::ToText(void) const +cString cChannel::ToText(void) const { return ToText(this); } @@ -800,7 +798,7 @@ bool cChannel::Parse(const char *s, bool AllowNonUniqueID) bool cChannel::Save(FILE *f) { - return fprintf(f, ToText()) > 0; + return fprintf(f, "%s", *ToText()) > 0; } // -- 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) { 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); NewChannel->SetId(Nid, Tid, Sid, Rid); NewChannel->SetName(Name, ShortName, Provider); @@ -950,9 +948,9 @@ cChannel *cChannels::NewChannel(const cChannel *Transponder, const char *Name, c 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->GroupSep()) snprintf(buffer, sizeof(buffer), "%s", Channel->Name()); diff --git a/channels.h b/channels.h index a9fd18ec..3670ad36 100644 --- a/channels.h +++ b/channels.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -67,7 +67,7 @@ public: tChannelID &ClrRid(void) { rid = 0; return *this; } tChannelID &ClrPolarization(void); static tChannelID FromString(const char *s); - const char *ToString(void); + cString ToString(void); static const tChannelID InvalidID; }; @@ -87,8 +87,7 @@ class cLinkChannels : public cList { class cChannel : public cListObject { friend class cMenuEditChannel; private: - static char *buffer; - static const char *ToText(const cChannel *Channel); + static cString ToText(const cChannel *Channel); char *name; char *shortName; char *provider; @@ -124,14 +123,14 @@ private: int modification; cLinkChannels *linkChannels; cChannel *refChannel; - const char *ParametersToString(void) const; + cString ParametersToString(void) const; bool StringToParameters(const char *s); public: cChannel(void); cChannel(const cChannel &Channel); ~cChannel(); cChannel& operator= (const cChannel &Channel); - const char *ToText(void) const; + cString ToText(void) const; bool Parse(const char *s, bool AllowNonUniqueID = false); bool Save(FILE *f); const char *Name(void) const { return name; } @@ -216,6 +215,6 @@ public: extern cChannels Channels; -const char *ChannelString(const cChannel *Channel, int Number); +cString ChannelString(const cChannel *Channel, int Number); #endif //__CHANNELS_H diff --git a/dvbplayer.c b/dvbplayer.c index aa9c04de..0ec06810 100644 --- a/dvbplayer.c +++ b/dvbplayer.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -366,7 +366,7 @@ void cDvbPlayer::Action(void) readIndex = Resume(); 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; int Length = 0; diff --git a/eit.c b/eit.c index ed02cf28..3d324561 100644 --- a/eit.c +++ b/eit.c @@ -8,7 +8,7 @@ * Robert Schneider and Rolf Hakenes . * Adapted to 'libsi' for VDR 1.3.0 by Marcel Wiesweg . * - * $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" @@ -245,8 +245,8 @@ cTDT::cTDT(const u_char *Data) if (abs(sattim - loctim) > 2) { mutex.Lock(); - isyslog("System Time = %s (%ld)\n", ctime(&loctim), loctim); - isyslog("Local Time = %s (%ld)\n", ctime(&sattim), sattim); + isyslog("System Time = %s (%ld)\n", *TimeToString(loctim), loctim); + isyslog("Local Time = %s (%ld)\n", *TimeToString(sattim), sattim); if (stime(&sattim) < 0) esyslog("ERROR while setting system time: %m"); mutex.Unlock(); diff --git a/epg.c b/epg.c index 877ce24c..2ea199c2 100644 --- a/epg.c +++ b/epg.c @@ -7,7 +7,7 @@ * Original version (as used in VDR before 1.3.0) written by * Robert Schneider and Rolf Hakenes . * - * $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" @@ -66,7 +66,7 @@ void cEvent::SetRunningStatus(int RunningStatus, cChannel *Channel) { if (Channel && runningStatus != RunningStatus && (RunningStatus > SI::RunningStatusNotRunning || runningStatus > SI::RunningStatusUndefined)) 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; } @@ -119,9 +119,9 @@ bool cEvent::IsRunning(bool OrAboutToStart) const 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; tm *tm = localtime_r(&startTime, &tm_r); char *p = stpcpy(buf, WeekDayName(tm->tm_wday)); @@ -130,26 +130,26 @@ const char *cEvent::GetDateString(void) const return buf; } -const char *cEvent::GetTimeString(void) const +cString cEvent::GetTimeString(void) const { - static char buf[25]; + char buf[25]; struct tm tm_r; strftime(buf, sizeof(buf), "%R", localtime_r(&startTime, &tm_r)); 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; struct tm tm_r; strftime(buf, sizeof(buf), "%R", localtime_r(&EndTime, &tm_r)); return buf; } -const char *cEvent::GetVpsString(void) const +cString cEvent::GetVpsString(void) const { - static char buf[25]; + char buf[25]; struct tm tm_r; strftime(buf, sizeof(buf), "%d.%m %R", localtime_r(&vps, &tm_r)); return buf; @@ -179,7 +179,8 @@ bool cEvent::Read(FILE *f, cSchedule *Schedule) if (Schedule) { cEvent *Event = NULL; char *s; - while ((s = readline(f)) != NULL) { + cReadLine ReadLine; + while ((s = ReadLine.Read(f)) != NULL) { char *t = skipspace(s + 1); switch (*s) { 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); 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; switch (DumpMode) { 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) { if (Schedules) { + cReadLine ReadLine; char *s; - while ((s = readline(f)) != NULL) { + while ((s = ReadLine.Read(f)) != NULL) { if (*s == 'C') { s = skipspace(s + 1); char *p = strchr(s, ' '); @@ -698,8 +700,7 @@ const cSchedules *cSchedules::Schedules(cSchedulesLock &SchedulesLock) void cSchedules::SetEpgDataFileName(const char *FileName) { delete epgDataFileName; - if (FileName) - epgDataFileName = strdup(FileName); + epgDataFileName = FileName ? strdup(FileName) : NULL; } void cSchedules::SetModified(cSchedule *Schedule) diff --git a/epg.h b/epg.h index 3268b17c..0668c49c 100644 --- a/epg.h +++ b/epg.h @@ -7,7 +7,7 @@ * Original version (as used in VDR before 1.3.0) written by * Robert Schneider and Rolf Hakenes . * - * $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 @@ -56,10 +56,10 @@ public: time_t Seen(void) const { return seen; } bool HasTimer(void) const; bool IsRunning(bool OrAboutToStart = false) const; - const char *GetDateString(void) const; - const char *GetTimeString(void) const; - const char *GetEndTimeString(void) const; - const char *GetVpsString(void) const; + cString GetDateString(void) const; + cString GetTimeString(void) const; + cString GetEndTimeString(void) const; + cString GetVpsString(void) const; void SetEventID(u_int16_t EventID); void SetTableID(uchar TableID); void SetVersion(uchar Version); diff --git a/menu.c b/menu.c index e1629a31..0c9aaf65 100644 --- a/menu.c +++ b/menu.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -116,7 +116,7 @@ void cMenuEditSrcItem::Set(void) { if (source) { 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); free(buffer); } @@ -249,7 +249,7 @@ cMenuEditChannel::cMenuEditChannel(cChannel *Channel, bool New) void cMenuEditChannel::Setup(void) { int current = Current(); - char type = *cSource::ToString(data.source); + char type = **cSource::ToString(data.source); #define ST(s) if (strchr(s, type)) Clear(); @@ -300,7 +300,7 @@ eOSState cMenuEditChannel::ProcessKey(eKeys Key) data.name = strcpyrealloc(data.name, name); if (channel) { *channel = data; - isyslog("edited channel %d %s", channel->Number(), data.ToText()); + isyslog("edited channel %d %s", channel->Number(), *data.ToText()); state = osBack; } else { @@ -308,7 +308,7 @@ eOSState cMenuEditChannel::ProcessKey(eKeys Key) *channel = data; Channels.Add(channel); Channels.ReNumber(); - isyslog("added channel %d %s", channel->Number(), data.ToText()); + isyslog("added channel %d %s", channel->Number(), *data.ToText()); state = osUser1; } 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", !(timer->HasFlags(tfActive)) ? ' ' : timer->FirstDay() ? '!' : timer->Recording() ? '#' : '>', timer->Channel()->Number(), - timer->IsSingleEvent() ? WeekDayName(timer->StartTime()) : "", + timer->IsSingleEvent() ? *WeekDayName(timer->StartTime()) : "", timer->IsSingleEvent() ? " " : "", - timer->PrintDay(timer->Day()), + *timer->PrintDay(timer->Day()), timer->Start() / 100, timer->Start() % 100, timer->Stop() / 100, @@ -795,7 +795,7 @@ eOSState cMenuTimers::OnOff(void) RefreshCurrent(); DisplayCurrent(true); 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 isyslog("timer %d %sactivated", timer->Index() + 1, timer->HasFlags(tfActive) ? "" : "de"); Timers.SetModified(); @@ -969,7 +969,7 @@ cMenuWhatsOnItem::cMenuWhatsOnItem(const cEvent *Event, cChannel *Channel) char t = Timers.GetMatch(Event, &TimerMatch) ? (TimerMatch == tmFull) ? 'T' : 't' : ' '; char v = event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' '; 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); } @@ -1087,7 +1087,7 @@ cMenuScheduleItem::cMenuScheduleItem(const cEvent *Event) char t = Timers.GetMatch(Event, &TimerMatch) ? (TimerMatch == tmFull) ? 'T' : 't' : ' '; char v = event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' '; 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); } diff --git a/recording.c b/recording.c index aa9f6dcf..7ba93b32 100644 --- a/recording.c +++ b/recording.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -157,7 +157,7 @@ cResumeFile::cResumeFile(const char *FileName) fileName = MALLOC(char, strlen(FileName) + strlen(RESUMEFILESUFFIX) + 1); if (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 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 *p = PrefixVideoFileName(FileName(), Prefix); - if (p) { + cString p = PrefixVideoFileName(FileName(), Prefix); + if (*p) { free(fileName); fileName = strdup(p); return fileName; @@ -665,7 +665,7 @@ void cRecordings::ScanVideoDir(const char *DirName) bool cRecordings::NeedsUpdate(void) { - return lastUpdate <= LastModifiedTime(*cAddDirectory(VideoDirectory, ".update")); + return lastUpdate <= LastModifiedTime(AddDirectory(VideoDirectory, ".update")); } bool cRecordings::Load(void) @@ -704,8 +704,6 @@ void cRecordings::DelByName(const char *FileName) // --- cMark ----------------------------------------------------------------- -char *cMark::buffer = NULL; - cMark::cMark(int Position, const char *Comment) { position = Position; @@ -717,10 +715,10 @@ cMark::~cMark() free(comment); } -const char *cMark::ToText(void) +cString cMark::ToText(void) { - free(buffer); - asprintf(&buffer, "%s%s%s\n", IndexToHMSF(position, true), comment ? " " : "", comment ? comment : ""); + char *buffer; + asprintf(&buffer, "%s%s%s\n", *IndexToHMSF(position, true), comment ? " " : "", comment ? comment : ""); return buffer; } @@ -747,7 +745,7 @@ bool cMark::Save(FILE *f) bool cMarks::Load(const char *RecordingFileName) { - if (cConfig::Load(*cAddDirectory(RecordingFileName, MARKSFILESUFFIX))) { + if (cConfig::Load(AddDirectory(RecordingFileName, MARKSFILESUFFIX))) { Sort(); return true; } @@ -811,7 +809,7 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi { if (command) { char *cmd; - asprintf(&cmd, "%s %s \"%s\"", command, State, *cStrEscape(RecordingFileName, "\"$")); + asprintf(&cmd, "%s %s \"%s\"", command, State, *strescape(RecordingFileName, "\"$")); isyslog("executing '%s'", cmd); SystemExec(cmd); free(cmd); @@ -1152,9 +1150,9 @@ int cFileName::NextFile(void) // --- 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 s = (Index / FRAMESPERSEC); int m = s / 60 % 60; diff --git a/recording.h b/recording.h index 184f49ef..a0f864f3 100644 --- a/recording.h +++ b/recording.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -86,14 +86,12 @@ public: extern cRecordings Recordings; class cMark : public cListObject { -private: - static char *buffer; public: int position; char *comment; cMark(int Position = 0, const char *Comment = NULL); ~cMark(); - const char *ToText(void); + cString ToText(void); bool Parse(const char *s); bool Save(FILE *f); }; @@ -176,7 +174,7 @@ public: 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. int HMSFToIndex(const char *HMSF); // Converts the given string (format: "hh:mm:ss.ff") to an index. diff --git a/skinclassic.c b/skinclassic.c index 3b9609f3..1a14f21a 100644 --- a/skinclassic.c +++ b/skinclassic.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -141,8 +141,8 @@ void cSkinClassicDisplayChannel::SetMessage(eMessageType Type, const char *Text) void cSkinClassicDisplayChannel::Flush(void) { if (!message) { - cDayDateTime date; - osd->DrawText(osd->Width() - cFont::GetFont(fontSml)->Width(*date) - 2, 0, *date, Theme.Color(clrChannelDate), Theme.Color(clrBackground), cFont::GetFont(fontSml)); + 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->Flush(); } @@ -299,11 +299,11 @@ void cSkinClassicDisplayMenu::SetEvent(const cEvent *Event) int y = y2; cTextScroller ts; 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)); if (Event->Vps() && Event->Vps() != Event->StartTime()) { char *buffer; - asprintf(&buffer, " VPS: %s", Event->GetVpsString()); + asprintf(&buffer, " VPS: %s", *Event->GetVpsString()); const cFont *font = cFont::GetFont(fontSml); osd->DrawText(x1 - font->Width(buffer), y, buffer, Theme.Color(clrMenuEventVpsFg), Theme.Color(clrMenuEventVpsBg), font); free(buffer); @@ -338,9 +338,9 @@ void cSkinClassicDisplayMenu::SetText(const char *Text, bool FixedFont) void cSkinClassicDisplayMenu::Flush(void) { - cDayDateTime date; + cString date = DayDateTime(); 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(); } diff --git a/skins.h b/skins.h index 814780c1..c20dece0 100644 --- a/skins.h +++ b/skins.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -99,7 +99,7 @@ protected: ///< Returns the offset of the given tab from the left border of the ///< item display area. The value returned is in pixel.//XXX ncurses??? 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 ///< part can be found, NULL will be returned. public: diff --git a/skinsttng.c b/skinsttng.c index cf60ae14..844cd29f 100644 --- a/skinsttng.c +++ b/skinsttng.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -289,9 +289,9 @@ void cSkinSTTNGDisplayChannel::Flush(void) { if (withInfo) { if (!message) { - cDayDateTime date; + cString date = DayDateTime(); 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; @@ -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) { - cDayDateTime date; + cString date = DayDateTime(); const cFont *font = cFont::GetFont(fontSml); int d = 10; int d2 = d / 2; - int t4 = x4 - font->Width(*date) - 2; + int t4 = x4 - font->Width(date) - 2; int w = t4 - x3; int t0 = x3 + d2; int t1 = x3 + w / 4; @@ -533,11 +533,11 @@ void cSkinSTTNGDisplayMenu::SetEvent(const cEvent *Event) int y = y3; cTextScroller ts; 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)); if (Event->Vps() && Event->Vps() != Event->StartTime()) { char *buffer; - asprintf(&buffer, " VPS: %s", Event->GetVpsString()); + asprintf(&buffer, " VPS: %s", *Event->GetVpsString()); const cFont *font = cFont::GetFont(fontSml); osd->DrawText(x4 - font->Width(buffer), y, buffer, Theme.Color(clrMenuEventVps), frameColor, font); int yb = y + font->Height(); @@ -583,9 +583,9 @@ void cSkinSTTNGDisplayMenu::SetText(const char *Text, bool FixedFont) void cSkinSTTNGDisplayMenu::Flush(void) { if (!message) { - cDayDateTime date; + cString date = DayDateTime(); 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(); } diff --git a/sources.c b/sources.c index a9c31488..2f08debd 100644 --- a/sources.c +++ b/sources.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -32,9 +32,9 @@ bool cSource::Parse(const char *s) 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; switch (Code & st_Mask) { case stCable: *q++ = 'C'; break; diff --git a/sources.h b/sources.h index 3e9abc7f..22076ea7 100644 --- a/sources.h +++ b/sources.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -32,7 +32,7 @@ public: int Code(void) const { return code; } const char *Description(void) const { return description; } bool Parse(const char *s); - static const char *ToString(int Code); + static cString ToString(int Code); static int FromString(const char *s); static int FromData(eSourceType SourceType, int Position = 0, bool East = false); }; diff --git a/svdrp.c b/svdrp.c index 365e4a36..1981f6e8 100644 --- a/svdrp.c +++ b/svdrp.c @@ -10,7 +10,7 @@ * and interact with the Video Disk Recorder - or write a full featured * 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" @@ -673,7 +673,7 @@ void cSVDRP::CmdLSTC(const char *Option) if (isnumber(Option)) { cChannel *channel = Channels.GetByNumber(strtol(Option, NULL, 10)); if (channel) - Reply(250, "%d %s", channel->Number(), channel->ToText()); + Reply(250, "%d %s", channel->Number(), *channel->ToText()); else Reply(501, "Channel \"%s\" not defined", Option); } @@ -685,7 +685,7 @@ void cSVDRP::CmdLSTC(const char *Option) if (channel) { if (strcasestr(channel->Name(), Option)) { if (next) - Reply(-250, "%d %s", next->Number(), next->ToText()); + Reply(-250, "%d %s", next->Number(), *next->ToText()); next = channel; } } @@ -696,7 +696,7 @@ void cSVDRP::CmdLSTC(const char *Option) i = channel->Number() + 1; } if (next) - Reply(250, "%d %s", next->Number(), next->ToText()); + Reply(250, "%d %s", next->Number(), *next->ToText()); else Reply(501, "Channel \"%s\" not defined", Option); } @@ -706,7 +706,7 @@ void cSVDRP::CmdLSTC(const char *Option) while (i <= Channels.MaxNumber()) { cChannel *channel = Channels.GetByNumber(i, 1); 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 Reply(501, "Channel \"%d\" not found", i); i = channel->Number() + 1; @@ -830,7 +830,7 @@ void cSVDRP::CmdLSTT(const char *Option) if (isnumber(Option)) { cTimer *timer = Timers.Get(strtol(Option, NULL, 10) - 1); if (timer) - Reply(250, "%d %s", timer->Index() + 1, timer->ToText()); + Reply(250, "%d %s", timer->Index() + 1, *timer->ToText()); else 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++) { cTimer *timer = Timers.Get(i); 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 Reply(501, "Timer \"%d\" not found", i + 1); } @@ -879,8 +879,8 @@ void cSVDRP::CmdMODC(const char *Option) *channel = ch; Channels.ReNumber(); Channels.SetModified(true); - isyslog("modifed channel %d %s", channel->Number(), channel->ToText()); - Reply(250, "%d %s", channel->Number(), channel->ToText()); + isyslog("modifed channel %d %s", channel->Number(), *channel->ToText()); + Reply(250, "%d %s", channel->Number(), *channel->ToText()); } else Reply(501, "Channel settings are not unique"); @@ -919,7 +919,7 @@ void cSVDRP::CmdMODT(const char *Option) *timer = t; Timers.SetModified(); 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 Reply(501, "Timer \"%d\" not defined", n); @@ -954,8 +954,8 @@ void cSVDRP::CmdNEWC(const char *Option) Channels.Add(channel); Channels.ReNumber(); Channels.SetModified(true); - isyslog("new channel %d %s", channel->Number(), channel->ToText()); - Reply(250, "%d %s", channel->Number(), channel->ToText()); + isyslog("new channel %d %s", channel->Number(), *channel->ToText()); + Reply(250, "%d %s", channel->Number(), *channel->ToText()); } else Reply(501, "Channel settings are not unique"); @@ -977,11 +977,11 @@ void cSVDRP::CmdNEWT(const char *Option) Timers.Add(timer); Timers.SetModified(); 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; } 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 Reply(501, "Error in timer settings"); @@ -998,7 +998,7 @@ void cSVDRP::CmdNEXT(const char *Option) time_t Start = t->StartTime(); int Number = t->Index() + 1; if (!*Option) - Reply(250, "%d %s", Number, *cCtime(Start)); + Reply(250, "%d %s", Number, *TimeToString(Start)); else if (strcasecmp(Option, "ABS") == 0) Reply(250, "%d %ld", Number, Start); else if (strcasecmp(Option, "REL") == 0) @@ -1057,7 +1057,7 @@ void cSVDRP::CmdUPDT(const char *Option) isyslog("timer %d added", timer->Index() + 1); } Timers.SetModified(); - Reply(250, "%d %s", timer->Index() + 1, timer->ToText()); + Reply(250, "%d %s", timer->Index() + 1, *timer->ToText()); return; } else @@ -1151,7 +1151,7 @@ bool cSVDRP::Process(void) char buffer[BUFSIZ]; gethostname(buffer, sizeof(buffer)); 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) lastActivity = time(NULL); diff --git a/themes.c b/themes.c index b4bffea3..69af61ff 100644 --- a/themes.c +++ b/themes.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -248,7 +248,7 @@ bool cThemes::Load(const char *SkinName) while ((e = d.Next()) != NULL) { if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { 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; if (Theme.Load(*FileName, true)) { names = (char **)realloc(names, (numThemes + 1) * sizeof(char *)); diff --git a/timers.c b/timers.c index 5c6ba70e..96a2cc91 100644 --- a/timers.c +++ b/timers.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -19,8 +19,6 @@ // -- cTimer ----------------------------------------------------------------- -char *cTimer::buffer = NULL; - cTimer::cTimer(bool Instant, bool Pause) { startTime = stopTime = 0; @@ -106,12 +104,12 @@ int cTimer::Compare(const cListObject &ListObject) const return r; } -const char *cTimer::ToText(bool UseChannelID) +cString cTimer::ToText(bool UseChannelID) { - free(buffer); + char *buffer; strreplace(file, ':', '|'); 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(file, '|', ':'); return buffer; @@ -162,10 +160,10 @@ int cTimer::ParseDay(const char *s, time_t *FirstDay) return d; } -const char *cTimer::PrintDay(int d, time_t FirstDay) +cString cTimer::PrintDay(int d, time_t FirstDay) { #define DAYBUFFERSIZE 32 - static char buffer[DAYBUFFERSIZE]; + char buffer[DAYBUFFERSIZE]; if ((d & 0x80000000) != 0) { char *b = buffer; const char *w = tr("MTWTFSS"); @@ -186,12 +184,12 @@ const char *cTimer::PrintDay(int d, time_t FirstDay) return buffer; } -const char *cTimer::PrintFirstDay(void) +cString cTimer::PrintFirstDay(void) { if (firstday) { - const char *s = PrintDay(day, firstday); + cString s = PrintDay(day, firstday); if (strlen(s) == 18) - return s + 8; + return *s + 8; } 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) { - return fprintf(f, ToText(true)) > 0; + return fprintf(f, "%s", *ToText(true)) > 0; } bool cTimer::IsSingleEvent(void) const @@ -397,8 +395,8 @@ void cTimer::SetEvent(const cEvent *Event) if (Event) { char vpsbuf[64] = ""; if (Event->Vps()) - 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()); + 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()); } else isyslog("timer %d (%d %04d-%04d '%s') set to no event", Index() + 1, Channel()->Number(), start, stop, file); diff --git a/timers.h b/timers.h index eceb0780..7dcaf16a 100644 --- a/timers.h +++ b/timers.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -27,7 +27,6 @@ class cTimer : public cListObject { friend class cMenuEditTimer; private: mutable time_t startTime, stopTime; - static char *buffer; bool recording, pending, inVpsMargin; int flags; cChannel *channel; @@ -59,7 +58,7 @@ public: const char *File(void) { return file; } time_t FirstDay(void) { return firstday; } const char *Summary(void) { return summary; } - const char *ToText(bool UseChannelID = false); + cString ToText(bool UseChannelID = false); const cEvent *Event(void) { return event; } bool Parse(const char *s); bool Save(FILE *f); @@ -85,10 +84,10 @@ public: bool HasFlags(int Flags) const; void Skip(void); void OnOff(void); - const char *PrintFirstDay(void); + cString PrintFirstDay(void); static int TimeToInt(int t); 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 { diff --git a/tools.c b/tools.c index fb95e7df..ebe9833c 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -155,6 +155,29 @@ char *compactspace(char *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) { while (*p) { @@ -199,6 +222,20 @@ bool isnumber(const char *s) 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) { if (UsedMB) @@ -450,106 +487,63 @@ uint64 cTimeMs::Elapsed(void) return Now() - begin; } -// --- cBufferedStringFunction ----------------------------------------------- +// --- cString --------------------------------------------------------------- -cBufferedStringFunction::cBufferedStringFunction(void) +cString::cString(const char *S) { - buffer = NULL; - result = ""; // makes sure dereferencing it doesn't hurt + s = S ? strdup(S) : NULL; } -cBufferedStringFunction::~cBufferedStringFunction() +cString::~cString() { - free(buffer); + free(s); } -// --- cAddDirectory --------------------------------------------------------- - -cAddDirectory::cAddDirectory(const char *DirName, const char *FileName) +cString &cString::operator=(const cString &String) { - asprintf(&buffer, "%s/%s", DirName && *DirName ? DirName : ".", FileName); - result = buffer; + s = String.s ? strdup(String.s) : NULL; + return *this; } -// --- cStrEscape ------------------------------------------------------------ - -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) +cString WeekDayName(int WeekDay) { + char buffer[4]; WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with monday==0! if (0 <= WeekDay && WeekDay <= 6) { const char *day = tr("MonTueWedThuFriSatSun"); day += WeekDay * 3; strn0cpy(buffer, day, sizeof(buffer)); - result = buffer; + return buffer; } else - result = "???"; + return "???"; } -// --- cDayDateTime ---------------------------------------------------------- - -cDayDateTime::cDayDateTime(time_t t) +cString WeekDayName(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) time(&t); struct tm 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); - result = buffer; + 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); + 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 ------------------------------------------------------------- diff --git a/tools.h b/tools.h index 2c90ff75..a89ac1f9 100644 --- a/tools.h +++ b/tools.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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 @@ -57,6 +57,17 @@ template inline void swap(T &a, T &b) { T t = a; a = b; b = t; } #define BCDCHARTOINT(x) (10 * ((x & 0xF0) >> 4) + (x & 0xF)) 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_write(int filedes, const void *buffer, size_t size); 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 *stripspace(char *s); char *compactspace(char *s); +cString strescape(const char *s, const char *chars); bool startswith(const char *s, const char *p); bool endswith(const char *s, const char *p); bool isempty(const char *s); int numdigits(int n); 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); bool DirectoryOk(const char *DirName, bool LogErrors = 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); bool SpinUpDisk(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 { private: @@ -92,58 +110,6 @@ public: uint64 Elapsed(void); }; -class cBufferedStringFunction { -protected: - char *buffer; - const char *result; -public: - cBufferedStringFunction(void); - virtual ~cBufferedStringFunction(); - const char * operator * () { return result; } - }; - -template 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 { private: char buffer[MAXPARSEBUFFER]; diff --git a/vdr.c b/vdr.c index 2276e7e8..f49a89a1 100644 --- a/vdr.c +++ b/vdr.c @@ -22,7 +22,7 @@ * * 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 @@ -384,19 +384,19 @@ int main(int argc, char *argv[]) ConfigDirectory = VideoDirectory; cPlugin::SetConfigDirectory(ConfigDirectory); - cThemes::SetThemesDirectory(*cAddDirectory(ConfigDirectory, "themes")); + cThemes::SetThemesDirectory(AddDirectory(ConfigDirectory, "themes")); - Setup.Load(*cAddDirectory(ConfigDirectory, "setup.conf")); - if (!(Sources.Load(*cAddDirectory(ConfigDirectory, "sources.conf"), true, true) && - Diseqcs.Load(*cAddDirectory(ConfigDirectory, "diseqc.conf"), true, Setup.DiSEqC) && - Channels.Load(*cAddDirectory(ConfigDirectory, "channels.conf"), false, true) && - Timers.Load(*cAddDirectory(ConfigDirectory, "timers.conf")) && - Commands.Load(*cAddDirectory(ConfigDirectory, "commands.conf"), true) && - RecordingCommands.Load(*cAddDirectory(ConfigDirectory, "reccmds.conf"), true) && - SVDRPhosts.Load(*cAddDirectory(ConfigDirectory, "svdrphosts.conf"), true) && - CaDefinitions.Load(*cAddDirectory(ConfigDirectory, "ca.conf"), true) && - Keys.Load(*cAddDirectory(ConfigDirectory, "remote.conf")) && - KeyMacros.Load(*cAddDirectory(ConfigDirectory, "keymacros.conf"), true) + Setup.Load(AddDirectory(ConfigDirectory, "setup.conf")); + if (!(Sources.Load(AddDirectory(ConfigDirectory, "sources.conf"), true, true) && + Diseqcs.Load(AddDirectory(ConfigDirectory, "diseqc.conf"), true, Setup.DiSEqC) && + Channels.Load(AddDirectory(ConfigDirectory, "channels.conf"), false, true) && + Timers.Load(AddDirectory(ConfigDirectory, "timers.conf")) && + Commands.Load(AddDirectory(ConfigDirectory, "commands.conf"), true) && + RecordingCommands.Load(AddDirectory(ConfigDirectory, "reccmds.conf"), true) && + SVDRPhosts.Load(AddDirectory(ConfigDirectory, "svdrphosts.conf"), true) && + CaDefinitions.Load(AddDirectory(ConfigDirectory, "ca.conf"), true) && + Keys.Load(AddDirectory(ConfigDirectory, "remote.conf")) && + KeyMacros.Load(AddDirectory(ConfigDirectory, "keymacros.conf"), true) )) EXIT(2); @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) } else if (*EpgDataFileName != '/' && *EpgDataFileName != '.') EpgDirectory = VideoDirectory; - cSchedules::SetEpgDataFileName(*cAddDirectory(EpgDirectory, EpgDataFileName)); + cSchedules::SetEpgDataFileName(AddDirectory(EpgDirectory, EpgDataFileName)); cSchedules::Read(); } @@ -870,7 +870,7 @@ int main(int argc, char *argv[]) if (!Next || Delta > Setup.MinEventTimeout * 60 || ForceShutdown) { ForceShutdown = false; if (timer) - dsyslog("next timer event at %s", *cCtime(Next)); + dsyslog("next timer event at %s", *TimeToString(Next)); if (WatchdogTimeout > 0) signal(SIGALRM, SIG_IGN); 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() : ""; Delta = Next - time(NULL); // compensates for Confirm() timeout 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); SystemExec(cmd); free(cmd); diff --git a/videodir.c b/videodir.c index 94e7141a..f0e54fe7 100644 --- a/videodir.c +++ b/videodir.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * 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" @@ -197,27 +197,23 @@ int VideoDiskSpace(int *FreeMB, int *UsedMB) 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 - int n = 2; - while (p-- > FileName && n > 0) { - if (*p == '/') { - if (--n == 0) { - int l = p - FileName + 1; - strncpy(PrefixedName, FileName, l); - PrefixedName[l] = Prefix; - strcpy(PrefixedName + l + 1, p + 1); - return PrefixedName; - } + const char *p = FileName + strlen(FileName); // p points at the terminating 0 + int n = 2; + while (p-- > FileName && n > 0) { + if (*p == '/') { + if (--n == 0) { + int l = p - FileName + 1; + strncpy(PrefixedName, FileName, l); + PrefixedName[l] = Prefix; + strcpy(PrefixedName + l + 1, p + 1); + return PrefixedName; } } - } + } return NULL; } diff --git a/videodir.h b/videodir.h index a719c5e0..b9e38cb4 100644 --- a/videodir.h +++ b/videodir.h @@ -4,13 +4,14 @@ * See the main source file 'vdr.c' for copyright information and * 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 #define __VIDEODIR_H #include +#include "tools.h" extern const char *VideoDirectory; @@ -20,7 +21,7 @@ bool RenameVideoFile(const char *OldName, const char *NewName); bool RemoveVideoFile(const char *FileName); bool VideoFileSpaceAvailable(int SizeMB); 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); #endif //__VIDEODIR_H