r5896 - software/gofind

Miriam Ruiz baby-guest at alioth.debian.org
Fri Feb 22 08:32:09 UTC 2008


Author: baby-guest
Date: 2008-02-22 08:32:08 +0000 (Fri, 22 Feb 2008)
New Revision: 5896

Modified:
   software/gofind/common.h
   software/gofind/gofind.cpp
   software/gofind/slre.c
   software/gofind/slre.h
Log:
SLRE now works properly with UTF8
gofind shows experimentally some results now



Modified: software/gofind/common.h
===================================================================
--- software/gofind/common.h	2008-02-21 23:48:10 UTC (rev 5895)
+++ software/gofind/common.h	2008-02-22 08:32:08 UTC (rev 5896)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2007  Enrico Zini <enrico at debian.org>
- * Copyright (C) 2007  Miriam Ruiz <little_miry at yahoo.es>
+ * Copyright (C) 2007, 2008  Miriam Ruiz <little_miry at yahoo.es>
  *
  * 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
@@ -24,7 +24,7 @@
 extern "C" {
 #endif /* __cplusplus */
 
-#undef USE_UTF8
+#define USE_UTF8
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>

Modified: software/gofind/gofind.cpp
===================================================================
--- software/gofind/gofind.cpp	2008-02-21 23:48:10 UTC (rev 5895)
+++ software/gofind/gofind.cpp	2008-02-22 08:32:08 UTC (rev 5896)
@@ -443,24 +443,11 @@
 		struct slre_pattern pget;
 		struct slre_pattern pset;
 
-		if (!slre_compile(&pget, "^\\s*(GET|G)\\s+(\\S+)\\s*$"))
+		if (!slre_compile(&pget, "^\\s*(GET|G)\\s+(TYPES|INTERFACES|RESULTS)\\s*$"))
 			std::cerr << _("Error compiling RE: ") << pget.err_str << std::endl;
 		if (!slre_compile(&pset, "^\\s*(SET|S)\\s+(\\S+)\\s+(\\S+)\\s*$"))
 			std::cerr << _("Error compiling RE: ") << pget.err_str << std::endl;
 
-	while (run && !feof(stdin)) {
-		struct slre_capture captures[4 + 1];
-		struct slre_pattern ptest;
-		if (!slre_compile(&ptest, "^\\s*(Año|Día|Coäëìt| \f\r\n\t\v|[leña][^lâo])\\s+(\\S+)\\s*$"))
-			std::cerr << _("Error compiling RE: ") << pget.err_str << std::endl;
-		slre_dump(&ptest, stdout);
-		char buffer[128];
-		fgets(buffer, sizeof(buffer), stdin);
-			if (slre_match(&ptest, buffer, strlen(buffer), captures))
-				out << "TEST: \"" << captures[2].ptr <<  "\"" << std::endl;
-	}
-exit(1);
-
 		while (run && !feof(stdin))
 		{
 			char buffer[128];
@@ -475,10 +462,81 @@
 					break;
 				}
 			}
+
 			if (slre_match(&pset, buffer, strlen(buffer), captures))
 				out << "#set: \"" << captures[3].ptr <<  "\"" << std::endl;
 			else if (slre_match(&pget, buffer, strlen(buffer), captures))
+			{
 				out << "#get: \"" << captures[2].ptr <<  "\"" << std::endl;
+				switch (captures[2].ptr[0])
+				{
+					case 'T': case 't':
+					{
+						const set<Tag> types = engine.types();
+						for (set<Tag>::const_iterator i = types.begin(); i != types.end(); ++i)
+						{
+							out << " " << gettext(i->shortDescription().c_str()) << std::endl;
+						}
+						out << std::endl ;
+						break;
+					}
+					case 'I': case 'i':
+					{
+						const set<Tag> ifaces = engine.interfaces();
+						for (set<Tag>::const_iterator i = ifaces.begin();
+								i != ifaces.end(); ++i)
+						{
+							out << " " << gettext(i->shortDescription().c_str()) << std::endl;
+						}
+						out << std::endl ;
+						break;
+					}
+					case 'R': case 'r':
+					{
+						const std::vector<Result> res = engine.results();
+						for (vector<Result>::const_iterator i = res.begin();
+								i != res.end(); ++i)
+						{
+							PackageRecord rec(engine.apt().rawRecord(i->name));
+//							char* userData = pkgString(rec.package());
+
+							set<Tag> tags = engine.debtags().getTagsOfItem((const char *)rec.package().c_str());
+							switch (pkgfilter.TagsValue(tags))
+							{
+								case PackageFilter::Green:
+									break;
+								case PackageFilter::Yellow:
+									break;
+								case PackageFilter::Red:
+									break;
+								case PackageFilter::Black:
+									break;
+								default:
+									break;
+							}
+
+							out << " "<<  rec.package() + "\t" + rec.shortDescription();
+
+							// Relevance is 0 to 100
+							// Popcon is a weird floating point number (to be improved)
+							//FIXMEaddToResults(rec.package() + " - " + rec.shortDescription(), i->relevance, i->popcon);
+							if (engine.popcon().hasData() && i->popcon)
+							{
+								out << "\tPOPCON=" << (int)rintf(log(i->popcon) * 100 / log(engine.popconLocalMax()));
+							}
+
+							if (engine.popcon().hasData() && i->relevance)
+							{
+								out << "\tRELEVANCE=" << i->relevance;
+							}
+
+							out << std::endl ;
+						}
+						out << std::endl ;
+						break;
+					}
+				}
+			}
 			else
 				out << "#unknown: \"" << buffer << "\"" << std::endl;
 		}

