diff options
Diffstat (limited to 'epgsearchcats.c')
-rw-r--r-- | epgsearchcats.c | 184 |
1 files changed, 89 insertions, 95 deletions
diff --git a/epgsearchcats.c b/epgsearchcats.c index fba8b5b..3d3a965 100644 --- a/epgsearchcats.c +++ b/epgsearchcats.c @@ -45,108 +45,103 @@ cSearchExtCat::~cSearchExtCat(void) { free(name); free(menuname); - for(int i=0; i<nvalues; i++) - free(values[i]); + for (int i = 0; i < nvalues; i++) + free(values[i]); free(values); } bool cSearchExtCat::Parse(const char *s) { - char *line; - char *pos; - char *pos_next; - int parameter = 1; - int valuelen; + char *line; + char *pos; + char *pos_next; + int parameter = 1; + int valuelen; #define MAXVALUELEN (10 * MaxFileName) - char value[MAXVALUELEN]; - - pos = line = strdup(s); - pos_next = pos + strlen(pos); - if (*pos_next == '\n') *pos_next = 0; - while (*pos) { - while (*pos == ' ') pos++; - if (*pos) { - if (*pos != '|') { - pos_next = strchr(pos, '|'); - if (!pos_next) - pos_next = pos + strlen(pos); - valuelen = pos_next - pos + 1; - if (valuelen > MAXVALUELEN) - { - LogFile.eSysLog("entry '%s' is too long. Will be truncated!", pos); - valuelen = MAXVALUELEN; - } - strn0cpy(value, pos, valuelen); - pos = pos_next; - switch (parameter) { - case 1: id = atoi(value); - break; - case 2: - { - name = strdup(value); - format=strchr(name,','); - if (format) - { - *format=0; - format++; - char cset[]="%0123456789di"; - if (strspn(format,cset)!=strlen(format)) format=NULL; - } - break; - } - case 3: menuname = strdup(value); - break; - case 4: - { - char* szBuffer = strdup(value); - char* pptr; - char* pstrToken=strtok_r(szBuffer, ",", &pptr); - while(pstrToken) - { - nvalues++; - char **tmp = (char**) realloc(values, nvalues * sizeof(char*)); - if (tmp) - { - values=tmp; - values[nvalues-1] = strdup(pstrToken); + char value[MAXVALUELEN]; + + pos = line = strdup(s); + pos_next = pos + strlen(pos); + if (*pos_next == '\n') *pos_next = 0; + while (*pos) { + while (*pos == ' ') pos++; + if (*pos) { + if (*pos != '|') { + pos_next = strchr(pos, '|'); + if (!pos_next) + pos_next = pos + strlen(pos); + valuelen = pos_next - pos + 1; + if (valuelen > MAXVALUELEN) { + LogFile.eSysLog("entry '%s' is too long. Will be truncated!", pos); + valuelen = MAXVALUELEN; + } + strn0cpy(value, pos, valuelen); + pos = pos_next; + switch (parameter) { + case 1: + id = atoi(value); + break; + case 2: { + name = strdup(value); + format = strchr(name, ','); + if (format) { + *format = 0; + format++; + char cset[] = "%0123456789di"; + if (strspn(format, cset) != strlen(format)) format = NULL; } - pstrToken=strtok_r(NULL, ",", &pptr); - } - free(szBuffer); - break; - } - case 5: - searchmode = atoi(value); - break; - default: - break; - } //switch - } - parameter++; - } - if (*pos) pos++; - } //while + break; + } + case 3: + menuname = strdup(value); + break; + case 4: { + char* szBuffer = strdup(value); + char* pptr; + char* pstrToken = strtok_r(szBuffer, ",", &pptr); + while (pstrToken) { + nvalues++; + char **tmp = (char**) realloc(values, nvalues * sizeof(char*)); + if (tmp) { + values = tmp; + values[nvalues - 1] = strdup(pstrToken); + } + pstrToken = strtok_r(NULL, ",", &pptr); + } + free(szBuffer); + break; + } + case 5: + searchmode = atoi(value); + break; + default: + break; + } //switch + } + parameter++; + } + if (*pos) pos++; + } //while - free(line); - return (parameter >= 3) ? true : false; + free(line); + return (parameter >= 3) ? true : false; } const char *cSearchExtCat::ToText(void) { char* buffer = NULL; string sValues = ""; - for(int i=0; i<nvalues; i++) - sValues += string(values[i]) + ((i<nvalues-1)?", ":""); + for (int i = 0; i < nvalues; i++) + sValues += string(values[i]) + ((i < nvalues - 1) ? ", " : ""); - if (format) - { + if (format) { msprintf(&buffer, "%d|%s,%s|%s|%s|%d", - id, name, format, menuname, sValues.c_str(), searchmode); + id, name, format, menuname, sValues.c_str(), searchmode); } else { msprintf(&buffer, "%d|%s|%s|%s|%d", - id, name, menuname, sValues.c_str(), searchmode); + id, name, menuname, sValues.c_str(), searchmode); } return buffer; } @@ -154,17 +149,16 @@ const char *cSearchExtCat::ToText(void) // -- cSearchExtCats ---------------------------------------------------------------- int cSearchExtCats::GetIndexFromID(int id) { - cSearchExtCat *SearchExtCat = SearchExtCats.First(); - int index = 0; - while (SearchExtCat) - { - if (SearchExtCat->id == id) - break; - index++; - SearchExtCat = SearchExtCats.Next(SearchExtCat); - } - if (!SearchExtCat && index == 0) - return -1; - else - return index; + cSearchExtCat *SearchExtCat = SearchExtCats.First(); + int index = 0; + while (SearchExtCat) { + if (SearchExtCat->id == id) + break; + index++; + SearchExtCat = SearchExtCats.Next(SearchExtCat); + } + if (!SearchExtCat && index == 0) + return -1; + else + return index; } |