[docs] xmldocs - racke modified 2 files
docs at icdevgroup.org
docs at icdevgroup.org
Wed Sep 21 08:07:26 EDT 2005
User: racke
Date: 2005-09-21 12:07:25 GMT
Modified: . Makefile
Modified: bin refs-autogen
Log:
new commandline options --validate and --skip-invalid for refs-autogen
script, requires XML::Twig
--validate validates XML chunks which helps to relate XML errors to symbols
--skip-invalid ignores invalid XML chunks for unattended builds
new Makefile variables REFS_AUTOGEN and REFS_AUTOGEN_FLAGS
Revision Changes Path
1.72 +8 -4 xmldocs/Makefile
rev 1.72, prev_rev 1.71
Index: Makefile
===================================================================
RCS file: /anon_cvs/repository/xmldocs/Makefile,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- Makefile 3 Sep 2005 17:09:47 -0000 1.71
+++ Makefile 21 Sep 2005 12:07:25 -0000 1.72
@@ -28,6 +28,10 @@
PSR = xsltproc
PSR_FLAGS = --xinclude
+# Scripts and options
+REFS_AUTOGEN = bin/refs-autogen
+REFS_AUTOGEN_FLAGS ?=
+
VPATH = guides refs howtos glossary
.SILENT:
.PHONY: all complete
@@ -239,7 +243,7 @@
# Silly, rewrite this, I forgot about $*. Or $* wouldn't help? I'm not
# willing to think about it right now.
refxmls: BOTH = --both
-refxmls: bin/refs-autogen $(foreach stype,$(SYMBOL_TYPES),refs/$(stype).xml) howtos/howtos.xml glossary/glossary.xml
+refxmls: $(REFS_AUTOGEN) $(foreach stype,$(SYMBOL_TYPES),refs/$(stype).xml) howtos/howtos.xml glossary/glossary.xml
:
$T/%.list: BNAME = $(subst $T/,,$@)
refs/%.xml: BNAME = $(subst refs/,,$@)
@@ -247,10 +251,10 @@
refs/%.xml: FNAME = $(subst .xml,,$(BNAME))
# A little 'overwork' here: we regenerate all .xml files even if just
# one file changes.
-$T/%.list refs/%.xml: $(foreach icver,$(IC_VERSIONS),cache/$(icver)/.cache.bin) $(shell find refs/ -regex '.+[^(\.xml)]$$') bin/refs-autogen
+$T/%.list refs/%.xml: $(foreach icver,$(IC_VERSIONS),cache/$(icver)/.cache.bin) $(shell find refs/ -regex '.+[^(\.xml)]$$') $(REFS_AUTOGEN)
# PEH, -g is useless since tags migrate between tag groups
- #bin/refs-autogen -g $(FNAME) -o $@ $(BOTH) $(IC_VERSIONS)
- bin/refs-autogen -o $@ $(BOTH) $(TARGET_RELEASE) $(IC_VERSIONS)
+ #$(REFS_AUTOGEN) $(REFS_AUTOGEN_FLAGS) -g $(FNAME) -o $@ $(BOTH) $(IC_VERSIONS)
+ $(REFS_AUTOGEN) $(REFS_AUTOGEN_FLAGS) -o $@ $(BOTH) $(TARGET_RELEASE) $(IC_VERSIONS)
#############################################################
1.96 +60 -1 xmldocs/bin/refs-autogen
rev 1.96, prev_rev 1.95
Index: refs-autogen
===================================================================
RCS file: /anon_cvs/repository/xmldocs/bin/refs-autogen,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- refs-autogen 7 Sep 2005 16:29:16 -0000 1.95
+++ refs-autogen 21 Sep 2005 12:07:25 -0000 1.96
@@ -43,6 +43,8 @@
my $output_spec; # 'list' produces tag list, 'xml' produces real xml source
my $output_both; # Unconditionally override $output_spec
my $no_autorefs; # Generate autorefs.ent collection of entities by default
+my $validate = 0; # Whether to validate XML chunks
+my $skip_invalid = 0; # Whether to skip invalid XML chunks
my $autopath = "docbook/autorefs.ent";
my %dups; # List of symbols names that are not unique
my $last_path; # Last version we want docs generated for (say, 5.2.0).
@@ -60,6 +62,8 @@
"both|b!" => \$output_both,
"noentities|noents!" => \$no_autorefs,
"last-path|last|lp=s" => \$last_path,
+ "validate|c!" => \$validate,
+ "skip-invalid|s" => \$skip_invalid,
)) { die "Error parsing options\n" }
# Determine which stuff to output
@@ -70,6 +74,10 @@
die "Unknown output combination '$output_spec'\n";
}
+if ($validate) {
+ require XML::Twig;
+}
+
$specific_only and $specific_only =~ s/s$//; # if user entered name in plural
@ARGV or die "Usage: $0 version[s]\n";
@@ -781,7 +789,25 @@
## Add items
for my $key (sort keys %{ $symbols{$group} }) {
- $refpage .= $symbols{$group}{$key}
+ ## Validate item
+ my ($buf, $msg);
+
+ $buf = '<!DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook-Interchange XML V4.2//EN"
+ "../docbook/docbookxi.dtd">';
+ $buf .= $symbols{$group}{$key};
+
+ if ($validate) {
+ unless (validate_xml($buf, \$msg)) {
+ if ($skip_invalid) {
+ warn "ERR: symbol ${group}::$key: $msg\n";
+ next;
+ } else {
+ die "ERR: symbol ${group}::$key: $msg\n";
+ }
+ }
+ }
+
+ $refpage .= $symbols{$group}{$key};
}
## Close up
@@ -1182,6 +1208,39 @@
} else {
return "@orig"
}
+}
+
+sub validate_xml {
+ my ($xml, $msgref) = @_;
+ my ($buf);
+
+ my $twig = new XML::Twig;
+
+ if ($twig->safe_parse($xml)) {
+ # sane XML
+ return 1;
+ }
+
+ # try to analyze error message
+ my $error = $@;
+
+ if ($error =~ /^\s+(.*?) at line (\d+), column (\d+), byte (\d+)/s) { # at(.*?)line (\d+)$/) {
+ my ($cause, $line, $col, $byte) = ($1, $2, $3, $4);
+
+ $cause = $1;
+ if ($cause eq 'undefined entity') {
+ $buf = substr($xml, $4);
+ if ($buf =~ /^&([\w_-]+);/) {
+ $$msgref = "undefined entity $1";
+ return;
+ }
+ }
+
+ $$msgref = "$cause " . substr($xml, $4, 60);
+ } else {
+ $$msgref = $error;
+ }
+ return;
}
sub O { print "@_\n"; print STDOUT "@_\n" if $verbose }
More information about the docs
mailing list