| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lingua::Ogmios::FileManager; |
|
2
|
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
66
|
use strict; |
|
|
16
|
|
|
|
|
19
|
|
|
|
16
|
|
|
|
|
593
|
|
|
4
|
16
|
|
|
16
|
|
81
|
use warnings; |
|
|
16
|
|
|
|
|
21
|
|
|
|
16
|
|
|
|
|
467
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
11567
|
use File::MMagic; |
|
|
16
|
|
|
|
|
84917
|
|
|
|
16
|
|
|
|
|
571
|
|
|
7
|
16
|
|
|
16
|
|
9379
|
use Lingua::Ogmios::Annotations; |
|
|
16
|
|
|
|
|
52
|
|
|
|
16
|
|
|
|
|
9060
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
0
|
|
|
0
|
0
|
|
my ($class, $MNFile) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $FM = { |
|
14
|
|
|
|
|
|
|
'MagicNumberFilename' => $MNFile, |
|
15
|
|
|
|
|
|
|
'MagicNumbers' => undef, |
|
16
|
|
|
|
|
|
|
}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
bless $FM, $class; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
$FM->_load_MagicNumber; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
return($FM); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub getMagicNumberFilename { |
|
26
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
return($self->{'MagicNumberFilename'}); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub setMagicNumberFilename { |
|
32
|
0
|
|
|
0
|
0
|
|
my ($self, $filename) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->{'MagicNumberFilename'} = $filename; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _load_MagicNumber |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
42
|
0
|
|
|
|
|
|
my $MNFile = $self->getMagicNumberFilename; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $mm = new File::MMagic; # use internal magic file |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
print STDERR "Loading complementary magic number ... "; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if (open FILEM, $MNFile) { |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $line; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
while($line = ) { |
|
53
|
0
|
|
|
|
|
|
chomp $line; |
|
54
|
0
|
|
|
|
|
|
$line =~ s/\s*\#.*//; |
|
55
|
0
|
|
|
|
|
|
$line =~ s/^\s*//; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ($line ne "") { |
|
58
|
0
|
|
|
|
|
|
$mm->addMagicEntry($line); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
0
|
|
|
|
|
|
print STDERR "done\n"; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} else { |
|
64
|
0
|
|
|
|
|
|
warn "$MNFile: no such file or directory\n"; |
|
65
|
0
|
|
|
|
|
|
warn "No more Magic Number definition is loaded\n"; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
|
68
|
0
|
|
|
|
|
|
$self->{'MagicNumbers'} = $mm; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return($mm); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub getType { |
|
74
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $xmlns; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if (-d $file) { |
|
79
|
0
|
|
|
|
|
|
return('directory'); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
0
|
0
|
|
|
|
|
if (-f $file) { |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $mm = $self->{'MagicNumbers'}; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
print STDERR "Determining the type of the file " . $file . ": "; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $type = $mm->checktype_filename($file); |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ($file =~ /.ppt$/i) { |
|
90
|
0
|
|
|
|
|
|
$type = "application/powerpoint"; |
|
91
|
0
|
|
|
|
|
|
warn "Getting the type thanks to the extension\n"; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
0
|
|
|
|
|
if ($file =~ /.xls$/i) { |
|
94
|
0
|
|
|
|
|
|
$type = "application/vnd.ms-excel"; |
|
95
|
0
|
|
|
|
|
|
warn "Getting the type thanks to the extension\n"; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
# if msword may be it should be relevant to check the extension, to better determine the type |
|
98
|
0
|
|
|
|
|
|
$type =~ s/;.*//; |
|
99
|
0
|
0
|
0
|
|
|
|
if (($type eq "message/rfc822") || ($file =~ /^x-system\/x-unix;/)) { |
|
100
|
0
|
0
|
|
|
|
|
if ($file =~ /.tex$/i) { |
|
101
|
0
|
|
|
|
|
|
$type = "text/x-tex"; |
|
102
|
0
|
|
|
|
|
|
warn "Getting the type thanks to the extension\n"; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
0
|
|
|
|
|
if ($type eq 'text/xml') { |
|
106
|
0
|
|
|
|
|
|
$xmlns = Lingua::Ogmios::Annotations::getNamespace($file); |
|
107
|
0
|
|
|
|
|
|
$type .= " ns=$xmlns"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
|
|
|
|
|
print STDERR "Type file: $type\n"; |
|
110
|
0
|
|
|
|
|
|
return($type); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} else { |
|
113
|
0
|
|
|
|
|
|
warn "Unknown type\n"; |
|
114
|
0
|
|
|
|
|
|
return('unknown'); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
0
|
0
|
|
sub convert { |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
0
|
0
|
|
sub XMLconvert { |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |