r5885 - software/gofind
Miriam Ruiz
baby-guest at alioth.debian.org
Thu Feb 21 09:34:31 UTC 2008
Author: baby-guest
Date: 2008-02-21 09:34:31 +0000 (Thu, 21 Feb 2008)
New Revision: 5885
Added:
software/gofind/GamesOptions.h
software/gofind/gofind.cpp
Log:
Added missing files
Copied: software/gofind/GamesOptions.h (from rev 5882, software/ui/src/GamesOptions.h)
===================================================================
--- software/gofind/GamesOptions.h (rev 0)
+++ software/gofind/GamesOptions.h 2008-02-21 09:34:31 UTC (rev 5885)
@@ -0,0 +1,69 @@
+#ifndef GAMES_OPTIONS_H
+#define GAMES_OPTIONS_H
+
+/*
+ * Commandline parser for the game viewer
+ *
+ * Copyright (C) 2003,2004,2005,2006,2007 Enrico Zini
+ *
+ * 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
+ */
+
+#include <wibble/commandline/parser.h>
+
+namespace wibble {
+namespace commandline {
+
+struct GamesOptions : public StandardParserWithManpage
+{
+public:
+ BoolOption* out_debug;
+ BoolOption* out_verbose;
+ StringOption* gowhere;
+ StringOption* mainFacet;
+ StringOption* secondaryFacet;
+ StringOption* ftags;
+
+ GamesOptions()
+ : StandardParserWithManpage("goplay", VERSION, 1, "Enrico Zini <enrico at enricozini.org> and Miriam Ruiz <little_miry at yahoo.es>")
+ {
+ usage = "[options and arguments]";
+ description = "Debian game browser";
+ longDescription =
+ "GoPlay! is a Graphical User Interface (GUI) that uses DebTags"
+ " for finding games in Debian easily.\n";
+
+ out_verbose = add<BoolOption>("verbose", 'v', "verbose", "",
+ "enable verbose output");
+ out_debug = add<BoolOption>("debug", 0, "debug", "",
+ "enable debugging output (including verbose output)");
+ gowhere = add<StringOption>("go", 0, "go", "where",
+ "change the interface flavour. "
+ "Available flavours are: play, learn, admin, net, office, safe, web");
+ mainFacet = add<StringOption>("primary", 0, "primary", "facet",
+ "use the given facet instead of 'games'");
+ secondaryFacet = add<StringOption>("secondary", 0, "secondary", "facet",
+ "use the given facet instead of 'interface'");
+ ftags = add<StringOption>("ftags", 0, "ftags", "tags",
+ "comma-separated list of tags that are always "
+ "required in search results (default: role::program)");
+ }
+};
+
+}
+}
+
+// vim:set ts=4 sw=4:
+#endif
Added: software/gofind/gofind.cpp
===================================================================
--- software/gofind/gofind.cpp (rev 0)
+++ software/gofind/gofind.cpp 2008-02-21 09:34:31 UTC (rev 5885)
@@ -0,0 +1,522 @@
+/*
+ * debtags - Implement package tags support for Debian
+ *
+ * Copyright (C) 2007 Enrico Zini <enrico at debian.org>
+ * 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
+ * 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
+ */
+
+#include "common.h"
+#include "filter.h"
+#include "slre.h"
+
+#include "Environment.h"
+#include "GamesOptions.h"
+#include "Engine.h"
+
+#include <ept/apt/packagerecord.h>
+#include <wibble/regexp.h>
+#include <wibble/string.h>
+#include <xapian.h>
+
+#include <iostream>
+#include <cmath>
+
+#ifdef USE_GETTEXT
+#include <libintl.h>
+#include <locale.h>
+#else
+// Work-around until goplay is actually gettextised
+#define gettext(a) (a)
+#endif
+
+#include <string.h>
+
+namespace std {
+
+template<typename TAG, typename _Traits>
+basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const std::set<TAG>& tags)
+{
+ for (typename std::set<TAG>::const_iterator i = tags.begin();
+ i != tags.end(); i++)
+ if (i == tags.begin())
+ out << i->fullname();
+ else
+ out << ", " << i->fullname();
+ return out;
+}
+
+template<typename TAG, typename _Traits>
+basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const wibble::Singleton<TAG>& tags)
+{
+ out << *tags.begin();
+ return out;
+}
+
+template<typename TAG, typename _Traits>
+basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const wibble::Empty<TAG>&)
+{
+ return out;
+}
+
+}
+
+using namespace std;
+using namespace ept;
+using namespace ept::debtags;
+using namespace ept::apt;
+using namespace ept::textsearch;
+
+char* tagString(const Tag& tag)
+{
+ static map<string, char*> table;
+ map<string, char*>::iterator i = table.find(tag.fullname());
+ if (i == table.end())
+ {
+ pair< map<string, char*>::iterator, bool > tmp =
+ table.insert(make_pair(tag.fullname(), strdup(tag.fullname().c_str())));
+ i = tmp.first;
+ }
+ return i->second;
+}
+char* pkgString(const std::string& name)
+{
+ static map<string, char*> table;
+ map<string, char*>::iterator i = table.find(name);
+ if (i == table.end())
+ {
+ pair< map<string, char*>::iterator, bool > tmp =
+ table.insert(make_pair(name, strdup(name.c_str())));
+ i = tmp.first;
+ }
+ return i->second;
+}
+
+void printResults(Engine& engine)
+{
+ const vector<Result>& packages = engine.results();
+ for (vector<Result>::const_iterator i = packages.begin();
+ i != packages.end(); ++i)
+ {
+ PackageRecord pkg = engine.apt().rawRecord(i->name);
+ cerr << "PKG " << pkg.package() << " - " << pkg.shortDescription() << endl;
+ }
+
+ const set<Tag>& ttags = engine.types();
+ for (set<Tag>::const_iterator i = ttags.begin();
+ i != ttags.end(); ++i)
+ {
+ cerr << "TTAG " << i->fullname() << endl;
+ }
+
+ const set<Tag>& ftags = engine.interfaces();
+ for (set<Tag>::const_iterator i = ftags.begin();
+ i != ftags.end(); ++i)
+ {
+ cerr << "ITAG " << i->fullname() << endl;
+ }
+}
+
+/*
+const char* ReadFlChoice(Fl_Choice& c)
+{
+ const Fl_Menu_Item* cur = c.mvalue();
+ if (cur->user_data_)
+ return (const char*)cur->user_data_;
+ else
+ return "";
+}
+
+static void UpdateUILists(GamesUI& ui)
+{
+ // Defining this here, non-const, because fltk's interface want non-const
+ // strings and I did not have time to check whether it would attempt to
+ // modify the parameter or not. Likely not, and thus a
+ // const_cast<char*>(VoidString) would probably have been better.
+ // --Enrico
+ char VoidString[1] = "";
+ Engine& engine = *ui.engine;
+ const char* oldType = ReadFlChoice(*ui.TypeSelection);
+ const char* oldIface = ReadFlChoice(*ui.InterfaceSelection);
+ ui.TypeSelection->clear();
+ ui.TypeSelection->add(_("Any type"), 0, NULL, VoidString, FL_NORMAL_LABEL);
+ ui.InterfaceSelection->clear();
+ ui.InterfaceSelection->add(_("Any interface"), 0, NULL, VoidString, FL_NORMAL_LABEL);
+
+ static int widths_with_popcon[] = { 100, 300, 0 }; // widths for each column
+ static int widths_without_popcon[] = { 100, 0 };
+ ui.ResultsBrowser->clear();
+ if (engine.popcon().hasData())
+ {
+ ui.ResultsBrowser->column_widths(widths_with_popcon);
+ // tab delimited columns with colors
+ ui.ResultsBrowser->add(_("@B12 at C7@b at .PACKAGE\t at B12@C7 at b@.DESCRIPTION\t at B12@C7 at b@.POPCON"));
+ }
+ else
+ {
+ ui.ResultsBrowser->column_widths(widths_without_popcon);
+ // tab delimited columns with colors
+ ui.ResultsBrowser->add(_("@B12 at C7@b at .PACKAGE\t at B12@C7 at b@.DESCRIPTION"));
+ }
+
+ // FIXME: there are better ways to remember the previous item
+
+ const set<Tag> types = engine.types();
+ int newIdx = 0;
+ for (set<Tag>::const_iterator i = types.begin();
+ i != types.end(); ++i)
+ {
+ int idx = ui.TypeSelection->add(gettext(i->shortDescription().c_str()),
+ 0, NULL, tagString(*i), FL_NORMAL_LABEL);
+ if (i->fullname() == oldType)
+ newIdx = idx;
+ }
+ ui.TypeSelection->value(newIdx);
+
+ const set<Tag> ifaces = engine.interfaces();
+ newIdx = 0;
+ for (set<Tag>::const_iterator i = ifaces.begin();
+ i != ifaces.end(); ++i)
+ {
+ int idx = ui.InterfaceSelection->add(gettext(i->shortDescription().c_str()),
+ 0, NULL, tagString(*i), FL_NORMAL_LABEL);
+ if (i->fullname() == oldIface)
+ newIdx = idx;
+ }
+ ui.InterfaceSelection->value(newIdx);
+
+ 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());
+
+ // Available Colors: FL_BLACK, FL_BLUE, FL_CYAN, FL_DARK_BLUE,
+ // FL_DARK_CYAN, FL_DARK_GREEN FL_DARK_MAGENTA, FL_DARK_RED,
+ // FL_DARK_YELLOW, FL_GREEN, FL_MAGENTA, FL_RED, FL_WHITE, FL_YELLOW
+
+ Fl_Color bk(FL_WHITE);
+ Fl_Color fr(FL_BLACK);
+ set<Tag> tags = ui.engine->debtags().getTagsOfItem((const char *)rec.package().c_str());
+ switch (pkgfilter.TagsValue(tags))
+ {
+ case PackageFilter::Green:
+ fr = FL_BLACK; bk = FL_GREEN; break;
+ case PackageFilter::Yellow:
+ fr = FL_BLACK; bk = FL_YELLOW; break;
+ case PackageFilter::Red:
+ fr = FL_WHITE; bk = FL_RED; break;
+ case PackageFilter::Black:
+ fr = FL_WHITE; bk = FL_BLACK; break;
+ default:
+ fr = FL_BLACK; bk = FL_WHITE; break;
+ }
+
+ char fmtstr[16];
+ snprintf(fmtstr, sizeof(fmtstr), "@B%d at C%d at .", bk, fr);
+
+ string desc = string(fmtstr) + rec.package() + "\t" +
+ string(fmtstr) + rec.shortDescription();
+ if (engine.popcon().hasData() && i->popcon)
+ {
+ desc += "\t" + string(fmtstr);
+ char stars[16];
+ snprintf(stars, sizeof(stars), "%%%d/8/1;",
+ (int)rintf(log(i->popcon) * 100 / log(engine.popconLocalMax())));
+ desc += stars;
+ //printf ("%s (%s): POPCON=%f\n", rec.package().c_str(), rec.shortDescription().c_str(), i->popcon);
+ }
+ ui.ResultsBrowser->add(desc.c_str(), userData);
+
+ // Relevance is 0 to 100
+ // Popcon is a weird floating point number (to be improved)
+ //FIXMEaddToResults(rec.package() + " - " + rec.shortDescription(), i->relevance, i->popcon);
+ }
+}
+
+static void CallBackTypeSelection(Fl_Choice* choice, void *data)
+{
+ //printf("CallBackTypeSelection\n");
+ //fflush(stdout);
+ GamesUI& ui = *static_cast<GamesUI*>(data);
+ Tag tag = ui.engine->voc().tagByName(ReadFlChoice(*choice));
+ ui.engine->setTypeFilter(tag);
+ UpdateUILists(ui);
+}
+
+static void CallBackInterfaceSelection(Fl_Choice* choice, void *data)
+{
+ //printf("CallBackInterfaceSelection\n");
+ //fflush(stdout);
+ GamesUI& ui = *static_cast<GamesUI*>(data);
+ Tag tag = ui.engine->voc().tagByName(ReadFlChoice(*choice));
+ ui.engine->setInterfaceFilter(tag);
+ UpdateUILists(ui);
+}
+
+static void CallBackSearchInput(Fl_Input* input, void *data)
+{
+ //printf("CallBackSearchInput\n"); fflush(stdout);
+ GamesUI& ui = *static_cast<GamesUI*>(data);
+ ui.engine->setKeywordFilter(input->value());
+ UpdateUILists(ui);
+}
+
+static void CallBackAlreadyInstalled(Fl_Round_Button*, void *data)
+{
+ //printf("CallBackInstalled\n"); fflush(stdout);
+ GamesUI& ui = *static_cast<GamesUI*>(data);
+ ui.AlreadyInstalled->value(1); ui.AlreadyInstalled->redraw();
+ ui.ToBeInstalled->value(0); ui.ToBeInstalled->redraw();
+ ui.InstalledOrNot->value(0); ui.InstalledOrNot->redraw();
+ ui.engine->setInstalledFilter(Engine::INSTALLED);
+ UpdateUILists(ui);
+}
+
+static void CallBackToBeInstalled(Fl_Round_Button*, void *data)
+{
+ //printf("CallBackToBeInstalled\n"); fflush(stdout);
+ GamesUI& ui = *static_cast<GamesUI*>(data);
+ ui.AlreadyInstalled->value(0); ui.AlreadyInstalled->redraw();
+ ui.ToBeInstalled->value(1); ui.ToBeInstalled->redraw();
+ ui.InstalledOrNot->value(0); ui.InstalledOrNot->redraw();
+ ui.engine->setInstalledFilter(Engine::NOTINSTALLED);
+ UpdateUILists(ui);
+}
+
+static void CallBackInstalledOrNot(Fl_Round_Button*, void *data)
+{
+ //printf("CallBackToBeInstalled\n"); fflush(stdout);
+ GamesUI& ui = *static_cast<GamesUI*>(data);
+ ui.AlreadyInstalled->value(0); ui.AlreadyInstalled->redraw();
+ ui.ToBeInstalled->value(0); ui.ToBeInstalled->redraw();
+ ui.InstalledOrNot->value(1); ui.InstalledOrNot->redraw();
+ ui.engine->setInstalledFilter(Engine::ANY);
+ UpdateUILists(ui);
+}
+
+#if 0
+static void OnResultsBrowserClick(Fl_Browser*, void *data)
+{
+ printf("OnResultsBrowserClick\n"); fflush(stdout);
+// GamesUI& ui = *static_cast<GamesUI*>(data);
+}
+#endif
+*/
+
+#ifndef UNIT_TEST
+int main(int argc, const char* argv[])
+{
+#ifdef USE_GETTEXT
+ setlocale (LC_MESSAGES, "");
+ setlocale (LC_CTYPE, "");
+ setlocale (LC_COLLATE, "");
+ textdomain ("gamesui");
+ bindtextdomain ("gamesui", NULL);
+#endif
+
+ std::ostream &out = std::cout;
+ out << "#" _("Starting system") << std::endl;
+
+ wibble::commandline::GamesOptions opts;
+
+ try {
+ // Install the handler for unexpected exceptions
+ wibble::exception::InstallUnexpected installUnexpected;
+
+ if (opts.parse(argc, argv))
+ return 0;
+
+ if (opts.out_verbose->boolValue())
+ ::Environment::get().verbose(true);
+
+ if (opts.out_debug->boolValue())
+ ::Environment::get().debug(true);
+
+ Engine engine;
+
+ if (wibble::str::endsWith(argv[0], "learn") || opts.gowhere->stringValue() == "learn")
+ {
+ engine.mainFacet = "field";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query(Xapian::Query::OP_AND,
+ Xapian::Query(Xapian::Query::OP_OR,
+ Xapian::Query("XTrole::documentation"),
+ Xapian::Query("XTrole::program")),
+ Xapian::Query("XTuse::learning"));
+ } else if (wibble::str::endsWith(argv[0], "admin") || opts.gowhere->stringValue() == "admin") {
+ engine.mainFacet = "admin";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+ Xapian::Query("XTrole::documentation"),
+ Xapian::Query("XTrole::program"));
+ } else if (wibble::str::endsWith(argv[0], "net") || opts.gowhere->stringValue() == "net") {
+ engine.mainFacet = "network";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+ Xapian::Query("XTrole::documentation"),
+ Xapian::Query("XTrole::program"));
+ } else if (wibble::str::endsWith(argv[0], "office") || opts.gowhere->stringValue() == "office") {
+ engine.mainFacet = "office";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+ Xapian::Query("XTrole::documentation"),
+ Xapian::Query("XTrole::program"));
+ } else if (wibble::str::endsWith(argv[0], "safe") || opts.gowhere->stringValue() == "safe") {
+ engine.mainFacet = "security";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+ Xapian::Query("XTrole::documentation"),
+ Xapian::Query("XTrole::program"));
+ } else if (wibble::str::endsWith(argv[0], "web") || opts.gowhere->stringValue() == "web") {
+ engine.mainFacet = "web";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+ Xapian::Query("XTrole::documentation"),
+ Xapian::Query("XTrole::program"));
+ } else {
+ engine.mainFacet = "game";
+ engine.secondaryFacet = "interface";
+ engine.globalFilter = Xapian::Query("XTrole::program");
+ }
+
+ if (opts.mainFacet->isSet())
+ engine.mainFacet = opts.mainFacet->stringValue();
+
+ if (opts.secondaryFacet->isSet())
+ engine.secondaryFacet = opts.secondaryFacet->stringValue();
+
+ if (opts.ftags->isSet())
+ {
+ Xapian::Query fquery;
+ wibble::Splitter tags(", *", REG_EXTENDED);
+ bool first = true;
+ for (wibble::Splitter::const_iterator i = tags.begin(opts.ftags->stringValue());
+ i != tags.end(); ++i)
+ {
+ if (first)
+ {
+ fquery = Xapian::Query("XT"+*i);
+ first = false;
+ }
+ else
+ fquery = Xapian::Query(Xapian::Query::OP_AND, fquery, Xapian::Query("XT"+*i));
+ }
+ engine.globalFilter = fquery;
+ }
+
+ /*
+ cerr << " *** Initial:" << endl;
+ printResults(engine);
+
+ engine.setTypeFilter(engine.voc().tagByName("game::arcade"));
+ cerr << " *** Arcades:" << endl;
+ printResults(engine);
+
+ engine.setInterfaceFilter(engine.voc().tagByName("interface::x11"));
+ cerr << " *** X11 Arcades:" << endl;
+ printResults(engine);
+
+ engine.setInstalledFilter(Engine::INSTALLED);
+ cerr << " *** Installed X11 Arcades:" << endl;
+ printResults(engine);
+ */
+
+ bool run = true;
+
+ out << "#" _("System running") << std::endl;
+
+ struct slre_pattern pget;
+ struct slre_pattern pset;
+
+ if (!slre_compile(&pget, "^\\s*(GET|G)\\s+(\\S+)\\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];
+ struct slre_capture captures[4 + 1];
+ fgets(buffer, sizeof(buffer), stdin);
+ if (*buffer == '#') continue;
+ for (char *pnt = buffer; *pnt; pnt++)
+ {
+ if (*pnt=='\0' || *pnt=='\r' || *pnt=='\n')
+ {
+ *pnt = '\0';
+ 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;
+ else
+ out << "#unknown: \"" << buffer << "\"" << std::endl;
+ }
+
+ out << "#" _("Stopping system") << std::endl;
+ return 0;
+ } catch (wibble::exception::BadOption& e) {
+ cerr << e.desc() << endl;
+ opts.outputHelp(cerr);
+ return 1;
+ } catch (std::exception& e) {
+ cerr << e.what() << endl;
+ return 1;
+ } catch (Xapian::InvalidArgumentError& e) {
+ cerr << "Xapian " << e.get_type() << ": " << e.get_msg();
+ if (!e.get_context().empty())
+ cerr << ". Context: " << e.get_context();
+ cerr << endl;
+ cerr << endl;
+ cerr << "It could be that your Apt Xapian index is missing: you can create it by running ept-cache reindex as root." << endl;
+ } catch (Xapian::DatabaseVersionError& e) {
+ cerr << "Xapian " << e.get_type() << ": " << e.get_msg();
+ if (!e.get_context().empty())
+ cerr << ". Context: " << e.get_context();
+ cerr << endl;
+ cerr << endl;
+ cerr << "Please recreate the database by removing /var/lib/apt-xapian and running ept-cache reindex as root." << endl;
+ } catch (Xapian::Error& e) {
+ cerr << "Xapian " << e.get_type() << ": " << e.get_msg();
+ if (!e.get_context().empty())
+ cerr << ". Context: " << e.get_context();
+ cerr << endl;
+ return 1;
+ }
+
+}
+#endif
+
+#include <ept/debtags/debtags.tcc>
+
+// vim:set ts=4 sw=4:
More information about the Pkg-games-commits
mailing list