11 |
GetOptions ( |
GetOptions ( |
12 |
'database-dir=s' => \$opt{db}, |
'database-dir=s' => \$opt{db}, |
13 |
'input-file=s' => \$opt{src}, |
'input-file=s' => \$opt{src}, |
14 |
'output-file=s' => \$opt{output}, |
'output-dir=s' => \$opt{output}, |
15 |
); |
); |
16 |
|
|
17 |
$opt{output} ||= $opt{db} . q</page/referer.db>; |
$opt{output} ||= $opt{db} . q</page/>; |
18 |
$opt{src} ||= $opt{db} . q</page/mt--52656665726572.dat>; |
$opt{src} ||= $opt{db} . q</page/mt--52656665726572.dat>; |
19 |
|
|
20 |
print STDERR "Reading $opt{src}...\n"; |
print STDERR "Reading $opt{src}...\n"; |
22 |
local $/ = undef; |
local $/ = undef; |
23 |
|
|
24 |
print STDERR "Output: $opt{output}\n"; |
print STDERR "Output: $opt{output}\n"; |
25 |
require SuikaWiki::DB::Hash; |
require SuikaWiki::DB::FileSystem::Count; |
26 |
my %db; |
my $out = SuikaWiki::DB::FileSystem::Count->new |
27 |
my $out = new SuikaWiki::DB::Hash constructor => sub { |
(base_directory => $opt{output}, |
28 |
tie %db, 'BerkeleyDB::Hash', |
directory_suffix => '.ns', |
29 |
-Filename => $opt{output}, |
file_suffix => '.ref', |
30 |
-Flags => DB_CREATE, |
auto_mkdir => 1); |
|
-Mode => 0644; |
|
|
\%db; |
|
|
}; |
|
31 |
|
|
32 |
my $source = scalar <$src>; |
my $source = scalar <$src>; |
33 |
$source =~ s!^\#\?SuikaWikiMetaInfo/0.9[^\x02]*\x02!!; |
$source =~ s!^\#\?SuikaWikiMetaInfo/0.9[^\x02]*\x02!!; |
35 |
my $i = 0; |
my $i = 0; |
36 |
for my $old (map {[split /\x1F/, $_, 2]} split /\x1E/, $source) { |
for my $old (map {[split /\x1F/, $_, 2]} split /\x1E/, $source) { |
37 |
my $page = [split m#//#, $old->[0]]; |
my $page = [split m#//#, $old->[0]]; |
38 |
my %referer = map {split /\x09/, 2} split /\x0A/, $out->get ('referer', $page); |
my $referer = $out->get ('referer', $page); |
39 |
my %newref = split /"/, $old->[1]; |
my %newref = split /"/, $old->[1]; |
40 |
for (grep {$_} keys %newref) { |
for (grep {$_} keys %newref) { |
41 |
$referer{$_} += $newref{$_} if $_ and $newref{$_}; |
$referer->{$_} += $newref{$_} if $_ and $newref{$_}; |
42 |
} |
} |
43 |
$out->set ('referer', $page |
$out->set ('referer', $page => $referer); |
|
=> join "\x0A", map {$_ . "\x09" . $referer{$_}} keys %referer); |
|
44 |
|
|
45 |
print STDERR '*' unless ++$i % 10; |
print STDERR '*' unless ++$i % 10; |
46 |
print STDERR "\n" unless $i % 500; |
print STDERR "\n" unless $i % 500; |
57 |
|
|
58 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
59 |
|
|
60 |
referer2to3.pl [--database-dir=<dir>] [--input-file=<file>] [--output-file=<file>] |
referer2to3.pl [--database-dir=<dir>] [--input-file=<file>] [--output-dir=<dir>] |
61 |
|
|
62 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
63 |
|
|
83 |
|
|
84 |
Source (SuikaWiki 2) referer database file. |
Source (SuikaWiki 2) referer database file. |
85 |
|
|
86 |
=item --output-file=I<file> (Default: C<I<database-dir>/page/referer.db>) |
=item --output-dir=I<dir> (Default: C<I<database-dir>/page/>) |
87 |
|
|
88 |
New (SuikaWiki 3 BerkeleyDB) referer database file. |
New (SuikaWiki 3 BerkeleyDB) referer database directory. |
89 |
|
|
90 |
=back |
=back |
91 |
|
|