summaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'common.c')
-rw-r--r--common.c161
1 files changed, 78 insertions, 83 deletions
diff --git a/common.c b/common.c
index 0bfb1d4..728dedb 100644
--- a/common.c
+++ b/common.c
@@ -4,7 +4,6 @@
#include "common.h"
#include <sstream>
-#include <locale.h>
#include <vdr/plugin.h>
#include <vdr/device.h>
#include <sys/ioctl.h>
@@ -39,7 +38,7 @@ const char *ChannelName(const cChannel *Channel, int Number)
if (Channel)
snprintf(buffer, sizeof(buffer), "%s", Channel->Name());
else if (!Number)
- snprintf(buffer, sizeof(buffer), "%s", tr("*** Invalid Channel ***"));
+ snprintf(buffer, sizeof(buffer), "%s", trVDR("*** Invalid Channel ***"));
#if VDRVERSNUM < 10315
char *ptr;
@@ -61,7 +60,7 @@ const char *ChannelShortName(const cChannel *Channel, int Number)
snprintf(buffer, sizeof(buffer), "%s", Channel->ShortName(true));
#endif
else if (!Number)
- snprintf(buffer, sizeof(buffer), "%s", tr("*** Invalid Channel ***"));
+ snprintf(buffer, sizeof(buffer), "%s", trVDR("*** Invalid Channel ***"));
#if VDRVERSNUM < 10315
char *ptr;
@@ -77,7 +76,7 @@ const char *ChannelShortName(const cChannel *Channel, int Number)
return buffer;
}
-const char *EventType(uint Number)
+const char *EventType(uint Number)
{
static char buffer[25];
buffer[0] = '\0';
@@ -139,7 +138,7 @@ int GetFrontendSTR(void)
{
uint16_t value = 0;
char *dev = NULL;
-
+
asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0);
int fe = open(dev, O_RDONLY | O_NONBLOCK);
free(dev);
@@ -154,7 +153,7 @@ int GetFrontendSNR(void)
{
uint16_t value = 0;
char *dev = NULL;
-
+
asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0);
int fe = open(dev, O_RDONLY | O_NONBLOCK);
free(dev);
@@ -169,7 +168,7 @@ bool GetFrontendHasLock(void)
{
uint16_t value = 0;
char *dev = NULL;
-
+
asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0);
int fe = open(dev, O_RDONLY | O_NONBLOCK);
free(dev);
@@ -184,7 +183,7 @@ bool GetFrontendHasSignal(void)
{
uint16_t value = 0;
char *dev = NULL;
-
+
asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0);
int fe = open(dev, O_RDONLY | O_NONBLOCK);
free(dev);
@@ -199,10 +198,10 @@ std::string AddExtInfoToDescription(const char *Title, const char *ShortText, co
{
// max. width so lines don't get wrapped
#define MAX_CHARS 50
-
+
// prepare the description
std::stringstream desc("");
-
+
if (!isempty(Description)) {
// it seems that sometimes the description ends with a newline
// and sometimes it does not
@@ -210,7 +209,7 @@ std::string AddExtInfoToDescription(const char *Title, const char *ShortText, co
while (!buf.empty() && buf[buf.size() - 1] == '\n') buf.erase(buf.size() - 1);
desc << buf << "\n"; // keep one newline
}
-
+
#ifdef DEVELOPMENT_FEATURES
// try to find a rerun of the show using epgsearch-service
if (!isempty(Title)) {
@@ -228,7 +227,7 @@ std::string AddExtInfoToDescription(const char *Title, const char *ShortText, co
if (!desc.str().empty()) desc << "\n";
desc << tr("RERUNS OF THIS SHOW") << ":\n";
int i = 0;
- for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r =
+ for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r =
list->First(); r && i < 5; r = list->Next(r)) {
i++;
std::stringstream buf;
@@ -242,27 +241,30 @@ std::string AddExtInfoToDescription(const char *Title, const char *ShortText, co
}
}
}
-#endif // DEVELOPMENT_FEATURES
-
+#endif // DEVELOPMENT_FEATURES
+
// Add the AUX-Info of the Recording
if (Aux) {
if (StripAux) {
std::string auxRaw(Aux);
std::string auxEpgsearch = StripXmlTag(auxRaw, "epgsearch");
if (!auxEpgsearch.empty()) {
- if (!desc.str().empty()) desc << "\n";
+ if (!desc.str().empty())
+ desc << "\n";
desc << tr("AUXILIARY INFOS") << ":\n";
std::stringstream buf;
buf << " - " << tr("Search timer") << ": " << StripXmlTag(auxRaw, "Search timer");
desc << FitToWidth(buf, MAX_CHARS) << "\n";
}
- } else {
- if (!desc.str().empty()) desc << "\n";
+ }
+ else {
+ if (!desc.str().empty())
+ desc << "\n";
desc << tr("AUXILIARY INFOS") << ":\n";
desc << Aux << "\n";
}
}
-
+
return desc.str();
}
@@ -277,7 +279,7 @@ int GetRecordingSize(const char *FileName)
// use our own approach
{
if (FileName != NULL) {
- bool bRet=false;
+ bool bRet = false;
long long size = 0;
int nFiles;
struct stat fileinfo; // Holds file information structure
@@ -286,38 +288,33 @@ int GetRecordingSize(const char *FileName)
cReadLine reader;
#endif
asprintf(&cmd, "find '%s' -follow -type f -name '*.*'|sort ", FileName);
-
+
FILE *p = popen(cmd, "r");
- int ret=0;
- if (p)
- {
+ int ret = 0;
+ if (p) {
char *s;
-
+
#if VDRVERSNUM >= 10318
- while ((s = reader.Read(p)) != NULL)
+ while ((s = reader.Read(p)) != NULL) {
#else
- while ((s = readline(p)) != NULL)
+ while ((s = readline(p)) != NULL) {
#endif
- {
- if ((ret=stat(s, &fileinfo)) != -1)
- {
+ if ((ret=stat(s, &fileinfo)) != -1) {
size += (long long)fileinfo.st_size;
nFiles++;
}
}
-
- bRet=true;
+
+ bRet = true;
}
-
+
pclose(p);
delete cmd;
-
+
return (int)(size / 1024 / 1024); // [MB]
}
else
- {
return 0;
- }
}
#endif
@@ -325,7 +322,7 @@ int GetRecordingLength(const char *FileName)
{
// based on the enAIO-Patch for VDR
#define INDEXFILESUFFIX "/index.vdr"
-
+
struct tIndex { int offset; uchar type; uchar number; short reserved; };
tIndex *index;
char RecLength[21];
@@ -333,36 +330,36 @@ int GetRecordingLength(const char *FileName)
int last = -1;
index = NULL;
if (FileName) {
- filename = MALLOC(char, strlen(FileName) + strlen(INDEXFILESUFFIX) + 1);
- if (filename) {
- strcpy(filename, FileName);
- char *pFileExt = filename + strlen(filename);
- strcpy(pFileExt, INDEXFILESUFFIX);
- int delta = 0;
- if (access(filename, R_OK) == 0) {
- struct stat buf;
- if (stat(filename, &buf) == 0) {
- delta = buf.st_size % sizeof(tIndex);
- if (delta) {
- delta = sizeof(tIndex) - delta;
- esyslog("ERROR: invalid file size (%ld) in '%s'", buf.st_size, filename);
- }
- last = (buf.st_size + delta) / sizeof(tIndex) - 1;
- char hour[2], min[3];
+ filename = MALLOC(char, strlen(FileName) + strlen(INDEXFILESUFFIX) + 1);
+ if (filename) {
+ strcpy(filename, FileName);
+ char *pFileExt = filename + strlen(filename);
+ strcpy(pFileExt, INDEXFILESUFFIX);
+ int delta = 0;
+ if (access(filename, R_OK) == 0) {
+ struct stat buf;
+ if (stat(filename, &buf) == 0) {
+ delta = buf.st_size % sizeof(tIndex);
+ if (delta) {
+ delta = sizeof(tIndex) - delta;
+ esyslog("ERROR: invalid file size (%ld) in '%s'", (long)buf.st_size, filename);
+ }
+ last = (buf.st_size + delta) / sizeof(tIndex) - 1;
+ char hour[2], min[3];
#if VDRVERSNUM >= 10318
- snprintf(RecLength, sizeof(RecLength), "%s", *IndexToHMSF(last, true));
+ snprintf(RecLength, sizeof(RecLength), "%s", *IndexToHMSF(last, true));
#else
- snprintf(RecLength, sizeof(RecLength), "%s", IndexToHMSF(last, true));
+ snprintf(RecLength, sizeof(RecLength), "%s", IndexToHMSF(last, true));
#endif
- snprintf(hour, sizeof(hour), "%c", RecLength[0]);
- snprintf(min, sizeof(min), "%c%c", RecLength[2], RecLength[3]);
- return (atoi(hour) * 60) + atoi(min);
- }
- }
- free(filename);
- }
- }
-
+ snprintf(hour, sizeof(hour), "%c", RecLength[0]);
+ snprintf(min, sizeof(min), "%c%c", RecLength[2], RecLength[3]);
+ return (atoi(hour) * 60) + atoi(min);
+ }
+ }
+ free(filename);
+ }
+ }
+
return 0;
}
@@ -372,32 +369,27 @@ int GetRecordingCuttedLength(const char *FileName)
double length = 0;
int totalLength = GetRecordingLength(FileName);
const double diffIFrame = FRAMESPERSEC / 2; // approx. 1/2 sec.
-
+
marks.Load(FileName);
-
- if (marks.Count())
- {
+
+ if (marks.Count()) {
int start = 1; // first frame
bool isStart = true;
-
- for (cMark *m = marks.First(); m; m = marks.GetNext(m->position))
- {
+
+ for (cMark *m = marks.First(); m; m = marks.GetNext(m->position)) {
if (isStart)
- {
start = m->position;
- }
else
- {
length += (double)(m->position - start + 1 + diffIFrame) / (FRAMESPERSEC * 60); // [min]
- }
-
+
isStart = !isStart;
}
-
+
// if there is no end-mark the last segment goes to the end of the rec.
- if (!isStart) length += totalLength - (double)(start - 1 - diffIFrame) / (FRAMESPERSEC * 60); // [min]
+ if (!isStart)
+ length += totalLength - (double)(start - 1 - diffIFrame) / (FRAMESPERSEC * 60); // [min]
}
-
+
// just to avoid, that the cutted length is bigger than the total length
return (int)length > totalLength ? totalLength : (int)length;
}
@@ -410,7 +402,6 @@ cxType TimeType(time_t Time, const std::string &Format)
if (Time > 0) {
if (Format.length() > 0) {
- setlocale(LC_TIME, tr("en_US"));
strftime(result, sizeof(result), Format.c_str(), tm);
cxType r = result;
@@ -552,7 +543,8 @@ void SkipQuotes(std::string &Value) {
esyslog("ERROR: text2skin: missing closing %c", quote);
}
-std::string FitToWidth(std::string &Line, uint Width) {
+std::string FitToWidth(std::string &Line, uint Width)
+{
std::string buf(Line);
if (buf.size() > Width) {
buf.erase(Width - 3);
@@ -561,7 +553,8 @@ std::string FitToWidth(std::string &Line, uint Width) {
return buf;
}
-std::string FitToWidth(std::stringstream &Line, uint Width) {
+std::string FitToWidth(std::stringstream &Line, uint Width)
+{
std::string buf(Line.str());
if (buf.size() > Width) {
buf.erase(Width - 3);
@@ -570,7 +563,8 @@ std::string FitToWidth(std::stringstream &Line, uint Width) {
return buf;
}
-std::string StripXmlTag(std::string &Line, const char *Tag) {
+std::string StripXmlTag(std::string &Line, const char *Tag)
+{
// set the search strings
std::stringstream strStart, strStop;
strStart << "<" << Tag << ">";
@@ -578,7 +572,8 @@ std::string StripXmlTag(std::string &Line, const char *Tag) {
// find the strings
std::string::size_type locStart = Line.find(strStart.str());
std::string::size_type locStop = Line.find(strStop.str());
- if (locStart == std::string::npos || locStop == std::string::npos) return "";
+ if (locStart == std::string::npos || locStop == std::string::npos)
+ return "";
// extract relevant text
int pos = locStart + strStart.str().size();
int len = locStop - pos;