One more update...  patch.topdir attached now uses the first entry 
listed in Aptitude::Sections::Top-Sections as a default if the top-level 
section is not recognized ... the previous patch was still using a 
hard-coded 'main' by default when the top-level section was not 
recognized.
diff -Naur aptitude.orig/aptitude-defaults aptitude.topdir/aptitude-defaults
--- aptitude.orig/aptitude-defaults     2008-01-04 10:52:49.000000000 -0500
+++ aptitude.topdir/aptitude-defaults   2008-01-04 11:00:19.000000000 -0500
@@ -141,3 +141,53 @@
   };
 };
 
+Aptitude::Sections
+{
+  Top-Sections "main,contrib,non-free,non-US";
+  Descriptions {
+    Unknown    "Packages with no declared section\n No section is given for 
these packages. Perhaps there is an error in the Packages file?";
+    Virtual    "Virtual packages\n These packages do not exist; they are names 
other packages use to require or provide some functionality.";
+    Tasks      "Packages which set up your computer to perform a particular 
task\n Packages in the 'Tasks' section contain no files; they merely depend 
upon other packages. These packages provide an easy way to select a predefined 
set of packages for a specialized task.";
+
+    admin      "Administrative utilities (install software, manage users, 
etc)\n Packages in the 'admin' section allow you to perform administrative 
tasks such as installing software, managing users, configuring and monitoring 
your system, examining network traffic, and so on.";
+    alien      "Packages converted from foreign formats (rpm, tgz, etc)\n 
Packages in the 'alien' section were created by the 'alien' program from a 
non-Debian package format such as RPM";
+    base       "The Debian base system\n Packages in the 'base' section are 
part of the initial system installation.";
+    comm       "Programs for faxmodems and other communication devices\n 
Packages in the 'comm' section are used to control modems and other hardware 
communications devices. This includes software to control faxmodems (for 
instance, PPP for dial-up internet connections and programs originally written 
for that purpose, such as zmodem/kermit), as well as software to control 
cellular phones, interface with FidoNet, and run a BBS.";
+    devel      "Utilities and programs for software development\n Packages in 
the 'devel' section are used to write new software and work on existing 
software. Non-programmers who do not compile their own software probably do not 
need much software from this section.\n .\n It includes compilers, debugging 
tools, programmer's editors, source processing tools, and other things related 
to software development.";
+    doc                "Documentation and specialized programs for viewing 
documentation\n Packages in the 'doc' section document parts of the Debian 
system, or are viewers for documentation formats.";
+    editors    "Text editors and word processors\n Packages in the 'editors' 
section allow you to edit plain ASCII text. These are not necessarily word 
processors, although some word processors may be found in this section.";
+    electronics        "Programs for working with circuits and electronics\n 
Packages in the 'electronics' section include circuit design tools, simulators 
and assemblers for microcontrollers, and other related software.";
+    embedded   "Programs for embedded systems\n Packages in the 'embedded' 
section are meant to run on embedded devices. Embedded devices are specialized 
hardware devices with much less power than a typical desktop system: for 
instance, a PDA, a cell phone, or a Tivo.";
+    gnome      "The GNOME Desktop System\n GNOME is a collection of software 
which provides an easy-to-use desktop environment for Linux.  Packages in the 
'gnome' section are part of the GNOME environment or closely integrated into 
it.";
+    games      "Games, toys, and fun programs\n Packages in the 'games' 
section are meant primarily for entertainment.";
+    graphics   "Utilities to create, view, and edit graphics files\n Packages 
in the 'graphics' section include viewers for image files, image processing and 
manipulation software, software to interact with graphics hardware (such as 
video cards, scanners, and digital cameras), and programming tools for handling 
graphics.";
+    hamradio   "Software for ham radio operators\n Packages in the 'hamradio' 
section are meant primarily for ham radio operators.";
+    interpreters "Interpreters for interpreted languages\n Packages in the 
'interpreters' section include interpreters for languages like Python, Perl, 
and Ruby, and libraries for these same languages.";
+    kde                "The KDE Desktop System\n KDE is a collection of 
software which provides an easy-to-use desktop environment for Linux.  Packages 
in the 'kde' section are part of the KDE environment or closely integrated into 
it.";
+    libdevel   "Development files for libraries\n Packages in the 'libdevel' 
section contain files required for building programs that use libraries in the 
'libs' section.  You don't need packages from this section unless you want to 
compile software yourself.";
+    libs       "Collections of software routines\n Packages in the 'libs' 
section provide necessary functionality for other software on the computer. 
With very few exceptions, you should not need to explicitly install a package 
from this section; the package system will install them as required to fulfill 
dependencies.";
+    perl       "Perl interpreter and libraries\n Packages in the 'perl' 
section provide the Perl programming language and many third-party libraries 
for it. Unless you are a Perl programmer, you don't need to install packages 
from this section explicitly; the package system will install them if they are 
required.";
+    python     "Python interpreter and libraries\n Packages in the 'python' 
section provide the Python programming language and many third-party libraries 
for it. Unless you are a Python programmer, you don't need to install packages 
from this section explicitly; the package system will install them if they are 
required.";
+    mail       "Programs to write, send, and route email messages\n Packages 
in the 'mail' section include mail readers, mail transport daemons, mailing 
list software, and spam filters, as well as various other software related to 
electronic mail.";
+    math       "Numeric analysis and other mathematics-related software\n 
Packages in the 'math' section include calculators, languages for mathematical 
computation (similar to Mathematica), symbolic algebra packages, and programs 
to visualize mathematical objects.";
+    misc       "Miscellaneous software\n Packages in the 'misc' section have 
too unusual a function to be classified.";
+    net                "Programs to connect to and provide various services\n 
Packages in the 'net' section include clients and servers for many protocols, 
tools to manipulate and debug low-level network protocols, IM systems, and 
other network-related software.";
+    news       "Usenet clients and servers\n Packages in the 'news' section 
are related to the Usenet distributed news system.  They include news readers 
and news servers.";
+    oldlibs    "Obsolete libraries\n Packages in the 'oldlibs' section are 
obsolete and should not be used by new software.  They are provided for 
compatibility reasons, or because software distributed by Debian still requires 
them.\n .\n With very few exceptions, you should not need to explicitly install 
a package from this section; the package system will install them as required 
to fulfill dependencies.";
+    otherosfs  "Emulators and software to read foreign filesystems\n Packages 
in the 'otherosfs' section emulate hardware and operating systems and provide 
tools for transferring data between different operating systems and hardware 
platforms. (for instance, utilities to read DOS floppies, and utilities to 
communicate with Palm Pilots)\n .\n It is worth noting that CD burning software 
is included in THIS section.";
+    science    "Software for scientific work\n Packages in the 'science' 
section include tools for astronomy, biology, and chemistry, as well as other 
science-related software.";
+    shells     "Command shells and alternative console environments\n Packages 
in the 'shells' section include programs providing a command-line interface.";
+    sound      "Utilities to play and record sound\n Packages in the 'sound' 
section include sound players, recorders, and encoders for many formats, mixers 
and volume controls, MIDI sequencers and programs to generate musical notation, 
drivers for sound hardware, and sound processing software.";
+    tex                "The TeX typesetting system\n Packages in the 'tex' 
section are related to TeX, a system for producing high-quality typeset output. 
 They include TeX itself, TeX packages, editors designed for TeX, utilities to 
convert TeX and TeX output files to various formats, TeX fonts, and other 
software related to TeX.";
+    text       "Text processing utilities\n Packages in the 'text' section 
include text filters and processors, spelling checkers, dictionary programs, 
utilities to convert between character encodings and text file formats (eg, 
Unix and DOS), text formatters and pretty-printers, and other software which 
operates on plain text.";
+    utils      "Various system utilities\n Packages in the 'utils' section are 
utilities whose purpose is too unique to be classified.";
+    web                "Web browsers, servers, proxies, and other tools\n 
Packages in the 'web' section include Web browsers, Web servers and proxies, 
software to write CGI scripts or Web-based programs, pre-written Web-based 
programs, and other software related to the World Wide Web.";
+    x11                "The X window system and related software\n Packages in 
the 'x11' section include the core packages for the X window system, window 
managers, utility programs for X, and miscellaneous programs with an X GUI 
which were placed here because they didn't fit anywhere else.";
+
+    main       "The main Debian archive\n The Debian distribution consists of 
packages from the 'main' section. Every package in 'main' is Free Software.\n 
.\n For more information about what Debian considers to be Free Software, see 
http://www.debian.org/social_contract#guidelines";;
+    contrib    "Programs which depend on software not in Debian\n Packages in 
the 'contrib' section are not part of Debian.\n .\n These packages are Free 
Software, but they depend on software which is not part of Debian.  This may be 
because it is not Free Software, but is packaged in the non-free section of the 
archive, because Debian cannot distribute it at all, or (in rare cases) because 
no-one has packaged it yet.\n .\n For more information about what Debian 
considers to be Free Software, see 
http://www.debian.org/social_contract#guidelines";;
+    non-free   "Programs which are not free software\n Packages in the 
'non-free' section are not part of Debian.\n .\n These packages fail to meet 
one or more of the requirements of the Debian Free Software Guidelines (see 
below). You should read the license of programs in this section to be sure that 
you are allowed to use them in the way you intend.\n .\n For more information 
about what Debian considers to be Free Software, see 
http://www.debian.org/social_contract#guidelines";;
+    non-US     "Programs stored outside the US due to export controls\n 
Packages in 'non-US' likely contain cryptography; a few implement patented 
algorithms. Because of this, they cannot be exported from the United States, 
and hence are stored on a server in the ''free world''.\n .\n Note: the Debian 
Project is currently merging cryptographic software into the US-based archives 
after consulting with legal experts about recent changes in export policies. 
Most packages which were formerly found in this section, therefore, are now in 
'main'.";
+  };
+};
+
diff -Naur aptitude.orig/doc/en/aptitude.xml aptitude.topdir/doc/en/aptitude.xml
--- aptitude.orig/doc/en/aptitude.xml   2008-01-04 10:52:48.000000000 -0500
+++ aptitude.topdir/doc/en/aptitude.xml 2008-01-04 11:07:01.000000000 -0500
@@ -5369,10 +5369,12 @@
                    <listitem>
                      <para>
                        Group based on the part of the Section field before the
