Subversion Repositories wimsdev

Rev

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