From 32b11e1a5331403d27e118c81d73add78f799994 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Fri, 21 Jun 2024 06:27:20 +0200 Subject: [PATCH] Added an EPG bugfix for broadcasters who put literal "\n" strings in their EPG --- HISTORY | 5 ++++- epg.c | 19 ++++++++++++++++++- tools.c | 35 +++++++++++++++++++---------------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/HISTORY b/HISTORY index 886188b4..b480f6a9 100644 --- a/HISTORY +++ b/HISTORY @@ -9919,10 +9919,13 @@ Video Disk Recorder Revision History - A device is now always kept occupied if a timer is in VPS margin or needs the transponder (thanks to Markus Ehrnsperger). -2024-06-13: +2024-06-21: - Updated the Italian OSD texts (thanks to Diego Pierotto). - Fixed a possible access of a deleted object in the EIT scanner. - Fixed setting T2 system ID from NIT (thanks to Stefan Herdler). - When starting an editing process, VDR now first checks whether there is enough free disk space to take up the edited version of the recording. +- Added an EPG bugfix for broadcasters who put literal "\n" strings in their EPG. + Note that the string version of strreplace() has been modified, so that it + replaces all occurrences of the search string, not just the first one. diff --git a/epg.c b/epg.c index 61c090de..ab4a6e83 100644 --- a/epg.c +++ b/epg.c @@ -7,7 +7,7 @@ * Original version (as used in VDR before 1.3.0) written by * Robert Schneider and Rolf Hakenes . * - * $Id: epg.c 5.8 2024/03/06 20:16:51 kls Exp $ + * $Id: epg.c 5.9 2024/06/21 06:27:20 kls Exp $ */ #include "epg.h" @@ -885,6 +885,23 @@ void cEvent::FixEpgBugs(void) Final: + // And then there are the specially gifted people who put a literal "\n" string where there should be + // a '\n' character: + if (shortText) { + if (char *p = strstr(shortText, "\\n")) { + *p = 0; + p += 2; + char *s = strdup(shortText); + char *d = strdup(cString::sprintf("%s\n\n%s", p, description)); + free(shortText); + free(description); + shortText = s; + description = d; + EpgBugFixStat(12, ChannelID()); + } + } + description = strreplace(description, "\\n", " \n"); + // VDR can't usefully handle newline characters in the title, shortText or component description of EPG // data, so let's always convert them to blanks (independent of the setting of EPGBugfixLevel): strreplace(title, '\n', ' '); diff --git a/tools.c b/tools.c index 51165e31..0e95ca2f 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 5.10 2024/02/15 14:57:56 kls Exp $ + * $Id: tools.c 5.11 2024/06/21 06:27:20 kls Exp $ */ #include "tools.h" @@ -151,26 +151,29 @@ char *strreplace(char *s, char c1, char c2) char *strreplace(char *s, const char *s1, const char *s2) { - if (!s || !s1 || !s2) + if (!s || !s1 || !s2 || strcmp(s1, s2) == 0) return s; - char *p = strstr(s, s1); - if (p) { - int of = p - s; + char *q = s; + if (char *p = strstr(s, s1)) { int l = strlen(s); int l1 = strlen(s1); int l2 = strlen(s2); - if (l2 > l1) { - if (char *NewBuffer = (char *)realloc(s, l + l2 - l1 + 1)) - s = NewBuffer; - else { - esyslog("ERROR: out of memory"); - return s; + do { + int of = p - s; + if (l2 > l1) { + if (char *NewBuffer = (char *)realloc(s, l + l2 - l1 + 1)) + s = NewBuffer; + else { + esyslog("ERROR: out of memory"); + return s; + } } - } - char *sof = s + of; - if (l2 != l1) - memmove(sof + l2, sof + l1, l - of - l1 + 1); - memcpy(sof, s2, l2); + char *sof = s + of; + if (l2 != l1) + memmove(sof + l2, sof + l1, l - of - l1 + 1); + memcpy(sof, s2, l2); + q = sof + l2; + } while (p = strstr(q, s1)); } return s; }