docs-common/bin xmlpp,1.2,1.3

Tommy Reynolds (jtr) fedora-docs-commits at redhat.com
Thu Dec 15 05:42:13 UTC 2005


Author: jtr

Update of /cvs/docs/docs-common/bin
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv6168

Modified Files:
	xmlpp 
Log Message:
Output <!ENTITY> elements, so they can now be compared.



Index: xmlpp
===================================================================
RCS file: /cvs/docs/docs-common/bin/xmlpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- xmlpp	15 Dec 2005 03:59:38 -0000	1.2
+++ xmlpp	15 Dec 2005 05:42:05 -0000	1.3
@@ -2,10 +2,10 @@
 
 #
 #  Copyright (c) 2002, DecisionSoft Limited All rights reserved.
-#  Please see: 
+#  Please see:
 #  http://software.decisionsoft.com/licence.html
 #  for more information.
-# 
+#
 
 # $Revision$
 #
@@ -37,7 +37,7 @@
 
 # expect to find attributeOrdering.txt file in same directory
 # as xmlpp is being run from
-    
+
   my $scriptDir = $0;
   if ($scriptDir =~ m#/#){
     $scriptDir =~ s#/[^/]+$##;
@@ -45,22 +45,22 @@
   else{
     $scriptDir =".";
   }
-    
+
   # get attribute ordering from external file
   if (open(SORTLIST, "<$scriptDir/attributeOrdering.txt")) {
     @sortlist = <SORTLIST>;
     chomp @sortlist;
     close (SORTLIST);
     @specialSort = grep(/^\w+/, @sortlist);
-  } 
-  else {      
+  }
+  else {
 #   print STDERR  "Could not open $scriptDir/attributeOrdering.txt: $!\nWARNING attribute sorting will only be alphabetic\n\n";
   }
 }
 
 
 # set line separator to ">" speeding up parsing of XML files
-# with no line breaks 
+# with no line breaks
 
 $/ = ">";
 
@@ -78,7 +78,7 @@
 }
 
 if (!$opt_z && scalar(@ARGV) > 1) {
-    print STDERR "Warning: Multiple files specified without -z option\n"; 
+    print STDERR "Warning: Multiple files specified without -z option\n";
 }
 
 my $fh;
