diff options
author | Frans Pop <elendil@planet.nl> | 2005-11-22 19:59:59 +0000 |
---|---|---|
committer | Frans Pop <elendil@planet.nl> | 2005-11-22 19:59:59 +0000 |
commit | 0562e552024aa07cd1b26e0d3467318db7764fa1 (patch) | |
tree | 93c908fa776dbbcd848ced2d7247a91d4be78de8 /build | |
parent | 0cb99b46d3885a68363aa0f9cbfea0cb9835a017 (diff) | |
download | installation-guide-0562e552024aa07cd1b26e0d3467318db7764fa1.zip |
Major whitespace cleanup; some minor code changes
Diffstat (limited to 'build')
-rwxr-xr-x | build/preseed.pl | 156 |
1 files changed, 83 insertions, 73 deletions
diff --git a/build/preseed.pl b/build/preseed.pl index d3c4b6c9a..e39ea208b 100755 --- a/build/preseed.pl +++ b/build/preseed.pl @@ -1,85 +1,95 @@ #!/usr/bin/perl -w # Define module to use - use HTML::Parser(); +use HTML::Parser(); local %tagstatus; -local $lasttag='', $titletag; -local $settitle=0, $printexample=0, $exampleinsect=0, $newexample; -local $BOF=1; +local %example; +local $prevtag='', $titletag; +local $settitle=0; - # 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'); +$example{'print'} = 0; +$example{'in_sect'} = 0; +$example{'first'} = 1; +$example{'new'} = 0; + +# 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->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; - } - } +# Execute when start tag is encountered +sub start_rtn { + my ($tagname, $text, $attr) = @_; + #print "\nStart: $tagname\n"; + #print "Condition: $attr->{condition}\n" if exists $attr->{condition}; + #print "Architecture: $attr->{arch}\n" if exists $attr->{arch}; + if ( $tagname =~ /appendix|sect1|sect2|sect3|para/ ) { + $tagstatus{$tagname}{'count'} += 1; + #print "$tagname $tagstatus{$tagname}{'count'}\n"; + } + # Assumes that <title> is the first tag after a section tag + if ( $prevtag =~ /sect1|sect2|sect3/ ) { + $settitle = ( $tagname eq 'title' ); + $titletag = $prevtag; + $example{'in_sect'} = 0; + } + $prevtag = $tagname; + if ( $tagname eq 'informalexample' ) { + $example{'print'} = 1; + $example{'new'} = 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'}; - } +# Execute when text is encountered +sub text_rtn { +my ($text) = @_; + if ( $settitle ) { + $tagstatus{$titletag}{'title'} = $text; + $settitle = 0; } - if ( $newexample ) { - $text =~ s/^[[:space:]]*//; + if ( $example{'print'} ) { + # Print section headers + for ($s=1; $s<=3; $s++) { + my $sect="sect$s"; + if ( $tagstatus{$sect}{'title'} ) { + print "\n" if ( $s == 1 && ! $example{'first'} ); + for ( $i = 1; $i <= 5 - $s; $i++ ) { print "#"; }; + print " $tagstatus{$sect}{'title'}\n"; + delete $tagstatus{$sect}{'title'}; + } + } + + # Clean leading whitespace + if ( $example{'new'} ) { + $text =~ s/^[[:space:]]*//; + } + + print "$text"; + + $example{'first'} = 0; + $example{'new'} = 0; + $example{'in_sect'} = 1; } - #$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; +# Execute when the end tag is encountered +sub end_rtn { + my ($tagname) = @_; + #print "\nEnd: $tagname\n"; + if ( $tagname eq 'informalexample' ) { + $example{'print'} = 0; + } + if ( $tagname =~ /appendix|sect1|sect2|sect3|para/ ) { + delete $tagstatus{$tagname}{'title'} if exists $tagstatus{$tagname}{'title'}; + if ( $example{'in_sect'} ) { + print "\n"; + $example{'in_sect'} = 0; + } + $tagstatus{$tagname}{'count'} -= 1; + #print "$tagname $tagstatus{$tagname}{'count'}\n"; } - } - if ( $tagname eq 'informalexample' ) { - $printexample = 0; - } - } +} |