[SCM] Development fot GoFind! branch, master, updated. ae4c9669bf6e49ef0106398f49b75a85391b8b3f

Miriam Ruiz miriam at debian.org
Mon Nov 24 00:20:18 UTC 2008


The following commit has been merged in the master branch:
commit ae4c9669bf6e49ef0106398f49b75a85391b8b3f
Author: Miriam Ruiz <miriam at debian.org>
Date:   Mon Nov 24 01:22:55 2008 +0100

    Open filter configuration data and parse its contents

diff --git a/Makefile b/Makefile
index 74b689b..247d0b1 100644
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,7 @@ LIBS= -lept -lept-core -lapt-pkg -lxapian -ldl `pkg-config libtagcoll2 boolstuff
 
 OBJS= Engine.o Environment.o filter.o field.o gofind.o \
 	taghandler.o cfgmanager.o boolparser.o \
-	utf8.o dll.o guiplugin.o pkgdata.o
+	utf8.o dll.o guiplugin.o pkgdata.o slre.o
 
 PLUGINS= gui_cli.so gui_fltk.so
 
@@ -38,7 +38,7 @@ all: gofind $(PLUGINS)
 gofind: $(OBJS)
 	g++ -o $@ $+ -rdynamic $(LDFLAGS) $(LIBS)
 
-gui_cli.so: gui_cli.o slre.o
+gui_cli.so: gui_cli.o
 
 %.o: %.cpp
 	g++ -o $@ -c $+ $(CFLAGS)
diff --git a/filter.cfg b/filter.cfg
new file mode 100644
index 0000000..7926d98
--- /dev/null
+++ b/filter.cfg
@@ -0,0 +1,5 @@
+black=rating:sex::violence
+red=rating:violence::non-realistic:optional
+red=rating:violence::non-realistic
+yellow =   rating:theme::horror
+green = rating:violence::none & rating:sex::none & rating:language::benign & rating:discrimination::none               
diff --git a/filter.cpp b/filter.cpp
index a11f6b7..fedb1ce 100644
--- a/filter.cpp
+++ b/filter.cpp
@@ -21,12 +21,18 @@
 #include "filter.h"
 #include "taghandler.h"
 #include "boolparser.h"
+#include "slre.h"
 
 #ifdef UNIT_TEST
 #include "CuTest.h"
 #endif
 
 #include <string>
+#include <fstream>
+#include <vector>
+
+#include <string.h>
+
 #include <ept/debtags/tag.h>
 
 #define GREEN_MINIMUM 2
@@ -145,9 +151,6 @@ PackageFilter::PackageFilter()
 	AddLast(element);
 
 	AddLast("a&(b|c|d)&d");
-
-	Print(std::cerr);
-	std::cerr << std::endl;
 }
 
 PackageFilter::~PackageFilter()
@@ -155,6 +158,61 @@ PackageFilter::~PackageFilter()
 	DeleteList();
 }
 
+using namespace std;
+
+bool PackageFilter::Load(const char *filename)
+{
+	struct slre_pattern pattern[1];
+	const char *pattern_text[1];
+	const char pattern_type[] = { 'd', '\0' };
+	pattern_text[0] = "^\\s*(\\S+)\\s*=\\s*((\\S|\\s)*\\S)\\s*$";
+	pattern_text[1] = NULL;
+
+	int j = 0;
+	while (pattern_text[j] != NULL)
+	{
+		if (!slre_compile(&pattern[j], pattern_text[j]))
+			std::cerr << _("Error compiling RE: ") << pattern[j].err_str << std::endl;
+		j++;
+	}
+
+	ifstream ifs(filename);
+	string line;
+
+	while( getline( ifs, line ) )
+	{
+		cout << "in: " << line << endl;
+		const char *buffer = line.c_str();
+		struct slre_capture captures[16];
+		int match = -1;
+		int j = 0;
+		while (match == -1 && pattern_text[j] != NULL)
+		{
+			if (slre_match(pattern+j, buffer, strlen(buffer), captures))
+			{
+				match = j;
+			}
+			j++;
+		}
+		if (match == -1)
+			cout << "Syntax Error" << std::endl;
+		else switch (pattern_type[match])
+		{
+			case 'd':
+			{
+				cout << "Assign: '"<< std::string(captures[1].ptr).substr(0,captures[1].len) <<
+					"' := \"" << std::string(captures[2].ptr).substr(0,captures[2].len) << "\"" << endl;
+				break;
+			}
+		}
+	}
+
+	Print(std::cerr);
+	std::cerr << std::endl;
+
+	return true;
+}
+
 /* Find out the color of a single tag */
 int PackageFilter::TagValue(const Tag &tag)
 {
diff --git a/filter.h b/filter.h
index 55e34f2..5d337bd 100644
--- a/filter.h
+++ b/filter.h
@@ -31,6 +31,9 @@ public:
 	PackageFilter();
 	~PackageFilter();
 
+	inline void Clean() { DeleteList(); }
+	bool Load(const char *filename);
+
 	typedef enum {
 		Unknown = 1,   // The calification for the tag/package is unknown
 		Green, // Green light, the tag/package is safe
diff --git a/gofind.cpp b/gofind.cpp
index 4a1731f..49b3cfe 100644
--- a/gofind.cpp
+++ b/gofind.cpp
@@ -188,6 +188,9 @@ int main(int argc, const char* argv[])
 			pkgdata.globalFilter = fquery;
 		}
 
+		pkgdata.GetPackageFilter().Clean();
+		pkgdata.GetPackageFilter().Load("filter.cfg");
+
 		/*
 		cerr << " *** Initial:" << endl;
 		printResults(pkgdata);
diff --git a/gui_cli.cpp b/gui_cli.cpp
index ef2116e..b63442e 100644
--- a/gui_cli.cpp
+++ b/gui_cli.cpp
@@ -49,33 +49,6 @@ using namespace ept::debtags;
 using namespace ept::apt;
 using namespace ept::textsearch;
 
-/*
-static bool slre_test_capture(const struct slre_capture &c, const char *txt)
-{
-	if (memcmp(c.ptr, txt, c.len) == 0)
-		return true;
-	return false;
-}
-*/
-
-static bool slre_test_capture(const struct slre_capture &c, int num, ... )
-{
-	const char *s;
-	va_list argptr;
-	va_start( argptr, num );
-	for( ; num > 0; num-- )
-	{
-		s = va_arg(argptr, char *);
-		if (memcmp(c.ptr, s, c.len) == 0)
-		{
-			va_end( argptr );
-			return true;
-		}
-	}
-	va_end( argptr );
-	return false;
-}
-
 static bool Go(PackageData &pkgdata)
 {
 	std::ostream &out = std::cout;
@@ -90,7 +63,7 @@ static bool Go(PackageData &pkgdata)
 	pattern_text[0] = "^\\s*(HELP|H)\\s*$";
 	pattern_text[1] = "^\\s*(LIST|L)\\s+(T|TYPES|I|INTERFACES|R|RESULTS)\\s*$";
 	pattern_text[2] = "^\\s*(GET|G)\\s+(\\S+)\\s*$";
-	pattern_text[3] = "^\\s*(SET|S)\\s+(\\S+)\\s*=\\s*((\\S|\\s)*)\\S\\s*$";
+	pattern_text[3] = "^\\s*(SET|S)\\s+(\\S+)\\s*=\\s*((\\S|\\s)*\\S)\\s*$";
 	pattern_text[4] = NULL;
 
 	int j = 0;
@@ -220,7 +193,7 @@ static bool Go(PackageData &pkgdata)
 				strncpy(name, captures[2].ptr, captures[2].len);
 				name[captures[2].len] = '\0';
 				out << "# Get " << name << std::endl ;
-				if (slre_test_capture(captures[2], 2, "INSTALLED", "INST"))
+				if (slre_compare_capture_multi(&captures[2], 2, "INSTALLED", "INST"))
 				{
 					switch (pkgdata.getInstalledFilter())
 					{
@@ -238,15 +211,15 @@ static bool Go(PackageData &pkgdata)
 							break;
 					}
 				}
-				else if (slre_test_capture(captures[2], 4, "KEYWORD", "KEYW", "KW", "K"))
+				else if (slre_compare_capture_multi(&captures[2], 4, "KEYWORD", "KEYW", "KW", "K"))
 				{
 					out << "keyword=\"" << pkgdata.getKeywordFilter() << "\"" << std::endl ;
 				}
-				else if (slre_test_capture(captures[2], 2, "TYPE", "T"))
+				else if (slre_compare_capture_multi(&captures[2], 2, "TYPE", "T"))
 				{
 					out << "type=?" << std::endl ;
 				}
-				else if (slre_test_capture(captures[2], 3, "INTERFACE", "IFACE", "IF"))
+				else if (slre_compare_capture_multi(&captures[2], 3, "INTERFACE", "IFACE", "IF"))
 				{
 					out << "interface=?" << std::endl ;
 				}
@@ -262,19 +235,19 @@ static bool Go(PackageData &pkgdata)
 				strncpy(name, captures[2].ptr, captures[2].len);
 				name[captures[2].len] = '\0';
 				out << "# Set " << name << " to " << captures[3].ptr <<std::endl ;
-				if (slre_test_capture(captures[2], 2, "INSTALLED", "INST"))
+				if (slre_compare_capture_multi(&captures[2], 2, "INSTALLED", "INST"))
 				{
-					if (slre_test_capture(captures[3], 4, "yes", "y", "true", "1"))
+					if (slre_compare_capture_multi(&captures[3], 4, "yes", "y", "true", "1"))
 					{
 						out << "# installed=yes" << std::endl ;
 						pkgdata.setInstalledFilter(Engine::INSTALLED);
 					}
-					else if (slre_test_capture(captures[3], 4, "no", "n", "false", "0"))
+					else if (slre_compare_capture_multi(&captures[3], 4, "no", "n", "false", "0"))
 					{
 						out << "# installed=no" << std::endl ;
 						pkgdata.setInstalledFilter(Engine::NOTINSTALLED);
 					}
-					else if (slre_test_capture(captures[3], 2, "any", "*"))
+					else if (slre_compare_capture_multi(&captures[3], 2, "any", "*"))
 					{
 						out << "# installed=any" << std::endl ;
 						pkgdata.setInstalledFilter(Engine::ANY);
@@ -284,17 +257,17 @@ static bool Go(PackageData &pkgdata)
 						out << "# Unknown value for installed" << std::endl ;
 					}
 				}
-				else if (slre_test_capture(captures[2], 4, "KEYWORD", "KEYW", "KW", "K"))
+				else if (slre_compare_capture_multi(&captures[2], 4, "KEYWORD", "KEYW", "KW", "K"))
 				{
 					char *kw = strndup(captures[3].ptr, captures[3].len);
 					pkgdata.setKeywordFilter(kw);
 					out << "keyword=\"" << pkgdata.getKeywordFilter() << "\"" << std::endl ;
 				}
-				else if (slre_test_capture(captures[2], 2, "TYPE", "T"))
+				else if (slre_compare_capture_multi(&captures[2], 2, "TYPE", "T"))
 				{
 					out << "type=?" << std::endl ;
 				}
-				else if (slre_test_capture(captures[2], 3, "INTERFACE", "IFACE", "IF"))
+				else if (slre_compare_capture_multi(&captures[2], 3, "INTERFACE", "IFACE", "IF"))
 				{
 					out << "interface=?" << std::endl ;
 				}
diff --git a/guiplugin.h b/guiplugin.h
index 93d8c47..0dec8a0 100644
--- a/guiplugin.h
+++ b/guiplugin.h
@@ -46,7 +46,7 @@ class GUIPlugIn : public DLLManager
 
 	inline int Go(PackageData &pkgdata)
 	{
-		if (go) go(pkgdata);
+		if (go) return go(pkgdata);
 		std::cout << _("No go function found in plugin.") << std::endl;
 		return -1; // error
 	}
diff --git a/slre.c b/slre.c
index a1ad26e..ac50590 100644
--- a/slre.c
+++ b/slre.c
@@ -1,4 +1,24 @@
 /*
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
  * Copyright (c) 2004-2005 Sergey Lyubka <valenok at gmail.com>
  * All rights reserved
  *
@@ -23,6 +43,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <stdarg.h>
 
 enum {END, BRANCH, ANY, EXACT, ANYOF, ANYBUT, OPEN, CLOSE, BOL, EOL,
 	STAR, PLUS, STARQ, PLUSQ, QUEST, SPACE, NONSPACE, DIGIT};
@@ -647,6 +668,31 @@ int slre_match(const struct slre_pattern *r, const char *buf, int len,
 	return (res);
 }
 
+int slre_compare_capture_single(const struct slre_capture *c, const char *txt)
+{
+	if (memcmp(c->ptr, txt, c->len) == 0)
+		return 1;
+	return 0;
+}
+
+int slre_compare_capture_multi(const struct slre_capture *c, int num, ... )
+{
+	const char *s;
+	va_list argptr;
+	va_start( argptr, num );
+	for( ; num > 0; num-- )
+	{
+		s = va_arg(argptr, char *);
+		if (memcmp(c->ptr, s, c->len) == 0)
+		{
+			va_end( argptr );
+			return 1;
+		}
+	}
+	va_end( argptr );
+	return 0;
+}
+
 #ifdef TEST_SLRE
 int main(int argc, char *argv[])
 {
diff --git a/slre.h b/slre.h
index e565612..8433f67 100644
--- a/slre.h
+++ b/slre.h
@@ -1,4 +1,24 @@
 /*
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
  * Copyright (c) 2004-2005 Sergey Lyubka <valenok at gmail.com>
  * All rights reserved
  *
@@ -105,6 +125,10 @@ int slre_match(const struct slre_pattern *, const char *buf, int buf_len,
 
 void slre_dump(const struct slre_pattern *r, FILE *fp);
 
+int slre_compare_capture_single(const struct slre_capture *c, const char *txt);
+
+int slre_compare_capture_multi(const struct slre_capture *c, int num, ... );
+
 #ifdef __cplusplus
 }
 #endif

-- 
Development fot GoFind!



More information about the Pkg-games-commits mailing list