Index: autoscripts/postinst-xmlcatalog
===================================================================
--- autoscripts/postinst-xmlcatalog	(revision 0)
+++ autoscripts/postinst-xmlcatalog	(revision 0)
@@ -0,0 +1,4 @@
+if [ "$1" = "configure" ]; then
+#ADD_PACKAGE#
+#ADD_ROOT#
+fi
Index: autoscripts/postrm-xmlcatalog
===================================================================
--- autoscripts/postrm-xmlcatalog	(revision 0)
+++ autoscripts/postrm-xmlcatalog	(revision 0)
@@ -0,0 +1,3 @@
+if [ "$1" = "purge" ]; then
+	rm -f #PACKAGECAT# #PACKAGECAT#.old
+fi
Index: autoscripts/prerm-xmlcatalog
===================================================================
--- autoscripts/prerm-xmlcatalog	(revision 0)
+++ autoscripts/prerm-xmlcatalog	(revision 0)
@@ -0,0 +1,4 @@
+if [ "$1" = "remove" ] || [ "$1" = "upgrade" ]; then
+#DEL_ROOT#
+#DEL_PACKAGE#
+fi
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 1633)
+++ debian/changelog	(working copy)
@@ -1,3 +1,25 @@
+debhelper (4.1.83.3) unstable; urgency=low
+
+  * NMU
+  * dh_installcatalogs POD spelling fixes
+
+ -- Adam Di Carlo <aph@debian.org>  Sun, 11 Jan 2004 17:01:20 -0500
+
+debhelper (4.1.83.2) unstable; urgency=low
+
+  * NMU
+  * more XML catalog sanity checks in dh_installcatalogs
+
+ -- Adam Di Carlo <aph@debian.org>  Sun, 11 Jan 2004 13:07:44 -0500
+
+debhelper (4.1.83.1) unstable; urgency=low
+
+  * NMU
+  * dh_installcatalogs expanded and now able to register XML catalogs.
+    By Ardo van Rangelrooij with revisions from Adam Di Carlo.
+
+ -- Adam Di Carlo <aph@debian.org>  Sat, 10 Jan 2004 19:42:36 -0500
+
 debhelper (4.1.83) unstable; urgency=low
 
   * Clarify dh_install's autodest behavior with wildcards. Closes: #224707
Index: dh_installcatalogs
===================================================================
--- dh_installcatalogs	(revision 1633)
+++ dh_installcatalogs	(working copy)
@@ -2,43 +2,87 @@
 
 =head1 NAME
 
-dh_installcatalogs - install and register SGML Catalogs
+dh_installcatalogs - install and register SGML and XML catalog files
 
-=cut
-
-use strict;
-use Debian::Debhelper::Dh_Lib;
-
-my $sgmlbasever = "1.17";
-
 =head1 SYNOPSIS
 
 B<dh_installcatalogs> [S<I<debhelper options>>] [B<-n>]
 
 =head1 DESCRIPTION
 
-dh_installcatalogs is a debhelper program that installs and
-registers SGML catalogs. (Note: it will be extended for XML catalog
-registration when xml-core is available.)  It complies with the Debian
-XML/SGML policy.
+dh_installcatalogs is a debhelper program that installs and registers
+SGML and XML catalog files.  It complies with the Debian XML/SGML policy.
 
-The file F<debian/I<package>.sgmlcatalogs> contains the catalogs to be
-installed per package.  Each line in that file should be of the form
-C<source dest>, where C<source> indicates where the catalog resides in
-the source tree, and C<dest> indicates the destination location for
-the catalog under the package build area.  C<dest> should start with
+=head2 SGML Catalog Files
+
+The file F<debian/I<package>.sgmlcatalogs> describes the local SGML
+catalog files to be installed per package and registered in the SGML
+catalog system.
+
+Each line in that file should be of the form C<source dest>, where
+C<source> indicates where the local SGML catalog resides in the source
+tree, and C<dest> indicates the destination for the local SGML catalog
+under the package build area.  C<dest> should start with
 F</usr/share/sgml/>.
 
