r6208 - software/gofind
Miriam Ruiz
baby-guest at alioth.debian.org
Wed Mar 19 10:13:55 UTC 2008
Author: baby-guest
Date: 2008-03-19 10:13:54 +0000 (Wed, 19 Mar 2008)
New Revision: 6208
Modified:
software/gofind/Engine.h
software/gofind/filter.cpp
software/gofind/gofind.cpp
Log:
Improved testing interface
Modified: software/gofind/Engine.h
===================================================================
--- software/gofind/Engine.h 2008-03-19 04:46:55 UTC (rev 6207)
+++ software/gofind/Engine.h 2008-03-19 10:13:54 UTC (rev 6208)
@@ -141,6 +141,9 @@
*/
void setKeywordFilter(const std::string& keywords = std::string());
+ inline const char * getKeywordFilter() const
+ { return m_filter_keywords.c_str(); }
+
/**
* Set the game type filter
*/
Modified: software/gofind/filter.cpp
===================================================================
--- software/gofind/filter.cpp 2008-03-19 04:46:55 UTC (rev 6207)
+++ software/gofind/filter.cpp 2008-03-19 10:13:54 UTC (rev 6208)
@@ -22,6 +22,10 @@
#include "taghandler.h"
#include "boolparser.h"
+#ifdef UNIT_TEST
+#include "CuTest.h"
+#endif
+
#include <string>
#include <ept/debtags/tag.h>
Modified: software/gofind/gofind.cpp
===================================================================
--- software/gofind/gofind.cpp 2008-03-19 04:46:55 UTC (rev 6207)
+++ software/gofind/gofind.cpp 2008-03-19 10:13:54 UTC (rev 6208)
@@ -440,18 +440,27 @@
out << "#" _("System running") << std::endl;
- struct slre_pattern pget;
- struct slre_pattern pset;
+ struct slre_pattern pattern[5];
+ const char *pattern_text[5];
+ const char pattern_type[] = { 'h', 'l', 'g', 's', '\0' };
+ 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*$";
+ pattern_text[4] = NULL;
- 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;
+ 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++;
+ }
while (run && !feof(stdin))
{
char buffer[128];
- struct slre_capture captures[4 + 1];
+ struct slre_capture captures[16];
fgets(buffer, sizeof(buffer), stdin);
if (*buffer == '#') continue;
for (char *pnt = buffer; *pnt; pnt++)
@@ -463,82 +472,148 @@
}
}
- if (slre_match(&pset, buffer, strlen(buffer), captures))
- out << "#set: \"" << captures[3].ptr << "\"" << std::endl;
- else if (slre_match(&pget, buffer, strlen(buffer), captures))
+ int match = -1;
+ int j = 0;
+ while (match == -1 && pattern_text[j] != NULL)
{
- out << "#get: \"" << captures[2].ptr << "\"" << std::endl;
- switch (captures[2].ptr[0])
+ if (slre_match(pattern+j, buffer, strlen(buffer), captures))
{
- case 'T': case 't':
+ match = j;
+ out << "#match pattern " << match << std::endl;
+ }
+ j++;
+ }
+ if (match == -1)
+ out << "#no pattern match " << match << std::endl;
+ else switch (pattern_type[match])
+ {
+ case 'h':
+ {
+ out << "# Commands:" << std::endl
+ << "# HELP" << std::endl
+ << "# LIST TYPES|INTERFACES|RESULTS" << std::endl
+ << "# GET <param>" << std::endl
+ << "# SET <param>=<value>" << std::endl;
+ }
+ break;
+ case 'l':
+ {
+ out << "#list: \"" << captures[2].ptr << "\"" << std::endl;
+ switch (captures[2].ptr[0])
{
- const set<Tag> types = engine.types();
- for (set<Tag>::const_iterator i = types.begin(); i != types.end(); ++i)
+ case 'T': case 't':
{
- out << " " << gettext(i->shortDescription().c_str()) << std::endl;
+ const set<Tag> types = engine.types();
+ for (set<Tag>::const_iterator i = types.begin(); i != types.end(); ++i)
+ {
+ out << " " << i->shortDescription().c_str() << std::endl;
+ }
+ out << std::endl ;
+ break;
}
- 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)
+ case 'I': case 'i':
{
- out << " " << gettext(i->shortDescription().c_str()) << std::endl;
+ const set<Tag> ifaces = engine.interfaces();
+ for (set<Tag>::const_iterator i = ifaces.begin();
+ i != ifaces.end(); ++i)
+ {
+ out << " " << i->shortDescription().c_str() << std::endl;
+ }
+ out << std::endl ;
+ break;
}
- 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)
+ case 'R': case 'r':
{
- 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))
+ const std::vector<Result> res = engine.results();
+ for (vector<Result>::const_iterator i = res.begin();
+ i != res.end(); ++i)
{
- case PackageFilter::Green:
- break;
- case PackageFilter::Yellow:
- break;
- case PackageFilter::Red:
- break;
- case PackageFilter::Black:
- break;
- default:
- break;
- }
+ PackageRecord rec(engine.apt().rawRecord(i->name));
+ // char* userData = pkgString(rec.package());
- out << " "<< rec.package() + "\t" + rec.shortDescription();
+ 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;
+ }
- // 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()));
- }
+ out << " "<< rec.package() + "\t" + rec.shortDescription();
- if (engine.popcon().hasData() && i->relevance)
- {
- out << "\tRELEVANCE=" << i->relevance;
+ // 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;
}
- out << std::endl ;
- break;
}
}
+ break;
+ case 'g':
+ {
+ char name[sizeof(buffer)];
+ strncpy(name, captures[2].ptr, captures[2].len);
+ name[captures[2].len] = '\0';
+ out << "#get " << name << std::endl ;
+ if (memcmp(captures[2].ptr, "INSTALLED", 9) == 0)
+ {
+ switch (engine.getInstalledFilter())
+ {
+ case Engine::INSTALLED:
+ out << "installed=yes" << std::endl ;
+ break;
+ case Engine::NOTINSTALLED:
+ out << "installed=no" << std::endl ;
+ break;
+ case Engine::ANY:
+ out << "installed=any" << std::endl ;
+ break;
+ default:
+ out << "#unknown installed value" << std::endl ;
+ break;
+ }
+ }
+ if (memcmp(captures[2].ptr, "KEYWORD", 7) == 0)
+ {
+ out << "keyword=\"" << engine.getKeywordFilter() << "\"" << std::endl ;
+ }
+ if (memcmp(captures[2].ptr, "TYPE", 4) == 0)
+ {
+ out << "type=?" << std::endl ;
+ }
+ if (memcmp(captures[2].ptr, "INTERFACE", 9) == 0)
+ {
+ out << "interface=?" << std::endl ;
+ }
+ }
+ break;
+ case 'p':
+ {
+ }
+ break;
+ default:
+ break;
}
- else
- out << "#unknown: \"" << buffer << "\"" << std::endl;
}
out << "#" _("Stopping system") << std::endl;
More information about the Pkg-games-commits
mailing list