Changeset 3081 for trunk


Ignore:
Timestamp:
2002-04-05T09:27:33+12:00 (22 years ago)
Author:
sjboddie
Message:

* empty log message *

Location:
trunk/gsdl/bin/script
Files:
2 edited

Legend:

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

    r2860 r3081  
    44# <Section> syntax (suitable for processing by HTMLPlug -description_tags
    55
    6 my $line = "";
    7 my $foundbody = 0;
    86my $level = 0;
    9 while (defined ($line = <STDIN>)) {
    107
    11     $line =~ s/[\cJ\cM]+$//;
    12     if (!$foundbody) {
    13     print STDOUT "$line\n";
    14     $foundbody = 1 if ($line =~ /<body/i);
    15     next;
     8sub 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/&lt;&lt;I&gt;&gt;\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*<\/?[^>]*>)*?&lt;&lt;TOC(\d+)&gt;&gt;(.*?)(?:\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
     37sub 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";
    1651    }
     52  }
     53  $toc .= "<Section>\n".
     54    "  <Description>\n".
     55    "    <Metadata name=\"Title\">$title</Metadata>\n".
     56    "  </Description>\n".
     57    "-->\n";
    1758
    18     # sort out the <<I>> image tags
    19     $line =~ s/&lt;&lt;I&gt;&gt;\s*(\w+\.(?:png|jpe?g|gif))/<center><img src=\"$1\"><\/center><br>\n/igs;
     59  $level = $thislevel;
     60 
     61  return $toc;
     62}
    2063
    21     if ($line =~ /&lt;&lt;TOC(\d+)&gt;&gt;(.*)/) {
    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  
    33# run convert_toc.pl on any html files found in the directory passed in on
    44# the command line (or any subdirs).
     5
     6die "\$GSDLOS not set !\n" if (!defined $ENV{GSDLOS});
     7my ($move, $separator);
     8if ($ENV{GSDLOS} eq "windows") {
     9  $move = "move";
     10  $separator = "\\";
     11} else {
     12  $move = "mv";
     13  $separator = "/";
     14}
    515
    616&recurse($ARGV[0]);
     
    2030    foreach my $file (@files) {
    2131    next if $file =~ /^\.\.?$/;
    22     my $fullpath = "$dir/$file";
     32    my $fullpath = "$dir$separator$file";
    2333    if (-d $fullpath) {
    2434        &recurse($fullpath);
    2535    } elsif ($file =~ /\.html?$/i) {
    2636        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`;
    2939    }
    3040    }
Note: See TracChangeset for help on using the changeset viewer.