line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::PML::Backend::CSTS; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2004
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
113
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
2
|
|
|
2
|
|
36
|
$VERSION='2.24'; # version template |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use Treex::PML; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
175
|
|
9
|
2
|
|
|
2
|
|
13
|
use Treex::PML::IO qw(set_encoding); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
91
|
|
10
|
2
|
|
|
2
|
|
1028
|
use Treex::PML::Backend::CSTS::Csts2fs; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
87
|
|
11
|
2
|
|
|
2
|
|
999
|
use Treex::PML::Backend::CSTS::Fs2csts; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
88
|
|
12
|
2
|
|
|
2
|
|
15
|
use Fcntl qw(SEEK_SET); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
104
|
|
13
|
2
|
|
|
2
|
|
12
|
use File::ShareDir; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
80
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
10
|
use vars qw($sgmls $sgmlsopts $doctype $csts_encoding); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
613
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub default_settings { |
18
|
2
|
50
|
|
2
|
0
|
10
|
$sgmls = "nsgmls" unless $sgmls; |
19
|
2
|
50
|
|
|
|
7
|
$sgmlsopts = "-i preserve.gen.entities" unless $sgmlsopts; |
20
|
2
|
50
|
33
|
|
|
10
|
unless ($doctype and -f $doctype) { |
21
|
2
|
|
|
|
|
4
|
$doctype = eval { File::ShareDir::module_file(__PACKAGE__,'csts.doctype') }; |
|
2
|
|
|
|
|
10
|
|
22
|
2
|
50
|
33
|
|
|
1590
|
unless (defined($doctype) and -f $doctype) { |
23
|
2
|
|
|
|
|
39
|
$doctype = Treex::PML::IO::CallerDir(File::Spec->catfile(qw(CSTS share csts.doctype))); |
24
|
|
|
|
|
|
|
} |
25
|
2
|
50
|
|
|
|
55
|
unless (-f $doctype) { |
26
|
0
|
|
|
|
|
0
|
$doctype = Treex::PML::FindInResources("csts.doctype"); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
2
|
50
|
|
|
|
11
|
$sgmls_command='%s %o %d %f' unless $sgmls_command; |
30
|
2
|
|
|
|
|
63
|
$csts_encoding = 'iso-8859-2'; # this the encoding of CSTS by definition |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my %stderr_pool; |
34
|
|
|
|
|
|
|
sub open_backend { |
35
|
0
|
|
|
0
|
0
|
0
|
my ($filename, $mode, $encoding)=@_; |
36
|
0
|
0
|
|
|
|
0
|
if ($mode eq 'w') { |
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
return Treex::PML::IO::open_backend($filename,$mode,$csts_encoding); |
38
|
|
|
|
|
|
|
} elsif ($mode eq 'r') { |
39
|
0
|
|
|
|
|
0
|
my $fh = undef; |
40
|
0
|
|
|
|
|
0
|
my $cmd = $sgmls_command; |
41
|
0
|
0
|
|
|
|
0
|
$doctype = Treex::PML::FindInResources($doctype) unless -f $doctype; |
42
|
0
|
0
|
|
|
|
0
|
print STDERR "$cmd\n" if $Treex::PML::Debug; |
43
|
0
|
|
|
|
|
0
|
$cmd=~s/\%s/$sgmls/g; |
44
|
0
|
|
|
|
|
0
|
$cmd=~s/\%o/$sgmlsopts/g; |
45
|
0
|
|
|
|
|
0
|
$cmd=~s/\%d/$doctype/g; |
46
|
0
|
|
|
|
|
0
|
$cmd=~s/\%f/-/g; |
47
|
0
|
0
|
|
|
|
0
|
warn "[r $cmd]\n" if $Treex::PML::Debug; |
48
|
2
|
|
|
2
|
|
16
|
no integer; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
|
|
0
|
my $err = File::Temp->new(UNLINK => 1); |
|
0
|
|
|
|
|
0
|
|
52
|
0
|
|
|
|
|
0
|
$err->autoflush(1); |
53
|
0
|
0
|
|
|
|
0
|
open my $olderr, ">&", \*STDERR or die "Can't dup STDERR: $!"; |
54
|
0
|
0
|
|
|
|
0
|
open STDERR, ">&", $err or die "Can't dup temporary filehandle as STDERR: $!"; |
55
|
0
|
|
|
|
|
0
|
eval { |
56
|
0
|
|
|
|
|
0
|
$fh = set_encoding(Treex::PML::IO::open_pipe($filename,'r',$cmd),$csts_encoding); |
57
|
0
|
0
|
0
|
|
|
0
|
binmode $fh,':crlf' if $fh and $^O eq 'MSWin32'; |
58
|
|
|
|
|
|
|
}; |
59
|
0
|
|
|
|
|
0
|
close(STDERR); |
60
|
0
|
0
|
|
|
|
0
|
open STDERR, ">&", $olderr or die "Can't dup old STDERR: $!"; |
61
|
0
|
0
|
|
|
|
0
|
if ($@) { |
62
|
0
|
|
|
|
|
0
|
close $err; |
63
|
0
|
|
|
|
|
0
|
die $@; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
0
|
$stderr_pool{$fh} = $err; |
66
|
0
|
|
|
|
|
0
|
return $fh; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
0
|
die "unknown mode $mode\n"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub close_backend { |
74
|
0
|
|
|
0
|
0
|
0
|
my ($fh)=@_; |
75
|
0
|
0
|
|
|
|
0
|
if (exists $stderr_pool{$fh}) { |
76
|
0
|
|
|
|
|
0
|
my $err = delete $stderr_pool{$fh}; |
77
|
0
|
|
|
|
|
0
|
seek($err,0,SEEK_SET); |
78
|
0
|
|
|
|
|
0
|
local $/; |
79
|
0
|
|
|
|
|
0
|
my $warnings = <$err>; |
80
|
0
|
|
|
|
|
0
|
close($err); |
81
|
0
|
0
|
0
|
|
|
0
|
if (defined $warnings and length $warnings) { |
82
|
0
|
|
|
|
|
0
|
warn $warnings; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
0
|
0
|
|
|
|
0
|
unless (Treex::PML::IO::close_backend($fh)) { |
86
|
0
|
|
|
|
|
0
|
die "$sgmls ended with error code $?\n"; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
0
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub read { |
92
|
0
|
|
|
0
|
0
|
0
|
Treex::PML::Backend::CSTS::Csts2fs::read(@_); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub write { |
96
|
0
|
|
|
0
|
0
|
0
|
Treex::PML::Backend::CSTS::Fs2csts::write(@_); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub test_nsgmls { |
100
|
1
|
50
|
|
1
|
0
|
46
|
return 1 if (-x $sgmls); |
101
|
1
|
50
|
|
|
|
31
|
foreach (split(($^O eq 'MSWin32' ? ';' : ':'),$ENV{PATH})) { |
102
|
9
|
50
|
|
|
|
193
|
if (-x "$_".($^O eq 'MSWin32' ? "\\" : "/")."$sgmls") { |
|
|
50
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
0
|
unless (-f $doctype) { |
104
|
0
|
0
|
|
|
|
0
|
warn("CSTS doctype not found: $doctype\n") if $Treex::PML::Debug; |
105
|
0
|
|
|
|
|
0
|
return 0; |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
0
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
1
|
50
|
|
|
|
17
|
warn("nsgmls not found at $sgmls\n") if $Treex::PML::Debug; |
111
|
1
|
|
|
|
|
6
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub test { |
115
|
0
|
|
|
0
|
0
|
|
my ($f,$encoding)=@_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
return 0 unless test_nsgmls(); |
118
|
0
|
0
|
|
|
|
|
if (ref($f)) { |
119
|
0
|
|
|
|
|
|
my $line=$f->getline(); |
120
|
0
|
|
|
|
|
|
return $line=~/^\s*]|^
|
121
|
|
|
|
|
|
|
} else { |
122
|
0
|
|
|
|
|
|
my $fh = Treex::PML::IO::open_backend($f,"r"); |
123
|
0
|
|
0
|
|
|
|
my $test = $fh && test($fh); |
124
|
0
|
|
|
|
|
|
Treex::PML::IO::close_backend($fh); |
125
|
0
|
|
|
|
|
|
return $test; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
BEGIN { |
130
|
2
|
|
|
2
|
|
1368
|
default_settings(); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
__END__ |