/[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.14 by wakaba, Mon Oct 27 04:52:38 2008 UTC revision 1.18 by wakaba, Sun Nov 2 04:49:55 2008 UTC
# Line 1  Line 1 
1  use strict;  use strict;
2    use utf8;
3    
 my $data_suffix = q[.dat];  
4  my $data_dir_name = q[data/];  my $data_dir_name = q[data/];
5  my $data2_dir_name = q[data2/];  my $data2_dir_name = q[data2/];
6  my $data2_suffix = q[.dat];  my $data2_suffix = q[.dat];
# Line 41  sub replace_pattern2 ($@) { Line 41  sub replace_pattern2 ($@) {
41    return $s;    return $s;
42  } # replace_pattern2  } # replace_pattern2
43    
 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  
   
44  sub read_data_file ($) {  sub read_data_file ($) {
45    my $file_name = shift;    my $file_name = shift;
46    if (-f $file_name) {    if (-f $file_name) {
# Line 88  sub write_data_file ($$) { Line 57  sub write_data_file ($$) {
57    
58    require Data::Dumper;    require Data::Dumper;
59    local $Data::Dumper::Sortkeys = 1;    local $Data::Dumper::Sortkeys = 1;
60      local $Data::Dumper::Useqq = 1;
61      local *Data::Dumper::qquote = sub {
62        my $s = shift;
63        $s =~ s/([\x27\x5C])/sprintf '\x%02X', ord $1/ge;
64        return q<qq'> . $s . q<'>;
65      }; # Data::Dumper::qquote
66      
67    my $had_file = -f $file_name;    my $had_file = -f $file_name;
68    open my $file, '>:encoding(utf8)', $file_name or die "$0: $file_name: $!";    open my $file, '>:encoding(utf8)', $file_name or die "$0: $file_name: $!";
69      print $file "use utf8;\n";
70    print $file Data::Dumper::Dumper ($data);    print $file Data::Dumper::Dumper ($data);
71    close $file;    close $file;
72    unless ($had_file) {    unless ($had_file) {
# Line 248  sub get_fallback_entries () { Line 224  sub get_fallback_entries () {
224    return $FallbackEntry;    return $FallbackEntry;
225  } # get_fallback_entries  } # get_fallback_entries
226    
 sub clear_fallback_entries () {  
   $FallbackEntry = {};  
 } # clear_fallback_entries  
   
227  sub save_fallback_entries () {  sub save_fallback_entries () {
228    write_data_file ($fallback_file_name => $FallbackEntry)    write_data_file ($fallback_file_name => $FallbackEntry)
229        if defined $FallbackEntry;        if defined $FallbackEntry;
# Line 262  sub get_modified_hashes () { Line 234  sub get_modified_hashes () {
234    return map {tr/\x0D\x0A//d; $_} <$file>;    return map {tr/\x0D\x0A//d; $_} <$file>;
235  } # get_modified_hashes  } # get_modified_hashes
236    
237  sub clear_modified_hashes () {  sub normalize_width ($) {
238    open my $file, '>', $patch_file_name;    my $s = shift;
239    close $file;    $s =~ tr{\x{3000}\x{FF01}-\x{FF5E}\x{FF61}-\x{FF9F}\x{FFE0}-\x{FFE6}}
240  } # clear_modified_hashes            { !-~。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン\x{3099}\x{309A}\xA2\xA3\xAC\xAF\xA6\xA5\x{20A9}};
241      return $s;
242    } # normalize_width
243    
244  sub htescape ($) {  sub htescape ($) {
245    my $s = shift;    my $s = shift;
# Line 282  sub system_ (@) { Line 256  sub system_ (@) {
256    
257  1;  1;
258    
259    ## Author: Wakaba <w@suika.fam.cx>.
260    ## License: Copyright 2008 Wakaba.  You are granted a license to use,
261    ##     reproduce and create derivative works of this script.
262    ## $Date$

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.18

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24