[Debtags-commits] [svn] r1394 - debtags/trunk/tools
Enrico Zini
enrico at costa.debian.org
Fri Oct 21 18:40:45 UTC 2005
Author: enrico
Date: Fri Oct 21 18:40:44 2005
New Revision: 1394
Added:
debtags/trunk/tools/Printer.h
Modified:
debtags/trunk/tools/Makefile.am
debtags/trunk/tools/debtags.cc
Log:
Split printing functions into a hierarchy of modular 'Printer's
Modified: debtags/trunk/tools/Makefile.am
==============================================================================
--- debtags/trunk/tools/Makefile.am (original)
+++ debtags/trunk/tools/Makefile.am Fri Oct 21 18:40:44 2005
@@ -14,4 +14,4 @@
INCLUDES = -I.. $(LIBTAGCOLL_CFLAGS) $(LIBABT_FRONT_CFLAGS)
-EXTRA_DIST = acqprogress.h ChildProcess.h CommandlineParser.h Environment.h Exec.h
+EXTRA_DIST = acqprogress.h ChildProcess.h CommandlineParser.h Environment.h Exec.h Printer.h
Modified: debtags/trunk/tools/debtags.cc
==============================================================================
--- debtags/trunk/tools/debtags.cc (original)
+++ debtags/trunk/tools/debtags.cc Fri Oct 21 18:40:44 2005
@@ -46,6 +46,7 @@
#include "Environment.h"
#include "CommandlineParser.h"
#include "acqprogress.h"
+#include "Printer.h"
#include <apt-pkg/configuration.h>
@@ -389,40 +390,6 @@
virtual ~ItemAdder() {}
};
-// Needs Package to print short description
-class PackagePrinter : /*public Debtags::PackageConsumer,*/ public Tagcoll::Consumer<entity::Package, Tag>
-{
-protected:
- int _count;
- OpSet<entity::Package> blacklist;
-
- virtual void consumeItemUntagged(const entity::Package& pkg)
- {
- if (blacklist.find(pkg) == blacklist.end())
- {
- printf("%.*s - %.*s\n", PFSTR(pkg.name()), PFSTR(pkg.shortDescription("(short description not available)")));
- _count++;
- }
- }
- virtual void consumeItem(const entity::Package& pkg, const OpSet<Tag>& tags)
- {
- consume(pkg);
- }
-
-public:
- PackagePrinter() : _count(0) {}
- PackagePrinter(const OpSet<entity::Package>& blacklist)
- : _count(0), blacklist(blacklist) {}
- virtual ~PackagePrinter() {}
-
- int count() const { return _count; }
-
- void print(const OpSet<entity::Package>& pkgs)
- {
- consumeItemsUntagged(pkgs);
- }
-};
-
template<class ITEM>
class FacetcollPrinter : public Tagcoll::Consumer<ITEM, Facet>
{
@@ -468,6 +435,49 @@
}
+class Searcher
+{
+protected:
+ component::PackageTags& debtags;
+ Printer<Package, Tag>* printer;
+
+public:
+ Searcher(component::PackageTags& debtags, Printer<Package, Tag>* printer) :
+ debtags(debtags), printer(printer) {}
+
+ void output()
+ {
+ debtags.outputPatched(*printer);
+ printer->flush();
+ }
+
+ int output(const string& expression, bool invertMatch)
+ {
+ // Build the grep filter chain
+ FilterItemsByExpression<Package, Tag> filter(*printer, expression);
+ if (invertMatch)
+ filter.setMatchType(FilterItemsByExpression<Package, Tag>::INVERTED);
+ debtags.outputPatched(filter);
+ printer->flush();
+ return filter.countMatched();
+ }
+};
+
+template<class ITEM, class TAG>
+int outputGrepped(component::PackageTags& debtags, const string& expression, bool invertMatch, Tagcoll::Consumer<ITEM, TAG>& cons)
+{
+ // Build the grep filter chain
+ FilterItemsByExpression<ITEM, TAG> filter(cons, expression);
+ if (invertMatch)
+ filter.setMatchType(FilterItemsByExpression<ITEM, TAG>::INVERTED);
+
+ debtags.outputPatched(filter);
+
+ return filter.countMatched();
+}
+
+
+
/*
class ItemPrinter : public Tagcoll::Tagcoll::Consumer<string, string>
{
@@ -883,18 +893,6 @@
cout << "Description: " << tag.shortDescription() << endl;
cout << " " << tag.longDescription() << endl;
cout << endl;
-
- /*
- string buf = tag.fulldata();
-
- // Count the end of lines at the end of the buffer
- int nnl = 0;
- while (buf[buf.size() - 1 - nnl] == '\n')
- nnl++;
- fwrite(buf.data(), buf.size() - nnl, 1, stdout);
- fputc('\n', stdout);
- fputc('\n', stdout);
- */
}
#if 0
@@ -927,28 +925,6 @@
#endif
#if 0
-template<>
-void ExpressionFilter<entity::Package, Tag>::consume(const entity::Package& item, const OpSet<Tag>& tags);
-
-template<>
-void ExpressionFilter<entity::Package, Tag>::consume(const OpSet<entity::Package>& items, const OpSet<Tag>& tags);
-#endif
-
-
-template<class ITEM, class TAG>
-int outputGrepped(component::PackageTags& debtags, const string& expression, bool invertMatch, Tagcoll::Consumer<ITEM, TAG>& cons)
-{
- // Build the grep filter chain
- FilterItemsByExpression<ITEM, TAG> filter(cons, expression);
- if (invertMatch)
- filter.setMatchType(FilterItemsByExpression<ITEM, TAG>::INVERTED);
-
- debtags.outputPatched(filter);
-
- return filter.countMatched();
-}
-
-#if 0
class MaintCollector : public PackageConsumer
{
protected:
@@ -1184,27 +1160,15 @@
{
component::PackageTags& debtags = debtagsInit();
wantTagDatabase();
+ auto_ptr< Printer<Package, Tag> > printer;
- Converter<entity::Package, string> fromitem;
- Converter<Tag, string> fromtag;
- TextFormat<entity::Package, Tag> writer(fromitem, fromtag, stdout);
- if (opts.get("groupitems").defined())
- {
- ItemGrouper<entity::Package, Tag> grouper;
- debtags.outputPatched(grouper);
- grouper.output(writer);
- } else
- debtags.outputPatched(writer);
- /*
- TextFormat<Package, Tag> writer(Debtags::Environment::get().serializer(), stdout);
if (opts.get("groupitems").defined())
- {
- ItemGrouper<Package, Tag> grouper;
- Debtags::Environment::get().tagDB().outputPatched(grouper);
- grouper.output(writer);
- } else
- Debtags::Environment::get().tagDB().outputPatched(writer);
- */
+ printer = auto_ptr< Printer<Package, Tag> >(new GroupedTagcollPrinter);
+ else
+ printer = auto_ptr< Printer<Package, Tag> >(new TagcollPrinter);
+
+ Searcher searcher(debtags, printer.get());
+ searcher.output();
break;
}
@@ -1216,13 +1180,12 @@
{
component::PackageTags& debtags = debtagsInit();
wantTagDatabase();
-
+ APTPrinter printer;
+ Searcher searcher(debtags, &printer);
string expression = args.next();
- PackagePrinter printer;
-
int matched =
- outputGrepped(debtags, expression, opts.get("invert-match").defined(), printer);
+ searcher.output(expression, opts.get("invert-match").defined());
return matched > 0 ? 0 : 1;
}
@@ -1235,23 +1198,20 @@
{
component::PackageTags& debtags = debtagsInit();
wantTagDatabase();
+ auto_ptr< Printer<Package, Tag> > printer;
- string expression = args.next();
-
- int matched;
if (opts.get("quiet").defined())
- {
- Sink<entity::Package, Tag> sink;
- matched = outputGrepped(debtags, expression, opts.get("invert-match").defined(), sink);
- }
+ printer = auto_ptr< Printer<Package, Tag> >(new NullPrinter);
+ if (opts.get("groupitems").defined())
+ printer = auto_ptr< Printer<Package, Tag> >(new GroupedTagcollPrinter);
else
- {
- Converter<entity::Package, string> fromitem;
- Converter<Tag, string> fromtag;
- TextFormat<entity::Package, Tag> writer(fromitem, fromtag, stdout);
+ printer = auto_ptr< Printer<Package, Tag> >(new TagcollPrinter);
- matched = outputGrepped(debtags, expression, opts.get("invert-match").defined(), writer);
- }
+ Searcher searcher(debtags, printer.get());
+ string expression = args.next();
+
+ int matched =
+ searcher.output(expression, opts.get("invert-match").defined());
return matched > 0 ? 0 : 1;
}
@@ -1457,9 +1417,10 @@
return 1;
}
- PackagePrinter printer(splititems);
+ APTPrinter printer(splititems);
OpSet<entity::Package> related(debtags.tagdb().getRelatedItems(ts, maxdist));
printer.print(related);
+ printer.flush();
if (printer.count() > 50 && maxdist == 0 && isatty(1))
{
@@ -1667,13 +1628,15 @@
wantTagDatabase();
// Write the package names to stdout
- PackagePrinter writer;
+ APTPrinter printer;
// Filter to select the right packages
- TODOFilter filter(writer);
+ TODOFilter filter(printer);
debtags.outputPatched(filter);
+ printer.flush();
+
break;
}
// score
More information about the Debtags-commits
mailing list