Modified: software/gofind/slre.c
===================================================================
--- software/gofind/slre.c	2008-02-21 23:48:10 UTC (rev 5895)
+++ software/gofind/slre.c	2008-02-22 08:32:08 UTC (rev 5896)
@@ -422,34 +422,30 @@
 	*ofs = saved_offset;
 }
 
-static int is_any_of(const unsigned char *p, int len, const char *s, int *ofs)
+#ifdef USE_UTF8
+static int is_any_of(const unsigned char *p, int len, unsigned long uchar)
 {
-	int	i, ch;
-
-	ch = s[*ofs];
-
-	for (i = 0; i < len; i++)
-		if (p[i] == ch) {
-			(*ofs)++;
-			return (1);
-		}
-
-	return (0);
+	int tmp_csize;
+	unsigned long tmp_uchar;
+	int i = 0;
+	while (i < len) {
+		tmp_csize = helper_utf8_to_unicode_char(&tmp_uchar, ((unsigned char *)p) + i, len - i);
+		if (tmp_uchar == uchar)
+			return 1;
+		i += ( tmp_csize ? tmp_csize : 1 );
+	}
+	return 0;
 }
-
-static int is_any_but(const unsigned char *p, int len, const char *s, int *ofs)
+#else
+static int is_any_of(const unsigned char *p, int len, char ch)
 {
-	int	i, ch;
-
-	ch = s[*ofs];
-
+	int i;
 	for (i = 0; i < len; i++)
 		if (p[i] == ch)
-			return (0);
-
-	(*ofs)++;
-	return (1);
+			return 1;
+	return 0;
 }
+#endif
 
 static int match(const struct slre_pattern *r, int pc, const char *s, int len,
 		int *ofs, struct slre_capture *caps)
@@ -576,16 +572,30 @@
 			break;
 		case ANYOF:
 			res = 0;
-			if (*ofs < len)
-				res = is_any_of(r->data + r->code[pc + 1],
-					r->code[pc + 2], s, ofs);
+			if (*ofs < len) {
+#ifdef USE_UTF8
+				csize = helper_utf8_to_unicode_char(&uchar, ((unsigned char *)s) + *ofs, len - *ofs);
+				res = is_any_of(r->data + r->code[pc + 1], r->code[pc + 2], uchar);
+				if (res) (*ofs) += csize;
+#else
+				res = is_any_of(r->data + r->code[pc + 1], r->code[pc + 2], s[*ofs]);
+				if (res) (*ofs)++;
+#endif
+			}
 			pc += 3;
 			break;
 		case ANYBUT:
 			res = 0;
-			if (*ofs < len)
-				res = is_any_but(r->data + r->code[pc + 1],
-					r->code[pc + 2], s, ofs);
+			if (*ofs < len) {
+#ifdef USE_UTF8
+				csize = helper_utf8_to_unicode_char(&uchar, ((unsigned char *)s) + *ofs, len - *ofs);
+				res = ! is_any_of(r->data + r->code[pc + 1], r->code[pc + 2], uchar);
+				if (res) (*ofs) += csize;
+#else
+				res = ! is_any_of(r->data + r->code[pc + 1], r->code[pc + 2], s[*ofs]);
+				if (res) (*ofs)++;
+#endif
+			}
 			pc += 3;
 			break;
 		case BOL:

Modified: software/gofind/slre.h
===================================================================
--- software/gofind/slre.h	2008-02-21 23:48:10 UTC (rev 5895)
+++ software/gofind/slre.h	2008-02-22 08:32:08 UTC (rev 5896)
@@ -55,16 +55,18 @@
 extern "C" {
 #endif /* __cplusplus */
 
+#ifdef USE_UTF8
+	typedef unsigned long slre_char;
+#else
+	typedef unsigned char slre_char;
+#endif
+
 /*
  * Compiled regular expression
  */
 struct slre_pattern {
 	unsigned char	code[256];
-#ifdef USE_UTF8
-	unsigned long	data[256];
-#else
 	unsigned char	data[256];
-#endif
 	int		code_size;
 	int		data_size;
 	int		num_caps;	/* Number of bracket pairs	*/




More information about the Pkg-games-commits mailing list