@@ -103,71 +103,72 @@
     my $input;
 
     while ($input .= <$fh>) {
-        while ($input) {
-            if ($input =~ s/^<($re_name)((?:\s+$re_name\s*=\s*$re_attr)*\s*)(\/?)>(.*)$/$4/s ) {
-                my %attr;
-                my ($name,$attr,$selfclose) = ($1,$2,$3);
-                while ($attr =~ m/($re_name)\s*=\s*($re_attr)/gs) {
-                    my ($name,$value) = ($1,$2);
-                    $value =~ s/^["'](.*)["']$/$1/s;
-                    $attr{$name} = $value;
-                }
-                if ($opt_e) {
-                    parseStart($name, 0, %attr);
-                    if ($selfclose) { parseEnd($name) }
-                } else {
-                    parseStart($name, $selfclose, %attr);
-                }
-            } elsif ($input =~ s/^<\/($re_name)\s*>(.*)$/$2/s) {
-                parseEnd($1);
-            } elsif ($input =~ s/^<!--(.*?)-->(.*)$/$2/s) { 
-                parseComment($1);
-            } elsif ($input =~ s/^([^<]+)(.*)$/$2/s) {
-                parseDefault($1);
-            } elsif ($input =~ s/^(<\?[^>]*\?>)(.*)$/$2/s) {
-                parsePI("$1\n");
-            } elsif ($input =~ s/^(<\!DOCTYPE[^\[>]*(\[[^\]]*\])?[^>]*>)(.*)$/$3/s) {
-                parseDoctype("$1");
-            } elsif ($input =~ s/^(<\!ENTITY.*>)//s) {
-            } else {
-                last;
-            }
-        }
-        if (eof($fh)) {
-            last;
-        }
+	while ($input) {
+	    if ($input =~ s/^<($re_name)((?:\s+$re_name\s*=\s*$re_attr)*\s*)(\/?)>(.*)$/$4/s ) {
+		my %attr;
+		my ($name,$attr,$selfclose) = ($1,$2,$3);
+		while ($attr =~ m/($re_name)\s*=\s*($re_attr)/gs) {
+		    my ($name,$value) = ($1,$2);
+		    $value =~ s/^["'](.*)["']$/$1/s;
+		    $attr{$name} = $value;
+		}
+		if ($opt_e) {
+		    parseStart($name, 0, %attr);
+		    if ($selfclose) { parseEnd($name) }
+		} else {
+		    parseStart($name, $selfclose, %attr);
+		}
+	    } elsif ($input =~ s/^<\/($re_name)\s*>(.*)$/$2/s) {
+		parseEnd($1);
+	    } elsif ($input =~ s/^<!--(.*?)-->(.*)$/$2/s) {
+		parseComment($1);
+	    } elsif ($input =~ s/^([^<]+)(.*)$/$2/s) {
+		parseDefault($1);
+	    } elsif ($input =~ s/^(<\?[^>]*\?>)(.*)$/$2/s) {
+		parsePI("$1\n");
+	    } elsif ($input =~ s/^(<\!DOCTYPE[^\[>]*(\[[^\]]*\])?[^>]*>)(.*)$/$3/s) {
+		parseDoctype("$1");
+	    } elsif ($input =~ s/^(<\!ENTITY[^>]*>)(.*)$/$2/s) {
+		    $output .= "$1";
+	    } else {
+		last;
+	    }
+	}
+	if (eof($fh)) {
+	    last;
+	}
     }
 
 
     if ($input) {
-        $input =~ m/([^\n]+)/gs;
-        print STDERR "WARNING: junk remaining on input: $1\n";
+	$input =~ m/([^\n]+)/gs;
+	print STDERR "WARNING: junk remaining on input: $1\n";
     }
     $fh->close();
 
     if (!$opt_z) {
-        if(!$opt_H){ 
-            print "$output\n"
-        } else {
-            print html_escape($output)."\n"
-        }
+	if(!$opt_H){
+	    print "$output\n"
+	} else {
+	    print html_escape($output)."\n"
+	}
     } else {
-        if ($input) { 
-            print STDERR "Not overwriting file\n";
-        } else {
-            open FOUT,"> $filename" or die "Cannot overwrite file: $!";
-            if(!$opt_H){
-                print FOUT "$output\n"
-            } else {
-                print FOUT html_escape($output)."\n"
-            }
-            close FOUT
-        }
+	if ($input) {
+	    print STDERR "Not overwriting file\n";
+	} else {
+	    open FOUT,"> $filename" or die "Cannot overwrite file: $!";
+	    if(!$opt_H){
+		print FOUT "$output\n"
+	    } else {
+		print FOUT html_escape($output)."\n"
+	    }
+	    close FOUT
+	}
     }
 } while (
     !$stdin && $opt_z && ($fh = open_next_file(\$filename))
   );
-  
+
 
 
 sub parseStart {
@@ -175,21 +176,21 @@
     my $selfclose = shift;
     my %attr = @_;
 
-    $textContent =~ s/\s+$//; 
+    $textContent =~ s/\s+$//;
     printContent($textContent);
 
     if($inAnnotation) {
-        return;
+	return;
     }
 
     if($schemaHackMode and $s =~ m/(^|:)annotation$/) {
-        $inAnnotation = 1;
-        $textContent = '';
-        $lastTag = 1;
-        return;
+	$inAnnotation = 1;
+	$textContent = '';
+	$lastTag = 1;
+	return;
     }
     if (length($output)) {
-        $output .= "\n";
+	$output .= "\n";
     }
 
     $output .= "  " x $indent;
@@ -211,59 +212,59 @@
       # alphabetic order). Else create a list that has attributes needing
       # special ordering.
       foreach $attribute (@alphaSorted){
-        $isSpecial = 0;
-        foreach $sortAttrib (@specialSort){
-          if ($attribute eq $sortAttrib){
-            push @needSpecialSort, $attribute;
-            $isSpecial = 1;
-          }
-        }
-        if (!$isSpecial){
-          push @final, $attribute;
-        }
+	$isSpecial = 0;
+	foreach $sortAttrib (@specialSort){
+	  if ($attribute eq $sortAttrib){
+	    push @needSpecialSort, $attribute;
+	    $isSpecial = 1;
+	  }
+	}
+	if (!$isSpecial){
+	  push @final, $attribute;
+	}
       }
 
       # now read through the specialSort list backwards looking for
-      # any match in the needSpecialSort list. Unshift this onto the 
+      # any match in the needSpecialSort list. Unshift this onto the
       # front of the final array to maintain proper order.
       foreach my $attribute (reverse @specialSort){
-        foreach (@needSpecialSort){
-          if ($attribute eq $_){
-            unshift @final, $attribute;
-          }
-        }
+	foreach (@needSpecialSort){
+	  if ($attribute eq $_){
+	    unshift @final, $attribute;
+	  }
+	}
       }
 
       @k = @final;
     }
 
     foreach my $attr (@k) {
-        # 
-        # Remove (min|max)Occurs = 1 if schemaHackMode
-        #
-        if ($schemaHackMode and $attr =~ m/^(minOccurs|maxOccurs)$/ and $attr{$attr} eq "1") {
-            next;
-        }
-
-        if ($splitAttributes) {
-            $output .= "\n"."  " x $indent." ";
-        }
-        if ($attr{$attr} =~ /'/) {
-            $output .= " $attr=\"$attr{$attr}\"";
-        } else {
-            $output .= " $attr='$attr{$attr}'";
-        }
+	#
+	# Remove (min|max)Occurs = 1 if schemaHackMode
+	#
+	if ($schemaHackMode and $attr =~ m/^(minOccurs|maxOccurs)$/ and $attr{$attr} eq "1") {
+	    next;
+	}
+
+	if ($splitAttributes) {
+	    $output .= "\n"."  " x $indent." ";
+	}
+	if ($attr{$attr} =~ /'/) {
+	    $output .= " $attr=\"$attr{$attr}\"";
+	} else {
+	    $output .= " $attr='$attr{$attr}'";
+	}
     }
     if ($splitAttributes and @k) {
-        $output .= "\n"."  " x $indent;
+	$output .= "\n"."  " x $indent;
     }
     if ($selfclose) {
-        $output .= " />";
-        $lastTag = 0;
+	$output .= " />";
+	$lastTag = 0;
     } else {
-        $output .= ">";
-        $indent++;
-        $lastTag = 1;
+	$output .= ">";
+	$indent++;
+	$lastTag = 1;
     }
     $textContent = '';
 }
