Subversion Repositories wimsdev

Rev

Rev 8792 | Rev 11510 | 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. ### for "editor"
  9. my %name ;
  10. $name{'explanation'}{'fr'}="Explication" ;
  11. $name{'example'}{'fr'}="Exemple" ;
  12. $name{'special'}{'fr'}="Méthodes spéciales<br>(énoncé)";
  13. $name{'syntax'}{'fr'}="Syntaxe";
  14. $name{'slib'}{'fr'}='SLIB';
  15. $name{'anstype'}{'fr'}='Types de réponses' ;
  16.  
  17. $name{'explanation'}{'en'}="Explanation" ;
  18. $name{'example'}{'en'}="Example" ;
  19. $name{'special'}{'en'}="Special method<br>(statement)";
  20. $name{'syntax'}{'en'}="Syntax";
  21. $name{'slib'}{'en'}='SLIB';
  22. $name{'anstype'}{'en'}='Answer types' ;
  23.  
  24. $name{'explanation'}{'cn'}="Explanation" ;
  25. $name{'example'}{'cn'}="Example" ;
  26. $name{'special'}{'cn'}="Special method<br>(statement)";
  27. $name{'syntax'}{'cn'}="Syntax";
  28. $name{'slib'}{'cn'}='SLIB';
  29. $name{'anstype'}{'cn'}='Answer types' ;
  30.  
  31. $name{'explanation'}{'nl'}="Explanation" ;
  32. $name{'example'}{'nl'}="Example" ;
  33. $name{'special'}{'nl'}="Special method<br>(statement)";
  34. $name{'syntax'}{'nl'}="Syntax";
  35. $name{'slib'}{'nl'}='SLIB';
  36. $name{'anstype'}{'nl'}='Answer types' ;
  37.  
  38. $name{'explanation'}{'it'}="Spiegazione" ;
  39. $name{'example'}{'it'}="Esempio" ;
  40. $name{'special'}{'it'}="Metodi speciali<br>(enunciato)";
  41. $name{'syntax'}{'it'}="Sintassi";
  42. $name{'slib'}{'it'}='SLIB';
  43. $name{'anstype'}{'it'}='Tipi di risposte' ;
  44.  
  45. $name{'explanation'}{'ca'}="Explicació" ;
  46. $name{'example'}{'ca'}="Exemple" ;
  47. $name{'special'}{'ca'}="Mètodes especials<br>(enunciat)";
  48. $name{'syntax'}{'ca'}="Sintaxi";
  49. $name{'slib'}{'ca'}='SLIB';
  50. $name{'anstype'}{'ca'}='Tipus de Respostes' ;
  51.  
  52. my $DOSSIER="public_html/scripts/js/editor/scripts_1/bd_js";
  53. my $DOSSIER_edit_area="public_html/scripts/js/edit_area/reg_syntax";
  54. my $DOSSIER_wims="public_html/modules/help/wimsdoc.en/cmd/";
  55. my $slibdir="public_html/scripts/slib/";
  56. my $helpdir="public_html/scripts/help";
  57.  
  58. my @Lang=('en','fr','cn','nl','it','ca') ;
  59.  
  60. system(`mkdir -p $DOSSIER`) ;
  61. my @table=('if', 'oefparm0', 'oefparm1', 'oefparm2', 'oefparm3', 'oefparm4', 'oefparm5','oefcommand') ;
  62.  
  63. ### for "editor"
  64. my (%Begin, %End) ;
  65. $Begin{'if'}= "  " ;
  66. $End{'if'}= "  " ;
  67. $Begin{'oefparm0'}= '\\\\' ;
  68. $End{'oefparm0'}= "\{  =  \}" ;
  69. $Begin{'oefcommand'}= '\\\\' ;
  70. $End{'oefcommand'}= "\{  \}" ;
  71. $Begin{'anstype'}='' ;
  72. $End{'anstype'}='' ;
  73. ##$Begin{'anstype'}='\\\\answer\{  \}\{  \}\{type=' ;
  74. ##$End{'anstype'}='\}\{option=  \}\{ weight= \}\n' ;
  75. for my $tag ("oefparm4") {
  76.    $Begin{$tag}= "" ;
  77.    $End{$tag}= "\(  \)" ;
  78. }
  79. for my $tag ("oefparm2", "oefparm3") {
  80.    $Begin{$tag}= " " ;
  81.    $End{$tag}= " " ;
  82. }
  83. for my $tag ( "oefparm1") {
  84.    $Begin{$tag}= "" ;
  85.    $End{$tag}= "" ;
  86. }
  87.  
  88. for my $tag ("oefparm5") {
  89.    $Begin{$tag}= '\\\\' ;
  90.    $End{$tag}= "" ;
  91. }
  92.  
  93. $Begin{'slib'}= "slib(" ;
  94. $End{'slib'}= " )" ;
  95.  
  96. my @phtml=("expandlines", "imagefill", "help", "tabs2lines", "rename", "tooltip", "codeinput", "imageinput", "mathmlinput", "drawinput") ;
  97. for my $tag (@phtml) {
  98.    $Begin{$tag}= "\\special\{" ;
  99.    $End{$tag}= " \}" ;
  100. }
  101. ### end for "editor"
  102. ### begin for "edit area"
  103. my $EDIT_AERA_OEF_begin = "editAreaLoader.load_syntax['wimsoef'] = {
  104.    'QUOTEMARKS' : {1: ' \" '}
  105.         ,'KEYWORD_CASE_SENSITIVE' : true
  106.         ,\'KEYWORDS\' : {" ;
  107. my $EDIT_AERA_begin = "editAreaLoader.load_syntax['wims'] = {
  108.    'QUOTEMARKS' : {1: ' \" '}
  109.         ,'KEYWORD_CASE_SENSITIVE' : true
  110.         ,\'KEYWORDS\' : {" ;
  111. my $EDIT_AERA_OEF_end = "}
  112.         ,'OPERATORS' : [
  113.                 '*', '+', '-', '/', '^', ':=', '<', '=', '>','..'
  114.         ]
  115.         ,'DELIMITERS' : [
  116.                 '(', ')', '[', ']','{','}','??','??'
  117.         ]
  118.         ,'REGEXPS' :
  119.         {
  120.                 'oefvariables' : { 'search': '()(\\\\\\\\\\\\w+)()',
  121.                         'class' : 'oefvariables',
  122.                         'modifiers' : 'g', 'execute' : 'after' },
  123.                 'record' : { 'search': '(\\n)(:)()',
  124.                         'class' : 'record',
  125.                         'modifiers' : 'g', 'execute' : 'after' },
  126.                 'question' : { 'search': '(\\\\?\\\\?)([^\\\\?]+)(\\\\?\\\\?)',
  127.                         'class' : 'question',
  128.                         'modifiers' : 'g', 'execute' : 'before' }
  129.         }
  130.         ,'STYLES' : {
  131.                 'COMMENTS': 'color: #0000CD;'
  132.                 ,'QUOTESMARKS': 'color: #6381F8;'
  133.                 ,'KEYWORDS' : {
  134.                         'oefcommand' : 'color: #FF9933;'
  135.                         ,'oefparm0' : 'color: #FF9933;'
  136.                         ,'oefparm1' : 'color: #985717;'
  137.                         ,'oefparm2' : 'color: #336600;'
  138.                         ,'oefparm3' : 'color: #336600;'
  139.                         ,'oefparm4' : 'color: #3399FF;'
  140.                         ,'oefparm5' : 'color: #330099;'
  141.                         ,'iff' : 'color: #FF00FF;'
  142.                         ,'slib' : 'color: #60CA33;'
  143.                         ,'anstype' : 'color: #3399FF;'
  144.                         ,'special' : 'color: #3399FF;'
  145.                         }
  146.                 ,'OPERATORS' : 'color: #FF00FF;'
  147.                 ,'DELIMITERS' : 'color: #60CA00;'
  148.                 ,'REGEXPS': {
  149.                         'oefvariables' : 'color: #FF3A6E;'
  150.                         ,'question' : 'color:#985717;'
  151.                 }
  152.         }
  153. };" ;
  154. my $EDIT_AERA_end = "}
  155.         ,'OPERATORS' :[
  156.                 '*', '+', '-', '/', '^', ':=', '<', '=', '>','//','\$'
  157.         ]
  158.         ,'DELIMITERS' :[
  159.                 '(', ')', '[', ']','{','}','\\(', '\\)','??','??'
  160.         ],
  161.         'REGEXPS' :
  162.         {
  163.                 'wimsvariables' : { 'search': '(\\\\\$)([a-zA-Z0-9_]*)()',
  164.                         'class' : 'wimsvariables',
  165.                         'modifiers' : 'g', 'execute' : 'before' },
  166.                 'record' : { 'search': '(\\n)(:)()',
  167.                         'class' : 'record',
  168.                         'modifiers' : 'g', 'execute' : 'after' },
  169.         }
  170.         ,'STYLES' : {
  171.                 'COMMENTS': 'color: #AAAAAA;'
  172.                 ,'QUOTESMARKS': 'color: #6381F8;'
  173.                 ,'KEYWORDS' : {
  174.                         'wimscommand' : 'color: #3399FF;'
  175.                         ,'compare' : 'color: #FF00FF;'
  176.                         ,'wimslogiciel' : 'color: yellow;'
  177.                         }
  178.                 ,'OPERATORS' : 'color: green;'
  179.                 ,'DELIMITERS' : 'color: #60CA00;',
  180.                 'REGEXPS': {
  181.                         'wimsvariables' : 'color: #FF3A6E;'
  182.                         ,'tex' : 'color:red;'
  183.                 }
  184.         }
  185. };" ;
  186. ### end for "editarea"
  187. ##### generation
  188.  
  189. my $debut_oef=1;
  190. my $debut_wims=1;
  191. my $EDIT_AERA_OEF=$EDIT_AERA_OEF_begin ;
  192. my $EDIT_AERA=$EDIT_AERA_begin ;
  193.  
  194. for my $lang (@Lang) {
  195.    print "oefdoc.pl $lang\n" ;  system(`mkdir -p $DOSSIER/$lang`) ;
  196.    slib($lang) ;
  197.    for my $t (@table) { tableau($t,$lang) ; }
  198.    phtml("$helpdir/$lang/special",$lang,"special",@phtml) ;
  199.    $EDIT_AERA_OEF .= "\n, \'special\' : \n[ \'\\embed\', \'\\special{" . join ("\', '\\special{", @phtml) . "\']" if ($lang =~ /en/) ;
  200.    anstype($lang) ;
  201.  
  202. };
  203. $EDIT_AERA_OEF .=$EDIT_AERA_OEF_end ;
  204. if ($debut_wims==1) {$EDIT_AERA .= "\n" ; $debut_wims=0 } else {$EDIT_AERA .= "\n," };
  205. $EDIT_AERA .= " \'wimscommand' : \n[ \' " . join ("\', \'", wimscommand($DOSSIER_wims)) . "']";
  206.  
  207. $EDIT_AERA .=$EDIT_AERA_end ;
  208. out( "$DOSSIER_edit_area/wimsoef.js",  $EDIT_AERA_OEF) ;
  209. out( "$DOSSIER_edit_area/wims.js",  $EDIT_AERA) ;
  210.  
  211. sub anstype { my ($lang)=@_ ;
  212.  my %HASH ;
  213.  my %HELP ;
  214.  open (IN, "$helpdir/$lang/reply.phtml") ;
  215.    while (<IN>) {my $line = $_; my @t=();
  216.     next if ($line =~ /^\!set/) ;
  217.     next if !($line) ;
  218.     if ($line =~ /\\\n/) {
  219.       my @L= split( ',', $line) ;
  220.       my $t1 = $L[0] ; $t1=~ s/\|/,/ ;
  221.       my @ta=split(',',$t1) ;
  222.       if ($ta[1]) {@t=split(' ',$ta[1]) ; } else {@t=($L[0])};
  223.       for my $tag (@t) { $HASH{$tag} = cleanup3($L[1] . ' ' . (($L[2]) ? $L[2]: '')); $HELP{$tag}=$ta[0] ;}
  224.      }
  225.    }
  226.  close IN ;
  227.  my $text ='';
  228.  my $Text = "var anstypename='$name{'anstype'}{$lang}';\n" ;
  229.    my $var=join ("$End{'anstype'}\',\'$Begin{'anstype'}", sort keys(%HASH)) ;
  230.    $Text .="var anstype = [ '$Begin{'anstype'}$var$End{'anstype'}' ];\n" ;
  231.    for my $tag (keys(%HASH)){
  232.      $text .= begin_js("$Begin{'anstype'}$tag$End{'anstype'}")
  233.            . title_js($tag,'title')
  234.            . middle_js($HASH{$tag},'out', $lang)
  235.            . end_js("<a target=\"wims_help\" href=\"wims.cgi?lang=$lang&module=adm%2Fcreatexo&modtoolhelp=yes&+special_parm=reply,$HELP{$tag}\">++>></a>") ;
  236.    }
  237.    $Text .= function_js($text,'anstype') ;
  238.    $EDIT_AERA_OEF .= "\n, \'anstype\' : \n[ \' type=" . join ("\', 'type=", sort keys(%HASH)) . "\']"  if $lang=~/en/ ;
  239.    out ("$DOSSIER/$lang/anstype" . "_bd\.js", $Text) ;
  240.  
  241. }
  242.  
  243. sub slib {my ($lang)= @_ ;
  244.  my $Text = "var slibname='$name{'slib'}{$lang}';\n" ;
  245.  my @list_keyword=();
  246.  my %HASH ;
  247.  my $slibdirhelp="$helpdir/$lang/slib";
  248. for my $file (glob("$slibdir/*/*")) {
  249. #for example file=$slibdir/function/integrate
  250.  $file =~s/$slibdir\///;
  251.  my $text=''; my $tag='';
  252.  my $filehelp="$slibdirhelp/$file" ;
  253.  if (!open(IN, "$filehelp")) { $filehelp="$slibdirhelp/en/$file"; }
  254.  if (!open(IN, "$filehelp")) { $filehelp="$slibdir/$file"; }
  255.  for my $fff ("$slibdir/$file",$filehelp) {
  256.    open (IN, ("$fff"));
  257.    while (<IN>) {my $line=$_;
  258.     if  ($line=~/^ *!exit/) { last ;}
  259.     if ($line=~ s/^ *slib_(\w+) *=//){
  260.      $tag=$1;
  261.      $line=cleanup($line) ;
  262.      if ($tag=~/parms/) {
  263.        $line=~s/\\//;
  264.        $HASH{nbparm}{$file}=$line;
  265.      } else
  266.      {
  267.        $HASH{$tag}{$file}=$line ;
  268.      }
  269.      } else {
  270.        next if !($tag) ;
  271.        if ($tag=~/parms/) {
  272.         chomp $line ;
  273.         next if ($line) ;
  274.         my @parm=split(",", $line) ;
  275.         if (($parm[1]) && ($parm[1] =~ s/\\//)) {
  276.           $HASH{$tag}{$file}.= cleanup3($parm[1]) . ",";
  277.          }
  278.          else
  279.          {  $HASH{$tag}{$file}= (($HASH{$tag}{$file})? $HASH{$tag}{$file}:' ') . (($parm[1]) ? cleanup3($parm[1]):'') ;
  280.          }
  281.        # $HASH{$tag}{$file} .= "\[$parm[0]\]" if ($parm[0]);
  282.        }
  283.        else {
  284.          $HASH{$tag}{$file} .= cleanup($line);
  285.          $tag='' if !($line=~/\\$/) ;
  286.        }
  287.      }
  288.    }
  289.  close IN;
  290.  }
  291.   push @list_keyword, $file if ($HASH{'title'}{$file});
  292.  $tag='';
  293.  }
  294.  my $var=join ("$End{'slib'}\',\'$Begin{'slib'}", @list_keyword) ;
  295.  $Text .="var slib = [ '$Begin{'slib'}$var$End{'slib'}' ];\n" ;
  296.  my $text='' ;
  297.  for my $file (@list_keyword) {
  298.   next if !($HASH{'title'}{$file}) ;
  299.   my @examples=split("\\\\\\\\",$HASH{'example'}{$file}) if ($HASH{'example'}{$file});
  300.   my $example='';
  301.   for my $ex (@examples) {
  302.     next if !($ex) ;
  303.     $example .="<div class=\"title\">$name{'example'}{$lang}</div><code><font color=\"red\">slib($file</font> $ex <font color=\"red\">)</font></code>" ;
  304.   }
  305.  
  306.   $text.=begin_js("$Begin{'slib'}$file$End{'slib'}")
  307.            . title_js($HASH{'title'}{$file},'title')
  308.            . syntax_js("<font color=\"red\">slib($file</font> " . ($HASH{'parms'}{$file}  ? $HASH{'parms'}{$file} : '') . " <font color=\"red\">)</font>",$lang)
  309.            . middle_js($HASH{'out'}{$file},'out',$lang)
  310.            . middle1_js (cleanup($example),'',$lang)
  311.            . end_js("<a target=\"wims_help\" href=\"wims.cgi?lang=$lang&module=adm%2Fcreatexo&modtoolhelp=yes&special_parm=slib&+slibdet=$file#slib\">++>></a>") ;
  312.  $text =cleanup2($text) ;
  313.  }
  314.  $Text .= function_js($text,'slib') ;
  315.   out ("$DOSSIER/$lang/slib" . "_bd\.js",$Text) ;
  316.   if ($lang=~/en/) {
  317.     if ($debut_oef==1) { $EDIT_AERA_OEF .= "\n" ; $debut_oef=0 } else {$EDIT_AERA_OEF .= "\n," };
  318.   $EDIT_AERA_OEF .= "\'slib\' : \n[ \'" . join ("\', '", @list_keyword) . "\']"   ;
  319.   }
  320. }
  321. ##special methode
  322. sub phtml {my ($dir,$lang,$f,@file)=@_ ;
  323.  my $cities=$f;
  324.  my %HASH = (
  325.   example       => {},
  326.   signification => {},
  327.   syntaxe => {},
  328.   ) ;
  329.  my $text='';
  330.  my $tag='';
  331.  my $Text="var specialname= '$name{'special'}{$lang}';\n";
  332.  for my $meth (@file) {
  333.   #print $meth . "\n";
  334.     open (IN, "$dir/$meth.phtml");
  335.     while (<IN>) {my $line=$_;
  336.     next if !($line) ;
  337.     if ($line =~ /^:/) {
  338.     chomp $line;
  339.        $tag=$line; $tag=~ s/://;
  340.     }
  341.     else
  342.     {
  343.      $HASH{$tag}{$meth} .= cleanup($line) . "\\n" ;
  344.     }
  345.   }
  346. }
  347.  my $var=join (" }\', \'\\\\special{", @phtml) ;
  348.  ### cas particulier
  349.  my $meth='embed';
  350.  my $embd='\\\\embed{r  }' ;
  351.    open (IN, "$helpdir/$lang/embedans.phtml");
  352.     while (<IN>) {my $line=$_;
  353.     next if !($line) ;
  354.     if ($line =~ /^:/) {
  355.     chomp $line;
  356.        $tag=$line; $tag=~ s/://;
  357.     }
  358.     else
  359.     {
  360.      $HASH{$tag}{$meth} .= cleanup($line) . "\\n" ;
  361.     }
  362.   }
  363.   close IN ;
  364.   $Text .= "var special= [ '$embd', '\\\\special{$var }'];\n" ;
  365.   $text = begin_js("$embd")
  366.         . syntax_js("\\\\embed{r i, option }",$lang)
  367.         . (($HASH{'signification'}{$meth}) ? middle_js($HASH{'signification'}{$meth},'title',$lang) : '')
  368.         . (($HASH{'example'}{$meth}) ? middle1_js ($HASH{'example'}{$meth},'title',$lang) : '')
  369.         . end_js("") ;
  370.   ## fin cas particulier embed
  371.   for my $meth (@phtml) {
  372.    $text .= begin_js("\\\\special{$meth }")
  373.            . syntax_js("\\\\special{$meth }",$lang)
  374.            . (($HASH{'signification'}{$meth}) ? middle_js($HASH{'signification'}{$meth},'title',$lang ) : '')
  375.            . (($HASH{'example'}{$meth}) ? middle1_js ($HASH{'example'}{$meth},'title',$lang) : '')
  376.            . end_js("") ;
  377.  
  378.   }
  379.   $Text .= function_js($text,'special') ;
  380.   out ("$DOSSIER/$lang/$f" . "_bd\.js",$Text) ;
  381.  
  382. }
  383. ##file : nom du fichier, n nombre de lignes dans chaque record
  384. sub tableau { my ($file, $lang) = @_ ;
  385. ### mettre $file à la place ensuite
  386.   my $file1="$helpdir/$lang/$file";
  387.   my $cities=$file ;
  388.   if ($file =~ /if/){ $cities .= 'f' } ;
  389.   my @list_keyword;
  390.   my @List_keyword;
  391.   my $text='';
  392. ##bug s'il n'y a pas de documentation
  393.   open (IN, $file1);
  394.   my $cnt=0 ;my $nl;
  395.   my $Text = '' ;
  396.   while (<IN>) { my $line=$_;
  397.    chomp $line ;
  398.    next if !($line) ;
  399.    if ($line =~ s /^://) {
  400.      $cnt ++ ;
  401.      if ($cnt == 1 ) { $Text = "var $cities" . "name= '$line';\n ";  }
  402.      next if $cnt < 3 ;
  403.      $line =~ s/:// ;
  404.      if($text) { $text .= end_js("") ;}
  405.        if ($text) {$text .= begin_js($Begin{$file} . $line . $End{$file}) ;}
  406.         else
  407.        { $text = begin_js($Begin{$file} . $line . $End{$file}) ; };
  408.      push @list_keyword, $line;
  409.      $line =~ s/(\(|\)|\.|,|\[|\]| )//g ;
  410.      push @List_keyword, $line;
  411.      $nl=0;
  412.      }
  413.      else  {
  414.        next if $cnt<3 ; if ($line =~ /^(\d)/) { my $arg=$1 ; next }
  415.        $nl ++ ;
  416.        $line = cleanup($line); if ($line =~ /help=/) { $line = '' ;}
  417.        if ($nl==1 && !($file=~/oefcommand/)){
  418.          if ($line) { $text .= syntax_js($line,$lang) ; }
  419.         }
  420.         else {
  421.          if ($line) { $text .= middle_js($line,1,$lang) ;  }
  422.            }
  423.          }
  424.    }
  425.   close IN ;
  426.          $text .= end_js("") ;
  427.   my $var=join ("$End{$file}\', \'$Begin{$file}", @list_keyword) ;
  428.   $Text .="var $cities= [ \'$Begin{$file}$var$End{$file}\' ];\n"
  429.   . function_js($text,$cities) ;
  430.   out ("$DOSSIER/$lang/$cities" . "_bd\.js",$Text) ;
  431.    if ($lang=~/en/){
  432.      if ($debut_oef==1) { $EDIT_AERA_OEF .= "\n" ; $debut_oef=0 } else {$EDIT_AERA_OEF .= "\n," };
  433.      $EDIT_AERA_OEF .= " \'$cities\' : \n[ \'" . join ("\', '", @List_keyword) . "\']" ;
  434.      if ($cities=~ /(iff|oefparm4)/) {
  435.        if ($debut_wims==1) {$EDIT_AERA .= "\n" ; $debut_wims=0 } else {$EDIT_AERA .= "\n," };
  436.        push @List_keyword, ('or', 'and') ;
  437.        $EDIT_AERA .= " \'compare\' : \n[ \'" . join ("\', '", @List_keyword) . "\']"  ;
  438.      }
  439.   }
  440. }
  441.  
  442. sub wimscommand { my ($d) = @_;
  443.   my @wimslist = () ;
  444.   for my $file (glob("$d/*")) {
  445.     $file =~ s,$d/,, ;
  446.     $file =~ s,.phtml,, ;
  447.     push @wimslist, $file ;
  448.   }
  449.   push @wimslist, ("endif","next","else") ;
  450.   @wimslist ;
  451. }
  452. ### subroutine for "editor"
  453. sub begin_js {my ($t)= @_ ;
  454. "case \'$t\' \:\nchaine_aide="
  455. }
  456. sub syntax_js {my ($line,$lang)=@_ ;
  457.  "\'<div class=\"syntax\"><div class=\"title\">$name{'syntax'}{$lang}</div><code>$line</code></div>\'+\n"
  458. }
  459. sub middle_js {my ($line,$tag,$lang)=@_ ; if(!$line) {$line='' ;}
  460.  if ($tag) { $line="<div class=\"title\">$name{'explanation'}{$lang}</div>$line" }
  461.  "\'<div class=\"explication\">$line</div>\'+\n";
  462. }
  463.  
  464. sub middle1_js {my ($line,$tag,$lang)=@_ ;
  465.  if ($tag) { $line="<div class=\"title\">$name{'example'}{$lang}</div>$line" }
  466.  "\'<div class=\"exemple\">$line</div>\'+\n";
  467. }
  468.  
  469. sub title_js {my ($line,$tag)=@_ ;
  470.  "\'<div class=\"title\">$line</div>\'+\n";
  471. }
  472.  
  473. sub end_js {my ($text)=@_ ;
  474.   "\'$text\' ; return chaine_aide;
  475.            break;
  476.         ////******************** \n
  477.         "
  478. }
  479. sub function_js {my ($text,$tag)=@_ ;
  480.  "function $tag" . "fun(instruction){
  481.     switch(instruction)
  482.         {
  483.         $text
  484.         }
  485. }"
  486. }
  487.  
  488. sub cleanup { my ($txt)=@_ ;
  489.   return $txt if !($txt) ;
  490.   $txt=~ s/\\\b/&#92;/g ;
  491.   $txt=~ s/\\\(/&#92;(/g ;
  492.   $txt=~ s/\\\)/&#92;)/g ;
  493.   $txt=~ s,\\,\\\\,g ;
  494.   $txt=~ s/'/\\'/g ;
  495.   $txt=~ s/\n/ /g ;
  496.   return $txt ;
  497. }
  498. sub cleanup2 {my ($txt)=@_ ;
  499.   $txt=~ s/\\\\ / /g if ($txt) ;
  500.   return $txt;
  501. }
  502. sub cleanup3 {my ($txt)=@_ ;
  503.   $txt=~ s/'/\\'/g if ($txt);
  504.   return $txt;
  505. }
  506.  
  507.  
  508. sub htmltex { my ($TEXT) = @_ ;
  509. $TEXT =~ s/<tt>\\/\\ttb{/g;
  510. $TEXT =~ s/_/\\_/g;
  511. $TEXT =~ s/\^/\\^{}/g;
  512. $TEXT =~ s/\&/\\\&/g;
  513. $TEXT =~ s/<(tt)>/\\text$1\{/g;
  514. $TEXT =~ s/<(em|i)>/\\textit\{/g;
  515. $TEXT =~ s/<b>/\\textbf\{/g;
  516. $TEXT =~ s'</(b|tt|em|i)>'}'g;
  517. $TEXT =~ s/<br>/\\par /g;
  518. $TEXT =~ s/<p>/\\par /g;
  519. $TEXT =~ s/<\/p>/\\par /g;
  520. $TEXT =~ s/<ul>/\\begin{itemize}\n /g;
  521. $TEXT =~ s/<\/ul>/\\end{itemize}\n /g;
  522. $TEXT =~ s/<ol>/\\begin{enumerate}\n /g;
  523. $TEXT =~ s/<\/ol>/\\end{enumerate}\n /g;
  524. $TEXT =~ s/<li>/\\item /g;
  525. $TEXT =~ s/<\/li>/\n /g;
  526. $TEXT =~ s/<\/center>/\\end{center}\n /g;
  527. $TEXT =~ s/<center>/\\begin{center}\n /g;
  528. $TEXT =~ s/<\/center>/\n /g;
  529. $TEXT =~ s/<center>/\n /g;
  530. $TEXT =~ s/<table[^>]*>/\\begin{table}\\begin{tabular}{*{1}{p{30mm}}|*{1}{p{50mm}|}|*{1}{p{50mm}|}}\\hline /g;
  531. $TEXT =~ s/<\/table>/\\\\ \\hline \\end{tabular} \\end{table}/g;
  532. $TEXT =~ s/\$table_tr/\\\\\\hline /g;
  533. $TEXT =~ s/\$table_hdtr/\\\\ \\hline/g;
  534. $TEXT =~ s/\$table_header/\\begin{table}\\begin{tabular}{*{1}{p{30mm}}|*{1}{p{50mm}|}|*{1}{p{50mm}|}}\\hline/g ;
  535. $TEXT =~ s/\$table_end/\\end{tabular}\\end{table}/g;
  536. #$TEXT =~ s/<caption>/\\caption\{ /g;
  537. #$TEXT =~ s/<\/caption>/\}\n /g;
  538. $TEXT =~ s/<tr[^>]*>/\\\\/g;
  539. $TEXT =~ s/<\/tr>/\\\\/g;
  540. $TEXT =~ s/<(td|th) colspan=(\d)( nowrap)?>/\\multicolumn{$2}{|c|}{/g;
  541. $TEXT =~ s/<\/(td|th)>/&/g;
  542. $TEXT =~ s/<(td|th)[^>]*>/&/g;
  543. $TEXT =~ s/&&/&/g;
  544. $TEXT =~ s/\_/_/g;
  545. $TEXT =~ s/&amp;/\\&/g;
  546. $TEXT =~ s'\\\\&'\\\\'g;
  547. $TEXT =~ s/&nbsp;/ /g;
  548. $TEXT =~ s/&eacute;/é/g;
  549. $TEXT =~ s/&egrave;/è/g;
  550. $TEXT =~ s/&agrave;/à/g;
  551. $TEXT =~ s/&ecirc;/ê/g;
  552. $TEXT =~ s/&lt;/</g;
  553. $TEXT =~ s/<(H|h)3>/\\subsection{/g;
  554. $TEXT =~ s/<\/(H|h)3>/}/g;
  555. $TEXT =~ s/<(H|h)4>/\\subsubsection{/g;
  556. $TEXT =~ s/<\/(H|h)4>/}/g;
  557. $TEXT =~ s/<(H|h)2>/\\section{/g;
  558. $TEXT =~ s/<\/(H|h)2>/}/g;
  559. $TEXT =~ s/&gt;/>/g;
  560. $TEXT =~ s/\#//g;
  561. $TEXT =~ s/<hr>/\\hrule/g;
  562. $TEXT =~ s/<pre>/\\begin{verbatim}/g;
  563. $TEXT =~ s/<\/pre>/\\end{verbatim}/g;
  564. $TEXT =~ s/\n{3,}/\n\n/g;
  565. $TEXT =~ s/<a[^>]+>([^<]+)<\/a>/\\url{$1}/g;
  566.  
  567. $TEXT ;
  568. }
  569.  
  570. sub out { my ($bloc, $text) = @_ ;
  571.   open  (OUT, ">$bloc") || die "peut pas créer $bloc";
  572.   print OUT "<!-- Automatically generated by bin/oefdoc.pl -->\n" . $text ; close OUT ;
  573. }
  574.  
  575. sub sortuniq {
  576.   my $prev = "not $_[0]";
  577.   grep { $_ ne $prev && ($prev = $_, 1) } sort @_;
  578. }
  579.