[Aptitude-svn-commit] r3707 - in branches/aptitude-0.3/aptitude: . src/generic

Daniel Burrows dburrows at costa.debian.org
Fri Aug 5 20:17:54 UTC 2005


Author: dburrows
Date: Fri Aug  5 20:17:50 2005
New Revision: 3707

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/tags.cc
   branches/aptitude-0.3/aptitude/src/generic/tags.h
Log:
Add code to load in the tag vocabulary database.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Aug  5 20:17:50 2005
@@ -1,5 +1,9 @@
 2005-08-05  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/tags.cc, src/generic/tags.h:
+
+	  Add code to load in the tag vocabulary database.
+
 	* src/download.cc:
 
 	  Apply Michael Vogt's patch for apt status reporting.

Modified: branches/aptitude-0.3/aptitude/src/generic/tags.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/tags.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/tags.cc	Fri Aug  5 20:17:50 2005
@@ -22,8 +22,10 @@
 #include "../aptitude.h"
 
 #include "apt.h"
+#include "config_signal.h"
 
 #include <algorithm>
+#include <map>
 #include <utility>
 
 #include <ctype.h>
@@ -222,3 +224,83 @@
 
   progress.Done();
 }
+
+
+
+
+// TAG VOCABULARY FILE
+typedef map<string, string> facet_description_map;
+typedef map<string, string> tag_description_map;
+
+facet_description_map *facet_descriptions;
+tag_description_map *tag_descriptions;
+
+static void init_vocabulary()
+{
+  if(facet_descriptions != NULL)
+    {
+      assert(tag_descriptions != NULL);
+      return;
+    }
+
+  facet_descriptions = new facet_description_map;
+  tag_descriptions = new tag_description_map;
+
+  FileFd F(aptcfg->FindFile("DebTags::Vocabulary", "/usr/share/debtags/vocabulary"),
+	   FileFd::ReadOnly);
+
+  if(!F.IsOpen())
+    // Fail silently; debtags need not be installed.
+    return;
+
+  pkgTagFile tagfile(&F);
+
+  pkgTagSection sec;
+
+  while(tagfile.Step(sec))
+    {
+      string facet;
+      const char *start, *end;
+
+      if(sec.Find("Facet", start, end))
+	{
+	  facet.assign(start, end-start);
+
+	  if(sec.Find("Description", start, end))
+	    (*facet_descriptions)[facet] = string(start, end-start);
+	}
+      else if(sec.Find("Tag", start, end))
+	{
+	  string tag(start, end-start);
+
+	  if(sec.Find("Description", start, end))
+	    (*tag_descriptions)[tag] = string(start, end-start);
+	}
+    }
+}
+
+string facet_description(const std::string &facet)
+{
+  init_vocabulary();
+
+  facet_description_map::const_iterator found =
+    facet_descriptions->find(facet);
+
+  if(found == facet_descriptions->end())
+    return string();
+  else
+    return found->second;
+}
+
+string tag_description(const std::string &tag)
+{
+  init_vocabulary();
+
+  tag_description_map::const_iterator found =
+    tag_descriptions->find(tag);
+
+  if(found == tag_descriptions->end())
+    return string();
+  else
+    return found->second;
+}

Modified: branches/aptitude-0.3/aptitude/src/generic/tags.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/tags.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/tags.h	Fri Aug  5 20:17:50 2005
@@ -195,4 +195,13 @@
 // Load tags for all packages (call before get_tags)
 void load_tags(OpProgress &progress);
 
+
+
+// Interface to the tag vocabulary file; tag vocabularies are assumed
+// to not change over time.
+std::string facet_description(const std::string &facet);
+
+// Here "Tag" is a fully qualified tag name.
+std::string tag_description(const std::string &tag);
+
 #endif



More information about the Aptitude-svn-commit mailing list