@@ -272,21 +273,21 @@
     my $s = shift;
 
     if($inAnnotation) {
-        if($s =~ m/(^|:)annotation$/) {
-            $inAnnotation = 0;
-        }
-        return;
+	if($s =~ m/(^|:)annotation$/) {
+	    $inAnnotation = 0;
+	}
+	return;
     }
 
     if($normaliseWhiteSpace) {
-        $textContent =~ s/^\s*(.*?)\s*$/$1/;
+	$textContent =~ s/^\s*(.*?)\s*$/$1/;
     }
     $indent--;
     printContent($textContent);
     if ($lastTag == 0) {
-        $output .= "\n";
-        $output .= "  " x $indent;
-    } 
+	$output .= "\n";
+	$output .= "  " x $indent;
+    }
     $output .= "</$s>";
     $textContent = '';
     $lastTag = 0;
@@ -317,7 +318,7 @@
 }
 
 sub parseComment {
-    my $s = shift; 
+    my $s = shift;
     if($inAnnotation) { return }
     printContent($textContent,1);
     if ($s =~ /([^\<]*)(<.*>)(.*)/ms) {
@@ -332,9 +333,9 @@
     }
     $s =~ s/\n\s*$/\n  /msg;
     if ($newLineComments) {
-        $output .= "\n<!--$s-->\n";
+	$output .= "\n<!--$s-->\n";
     } else {
-        $output .= "<!--$s-->";
+	$output .= "<!--$s-->";
     }
     $textContent='';
 }
@@ -345,16 +346,16 @@
     my ($LF,$ret) = ("","");
 
     if ($s =~ m/\n\s*$/) {
-        $LF = "\n"; 
+	$LF = "\n";
     }
     if ($s =~ m/^[\s\n]*$/) {
-        $ret = undef;
+	$ret = undef;
     } else {
-        $output .= "$s";
-        $ret = 1;
+	$output .= "$s";
+	$ret = 1;
     }
     if ($printLF) {
-        $output .= $LF;
+	$output .= $LF;
     }
 }
 
@@ -371,11 +372,11 @@
     my $filename = shift;
     $$filename = shift @ARGV;
     while ($$filename and ! -f $$filename) {
-        print STDERR "WARNING: Could not find file: $$filename\n";
-        $$filename = shift @ARGV;
+	print STDERR "WARNING: Could not find file: $$filename\n";
+	$$filename = shift @ARGV;
     }
     if(!$$filename) {
-        return undef;
+	return undef;
     }
     my $fh = new FileHandle;
     $fh->open("< $$filename") or die "Can't open $$filename: $!";




More information about the Fedora-docs-commits mailing list