diff options
author | Christian Wieninger <cwieninger (at) gmx (dot) de> | 2008-02-20 17:47:50 +0100 |
---|---|---|
committer | Christian Wieninger <cwieninger (at) gmx (dot) de> | 2008-02-20 17:47:50 +0100 |
commit | 1ca3263b1febbef86071eaaa4e8eda0bbac578fa (patch) | |
tree | 51acae08ac515eba84e01c76261a7735665dd601 | |
parent | 57d0cbd75c591e450e4d11a45ac6a016de48b8cf (diff) | |
download | vdr-plugin-epgsearch-1ca3263b1febbef86071eaaa4e8eda0bbac578fa.tar.gz vdr-plugin-epgsearch-1ca3263b1febbef86071eaaa4e8eda0bbac578fa.tar.bz2 |
replaced asprintf with cString::sprintf and a wrapper function
45 files changed, 284 insertions, 444 deletions
@@ -27,6 +27,7 @@ new: suggested by Bittor Corl - update of 'undoneepgsearch.sh', a script to remove recordings from the done file via reccmds.conf, thanks to Viking@vdrportal. +- menu of recordings done now sorts the date top down fixes: - shifting the time display: the start time now only gets displayed in 'Overview - Now' instead of a progressbar, if there's not already a start time @@ -32,6 +32,7 @@ neu: werden, vorgeschlagen von Bittor Corl - Update von 'undoneepgsearch.sh', einem Skript zum Entfernen einer Aufnahme aus dem done-File über die reccmds.conf, Danke an Viking@vdrportal. +- Im Menü "erledigte Aufnahmen" wird nun beim Datum absteigend sortiert. fixes: - Shiften der Uhrzeit: die Startzeit wird jetzt nur noch dann anstelle des Fortschrittsbalken angezeigt, wenn in der Menüvorlage nicht bereits eine diff --git a/blacklist.c b/blacklist.c index 6f23aef..a6ae2d7 100644 --- a/blacklist.c +++ b/blacklist.c @@ -195,9 +195,9 @@ const char *cBlacklist::ToText(void) if (useChannel==1) { if (channelMin->Number() < channelMax->Number()) - asprintf(&tmp_chanSel, "%s|%s", CHANNELSTRING(channelMin), CHANNELSTRING(channelMax)); + msprintf(&tmp_chanSel, "%s|%s", CHANNELSTRING(channelMin), CHANNELSTRING(channelMax)); else - asprintf(&tmp_chanSel, "%s", CHANNELSTRING(channelMin)); + msprintf(&tmp_chanSel, "%s", CHANNELSTRING(channelMin)); } if (useChannel==2) { @@ -218,18 +218,18 @@ const char *cBlacklist::ToText(void) while (SearchExtCat) { char* catvalue = NULL; - asprintf(&catvalue, "%s", catvalues[index]); + msprintf(&catvalue, "%s", catvalues[index]); while(strstr(catvalue, ":")) catvalue = strreplace(catvalue, ":", "!^colon^!"); // ugly: replace with something, that should not happen to be part ofa category value while(strstr(catvalue, "|")) catvalue = strreplace(catvalue, "|", "!^pipe^!"); // ugly: replace with something, that should not happen to be part of a regular expression if (index == 0) - asprintf(&tmp_catvalues, "%d#%s", SearchExtCat->id, catvalue); + msprintf(&tmp_catvalues, "%d#%s", SearchExtCat->id, catvalue); else { char* temp = tmp_catvalues; - asprintf(&tmp_catvalues, "%s|%d#%s", tmp_catvalues, SearchExtCat->id, catvalue); + msprintf(&tmp_catvalues, "%s|%d#%s", tmp_catvalues, SearchExtCat->id, catvalue); free(temp); } SearchExtCat = SearchExtCats.Next(SearchExtCat); @@ -238,7 +238,7 @@ const char *cBlacklist::ToText(void) } } - asprintf(&buffer, "%d:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d:%d:%d:%s:%s:%d:%d:%d:%s:%d:%d", + msprintf(&buffer, "%d:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d:%d:%d:%s:%s:%d:%d:%d:%s:%d:%d", ID, tmp_search, useTime, @@ -549,7 +549,7 @@ cEvent * cBlacklist::GetEventByBlacklist(const cSchedule *schedules, const cEven if (!p->Title() || strlen(p->Title()) == 0) continue; - asprintf(&szTest, "%s%s%s%s%s", (useTitle?p->Title():""), (useSubtitle||useDescription)?"~":"", + msprintf(&szTest, "%s%s%s%s%s", (useTitle?p->Title():""), (useSubtitle||useDescription)?"~":"", (useSubtitle?p->ShortText():""),useDescription?"~":"", (useDescription?p->Description():"")); @@ -111,13 +111,13 @@ const char *cChannelGroup::ToText(void) else { char* temp = channelbuffer; - asprintf(&channelbuffer, "%s|%s", channelbuffer, CHANNELSTRING(channel)); + msprintf(&channelbuffer, "%s|%s", channelbuffer, CHANNELSTRING(channel)); free(temp); } ChannelGroupItem = channels.Next(ChannelGroupItem); } char* buffer = NULL; - asprintf(&buffer, "%s|%s", name, channelbuffer); + msprintf(&buffer, "%s|%s", name, channelbuffer); free(channelbuffer); return buffer; } @@ -258,7 +258,7 @@ cMenuChannelGroupItem::cMenuChannelGroupItem(cChannelGroup* Group) void cMenuChannelGroupItem::Set(void) { - char* channelbuffer = NULL; + cString channelbuffer; cChannelGroupItem* channelInGroup = group->channels.First(); int channelNr, chIntBegin = -1, chIntEnd = -1, chLast = -1; @@ -276,9 +276,9 @@ void cMenuChannelGroupItem::Set(void) { chIntEnd = chLast; if(chIntBegin == chIntEnd) - asprintf(&channelbuffer, "%s %d", channelbuffer?channelbuffer:"", chIntBegin); + channelbuffer = cString::sprintf("%s %d", *channelbuffer?*channelbuffer:"", chIntBegin); else if (chIntEnd != -1) - asprintf(&channelbuffer, "%s %d-%d", channelbuffer?channelbuffer:"", chIntBegin, chIntEnd); + channelbuffer = cString::sprintf("%s %d-%d", *channelbuffer?*channelbuffer:"", chIntBegin, chIntEnd); chIntBegin = chIntEnd = channelNr; } @@ -287,17 +287,13 @@ void cMenuChannelGroupItem::Set(void) if (!channelInGroup) { if(chLast == chIntBegin) - asprintf(&channelbuffer, "%s %d", channelbuffer?channelbuffer:"", chIntBegin); + channelbuffer = cString::sprintf("%s %d", *channelbuffer?*channelbuffer:"", chIntBegin); else - asprintf(&channelbuffer, "%s %d-%d", channelbuffer?channelbuffer:"", chIntBegin, chLast); + channelbuffer = cString::sprintf("%s %d-%d", *channelbuffer?*channelbuffer:"", chIntBegin, chLast); } } - - char* buffer = NULL; - asprintf(&buffer, "%s\t%s", group->name, channelbuffer?channelbuffer:""); - free(channelbuffer); - SetText(buffer, false); + SetText(cString::sprintf("%s\t%s", group->name, *channelbuffer?*channelbuffer:"")); } // --- cMenuChannelGroups ---------------------------------------------------------- @@ -346,10 +342,8 @@ eOSState cMenuChannelGroups::Delete(void) cSearchExt* search = ChannelGroups.Used(curGroup); if (search) { - char* Message = NULL; - asprintf(&Message, "%s %s", tr("Channel group used by:"), search->search); + cString Message = cString::sprintf("%s %s", tr("Channel group used by:"), search->search); Skins.Message(mtInfo, Message); - free(Message); return osContinue; } if (Interface->Confirm(tr("Edit$Delete group?"))) { diff --git a/conflictcheck_thread.c b/conflictcheck_thread.c index 7a7fabf..b9e4742 100644 --- a/conflictcheck_thread.c +++ b/conflictcheck_thread.c @@ -110,23 +110,22 @@ void cConflictCheckThread::Action(void) time_t nextConflict = 0; if (conflictCheck.relevantConflicts > 0) { - char* msgfmt = NULL; - asprintf(&msgfmt, tr("%d timer conflict(s)! First at %s. Show them?"), conflictCheck.relevantConflicts, - *DateTime(conflictCheck.nextRelevantConflictDate)); - bool doMessage = EPGSearchConfig.noConflMsgWhileReplay == 0 || - !cDevice::PrimaryDevice()->Replaying() || - conflictCheck.nextRelevantConflictDate - now < 2*60*60; - if (doMessage && SendMsg(msgfmt, true,7) == kOk) + cString msgfmt = cString::sprintf(tr("%d timer conflict(s)! First at %s. Show them?"), + conflictCheck.relevantConflicts, + *DateTime(conflictCheck.nextRelevantConflictDate)); + bool doMessage = EPGSearchConfig.noConflMsgWhileReplay == 0 || + !cDevice::PrimaryDevice()->Replaying() || + conflictCheck.nextRelevantConflictDate - now < 2*60*60; + if (doMessage && SendMsg(msgfmt, true,7) == kOk) { - m_plugin->showConflicts = true; - cRemote::CallPlugin("epgsearch"); + m_plugin->showConflicts = true; + cRemote::CallPlugin("epgsearch"); } - free(msgfmt); - - if (EPGSearchConfig.sendMailOnConflicts) + + if (EPGSearchConfig.sendMailOnConflicts) { - cMailConflictNotifier mailNotifier; - mailNotifier.SendConflictNotifications(conflictCheck); + cMailConflictNotifier mailNotifier; + mailNotifier.SendConflictNotifications(conflictCheck); } } diff --git a/conflictcheckonly.c b/conflictcheckonly.c index bc93b24..db7b50f 100644 --- a/conflictcheckonly.c +++ b/conflictcheckonly.c @@ -30,6 +30,7 @@ The project's page is at http://winni.vdr-developer.org/epgsearch #endif #include "services.h" #include "mainmenushortcut.h" +#include "epgsearchtools.h" static const char VERSION[] = "0.0.1"; static const char DESCRIPTION[] = trNOOP("Direct access to epgsearch's conflict check menu"); @@ -207,7 +208,7 @@ const char *cPluginConflictcheckonly::MainMenuText(void) if (epgSearchPlugin->Service("Epgsearch-lastconflictinfo-v1.0", serviceData)) { if (serviceData->relevantConflicts > 0) { free(_menuText); - asprintf(&_menuText, "%s (%d, %s: %s)", menuText, serviceData->relevantConflicts, + msprintf(&_menuText, "%s (%d, %s: %s)", menuText, serviceData->relevantConflicts, #if APIVERSNUM < 10507 tr("next"), *DateTime(serviceData->nextConflict)); #else diff --git a/epgsearchcats.c b/epgsearchcats.c index 3400bc0..e6c09f6 100644 --- a/epgsearchcats.c +++ b/epgsearchcats.c @@ -24,6 +24,7 @@ The project's page is at http://winni.vdr-developer.org/epgsearch #include <string> #include "epgsearchcats.h" #include "log.h" +#include "epgsearchtools.h" #include <vdr/tools.h> using std::string; @@ -122,7 +123,7 @@ const char *cSearchExtCat::ToText(void) for(int i=0; i<nvalues; i++) sValues += string(values[i]) + ((i<nvalues-1)?", ":""); - asprintf(&buffer, "%d|%s|%s|%s|%d", + msprintf(&buffer, "%d|%s|%s|%s|%d", id, name, menuname, sValues.c_str(), searchmode); return buffer; } diff --git a/epgsearchext.c b/epgsearchext.c index 2452a06..604107c 100644 --- a/epgsearchext.c +++ b/epgsearchext.c @@ -252,7 +252,7 @@ const char *cSearchExt::ToText() char tmp_Stop[5] = ""; char tmp_minDuration[5] = ""; char tmp_maxDuration[5] = ""; - char* tmp_chanSel = NULL; + cString tmp_chanSel; char* tmp_search = NULL; char* tmp_directory = NULL; char* tmp_catvalues = NULL; @@ -285,9 +285,9 @@ const char *cSearchExt::ToText() if (useChannel==1) { if (channelMin->Number() < channelMax->Number()) - asprintf(&tmp_chanSel, "%s|%s", CHANNELSTRING(channelMin), CHANNELSTRING(channelMax)); + tmp_chanSel = cString::sprintf("%s|%s", CHANNELSTRING(channelMin), CHANNELSTRING(channelMax)); else - asprintf(&tmp_chanSel, "%s", CHANNELSTRING(channelMin)); + tmp_chanSel = cString(CHANNELSTRING(channelMin)); } if (useChannel==2) { @@ -298,7 +298,7 @@ const char *cSearchExt::ToText() useChannel = 0; } else - tmp_chanSel = strdup(channelGroup); + tmp_chanSel = cString(channelGroup); } if (useExtEPGInfo) @@ -308,18 +308,18 @@ const char *cSearchExt::ToText() while (SearchExtCat) { char* catvalue = NULL; - asprintf(&catvalue, "%s", catvalues[index]); + msprintf(&catvalue, "%s", catvalues[index]); while(strstr(catvalue, ":")) catvalue = strreplace(catvalue, ":", "!^colon^!"); // ugly: replace with something, that should not happen to be part ofa category value while(strstr(catvalue, "|")) catvalue = strreplace(catvalue, "|", "!^pipe^!"); // ugly: replace with something, that should not happen to be part of a regular expression if (index == 0) - asprintf(&tmp_catvalues, "%d#%s", SearchExtCat->id, catvalue); + msprintf(&tmp_catvalues, "%d#%s", SearchExtCat->id, catvalue); else { char* temp = tmp_catvalues; - asprintf(&tmp_catvalues, "%s|%d#%s", tmp_catvalues, SearchExtCat->id, catvalue); + msprintf(&tmp_catvalues, "%s|%d#%s", tmp_catvalues, SearchExtCat->id, catvalue); free(temp); } SearchExtCat = SearchExtCats.Next(SearchExtCat); @@ -335,11 +335,11 @@ const char *cSearchExt::ToText() while (blacklistObj) { if (index == 0) - asprintf(&tmp_blacklists, "%d", blacklistObj->blacklist->ID); + msprintf(&tmp_blacklists, "%d", blacklistObj->blacklist->ID); else { char* temp = tmp_blacklists; - asprintf(&tmp_blacklists, "%s|%d", tmp_blacklists, blacklistObj->blacklist->ID); + msprintf(&tmp_blacklists, "%s|%d", tmp_blacklists, blacklistObj->blacklist->ID); free(temp); } blacklistObj = blacklists.Next(blacklistObj); @@ -347,14 +347,14 @@ const char *cSearchExt::ToText() } } - asprintf(&buffer, "%d:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d:%d:%d:%s:%s:%d:%d:%d:%d:%s:%d:%d:%d:%d:%d:%d:%d:%s:%d:%d:%d:%d:%d:%ld:%d:%d:%d:%d:%d:%d:%s:%d:%d:%d:%d:%d:%d:%ld:%ld:%d:%d", + msprintf(&buffer, "%d:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d:%d:%d:%s:%s:%d:%d:%d:%d:%s:%d:%d:%d:%d:%d:%d:%d:%s:%d:%d:%d:%d:%d:%ld:%d:%d:%d:%d:%d:%d:%s:%d:%d:%d:%d:%d:%d:%ld:%ld:%d:%d", ID, tmp_search, useTime, tmp_Start, tmp_Stop, useChannel, - (useChannel>0 && useChannel<3)?tmp_chanSel:"0", + (useChannel>0 && useChannel<3)?*tmp_chanSel:"0", useCase, mode, useTitle, @@ -400,7 +400,6 @@ const char *cSearchExt::ToText() ignoreMissingEPGCats, unmuteSoundOnSwitch); - if (tmp_chanSel) free(tmp_chanSel); if (tmp_search) free(tmp_search); if (tmp_directory) free(tmp_directory); if (tmp_catvalues) free(tmp_catvalues); @@ -644,14 +643,12 @@ char* cSearchExt::BuildFile(const cEvent* pEvent) const if (useEpisode) { - char* pFile = NULL; - asprintf(&pFile, "%s~%s", pEvent->Title(), Subtitle); - if (file) free(file); - file = strdup(pFile); - free(pFile); + cString pFile = cString::sprintf("%s~%s", pEvent->Title(), Subtitle); + if (file) free(file); + file = strdup(pFile); } - else - asprintf(&file, "%s", pEvent->Title()); + else if (pEvent->Title()) + file = strdup(pEvent->Title()); if (!isempty(directory)) { @@ -659,10 +656,10 @@ char* cSearchExt::BuildFile(const cEvent* pEvent) const cVarExpr varExprDir(directory); if (!varExprDir.DependsOnVar("%title%", pEvent) && !varExprDir.DependsOnVar("%subtitle%", pEvent)) - asprintf(&pFile, "%s~%s", directory, file?file:""); + msprintf(&pFile, "%s~%s", directory, file?file:""); else // ignore existing title and subtitle in file if already used as variables in directory - asprintf(&pFile, "%s", directory); + msprintf(&pFile, "%s", directory); // parse the epxression and evaluate it cVarExpr varExprFile(pFile); @@ -880,7 +877,7 @@ cEvent * cSearchExt::GetEventBySearchExt(const cSchedule *schedules, const cEven if (!p->Title() || !*p->Title()) continue; - asprintf(&szTest, "%s%s%s%s%s", (useTitle?(p->Title()?p->Title():""):""), (useSubtitle||useDescription)?"~":"", + msprintf(&szTest, "%s%s%s%s%s", (useTitle?(p->Title()?p->Title():""):""), (useSubtitle||useDescription)?"~":"", (useSubtitle?(p->ShortText()?p->ShortText():""):""),useDescription?"~":"", (useDescription?(p->Description()?p->Description():""):"")); diff --git a/epgsearchsetup.c b/epgsearchsetup.c index e01a469..57293f2 100644 --- a/epgsearchsetup.c +++ b/epgsearchsetup.c @@ -87,7 +87,7 @@ eOSState cMenuSetupSubMenu::Help() if(Current() < (int) helpTexts.size()) { char* title = NULL; - asprintf(&title, "%s - %s", tr("Button$Help"), ItemText); + msprintf(&title, "%s - %s", tr("Button$Help"), ItemText); if (strchr(title, ':')) *strchr(title, ':') = 0; state = AddSubMenu(new cMenuText(title, helpTexts[Current()])); @@ -471,8 +471,7 @@ void cMenuSetupUserdefTimes::Set() Clear(); helpTexts.clear(); - char* szUseUserTime = NULL; - asprintf(&szUseUserTime, "%s %d", tr("Use user-defined time"), 1); + cString szUseUserTime = cString::sprintf("%s %d", tr("Use user-defined time"), 1); Add(new cMenuEditBoolItem(szUseUserTime, &data->ShowModes[showUserMode1].useIt, trVDR("no"), trVDR("yes"))); AddHelp(tr("Help$Besides 'Now' and 'Next' you can specify up to 4 other times in the EPG which can be used by repeatedly pressing the green key, e.g. 'prime time', 'late night',...")); if (data->ShowModes[showUserMode1].GetUsage()) @@ -482,9 +481,8 @@ void cMenuSetupUserdefTimes::Set() Add(new cMenuEditTimeItem(IndentMenuItem(tr("Time")), &data->ShowModes[showUserMode1].itime)); AddHelp(tr("Help$Specify the user-defined time here in 'HH:MM'.")); } - free(szUseUserTime); - asprintf(&szUseUserTime, "%s %d", tr("Use user-defined time"), 2); + szUseUserTime = cString::sprintf("%s %d", tr("Use user-defined time"), 2); Add(new cMenuEditBoolItem( szUseUserTime, &data->ShowModes[showUserMode2].useIt, trVDR("no"), trVDR("yes"))); AddHelp(tr("Help$Besides 'Now' and 'Next' you can specify up to 4 other times in the EPG which can be used by repeatedly pressing the green key, e.g. 'prime time', 'late night',...")); if (data->ShowModes[showUserMode2].GetUsage()) @@ -494,9 +492,8 @@ void cMenuSetupUserdefTimes::Set() Add(new cMenuEditTimeItem(IndentMenuItem(tr("Time")), &data->ShowModes[showUserMode2].itime)); AddHelp(tr("Help$Specify the user-defined time here in 'HH:MM'.")); } - free(szUseUserTime); - asprintf(&szUseUserTime, "%s %d", tr("Use user-defined time"), 3); + szUseUserTime = cString::sprintf("%s %d", tr("Use user-defined time"), 3); Add(new cMenuEditBoolItem(szUseUserTime, &data->ShowModes[showUserMode3].useIt, trVDR("no"), trVDR("yes"))); AddHelp(tr("Help$Besides 'Now' and 'Next' you can specify up to 4 other times in the EPG which can be used by repeatedly pressing the green key, e.g. 'prime time', 'late night',...")); if (data->ShowModes[showUserMode3].GetUsage()) @@ -506,9 +503,8 @@ void cMenuSetupUserdefTimes::Set() Add(new cMenuEditTimeItem(IndentMenuItem(tr("Time")), &data->ShowModes[showUserMode3].itime)); AddHelp(tr("Help$Specify the user-defined time here in 'HH:MM'.")); } - free(szUseUserTime); - asprintf(&szUseUserTime, "%s %d", tr("Use user-defined time"), 4); + szUseUserTime = cString::sprintf("%s %d", tr("Use user-defined time"), 4); Add(new cMenuEditBoolItem(szUseUserTime, &data->ShowModes[showUserMode4].useIt, trVDR("no"), trVDR("yes"))); AddHelp(tr("Help$Besides 'Now' and 'Next' you can specify up to 4 other times in the EPG which can be used by repeatedly pressing the green key, e.g. 'prime time', 'late night',...")); if (data->ShowModes[showUserMode4].GetUsage()) @@ -518,7 +514,6 @@ void cMenuSetupUserdefTimes::Set() Add(new cMenuEditTimeItem(IndentMenuItem(tr("Time")), &data->ShowModes[showUserMode4].itime)); AddHelp(tr("Help$Specify the user-defined time here in 'HH:MM'.")); } - free(szUseUserTime); SetCurrent(Get(current)); Display(); diff --git a/epgsearchsvdrp.c b/epgsearchsvdrp.c index db58a80..6f60c6b 100644 --- a/epgsearchsvdrp.c +++ b/epgsearchsvdrp.c @@ -156,14 +156,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, { cSearchExt *search = SearchExts.GetSearchFromID(atol(Option)); if (search) - { - char* buffer = NULL; - asprintf(&buffer, "%s", search->ToText()); - cString sBuffer = cString(buffer); - free(buffer); - return sBuffer; - } - + return cString(search->ToText()); else { ReplyCode = 901; @@ -405,7 +398,6 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, { const cEvent* pEvent = result->event; cTimer* Timer = new cTimer(pEvent); - char *cmdbuf = NULL; static char bufStart[25]; static char bufEnd[25]; @@ -426,7 +418,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, strftime(bufStart, sizeof(bufStart), "%H%M", localtime_r(&start, &tm_r)); strftime(bufEnd, sizeof(bufEnd), "%H%M", localtime_r(&stop, &tm_r)); - asprintf(&cmdbuf, "NEWT %d:%d:%s:%s:%s:%d:%d:%s:%s", + cString cmdbuf = cString::sprintf("NEWT %d:%d:%s:%s:%s:%d:%d:%s:%s", Flags, Timer->Channel()->Number(), #if VDRVERSNUM < 10503 @@ -443,7 +435,6 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, sBuffer += string(cmdbuf) + string(results->Next(result)?"\n":""); - free(cmdbuf); delete(Timer); result = results->Next(result); } @@ -531,7 +522,6 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, { const cEvent* pEvent = result->event; cTimer* Timer = new cTimer(pEvent); - char *cmdbuf = NULL; static char bufStart[25]; static char bufEnd[25]; @@ -565,7 +555,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, string shorttext = pEvent->ShortText()?ReplaceAll(pEvent->ShortText(), "|", "!^pipe!^"):""; shorttext = ReplaceAll(shorttext, ":", "|"); - asprintf(&cmdbuf, "%d:%u:%s:%s:%ld:%ld:%s:%ld:%ld:%s:%d", + cString cmdbuf = cString::sprintf("%d:%u:%s:%s:%ld:%ld:%s:%ld:%ld:%s:%d", result->search->ID, pEvent->EventID(), title.c_str(), @@ -579,7 +569,6 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, timerMode); sBuffer += string(cmdbuf) + string(pCompleteSearchResults->Next(result)?"\n":""); - free(cmdbuf); delete(Timer); result = pCompleteSearchResults->Next(result); } @@ -628,14 +617,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, { cChannelGroup *changrp = ChannelGroups.GetGroupByName(Option); if (changrp) - { - char* buffer = NULL; - asprintf(&buffer, "%s", changrp->ToText()); - cString sBuffer = cString(buffer); - free(buffer); - return sBuffer; - } - + return cString(changrp->ToText()); else { ReplyCode = 901; @@ -816,14 +798,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, { cBlacklist *blacklist = Blacklists.GetBlacklistFromID(atol(Option)); if (blacklist) - { - char* buffer = NULL; - asprintf(&buffer, "%s", blacklist->ToText()); - cString sBuffer = cString(buffer); - free(buffer); - return sBuffer; - } - + return cString(blacklist->ToText()); else { ReplyCode = 901; @@ -964,14 +939,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, int index = SearchExtCats.GetIndexFromID(atoi(Option)); if (index >= 0) SearchExtCat = SearchExtCats.Get(index); if (SearchExtCat) - { - char* buffer = NULL; - asprintf(&buffer, "%s", SearchExtCat->ToText()); - cString sBuffer = cString(buffer); - free(buffer); - return sBuffer; - } - + return cString(SearchExtCat->ToText()); else { ReplyCode = 901; @@ -1093,14 +1061,7 @@ cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, { cSearchExt *search = SearchTemplates.GetSearchFromID(atol(Option)); if (search) - { - char* buffer = NULL; - asprintf(&buffer, "%s", search->ToText()); - cString sBuffer = cString(buffer); - free(buffer); - return sBuffer; - } - + return cString(search->ToText()); else { ReplyCode = 901; diff --git a/epgsearchtools.c b/epgsearchtools.c index 0ee4486..6a740fa 100644 --- a/epgsearchtools.c +++ b/epgsearchtools.c @@ -73,7 +73,7 @@ int CompareEventChannel(const void *p1, const void *p2) char* IndentMenuItem(const char* szString) { char* szIndented = NULL; - asprintf(&szIndented, " %s", szString); + msprintf(&szIndented, " %s", szString); return szIndented; } @@ -414,7 +414,7 @@ char* GetExtEPGValue(const char* description, const char* catname) char* tmp = NULL; // search the category, must be at beginnig of a line - asprintf(&tmp, "\n%s: ", catname); + msprintf(&tmp, "\n%s: ", catname); char* descr = strdup(description); char* cat = NULL; if ((cat = strstr(descr, tmp)) == NULL) @@ -434,7 +434,7 @@ char* GetExtEPGValue(const char* description, const char* catname) cat[endpos] = 0; char* value = NULL; - asprintf(&value, "%s", cat + strlen(tmp)-1); + msprintf(&value, "%s", cat + strlen(tmp)-1); free(descr); free(tmp); @@ -473,7 +473,7 @@ char* GetAuxValue(const char* aux, const char* name) cat[endpos] = 0; char* value = NULL; - asprintf(&value, "%s", cat + strlen(name)+2); + msprintf(&value, "%s", cat + strlen(name)+2); free(descr); return value; @@ -582,42 +582,41 @@ void sleepSec(long s) sleepMSec(s * 1000); } -bool SendViaSVDRP(const char* SVDRPcmd) +bool SendViaSVDRP(cString SVDRPcmd) { bool bSuccess = true; - char *cmdbuf = NULL; + cString cmdbuf; if (EPGSearchConfig.useExternalSVDRP) { - asprintf(&cmdbuf, "%s -p %d \"%s\"", + cmdbuf = cString::sprintf("%s -p %d \"%s\"", cSVDRPClient::SVDRPSendCmd, EPGSearchConfig.SVDRPPort, - SVDRPcmd); + *SVDRPcmd); FILE *p = popen(cmdbuf, "r"); if (p) pclose(p); else { - LogFile.eSysLog("can't open pipe for command '%s'", cmdbuf); + LogFile.eSysLog("can't open pipe for command '%s'", *cmdbuf); bSuccess = false; } } else { - asprintf(&cmdbuf, "%s", SVDRPcmd); + cmdbuf = SVDRPcmd; cSVDRPClient client(EPGSearchConfig.SVDRPPort); - if (!client.SendCmd(cmdbuf)) + if (!client.SendCmd(*cmdbuf)) { - LogFile.eSysLog("command '%s' failed", cmdbuf); + LogFile.eSysLog("command '%s' failed", *cmdbuf); bSuccess = false; } } - free(cmdbuf); return bSuccess; } -int SendMsg(const char* Message, bool confirm, int seconds) +int SendMsg(cString Message, bool confirm, int seconds) { int Keys = Skins.QueueMessage(mtInfo, Message, seconds, confirm?seconds+2:0); return Keys; @@ -887,12 +886,9 @@ int ChannelNrFromEvent(const cEvent* pEvent) void DelTimer(int index) { - char *cmdbuf = NULL; - asprintf(&cmdbuf, "DELT %d", index); - LogFile.Log(2, "delete timer %d", index); - SendViaSVDRP(cmdbuf); - - free(cmdbuf); + cString cmdbuf = cString::sprintf("DELT %d", index); + LogFile.Log(2, "delete timer %d", index); + SendViaSVDRP(cmdbuf); } char* FixSeparators(char* buffer, char sep) @@ -1024,3 +1020,11 @@ void SetAux(cTimer* timer, string aux) timer->Parse(timerText.c_str()); } +int msprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + int res=vasprintf (strp, fmt, ap); + va_end (ap); + return res; +} diff --git a/epgsearchtools.h b/epgsearchtools.h index 3ca85c4..89d6853 100644 --- a/epgsearchtools.h +++ b/epgsearchtools.h @@ -100,8 +100,8 @@ char *strreplacei(char *s, const char *s1, const char *s2); char *strreplaceall(char* source, char ch, const char* replacement); void sleepMSec(long ms); void sleepSec(long s); -bool SendViaSVDRP(const char* SVDRPcmd); -int SendMsg(const char* Message, bool confirm = false, int seconds = 0); +bool SendViaSVDRP(cString SVDRPcmd); +int SendMsg(cString Message, bool confirm = false, int seconds = 0); bool InEditMode(const char* ItemText, const char* ItemName, const char* ItemValue); cSearchExt* TriggeredFromSearchTimer(const cTimer* timer); int TriggeredFromSearchTimerID(const cTimer* timer); @@ -128,6 +128,7 @@ string QuoteApostroph(const string& S); string MD5(const string& input); time_t GetDateTime(time_t day, int start); void SetAux(cTimer* timer, string aux); +int msprintf(char **strp, const char *fmt, ...); // --- cTimerObj -------------------------------------------------------- class cTimerObj : public cListObject { @@ -63,11 +63,9 @@ class cLogFile: public cFile char timebuf[25]; strftime(timebuf, sizeof(timebuf), "%T", localtime_r(&now, &tm_r)); - char* log = NULL; - asprintf(&log, "%s %s: %s\n", datebuf, timebuf, buffer); + cString log = cString::sprintf("%s %s: %s\n", datebuf, timebuf, buffer); free(buffer); safe_write(*this, log, strlen(log)); - free(log); } } void eSysLog(const char *text, ...) diff --git a/menu_announcelist.c b/menu_announcelist.c index 5cd7282..dec225d 100644 --- a/menu_announcelist.c +++ b/menu_announcelist.c @@ -89,12 +89,10 @@ cMenuAnnounceDetails::cMenuAnnounceDetails(const cEvent* Event, const cSearchExt :cOsdMenu("", 25), event(Event) { cMenuAnnounceList::showsDetails = true; - char* szTitle = NULL; if (event && !isempty(event->Title())) { - asprintf(&szTitle, "%s: %s", tr("announce details"), event->Title()); - SetTitle(szTitle); - free(szTitle); + cString szTitle = cString::sprintf("%s: %s", tr("announce details"), event->Title()); + SetTitle(szTitle); } search = Search; @@ -142,10 +140,8 @@ void cMenuAnnounceDetails::Set() pInfoItem->SetSelectable(false); Add(pInfoItem); - char* info = NULL; - asprintf(&info, "%s: %s", tr("Search timer"), search->search); + cString info = cString::sprintf("%s: %s", tr("Search timer"), search->search); pInfoItem = new cOsdItem(info); - free(info); pInfoItem->SetSelectable(false); Add(pInfoItem); } diff --git a/menu_blacklistedit.c b/menu_blacklistedit.c index 08786f4..f195a63 100644 --- a/menu_blacklistedit.c +++ b/menu_blacklistedit.c @@ -385,7 +385,7 @@ eOSState cMenuBlacklistEdit::ProcessKey(eKeys Key) if (SearchExtCat->searchmode >= 10) { if (blacklist->catvalues[index]) free(blacklist->catvalues[index]); - asprintf(&blacklist->catvalues[index], "%d", catvaluesNumeric[index]); + msprintf(&blacklist->catvalues[index], "%d", catvaluesNumeric[index]); } SearchExtCat = SearchExtCats.Next(SearchExtCat); index++; diff --git a/menu_commands.c b/menu_commands.c index 42f186e..9333540 100644 --- a/menu_commands.c +++ b/menu_commands.c @@ -63,10 +63,8 @@ cMenuSearchCommands::cMenuSearchCommands(const char *Title, const cEvent* Event, Add(new cOsdItem(hk(command->Title()))); if (event) { - char* szTitle = NULL; - asprintf(&szTitle, "%s: %s", tr("EPG Commands"), event->Title()); - SetTitle(szTitle); - free(szTitle); + cString szTitle = cString::sprintf("%s: %s", tr("EPG Commands"), event->Title()); + SetTitle(szTitle); } } @@ -88,16 +86,13 @@ void cMenuSearchCommands::LoadCommands() bool bLoaded = false; while(pstrSearchToken) // may contain multiple code, e.g. 'ger,deu' { - char* cmdFile = NULL; - asprintf(&cmdFile, "%s-%s.conf", ADDDIR(CONFIGDIR, "epgsearchcmds"), pstrSearchToken); + cString cmdFile = cString::sprintf("%s-%s.conf", ADDDIR(CONFIGDIR, "epgsearchcmds"), pstrSearchToken); if (access(cmdFile, F_OK) == 0) { commands.Load(cmdFile, true); - free(cmdFile); bLoaded = true; break; } - free(cmdFile); pstrSearchToken=strtok_r(NULL, ",", &pptr); } if (!bLoaded) @@ -274,31 +269,28 @@ eOSState cMenuSearchCommands::Execute(void) cCommand *command = commands.Get(current-8); if (command) { - char *buffer = NULL; + cString buffer; bool confirmed = true; if (command->Confirm()) { - asprintf(&buffer, "%s?", command->Title()); - confirmed = Interface->Confirm(buffer); - free(buffer); + buffer = cString::sprintf("%s?", command->Title()); + confirmed = Interface->Confirm(buffer); } if (confirmed) { - asprintf(&buffer, "%s...", command->Title()); - Skins.Message(mtStatus, buffer); - free(buffer); - - asprintf(&buffer, "'%s' %ld %ld %d '%s' '%s'", - EscapeString(event->Title()).c_str(), - event->StartTime(), - event->EndTime(), - ChannelNrFromEvent(event), - EscapeString(Channels.GetByChannelID(event->ChannelID(), true, true)->Name()).c_str(), - EscapeString(event->ShortText()?event->ShortText():"").c_str()); - const char *Result = command->Execute(buffer); - free(buffer); - Skins.Message(mtStatus, NULL); - if (Result) - return AddSubMenu(new cMenuText(command->Title(), Result, fontFix)); - return osBack; + buffer = cString::sprintf("%s...", command->Title()); + Skins.Message(mtStatus, buffer); + + buffer = cString::sprintf("'%s' %ld %ld %d '%s' '%s'", + EscapeString(event->Title()).c_str(), + event->StartTime(), + event->EndTime(), + ChannelNrFromEvent(event), + EscapeString(Channels.GetByChannelID(event->ChannelID(), true, true)->Name()).c_str(), + EscapeString(event->ShortText()?event->ShortText():"").c_str()); + const char *Result = command->Execute(buffer); + Skins.Message(mtStatus, NULL); + if (Result) + return AddSubMenu(new cMenuText(command->Title(), Result, fontFix)); + return osBack; } } return osContinue; diff --git a/menu_conflictcheck.c b/menu_conflictcheck.c index c9a1fd5..73ca7f5 100644 --- a/menu_conflictcheck.c +++ b/menu_conflictcheck.c @@ -37,7 +37,7 @@ cMenuConflictCheckItem::cMenuConflictCheckItem(cConflictCheckTime* Ct, cConflict { checktime = Ct; timerObj = TimerObj; - char* buffer = NULL; + cString buffer; if (!TimerObj) // print header { struct tm tm_r; @@ -45,16 +45,16 @@ cMenuConflictCheckItem::cMenuConflictCheckItem(cConflictCheckTime* Ct, cConflict tm *tm = localtime_r(&t, &tm_r); char dateshort[7] = ""; strftime(dateshort, sizeof(dateshort), "%d.%m.", tm); - asprintf(&buffer, "%s\t%s %s", WEEKDAYNAME(t), dateshort, TIMESTRING(t)); + buffer = cString::sprintf("%s\t%s %s", WEEKDAYNAME(t), dateshort, TIMESTRING(t)); SetSelectable(false); } else { cTimer* t = timerObj->timer; int recPart = timerObj->recDuration * 100 / (timerObj->stop - timerObj->start); - asprintf(&buffer, "%d\t%s\t%d\t%2d%%\t%s", t->Channel()->Number(), t->Channel()->ShortName(true), t->Priority(), recPart, t->File()); + buffer = cString::sprintf("%d\t%s\t%d\t%2d%%\t%s", t->Channel()->Number(), t->Channel()->ShortName(true), t->Priority(), recPart, t->File()); } - SetText(buffer, false); + SetText(buffer); } // --- cMenuConflictCheck ------------------------------------------------------- @@ -82,14 +82,12 @@ void cMenuConflictCheck::Update() else SetHelp(NULL, NULL, NULL, NULL); - char *buffer = NULL; - asprintf(&buffer, "%s - %d/%d %s", tr("Timer conflicts"), + cString buffer = cString::sprintf("%s - %d/%d %s", tr("Timer conflicts"), showAll?conflictCheck.numConflicts:conflictCheck.relevantConflicts, conflictCheck.numConflicts, tr("conflicts")); SetTitle(buffer); Display(); - free(buffer); } bool cMenuConflictCheck::BuildList() @@ -175,7 +173,6 @@ bool cMenuConflictCheckDetailsItem::Update(bool Force) if (Force || hasTimer != oldhasTimer) { cTimer* timer = timerObj->timer; - char* buffer = NULL; char device[2]=""; if (hasTimer) { @@ -185,9 +182,9 @@ bool cMenuConflictCheckDetailsItem::Update(bool Force) strcpy(device, tr("C")); } - asprintf(&buffer, "%s\t%d\t%s - %s\t%d\t%s\t%s", hasTimer?">":"", timer->Channel()->Number(), TIMESTRING(timerObj->start), TIMESTRING(timerObj->stop), timer->Priority(), device, timer->File()); + cString buffer = cString::sprintf("%s\t%d\t%s - %s\t%d\t%s\t%s", hasTimer?">":"", timer->Channel()->Number(), TIMESTRING(timerObj->start), TIMESTRING(timerObj->stop), timer->Priority(), device, timer->File()); - SetText(buffer, false); + SetText(buffer); } return true; } diff --git a/menu_deftimercheckmethod.c b/menu_deftimercheckmethod.c index a6d836a..6edf945 100644 --- a/menu_deftimercheckmethod.c +++ b/menu_deftimercheckmethod.c @@ -27,18 +27,8 @@ The project's page is at http://winni.vdr-developer.org/epgsearch const char *cMenuDefTimerCheckMethod::CheckModes[3]; cDefTimerCheckModes DefTimerCheckModes; -char *cDefTimerCheckMode::buffer = NULL; // -- cDefTimerCheckMode ----------------------------------------------------------------- - -cDefTimerCheckMode::~cDefTimerCheckMode(void) -{ - if (buffer) { - free(buffer); - buffer = NULL; - } -} - bool cDefTimerCheckMode::Parse(const char *s) { char *line; @@ -85,19 +75,16 @@ bool cDefTimerCheckMode::Parse(const char *s) return (parameter >= 2) ? true : false; } -const char *cDefTimerCheckMode::ToText(void) const +cString cDefTimerCheckMode::ToText(void) const { - free(buffer); - asprintf(&buffer, "%s|%d", - *channelID.ToString(), - mode); - return buffer; + cString buffer = cString::sprintf("%s|%d", *channelID.ToString(), mode); + return buffer; } bool cDefTimerCheckMode::Save(FILE *f) { if (mode == 0) return true; // don't save the default - return fprintf(f, "%s\n", ToText()) > 0; + return fprintf(f, "%s\n", *ToText()) > 0; } int cDefTimerCheckModes::GetMode(const cChannel* channel) diff --git a/menu_deftimercheckmethod.h b/menu_deftimercheckmethod.h index abc5ce5..613a6ce 100644 --- a/menu_deftimercheckmethod.h +++ b/menu_deftimercheckmethod.h @@ -31,17 +31,14 @@ The project's page is at http://winni.vdr-developer.org/epgsearch #define UPD_EVENTID 2 class cDefTimerCheckMode : public cListObject { - private: - static char *buffer; public: tChannelID channelID; int mode; cDefTimerCheckMode() : mode(0) {} cDefTimerCheckMode(tChannelID ChannelID, int Mode) : channelID(ChannelID), mode(Mode) {} - ~cDefTimerCheckMode(void); bool Parse(const char *s); - const char *ToText(void) const; + cString ToText(void) const; bool Save(FILE *f); }; diff --git a/menu_dirselect.c b/menu_dirselect.c index b92b8cf..335eeae 100644 --- a/menu_dirselect.c +++ b/menu_dirselect.c @@ -221,7 +221,7 @@ void cMenuDirSelect::Load() free(yellow); yellow = NULL; } - asprintf(&yellow, "%s %d", tr("Button$Level"), (CurLevel==MaxLevel?1:CurLevel+1)); + msprintf(&yellow, "%s %d", tr("Button$Level"), (CurLevel==MaxLevel?1:CurLevel+1)); SetHelp(NULL, NULL, MaxLevel==1?NULL:yellow, tr("Button$Select")); Display(); } diff --git a/menu_favorites.c b/menu_favorites.c index a5c201a..36eb3c3 100644 --- a/menu_favorites.c +++ b/menu_favorites.c @@ -73,10 +73,8 @@ bool cMenuFavorites::BuildList() delete pCompleteSearchResults; } SetHelpKeys(); - char* szTitle = NULL; - asprintf(&szTitle, "%s: %d %s", tr("Favorites"), Count(), tr("Search results")); + cString szTitle = cString::sprintf("%s: %d %s", tr("Favorites"), Count(), tr("Search results")); SetTitle(szTitle); - free(szTitle); Display(); return true; diff --git a/menu_main.c b/menu_main.c index a67ced1..0465301 100644 --- a/menu_main.c +++ b/menu_main.c @@ -85,10 +85,8 @@ int cMenuSearchMain::GetTab(int Tab) void cMenuSearchMain::PrepareSchedule(cChannel *Channel) { Clear(); - char *buffer = NULL; - asprintf(&buffer, "%s - %s", trVDR("Schedule"), Channel->Name()); + cString buffer = cString::sprintf("%s - %s", trVDR("Schedule"), Channel->Name()); SetTitle(buffer); - free(buffer); cMenuTemplate* ScheduleTemplate = cTemplFile::GetTemplateByName("MenuSchedule"); eventObjects.Clear(); @@ -120,12 +118,10 @@ void cMenuSearchMain::PrepareSchedule(cChannel *Channel) struct tm *t_lastevent = localtime_r(&lastEventDate, &tm_rLastEvent); if (t_event->tm_mday != t_lastevent->tm_mday) { - char* szSep = NULL; - asprintf(&szSep, "----------------------------------\t %s ----------------------------------------------------------------------------------------------", GETDATESTRING(Event)); - cOsdItem* pSepItem = new cOsdItem(szSep); - free(szSep); - pSepItem->SetSelectable(false); - Add(pSepItem); + cString szSep = cString::sprintf("----------------------------------\t %s ----------------------------------------------------------------------------------------------", GETDATESTRING(Event)); + cOsdItem* pSepItem = new cOsdItem(szSep); + pSepItem->SetSelectable(false); + Add(pSepItem); } lastEventDate = EventDate; } @@ -140,10 +136,9 @@ void cMenuSearchMain::PrepareSchedule(cChannel *Channel) } if (shiftTime) { - char *buffer = NULL; - asprintf(&buffer, "%s (%s%dh %dm)", Channel->Name(), shiftTime>0?"+":"", shiftTime/60, abs(shiftTime)%60); - SetTitle(buffer); - free(buffer); + cString buffer = cString::sprintf("%s (%s%dh %dm)", Channel->Name(), shiftTime>0?"+":"", + shiftTime/60, abs(shiftTime)%60); + SetTitle(buffer); } } diff --git a/menu_myedittimer.c b/menu_myedittimer.c index 078c3b8..ffe86bb 100644 --- a/menu_myedittimer.c +++ b/menu_myedittimer.c @@ -76,42 +76,40 @@ cMenuMyEditTimer::cMenuMyEditTimer(cTimer *Timer, bool New, const cEvent* Event, void cMenuMyEditTimer::SplitFile() { - char* tmp = strrchr(file, '~'); - if (tmp) // split file in real file and directory + char* tmp = strrchr(file, '~'); + if (tmp) // split file in real file and directory { - if (event && !isempty(event->ShortText())) + if (event && !isempty(event->ShortText())) { - char* eventFile = NULL; - asprintf(&eventFile, "%s~%s", event->Title(), event->ShortText()); - char* tmp2 = strstr(file, eventFile); - free(eventFile); - if (tmp2) // file contains title and subtitle + cString eventFile = cString::sprintf("%s~%s", event->Title(), event->ShortText()); + char* tmp2 = strstr(file, eventFile); + if (tmp2) // file contains title and subtitle { - if (tmp2 > file) + if (tmp2 > file) { - *(tmp2-1) = 0; - strcpy(directory, file); - strcpy(file, tmp2); + *(tmp2-1) = 0; + strcpy(directory, file); + strcpy(file, tmp2); } - else - *directory = 0; + else + *directory = 0; } - else + else { - *tmp = 0; - strcpy(directory, file); - strcpy(file, tmp+1); + *tmp = 0; + strcpy(directory, file); + strcpy(file, tmp+1); } } - else + else { - *tmp = 0; - strcpy(directory, file); - strcpy(file, tmp+1); + *tmp = 0; + strcpy(directory, file); + strcpy(file, tmp+1); } } - else - *directory = 0; + else + *directory = 0; } void cMenuMyEditTimer::Set() @@ -125,10 +123,8 @@ void cMenuMyEditTimer::Set() #ifdef USE_PINPLUGIN if (cOsd::pinValid) Add(new cMenuEditChanItem(tr("Channel"), &channel)); else { - char* buf = 0; - asprintf(&buf, "%s\t%s", tr("Channel"), Channels.GetByNumber(channel)->Name()); - Add(new cOsdItem(buf)); - free(buf); + cSting buf = cString::sprintf("%s\t%s", tr("Channel"), Channels.GetByNumber(channel)->Name()); + Add(new cOsdItem(buf)); } #else Add(new cMenuEditChanItem(trVDR("Channel"), &channel)); @@ -146,10 +142,8 @@ void cMenuMyEditTimer::Set() #ifdef USE_PINPLUGIN if (cOsd::pinValid || !fskProtection) Add(new cMenuEditBoolItem(tr("Childlock"),&fskProtection)); else { - char* buf = 0; - asprintf(&buf, "%s\t%s", tr("Childlock"), fskProtection ? trVDR("yes") : trVDR("no")); - Add(new cOsdItem(buf)); - free(buf); + cString buf = cString::sprintf("%s\t%s", tr("Childlock"), fskProtection ? trVDR("yes") : trVDR("no")); + Add(new cOsdItem(buf)); } #endif Add(new cMenuEditStrItem( trVDR("File"), file, MaxFileName, trVDR(FileNameChars))); @@ -179,10 +173,8 @@ void cMenuMyEditTimer::Set() cOsdItem* pInfoItem = new cOsdItem(""); pInfoItem->SetSelectable(false); Add(pInfoItem); - char* info = NULL; - asprintf(&info, "%s: %d/%d", tr("recording with device"), deviceNr, cDevice::NumDevices()); + cString info = cString::sprintf("%s: %d/%d", tr("recording with device"), deviceNr, cDevice::NumDevices()); pInfoItem = new cOsdItem(info); - free(info); pInfoItem->SetSelectable(false); Add(pInfoItem); } @@ -381,9 +373,9 @@ eOSState cMenuMyEditTimer::ProcessKey(eKeys Key) if (timer) { - char* cmdbuf = NULL; + cString cmdbuf; if (addIfConfirmed) - asprintf(&cmdbuf, "NEWT %d:%d:%s:%04d:%04d:%d:%d:%s%s%s:%s", + cmdbuf = cString::sprintf("NEWT %d:%d:%s:%04d:%04d:%d:%d:%s%s%s:%s", flags, ch->Number(), #if VDRVERSNUM < 10503 @@ -400,7 +392,7 @@ eOSState cMenuMyEditTimer::ProcessKey(eKeys Key) tmpFile, fullaux.c_str()); else - asprintf(&cmdbuf, "MODT %d %d:%d:%s:%04d:%04d:%d:%d:%s%s%s:%s", + cmdbuf = cString::sprintf("MODT %d %d:%d:%s:%04d:%04d:%d:%d:%s%s%s:%s", timer->Index()+1, flags, ch->Number(), @@ -421,7 +413,6 @@ eOSState cMenuMyEditTimer::ProcessKey(eKeys Key) cTimerThread timerThread; timerThread.Init(cmdbuf); - free(cmdbuf); free(tmpFile); free(tmpDir); diff --git a/menu_recsdone.c b/menu_recsdone.c index 0a52616..be5b46a 100644 --- a/menu_recsdone.c +++ b/menu_recsdone.c @@ -44,7 +44,7 @@ void cMenuRecDoneItem::Set() tm *tm = localtime_r(&recDone->startTime, &tm_r); strftime(buf, sizeof(buf), "%d.%m.%y %H:%M", tm); - asprintf(&buffer, "%s\t%s~%s", buf, recDone->title && !showEpisodeOnly?recDone->title:"", + msprintf(&buffer, "%s\t%s~%s", buf, recDone->title && !showEpisodeOnly?recDone->title:"", recDone->shortText?recDone->shortText:""); SetText(buffer, false); } @@ -53,17 +53,13 @@ int cMenuRecDoneItem::Compare(const cListObject &ListObject) const { cMenuRecDoneItem *p = (cMenuRecDoneItem *)&ListObject; if (sortModeRecDone == 0) // sort by Date - if (recDone->startTime > p->recDone->startTime) return 1; else return -1; + if (recDone->startTime < p->recDone->startTime) return 1; else return -1; else { - char* s1 = NULL; - char* s2 = NULL; - asprintf(&s1, "%s~%s", recDone->title?recDone->title:"", recDone->shortText?recDone->shortText:""); - asprintf(&s2, "%s~%s", p->recDone->title?p->recDone->title:"", p->recDone->shortText?p->recDone->shortText:""); - int res = strcasecmp(s1, s2); - free(s1); - free(s2); - return res; + cString s1 = cString::sprintf("%s~%s", recDone->title?recDone->title:"", recDone->shortText?recDone->shortText:""); + cString s2 = cString::sprintf("%s~%s", p->recDone->title?p->recDone->title:"", p->recDone->shortText?p->recDone->shortText:""); + int res = strcasecmp(s1, s2); + return res; } } @@ -103,11 +99,9 @@ cRecDone *cMenuRecsDone::CurrentRecDone(void) void cMenuRecsDone::UpdateTitle() { - char *buffer = NULL; - asprintf(&buffer, "%d %s%s%s", Count(), tr("Recordings"), showAll?"":" ", showAll?"":search->search); - SetTitle(buffer); - Display(); - free(buffer); + cString buffer = cString::sprintf("%d %s%s%s", Count(), tr("Recordings"), showAll?"":" ", showAll?"":search->search); + SetTitle(buffer); + Display(); } eOSState cMenuRecsDone::Delete(void) diff --git a/menu_search.c b/menu_search.c index 9b2dd3d..8a70687 100644 --- a/menu_search.c +++ b/menu_search.c @@ -130,11 +130,9 @@ void cMenuEPGSearchExt::UpdateTitle() total++; } - char *buffer = NULL; - asprintf(&buffer, "%s (%d/%d %s)", tr("Search entries"), active, total, tr("active")); + cString buffer = cString::sprintf("%s (%d/%d %s)", tr("Search entries"), active, total, tr("active")); SetTitle(buffer); Display(); - free(buffer); } cSearchExt *cMenuEPGSearchExt::CurrentSearchExt(void) diff --git a/menu_searchedit.c b/menu_searchedit.c index 3766183..d1d9bd1 100644 --- a/menu_searchedit.c +++ b/menu_searchedit.c @@ -337,10 +337,8 @@ void cMenuEditSearchExt::Set() index++; } - char* itemtext = NULL; - asprintf(&itemtext, "%s (%d/%d)", tr("Compare categories"), iUsed, SearchExtCats.Count()); + cString itemtext = cString::sprintf("%s (%d/%d)", tr("Compare categories"), iUsed, SearchExtCats.Count()); Add(new cOsdItem(IndentMenuItem(IndentMenuItem(itemtext)))); - free(itemtext); } } @@ -399,7 +397,7 @@ eOSState cMenuEditSearchExt::Help() if(Current() < (int) helpTexts.size()) { char* title = NULL; - asprintf(&title, "%s - %s", tr("Button$Help"), ItemText); + msprintf(&title, "%s - %s", tr("Button$Help"), ItemText); if (strchr(title, ':')) *strchr(title, ':') = 0; state = AddSubMenu(new cMenuText(title, helpTexts[Current()])); @@ -628,7 +626,7 @@ eOSState cMenuEditSearchExt::ProcessKey(eKeys Key) if (SearchExtCat->searchmode >= 10) { if (searchExt->catvalues[index]) free(searchExt->catvalues[index]); - asprintf(&searchExt->catvalues[index], "%d", catvaluesNumeric[index]); + msprintf(&searchExt->catvalues[index], "%d", catvaluesNumeric[index]); } SearchExtCat = SearchExtCats.Next(SearchExtCat); index++; @@ -805,10 +803,8 @@ cMenuSearchEditCompCats::cMenuSearchEditCompCats(int* catarrayAvoidRepeats) while (SearchExtCat) { edit_catarrayAvoidRepeats[index] = catarrayAvoidRepeats[index]; - char* menutext = NULL; - asprintf(&menutext, "%s %s", tr("Compare"), SearchExtCat->menuname); + cString menutext = cString::sprintf("%s %s", tr("Compare"), SearchExtCat->menuname); Add(new cMenuEditBoolItem(menutext, &edit_catarrayAvoidRepeats[index], trVDR("no"), trVDR("yes"))); - free(menutext); SearchExtCat = SearchExtCats.Next(SearchExtCat); index++; } @@ -1052,20 +1048,15 @@ void cMenuCatValuesSelect::Set() { for(int i=0; i<SearchExtCat->nvalues; i++) { - char* entry = NULL; - asprintf(&entry, "%c\t%s", sel_cats[i]?'*':' ', SearchExtCat->values[i]); - if (sel_cats[i]) selCount++; - Add(new cOsdItem(entry)); - free(entry); + cString entry = cString::sprintf("%c\t%s", sel_cats[i]?'*':' ', SearchExtCat->values[i]); + if (sel_cats[i]) selCount++; + Add(new cOsdItem(entry)); } } SetCurrent(Get(current)); - char *title = NULL; - asprintf(&title, "%s (%d/%d)", tr("Values for EPG category"), selCount, SearchExtCat->nvalues); + cString title = cString::sprintf("%s (%d/%d)", tr("Values for EPG category"), selCount, SearchExtCat->nvalues); SetTitle(title); Display(); - free(title); - } eOSState cMenuCatValuesSelect::ProcessKey(eKeys Key) diff --git a/menu_searchresults.c b/menu_searchresults.c index 6190a1e..e7e7753 100644 --- a/menu_searchresults.c +++ b/menu_searchresults.c @@ -467,10 +467,9 @@ bool cMenuSearchResultsForSearch::BuildList() if (Count()) SetCurrent(Get(0)); SetHelpKeys(true); - char* szTitle = NULL; - asprintf(&szTitle, "%d %s - %s", Count(), tr("Search results"), searchExt->search); + + cString szTitle = cString::sprintf("%d %s - %s", Count(), tr("Search results"), searchExt->search); SetTitle(szTitle); - free(szTitle); SetCurrent(Get(current)); Display(); @@ -583,10 +582,8 @@ bool cMenuSearchResultsForBlacklist::BuildList() if (Count()) SetCurrent(Get(0)); SetHelpKeys(); - char* szTitle = NULL; - asprintf(&szTitle, "%d %s - %s", Count(), tr("Blacklist results"), blacklist->search); + cString szTitle = cString::sprintf("%d %s - %s", Count(), tr("Blacklist results"), blacklist->search); SetTitle(szTitle); - free(szTitle); SetCurrent(Get(current)); Display(); @@ -819,10 +816,8 @@ cMenuSearchResultsForList::cMenuSearchResultsForList(cSearchResults& SearchResul BuildList(); - char* szTitle = NULL; - asprintf(&szTitle, Title, Count()); + cString szTitle = cString::sprintf(Title, Count()); SetTitle(szTitle); - free(szTitle); } void cMenuSearchResultsForList::SetHelpKeys(bool Force) diff --git a/menu_switchtimers.c b/menu_switchtimers.c index e3c7e3e..25164d3 100644 --- a/menu_switchtimers.c +++ b/menu_switchtimers.c @@ -54,10 +54,9 @@ void cMenuEditSwitchTimer::Set() Clear(); Add(new cMenuEditIntItem(tr("Switch ... minutes before start"), &data.switchMinsBefore, 0, 99)); - char* info = NULL; - asprintf(&info, "%s:\t%s", tr("action at"), TIMESTRING(data.event->StartTime() - 60 * data.switchMinsBefore)); + cString info = cString::sprintf("%s:\t%s", tr("action at"), + TIMESTRING(data.event->StartTime() - 60 * data.switchMinsBefore)); cOsdItem* pInfoItem = new cOsdItem(info); - free(info); pInfoItem->SetSelectable(false); Add(pInfoItem); Add(new cMenuEditBoolItem(tr("Announce only"), &data.announceOnly, trVDR("no"), trVDR("yes"))); @@ -123,7 +122,7 @@ void cMenuSwitchTimerItem::Set(void) cChannel* channel = Channels.GetByChannelID(event->ChannelID(),true,true); - asprintf(&buffer, "%s\t%d\t%s\t%s\t%d\'\t%s~%s", switchTimer->announceOnly?"":">", channel?channel->Number():-1, datebuf, TIMESTRING(startTime), switchTimer->switchMinsBefore, event->Title()?event->Title():"", event->ShortText()?event->ShortText():""); + msprintf(&buffer, "%s\t%d\t%s\t%s\t%d\'\t%s~%s", switchTimer->announceOnly?"":">", channel?channel->Number():-1, datebuf, TIMESTRING(startTime), switchTimer->switchMinsBefore, event->Title()?event->Title():"", event->ShortText()?event->ShortText():""); SetText(buffer, false); } diff --git a/menu_templateedit.c b/menu_templateedit.c index cfe6c97..3eb9550 100644 --- a/menu_templateedit.c +++ b/menu_templateedit.c @@ -238,7 +238,7 @@ eOSState cMenuEditTemplate::ProcessKey(eKeys Key) if (SearchExtCat->searchmode >= 10) { if (searchExt->catvalues[index]) free(searchExt->catvalues[index]); - asprintf(&searchExt->catvalues[index], "%d", catvaluesNumeric[index]); + msprintf(&searchExt->catvalues[index], "%d", catvaluesNumeric[index]); } SearchExtCat = SearchExtCats.Next(SearchExtCat); index++; diff --git a/menu_timersdone.c b/menu_timersdone.c index d71e6c9..1e6bb7c 100644 --- a/menu_timersdone.c +++ b/menu_timersdone.c @@ -45,7 +45,7 @@ void cMenuTimerDoneItem::Set(void) strftime(buf, sizeof(buf), "%d.%m.%y %H:%M", tm); const cChannel* ch = Channels.GetByChannelID(timerDone->channelID, true, true); - asprintf(&buffer, "%d\t%s\t%s~%s", ch?ch->Number():0, buf, timerDone->title.c_str(), timerDone->shorttext.c_str()); + msprintf(&buffer, "%d\t%s\t%s~%s", ch?ch->Number():0, buf, timerDone->title.c_str(), timerDone->shorttext.c_str()); SetText(buffer, false); } @@ -56,14 +56,10 @@ int cMenuTimerDoneItem::Compare(const cListObject &ListObject) const if (timerDone->start > p->timerDone->start) return 1; else return -1; else { - char* s1 = NULL; - char* s2 = NULL; - asprintf(&s1, "%s~%s", timerDone->title.c_str(), timerDone->shorttext.c_str()); - asprintf(&s2, "%s~%s", p->timerDone->title.c_str(), p->timerDone->shorttext.c_str()); - int res = strcasecmp(s1, s2); - free(s1); - free(s2); - return res; + cString s1 = cString::sprintf("%s~%s", timerDone->title.c_str(), timerDone->shorttext.c_str()); + cString s2 = cString::sprintf("%s~%s", p->timerDone->title.c_str(), p->timerDone->shorttext.c_str()); + int res = strcasecmp(s1, s2); + return res; } } @@ -129,11 +125,9 @@ cTimerDone *cMenuTimersDone::CurrentTimerDone(void) void cMenuTimersDone::UpdateTitle() { - char *buffer = NULL; - asprintf(&buffer, "%d %s%s%s", Count(), tr("Timers"), showAll?"":" ", showAll?"":search->search); - SetTitle(buffer); - Display(); - free(buffer); + cString buffer = cString::sprintf("%d %s%s%s", Count(), tr("Timers"), showAll?"":" ", showAll?"":search->search); + SetTitle(buffer); + Display(); } eOSState cMenuTimersDone::Delete(void) diff --git a/menu_whatson.c b/menu_whatson.c index a36bd6b..ad54b3a 100644 --- a/menu_whatson.c +++ b/menu_whatson.c @@ -267,7 +267,7 @@ void cMenuWhatsOnSearch::LoadSchedules() eventObjects.Clear(); // time_t SeekTime; - char* szTitle = NULL; + cString szTitle; cShowMode* mode = GetShowMode(currentShowMode); if (shiftTime != 0) @@ -288,9 +288,9 @@ void cMenuWhatsOnSearch::LoadSchedules() tm tm_seek = *localtime_r(&seekTime, &tm_r); tm tm_now = *localtime_r(&now, &tm_r); if (tm_seek.tm_mday != tm_now.tm_mday) - asprintf(&szTitle, "%s - %s", tr("Overview"), DAYDATETIME(seekTime)); + szTitle = cString::sprintf("%s - %s", tr("Overview"), DAYDATETIME(seekTime)); else - asprintf(&szTitle, "%s - %02d:%02d", tr("Overview"), tm_seek.tm_hour, tm_seek.tm_min); + szTitle = cString::sprintf("%s - %02d:%02d", tr("Overview"), tm_seek.tm_hour, tm_seek.tm_min); } else { @@ -300,14 +300,13 @@ void cMenuWhatsOnSearch::LoadSchedules() if (seekTime < time(NULL) && currentShowMode != showNow && currentShowMode != showNext) { seekTime += HOURS2SECS(24); - asprintf(&szTitle, "%s - %s (%s)", tr("Overview"), mode->GetDescription(), *WeekDayName(seekTime)); + szTitle = cString::sprintf("%s - %s (%s)", tr("Overview"), mode->GetDescription(), *WeekDayName(seekTime)); } else - asprintf(&szTitle, "%s - %s", tr("Overview"), mode->GetDescription()); + szTitle = cString::sprintf("%s - %s", tr("Overview"), mode->GetDescription()); } } SetTitle(szTitle); - free(szTitle); cMenuTemplate* currentTemplate = NULL; if (currentShowMode == showNow) @@ -365,10 +364,8 @@ void cMenuWhatsOnSearch::LoadSchedules() { if (EPGSearchConfig.showChannelGroups && strlen(Channel->Name())) { - char* szGroup = NULL; - asprintf(&szGroup, "----------------------------------------\t %s ----------------------------------------------------------------------------------------------", Channel->Name()); + cString szGroup = cString::sprintf("----------------------------------------\t %s ----------------------------------------------------------------------------------------------", Channel->Name()); cOsdItem* pGroupItem = new cOsdItem(szGroup); - free(szGroup); pGroupItem->SetSelectable(false); Add(pGroupItem); } diff --git a/noannounce.c b/noannounce.c index 9d87bdd..a22bf1d 100644 --- a/noannounce.c +++ b/noannounce.c @@ -120,7 +120,7 @@ bool cNoAnnounce::Parse(const char *s) const char *cNoAnnounce::ToText(void) const { free(buffer); - asprintf(&buffer, "%s:%s:%s:%ld:%ld", + msprintf(&buffer, "%s:%s:%s:%ld:%ld", ReplaceAll(title, ":", "|").c_str(), ReplaceAll(shortText, ":", "|").c_str(), *channelID.ToString(), @@ -197,7 +197,7 @@ const char *cRecDone::ToText(void) if (!channel) LogFile.Log(3,"invalid channel in recs done!"); - asprintf(&buffer, "R %ld %d %d\nC %s\n%s%s%s%s%s%s%s%s%s%s%s%sr", + msprintf(&buffer, "R %ld %d %d\nC %s\n%s%s%s%s%s%s%s%s%s%s%s%sr", startTime, duration, searchID, channel?CHANNELSTRING(channel):"", title?"T ":"",title?title:"", title?"\n":"", diff --git a/searchtimer_thread.c b/searchtimer_thread.c index d376071..7a800c6 100644 --- a/searchtimer_thread.c +++ b/searchtimer_thread.c @@ -312,7 +312,7 @@ void cSearchTimerThread::Action(void) } char* pFile = NULL; // File is prepared for svdrp, so prepare t->File for comparision too - asprintf(&pFile, "%s", t->File()); + msprintf(&pFile, "%s", t->File()); pFile = strreplace(pFile, ':', '|'); pFile = strreplace(pFile, " ~", "~"); pFile = strreplace(pFile, "~ ", "~"); @@ -447,14 +447,12 @@ void cSearchTimerThread::Action(void) if (announceList.Count() > 0) { - char* msgfmt = NULL; - asprintf(&msgfmt, tr("%d new broadcast(s) found! Show them?"), announceList.Count()); - if (SendMsg(msgfmt, true,7) == kOk) - { - m_plugin->showAnnounces = true; - cRemote::CallPlugin("epgsearch"); - } - free(msgfmt); + cString msgfmt = cString::sprintf(tr("%d new broadcast(s) found! Show them?"), announceList.Count()); + if (SendMsg(msgfmt, true,7) == kOk) + { + m_plugin->showAnnounces = true; + cRemote::CallPlugin("epgsearch"); + } } LogFile.iSysLog("search timer update finished"); @@ -474,9 +472,9 @@ void cSearchTimerThread::Action(void) mailNotifier.SendConflictNotifications(conflictCheck); } - char* msgfmt = NULL; - asprintf(&msgfmt, tr("%d timer conflict(s)! First at %s. Show them?"), conflictCheck.relevantConflicts, - *DateTime(conflictCheck.nextRelevantConflictDate)); + cString msgfmt = cString::sprintf(tr("%d timer conflict(s)! First at %s. Show them?"), + conflictCheck.relevantConflicts, + *DateTime(conflictCheck.nextRelevantConflictDate)); bool doMessage = EPGSearchConfig.noConflMsgWhileReplay == 0 || !cDevice::PrimaryDevice()->Replaying() || conflictCheck.nextRelevantConflictDate - now < 2*60*60; @@ -485,7 +483,6 @@ void cSearchTimerThread::Action(void) m_plugin->showConflicts = true; cRemote::CallPlugin("epgsearch"); } - free(msgfmt); } LogFile.iSysLog("check for timer conflicts - done"); @@ -537,7 +534,7 @@ char* cSearchTimerThread::SummaryExtended(cSearchExt* searchExt, cTimer* Timer, time_t stop = eStop + (UseVPS?0:(searchExt->MarginStop * 60)); char* addSummaryFooter = NULL; - asprintf(&addSummaryFooter, "<channel>%d - %s</channel><searchtimer>%s</searchtimer><start>%ld</start><stop>%ld</stop><s-id>%d</s-id><eventid>%ld</eventid>", + msprintf(&addSummaryFooter, "<channel>%d - %s</channel><searchtimer>%s</searchtimer><start>%ld</start><stop>%ld</stop><s-id>%d</s-id><eventid>%ld</eventid>", Timer->Channel()->Number(), CHANNELNAME(Timer->Channel()), searchExt->search, start, @@ -561,7 +558,7 @@ char* cSearchTimerThread::SummaryExtended(cSearchExt* searchExt, cTimer* Timer, } char* tmpSummary = NULL; - asprintf(&tmpSummary, "<epgsearch>%s</epgsearch>%s", addSummaryFooter, tmpaux?tmpaux:""); + msprintf(&tmpSummary, "<epgsearch>%s</epgsearch>%s", addSummaryFooter, tmpaux?tmpaux:""); free(addSummaryFooter); if (tmpaux) free(tmpaux); return tmpSummary; @@ -608,7 +605,7 @@ bool cSearchTimerThread::AddModTimer(cTimer* Timer, int index, cSearchExt* searc tmpSummary = SummaryExtended(searchExt, Timer, pEvent); if (index==0) - asprintf(&cmdbuf, "NEWT %d:%d:%s:%s:%s:%d:%d:%s:%s", + msprintf(&cmdbuf, "NEWT %d:%d:%s:%s:%s:%d:%d:%s:%s", Flags, Timer->Channel()->Number(), #if VDRVERSNUM < 10503 @@ -623,7 +620,7 @@ bool cSearchTimerThread::AddModTimer(cTimer* Timer, int index, cSearchExt* searc Timer->File(), tmpSummary?tmpSummary:""); else - asprintf(&cmdbuf, "MODT %d %d:%d:%s:%s:%s:%d:%d:%s:%s", + msprintf(&cmdbuf, "MODT %d %d:%d:%s:%s:%s:%d:%d:%s:%s", index, Flags, Timer->Channel()->Number(), @@ -680,12 +677,9 @@ void cSearchTimerThread::RemoveTimer(cTimer* t, const cEvent* e) void cSearchTimerThread::DelRecording(int index) { - char *cmdbuf = NULL; // first LSTR required - asprintf(&cmdbuf, "DELR %d", index); - LogFile.Log(2, "delete recording %d", index); - SendViaSVDRP(cmdbuf); - - free(cmdbuf); + cString cmdbuf = cString::sprintf("DELR %d", index); + LogFile.Log(2, "delete recording %d", index); + SendViaSVDRP(cmdbuf); } void cSearchTimerThread::CheckExpiredRecs() @@ -773,7 +767,7 @@ void cSearchTimerThread::ModifyManualTimer(const cEvent* event, const cTimer* ti strftime(stopbuffer, DAYBUFFERSIZE, "%H%M", &tm_r_stop); char* cmdbuf = NULL; - asprintf(&cmdbuf, "MODT %d %d:%d:%s:%s:%s:%d:%d:%s:%s", + msprintf(&cmdbuf, "MODT %d %d:%d:%s:%s:%s:%d:%d:%s:%s", timer->Index()+1, timer->Flags(), timer->Channel()->Number(), @@ -124,7 +124,6 @@ std::list<std::string> cEpgsearchServiceHandler::TranslateResults(cSearchResults { const cEvent* pEvent = result->event; cTimer* Timer = new cTimer(pEvent); - char *cmdbuf = NULL; static char bufStart[25]; static char bufEnd[25]; @@ -160,7 +159,7 @@ std::list<std::string> cEpgsearchServiceHandler::TranslateResults(cSearchResults std::string description = pEvent->Description()?ReplaceAll(pEvent->Description(), "|", "!^pipe!^"):""; description = ReplaceAll(description, ":", "|"); - asprintf(&cmdbuf, "%d:%u:%s:%s:%s:%ld:%ld:%s:%ld:%ld:%s:%d", + cString cmdbuf = cString::sprintf("%d:%u:%s:%s:%s:%ld:%ld:%s:%ld:%ld:%s:%d", result->search->ID, pEvent->EventID(), title.c_str(), @@ -174,8 +173,8 @@ std::list<std::string> cEpgsearchServiceHandler::TranslateResults(cSearchResults timerMode>0?result->search->BuildFile(pEvent):"", timerMode); - list.push_back(cmdbuf); - free(cmdbuf); + list.push_back(*cmdbuf); + delete(Timer); result = pCompleteSearchResults->Next(result); } diff --git a/svdrpclient.h b/svdrpclient.h index 10bdbae..177ce1f 100644 --- a/svdrpclient.h +++ b/svdrpclient.h @@ -91,21 +91,18 @@ public: } } - bool SendCmd(char* cmd) + bool SendCmd(const char* cmd) { if (!bConnected) return false; - char* szCmd = NULL; - - asprintf(&szCmd, "%s\r\n", cmd); - Send(szCmd); - free(szCmd); + cString szCmd = cString::sprintf("%s\r\n", cmd); + Send(*szCmd); bool cmdret = (Receive() == CMDSUCCESS); - asprintf(&szCmd, "QUIT\r\n"); + szCmd = cString::sprintf("QUIT\r\n"); Send(szCmd); - free(szCmd); + long rc = 0; if ((rc = Receive()) != SVDRPDISCONNECT) LogFile.eSysLog("could not disconnect (%ld)!", rc); @@ -113,7 +110,7 @@ public: close(sock); return cmdret; } - bool Send(char* szSend) + bool Send(const char* szSend) { int length = strlen(szSend); int sent = 0; @@ -147,7 +144,7 @@ public: return -1; } char* Temp = NULL; - asprintf(&Temp, "%s%c", csResp, ch); + msprintf(&Temp, "%s%c", csResp, ch); free(csResp); csResp = Temp; } diff --git a/switchtimer.c b/switchtimer.c index 7293ad2..53e44e2 100644 --- a/switchtimer.c +++ b/switchtimer.c @@ -117,7 +117,7 @@ bool cSwitchTimer::Parse(const char *s) return (parameter >= 3) ? true : false; } -const char *cSwitchTimer::ToText(bool& ignore) +cString cSwitchTimer::ToText(bool& ignore) { ignore = false; if (!event) @@ -127,17 +127,19 @@ const char *cSwitchTimer::ToText(bool& ignore) } cChannel *channel = Channels.GetByChannelID(event->ChannelID(), true, true); if (!channel) return NULL; - char* buffer = NULL; - asprintf(&buffer, "%s:%u:%ld:%d:%d:%d", CHANNELSTRING(channel), event->EventID(), event->StartTime(), switchMinsBefore, announceOnly?1:0, unmute?1:0); + cString buffer = cString::sprintf("%s:%u:%ld:%d:%d:%d", + CHANNELSTRING(channel), event->EventID(), + event->StartTime(), switchMinsBefore, + announceOnly?1:0, unmute?1:0); return buffer; } bool cSwitchTimer::Save(FILE *f) { bool ignore = false; - const char* buffer = ToText(ignore); + cString buffer = ToText(ignore); if (!ignore) - return fprintf(f, "%s\n", buffer) > 0; + return fprintf(f, "%s\n", *buffer) > 0; return true; } diff --git a/switchtimer.h b/switchtimer.h index 7ef925f..b0e9a4f 100644 --- a/switchtimer.h +++ b/switchtimer.h @@ -37,7 +37,7 @@ public: cSwitchTimer(void); cSwitchTimer(const cEvent* Event, int SwitchMinsBefore=1, int announceOnly=0, int unmute=0); bool Parse(const char *s); - const char *ToText(bool& ignore); + cString ToText(bool& ignore); bool Save(FILE *f); }; diff --git a/switchtimer_thread.c b/switchtimer_thread.c index f8e10d8..3a48705 100644 --- a/switchtimer_thread.c +++ b/switchtimer_thread.c @@ -95,18 +95,15 @@ void cSwitchTimerThread::Action(void) if (doswitch) { LogFile.Log(1,"switching to channel %d", channel->Number()); - char* cmd = NULL; - asprintf(&cmd, "CHAN %d", channel->Number()); + cString cmd = cString::sprintf("CHAN %d", channel->Number()); SendViaSVDRP(cmd); - free(cmd); if (switchTimer->unmute && cDevice::PrimaryDevice()->IsMute()) cDevice::PrimaryDevice()->ToggleMute(); } - char* Message = NULL; - asprintf(&Message, "%s: %s - %s", event->Title(), CHANNELNAME(channel), GETTIMESTRING(event)); + cString Message = cString::sprintf("%s: %s - %s", event->Title(), + CHANNELNAME(channel), GETTIMESTRING(event)); SendMsg(Message); - free(Message); sleepSec(MSG_DELAY); } SwitchTimers.Save(); diff --git a/templatefile.c b/templatefile.c index 7630fe4..2f7e27f 100644 --- a/templatefile.c +++ b/templatefile.c @@ -36,7 +36,7 @@ bool cMenuTemplate::PrepareTemplate(const char* templateLine) char *pstrSearchToken, *pptr; char *pstrSearch=strdup(templateLine); pstrSearchToken=strtok_r(pstrSearch, "|", &pptr); - char* stripped = NULL; + cString stripped; int iToken = 0; while(pstrSearchToken) { @@ -58,14 +58,12 @@ bool cMenuTemplate::PrepareTemplate(const char* templateLine) return false; } *tmp = 0; - if (!stripped) + if (isempty(stripped)) stripped = strdup(pstrSearchToken); else { - char* tmp = stripped; - stripped = NULL; - asprintf(&stripped, "%s|%s", tmp, pstrSearchToken); - free(tmp); + cString tmp = stripped; + stripped = cString::sprintf("%s|%s", *tmp, pstrSearchToken); } pstrSearchToken=strtok_r(NULL, "|", &pptr); } @@ -74,9 +72,9 @@ bool cMenuTemplate::PrepareTemplate(const char* templateLine) // no limit for the last column if (iToken>0) menuTabs[iToken-1] = 0; - if (stripped) + if (!isempty(stripped)) { - menuTemplate = stripped; + menuTemplate = strdup(stripped); // the status variables are handled in menu_whatson.c itself // to speedup the var-parser we 'hide' them here in renaming them menuTemplate = strreplacei(menuTemplate, "%status%", "$status$"); diff --git a/timer_thread.c b/timer_thread.c index b3f1e07..d47df5f 100644 --- a/timer_thread.c +++ b/timer_thread.c @@ -40,21 +40,18 @@ cTimerThread::cTimerThread() : cThread("EPGSearch: timer") { m_Active = false; - m_cmd = NULL; } cTimerThread::~cTimerThread() { if (m_Active) Stop(); - if (m_cmd) - free(m_cmd); cTimerThread::m_Instance = NULL; } -void cTimerThread::Init(char* cmd) { +void cTimerThread::Init(cString cmd) { if (m_Instance == NULL) { m_Instance = new cTimerThread; - m_Instance->m_cmd = strdup(cmd); + m_Instance->m_cmd = cmd; m_Instance->Start(); } } diff --git a/timer_thread.h b/timer_thread.h index 09d90fa..a4ee1f2 100644 --- a/timer_thread.h +++ b/timer_thread.h @@ -41,7 +41,7 @@ typedef enum class cTimerThread: public cThread { private: static cTimerThread *m_Instance; - char* m_cmd; + cString m_cmd; static TimerThreadStatus m_Status; protected: virtual void Action(void); @@ -52,7 +52,7 @@ public: void SetStatus(TimerThreadStatus Status) { LogFile.eSysLog("%d", int(Status)); cTimerThread::m_Status = Status; } cTimerThread(); virtual ~cTimerThread(); - void Init(char*); + void Init(cString); void Exit(void); }; diff --git a/timerdone.c b/timerdone.c index 52dddd0..0685f7b 100644 --- a/timerdone.c +++ b/timerdone.c @@ -28,12 +28,10 @@ The project's page is at http://winni.vdr-developer.org/epgsearch using std::string; cTimersDone TimersDone; -char *cTimerDone::buffer = NULL; // -- cTimerDone ----------------------------------------------------------------- cTimerDone::cTimerDone(void) { start = stop = 0; - buffer = NULL; searchID = -1; } @@ -48,15 +46,6 @@ cTimerDone::cTimerDone(const time_t Start, const time_t Stop, const cEvent* pEve shorttext = pEvent->ShortText()?pEvent->ShortText():""; } searchID = SearchID; - buffer = NULL; -} - -cTimerDone::~cTimerDone(void) -{ - if (buffer) { - free(buffer); - buffer = NULL; - } } bool cTimerDone::operator== (const cTimerDone &arg) const @@ -133,13 +122,12 @@ bool cTimerDone::Parse(const char *s) return (parameter >= 6) ? true : false; } -const char *cTimerDone::ToText(void) const +cString cTimerDone::ToText(void) const { - free(buffer); cChannel *channel = Channels.GetByChannelID(channelID, true, true); string info = string(DAYDATETIME(start)) + " - " + string(channel?channel->Name():""); - asprintf(&buffer, "%s:%ld:%ld:%d:%s:%s:%s", + cString buffer = cString::sprintf("%s:%ld:%ld:%d:%s:%s:%s", *channelID.ToString(), start, stop, @@ -152,7 +140,7 @@ const char *cTimerDone::ToText(void) const bool cTimerDone::Save(FILE *f) { - return fprintf(f, "%s\n", ToText()) > 0; + return fprintf(f, "%s\n", *ToText()) > 0; } const cEvent* cTimerDone::GetEvent() const diff --git a/timerdone.h b/timerdone.h index 2c4faa1..682e5fb 100644 --- a/timerdone.h +++ b/timerdone.h @@ -39,16 +39,13 @@ public: string title; string shorttext; - static char *buffer; - cTimerDone(); cTimerDone(const time_t Start, const time_t Stop, const cEvent* pEvent, const int SearchID); - ~cTimerDone(); bool operator== (const cTimerDone &arg) const; static bool Read(FILE *f); bool Parse(const char *s); - const char *ToText(void) const; + cString ToText(void) const; bool Save(FILE *f); const cEvent* GetEvent() const; }; @@ -235,33 +235,30 @@ public: string res; if (labs(diff) >= SECSINDAY) { - char* buffer = NULL; - if (diff > 0) - asprintf(&buffer, tr("in %02ldd"), long(diff / SECSINDAY)); - else - asprintf(&buffer, "%02ldd", long(-diff / SECSINDAY)); - res = buffer; - free(buffer); + cString buffer; + if (diff > 0) + buffer = cString::sprintf(tr("in %02ldd"), long(diff / SECSINDAY)); + else + buffer = cString::sprintf("%02ldd", long(-diff / SECSINDAY)); + res = buffer; } else if (labs(diff) >= (60 * 60)) { - char* buffer = NULL; - if (diff > 0) - asprintf(&buffer, tr("in %02ldh"), long(diff / (60*60))); - else - asprintf(&buffer, "%02ldh", long(-diff / (60*60))); - res = buffer; - free(buffer); + cString buffer; + if (diff > 0) + buffer = cString::sprintf(tr("in %02ldh"), long(diff / (60*60))); + else + buffer = cString::sprintf("%02ldh", long(-diff / (60*60))); + res = buffer; } else { - char* buffer = NULL; - if (diff > 0) - asprintf(&buffer, tr("in %02ldm"), long(diff / 60)); - else - asprintf(&buffer, "%02ldm", long(-diff / 60)); - res = buffer; - free(buffer); + cString buffer; + if (diff > 0) + buffer = cString::sprintf(tr("in %02ldm"), long(diff / 60)); + else + buffer = cString::sprintf("%02ldm", long(-diff / 60)); + res = buffer; } if (escapeStrings) return "'" + EscapeString(res) + "'"; else return res; } |