diff options
-rw-r--r-- | blacklist.c | 13 | ||||
-rw-r--r-- | charset.c | 13 | ||||
-rw-r--r-- | config.c | 4 | ||||
-rw-r--r-- | epgclone.c | 13 | ||||
-rw-r--r-- | regexp.c | 81 | ||||
-rw-r--r-- | tools.c | 94 | ||||
-rw-r--r-- | tools.h | 2 |
7 files changed, 99 insertions, 121 deletions
diff --git a/blacklist.c b/blacklist.c index 4bacf2c..786ef87 100644 --- a/blacklist.c +++ b/blacklist.c @@ -21,16 +21,9 @@ bool cBlacklist::Apply(cChannel *Channel) void cBlacklist::SetFromString(char *s, bool Enabled) { Free(); - enabled = Enabled; - if (s[0] == '!') - string = strdup(s+1); - else - string = strdup(s); - if (s[0] == '!' || s[0] == '#') - enabled = false; - char *p = (s[0] == '#') ? NULL : s; - if (p) { - char *p = (s[0] == '!') ? s+1 : s; + cListItem::SetFromString(s, Enabled); + if (enabled) { + char *p = (s[0] == '!') ? s + 1 : s; numchannels = LoadChannelsFromString(p); } } @@ -42,16 +42,9 @@ void cCharSet::SetFromString(char *s, bool Enabled) FREE(origcharset); FREE(realcharset); Free(); - enabled = Enabled; - if (s[0] == '!') - string = strdup(s + 1); - else - string = strdup(s); - if (s[0] == '!' || s[0] == '#') - enabled = false; - char *p = (s[0] == '#') ? NULL : s; - if (p) { - char *p = (s[0] == '!') ? s+1 : s; + cListItem::SetFromString(s, Enabled); + if (enabled) { + char *p = (s[0] == '!') ? s + 1 : s; char *r = strchr(p, ':'); if (r) { *r = 0; @@ -45,8 +45,8 @@ bool cEpgfixerSetup::ProcessArgs(int argc, char *argv[]) bool cEpgfixerSetup::SetupParse(const char *Name, const char *Value) { const char *pt; - if (*m_ProcessedArgs && NULL != (pt=strstr(m_ProcessedArgs+1, Name)) && - *(pt-1) == ' ' && *(pt+strlen(Name)) == ' ') { + if (*m_ProcessedArgs && NULL != (pt = strstr(m_ProcessedArgs + 1, Name)) && + *(pt - 1) == ' ' && *(pt + strlen(Name)) == ' ') { dsyslog("Skipping configuration entry %s=%s (overridden in command line)", Name, Value); return true; } @@ -68,16 +68,9 @@ void cEpgClone::SetFromString(char *s, bool Enabled) dest_num = 0; FREE(dest_str); Free(); - enabled = Enabled; - if (s[0] == '!') - string = strdup(s+1); - else - string = strdup(s); - if (s[0] == '!' || s[0] == '#') - enabled = false; - char *p = (s[0] == '#') ? NULL : s; - if (p) { - char *p = (s[0] == '!') ? s+1 : s; + cListItem::SetFromString(s, Enabled); + if (enabled) { + char *p = (s[0] == '!') ? s + 1 : s; char *f = strchr(p, '='); if (f) { *f = 0; @@ -21,8 +21,8 @@ cEpgfixerList<cRegexp, cEvent> EpgfixerRegexps; const char *strSources[] = { "title","shorttext","description","undefined" }; -typedef enum { ATITLE,PTITLE,TITLE,ASHORTTEXT,PSHORTTEXT,SHORTTEXT,ADESCRIPTION,PDESCRIPTION,DESCRIPTION,RATING } backrefs; -const char *strBackrefs[] = { "atitle","ptitle","title","ashorttext","pshorttext","shorttext","adescription","pdescription","description","rating" }; +typedef enum { ATITLE, PTITLE, TITLE, ASHORTTEXT, PSHORTTEXT, SHORTTEXT, ADESCRIPTION, PDESCRIPTION, DESCRIPTION, RATING } backrefs; +const char *strBackrefs[] = { "atitle", "ptitle", "title", "ashorttext", "pshorttext", "shorttext", "adescription", "pdescription", "description", "rating" }; cRegexp::cRegexp() { @@ -87,8 +87,8 @@ void cRegexp::ParseRegexp(char *restring) *l = 0; int i = 1; // handle all modifiers - while (*(l+i) != 0) { - switch (*(l+i)) { + while (*(l + i) != 0) { + switch (*(l + i)) { case 'g': if (restring[0] == 's') replace = GLOBAL; @@ -124,11 +124,11 @@ void cRegexp::ParseRegexp(char *restring) char *p = &restring[2]; while (p = strchr(p, '/')) { // check for escaped slashes - if (*(p-1) != '\\') { + if (*(p - 1) != '\\') { *p = 0; regexp = strdup(&restring[2]); - if (*(p+1) != '/') // - replacement = strdup(p+1); + if (*(p + 1) != '/') // + replacement = strdup(p + 1); else replacement = strdup(""); break; @@ -151,43 +151,30 @@ void cRegexp::SetFromString(char *s, bool Enabled) FREE(replacement); Free(); FreeCompiled(); - enabled = Enabled; - bool compile = true; - // comments are not analysed - if (s[0] == '#') { - enabled = false; - source = REGEXP_UNDEFINED; - string = strdup(s); - return; - } - // inactive regexps - if (s[0] == '!') { - enabled = compile = false; - string = strdup(s+1); - } - else - string = strdup(s); - char *p = strchr(s, '='); - if (p) { - *p = 0; - ParseRegexp(p + 1); - char *chanfield = (s[0] == '!') ? s+1 : s; - char *field = chanfield; - // find active channels list - char *f = strchr(chanfield, ':'); - if (f) { - *f = 0; - field = f+1; - numchannels = LoadChannelsFromString(chanfield); - } - if (strcmp(field, "title") == 0) - source = REGEXP_TITLE; - if (strcmp(field, "shorttext") == 0) - source = REGEXP_SHORTTEXT; - if (strcmp(field, "description") == 0) - source = REGEXP_DESCRIPTION; - if (compile) + source = REGEXP_UNDEFINED; + cListItem::SetFromString(s, Enabled); + if (enabled) { + char *p = strchr(s, '='); + if (p) { + *p = 0; + ParseRegexp(p + 1); + char *chanfield = (s[0] == '!') ? s + 1 : s; + char *field = chanfield; + // find active channels list + char *f = strchr(chanfield, ':'); + if (f) { + *f = 0; + field = f + 1; + numchannels = LoadChannelsFromString(chanfield); + } + if (strcmp(field, "title") == 0) + source = REGEXP_TITLE; + if (strcmp(field, "shorttext") == 0) + source = REGEXP_SHORTTEXT; + if (strcmp(field, "description") == 0) + source = REGEXP_DESCRIPTION; Compile(); + } } } @@ -222,7 +209,7 @@ bool cRegexp::Apply(cEvent *Event) // loop through matches while ((rc = pcre_exec(re, sd, *tmpstring, tmpstringlen, start_offset, options, ovector, OVECCOUNT)) > 0) { last_match_end = ovector[1]; - resultstring = cString::sprintf("%s%.*s%s", *resultstring, ovector[0]-start_offset, &tmpstring[start_offset], replacement); + resultstring = cString::sprintf("%s%.*s%s", *resultstring, ovector[0] - start_offset, &tmpstring[start_offset], replacement); options = 0; if (ovector[0] == ovector[1]) { if (ovector[0] == tmpstringlen) @@ -234,8 +221,8 @@ bool cRegexp::Apply(cEvent *Event) start_offset = ovector[1]; } // replace EPG field if regexp matched - if (last_match_end > 0 && (last_match_end < tmpstringlen-1)) { - resultstring = cString::sprintf("%s%s", *resultstring, tmpstring+last_match_end); + if (last_match_end > 0 && (last_match_end < tmpstringlen - 1)) { + resultstring = cString::sprintf("%s%s", *resultstring, tmpstring + last_match_end); switch (source) { case REGEXP_TITLE: Event->SetTitle(resultstring); @@ -256,7 +243,7 @@ bool cRegexp::Apply(cEvent *Event) const char *string; rc = pcre_exec(re, sd, *tmpstring, strlen(*tmpstring), 0, 0, ovector, OVECCOUNT); if (rc == 0) { - error("maximum number of captured substrings is %d\n", OVECCOUNT/3 - 1); + error("maximum number of captured substrings is %d\n", OVECCOUNT / 3 - 1); } else if (rc > 0) { int i = 0; @@ -108,22 +108,22 @@ static char *htmlcharconv(char *str, struct conv_table *conv, unsigned int elem) { if (str && conv) { for (unsigned int i = 0; i < elem; ++i) { - char *ptr = strstr(str, conv[i].from); - while (ptr) { - long of = ptr - str; - size_t l = strlen(str); - size_t l1 = strlen(conv[i].from); - size_t l2 = strlen(conv[i].to); - if (l2 > l1) { - error("htmlcharconv(): cannot reallocate string"); - return str; - } - if (l2 != l1) - memmove(str + of + l2, str + of + l1, l - of - l1 + 1); - strncpy(str + of, conv[i].to, l2); - ptr = strstr(str, conv[i].from); - } - } + char *ptr = strstr(str, conv[i].from); + while (ptr) { + long of = ptr - str; + size_t l = strlen(str); + size_t l1 = strlen(conv[i].from); + size_t l2 = strlen(conv[i].to); + if (l2 > l1) { + error("htmlcharconv(): cannot reallocate string"); + return str; + } + if (l2 != l1) + memmove(str + of + l2, str + of + l1, l - of - l1 + 1); + strncpy(str + of, conv[i].to, l2); + ptr = strstr(str, conv[i].from); + } + } return str; } return NULL; @@ -139,14 +139,14 @@ char *striphtml(char *str) c = str; r = str; while (*str != '\0') { - if (*str == '<') - t++; - else if (*str == '>') - t--; - else if (t < 1) - *(c++) = *str; - str++; - } + if (*str == '<') + t++; + else if (*str == '>') + t--; + else if (t < 1) + *(c++) = *str; + str++; + } *c = '\0'; return htmlcharconv(r, post_conv_table, ELEMENTS(post_conv_table)); } @@ -198,20 +198,20 @@ void cAddEventThread::Action(void) { SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { - cAddEventListItem *e = NULL; - cSchedulesLock SchedulesLock(true, 10); - cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); - Lock(); - while (schedules && (e = list->First()) != NULL) { - cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID(e->GetChannelID()), true); - schedule->AddEvent(e->GetEvent()); - EpgHandlers.SortSchedule(schedule); - EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); - list->Del(e); - } - Unlock(); - cCondWait::SleepMs(10); - } + cAddEventListItem *e = NULL; + cSchedulesLock SchedulesLock(true, 10); + cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); + Lock(); + while (schedules && (e = list->First()) != NULL) { + cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID(e->GetChannelID()), true); + schedule->AddEvent(e->GetEvent()); + EpgHandlers.SortSchedule(schedule); + EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); + list->Del(e); + } + Unlock(); + cCondWait::SleepMs(10); + } } void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) @@ -306,7 +306,7 @@ int cListItem::LoadChannelsFromString(const char *string) ++numchannels; char *d = 0; if (numbers && (d = strchr(c, '-')))// only true if numbers are used - numchannels = numchannels + atoi(d+1) - atoi(c); + numchannels = numchannels + atoi(d + 1) - atoi(c); c = strtok(NULL, ","); } free(tmpstring); @@ -325,10 +325,10 @@ int cListItem::LoadChannelsFromString(const char *string) if (numbers) { channels_num[i] = atoi(c); if (char *d = strchr(c, '-')) { - int count = atoi(d+1) - channels_num[i] + 1; + int count = atoi(d + 1) - channels_num[i] + 1; int j = 1; while (j < count) { - channels_num[i+j] = channels_num[i] + j; + channels_num[i + j] = channels_num[i] + j; ++j; } i = i + count; @@ -344,6 +344,18 @@ int cListItem::LoadChannelsFromString(const char *string) return numchannels; } +void cListItem::SetFromString(char *s, bool Enabled) +{ + enabled = Enabled; + if (s[0] == '!') + string = strdup(s + 1); + else + string = strdup(s); + // disable comments and inactive lines + if (s[0] == '!' || s[0] == '#') + enabled = false; +} + void cListItem::ToggleEnabled(void) { enabled = !enabled; @@ -66,7 +66,7 @@ protected: ++line; if (!isempty(s)) { this->Add(new LISTITEM()); - cList<LISTITEM>::Last()->SetFromString(s, true); + cList<LISTITEM>::Last()->LISTITEM::SetFromString(s, true); if (cList<LISTITEM>::Last()->Enabled()) { ++count; logmsg = cString::sprintf("%s%s%i", *logmsg, count == 1 ? " " : ",", line); |