-Catalogs will be registered in a supercatalog, in
-F</etc/sgml/I<package>.cat>.
+The SGML catalog files listed in the file
+F<debian/I<package>.sgmlcatalogs> will be registered in the package
+SGML catalog file, F</etc/sgml/I<package>.cat>.  In turn, this package
+SGML catalog will to be registered in the root SGML catalog file,
+F</etc/sgml/catalog>.
 
-This command automatically adds maintainer script snippets for
-registering and unregistering the catalogs and "supercatalogs" (unless
-B<-n> is used).  A dependancy on B<sgml-base> will be added to
-C<${misc:Depends}>, so be sure your package uses that variable in
-F<debian/control>.  See L<dh_installdeb(1)> for an explantion of
-Debhelper maintainer script snippets.
+B<dh_installcatalogs> automatically adds maintainer script snippets for the
+registration and unregistration in the SGML catalog system of the
+listed local SGML catalog files and the resulting package SGML catalog
+file (unless B<-n> is used).  A dependency on the B<sgml-base> package
+will be added to C<${misc:Depends}>, so be sure to use that variable
+in the file F<debian/control>.	See L<dh_installdeb(1)> for an
+explantion of Debhelper maintainer script snippets.
 
+=head2 XML Catalog Files
+
+The file F<debian/I<package>.xmlcatalogs> lists the local XML catalog
+files to be installed per package as well as the XML entities in those
+local XML catalog files that are to be registered in the XML catalog
+system.
+
+The local XML catalog file entries in that file should be of the form
+C<local;source;dest>, where the verbatim C<local> indicates this is an
+entry for a local XML catalog file, C<source> indicates where the
+local XML catalog resides in the source tree, and C<dest> indicates
+the destination location for the local XML catalog under the package
+build area.  C<dest> should start with F</usr/share/xml/>.
+
+The entries for the XML entities to be registered in the package XML
+catalog file should be of the form C<package;type;id;catalog>, where
+the verbatim C<package> indicates this is an entry for an XML entity
+to be registered in the package XML catalog file, C<type> indicates
+the XML entity type (public, system, uri), C<id> indicates the XML
+entity id, and C<catalog> indicates the local XML catalog file.
+
+The entries for the XML entities to be registered in the root XML
+catalog file should be of the form C<root;type;id>, where the verbatim
+C<root> indicates this is an entry for an XML entity to be registered
+in the root XML catalog file, C<type> indicates the XML entity type
+(public, system, uri), and C<id> indicates the XML entity id.
+
+XML entity types are described in L<update-xmlcatalog(8)>.  Using the
+C<root> or C<package> commands, a type of C<public> will general
+C<delegatePublic> statements in the applicable catalog file.
+Generally you will want to use the types C<public> for any formal
+public identifiers, and C<system> for any files on the local
+filesystem or URLs.  C<uri> is only used for non-local files which are
+not part of the external document subset, e.g., they are not used for
+entities or DTDs.
+
+B<dh_installcatalogs> automatically adds maintainer script snippets for the
+registration and unregistration of the listed XML entities in the XML
+catalog system (unless B<-n> is used).	A dependency on the
+B<xml-core> package will be added to C<${misc:Depends}>, so be sure to
+use that variable in the file F<debian/control>.  See
+L<dh_installdeb(1)> for an explantion of Debhelper maintainer script
+snippets.
+
 =head1 OPTIONS
 
 =over 4
@@ -55,22 +99,63 @@
 called between invocations of this command. Otherwise, it may cause
 multiple instances of the same text to be added to maintainer scripts.
 
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+=over 0
+
+=item
+F</usr/share/doc/sgml-base-doc/>
+
+=item
+F</usr/share/doc/xml-core/>
+
+=back
+
+=head1 AUTHOR
+
+=over 0
+
+=item
+Adam Di Carlo <aph@debian.org> (SGML catalog support)
+
+=item
+Ardo van Rangelrooij <ardo@debian.org> (XML catalog support)
+
+=back
+
 =cut
 
+use strict;
+use Debian::Debhelper::Dh_Lib;
+
+my $sgmlbasever = "1.17";
+my $xmlcorever	= "0.05";
+
+my $debug_update_xmlcatalog = 0;
+
 init();
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
-	my $tmpdir = tmpdir($package);
-	my $sgmlcatlistfile = pkgfile($package, "sgmlcatalogs");
-	my @sgmlinstalled; # catalogs we've installed
+
 	if ($#ARGV >= 0) {
 		error("extra command-line arguments");
 	}
