[gtk-doc] mkdb: keep db-header also if ns decl is in doctype. Fixes #590602



commit cb50e6173199821f8a28f39ac2f2fe78f8c1f858
Author: Stefan Kost <ensonic users sf net>
Date:   Sun Jan 3 14:55:02 2010 +0200

    mkdb: keep db-header also if ns decl is in doctype. Fixes #590602
    
    Nowadays we add the xinclude namespace decl to the doctype. The code was
    expecting it only in the top-level tag.

 gtkdoc-mkdb.in |   52 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/gtkdoc-mkdb.in b/gtkdoc-mkdb.in
index b8e8a7b..416f6e7 100755
--- a/gtkdoc-mkdb.in
+++ b/gtkdoc-mkdb.in
@@ -118,16 +118,35 @@ EOF
 
 my ($empty_element_end, $doctype_header);
 
-if (lc($OUTPUT_FORMAT) eq "xml") {
+# autodetect output format
+if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
+    if (!$MAIN_SGML_FILE) {
+        if (-e "${MODULE}-docs.xml") {
+            $OUTPUT_FORMAT = "xml";
+        } else {
+            $OUTPUT_FORMAT = "sgml";
+        }
+    } else {
+        if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
+            $OUTPUT_FORMAT = lc($1);
+        }
+    }
+    
+} else {
+    $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
+}
+
+#print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
+
+if ($OUTPUT_FORMAT eq "xml") {
     if (!$MAIN_SGML_FILE) {
         # backwards compatibility
         if (-e "${MODULE}-docs.sgml") {
-            $MAIN_SGML_FILE="${MODULE}-docs.sgml";
+            $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
         } else {
-            $MAIN_SGML_FILE="${MODULE}-docs.xml";
+            $MAIN_SGML_FILE = "${MODULE}-docs.xml";
         }
     }
-    $OUTPUT_FORMAT = "xml";
     $empty_element_end = "/>";
 
     if (-e $MAIN_SGML_FILE) {
@@ -135,7 +154,8 @@ if (lc($OUTPUT_FORMAT) eq "xml") {
 	$doctype_header = "";
 	while (<INPUT>) {
 	    if (/^\s*<(book|chapter|article)/) {
-		if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
+	        # check that the top-level tag or the doctype decl contain the xinclude namespace decl
+		if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
 		    $doctype_header = "";
 		}
 	        last;
@@ -147,16 +167,18 @@ if (lc($OUTPUT_FORMAT) eq "xml") {
         $doctype_header =
 "<?xml version=\"1.0\"?>\n" .
 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
-"               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\";>\n";
+"               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n"; .
+"[\n" .
+"  <!ENTITY % local.common.attrib \"xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
+"]>\n";
     }
     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
 } else {
     if (!$MAIN_SGML_FILE) {
-        $MAIN_SGML_FILE="${MODULE}-docs.sgml";
+        $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
     }
-    $OUTPUT_FORMAT = "sgml";
-    $doctype_header = "";
     $empty_element_end = ">";
+    $doctype_header = "";
 }
 
 my $ROOT_DIR = ".";
@@ -404,7 +426,7 @@ sub OutputObjectList {
     open (OUTPUT, ">$new_object_index")
 	|| die "Can't create $new_object_index: $!";
 
-    if (lc($OUTPUT_FORMAT) eq "xml") {
+    if ($OUTPUT_FORMAT eq "xml") {
         my $header = $doctype_header;
 
         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
@@ -555,7 +577,7 @@ sub OutputSGML {
             #print "End of section: $title\n";
 	    if ($num_symbols > 0) {
 		# collect documents
-		if (lc($OUTPUT_FORMAT) eq "xml") {
+		if ($OUTPUT_FORMAT eq "xml") {
 		    $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
 		} else {
 		    $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
@@ -2269,7 +2291,7 @@ sub OutputSGMLFile {
     # since it changes every day (and it is only used in the man pages):
     # "<refentry id="$section_id" revision="$mday $month $year">"
 
-    if (lc($OUTPUT_FORMAT) eq "xml") {
+    if ($OUTPUT_FORMAT eq "xml") {
         print OUTPUT $doctype_header;
     }
 
@@ -2376,13 +2398,13 @@ sub OutputBook {
     &UpdateFileIfChanged ($old_file, $new_file, 0);
 
 
-    # If the main SGML file hasn't been created yet, we create it here.
+    # If the main SGML/XML file hasn't been created yet, we create it here.
     # The user can tweak it later.
     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
       open (OUTPUT, ">$MAIN_SGML_FILE")
 	|| die "Can't create $MAIN_SGML_FILE: $!";
 
-      if (lc($OUTPUT_FORMAT) eq "xml") {
+      if ($OUTPUT_FORMAT eq "xml") {
 	  print OUTPUT <<EOF;
 <?xml version="1.0"?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
@@ -4921,7 +4943,7 @@ sub ReadObjectHierarchy {
     open (OUTPUT, ">$new_tree_index")
 	|| die "Can't create $new_tree_index: $!";
 
-    if (lc($OUTPUT_FORMAT) eq "xml") {
+    if ($OUTPUT_FORMAT eq "xml") {
         my $tree_header = $doctype_header;
 
         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]