[SCM] Development fot GoFind! branch, master, updated. ffb0d490b652cc9dfc254fae2b33955e52923f9d
Miriam Ruiz
miriam at debian.org
Sun Nov 23 13:11:55 UTC 2008
The following commit has been merged in the master branch:
commit ffb0d490b652cc9dfc254fae2b33955e52923f9d
Author: Miriam Ruiz <miriam at debian.org>
Date: Sun Nov 23 14:14:40 2008 +0100
CLI Plugin: Set installed and keyword parameters implemented
diff --git a/gofind.cpp b/gofind.cpp
index 853d693..ecad3a1 100644
--- a/gofind.cpp
+++ b/gofind.cpp
@@ -90,8 +90,8 @@ int main(int argc, const char* argv[])
bindtextdomain ("gofind", NULL);
#endif
-// DLLFactory<GUIPlugInFactory> gui_factory( "./gui_cli.so" );
- DLLFactory<GUIPlugInFactory> gui_factory( "./gui_fltk.so" );
+ DLLFactory<GUIPlugInFactory> gui_factory( "./gui_cli.so" );
+// DLLFactory<GUIPlugInFactory> gui_factory( "./gui_fltk.so" );
if( ! gui_factory.factory )
{
diff --git a/gui_cli.cpp b/gui_cli.cpp
index 48fdc56..5615eb5 100644
--- a/gui_cli.cpp
+++ b/gui_cli.cpp
@@ -45,8 +45,8 @@
#define gettext(a) (a)
#endif
-#include <stdarg.h>
#include <string.h>
+#include <stdarg.h>
using namespace std;
using namespace ept;
@@ -85,6 +85,33 @@ void GUIPlugInCLI::Comment(const char *szFormat, ...)
std::cout << "# " << str << std::endl;
}
+/*
+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;
+}
+
bool GUIPlugInCLI::Go(PackageData &pkgdata)
{
std::ostream &out = std::cout;
@@ -99,7 +126,7 @@ bool GUIPlugInCLI::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*$";
+ pattern_text[3] = "^\\s*(SET|S)\\s+(\\S+)\\s*=\\s*((\\S|\\s)*)\\S\\s*$";
pattern_text[4] = NULL;
int j = 0;
@@ -125,6 +152,8 @@ bool GUIPlugInCLI::Go(PackageData &pkgdata)
}
}
+ static const char *pattern_name[16] = { "Show help", "Show list", "Get parameter", "Set parameter", NULL};
+
int match = -1;
int j = 0;
while (match == -1 && pattern_text[j] != NULL)
@@ -132,12 +161,12 @@ bool GUIPlugInCLI::Go(PackageData &pkgdata)
if (slre_match(pattern+j, buffer, strlen(buffer), captures))
{
match = j;
- out << "#match pattern " << match << std::endl;
+ out << "# Command: " << pattern_name[match] << std::endl;
}
j++;
}
if (match == -1)
- out << "#no pattern match " << match << std::endl;
+ out << "# Syntax Error: Command pattern not recognized" << std::endl;
else switch (pattern_type[match])
{
case 'h':
@@ -151,26 +180,26 @@ bool GUIPlugInCLI::Go(PackageData &pkgdata)
break;
case 'l':
{
- out << "#list: \"" << captures[2].ptr << "\"" << std::endl;
+ out << "# List: \"" << captures[2].ptr << "\"" << std::endl;
switch (captures[2].ptr[0])
{
case 'T': case 't':
{
- const set<Tag> types = pkgdata.types();
- for (set<Tag>::const_iterator i = types.begin(); i != types.end(); ++i)
+ const PackageData::TagSet types = pkgdata.types();
+ for (PackageData::TagSet::const_iterator i = types.begin(); i != types.end(); ++i)
{
- out << " " << i->shortDescription().c_str() << std::endl;
+ out << " " << i->fullname() << "\t" << i->shortDescription().c_str() << std::endl;
}
out << std::endl ;
break;
}
case 'I': case 'i':
{
- const set<Tag> ifaces = pkgdata.interfaces();
- for (set<Tag>::const_iterator i = ifaces.begin();
+ const PackageData::TagSet ifaces = pkgdata.interfaces();
+ for (PackageData::TagSet::const_iterator i = ifaces.begin();
i != ifaces.end(); ++i)
{
- out << " " << i->shortDescription().c_str() << std::endl;
+ out << " " << i->fullname() << "\t" << i->shortDescription().c_str() << std::endl;
}
out << std::endl ;
break;
@@ -226,8 +255,8 @@ bool GUIPlugInCLI::Go(PackageData &pkgdata)
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)
+ out << "# Get " << name << std::endl ;
+ if (slre_test_capture(captures[2], 2, "INSTALLED", "INST"))
{
switch (pkgdata.getInstalledFilter())
{
@@ -245,22 +274,71 @@ bool GUIPlugInCLI::Go(PackageData &pkgdata)
break;
}
}
- if (memcmp(captures[2].ptr, "KEYWORD", 7) == 0)
+ else if (slre_test_capture(captures[2], 4, "KEYWORD", "KEYW", "KW", "K"))
{
out << "keyword=\"" << pkgdata.getKeywordFilter() << "\"" << std::endl ;
}
- if (memcmp(captures[2].ptr, "TYPE", 4) == 0)
+ else if (slre_test_capture(captures[2], 2, "TYPE", "T"))
{
out << "type=?" << std::endl ;
}
- if (memcmp(captures[2].ptr, "INTERFACE", 9) == 0)
+ else if (slre_test_capture(captures[2], 3, "INTERFACE", "IFACE", "IF"))
{
out << "interface=?" << std::endl ;
}
+ else
+ {
+ out << "# Unknown parameter name" << std::endl ;
+ }
}
break;
case 's':
{
+ char name[sizeof(buffer)];
+ 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_test_capture(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"))
+ {
+ out << "# installed=no" << std::endl ;
+ pkgdata.setInstalledFilter(Engine::NOTINSTALLED);
+ }
+ else if (slre_test_capture(captures[3], 2, "any", "*"))
+ {
+ out << "# installed=any" << std::endl ;
+ pkgdata.setInstalledFilter(Engine::ANY);
+ }
+ else
+ {
+ out << "# Unknown value for installed" << std::endl ;
+ }
+ }
+ else if (slre_test_capture(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"))
+ {
+ out << "type=?" << std::endl ;
+ }
+ else if (slre_test_capture(captures[2], 3, "INTERFACE", "IFACE", "IF"))
+ {
+ out << "interface=?" << std::endl ;
+ }
+ else
+ {
+ out << "# Unknown parameter name" << std::endl ;
+ }
+
}
break;
default:
--
Development fot GoFind!
More information about the Pkg-games-commits
mailing list