summaryrefslogtreecommitdiff
path: root/epgsearchcats.c
diff options
context:
space:
mode:
authorChristian Wieninger <winni@debian.(none)>2007-11-11 15:40:28 +0100
committerChristian Wieninger <winni@debian.(none)>2007-11-11 15:40:28 +0100
commit8d4f8607dc1558ce73eb4c376bdbf78ddb65da83 (patch)
treed0c5dde81a36ab2e8a2edc7c1e6922556518b312 /epgsearchcats.c
downloadvdr-plugin-epgsearch-8d4f8607dc1558ce73eb4c376bdbf78ddb65da83.tar.gz
vdr-plugin-epgsearch-8d4f8607dc1558ce73eb4c376bdbf78ddb65da83.tar.bz2
Initial commit
Diffstat (limited to 'epgsearchcats.c')
-rw-r--r--epgsearchcats.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/epgsearchcats.c b/epgsearchcats.c
new file mode 100644
index 0000000..3400bc0
--- /dev/null
+++ b/epgsearchcats.c
@@ -0,0 +1,146 @@
+/*
+Copyright (C) 2004-2007 Christian Wieninger
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+
+The author can be reached at cwieninger@gmx.de
+
+The project's page is at http://winni.vdr-developer.org/epgsearch
+*/
+
+#include <string>
+#include "epgsearchcats.h"
+#include "log.h"
+#include <vdr/tools.h>
+
+using std::string;
+
+// -- cSearchExtCat -----------------------------------------------------------------
+cSearchExtCat::cSearchExtCat(void)
+{
+ id = 0;
+ name = NULL;
+ menuname = NULL;
+ searchmode = 1; // default: all substrings must exist
+ values = NULL;
+ nvalues = 0;
+}
+
+cSearchExtCat::~cSearchExtCat(void)
+{
+ free(name);
+ free(menuname);
+ 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;
+
+#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);
+ break;
+ case 3: menuname = strdup(value);
+ break;
+ case 4:
+ {
+ char* szBuffer = strdup(value);
+ char* pptr;
+ char* pstrToken=strtok_r(szBuffer, ",", &pptr);
+ while(pstrToken)
+ {
+ nvalues++;
+ values = (char**) realloc(values, nvalues * sizeof(char*));
+ values[nvalues-1] = strdup(pstrToken);
+ pstrToken=strtok_r(NULL, ",", &pptr);
+ }
+ free(szBuffer);
+ break;
+ }
+ case 5:
+ searchmode = atoi(value);
+ break;
+ break;
+ } //switch
+ }
+ parameter++;
+ }
+ if (*pos) pos++;
+ } //while
+
+ 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)?", ":"");
+
+ asprintf(&buffer, "%d|%s|%s|%s|%d",
+ id, name, menuname, sValues.c_str(), searchmode);
+ return buffer;
+}
+
+// -- 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;
+}