Changeset 3081
- Timestamp:
- 2002-04-05T09:27:33+12:00 (21 years ago)
- Location:
- trunk/gsdl/bin/script
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/convert_toc.pl
r2860 r3081 4 4 # <Section> syntax (suitable for processing by HTMLPlug -description_tags 5 5 6 my $line = "";7 my $foundbody = 0;8 6 my $level = 0; 9 while (defined ($line = <STDIN>)) {10 7 11 $line =~ s/[\cJ\cM]+$//; 12 if (!$foundbody) { 13 print STDOUT "$line\n"; 14 $foundbody = 1 if ($line =~ /<body/i); 15 next; 8 sub main { 9 open STDIN, "<$ARGV[0]" or die "$ARGV[0]: $!\n"; 10 open STDOUT, ">$ARGV[1]" or die "$ARGV[1]: $!\n"; 11 12 my $content = ""; 13 14 while (<STDIN>) { 15 $_ =~ s/[\cJ\cM]+$//; 16 $content .= $_; 17 } 18 19 # fix images 20 $content =~ s/<<I>>\s*(\w+\.(?:png|jpe?g|gif))\s*(.*?)<\/p>/<center><img src=\"$1\"><br>$2<\/center><\/p>\n/igs; 21 22 # process section title 23 while ($content =~ s/(?:<P[^>]*>|<BR>)(?:\s*<\/?[^>]*>)*?<<TOC(\d+)>>(.*?)(?:\s*<\/?[^>]*>)*?\s*(<\/P[^>]*>|<BR>)/process_toc ($1, $2)/sige) {} 24 25 # close the remaining sections 26 my $section_ending = "<!--\n"; 27 for (my $j = 0; $j < $level; $j++) { 28 $section_ending .= "</Section>\n"; 29 } 30 $section_ending .= "-->\n"; 31 $content =~ s/(<\/body>)/$section_ending.$1/ie; 32 33 print STDOUT $content; 34 close STDOUT; close STDIN; 35 } 36 37 sub process_toc { 38 my ($thislevel, $title) = @_; 39 my $toc = ''; 40 41 $title =~ s/\n/ /g; 42 $title =~ s/<[^>]+>//g; 43 $title =~ s/^\s+//; 44 $title =~ s/\s+$//; 45 46 $toc .= "\n<!--\n"; 47 48 if ($thislevel <= $level) { 49 for (my $i = 0; $i < ($level-$thislevel+1); $i++) { 50 $toc .= "</Section>\n"; 16 51 } 52 } 53 $toc .= "<Section>\n". 54 " <Description>\n". 55 " <Metadata name=\"Title\">$title</Metadata>\n". 56 " </Description>\n". 57 "-->\n"; 17 58 18 # sort out the <<I>> image tags 19 $line =~ s/<<I>>\s*(\w+\.(?:png|jpe?g|gif))/<center><img src=\"$1\"><\/center><br>\n/igs; 59 $level = $thislevel; 60 61 return $toc; 62 } 20 63 21 if ($line =~ /<<TOC(\d+)>>(.*)/) { 22 my $thislevel = $1; 23 my $title = $2; 24 $title =~ s/<[^>]+>//g; 25 $title =~ s/^\s+//; 26 $title =~ s/\s+$//; 27 28 # print out any tags that were on the line 29 while ($line =~ s/(<[^>]+>)//) { 30 print STDOUT $1; 31 } 32 33 print STDOUT "\n<!--\n"; 34 35 if ($thislevel <= $level) { 36 for (my $i = 0; $i < ($level-$thislevel+1); $i++) { 37 print STDOUT "</Section>\n"; 38 } 39 } 40 print STDOUT "<Section>\n"; 41 print STDOUT " <Description>\n"; 42 print STDOUT " <Metadata name=\"Title\">$title</Metadata>\n"; 43 print STDOUT " </Description>\n"; 44 print STDOUT "-->\n"; 45 46 $level = $thislevel; 47 48 } elsif ($line =~ /<\/body>/i) { 49 $line =~ /^(.*?)(<\/body>.*)$/i; 50 print STDOUT $1 if defined $1; 51 print STDOUT "\n<!--\n"; 52 for (my $j = 0; $j < $level; $j++) { 53 print STDOUT "</Section>\n"; 54 } 55 print STDOUT "-->\n"; 56 print STDOUT $2 if defined $2; 57 print STDOUT "\n"; 58 59 } else { 60 print STDOUT "$line\n"; 61 } 62 } 64 &main; -
trunk/gsdl/bin/script/convert_toc_dir.pl
r2815 r3081 3 3 # run convert_toc.pl on any html files found in the directory passed in on 4 4 # the command line (or any subdirs). 5 6 die "\$GSDLOS not set !\n" if (!defined $ENV{GSDLOS}); 7 my ($move, $separator); 8 if ($ENV{GSDLOS} eq "windows") { 9 $move = "move"; 10 $separator = "\\"; 11 } else { 12 $move = "mv"; 13 $separator = "/"; 14 } 5 15 6 16 &recurse($ARGV[0]); … … 20 30 foreach my $file (@files) { 21 31 next if $file =~ /^\.\.?$/; 22 my $fullpath = "$dir /$file";32 my $fullpath = "$dir$separator$file"; 23 33 if (-d $fullpath) { 24 34 &recurse($fullpath); 25 35 } elsif ($file =~ /\.html?$/i) { 26 36 print STDERR "converting $fullpath\n"; 27 `convert_toc.pl < $fullpath >$fullpath.new`;28 ` mv$fullpath.new $fullpath`;37 `convert_toc.pl $fullpath $fullpath.new`; 38 `$move $fullpath.new $fullpath`; 29 39 } 30 40 }
Note:
See TracChangeset
for help on using the changeset viewer.