[SCM] Development for GoFind! branch, master, updated. 83441d83106f9da0a5b21c2b6ef94215ab924690

Miriam Ruiz miriam at debian.org
Sat May 2 03:58:50 UTC 2009


The following commit has been merged in the master branch:
commit 83441d83106f9da0a5b21c2b6ef94215ab924690
Author: Miriam Ruiz <miriam at debian.org>
Date:   Sat May 2 06:04:39 2009 +0200

    Initial support for obtaining translated package descriptions through apt-pkg

diff --git a/Makefile b/Makefile
index 7af243d..5eb33e1 100644
--- a/Makefile
+++ b/Makefile
@@ -31,11 +31,11 @@ PLUGINS_LDFLAGS=
 LIBS= -lept -lept-core -lapt-pkg -lxapian -ldl `pkg-config $(PKGCONFIG_FILES) --libs`
 
 OBJS= Engine.o Environment.o filter.o field.o gofind.o \
-	taghandler.o cfgmanager.o boolparser.o \
+	taghandler.o cfgmanager.o boolparser.o apthelper.o \
 	utf8.o dll.o guiplugin.o pkgdata.o slre.o i18n.o
 
 LIB_OBJS= Engine.o Environment.o filter.o field.o \
-	taghandler.o cfgmanager.o boolparser.o \
+	taghandler.o cfgmanager.o boolparser.o apthelper.o \
 	utf8.o dll.o guiplugin.o pkgdata.o slre.o i18n.o
 
 HEADERS=$(shell find . -name "*.h")
@@ -104,7 +104,9 @@ gui_luagtk.o: gui_luagtk.cpp
 %.static.o: %.c $(HEADERS)
 	gcc -o $@ -c $< $(STATIC_CFLAGS) $(PKGCONFIG_CFLAGS)
 
-TEST_OBJS=  filter.test.o taghandler.test.o cfgmanager.test.o boolparser.test.o slre.test.o utf8.test.o CuTest.o dll.test.o test.o
+TEST_OBJS= filter.test.o taghandler.test.o cfgmanager.test.o \
+	boolparser.test.o slre.test.o utf8.test.o apthelper.test.o \
+	dll.test.o i18n.test.o CuTest.o test.o
 TEST_PLUGINS= testplugin.test.so
 
 test: $(TEST_OBJS) $(TEST_PLUGINS)
