Changeset 3093 for trunk


Ignore:
Timestamp:
2002-04-23T14:36:52+12:00 (22 years ago)
Author:
nzdl
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/convert_toc.pl

    r3092 r3093  
    1212  open STDOUT, ">$ARGV[1]" or die "$ARGV[1]: $!\n";
    1313
     14  my $dirname = &File::Basename::dirname($ARGV[0]);
     15
    1416  my $content = "";
    1517 
    1618  while (<STDIN>) {
    17     $_ =~ s/[\cJ\cM]+$//;
     19    $_ =~ s/[\cJ\cM]+$/\n/;
    1820    $content .= $_;
    1921  }
    2022
    2123  # fix images
    22   $content =~ s/&lt;&lt;I&gt;&gt;\s*(\w+\.(?:png|jpe?g|gif))\s*(.*?)<\/p>/<center><img src=\"$1\"><br>$2<\/center><\/p>\n/igs;
     24  $content =~ s/&lt;&lt;I&gt;&gt;\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;
    2326
    24   # may need to rename image files if case isn't consistent
    25   # (i.e. collections prepared on windows may have images named
    26   # 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 case
    31     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   }
    3927
    4028  # process section title
    41   while ($content =~ s/(?:<P[^>]*>|<BR>)(?:\s*<\/?[^>]*>)*?&lt;&lt;TOC(\d+)&gt;&gt;(.*?)(?:\s*<\/?[^>]*>)*?\s*(<\/P[^>]*>|<BR>)/process_toc ($1, $2)/sige) {}
     29  $content =~ s/(?:<P[^>]*>|<BR>)(?:\s*<\/?[^>]*>)*?&lt;&lt;TOC(\d+)&gt;&gt;(.*?)(?=<\/?P[^>]*>|<BR>)/
     30      process_toc ($1, $2)/sige;
    4231 
    4332  # close the remaining sections
     
    4736  }
    4837  $section_ending .= "-->\n";
    49   $content =~ s/(<\/body>)/$section_ending.$1/ie;
     38  $content =~ s/(<\/body>)/$section_ending.$1/sie;
    5039
    5140  print STDOUT $content;
     
    5746  my $toc = '';
    5847 
    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;
    6352
    6453  $toc .= "\n<!--\n";
     
    8069}
    8170
     71sub 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)
     83sub 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
    82119&main;
Note: See TracChangeset for help on using the changeset viewer.