Skip to content

Commit

Permalink
radio, translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Ehrnsperger committed Jun 11, 2023
1 parent f1740e5 commit 5090b8f
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 158 deletions.
142 changes: 76 additions & 66 deletions largeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,79 @@
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include "largeString.h"
#include <sys/stat.h>
#include <vdr/plugin.h>
#include "largeString.h"

cLargeString::cLargeString(const char *name, size_t initialSize, size_t increaseSize, bool debugBufferSize) {
if (name) m_name = name;
void cLargeString::init(size_t initialSize, size_t increaseSize, bool debugBufferSize) {
m_debugBufferSize = debugBufferSize;
if (initialSize <= 0) {
esyslog("cLargeString::cLargeString, ERROR name = %s, initialSize = %zu", m_name.c_str(), initialSize);
initialSize = 100;
}
if (increaseSize > 0) m_increaseSize = increaseSize;
else m_increaseSize = std::max((size_t)10, initialSize / 2);
else m_increaseSize = std::max((size_t)100, initialSize / 2);
if (initialSize == 0) return;
m_s = (char *) malloc(initialSize * sizeof(char));
if (!m_s) {
esyslog("cLargeString::cLargeString, ERROR out of memory, name = %s, initialSize = %zu", m_name.c_str(), initialSize);
esyslog("cLargeString::init, ERROR out of memory, name = %.*s, initialSize = %zu", nameLen(), nameData(), initialSize);
throw std::runtime_error("cLargeString::cLargeString, ERROR out of memory");
return;
}
m_buffer_end = m_s + initialSize;
m_string_end = m_s;
}
void cLargeString::loadFile(const char *filename, bool *exists) {
if (exists) *exists = false;
if (!filename) return;
struct stat buffer;
if (stat(filename, &buffer) != 0) return;

// file exists, length buffer.st_size
if (exists) *exists = true;
if (buffer.st_size == 0) return; // empty file
m_s = (char *) malloc((size_t)(buffer.st_size + 1) * sizeof(char)); // add one. So we can add the 0 string terminator
if (!m_s) {
esyslog("cLargeString::loadFile, ERROR out of memory, name = %.*s, filename = %s, requested size = %zu", nameLen(), nameData(), filename, (size_t)(buffer.st_size + 1));
throw std::runtime_error("cLargeString::cLargeString, ERROR out of memory (file)");
return;
}
m_buffer_end = m_s + buffer.st_size + 1;
m_string_end = m_s;
FILE *f = fopen(filename, "rb");
if (!f) {
esyslog("cLargeString::loadFile, ERROR: stat OK, fopen fails, filename %s", filename);
return;
}
size_t num_read = fread (m_s, 1, (size_t)buffer.st_size, f);
fclose(f);
m_string_end = m_s + num_read;
if (num_read != (size_t)buffer.st_size) {
esyslog("cLargeString::loadFile, ERROR: num_read = %zu, buffer.st_size = %zu, ferror %i, name = %.*s, filename %s", num_read, (size_t)buffer.st_size, ferror(f), nameLen(), nameData(), filename);
m_string_end = m_s + std::min(num_read, (size_t)buffer.st_size);
}
}

cLargeString::~cLargeString() {
if (!m_s) return;
if (m_s == m_s_initial) return;
free (m_s);
setMaxSize();
size_t buffer_len = m_buffer_end - m_s;
if (m_debugBufferSize && buffer_len > m_maxSize * 2) esyslog("cLargeString::cLargeString WARNING too large buffer, name = %s, buffer %zu, len %zu", m_name.c_str(), buffer_len, m_maxSize);
if (m_debugBufferSize && buffer_len > m_maxSize * 2) esyslog("cLargeString::cLargeString WARNING too large buffer, name = %.*s, buffer %zu, len %zu", nameLen(), nameData(), buffer_len, m_maxSize);
}

bool cLargeString::clear() {
if (!m_s) return false;
void cLargeString::clear() {
setMaxSize();
m_string_end = m_s;
m_endBorrowed = false;
return true;
}

char *cLargeString::borrowEnd(size_t len) {
if (!m_s) return NULL;
if (!appendLen(len)) return NULL;
appendLen(len);
m_endBorrowed = true;
return m_string_end;
}
bool cLargeString::finishBorrow(size_t len) {
if (!m_s) return false;
if (!m_endBorrowed) return true;
m_endBorrowed = false;
if (m_string_end + len >= m_buffer_end) {
esyslog("cLargeString::finishBorrow(size_t len), ERROR name = %s, len %zu too large, available %zu", m_name.c_str(), len, m_buffer_end - m_string_end - 1);
esyslog("cLargeString::finishBorrow(size_t len), ERROR name = %.*s, len %zu too large, available %zu", nameLen(), nameData(), len, m_buffer_end - m_string_end - 1);
m_string_end = m_buffer_end - 1;
return false;
}
Expand All @@ -60,85 +84,71 @@ bool cLargeString::finishBorrow(size_t len) {
}

bool cLargeString::finishBorrow() {
if (!m_s) return false;
if (!m_endBorrowed) return true;
m_endBorrowed = false;
char *end = strchr(m_string_end, 0);
if (!end) return false;
if (end >= m_buffer_end) {
esyslog("cLargeString::finishBorrow(), ERROR name = %s, end >= m_buffer_end, available %zu", m_name.c_str(), m_buffer_end - m_string_end - 1);
esyslog("cLargeString::finishBorrow(), ERROR name = %.*s, end >= m_buffer_end, available %zu", nameLen(), nameData(), m_buffer_end - m_string_end - 1);
m_string_end = m_buffer_end - 1;
return false;
}
m_string_end = end;
return true;
}

bool cLargeString::append(char c) {
if (!m_s) return false;
if (!appendLen(1)) return false;
cLargeString &cLargeString::append(char c) {
appendLen(1);
*(m_string_end++) = c;
return true;
return *this;
}

bool cLargeString::append(int i) {
if (!m_s) return false;
cLargeString &cLargeString::append(int i) {
if (i < 0) {
if(!appendLen(2)) return false;
appendLen(2);
*(m_string_end++) = '-';
i *= -1;
}
if (i < 10) return append((char)('0' + i));
char *buf;
for (int j = i; j > 0;) {
for (j = i, buf = m_buffer_end - 2; j > 0 && buf >= m_string_end; j /= 10, buf--) *buf = j%10 + '0';
if (j > 0 && !enlarge()) return false;
}
if (buf >= m_string_end) for (buf++; buf < m_buffer_end - 1;m_string_end++, buf++) *m_string_end = *buf;
else m_string_end = m_buffer_end - 1;
return true;
char buf[21]; // unsigned int 64: max. 20. (18446744073709551615) signed int64: max. 19 (+ sign)
char *bufferEnd = buf+20;
*bufferEnd = 0;
for (; i; i /= 10) *(--bufferEnd) = '0' + (i%10);
return appendS(bufferEnd);
}

bool cLargeString::appendLen(size_t len) {
char *newStringEnd = m_string_end + len;
if (newStringEnd < m_buffer_end) return true;
return enlarge(newStringEnd + 1 - m_buffer_end);
cLargeString &cLargeString::append(const char *s, size_t len) {
if (!s || len == 0) return *this;
appendLen(len);
memcpy(m_string_end, s, len);
m_string_end += len;
return *this;
}

bool cLargeString::append(const char *s, size_t len) {
if (!m_s) return false;
if (!s || len == 0) return true;
if (!appendLen(len)) return false;
for (char *newStringEnd = m_string_end + len; m_string_end < newStringEnd; s++, m_string_end++) *m_string_end = *s;
return true;
}

bool cLargeString::append(const char *s) {
if (!m_s) return false;
if (!s || !*s) return true;
for (; *s && m_string_end < m_buffer_end; s++, m_string_end++) *m_string_end = *s;
while(m_string_end == m_buffer_end) {
if (!enlarge()) return false;
for (; *s && m_string_end < m_buffer_end; s++, m_string_end++) *m_string_end = *s;
}
return true;
cLargeString &cLargeString::appendS(const char *s) {
if (!s || !*s) return *this;
size_t len = strlen(s);
appendLen(len);
memcpy(m_string_end, s, len);
m_string_end += len;
return *this;
}

bool cLargeString::enlarge(size_t increaseSize) {
if (!m_s) return false;
void cLargeString::enlarge(size_t increaseSize) {
increaseSize = std::max(increaseSize, m_increaseSize);
increaseSize = std::max(increaseSize, (size_t)((m_buffer_end - m_s)/2) );
size_t stringLength = m_string_end - m_s;
size_t newSize = m_buffer_end - m_s + increaseSize;
if (m_debugBufferSize) esyslog("cLargeString::cLargeString, WARNING realloc required!!!, name = %s, new Size = %zu", m_name.c_str(), newSize);
char *tmp = (char *)realloc(m_s, newSize * sizeof(char));
if (!tmp) {
esyslog("cLargeString::cLargeString, ERROR out of memory, name = %s, new Size = %zu", m_name.c_str(), newSize);
if (m_s == m_s_initial)
m_s = (char *) malloc(newSize * sizeof(char));
else {
if (m_debugBufferSize) esyslog("cLargeString::cLargeString, WARNING realloc required!!!, name = %.*s, new Size = %zu", nameLen(), nameData(), newSize);
m_s = (char *)realloc(m_s, newSize * sizeof(char));
}
if (!m_s) {
esyslog("cLargeString::cLargeString, ERROR out of memory, name = %.*s, new Size = %zu", nameLen(), nameData(), newSize);
throw std::runtime_error("cLargeString::cLargeString, ERROR out of memory (enlarge)");
return false;
return;
}
m_s = tmp;
m_buffer_end = m_s + newSize;
m_string_end = m_s + stringLength;
return true;
}
76 changes: 61 additions & 15 deletions largeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,81 @@

class cLargeString {
private:
char *m_s = NULL;
char *m_string_end = NULL; // *m_string_end = 0; m_string_end must be < m_buffer_end, because m_buffer_end is excluded
char *m_buffer_end = NULL; // buffer is between [m_s;m_buffer_end), i.e. m_buffer_end is excluded
char m_s_initial[1] = "";
char *m_s = m_s_initial;
char *m_string_end = m_s; // *m_string_end = 0; m_string_end must be < m_buffer_end, because m_buffer_end is excluded
char *m_buffer_end = m_s + 1; // buffer is between [m_s;m_buffer_end), i.e. m_buffer_end is excluded
size_t m_increaseSize = 0;
size_t m_maxSize = 0;
std::string m_name = "";
const char *m_nameData;
int m_nameLen;
bool m_debugBufferSize = false;
bool m_endBorrowed = false;
bool enlarge(size_t increaseSize = 0);
bool appendLen(size_t len); // enure buffer is large enough to append len characters
void enlarge(size_t increaseSize = 0);
inline void appendLen(size_t len) { // enure buffer is large enough to append len characters
if (m_string_end + len < m_buffer_end) return;
enlarge(m_string_end + len + 1 - m_buffer_end);
}
void setMaxSize() { m_maxSize = std::max(m_maxSize, (size_t)(m_string_end - m_s)); }
void init(size_t initialSize, size_t increaseSize, bool debugBufferSize);
void loadFile(const char *filename, bool *exists);
public:
cLargeString(const char *name, size_t initialSize, size_t increaseSize = 0, bool debugBufferSize = false);
cLargeString(const cLargeString& o) = delete;
cLargeString &operator= (const cLargeString &) = delete;
cLargeString(cLargeString&& o) = default;
cLargeString &operator= (cLargeString &&) = default;
template<std::size_t N>
cLargeString(const char (&name)[N], size_t initialSize = 0, size_t increaseSize = 0, bool debugBufferSize = false) {
m_nameData = name;
m_nameLen = static_cast<int>(N) - 1;
init(initialSize, increaseSize, debugBufferSize);
}
template<std::size_t N>
cLargeString(const char (&name)[N], const char *filename, bool *exists = NULL) {
m_nameData = name;
m_nameLen = static_cast<int>(N) - 1;
loadFile(filename, exists);
}
~cLargeString();
char *data() { *m_string_end = 0; return m_s; }
const char *c_str() const { *m_string_end = 0; return m_s; }
bool append(char c);
bool append(const char *s);
bool append(const char *s, size_t len);
bool append(std::string s) { return append(s.c_str(), s.length()); }
bool append(int i);
cLargeString &append(const char (&s)[1]) {
// note: every other specific implementation is too slow. memcpy is too fast :)
// std::cout << "append template xx1xx !!!!\n";
return *this;
}
template<std::size_t N> cLargeString &append(const char (&s)[N]) {
// std::cout << "append template!!!!\n";
appendLen(N-1);
memcpy(m_string_end, s, N-1);
m_string_end += N-1;
return *this;
}
cLargeString &append(char c);
cLargeString &append(const char *s, size_t len);
cLargeString &append(const std::string &s) { return append(s.c_str(), s.length()); }
cLargeString &append(int i);
cLargeString &appendS(const char *s);
template<typename... Args> cLargeString &appendFormated(char const* format, Args&&... args) {
size_t avail = m_buffer_end - m_string_end;
size_t numNeeded = snprintf(m_string_end, avail, format, std::forward<Args>(args)...);
if (numNeeded >= avail) {
appendLen(numNeeded + 1);
sprintf(m_string_end, format, std::forward<Args>(args)...);
}
m_string_end += numNeeded;
return *this;
}
char *borrowEnd(size_t len); // len: upper limit of characters that can be written
bool finishBorrow(size_t len); // len: number of actually written characters
bool finishBorrow(); // number of actually written characters: zero terminated
bool clear();
size_t length() const { return m_string_end - m_s; }
bool empty() const { return m_string_end == m_s; }
void clear();
inline size_t length() const { return m_string_end - m_s; }
inline bool empty() const { return m_string_end == m_s; }
cLargeString &erase(size_t index = 0) { setMaxSize(); m_string_end = std::min(m_string_end, m_s + index); return *this;}
char operator[](size_t i) const { return *(m_s + i); }
const char *nameData() const { return m_nameData; }
int nameLen() const { return m_nameLen; }
};

#endif // __LARGE_STRING_H
Binary file added live/img/rd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions live/js/live/createHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ function injectHdSdIcon(elementId, sdhd, channelName) {
if (typeof liveEnhanced !== 'undefined') liveEnhanced.domReadySetup();
}

function injectErrorHdSdIcon(elementId, numErrors, durationDeviation, sdhd, channelName) {
function injectErrorHdSdIcon(elementId, numErrors, durationDeviation, sdhd, channelName, duration) {
const s = Object.create(null);
s.a = "";
addErrorIcon(s, numErrors, durationDeviation);
addErrorIcon(s, numErrors, durationDeviation, duration);
addHdSdIcon(s, sdhd, channelName);
document.getElementById(elementId).innerHTML = s.a;
if (typeof liveEnhanced !== 'undefined') liveEnhanced.domReadySetup();
Expand Down
7 changes: 5 additions & 2 deletions pages/recordings.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function RecordingActionS(s, id, A, Img, Title) {
// [1] : ArchiveDescr()
// scraper data
// [2] : IMDB ID
// [3] : image.path (nach "/tvscraper/")
// [3] : image.path (behind "/tvscraper/")
// [4] : "pt" if m_s_image.width <= m_s_image.height, otherwise= ""
// [5] : title (scraper)
// [6] : season / episode (scraper, for tv shows, if available. Otherwise: Empty)
Expand Down Expand Up @@ -589,14 +589,17 @@ if (recording && recording->Info() ) {
char sdhd = video_SD_HD == 0 ? 's': video_SD_HD == 1 ? 'h': 'u';
CONVERT(b_recordingErrors, recordingErrors, toCharsI);
CONVERT(b_duration_deviation, duration_deviation, toCharsI);
std::string duration;
if (recording->FileName() )
AppendDuration(duration, tr("%d:%02d"), recording->LengthInSeconds() );
</%cpp>
<img data-src="img/transparent.png" height="10px" />
<span id="icons-<$id$>"></span>
<#
<img src="img/forceError.png" height="0.1px" onerror="injectErrorHdSdIcon(&quot;icons-<$id$>&quot;, <$b_recordingErrors$>, <$b_duration_deviation$>, &quot;<$sdhd$>&quot;, &quot;<$recording->Info()->ChannelName()?recording->Info()->ChannelName():""$>&quot;)"/>
#>
<script class="injectIcons">
injectErrorHdSdIcon(\"icons-<$id$>\", <$b_recordingErrors$>, <$b_duration_deviation$>, \"<$sdhd$>\", \"<$recording->Info()->ChannelName()?recording->Info()->ChannelName():""$>\")
injectErrorHdSdIcon(\"icons-<$id$>\", <$b_recordingErrors$>, <$b_duration_deviation$>, \"<$sdhd$>\", \"<$recording->Info()->ChannelName()?recording->Info()->ChannelName():""$>\", \"<$duration$>\")
</script>
<%cpp>
}
Expand Down
2 changes: 1 addition & 1 deletion pages/timers.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ using namespace vdrlive;
timerStateHint = tr("Timer is recording.");
}
else if (timer->Flags() & tfActive) {
if (timerConflicts.HasConflict(*timer)) {
if (timerConflicts.HasConflict(timer->Id() )) {
timerStateImg = "timerconflict.gif";
timerStateHint = tr("Timer has a conflict.");
}
Expand Down
7 changes: 7 additions & 0 deletions po/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ msgstr "Fehler beim Zugriff auf Programinfos"
msgid "%d:%02d"
msgstr "%d:%02d"

#, c-format
msgid "%'d MB"
msgstr "%'d MB"

msgid "Recording length"
msgstr "Länge der Aufzeichnung"

Expand Down Expand Up @@ -1025,6 +1029,9 @@ msgstr "Timer löschen"
msgid "No timer defined"
msgstr "Keine Timer vorhanden"

msgid "Duration"
msgstr "Dauer"

msgid "Timer is recording."
msgstr "Timer zeichnet auf."

Expand Down
Loading

0 comments on commit 5090b8f

Please sign in to comment.