-                       first <literal>/</literal> character; if there is no
-                       <literal>/</literal>,
-                       <quote><literal>main</literal></quote> will be used
-                       instead.
+                       first <literal>/</literal> character; if this part of
+                       the Section is not recognized, or if there is no
+                       <literal>/</literal>, the first recognized value will
+                       be used instead.  The configuration item <literal><link
+                       
linkend='configTop-Sections'>Aptitude::Sections::Top-Sections</link></literal>
+                       specifies the <quote>recognized</quote> values.
                      </para>
                    </listitem>
                  </varlistentry>
@@ -5383,7 +5385,9 @@
                    <listitem>
                      <para>
                        Group based on the part of the Section field after the
-                       first <literal>/</literal> character; if there is no
+                       first <literal>/</literal> character; if the
+                       <quote><literal>topdir</literal></quote> part of the
+                       Section is not recognized, or if there is no
                        <literal>/</literal>, the entire field will be used.
                      </para>
                    </listitem>
@@ -5395,7 +5399,9 @@
                    <listitem>
                      <para>
                        Group based on the part of the Section field after the
-                       first <literal>/</literal> character; if there is no
+                       first <literal>/</literal> character; if the
+                       <quote><literal>topdir</literal></quote> part of the
+                       Section is not recognized, or if there is no
                        <literal>/</literal>, the entire field will be used; if
                        there are multiple <literal>/</literal> characters,
                        a hierarchy of groups will be formed.
@@ -9003,6 +9009,32 @@
              </seg>
            </seglistitem>
 
+           <seglistitem id='configTop-Sections'>
+             <seg><literal>Aptitude::Sections::Top-Sections</literal></seg>
+             <seg><literal>main,contrib,non-free,non-US</literal></seg>
+             <seg>
+               Comma-separated list of section components to be recognized by
+               the <quote><literal>topdir</literal></quote> mode of the
+               <quote><literal>section</literal></quote> package heirarchy
+               grouping policy; see <xref linkend='secGroupingPolicy'/>
+               for more information.  The first value in this list will be
+               used in cases where there is no <literal>/</literal> in the
+               package's Section field, or the first part of the package's
+               Section field is not in this list.
+             </seg>
+           </seglistitem>
+
+           <seglistitem id='configDescriptions'>
+             <seg><literal>Aptitude::Sections::Descriptions</literal></seg>
+             <seg><literal></literal></seg>
+             <seg>
+               This option is a group whose members define the descriptions
+               displayed for each section when using the
+               <quote><literal>section</literal></quote> package heirarchy
+               grouping policy.
+             </seg>
+           </seglistitem>
+
            <seglistitem id='configSimulate'>
              <seg><literal>Aptitude::Simulate</literal></seg>
              <seg><literal>false</literal></seg>