+
+	my $tmpdir = tmpdir($package);
+
+	my $sgmlcatlistfile = pkgfile($package, "sgmlcatalogs");
+	my @sgmlinstalled; # SGML catalogs we've installed
+
 	if ($sgmlcatlistfile) {
+	
 		foreach my $line (filedoublearray($sgmlcatlistfile)) {
+	
 			my $source = $line->[0];
 			my $dest = $line->[1];
-	                my $fulldest = "$tmpdir/$dest"; 
+			
+			my $fulldest = "$tmpdir/$dest"; 
 			$fulldest =~ s|//|/|g; # beautification
 	
 			if (! -d dirname($fulldest)) {
@@ -80,36 +165,164 @@
 			doit("install","-p","-m644",$source,$fulldest);
 	
 			push(@sgmlinstalled,$dest);
+	
 		}
+	
 	}
+
 	if (@sgmlinstalled) {
+	
 		addsubstvar($package, "misc:Depends", "sgml-base", ">= $sgmlbasever");
 
 		if (! $dh{NOSCRIPTS}) {
+		
 			my $ordcats = join(" ", @sgmlinstalled);
 			my $centralcat = "/etc/sgml/$package.cat";
+			
 			autoscript($package, "postinst", "postinst-sgmlcatalog",
 				   "s%#CENTRALCAT#%$centralcat%g; s%#ORDCATS#%$ordcats%g;");
 			autoscript($package, "prerm", "prerm-sgmlcatalog",
 				   "s%#CENTRALCAT#%$centralcat%g;");
 			autoscript($package, "postrm", "postrm-sgmlcatalog",
 				   "s%#CENTRALCAT#%$centralcat%g;");
+		
 		}
+		
 	}
-	else {
-		# remove the dependency
-		addsubstvar($package, "misc:Depends", "sgml-base", ">= $sgmlbasever", 1);
-	}
-}
 
-=head1 SEE ALSO
+	my $xmlcatlistfile = pkgfile( $package, "xmlcatalogs" );
 
