/[suikacvs]/markup/html/html5/spec-ja/common.pl
Suika

Diff of /markup/html/html5/spec-ja/common.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by wakaba, Sun Oct 26 12:38:48 2008 UTC revision 1.16 by wakaba, Mon Oct 27 05:00:33 2008 UTC
# Line 1  Line 1 
1  use strict;  use strict;
2    
 my $data_suffix = q[.dat];  
3  my $data_dir_name = q[data/];  my $data_dir_name = q[data/];
4  my $data2_dir_name = q[data2/];  my $data2_dir_name = q[data2/];
5  my $data2_suffix = q[.dat];  my $data2_suffix = q[.dat];
# Line 24  sub normalize ($) { Line 23  sub normalize ($) {
23    
24  sub get_hash ($) {  sub get_hash ($) {
25    require Digest::MD5;    require Digest::MD5;
26    return Digest::MD5::md5_hex (normalize ($_[0]));    require Encode;
27      return Digest::MD5::md5_hex (Encode::encode ('utf8', normalize ($_[0])));
28  } # get_hash  } # get_hash
29    
30  sub create_pattern1 ($) {  sub create_pattern1 ($) {
# Line 40  sub replace_pattern2 ($@) { Line 40  sub replace_pattern2 ($@) {
40    return $s;    return $s;
41  } # replace_pattern2  } # replace_pattern2
42    
 sub load_data_file ($$$) {  
   my ($data_file_name, $exact_data, $pattern_data) = @_;  
   
   open my $data_file, '<:utf8', $data_file_name  
       or die "$0: $data_file_name: $!";  
   local $/ = undef;  
   my $data = <$data_file>;  
   $data =~ s/\x0D?\x0A/\n/g;  
   for (split /\n\n+(?=#)/, $data) {  
     my ($en, $ja) = split /\n#ja\n/, $_;  
     if ($en =~ s/^#en\n//) {  
       $exact_data->{normalize ($en)} = $ja;  
     } elsif ($en =~ s/^#pattern\n//) {  
       $pattern_data->{create_pattern1 (normalize ($en))} = $ja;  
     }  
   }  
 } # load_data_file  
   
 sub for_each_data_file ($) {  
   my ($code) = @_;  
   
   opendir my $data_dir, $data_dir_name or die "$0: $data_dir_name: $!";  
   for (sort {$a cmp $b} readdir $data_dir) {  
     next if /^\./; # hidden files  
     next if /^_/; # editable but not-used files  
     my $data_file_name = qq[$data_dir_name$_];  
     next unless $data_file_name =~ /\Q$data_suffix\E$/;  
     $code->($data_file_name, $_);  
   }  
 } # for_each_data_file  
   
43  sub read_data_file ($) {  sub read_data_file ($) {
44    my $file_name = shift;    my $file_name = shift;
45    if (-f $file_name) {    if (-f $file_name) {
# Line 188  sub get_all_entries () { Line 157  sub get_all_entries () {
157    return $Entry;    return $Entry;
158  } # get_all_entries  } # get_all_entries
159    
160    sub for_each_entry_set ($;$) {
161      my $code = shift;
162      my $on_the_fly = shift;
163      
164      opendir my $dir, $data2_dir_name or die "$0: $data2_dir_name: $!";
165      for (readdir $dir) {
166        next unless /\Q$data2_suffix\E$/;
167        my $file_name = $data2_dir_name . $_;
168        next if $file_name eq $fallback_file_name;
169    
170        if ($Entry->{$file_name}) {
171          $code->($file_name, $Entry->{$file_name});
172        } elsif ($on_the_fly) {
173          $code->($file_name, read_data_file ($file_name));
174        } else {
175          $Entry->{$file_name} = read_data_file ($file_name);
176          $code->($file_name, $Entry->{$file_name});
177        }
178      }
179    } # for_each_entry_set
180    
181  my $FallbackEntry;  my $FallbackEntry;
182  sub get_fallback_entry ($) {  sub get_fallback_entry ($) {
183    my $hash = shift;    my $hash = shift;
# Line 218  sub set_fallback_entry ($$) { Line 208  sub set_fallback_entry ($$) {
208    $FallbackEntry->{$hash} = $value;    $FallbackEntry->{$hash} = $value;
209  } # set_fallback_entry  } # set_fallback_entry
210    
211  sub clear_fallback_entries () {  sub get_fallback_entries () {
212    $FallbackEntry = {};    unless (defined $FallbackEntry) {
213  } # clear_fallback_entries      $FallbackEntry = read_data_file ($fallback_file_name);
214      }
215      
216      return $FallbackEntry;
217    } # get_fallback_entries
218    
219  sub save_fallback_entries () {  sub save_fallback_entries () {
220    write_data_file ($fallback_file_name => $FallbackEntry)    write_data_file ($fallback_file_name => $FallbackEntry)
# Line 232  sub get_modified_hashes () { Line 226  sub get_modified_hashes () {
226    return map {tr/\x0D\x0A//d; $_} <$file>;    return map {tr/\x0D\x0A//d; $_} <$file>;
227  } # get_modified_hashes  } # get_modified_hashes
228    
 sub clear_modified_hashes () {  
   open my $file, '>', $patch_file_name;  
   close $file;  
 } # clear_modified_hashes  
   
229  sub htescape ($) {  sub htescape ($) {
230    my $s = shift;    my $s = shift;
231    $s =~ s/&/&amp;/g;    $s =~ s/&/&amp;/g;
# Line 252  sub system_ (@) { Line 241  sub system_ (@) {
241    
242  1;  1;
243    
244    ## Author: Wakaba <w@suika.fam.cx>.
245    ## License: Copyright 2008 Wakaba.  You are granted a license to use,
246    ##     reproduce and create derivative works of this script.
247    ## $Date$

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.16

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24