diff -Naur aptitude.orig/src/pkg_grouppolicy.cc 
aptitude.topdir/src/pkg_grouppolicy.cc
--- aptitude.orig/src/pkg_grouppolicy.cc        2008-01-04 10:52:49.000000000 
-0500
+++ aptitude.topdir/src/pkg_grouppolicy.cc      2008-01-04 11:00:19.000000000 
-0500
@@ -28,6 +28,7 @@
 #include <cwidget/generic/util/transcode.h>
 
 #include <generic/apt/apt.h>
+#include <generic/apt/config_signal.h>
 #include <generic/apt/matchers.h>
 #include <generic/apt/pkg_hier.h>
 #include <generic/apt/tags.h>
@@ -40,6 +41,7 @@
 
 #include <ctype.h>
 
+#include <apt-pkg/error.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/version.h>
 
@@ -121,6 +123,7 @@
 
   // The descriptions are in the cw::style used by package descriptions.
   static hash_map<string, wstring> section_descriptions;
+  static string top_sections;
   static void init_section_descriptions();
 public:
   pkg_grouppolicy_section(pkg_grouppolicy_section_factory::split_mode_type 
_split_mode,
@@ -139,7 +142,7 @@
   virtual ~pkg_grouppolicy_section()
     {
       for(section_map::iterator i=sections.begin(); i!=sections.end(); i++)
-        delete i->second.first;
+       delete i->second.first;
     }
 };
 
@@ -151,63 +154,54 @@
 }
 
 hash_map<string, wstring> pkg_grouppolicy_section::section_descriptions;
+string pkg_grouppolicy_section::top_sections;
+
+typedef codecvt<wstring::value_type, string::value_type, mbstate_t> 
codecvt_type;
 