-L<debhelper(7)>
+	if ( $xmlcatlistfile ) {
 
-F</usr/share/doc/sgml-base-doc/>
+		my @xml_data = ();
 
-=head1 AUTHOR
+		open ( DH_FARRAY_IN, $xmlcatlistfile )
+			|| error( "cannot read $xmlcatlistfile: $1" );
+		while ( <DH_FARRAY_IN> ) {
+			chomp;
+			s/#.*//;
+			s/^\s+//;
+			s/\s+$//;
+			next unless length;
+			my @line = split( /;/ );
+			push( @xml_data, [@line] );
+		}
+		close( DH_FARRAY_IN );
 
-Adam Di Carlo <aph@debian.org>
+		my $packagecat	= "/etc/xml/$package.xml";
+		my $ADD_PACKAGE = '';
+		my $ADD_ROOT	= '';
+		my $DEL_PACKAGE = '';
+		my $DEL_ROOT	= '';
 
-=cut
+		foreach my $line ( @xml_data ) {
+
+			if ( $line->[0] eq 'local' ) {
+
+				my $source = $line->[1];
+				my $dest = $line->[2];
+
+				my $fulldest = "$tmpdir/$dest"; 
+				$fulldest =~ s|//|/|g; # beautification
+	
+				if ( ! -d dirname( $fulldest ) ) {
+					doit( "install", "-d", "-m755",
+					$tmpdir . "/" . dirname( $dest ) );
+				}
+
+				doit( "install", "-p", "-m644", $source, $fulldest );
+
+			} elsif ( $line->[0] eq 'package' ) {
+				if ( ! $dh{ NOSCRIPTS } ) {
+					my $type  = $line->[1];
+					my $id	  = $line->[2];
+					my $local = $line->[3];
+
+					if ( ! -f "$tmpdir/$local" ) {
+						die("error: package line uses non-existent catalog '$local'\n");
+					}
+
+					my $add_cmd = 'update-xmlcatalog';
+					$debug_update_xmlcatalog and $add_cmd .= ' --verbose';
+					$add_cmd .= ' --add';
+					$add_cmd .= " --package $package";
+					$add_cmd .= " --type $type";
+					$add_cmd .= " --id \\\"$id\\\"";
+					$add_cmd .= " --local $local";
+
+					$ADD_PACKAGE .= "\t$add_cmd\\n";
+
+					my $del_cmd = 'update-xmlcatalog';
+					$debug_update_xmlcatalog and $del_cmd .= ' --verbose';
+					$del_cmd .= ' --del';
+					$del_cmd .= " --package $package";
+					$del_cmd .= " --type $type";
+					$del_cmd .= " --id \\\"$id\\\"";
+					$del_cmd .= ' || true';
+
+					$DEL_PACKAGE .= "\t$del_cmd\\n";
+
+				}
+			} elsif ( $line->[0] eq 'root' ) {
+				if ( ! $dh{ NOSCRIPTS } ) {
+					my $type = $line->[1];
+					my $id	 = $line->[2];
+
+					my $add_cmd = 'update-xmlcatalog';
+					$debug_update_xmlcatalog and $add_cmd .= ' --verbose';
+					$add_cmd .= ' --add';
+					$add_cmd .= ' --root';
+					$add_cmd .= " --type $type";
+					$add_cmd .= " --id \\\"$id\\\"";
+					$add_cmd .= " --package $package";
+
+					$ADD_ROOT .= "\t$add_cmd\\n";
+
+					my $del_cmd = 'update-xmlcatalog';
+					$debug_update_xmlcatalog and $del_cmd .= ' --verbose';
+					$del_cmd .= ' --del';
+					$del_cmd .= ' --root';
+					$del_cmd .= " --type $type";
+					$del_cmd .= " --id \\\"$id\\\"";
+					$del_cmd .= ' || true';
+
+					$DEL_ROOT .= "\t$del_cmd\\n";
+
+				}
+			} else {
+				die("cannot understand command '" . $line->[0] . 
+				    "' in file $xmlcatlistfile\n");
+			}
+		}
+
+		if ( ! $dh{ NOSCRIPTS } ) {
+
+			# sanity checking
+			if ( $ADD_PACKAGE and not $ADD_ROOT ) {
+				warn("warning: elements added to package XML catalog, but not entry for root catalog\n");
+			}
+
+			if ( not $ADD_PACKAGE and not $ADD_ROOT ) {
+				warning("warning: no catalogs registered\n");
+			} else {
+				$ADD_PACKAGE or $ADD_PACKAGE = "\t:";
+				$ADD_ROOT    or $ADD_ROOT    = "\t:";
+				$DEL_PACKAGE or $DEL_PACKAGE = "\t:";
+				$DEL_ROOT    or $DEL_ROOT    = "\t:";
+
+				autoscript( $package, "postinst", "postinst-xmlcatalog",
+					    "s%#ADD_PACKAGE#%$ADD_PACKAGE%g; s%#ADD_ROOT#%$ADD_ROOT%g;" );
+				autoscript( $package, "prerm", "prerm-xmlcatalog",
+					    "s%#DEL_PACKAGE#%$DEL_PACKAGE%g; s%#DEL_ROOT#%$DEL_ROOT%g;" );
+				autoscript( $package, "postrm", "postrm-xmlcatalog",
+					    "s%#PACKAGECAT#%$packagecat%g;" );
+
+				addsubstvar( $package,
+					     "misc:Depends", "xml-core", ">= $xmlcorever" );
+			}
+		}
+
+	}
+	
+}
+
Index: examples/xml-core.xmlcatalogs
===================================================================
--- examples/xml-core.xmlcatalogs	(revision 0)
+++ examples/xml-core.xmlcatalogs	(revision 0)
@@ -0,0 +1,5 @@
+local;catalog.xml;/usr/share/xml/schema/xml-core/catalog.xml
+package;public;-//OASIS//DTD XML Catalogs V1.0//EN;/usr/share/xml/schema/xml-core/catalog.xml
+package;system;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd;/usr/share/xml/schema/xml-core/catalog.xml
+root;public;-//OASIS//DTD XML Catalogs V1.0//EN
+root;system;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd
