Subversion Repositories wimsdev

Rev

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

  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. my $dirform="form";
  7. my $dirdic="dic";
  8. my %list=();
  9. my $list=\%list;
  10. my @Keywords=();
  11. my @Files = GetFilesList ($dirform);
  12. foreach my $File  (@Files) {
  13.         next if !($File =~ /.def\b/) ;
  14.         my @l=treate_keywords($File);
  15.         push @Keywords, @l;
  16. }
  17. @Keywords=sortuniq(@Keywords);
  18. out("$dirdic/form.json", "\"" .join("\",\n\"", @Keywords) . "\",");
  19.  
  20. my @text=();
  21. while ( my ($key, $value) = each (%list) ) {
  22.      push @text, "$key:$value" ; }
  23. ###il faut sorter  
  24. out("$dirdic/form", join("\n",sortuniq(@text)));
  25.  
  26. sub treate_keywords { my ($file) = @_ ;
  27.    my $t=0; my $t1=0; my @keywords=();
  28.    my $file1 = $file ; $file1=~ s,$dirform/(.*)\.def,$1,;
  29.     open IN, $file;
  30.     while(<IN>) {
  31.      my $k = $_ ;
  32.      if( ($k =~ /^:/) && $t==0 && $t1==0) {
  33.       $t = 1; $k =~ s/://;
  34.       push @keywords,split(", *",lc($k)) ;
  35.      }
  36.      if( !($k =~ /^:/) && $t==1 && $t1==0) {
  37.       push @keywords,split(", *",lc($k)) ;
  38.      }
  39.      if( ($k =~ /^:/) && $t==1 ) {$t1=1}
  40.     }
  41.     for my $k (@keywords) { chomp $k;
  42.      next if !($k);
  43.     if (!$list{$k}) { $list{$k} .= $file1 ." "; } else {$list{$k} .= $file1 . " " };
  44.     }
  45.     close IN;
  46.    @keywords;
  47.    
  48.    
  49. }
  50.  
  51. sub out { my ($bloc, $text) = @_;
  52.   open  (OUT, ">$bloc") ;
  53.   print OUT $text ; close OUT;
  54. }
  55.  
  56.  
  57. sub sortuniq {
  58.   my $prev = "not $_[0]";
  59.   grep { $_ ne $prev && ($prev = $_, 1) } sort @_;
  60. }
  61.  
  62. sub GetFilesList
  63. {
  64.         my $Path = $_[0];
  65.         my $FileFound;
  66.         my @FilesList=();
  67.  
  68.         # Lecture de la liste des fichiers
  69.         opendir (my $FhRep, $Path)
  70.                 or die "Impossible d'ouvrir le repertoire $Path\n";
  71.         my @Contenu = grep { !/^\.\.?$/ } readdir($FhRep);
  72.         closedir ($FhRep);
  73.  
  74.         foreach my $FileFound (@Contenu) {
  75.                 # Traitement des fichiers
  76.                 if ( -f "$Path/$FileFound") {
  77.                         push ( @FilesList, "$Path/$FileFound" );
  78.                 }
  79.                 # Traitement des repertoires
  80.                 elsif ( -d "$Path/$FileFound") {
  81.                         # Boucle pour lancer la recherche en mode recursif
  82.                         push (@FilesList, GetFilesList("$Path/$FileFound") );
  83.                 }
  84.  
  85.         }
  86.         return @FilesList;
  87. }
  88.  
  89.  
  90.  
  91.