[LON-CAPA-cvs] cvs: modules /gerd/chm translate.pl

www lon-capa-cvs-allow@mail.lon-capa.org
Wed, 11 Apr 2007 14:08:13 -0000


www		Wed Apr 11 10:08:13 2007 EDT

  Added files:                 
    /modules/gerd/chm	translate.pl 
  Log:
  CHM Custom Translation Code Work in Progress
  
  

Index: modules/gerd/chm/translate.pl
+++ modules/gerd/chm/translate.pl
open(IN,shift);
while ($line=<IN>) {
   chomp($line);
   if ($line=~/^\d+\)\s+\[([^\]]+)\]/) {
      $newtitle=$1;
# - Anything to write out?
      if ($title) { 
         &writeout(); 
      }
      $title=$newtitle;
      ($topic)=($line=~/\s+T\:\s(\w+)\s+/i);
      $topic=~s/\_/ /g;
      ($subtopic)=($line=~/\s+ST\:\s(.+)$/);
      next;
   }
   if ($line=~/^\s+Date\(s\)\:\s+(.+)$/) {
      $prevsem=$1;
      next;
   }
   if ($line=~/^\s+Author\:\s+(.+)$/) {
      $author=$1;
      next;
   }
   if ($line=~/^\s+Difficulty\:\s+(\S+)\s+Discrimination\:\s+(.+)$/) {
      $diff=$1;
      $disc=$2;
      next;
   }
   if ($line=~/^\s+Feedback\:\s+(.*)$/) {
      $feedback=$1;
      next;
   }
   if ($line=~/^\s+Objective\:\s+(.*)$/) {
      $objective=$1;
      next;
   }
   if ($line=~/^\s+Discipline\:\s+(.*)$/) {
      $discipline=$1;
      next;
   }
   if ($line=~/^\s+Reference\:\s+(.*)$/) {
      $reference=$1;
      next;
   }
   if ($line=~/^\s+Photo File\:\s+(.*)$/) {
      $image=$1;
      next;
   }

 
}
writeout();
close(IN);

sub writeout {
    ($number,$code)=($title=~/^(\d+)(\w+)\./);
    unless (-e "translated/$code") { system("mkdir translated/$code"); }
    $title=~s/\./\_/gs;
    open(OUT,">translated/$code/$title.problem");
    print OUT "<problem>\n";
    print OUT "<meta name='title' content='$subtopic' />\n";
    print OUT "<meta name='subject' content='$topic' />\n";
    print OUT "<meta name='author' content='$author' />\n";
    print OUT "<meta name='previoussemesters' content='$prevsem' />\n";
    print OUT "<meta name='previousdifficulty' content='$diff' />\n";
    print OUT "<meta name='previousdiscrimination' content='$disc' />\n";
    if ($feedback) { print OUT "<meta name='previousfeedback' content='$feedback' />\n" };
    if ($objective) { print OUT "<meta name='objective' content='$objective' />\n" };
    if ($discipline) { print OUT "<meta name='discipline' content='$discipline' />\n" };
    if ($reference) { print OUT "<meta name='reference' content='$reference' />\n" };
    if ($image) { print OUT "<img src='$image' />\n"; }
    print OUT "</problem>\n";
}