diff options
author | Frans Pop <elendil@planet.nl> | 2005-11-21 22:58:52 +0000 |
---|---|---|
committer | Frans Pop <elendil@planet.nl> | 2005-11-21 22:58:52 +0000 |
commit | 8047cf64f00af87fd71269d4d2c077ff0367ec3c (patch) | |
tree | 42b863a5084f61245948aaf55910b007264ae3ff /build/preseed.pl | |
parent | 039fecc0a123aa7dada004036153dfb1fd9762a5 (diff) | |
download | installation-guide-8047cf64f00af87fd71269d4d2c077ff0367ec3c.zip |
Initial version of script to parse preseeding appendix into preseed example file
Diffstat (limited to 'build/preseed.pl')
-rwxr-xr-x | build/preseed.pl | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/build/preseed.pl b/build/preseed.pl new file mode 100755 index 000000000..d3c4b6c9a --- /dev/null +++ b/build/preseed.pl @@ -0,0 +1,85 @@ +#!/usr/bin/perl -w + +# Define module to use + use HTML::Parser(); + +local %tagstatus; +local $lasttag='', $titletag; +local $settitle=0, $printexample=0, $exampleinsect=0, $newexample; +local $BOF=1; + + # Create instance + $p = HTML::Parser->new( + start_h => [\&start_rtn, 'tagname, text, attr'], + text_h => [\&text_rtn, 'text'], + end_h => [\&end_rtn, 'tagname']); + # Start parsing the following HTML string + #$p->report_tags( qw(appendix sect1 sect2 sect3 para informalexample title) ); + $p->parse_file('example-preseed-etch-new.xml'); + + sub start_rtn { + # Execute when start tag is encountered + my ($tagname, $text, $attr) = @_; + #print "\nStart: $tagname\n"; + #print "Condition: $attr->{condition}\n" if exists $attr->{condition}; + #print "Id: $attr->{id}\n" if exists $attr->{id}; + if ( $tagname =~ /appendix|sect1|sect2|sect3|para/ ) { + $tagstatus{$tagname}{'count'} += 1; + #print "$tagname $tagstatus{$tagname}{'count'}\n"; + } + if ( $lasttag =~ /sect1|sect2|sect3/ ) { + $settitle = ( $tagname eq 'title' ); + $titletag = $lasttag; + $exampleinsect=0; + } + $lasttag = $tagname; + if ( $tagname eq 'informalexample' ) { + $printexample = 1; + $newexample = 1; + } + } + + sub text_rtn { + # Execute when text is encountered + my ($text) = @_; + if ( $settitle ) { + $tagstatus{$titletag}{'title'} = $text; + $settitle = 0; + } + if ( $printexample ) { + for ($s=1; $s<=3; $s++) { + my $sect="sect$s"; + if ( $tagstatus{$sect}{'title'} ) { + print "\n" if ($s == 1 && ! $BOF); + for ($i=1; $i<=5-$s; $i++) { print "#"; }; + print " $tagstatus{$sect}{'title'}\n"; + delete $tagstatus{$sect}{'title'}; + } + } + if ( $newexample ) { + $text =~ s/^[[:space:]]*//; + } + #$text =~ s/[[:space:]]*$//; + print "$text"; + $newexample=0; $exampleinsect=1; + $BOF=0; + } + } + + sub end_rtn { + # Execute when the end tag is encountered + my ($tagname) = @_; + #print "\nEnd: $tagname\n"; + if ( $tagname =~ /appendix|sect1|sect2|sect3|para/ ) { + $tagstatus{$tagname}{'count'} -= 1; + #print "$tagname $tagstatus{$tagname}{'count'}\n"; + #print "Title: $tagstatus{$tagname}{'title'}\n" if $tagstatus{$tagname}{'title'}; + if ( $exampleinsect ) { + print "\n"; + $exampleinsect=0; + } + } + if ( $tagname eq 'informalexample' ) { + $printexample = 0; + } + } |