Debian Codegraph @

bin/transform-fdt

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 transform-fdt - transform .fdt files to new file format
6
7 =head1 SYNOPSIS
8
9 transform-fdt *.fdt
10
11 =head1 DESCRIPTION
12
13 We are going to change the file format slightly for .fdt files. This
14 script will take files of the old format and rewrite them using the new
15 format. Old files will be renamed to have a ".BAK" extension.
16
17 Running this script multiple times against the same file should cause
18 an error.
19
20 NOTE: The file format has not changed yet, so you should not run this.
21 It is for testing purposes for core developers only at this point.
22
23 =cut
24
25 use strict;
26 use warnings;
27
28 use File::Slurp;
29 use Plucene::Store::InputStream;
30
31 while (my $file = shift) {
32 eval {
33 my $back = $file . ".BAK";
34 local $SIG{__WARN__} = sub { die "$file already converted" };
35
36 my $in = Plucene::Store::InputStream->new($file);
37 my $out = "";
38 while (!$in->eof) {
39 my @docs = map [ $in->read_vint, $in->read_byte, $in->read_string ],
40 1 .. $in->read_vint;
41 my $template = "w" . ("wCw/a*" x @docs);
42 $out .= pack $template, scalar @docs, map @$_, @docs;
43 }
44
45 rename $file => $back;
46 write_file $file, $out;
47 };
48 warn $@ if $@;
49 }