line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::PML::Backend::NTRED; |
2
|
1
|
|
|
1
|
|
1788
|
use Treex::PML; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
3
|
1
|
|
|
1
|
|
7
|
use Storable qw(nfreeze thaw); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
4
|
1
|
|
|
1
|
|
482
|
use MIME::Base64; |
|
1
|
|
|
|
|
735
|
|
|
1
|
|
|
|
|
61
|
|
5
|
1
|
|
|
1
|
|
9
|
use Treex::PML::IO; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
1
|
|
|
1
|
|
19
|
$VERSION='2.24'; # version template |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use vars qw($ntred); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
682
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$ntred='ntred'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub test { |
19
|
0
|
|
|
0
|
0
|
|
my ($filename,$encoding)=@_; |
20
|
0
|
|
|
|
|
|
return $filename=~m(^ntred://); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub open_backend { |
24
|
0
|
|
|
0
|
0
|
|
my ($filename, $mode, $encoding)=@_; |
25
|
0
|
|
|
|
|
|
my $fh = undef; |
26
|
0
|
|
|
|
|
|
my $cmd = ""; |
27
|
0
|
0
|
|
|
|
|
return unless $filename=~m(^ntred://(.*)$); |
28
|
0
|
|
|
|
|
|
$filename=$1; |
29
|
0
|
|
|
|
|
|
$filename=~s/@/##/; |
30
|
0
|
0
|
|
|
|
|
if ($filename) { |
31
|
0
|
0
|
|
|
|
|
if ($mode eq 'w') { |
32
|
0
|
0
|
|
|
|
|
open($fh,'|-',$ntred, '-Q', '--upload-file', $filename) || die "Failed to start NTrEd Client '$ntred': $!\n"; |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
0
|
|
|
|
|
open($fh,'-|',$ntred, '-Q', '--dump-files', $filename) || die "Failed NTrEd Client '$ntred': $!\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
return Treex::PML::IO::set_encoding($fh,$encoding); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub close_backend { |
41
|
0
|
|
|
0
|
0
|
|
my ($fh)=@_; |
42
|
0
|
|
0
|
|
|
|
return $fh && $fh->close(); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub read { |
46
|
0
|
|
|
0
|
0
|
|
my ($fd,$fs)=@_; |
47
|
0
|
|
|
|
|
|
my $data = do{{ local $/; <$fd>}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
unless (defined $data and length $data) { |
49
|
0
|
|
|
|
|
|
die "NTrEd Client returned no data\n"; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
my $fs_files = Storable::thaw(decode_base64($data)); |
52
|
0
|
|
|
|
|
|
undef $data; |
53
|
0
|
|
|
|
|
|
my $restore = $fs_files->[0]; |
54
|
0
|
0
|
|
|
|
|
if (ref($restore)) { |
55
|
0
|
|
|
|
|
|
my $api_version = $restore->[6]; |
56
|
0
|
0
|
|
|
|
|
if ($api_version ne $Treex::PML::API_VERSION) { |
57
|
0
|
|
|
|
|
|
warn "Warning: the binary content obtained via Treex::PML::Backend::NTRED from ".$fs->filename." is a dump of structures created by possibly incompatible Treex::PML API version $api_version (the current Treex::PML API version is $Treex::PML::API_VERSION)\n"; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$fs->changeFS($restore->[0]); |
60
|
0
|
|
|
|
|
|
$fs->changeTrees(@{$restore->[1]}); |
|
0
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$fs->changeTail(@{$restore->[2]}); |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$fs->[13]=$restore->[3]; # metaData |
63
|
0
|
|
|
|
|
|
$fs->changePatterns(@{$restore->[4]}); |
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$fs->changeHint($restore->[5]); |
65
|
0
|
|
|
|
|
|
$fs->FS->renew_specials(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub write { |
72
|
0
|
|
|
0
|
0
|
|
my ($fh,$fsfile)=@_; |
73
|
0
|
|
|
|
|
|
my $dump= [$fsfile->FS, |
74
|
|
|
|
|
|
|
$fsfile->treeList, |
75
|
|
|
|
|
|
|
[$fsfile->tail], |
76
|
|
|
|
|
|
|
$fsfile->[13], # metaData |
77
|
|
|
|
|
|
|
[$fsfile->patterns], |
78
|
|
|
|
|
|
|
$fsfile->hint, |
79
|
|
|
|
|
|
|
$Treex::PML::API_VERSION |
80
|
|
|
|
|
|
|
# CAUTION: when adding to this list, don't forget to do the same |
81
|
|
|
|
|
|
|
# in btred DUMP request handler |
82
|
|
|
|
|
|
|
]; |
83
|
0
|
|
|
|
|
|
eval { |
84
|
0
|
|
|
|
|
|
print $fh (encode_base64(Storable::nfreeze([$dump]))); |
85
|
0
|
|
|
|
|
|
print $fh ("\n"); |
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |