Subversion Repositories wimsdev

Rev

Rev 3845 | Rev 4879 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/usr/bin/perl
  2.  
  3. use locale;
  4. use warnings;
  5. use strict;
  6. ##lancer du répertoire wims : bin/oedfdoc.pl
  7.  
  8. my %name ;
  9. $name{'explanation'}{'fr'}="Explication" ;
  10. $name{'example'}{'fr'}="Exemple" ;
  11. $name{'special'}{'fr'}="Méthodes spéciales<br>(énoncé)";
  12. $name{'syntax'}{'fr'}="Syntaxe";
  13. $name{'slib'}{'fr'}='SLIB';
  14. $name{'anstype'}{'fr'}='Types de réponses' ;
  15.  
  16. $name{'explanation'}{'en'}="Explanation" ;
  17. $name{'example'}{'en'}="Example" ;
  18. $name{'special'}{'en'}="Special method<br>(statement)";
  19. $name{'syntax'}{'en'}="Syntax";
  20. $name{'slib'}{'en'}='SLIB';
  21. $name{'anstype'}{'en'}='Answer types' ;
  22.  
  23. $name{'explanation'}{'cn'}="Explanation" ;
  24. $name{'example'}{'cn'}="Example" ;
  25. $name{'special'}{'cn'}="Special method<br>(statement)";
  26. $name{'syntax'}{'cn'}="Syntax";
  27. $name{'slib'}{'cn'}='SLIB';
  28. $name{'anstype'}{'cn'}='Answer types' ;
  29.  
  30. $name{'explanation'}{'nl'}="Explanation" ;
  31. $name{'example'}{'nl'}="Example" ;
  32. $name{'special'}{'nl'}="Special method<br>(statement)";
  33. $name{'syntax'}{'nl'}="Syntax";
  34. $name{'slib'}{'nl'}='SLIB';
  35. $name{'anstype'}{'nl'}='Answer types' ;
  36.  
  37. $name{'explanation'}{'it'}="Spiegazione" ;
  38. $name{'example'}{'it'}="Esempio" ;
  39. $name{'special'}{'it'}="Metodi speciali<br>(enunciato)";
  40. $name{'syntax'}{'it'}="Sintassi";
  41. $name{'slib'}{'it'}='SLIB';
  42. $name{'anstype'}{'it'}='Tipi di risposte' ;
  43.  
  44. my $DOSSIER="public_html/scripts/js/editor/scripts_1/bd_js";
  45. my $slibdir="public_html/scripts/slib/";
  46. my $helpdir="public_html/scripts/help";
  47.  
  48. my @Lang=('en','fr','cn', 'nl','it') ;
  49.  
  50. system(`mkdir -p $DOSSIER`) ;
  51. my @table=('if', 'oefparm0', 'oefparm1', 'oefparm2', 'oefparm3', 'oefparm4', 'oefparm5','oefcommand') ;
  52.  
  53. my (%Begin, %End) ;
  54. $Begin{'if'}= "  " ;
  55. $End{'if'}= "  " ;
  56. $Begin{'oefparm0'}= '\\\\' ;
  57. $End{'oefparm0'}= "\{  =  \}" ;
  58. $Begin{'oefcommand'}= '\\\\' ;
  59. $End{'oefcommand'}= "\{  \}" ;
  60. $Begin{'anstype'}='' ;
  61. $End{'anstype'}='' ;
  62. ##$Begin{'anstype'}='\\\\answer\{  \}\{  \}\{type=' ;
  63. ##$End{'anstype'}='\}\{option=  \}\{ weight= \}\n' ;
  64. for my $tag ("oefparm4") {
  65.    $Begin{$tag}= "" ;
  66.    $End{$tag}= "\(  \)" ;
  67. }
  68. for my $tag ("oefparm2", "oefparm3") {
  69.    $Begin{$tag}= " " ;
  70.    $End{$tag}= " " ;
  71. }
  72. for my $tag ( "oefparm1") {
  73.    $Begin{$tag}= "" ;
  74.    $End{$tag}= "" ;
  75. }
  76.  
  77. for my $tag ("oefparm5") {
  78.    $Begin{$tag}= '\\\\' ;
  79.    $End{$tag}= "" ;
  80. }
  81.  
  82. $Begin{'slib'}= "slib(" ;
  83. $End{'slib'}= " )" ;
  84.  
  85. my @phtml=("expandlines", "imagefill", "help", "tabs2lines", "rename", "tooltip") ;
  86. for my $tag (@phtml) {
  87.    $Begin{$tag}= "\\special\{" ;
  88.    $End{$tag}= " \}" ;
  89. }
  90.  
  91. ##### generation
  92. for my $lang (@Lang) {
  93.    print "oefdoc.pl $lang\n" ;  system(`mkdir -p $DOSSIER/$lang`) ;
  94.    for my $t (@table) { tableau($t,$lang) ; }
  95.    phtml("$helpdir/$lang/special",$lang,"special",@phtml) ;
  96.    anstype($lang) ;
  97.    slib($lang) ;
  98. };
  99.  
  100. sub anstype { my ($lang)=@_ ;
  101.  my %HASH ;
  102.  my %HELP ;
  103.  open (IN, "$helpdir/$lang/reply.phtml") ;
  104.    while (<IN>) {my $line = $_; my @t=();
  105.     next if ($line =~ /^\!set/) ;
  106.     next if !($line) ;
  107.     if ($line =~ /\\\n/) {
  108.       my @L= split( ',', $line) ;
  109.       my $t1 = $L[0] ; $t1=~ s/\|/,/ ;
  110.       my @ta=split(',',$t1) ;
  111.       if ($ta[1]) {@t=split(' ',$ta[1]) ; } else {@t=($L[0])};
  112.       for my $tag (@t) { $HASH{$tag} = cleanup3($L[1] . ' ' . (($L[2]) ? $L[2]: '')); $HELP{$tag}=$ta[0] ;}
  113.      }
  114.    }
  115.  close IN ;
  116.  my $text ='';
  117.  my $Text = "var anstypename='$name{'anstype'}{$lang}';\n" ;
  118.    my $var=join ("$End{'anstype'}\',\'$Begin{'anstype'}", sort keys(%HASH)) ;
  119.    $Text .="var anstype = [ '$Begin{'anstype'}$var$End{'anstype'}' ];\n" ;
  120.    for my $tag (keys(%HASH)){
  121.      $text .= begin_js("$Begin{'anstype'}$tag$End{'anstype'}")
  122.            . title_js($tag,'title')
  123.            . middle_js($HASH{$tag},'out', $lang)
  124.            . end_js("<a target=\"wims_help\" href=\"wims.cgi?lang=$lang&module=adm%2Fcreatexo&modtoolhelp=yes&+special_parm=reply,$HELP{$tag}\">++>></a>") ;
  125.    }
  126.    $Text .= function_js($text,'anstype') ;
  127.   out ("$DOSSIER/$lang/anstype" . "_bd\.js", $Text) ;
  128. }
  129. sub slib {my ($lang)= @_ ;
  130.  my $Text = "var slibname='$name{'slib'}{$lang}';\n" ;
  131.  my @list_keyword=();
  132.  my %HASH ;
  133.  my $slibdirhelp="$helpdir/$lang/slib";
  134. for my $file (glob("$slibdir/*/*")) {
  135. #for example file=$slibdir/function/integrate
  136.  $file =~s/$slibdir\///;
  137.  my $text=''; my $tag='';
  138.  my $filehelp="$slibdirhelp/$file" ;
  139.  if (!open(IN, "$filehelp")) { $filehelp="$slibdirhelp/en/$file"; }
  140.  if (!open(IN, "$filehelp")) { $filehelp="$slibdir/$file"; }
  141.  for my $fff ("$slibdir/$file",$filehelp) {
  142.    open (IN, ("$fff"));
  143.    while (<IN>) {my $line=$_;
  144.     if  ($line=~/^ *!exit/) { last ;}
  145.     if ($line=~ s/^ *slib_(\w+) *=//){
  146.      $tag=$1;
  147.      $line=cleanup($line) ;
  148.      if ($tag=~/parms/) {
  149.        $line=~s/\\//;
  150.        $HASH{nbparm}{$file}=$line;
  151.      } else
  152.      {
  153.        $HASH{$tag}{$file}=$line ;
  154.      }
  155.      } else {
  156.        next if !($tag) ;
  157.        if ($tag=~/parms/) {
  158.         chomp $line ;
  159.         next if ($line) ;
  160.         my @parm=split(",", $line) ;
  161.         if (($parm[1]) && ($parm[1] =~ s/\\//)) {
  162.           $HASH{$tag}{$file}.= cleanup3($parm[1]) . ",";
  163.          }
  164.          else
  165.          {  $HASH{$tag}{$file}= (($HASH{$tag}{$file})? $HASH{$tag}{$file}:' ') . (($parm[1]) ? cleanup3($parm[1]):'') ;
  166.          }
  167.        # $HASH{$tag}{$file} .= "\[$parm[0]\]" if ($parm[0]);
  168.        }
  169.        else {
  170.          $HASH{$tag}{$file} .= cleanup($line);
  171.          $tag='' if !($line=~/\\$/) ;
  172.        }
  173.      }
  174.    }
  175.  close IN;
  176.  }
  177.   push @list_keyword, $file if ($HASH{'title'}{$file});
  178.  $tag='';
  179.  }
  180.  my $var=join ("$End{'slib'}\',\'$Begin{'slib'}", @list_keyword) ;
  181.  $Text .="var slib = [ '$Begin{'slib'}$var$End{'slib'}' ];\n" ;
  182.  my $text='' ;
  183.  for my $file (@list_keyword) {
  184.   next if !($HASH{'title'}{$file}) ;
  185.   my @examples=split("\\\\\\\\",$HASH{'example'}{$file}) if ($HASH{'example'}{$file});
  186.   my $example='';
  187.   for my $ex (@examples) {
  188.     next if !($ex) ;
  189.     $example .="<div class=\"title\">$name{'example'}{$lang}</div><code><font color=\"red\">slib($file</font> $ex <font color=\"red\">)</font></code>" ;
  190.   }
  191.  
  192.   $text.=begin_js("$Begin{'slib'}$file$End{'slib'}")
  193.            . title_js($HASH{'title'}{$file},'title')
  194.            . syntax_js("<font color=\"red\">slib($file</font> " . ($HASH{'parms'}{$file}  ? $HASH{'parms'}{$file} : '') . " <font color=\"red\">)</font>",$lang)
  195.            . middle_js($HASH{'out'}{$file},'out',$lang)
  196.            . middle1_js (cleanup($example),'',$lang)
  197.            . end_js("<a target=\"wims_help\" href=\"wims.cgi?lang=$lang&module=adm%2Fcreatexo&modtoolhelp=yes&special_parm=slib&+slibdet=$file#slib\">++>></a>") ;
  198.  $text =cleanup2($text) ;
  199.  }
  200.  $Text .= function_js($text,'slib') ;
  201.   out ("$DOSSIER/$lang/slib" . "_bd\.js",$Text) ;
  202. }
  203. ##special methode
  204. sub phtml {my ($dir,$lang,$f,@file)=@_ ;
  205.  my $cities=$f;
  206.  my %HASH = (
  207.   example       => {},
  208.   signification => {},
  209.   syntaxe => {},
  210.   ) ;
  211.  my $text='';
  212.  my $tag='';
  213.  my $Text="var specialname= '$name{'special'}{$lang}';\n";
  214.  for my $meth (@file) {
  215.     open (IN, "$dir/$meth.phtml");
  216.     while (<IN>) {my $line=$_;
  217.     next if !($line) ;
  218.     if ($line =~ /^:/) {
  219.     chomp $line;
  220.        $tag=$line; $tag=~ s/://;
  221.     }
  222.     else
  223.     {
  224.      $HASH{$tag}{$meth} .= cleanup($line) . "\\n" ;
  225.     }
  226.   }
  227. }
  228.  my $var=join (" }\', \'\\\\special{", @phtml) ;
  229.  ### cas particulier
  230.  my $meth='embed';
  231.  my $embd='\\\\embed{r  }' ;
  232.    open (IN, "$helpdir/$lang/embedans.phtml");
  233.     while (<IN>) {my $line=$_;
  234.     next if !($line) ;
  235.     if ($line =~ /^:/) {
  236.     chomp $line;
  237.        $tag=$line; $tag=~ s/://;
  238.     }
  239.     else
  240.     {
  241.      $HASH{$tag}{$meth} .= cleanup($line) . "\\n" ;
  242.     }
  243.   }
  244.   close IN ;
  245.   $Text .= "var special= [ '$embd', '\\\\special{$var }'];\n" ;
  246.   $text = begin_js("$embd")
  247.         . syntax_js("\\\\embed{r i, option }",$lang)
  248.         . (($HASH{'signification'}{$meth}) ? middle_js($HASH{'signification'}{$meth},'title',$lang) : '')
  249.         . (($HASH{'example'}{$meth}) ? middle1_js ($HASH{'example'}{$meth},'title',$lang) : '')
  250.         . end_js("") ;
  251.   ## fin cas particulier embed
  252.   for my $meth (@phtml) {
  253.    $text .= begin_js("\\\\special{$meth }")
  254.            . syntax_js("\\\\special{$meth }",$lang)
  255.            . (($HASH{'signification'}{$meth}) ? middle_js($HASH{'signification'}{$meth},'title',$lang ) : '')
  256.            . (($HASH{'example'}{$meth}) ? middle1_js ($HASH{'example'}{$meth},'title',$lang) : '')
  257.            . end_js("") ;
  258.    
  259.   }
  260.   $Text .= function_js($text,'special') ;
  261.  
  262.   out ("$DOSSIER/$lang/$f" . "_bd\.js",$Text) ;
  263.  
  264. }
  265. ##file : nom du fichier, n nombre de lignes dans chaque record
  266. sub tableau { my ($file, $lang) = @_ ;
  267. ### mettre $file à la place ensuite
  268.   my $file1="$helpdir/$lang/$file";
  269.   my $cities=$file ;
  270.   if ($file =~ /if/){ $cities .= 'f' } ;
  271.   my @list_keyword;
  272.   my $text='';
  273. ##bug s'il n'y a pas de documentation
  274.   open (IN, $file1);
  275.   my $cnt=0 ;my $nl;
  276.   my $Text = '' ;
  277.   while (<IN>) { my $line=$_;
  278.    chomp $line ;
  279.    next if !($line) ;
  280.    if ($line =~ s /^://) {
  281.      $cnt ++ ;
  282.      if ($cnt == 1 ) { $Text = "var $cities" . "name= '$line';\n ";  }
  283.      next if $cnt < 3 ;
  284.      $line =~ s/:// ;
  285.      if($text) { $text .= end_js("") ;}
  286.        if ($text) {$text .= begin_js($Begin{$file} . $line . $End{$file}) ;}
  287.         else
  288.        { $text = begin_js($Begin{$file} . $line . $End{$file}) ; };
  289.      push @list_keyword, $line;
  290.      $nl=0;
  291.      }
  292.      else  {
  293.        next if $cnt<3 ; if ($line =~ /^(\d)/) { my $arg=$1 ; next }  
  294.        $nl ++ ;
  295.        $line = cleanup($line); if ($line =~ /help=/) { $line = '' ;}
  296.        if ($nl==1 && !($file=~/oefcommand/)){
  297.          if ($line) { $text .= syntax_js($line,$lang) ; }
  298.         }
  299.         else {
  300.          if ($line) { $text .= middle_js($line,1,$lang) ;  }
  301.            }
  302.          }
  303.    }
  304.   close IN ;
  305.          $text .= end_js("") ;
  306.   my $var=join ("$End{$file}\', \'$Begin{$file}", @list_keyword) ;
  307.   $Text .="var $cities= [ \'$Begin{$file}$var$End{$file}\' ];\n"
  308.   . function_js($text,$cities) ;
  309.   out ("$DOSSIER/$lang/$cities" . "_bd\.js",$Text) ;
  310. }
  311.  
  312. sub begin_js {my ($t)= @_ ;
  313. "case \'$t\' \:\nchaine_aide="
  314. }
  315. sub syntax_js {my ($line,$lang)=@_ ;
  316.  "\'<div class=\"syntax\"><div class=\"title\">$name{'syntax'}{$lang}</div><code>$line</code></div>\'+\n"
  317. }
  318. sub middle_js {my ($line,$tag,$lang)=@_ ; if(!$line) {$line='' ;}
  319.  if ($tag) { $line="<div class=\"title\">$name{'explanation'}{$lang}</div>$line" }
  320.  "\'<div class=\"explication\">$line</div>\'+\n";
  321. }
  322.  
  323. sub middle1_js {my ($line,$tag,$lang)=@_ ;
  324.  if ($tag) { $line="<div class=\"title\">$name{'example'}{$lang}</div>$line" }
  325.  "\'<div class=\"exemple\">$line</div>\'+\n";
  326. }
  327.  
  328. sub title_js {my ($line,$tag)=@_ ;
  329.  "\'<div class=\"title\">$line</div>\'+\n";
  330. }
  331.  
  332. sub end_js {my ($text)=@_ ;
  333.   "\'$text\' ; return chaine_aide;
  334.            break;
  335.         ////******************** \n
  336.         "
  337. }
  338. sub function_js {my ($text,$tag)=@_ ;
  339.  "function $tag" . "fun(instruction){
  340.     switch(instruction)
  341.         {
  342.         $text
  343.         }
  344. }"
  345. }
  346.  
  347. sub cleanup { my ($txt)=@_ ;
  348.   return $txt if !($txt) ;
  349.   $txt=~ s/\\\b/&#92;/g ;
  350.   $txt=~ s/\\\(/&#92;(/g ;
  351.   $txt=~ s/\\\)/&#92;)/g ;
  352.   $txt=~ s,\\,\\\\,g ;
  353.   $txt=~ s/'/\\'/g ;
  354.   $txt=~ s/\n/ /g ;
  355.   return $txt ;
  356. }
  357. sub cleanup2 {my ($txt)=@_ ;
  358.   $txt=~ s/\\\\ / /g if ($txt) ;
  359.   return $txt;
  360. }
  361. sub cleanup3 {my ($txt)=@_ ;
  362.   $txt=~ s/'/\\'/g if ($txt);
  363.   return $txt;
  364. }
  365.  
  366.  
  367. sub htmltex { my ($TEXT) = @_ ;
  368. $TEXT =~ s/<tt>\\/\\ttb{/g;
  369. $TEXT =~ s/_/\\_/g;
  370. $TEXT =~ s/\^/\\^{}/g;
  371. $TEXT =~ s/\&/\\\&/g;
  372. $TEXT =~ s/<(tt)>/\\text$1\{/g;
  373. $TEXT =~ s/<(em|i)>/\\textit\{/g;
  374. $TEXT =~ s/<b>/\\textbf\{/g;
  375. $TEXT =~ s'</(b|tt|em|i)>'}'g;
  376. $TEXT =~ s/<br>/\\par /g;
  377. $TEXT =~ s/<p>/\\par /g;
  378. $TEXT =~ s/<\/p>/\\par /g;
  379. $TEXT =~ s/<ul>/\\begin{itemize}\n /g;
  380. $TEXT =~ s/<\/ul>/\\end{itemize}\n /g;
  381. $TEXT =~ s/<ol>/\\begin{enumerate}\n /g;
  382. $TEXT =~ s/<\/ol>/\\end{enumerate}\n /g;
  383. $TEXT =~ s/<li>/\\item /g;
  384. $TEXT =~ s/<\/li>/\n /g;
  385. $TEXT =~ s/<\/center>/\\end{center}\n /g;
  386. $TEXT =~ s/<center>/\\begin{center}\n /g;
  387. $TEXT =~ s/<\/center>/\n /g;
  388. $TEXT =~ s/<center>/\n /g;
  389. $TEXT =~ s/<table[^>]*>/\\begin{table}\\begin{tabular}{*{1}{p{30mm}}|*{1}{p{50mm}|}|*{1}{p{50mm}|}}\\hline /g;
  390. $TEXT =~ s/<\/table>/\\\\ \\hline \\end{tabular} \\end{table}/g;
  391. $TEXT =~ s/\$table_tr/\\\\\\hline /g;
  392. $TEXT =~ s/\$table_hdtr/\\\\ \\hline/g;
  393. $TEXT =~ s/\$table_header/\\begin{table}\\begin{tabular}{*{1}{p{30mm}}|*{1}{p{50mm}|}|*{1}{p{50mm}|}}\\hline/g ;
  394. $TEXT =~ s/\$table_end/\\end{tabular}\\end{table}/g;
  395. #$TEXT =~ s/<caption>/\\caption\{ /g;
  396. #$TEXT =~ s/<\/caption>/\}\n /g;
  397. $TEXT =~ s/<tr[^>]*>/\\\\/g;
  398. $TEXT =~ s/<\/tr>/\\\\/g;
  399. $TEXT =~ s/<(td|th) colspan=(\d)( nowrap)?>/\\multicolumn{$2}{|c|}{/g;
  400. $TEXT =~ s/<\/(td|th)>/&/g;
  401. $TEXT =~ s/<(td|th)[^>]*>/&/g;
  402. $TEXT =~ s/&&/&/g;
  403. $TEXT =~ s/\_/_/g;
  404. $TEXT =~ s/&amp;/\\&/g;
  405. $TEXT =~ s'\\\\&'\\\\'g;
  406. $TEXT =~ s/&nbsp;/ /g;
  407. $TEXT =~ s/&eacute;/é/g;
  408. $TEXT =~ s/&egrave;/è/g;
  409. $TEXT =~ s/&agrave;/à/g;
  410. $TEXT =~ s/&ecirc;/ê/g;
  411. $TEXT =~ s/&lt;/</g;
  412. $TEXT =~ s/<(H|h)3>/\\subsection{/g;
  413. $TEXT =~ s/<\/(H|h)3>/}/g;
  414. $TEXT =~ s/<(H|h)4>/\\subsubsection{/g;
  415. $TEXT =~ s/<\/(H|h)4>/}/g;
  416. $TEXT =~ s/<(H|h)2>/\\section{/g;
  417. $TEXT =~ s/<\/(H|h)2>/}/g;
  418. $TEXT =~ s/&gt;/>/g;
  419. $TEXT =~ s/\#//g;
  420. $TEXT =~ s/<hr>/\\hrule/g;
  421. $TEXT =~ s/<pre>/\\begin{verbatim}/g;
  422. $TEXT =~ s/<\/pre>/\\end{verbatim}/g;
  423. $TEXT =~ s/\n{3,}/\n\n/g;
  424. $TEXT =~ s/<a[^>]+>([^<]+)<\/a>/\\url{$1}/g;
  425.  
  426. $TEXT ;
  427. }
  428.  
  429. sub out { my ($bloc, $text) = @_ ;
  430.   open  (OUT, ">$bloc") || die "peut pas créer $bloc";
  431.   print OUT "<!-- Automatically generated by bin/oefdoc.pl -->\n" . $text ; close OUT ;
  432. }
  433.  
  434. sub sortuniq {
  435.   my $prev = "not $_[0]";
  436.   grep { $_ ne $prev && ($prev = $_, 1) } sort @_;
  437. }
  438.