Subversion Repositories wimsdev

Rev

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