Changeset 3093
- Timestamp:
- 2002-04-23T14:36:52+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/convert_toc.pl
r3092 r3093 12 12 open STDOUT, ">$ARGV[1]" or die "$ARGV[1]: $!\n"; 13 13 14 my $dirname = &File::Basename::dirname($ARGV[0]); 15 14 16 my $content = ""; 15 17 16 18 while (<STDIN>) { 17 $_ =~ s/[\cJ\cM]+$/ /;19 $_ =~ s/[\cJ\cM]+$/\n/; 18 20 $content .= $_; 19 21 } 20 22 21 23 # fix images 22 $content =~ s/<<I>>\s*(\w+\.(?:png|jpe?g|gif))\s*(.*?)<\/p>/<center><img src=\"$1\"><br>$2<\/center><\/p>\n/igs; 24 $content =~ s/<<I>>\s*(\w+\.(?:png|jpe?g|gif))\s*(.*?)<\/p>/rename_image_old($1, $2, $dirname)/iegs; 25 $content =~ s/<img\s+src=\"?(\w+\.(?:png|jpe?g|gif))\"?/rename_image($1, $dirname)/iegs; 23 26 24 # may need to rename image files if case isn't consistent25 # (i.e. collections prepared on windows may have images named26 # AAA.GIF which are linked into the HTML as aaa.gif)27 my $image_file = $1;28 my $dirname = &File::Basename::dirname($ARGV[0]);29 if (!-e "$dirname/$image_file") {30 # try all lower case31 my $image_file_new = lc($image_file);32 if (-e "$dirname/$image_file_new") {33 print STDERR "renaming $dirname/$image_file --> $dirname/$image_file_new\n";34 rename ("$dirname/$image_file", "$dirname/$image_file_new");35 } else {36 print STDERR "ERROR**** $dirname/$image_file does not exist\n";37 }38 }39 27 40 28 # process section title 41 while ($content =~ s/(?:<P[^>]*>|<BR>)(?:\s*<\/?[^>]*>)*?<<TOC(\d+)>>(.*?)(?:\s*<\/?[^>]*>)*?\s*(<\/P[^>]*>|<BR>)/process_toc ($1, $2)/sige) {} 29 $content =~ s/(?:<P[^>]*>|<BR>)(?:\s*<\/?[^>]*>)*?<<TOC(\d+)>>(.*?)(?=<\/?P[^>]*>|<BR>)/ 30 process_toc ($1, $2)/sige; 42 31 43 32 # close the remaining sections … … 47 36 } 48 37 $section_ending .= "-->\n"; 49 $content =~ s/(<\/body>)/$section_ending.$1/ ie;38 $content =~ s/(<\/body>)/$section_ending.$1/sie; 50 39 51 40 print STDOUT $content; … … 57 46 my $toc = ''; 58 47 59 $title =~ s/<[^>]+>// g;60 $title =~ s/^\s+// ;61 $title =~ s/\s+$// ;62 $title =~ s/\n/ / g;48 $title =~ s/<[^>]+>//sg; 49 $title =~ s/^\s+//s; 50 $title =~ s/\s+$//s; 51 $title =~ s/\n/ /sg; 63 52 64 53 $toc .= "\n<!--\n"; … … 80 69 } 81 70 71 sub rename_image_old { 72 my ($image_name, $following_text, $dirname) = @_; 73 74 &rename_image($image_name, $dirname); 75 76 return "<center><img src=\"$image_name\"><br>$following_text<\/center><\/p>\n"; 77 } 78 79 80 # may need to rename image files if case isn't consistent 81 # (i.e. collections prepared on windows may have images named 82 # AAA.GIF which are linked into the HTML as aaa.gif) 83 sub rename_image { 84 my ($image_name, $dirname) = @_; 85 86 if (!-e "$dirname/$image_name") { 87 88 my ($pre, $ext) = $image_name =~ /^([^\.]+)\.(.*)$/; 89 my $image_name_uc = uc($image_name); 90 my $image_name_lc = lc($image_name); 91 my $image_name_ul = uc($pre) . "." . lc($ext); 92 my $image_name_lu = lc($pre) . "." . uc($ext); 93 94 if (-e "$dirname/$image_name_uc") { 95 print STDERR "renaming $dirname/$image_name_uc --> $dirname/$image_name\n"; 96 rename ("$dirname/$image_name_uc", "$dirname/$image_name"); 97 98 } elsif (-e "$dirname/$image_name_lc") { 99 print STDERR "renaming $dirname/$image_name_lc --> $dirname/$image_name\n"; 100 rename ("$dirname/$image_name_lc", "$dirname/$image_name"); 101 102 } elsif (-e "$dirname/$image_name_ul") { 103 print STDERR "renaming $dirname/$image_name_ul --> $dirname/$image_name\n"; 104 rename ("$dirname/$image_name_ul", "$dirname/$image_name"); 105 106 } elsif (-e "$dirname/$image_name_lu") { 107 print STDERR "renaming $dirname/$image_name_lu --> $dirname/$image_name\n"; 108 rename ("$dirname/$image_name_lu", "$dirname/$image_name"); 109 110 } else { 111 print STDERR "ERROR**** $dirname/$image_name could not be found\n"; 112 } 113 } 114 return "<img src=\"$image_name\""; 115 } 116 117 118 82 119 &main;
Note:
See TracChangeset
for help on using the changeset viewer.