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*$/) { |
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{%%([^%]+)%%}{ |
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 |
} |
} |
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 |