diff --git a/apthelper.cpp b/apthelper.cpp
new file mode 100644
index 0000000..f21ca45
--- /dev/null
+++ b/apthelper.cpp
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2009  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * Based on cmdline/apt-cache.cc from apt-0.7.21
+ *
+ * Apt is copyright 1997, 1998, 1999 Jason Gunthorpe and others.
+ * Apt is currently developed by APT Development Team <deity at lists.debian.org>.
+ *
+ * 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 "apthelper.h"
+#include "common.h"
+#include "i18n.h"
+
+#include <apt-pkg/error.h>
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/policy.h>
+#include <apt-pkg/tagfile.h>
+#include <apt-pkg/algorithms.h>
+#include <apt-pkg/sptr.h>
+
+#include <locale.h>
+#include <iostream>
+#include <unistd.h>
+#include <errno.h>
+#include <regex.h>
+#include <stdio.h>
+
+#include <iomanip>
+
+#ifdef UNIT_TEST
+#include "CuTest.h"
+#endif
+
+using namespace std;
+
+AptHelper::AptHelper(int argc,const char *argv[]) : Init(false), GCache(NULL), SrcList(NULL), Map(NULL)
+{
+	CommandLine::Args Args[] =
+	{
+		{0, "pkg-cache",        "Dir::Cache::pkgcache",       CommandLine::HasArg},
+		{0, "src-cache",        "Dir::Cache::srcpkgcache",    CommandLine::HasArg},
+		{0, "important",        "APT::Cache::Important",      0},
+		{0, "full",             "APT::Cache::ShowFull",       0},
+		{0, "generate",         "APT::Cache::Generate",       0},
+		{0, "all-versions",     "APT::Cache::AllVersions",    0},
+		{0, "names-only",       "APT::Cache::NamesOnly",      0},
+		{0, "all-names",        "APT::Cache::AllNames",       0},
+		{0, "recurse",          "APT::Cache::RecurseDepends", 0},
+		{0, "apt-config-file",   0,                           CommandLine::ConfigFile},
+		{0, "apt-option",        0,                           CommandLine::ArbItem},
+		{0, "installed",         "APT::Cache::Installed",     0},
+		{0,0,0,0}
+	};
+
+	_config->Set("quiet",0);
+	_config->Set("help",false);
+
+	// Parse the command line and initialize the package library
+	CommandLine CmdL(Args, _config);
+	if (pkgInitConfig(*_config) == false ||
+		CmdL.Parse(argc,argv) == false ||
+		pkgInitSystem(*_config,_system) == false)
+	{
+		_error->DumpErrors();
+		Init = false;
+		return;
+	}
+
+	// Deal with stdout not being a tty
+	if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
+		_config->Set("quiet","1");
+
+	if (_error->PendingError() == false)
+	{
+		if (_config->FindB("APT::Cache::Generate",true) == false)
+		{
+			Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
+				FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
+		}
+		else
+		{
+			// Open the cache file
+			SrcList = new pkgSourceList;
+			SrcList->ReadMainList();
+
+			// Generate it and map it
+			OpProgress Prog;
+			pkgMakeStatusCache(*SrcList,Prog,&Map,true);
+		}
+
+		if (_error->PendingError() == false)
+		{
+			GCache = new pkgCache(Map);
+		}
+	}
+
+	Init = true;
+}
+
+AptHelper::~AptHelper()
+{
+	if (Map)
+	{
+		delete Map;
+		Map = NULL;
+	}
+
+	// Print any errors or warnings found during parsing
+	if (_error->empty() == false)
+	{
+		//bool Errors = _error->PendingError();
+		_error->DumpErrors();
+	}
+}
+
+bool AptHelper::ShowPackage(const char *package)
+{
+	if (!IsInit() || !GCache || _error->PendingError() != false)
+		return false;
+
+	pkgCache &Cache = *GCache;
+	pkgDepCache::Policy Plcy;
+
+	unsigned found = 0;
+
+	pkgCache::PkgIterator Pkg = Cache.FindPkg(package);
+	if (Pkg.end() == true)
+	{
+		_error->Warning(_("Unable to locate package %s"),package);
+		return _error->Error(_("No packages found"));;
+	}
+
+	++found;
+
+	// Find the proper version to use.
+	if (_config->FindB("APT::Cache::AllVersions","true") == true)
+	{
+		pkgCache::VerIterator V;
+		for (V = Pkg.VersionList(); V.end() == false; V++)
+		{
+		// Show the right description
+		pkgRecords Recs(*GCache);
+		pkgCache::DescIterator Desc = V.TranslatedDescription();
+		pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
+		cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc() << std::endl;
+		break;
+		}
+	}
+	else
+	{
+		pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
+		if (V.end() == true || V.FileList().end() == true)
+			return _error->Error(_("No packages found"));
+
+		// Show the right description
+		pkgRecords Recs(*GCache);
+		pkgCache::DescIterator Desc = V.TranslatedDescription();
+		pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
+		cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc() << std::endl;
+	}
+
+	if (found > 0)
+		return true;
+	return _error->Error(_("No packages found"));
+}
+
+int AptHelper::LocalityCompare(const void *a, const void *b)
+{
+	pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
+	pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
+
+	if (A == 0 && B == 0)
+		return 0;
+	if (A == 0)
+		return 1;
+	if (B == 0)
+		return -1;
+
+	if (A->File == B->File)
+		return A->Offset - B->Offset;
+	return A->File - B->File;
+}
+
+void AptHelper::CacheInitialize()
+{
+	_config->Set("quiet",0);
+	_config->Set("help",false);
+}
+
+#ifdef UNIT_TEST
+TEST_FUNCTION TestCuAptHelper(CuTest* tc)
+{
+	std::cerr << "TestCuAptHelper(CuTest* tc)" << std::endl;
+
+	const char *args[2];
+	args[0] = "./test";
+	args[1] = NULL;
+
+	AptHelper helper(1, args);
+	CuAssertTrue(tc, helper.IsInit() == true );
+	CuAssertTrue(tc, helper.ShowPackage("3dchess") == true );
+}
+#endif
diff --git a/fltk/windows.h b/apthelper.h
similarity index 58%
copy from fltk/windows.h
copy to apthelper.h
index a8dd413..6d635ef 100644
--- a/fltk/windows.h
+++ b/apthelper.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007  Miriam Ruiz <little_miry at yahoo.es>
+ * Copyright (C) 2009  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
@@ -16,21 +16,34 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef _GOFIND_FLTK_WINDOWS_H
-#define _GOFIND_FLTK_WINDOWS_H
+#ifndef _games_apthelper_h
+#define _games_apthelper_h
 
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
+#include <cstdlib>
 
-class MainWindow : public Fl_Double_Window
+class pkgCache;
+class pkgSourceList;
+class MMap;
+
+class AptHelper
 {
 public:
-	MainWindow(int w, int h, const char *label = 0);
-	MainWindow(int x, int y, int w, int h, const char *label = 0);
+	AptHelper(int argc,const char *argv[]);
+	~AptHelper();
+
+	inline bool IsInit() { return Init; }
+	bool ShowPackage(const char *package);
 
-	virtual void resize(int x, int y, int w, int h);
+	static int LocalityCompare(const void *a, const void *b);
 
 private:
+	static void CacheInitialize();
+
+	bool Init;
+
+	pkgCache *GCache;
+	pkgSourceList *SrcList;
+	MMap *Map;
 };
 
-#endif // _GOFIND_FLTK_WINDOWS_H
+#endif // _games_apthelper_h

-- 
Development for GoFind!



More information about the Pkg-games-commits mailing list