/[suikacvs]/www/mozilla/tool/replace.pl
Suika

Diff of /www/mozilla/tool/replace.pl

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

revision 1.2 by wakaba, Sat Oct 25 12:00:20 2003 UTC revision 1.3 by wakaba, Wed Apr 14 12:17:38 2004 UTC
# Line 7  Getopt::Long::GetOptions ( Line 7  Getopt::Long::GetOptions (
7    'output-type=s'       => \$opt{type},    'output-type=s'       => \$opt{type},
8  );  );
9    
10  my %var = (percent => '%');  my %var = (percent => {value => '%'});
11  my $name;  my $name;
12  while (<>) {  while (<>) {
13    if (/^(.+?)(?:\[([^]]+)\])?:\s*$/) {    if (/^(.+?)(?:\[([^]]+)\])?:\s*$/) {
# Line 34  open SRC, $opt{input} or die "$0: $opt{i Line 34  open SRC, $opt{input} or die "$0: $opt{i
34                            .qq(Do not edit by hand!\n))                            .qq(Do not edit by hand!\n))
35          unless $opt{type} eq 'xml';          unless $opt{type} eq 'xml';
36    while (<SRC>) {    while (<SRC>) {
37      print scalar replace_percent ($_, \%var);      print scalar escape (replace_percent ($_, \%var));
38    }    }
39  close SRC;  close SRC;
40    
41  exit;  exit;
42    
43    sub escape ($) {
44      my $s = shift;
45      if ($opt{type} eq 'moz-properties') {
46        require Encode;
47        $s = Encode::decode ('utf8', $s);
48        ## TODO: How to encode U+10000 - U-7F000000 ?
49        $s =~ s/([^\x0A\x0D\x20-\x22\x24-\x5B\x5D-\x7E])/sprintf '\u%04X', ord $1/ge
50          unless $s =~ /^\s*\#/;
51      }
52      $s;
53    }
54    
55  sub replace_percent ($$) {  sub replace_percent ($$) {
56    my ($s, $l) = @_;    my ($s, $l) = @_;
57    $s =~ s{%%([^%]+)%%}{    $s =~ s{%%([^%]+)%%}{
# Line 72  sub commentize ($) { Line 84  sub commentize ($) {
84    } elsif ($opt{type} eq 'xml') {    } elsif ($opt{type} eq 'xml') {
85      $s =~ s!^!   - !mg;      $s =~ s!^!   - !mg;
86      return "<!--\n" . $s . "   -->\n";      return "<!--\n" . $s . "   -->\n";
87    } else {    } else { # moz-properties
88      $s =~ s!^!## !mg;      $s =~ s!^!## !mg;
89      return $s."\n";      return $s."\n";
90    }    }
# Line 81  sub commentize ($) { Line 93  sub commentize ($) {
93    
94  =head1 LICENSE  =head1 LICENSE
95    
96  Copyright 2003 Wakaba <w@suika.fam.cx>.  Copyright 2003-2004 Wakaba <w@suika.fam.cx>.  All rights reserved.
97    
98  This program is free software; you can redistribute it and/or modify  This program is free software; you can redistribute it and/or modify
99  it under the terms of the GNU General Public License as published by  it under the terms of the GNU General Public License as published by

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24