-// Should this be externally configurable?
 void pkg_grouppolicy_section::init_section_descriptions()
 {
   static bool already_done=false;
-
   if(already_done)
     return;
+  already_done=true;
 
-  section_descriptions["Tasks"]=W_("Packages which set up your computer to 
perform a particular task\n Packages in the 'Tasks' section contain no files; 
they merely depend upon other packages. These packages provide an easy way to 
select a predefined set of packages for a specialized task.");
-
-  section_descriptions["Unknown"]=W_("Packages with no declared section\n No 
section is given for these packages. Perhaps there is an error in the Packages 
file?");
-
-  section_descriptions["admin"]=W_("Administrative utilities (install 
software, manage users, etc)\n Packages in the 'admin' section allow you to 
perform administrative tasks such as installing software, managing users, 
configuring and monitoring your system, examining network traffic, and so on.");
-
-  section_descriptions["alien"]=W_("Packages converted from foreign formats 
(rpm, tgz, etc)\n Packages in the 'alien' section were created by the 'alien' 
program from a non-Debian package format such as RPM");
-  section_descriptions["base"]=W_("The Debian base system\n Packages in the 
'base' section are part of the initial system installation.");
-  section_descriptions["comm"]=W_("Programs for faxmodems and other 
communication devices\n Packages in the 'comm' section are used to control 
modems and other hardware communications devices. This includes software to 
control faxmodems (for instance, PPP for dial-up internet connections and 
programs originally written for that purpose, such as zmodem/kermit), as well 
as software to control cellular phones, interface with FidoNet, and run a 
BBS.");
-  section_descriptions["devel"]=W_("Utilities and programs for software 
development\n Packages in the 'devel' section are used to write new software 
and work on existing software. Non-programmers who do not compile their own 
software probably do not need much software from this section.\n .\n It 
includes compilers, debugging tools, programmer's editors, source processing 
tools, and other things related to software development.");
-  section_descriptions["doc"]=W_("Documentation and specialized programs for 
viewing documentation\n Packages in the 'doc' section document parts of the 
Debian system, or are viewers for documentation formats.");
-  section_descriptions["editors"]=W_("Text editors and word processors\n 
Packages in the 'editors' section allow you to edit plain ASCII text. These are 
not necessarily word processors, although some word processors may be found in 
this section.");
-  section_descriptions["electronics"]=W_("Programs for working with circuits 
and electronics\n Packages in the 'electronics' section include circuit design 
tools, simulators and assemblers for microcontrollers, and other related 
software.");
-  section_descriptions["embedded"]=W_("Programs for embedded systems\n 
Packages in the 'embedded' section are meant to run on embedded devices. 
Embedded devices are specialized hardware devices with much less power than a 
typical desktop system: for instance, a PDA, a cell phone, or a Tivo.");
-  section_descriptions["gnome"]=W_("The GNOME Desktop System\n GNOME is a 
collection of software which provides an easy-to-use desktop environment for 
Linux.  Packages in the 'gnome' section are part of the GNOME environment or 
closely integrated into it.");
-  section_descriptions["games"]=W_("Games, toys, and fun programs\n Packages 
in the 'games' section are meant primarily for entertainment.");
-  section_descriptions["graphics"]=W_("Utilities to create, view, and edit 
graphics files\n Packages in the 'graphics' section include viewers for image 
files, image processing and manipulation software, software to interact with 
graphics hardware (such as video cards, scanners, and digital cameras), and 
programming tools for handling graphics.");
-  section_descriptions["hamradio"]=W_("Software for ham radio operators\n 
Packages in the 'hamradio' section are meant primarily for ham radio 
operators.");
-  section_descriptions["interpreters"]=W_("Interpreters for interpreted 
languages\n Packages in the 'interpreters' section include interpreters for 
languages like Python, Perl, and Ruby, and libraries for these same 
languages.");
-  section_descriptions["kde"]=W_("The KDE Desktop System\n KDE is a collection 
of software which provides an easy-to-use desktop environment for Linux.  
Packages in the 'kde' section are part of the KDE environment or closely 
integrated into it.");
-  section_descriptions["libdevel"]=W_("Development files for libraries\n 
Packages in the 'libdevel' section contain files required for building programs 
that use libraries in the 'libs' section.  You don't need packages from this 
section unless you want to compile software yourself.");
-  section_descriptions["libs"]=W_("Collections of software routines\n Packages 
in the 'libs' section provide necessary functionality for other software on the 
computer. With very few exceptions, you should not need to explicitly install a 
package from this section; the package system will install them as required to 
fulfill dependencies.");
-  section_descriptions["perl"]=W_("Perl interpreter and libraries\n Packages 
in the 'perl' section provide the Perl programming language and many 
third-party libraries for it. Unless you are a Perl programmer, you don't need 
to install packages from this section explicitly; the package system will 
install them if they are required.");
-  section_descriptions["python"]=W_("Python interpreter and libraries\n 
Packages in the 'python' section provide the Python programming language and 
many third-party libraries for it. Unless you are a Python programmer, you 
don't need to install packages from this section explicitly; the package system 
will install them if they are required.");
-  section_descriptions["mail"]=W_("Programs to write, send, and route email 
messages\n Packages in the 'mail' section include mail readers, mail transport 
daemons, mailing list software, and spam filters, as well as various other 
software related to electronic mail.");
-  section_descriptions["math"]=W_("Numeric analysis and other 
mathematics-related software\n Packages in the 'math' section include 
calculators, languages for mathematical computation (similar to Mathematica), 
symbolic algebra packages, and programs to visualize mathematical objects.");
-  section_descriptions["misc"]=W_("Miscellaneous software\n Packages in the 
'misc' section have too unusual a function to be classified.");
-  section_descriptions["net"]=W_("Programs to connect to and provide various 
services\n Packages in the 'net' section include clients and servers for many 
protocols, tools to manipulate and debug low-level network protocols, IM 
systems, and other network-related software.");
-  section_descriptions["news"]=W_("Usenet clients and servers\n Packages in 
the 'news' section are related to the Usenet distributed news system.  They 
include news readers and news servers.");
-  section_descriptions["oldlibs"]=W_("Obsolete libraries\n Packages in the 
'oldlibs' section are obsolete and should not be used by new software.  They 
are provided for compatibility reasons, or because software distributed by 
Debian still requires them.\n .\n With very few exceptions, you should not need 
to explicitly install a package from this section; the package system will 
install them as required to fulfill dependencies.");
-  section_descriptions["otherosfs"]=W_("Emulators and software to read foreign 
filesystems\n Packages in the 'otherosfs' section emulate hardware and 
operating systems and provide tools for transferring data between different 
operating systems and hardware platforms. (for instance, utilities to read DOS 
floppies, and utilities to communicate with Palm Pilots)\n .\n It is worth 
noting that CD burning software is included in THIS section.");
-  section_descriptions["science"]=W_("Software for scientific work\n Packages 
in the 'science' section include tools for astronomy, biology, and chemistry, 
as well as other science-related software.");
-  section_descriptions["shells"]=W_("Command shells and alternative console 
environments\n Packages in the 'shells' section include programs providing a 
command-line interface.");
-  section_descriptions["sound"]=W_("Utilities to play and record sound\n 
Packages in the 'sound' section include sound players, recorders, and encoders 
for many formats, mixers and volume controls, MIDI sequencers and programs to 
generate musical notation, drivers for sound hardware, and sound processing 
software.");
-  section_descriptions["tex"]=W_("The TeX typesetting system\n Packages in the 
'tex' section are related to TeX, a system for producing high-quality typeset 
output.  They include TeX itself, TeX packages, editors designed for TeX, 
utilities to convert TeX and TeX output files to various formats, TeX fonts, 
and other software related to TeX.");
-  section_descriptions["text"]=W_("Text processing utilities\n Packages in the 
'text' section include text filters and processors, spelling checkers, 
dictionary programs, utilities to convert between character encodings and text 
file formats (eg, Unix and DOS), text formatters and pretty-printers, and other 
software which operates on plain text.");
-  section_descriptions["utils"]=W_("Various system utilities\n Packages in the 
'utils' section are utilities whose purpose is too unique to be classified.");
-  section_descriptions["web"]=W_("Web browsers, servers, proxies, and other 
tools\n Packages in the 'web' section include Web browsers, Web servers and 
proxies, software to write CGI scripts or Web-based programs, pre-written 
Web-based programs, and other software related to the World Wide Web.");
-  section_descriptions["x11"]=W_("The X window system and related software\n 
Packages in the 'x11' section include the core packages for the X window 
system, window managers, utility programs for X, and miscellaneous programs 
with an X GUI which were placed here because they didn't fit anywhere else.");
-
-  section_descriptions["contrib"]=W_("Programs which depend on software not in 
Debian\n Packages in the 'contrib' section are not part of Debian.\n .\n These 
packages are Free Software, but they depend on software which is not part of 
Debian.  This may be because it is not Free Software, but is packaged in the 
non-free section of the archive, because Debian cannot distribute it at all, or 
(in rare cases) because no-one has packaged it yet.\n .\n For more information 
about what Debian considers to be Free Software, see 
http://www.debian.org/social_contract#guidelines";);
-  section_descriptions["main"]=W_("The main Debian archive\n The Debian 
distribution consists of packages from the 'main' section. Every package in 
'main' is Free Software.\n .\n For more information about what Debian considers 
to be Free Software, see http://www.debian.org/social_contract#guidelines";);
-  section_descriptions["non-US"]=W_("Programs stored outside the US due to 
export controls\n Packages in 'non-US' likely contain cryptography; a few 
implement patented algorithms. Because of this, they cannot be exported from 
the United States, and hence are stored on a server in the \"free world\".\n 
.\n Note: the Debian Project is currently merging cryptographic software into 
the US-based archives after consulting with legal experts about recent changes 
in export policies. Most packages which were formerly found in this section, 
therefore, are now in 'main'.");
-  section_descriptions["non-free"]=W_("Programs which are not free software\n 
Packages in the 'non-free' section are not part of Debian.\n .\n These packages 
fail to meet one or more of the requirements of the Debian Free Software 
Guidelines (see below). You should read the license of programs in this section 
to be sure that you are allowed to use them in the way you intend.\n .\n For 
more information about what Debian considers to be Free Software, see 
http://www.debian.org/social_contract#guidelines";);
-
-  section_descriptions["virtual"]=W_("Virtual packages\n These packages do not 
exist; they are names other packages use to require or provide some 
functionality.");
+  top_sections = aptcfg->Find(PACKAGE "::Sections::Top-Sections", 
"main,contrib,non-free,non-US");
 
-  already_done=true;
+  if(aptcfg->Exists(PACKAGE "::Sections::Descriptions"))
+    {
+      for(const Configuration::Item *Curr=aptcfg->Tree(PACKAGE 
"::Sections::Descriptions")->Child; Curr; Curr=Curr->Next)
+        {
+          string desc = Curr->Value;
+
+          // Replace literal "\n" sequences in description with '\n' characters
+          string::size_type pos;
+          while((pos = desc.find("\\n")) != desc.npos)
+            desc.replace(pos, 2, 1, '\n');
+
+          // Hack to work around the fact that " characters can't be used in 
configuration values
+          while((pos = desc.find("''")) != desc.npos)
+            desc.replace(pos, 2, 1, '"');
+
+          // Convert 'string' configuration value to 'wstring' description
+          // Based on examples at 
http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/codecvt.html
+          // and files in libstdc++-v3/testsuite/22_locale/codecvt/in/wchar_t/
+          wstring wdesc;
+          // size() and resize() work on characters, not bytes, so the 
following allocation should be sufficient
+          wdesc.resize(desc.size());
+          const codecvt_type& cvt = use_facet<codecvt_type>(locale());
+          codecvt_type::state_type state;
+          memset(&state, 0, sizeof(state));
+          const string::value_type *desc_next;
+          wstring::value_type *wdesc_next;
+          codecvt_base::result ret = cvt.in(state, &*desc.begin(), 
&*desc.end(), desc_next, &*wdesc.begin(), &*wdesc.end(), wdesc_next);
+
+          // Populate the section_descriptions hash
+          if(ret != codecvt_base::ok && ret != codecvt_base::noconv)
+            _error->Error(_("Error converting Sections::Description::%s"), 
Curr->Tag.c_str());
+          else
+            section_descriptions[Curr->Tag] = wdesc;
+        }
+    }
 }
 
 void pkg_grouppolicy_section::add_package(const pkgCache::PkgIterator &pkg,
@@ -226,7 +220,7 @@
     }
   else if(pkg.VersionList().end())
     {
-      section=_("virtual");
+      section=_("Virtual");
       may_passthrough = true;
     }
   else if(!pkg.VersionList().Section())
@@ -243,13 +237,14 @@
       // or only the part following it, modify the section
       // accordingly.
       string::size_type first_split = section.find('/');
+      string first_section = section.substr(0,first_split);
+      bool is_top_section = (first_split != section.npos
+                            && top_sections.find(first_section) != 
top_sections.npos);
       if(split_mode == pkg_grouppolicy_section_factory::split_topdir)
-       section = (first_split != section.npos
-                  ? section.substr(0,first_split)
-                  : _("main"));
+       section = (is_top_section ? first_section : 
top_sections.substr(0,top_sections.find(',')));
       else if((split_mode == pkg_grouppolicy_section_factory::split_subdir ||
               split_mode == pkg_grouppolicy_section_factory::split_subdirs) &&
-             first_split != section.npos)
+             is_top_section)
        section = section.substr(first_split + 1);
     }
 
@@ -308,19 +303,23 @@
          section_map::iterator found = sections.find(section_id);
          if(found == sections.end())
            {
-             string section_tail = section;
+             string desc_section = section_id;
              pkg_subtree *newtree;
 
-             // Look up the description of the section based on the
-             // last component of its name, and create a new subtree
-             // for it.
-             string::size_type last_split = section.rfind('/');
-             if(last_split != section.npos)
-               section_tail = section.substr(last_split+1);
+             // Use only the last component of the section to look up
+             // descriptions when grouping policy is 'none'
+             if(split_mode == pkg_grouppolicy_section_factory::split_none)
+               {
+                 string::size_type last_split = desc_section.rfind('/');
+                 if(last_split != desc_section.npos)
+                   desc_section = desc_section.substr(last_split+1);
+               }
 
-             if(section_descriptions.find(section_tail) != 
section_descriptions.end())
+             // Look up the description of the section and create
+             // a new subtree for it.
+             if(section_descriptions.find(desc_section) != 
section_descriptions.end())
                {
-                 wstring desc = section_descriptions[section_tail];
+                 wstring desc = section_descriptions[desc_section];
                  if(desc.find(L'\n') != desc.npos)
                    newtree = new pkg_subtree(cw::util::transcode(section) + L" 
- " + wstring(desc, 0, desc.find('\n')), desc, get_desc_sig());
                  else

Reply via email to