Subversion Repositories wimsdev

Rev

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