arXiv/FileGuess.pm

filter: Statementstmt 86.8% 152 / 175 Branchbran 58.8% 73 / 124 Conditioncond 47.4% 64 / 135 MC/DCmcdc 14.2% 10 / 70 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 60.1% 310 / 515 CC 111 SCAR 66.6
CC
111
Cov
67%
guess_file_type
879.4
_type_of_latex2e
6.0
type_name
2.0
CRAP 782.9
↑ Summary arXiv.pm »
1 package arXiv::FileGuess;
2  
3 =head1 NAME
4  
5 arXiv::FileGuess - Central file type determination for arXiv
6  
7 =head1 SYNOPSIS
8  
9 Central file type identification for arXiv.org.
10  
11 Much of this should probably be replaced with the file program with externally
12 maintained magic information. However, we need here to support a number of cases
13 special to arXiv and to make some rather fine-grained determinations of TeX
14 related file formats, along with determination of the order in which they
15 should be processed.
16  
17 =cut
18  
19 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 our @EXPORT_OK = qw( guess_file_type is_tex_type type_name );
23  
24 2 ▶use vars qw(%NAME %TEX_types);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 =head2 INTERNAL VARIABLES
27  
28 =head3 %TEX_types
29  
30 A hash of type names which represent TeX types (i.e. should be processed with
31 AutoTeX). Accessed via function is_tex_type().
32  
33 =cut
34  
35 =head3 %NAME
36  
37 A display name indexed by type. Accessed via function type_name().
38  
39 =cut
40  
41 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
42 # Make sure %TEX_types and %NAME full before use
43  
44 2 @TEX_types{qw(
45 TYPE_LATEX
46 TYPE_TEX
47 TYPE_TEX_priority
48 TYPE_TEX_AMS
49 TYPE_TEX_MAC
50 TYPE_LATEX2e
51 TYPE_TEX_priority2
52 TYPE_TEXINFO
53 TYPE_PDFLATEX
54 TYPE_PDFTEX
55 )} = ();
56  
57 2 $NAME{'TYPE_ABORT'} = 'Immediate stop';
58 2 $NAME{'TYPE_FAILED'} = 'unknown';
59 2 $NAME{'TYPE_ALWAYS_IGNORE'} = 'Always ignore';
60 2 $NAME{'TYPE_INPUT'} = 'Input for (La)TeX';
61 2 $NAME{'TYPE_BIBTEX'} = 'BiBTeX';
62 2 $NAME{'TYPE_POSTSCRIPT'} = 'Postscript';
63 2 $NAME{'TYPE_DOS_EPS'} = 'DOS EPS Binary File';
64 2 $NAME{'TYPE_PS_FONT'} = 'Postscript Type 1 Font';
65 2 $NAME{'TYPE_PS_PC'} = '^D%! Postscript';
66 2 $NAME{'TYPE_IMAGE'} = 'Image (gif/jpg etc)';
67 2 $NAME{'TYPE_ANIM'} = 'Animation (mpeg etc)';
68 2 $NAME{'TYPE_HTML'} = 'HTML';
69 2 $NAME{'TYPE_PDF'} = 'PDF';
70 2 $NAME{'TYPE_DVI'} = 'DVI';
71 2 $NAME{'TYPE_NOTEBOOK'} = 'Mathematica Notebook';
72 2 $NAME{'TYPE_ODF'} = 'OpenDocument Format';
73 2 $NAME{'TYPE_DOCX'} = 'Microsoft DOCX';
74 2 $NAME{'TYPE_TEX'} = 'TEX';
75 2 $NAME{'TYPE_PDFTEX'} = 'PDFTEX';
76 2 $NAME{'TYPE_TEX_priority2'} = 'TeX (with \\end or \\bye - not starting a line)';
77 2 $NAME{'TYPE_TEX_AMS'} = 'AMSTeX';
78 2 $NAME{'TYPE_TEX_priority'} = 'TeX (with \\end or \\bye)';
79 2 $NAME{'TYPE_TEX_MAC'} = 'TeX +macros (harv,lanl..)';
80 2 $NAME{'TYPE_LATEX'} = 'LaTeX';
81 2 $NAME{'TYPE_LATEX2e'} = 'LATEX2e';
82 2 $NAME{'TYPE_PDFLATEX'} = 'PDFLATEX';
83 2 $NAME{'TYPE_TEXINFO'} = 'Texinfo';
84 2 $NAME{'TYPE_MF'} = 'Metafont';
85 2 $NAME{'TYPE_UUENCODED'} = 'UUencoded';
86 2 $NAME{'TYPE_ENCRYPTED'} = 'Encrypted';
87 2 $NAME{'TYPE_PC'} = 'PC-ctrl-Ms';
88 2 $NAME{'TYPE_MAC'} = 'MAC-ctrl-Ms';
89 2 $NAME{'TYPE_CSH'} = 'CSH';
90 2 $NAME{'TYPE_SH'} = 'SH';
91 2 $NAME{'TYPE_JAR'} = 'JAR archive';
92 2 $NAME{'TYPE_RAR'} = 'RAR archive';
93 2 $NAME{'TYPE_COMPRESSED'} = 'UNIX-compressed';
94 2 $NAME{'TYPE_ZIP'} = 'ZIP-compressed';
95 2 $NAME{'TYPE_GZIPPED'} = 'GZIP-compressed';
96 2 $NAME{'TYPE_BZIP2'} = 'BZIP2-compressed';
97 2 $NAME{'TYPE_MULTI_PART_MIME'} = 'MULTI_PART_MIME';
98 2 $NAME{'TYPE_TAR'} = 'TAR archive';
99 2 $NAME{'TYPE_IGNORE'} = ' user defined IGNORE';
100 2 $NAME{'TYPE_README'} = 'override';
101 2 $NAME{'TYPE_TEXAUX'} = 'TeX auxiliary';
102 2 $NAME{'TYPE_ABS'} = 'abstract';
103 2 $NAME{'TYPE_INCLUDE'} = ' keep';
104 }
105  
106  
107 =head2 SUBROUTINES
108  
109 =head3 guess_file_type($filename)
110  
111 Guess the file type $filename. Returns ($type, $tex_format,
112 $error), all of which are strings. The $type may be supplied to
113 is_tex_type($type) or type_name($type) for additional information
114 related to the file type.
115  
116 For most files $tex_format and $error will be undefined. $tex_format
117 will be defined for some TeX file formats where there is additional
118 information about the type of TeX.
119  
120 =cut
121  
122 31 ▶sub guess_file_type {
Subroutine guess_file_type: called CC=105 SCAR=67.8
Pod documented
123 31 my ($filename) = @_;
124 31 local $_ = $filename;
125  
126 31 ▶ return 'TYPE_README' if /(^|\/)00README\.XXX$/;
Branch: 1 branch
BranchTrueFalseTotal
if m[(^|/)00README\.XXX$] 1 30 31
127  
128 # Ignore tmp files created by (unpatched) dvihps, in top dir
129 30 ▶ return 'TYPE_ALWAYS_IGNORE' if /(^|\/)(head|body)\.tmp$/;
Branch: 1 branch
BranchTrueFalseTotal
if m[(^|/)(head|body)\.tmp$] 0 30 30
130  
131 # missfont.log files created in top dir should abort processing
132 # (missfont.log files in subdirs can be ignored)
133 30 ▶ return 'TYPE_ABORT' if /(^|\/)missfont.log$/;
Branch: 1 branch
BranchTrueFalseTotal
if m[(^|/)missfont.log$] 0 30 30
134  
135 30 ▶ return 'TYPE_TEXAUX' if /\.(sty|cls|mf|\d*pk|bbl|bst|tfm|ax|def|log|hrfldf|cfg|clo|inx|end|fgx|tbx|rtx|rty|toc)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /\.(sty|cls|mf|\d*pk|bbl|bst|tfm|ax|def|log|hrfldf|cfg|clo|inx|end|fgx|tbx|rtx|rty|toc)$/i 0 30 30
136 30 ▶ return 'TYPE_ABS' if /\.abs$/;
Branch: 1 branch
BranchTrueFalseTotal
if /\.abs$/ 0 30 30
137 30 ▶ return 'TYPE_IGNORE' if /\.fig$/; # ignore xfig files
Branch: 1 branch
BranchTrueFalseTotal
if /\.fig$/ 0 30 30
138 30 ▶ return 'TYPE_NOTEBOOK' if /\.nb$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /\.nb$/i 0 30 30
139 30 ▶ return 'TYPE_INPUT' if /\.inp$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /\.inp$/i 0 30 30
140  
141 30 ▶ return 'TYPE_HTML' if /\.html?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /\.html?$/i 0 30 30
142 30 ▶ return 'TYPE_ENCRYPTED' if /\.cry$/;
Branch: 1 branch
BranchTrueFalseTotal
if /\.cry$/ 0 30 30
143  
144 # Ignore zero size files
145 30 ▶ return 'TYPE_IGNORE' if (-z $filename);
Branch: 1 branch
BranchTrueFalseTotal
if -z $filename 0 30 30
146  
147 # Open file and read first few bytes to do magic sequence identification
148 # note that file will be auto-closed when $FILE_TO_GUESS goes out of scope
149 30 ▶ open(my $FILE_TO_GUESS, '<', $_) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $FILE_TO_GUESS, "<", $_ or return "TYPE_FAILED", undef, "failed to open '${filename}' to guess its format: $!. Continuing.\n" 28 2 30
150 return ('TYPE_FAILED', undef, "failed to open '$filename' to guess its format: $!. Continuing.\n");
151  
152 28 ▶ my $b1 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
153 28 ▶ my $b2 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
154 28 ▶ my $b3 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
155 28 ▶ my $b4 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
156 28 ▶ my $b5 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
157 28 ▶ my $b6 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
158 28 ▶ my $b7 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
159 28 ▶ my $b8 = ord(getc($FILE_TO_GUESS) || 0);
Condition50%1/2
getc $FILE_TO_GUESS || 0
l!l
280
MC/DC0%0/1
getc $FILE_TO_GUESS || 0
getc $FILE_TO_GUESS
Truth table50%1/2
A
A= getc $FILE_TO_GUESS
Aresult
11
00
160  
161 28 ▶ return 'TYPE_COMPRESSED' if $b1 == 037 && $b2 == 0235;
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 31 and $b2 == 157 0 28 28
Condition33%1/3
$b1 == 31 and $b2 == 157
!ll&&!rl&&r
2800
MC/DC0%0/2
$b1 == 31 and $b2 == 157
$b1 == 31 $b2 == 157
Truth table33%1/3
A and B
A= $b1 == 31B= $b2 == 157
ABresult
0X0
100
111
162 28 ▶ return 'TYPE_GZIPPED' if $b1 == 037 && $b2 == 0213;
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 31 and $b2 == 139 0 28 28
Condition33%1/3
$b1 == 31 and $b2 == 139
!ll&&!rl&&r
2800
MC/DC0%0/2
$b1 == 31 and $b2 == 139
$b1 == 31 $b2 == 139
Truth table33%1/3
A and B
A= $b1 == 31B= $b2 == 139
ABresult
0X0
100
111
163 28 ▶ return 'TYPE_BZIP2' if $b1 == 0x42 && $b2 == 0x5A && $b3 == 0x68 && $b4 > 0x2F;
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 66 and $b2 == 90 and $b3 == 104 and $b4 > 47 3 25 28
Condition66%6/9
$b1 == 66 and $b2 == 90 and $b3 == 104 and $b4 > 47
!ll&&!rl&&r
2503
$b1 == 66 and $b2 == 90 and $b3 == 104
!ll&&!rl&&r
2503
$b1 == 66 and $b2 == 90
!ll&&!rl&&r
2503
MC/DC25%1/4
$b1 == 66 and $b2 == 90 and $b3 == 104 and $b4 > 47
$b1 == 66 $b2 == 90 $b3 == 104 $b4 > 47
Truth table40%2/5
A and B and C and D
A= $b1 == 66B= $b2 == 90C= $b3 == 104D= $b4 > 47
ABCDresult
0XXX0
10XX0
110X0
11100
11111
164  
165 # POSIX tarfiles: look for the string 'ustar' at posn 257
166 # (There used to be additional code to detect non-POSIX tar files
167 # which is not detected with above, no longer necessary)
168 25 my $tar_test;
169 25 seek($FILE_TO_GUESS, 257, 0);
170 25 ▶ if ( read($FILE_TO_GUESS, $tar_test, 5) && $tar_test eq 'ustar' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $FILE_TO_GUESS, $tar_test, 5 and $tar_test eq "ustar") 0 25 25
Condition66%2/3
read $FILE_TO_GUESS, $tar_test, 5 and $tar_test eq "ustar"
!ll&&!rl&&r
5200
MC/DC0%0/2
read $FILE_TO_GUESS, $tar_test, 5 and $tar_test eq "ustar"
read $FILE_TO_GUESS, $tar_test, 5 $tar_test eq "ustar"
Truth table66%2/3
A and B
A= read $FILE_TO_GUESS, $tar_test, 5B= $tar_test eq "ustar"
ABresult
0X0
100
111
171 0 return 'TYPE_TAR';
172 }
173  
174 # DVI
175 25 ▶ return 'TYPE_DVI' if $b1 == oct(367) && $b2 == oct(2);
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 247 and $b2 == 2 1 24 25
Condition66%2/3
$b1 == 247 and $b2 == 2
!ll&&!rl&&r
2401
MC/DC50%1/2
$b1 == 247 and $b2 == 2
$b1 == 247 $b2 == 2
Truth table66%2/3
A and B
A= $b1 == 247B= $b2 == 2
ABresult
0X0
100
111
176 # GIF
177 24 ▶ return 'TYPE_IMAGE' if (sprintf('%c%c%c%c',$b1,$b2,$b3,$b4) eq 'GIF8');
Branch: 1 branch
BranchTrueFalseTotal
if sprintf("%c%c%c%c", $b1, $b2, $b3, $b4) eq "GIF8" 0 24 24
178 # PNG
179 24 ▶ return 'TYPE_IMAGE' if sprintf('%c%c%c%c%c%c%c%c',$b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8) eq "\211PNG\r\n\032\n";
Branch: 1 branch
BranchTrueFalseTotal
if sprintf("%c%c%c%c%c%c%c%c", $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8) eq "\211PNG\r\n\32\n" 0 24 24
180  
181 # TIF
182 24 ▶ return 'TYPE_IMAGE' if $b1 == 0115 && $b2 == 0115 && $filename =~ /\.tif/i;
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 77 and $b2 == 77 and $filename =~ /\.tif/i 0 24 24
Condition33%2/6
$b1 == 77 and $b2 == 77 and $filename =~ /\.tif/i
!ll&&!rl&&r
2400
$b1 == 77 and $b2 == 77
!ll&&!rl&&r
2400
MC/DC0%0/3
$b1 == 77 and $b2 == 77 and $filename =~ /\.tif/i
$b1 == 77 $b2 == 77 $filename =~ /\.tif/i
Truth table25%1/4
A and B and C
A= $b1 == 77B= $b2 == 77C= $filename =~ /\.tif/i
ABCresult
0XX0
10X0
1100
1111
183 # JPEG
184 24 ▶ return 'TYPE_IMAGE' if ($b1==0377 && $b2==0330 && $b3==0377 && ($b4==0340 || $b4==0356));
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 255 and $b2 == 216 and $b3 == 255 and $b4 == 224 || $b4 == 238 0 24 24
Condition25%3/12
$b1 == 255 and $b2 == 216 and $b3 == 255 and $b4 == 224 || $b4 == 238
!ll&&!rl&&r
2400
$b1 == 255 and $b2 == 216 and $b3 == 255
!ll&&!rl&&r
2400
$b1 == 255 and $b2 == 216
!ll&&!rl&&r
2400
$b4 == 224 or $b4 == 238
l!l&&r!l&&!r
000
MC/DC0%0/5
$b1 == 255 and $b2 == 216 and $b3 == 255 and $b4 == 224 || $b4 == 238
$b1 == 255 $b2 == 216 $b3 == 255 $b4 == 224 $b4 == 238
Truth table16%1/6
A and B and C and D or E
A= $b1 == 255B= $b2 == 216C= $b3 == 255D= $b4 == 224E= $b4 == 238
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
185  
186 # MPEG
187 24 ▶ return 'TYPE_ANIM' if $b1 == 0 && $b2 == 0 && $b3 == 01 && $b4 == 0263;
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 0 and $b2 == 0 and $b3 == 1 and $b4 == 179 0 24 24
Condition55%5/9
$b1 == 0 and $b2 == 0 and $b3 == 1 and $b4 == 179
!ll&&!rl&&r
2400
$b1 == 0 and $b2 == 0 and $b3 == 1
!ll&&!rl&&r
2310
$b1 == 0 and $b2 == 0
!ll&&!rl&&r
2301
MC/DC0%0/4
$b1 == 0 and $b2 == 0 and $b3 == 1 and $b4 == 179
$b1 == 0 $b2 == 0 $b3 == 1 $b4 == 179
Truth table40%2/5
A and B and C and D
A= $b1 == 0B= $b2 == 0C= $b3 == 1D= $b4 == 179
ABCDresult
0XXX0
10XX0
110X0
11100
11111
188  
189 24 ▶ if (("PK\003\004" eq sprintf('%c%c%c%c', $b1,$b2,$b3,$b4)) or
Branch: 1 branch
BranchTrueFalseTotal
if ("PK\3\4" eq sprintf("%c%c%c%c", $b1, $b2, $b3, $b4) or "PK00PK\3\4" eq sprintf("%c%c%c%c%c%c%c%c", $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8)) 7 17 24
Condition66%2/3
"PK\3\4" eq sprintf("%c%c%c%c", $b1, $b2, $b3, $b4) or "PK00PK\3\4" eq sprintf("%c%c%c%c%c%c%c%c", $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8)
l!l&&r!l&&!r
7017
MC/DC50%1/2
"PK\3\4" eq sprintf("%c%c%c%c", $b1, $b2, $b3, $b4) or "PK00PK\3\4" eq sprintf("%c%c%c%c%c%c%c%c", $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8)
"PK\3\4" eq sprintf("%c%c%c%c", $b1, $b2, $b3, $b4) "PK00PK\3\4" eq sprintf("%c%c%c%c%c%c%c%c", $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8)
Truth table66%2/3
A or B
A= "PK\3\4" eq sprintf("%c%c%c%c", $b1, $b2, $b3, $b4)B= "PK00PK\3\4" eq sprintf("%c%c%c%c%c%c%c%c", $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8)
ABresult
1X1
011
000
190 ("PK00PK\003\004" eq sprintf('%c%c%c%c%c%c%c%c', $b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8))) {
191 7 ▶ return 'TYPE_JAR' if ($filename =~ /\.jar$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /\.jar$/i 1 6 7
192 6 ▶ return 'TYPE_ODF' if ($filename =~ /\.odt$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /\.odt$/i 1 5 6
193 5 ▶ return 'TYPE_DOCX' if ($filename =~ /\.docx$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /\.docx$/i 2 3 5
194 3 return 'TYPE_ZIP'
195 }
196 17 ▶ return 'TYPE_RAR' if ('Rar!' eq sprintf('%c%c%c%c', $b1,$b2,$b3,$b4));
Branch: 1 branch
BranchTrueFalseTotal
if "Rar!" eq sprintf("%c%c%c%c", $b1, $b2, $b3, $b4) 1 16 17
197  
198 #:0 belong 0xC5D0D3C6 DOS EPS Binary File
199 #->4 long >0 Postscript starts at byte %d
200 16 ▶ return 'TYPE_DOS_EPS' if $b1 == oct(305) && $b2 == oct(320) && $b3 == oct(323) && $b4 == oct(306);
Branch: 1 branch
BranchTrueFalseTotal
if $b1 == 197 and $b2 == 208 and $b3 == 211 and $b4 == 198 2 14 16
Condition66%6/9
$b1 == 197 and $b2 == 208 and $b3 == 211 and $b4 == 198
!ll&&!rl&&r
1402
$b1 == 197 and $b2 == 208 and $b3 == 211
!ll&&!rl&&r
1402
$b1 == 197 and $b2 == 208
!ll&&!rl&&r
1402
MC/DC25%1/4
$b1 == 197 and $b2 == 208 and $b3 == 211 and $b4 == 198
$b1 == 197 $b2 == 208 $b3 == 211 $b4 == 198
Truth table40%2/5
A and B and C and D
A= $b1 == 197B= $b2 == 208C= $b3 == 211D= $b4 == 198
ABCDresult
0XXX0
10XX0
110X0
11100
11111
201  
202 14 my $one_kb;
203 14 seek($FILE_TO_GUESS, 0, 0);
204 14 read($FILE_TO_GUESS, $one_kb, 1024);
205 14 ▶ return 'TYPE_PDF' if index($one_kb, '%PDF-') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($one_kb, "%PDF-") != -1 0 14 14
206 14 ▶ return 'TYPE_MAC' if $one_kb =~ /#!\/bin\/csh -f\r#|(\r|^)begin \d{1,4}\s+\S.*\r[^\n]/;
Branch: 1 branch
BranchTrueFalseTotal
if $one_kb =~ m[#!/bin/csh -f\r#|(\r|^)begin \d{1,4}\s+\S.*\r[^\n]] 0 14 14
207  
208 14 my ($maybe_tex, $maybe_tex_priority, $maybe_tex_priority2);
209 14 seek($FILE_TO_GUESS, 0, 0);
210  
211 14 local $/ = "\n";
212 14 my $accum='';
213 14 ▶ while (<$FILE_TO_GUESS>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $FILE_TO_GUESS)) 40 1 41
214 40 ▶ if (/\%auto-ignore/ && $. <= 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\%auto-ignore/ and $. <= 10) 0 40 40
Condition33%1/3
/\%auto-ignore/ and $. <= 10
!ll&&!rl&&r
4000
MC/DC0%0/2
/\%auto-ignore/ and $. <= 10
/\%auto-ignore/ $. <= 10
Truth table33%1/3
A and B
A= /\%auto-ignore/B= $. <= 10
ABresult
0X0
100
111
215 0 return 'TYPE_IGNORE';
216 }
217 40 ▶ if ($. <= 10 && /\\input texinfo/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. <= 10 and /\\input texinfo/) 0 40 40
Condition33%1/3
$. <= 10 and /\\input texinfo/
!ll&&!rl&&r
0400
MC/DC0%0/2
$. <= 10 and /\\input texinfo/
$. <= 10 /\\input texinfo/
Truth table33%1/3
A and B
A= $. <= 10B= /\\input texinfo/
ABresult
0X0
100
111
218 0 return 'TYPE_TEXINFO';
219 }
220 40 ▶ if ($. <= 40 && /(^|\r)Content-type: /i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. <= 40 and /(^|\r)Content-type: /i) 0 40 40
Condition33%1/3
$. <= 40 and /(^|\r)Content-type: /i
!ll&&!rl&&r
0400
MC/DC0%0/2
$. <= 40 and /(^|\r)Content-type: /i
$. <= 40 /(^|\r)Content-type: /i
Truth table33%1/3
A and B
A= $. <= 40B= /(^|\r)Content-type: /i
ABresult
0X0
100
111
221 0 return 'TYPE_MULTI_PART_MIME';
222 }
223  
224 # Match strings starting at either 1st or 7th byte. Use $accum
225 # to build string of file to this point as the preceding 6 chars
226 # may include \n
227 40 $accum.=$_;
228 40 ▶ if ($. <= 7 && $accum=~/^(......)?%\!(PS-AdobeFont-1\.|FontType1|PS-Adobe-3\.0\ Resource-Font)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. <= 7 and $accum =~ /^(......)?%\!(PS-AdobeFont-1\.|FontType1|PS-Adobe-3\.0\ Resource-Font)/s) 4 36 40
Condition100%3/3
$. <= 7 and $accum =~ /^(......)?%\!(PS-AdobeFont-1\.|FontType1|PS-Adobe-3\.0\ Resource-Font)/s
!ll&&!rl&&r
6304
MC/DC100%2/2
$. <= 7 and $accum =~ /^(......)?%\!(PS-AdobeFont-1\.|FontType1|PS-Adobe-3\.0\ Resource-Font)/s
$. <= 7 $accum =~ /^(......)?%\!(PS-AdobeFont-1\.|FontType1|PS-Adobe-3\.0\ Resource-Font)/s
Truth table100%3/3
A and B
A= $. <= 7B= $accum =~ /^(......)?%\!(PS-AdobeFont-1\.|FontType1|PS-Adobe-3\.0\ Resource-Font)/s
ABresult
0X0
100
111
229 4 return 'TYPE_PS_FONT';
230 }
231  
232 # This must come after the test for TYPE_PS_FONT
233 36 ▶ if ($. == 1 && /^%\!/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. == 1 and /^%\!/) 0 36 36
Condition66%2/3
$. == 1 and /^%\!/
!ll&&!rl&&r
25110
MC/DC0%0/2
$. == 1 and /^%\!/
$. == 1 /^%\!/
Truth table66%2/3
A and B
A= $. == 1B= /^%\!/
ABresult
0X0
100
111
234 0 return 'TYPE_POSTSCRIPT';
235 }
236  
237 36 ▶ if (($. == 1 && (/^\%*\004%\!/ || /.*%\!PS-Adobe/))
Branch: 1 branch
BranchTrueFalseTotal
if ($. == 1 and /^\%*\004%\!/ || /.*%\!PS-Adobe/ or $. <= 10 and /^%\!PS/ and not $maybe_tex) 0 36 36
Condition40%6/15
$. == 1 and /^\%*\004%\!/ || /.*%\!PS-Adobe/ or $. <= 10 and /^%\!PS/ and not $maybe_tex
l!l&&r!l&&!r
0036
$. == 1 and /^\%*\004%\!/ || /.*%\!PS-Adobe/
!ll&&!rl&&r
25110
/^\%*\004%\!/ or /.*%\!PS-Adobe/
l!l&&r!l&&!r
0011
$. <= 10 and /^%\!PS/ and not $maybe_tex
!ll&&!rl&&r
3600
$. <= 10 and /^%\!PS/
!ll&&!rl&&r
0360
MC/DC0%0/6
$. == 1 and /^\%*\004%\!/ || /.*%\!PS-Adobe/ or $. <= 10 and /^%\!PS/ and not $maybe_tex
$. == 1 /^\%*\004%\!/ /.*%\!PS-Adobe/ $. <= 10 /^%\!PS/ not $maybe_tex
Truth table20%2/10
A and B or C or D and E and not(F)
A= $. == 1B= /^\%*\004%\!/C= /.*%\!PS-Adobe/D= $. <= 10E= /^%\!PS/F= not $maybe_tex
ABCDEFresult
11XXXX1
101XXX1
0XX1111
1001111
0XX0XX0
0XX10X0
0XX1100
1000XX0
10010X0
1001100
238 || ($. <= 10 && /^%\!PS/ && !$maybe_tex)) {
239 0 return 'TYPE_PS_PC';
240 }
241  
242 36 ▶ if ($. <= 12 && /^\r?%\&([^\s\n]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. <= 12 and /^\r?%\&([^\s\n]+)/) 0 36 36
Condition33%1/3
$. <= 12 and /^\r?%\&([^\s\n]+)/
!ll&&!rl&&r
0360
MC/DC0%0/2
$. <= 12 and /^\r?%\&([^\s\n]+)/
$. <= 12 /^\r?%\&([^\s\n]+)/
Truth table33%1/3
A and B
A= $. <= 12B= /^\r?%\&([^\s\n]+)/
ABresult
0X0
100
111
243 0 ▶ if ($1 eq 'latex209' || $1 eq 'biglatex' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq 'latex209' or $1 eq 'biglatex' or $1 eq 'latex' or $1 eq 'LaTeX') { } 0 0 0
Condition0%0/9
$1 eq "latex209" or $1 eq "biglatex" or $1 eq "latex" or $1 eq "LaTeX"
l!l&&r!l&&!r
000
$1 eq "latex209" or $1 eq "biglatex" or $1 eq "latex"
l!l&&r!l&&!r
000
$1 eq "latex209" or $1 eq "biglatex"
l!l&&r!l&&!r
000
MC/DC0%0/4
$1 eq "latex209" or $1 eq "biglatex" or $1 eq "latex" or $1 eq "LaTeX"
$1 eq "latex209" $1 eq "biglatex" $1 eq "latex" $1 eq "LaTeX"
Truth table0%0/5
A or B or C or D
A= $1 eq "latex209"B= $1 eq "biglatex"C= $1 eq "latex"D= $1 eq "LaTeX"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
244 $1 eq 'latex' || $1 eq 'LaTeX') {
245 0 return ('TYPE_LATEX', $1);
246 } else {
247 0 return ('TYPE_TEX_MAC', $1);
248 }
249 }
250 36 ▶ if ($. <= 10 && /<html[>\s]/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. <= 10 and /<html[>\s]/i) 0 36 36
Condition33%1/3
$. <= 10 and /<html[>\s]/i
!ll&&!rl&&r
0360
MC/DC0%0/2
$. <= 10 and /<html[>\s]/i
$. <= 10 /<html[>\s]/i
Truth table33%1/3
A and B
A= $. <= 10B= /<html[>\s]/i
ABresult
0X0
100
111
251 0 return 'TYPE_HTML';
252 }
253 36 ▶ if ($. <= 10 && /\%auto-include/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. <= 10 and /\%auto-include/) 0 36 36
Condition33%1/3
$. <= 10 and /\%auto-include/
!ll&&!rl&&r
0360
MC/DC0%0/2
$. <= 10 and /\%auto-include/
$. <= 10 /\%auto-include/
Truth table33%1/3
A and B
A= $. <= 10B= /\%auto-include/
ABresult
0X0
100
111
254 0 return 'TYPE_INCLUDE';
255 }
256 # All subsequent checks have lines with '%' in them chopped.
257 # if we need to look for a % then do it earlier!
258 36 s/\%[^\r]*//;
259 36 ▶ if (/(^|\r)\s*\\documentstyle/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(^|\r)\s*\\documentstyle/) 1 35 36
260 1 return 'TYPE_LATEX';
261 }
262 35 ▶ if (/(^|\r)\s*\\documentclass/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(^|\r)\s*\\documentclass/) 8 27 35
263 8 return _type_of_latex2e(\*{$FILE_TO_GUESS});
264 }
265 27 ▶ if (/(^|\r)\s*(\\font|\\magnification|\\input|\\def|\\special|\\baselineskip|\\begin)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(^|\r)\s*(\\font|\\magnification|\\input|\\def|\\special|\\baselineskip|\\begin)/) 0 27 27
266 0 $maybe_tex = 1;
267 0 ▶ return 'TYPE_TEX_priority' if /\\input\s+amstex/;
Branch: 1 branch
BranchTrueFalseTotal
if /\\input\s+amstex/ 0 0 0
268 }
269 27 ▶ if (/(^|\r)\s*\\(end|bye)(\s|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(^|\r)\s*\\(end|bye)(\s|$)/) 0 27 27
270 0 $maybe_tex_priority = 1;
271 }
272 27 ▶ if (/\\(end|bye)(\s|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\(end|bye)(\s|$)/) 0 27 27
273 0 $maybe_tex_priority2 = 1;
274 }
275 27 ▶ if (/\\input *(harv|lanl)mac/ || /\\input\s+phyzzx/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\input *(harv|lanl)mac/ or /\\input\s+phyzzx/) 0 27 27
Condition33%1/3
/\\input *(harv|lanl)mac/ or /\\input\s+phyzzx/
l!l&&r!l&&!r
0027
MC/DC0%0/2
/\\input *(harv|lanl)mac/ or /\\input\s+phyzzx/
/\\input *(harv|lanl)mac/ /\\input\s+phyzzx/
Truth table33%1/3
A or B
A= /\\input *(harv|lanl)mac/B= /\\input\s+phyzzx/
ABresult
1X1
011
000
276 0 return 'TYPE_TEX_MAC';
277 }
278 27 ▶ if (/beginchar\(/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/beginchar\(/) 0 27 27
279 0 return 'TYPE_MF';
280 }
281 27 ▶ if (/(^|\r)\@(book|article|inbook|unpublished)\{/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(^|\r)\@(book|article|inbook|unpublished)\{/i) 0 27 27
282 0 return 'TYPE_BIBTEX';
283 }
284 27 ▶ if (/^begin \d{1,4}\s+[^\s]+\r?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^begin \d{1,4}\s+[^\s]+\r?$/) 0 27 27
285 0 ▶ return 'TYPE_TEX_priority' if $maybe_tex_priority;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_tex_priority 0 0 0
286 0 ▶ return 'TYPE_TEX' if $maybe_tex;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_tex 0 0 0
287 0 ▶ return 'TYPE_PC' if /\r$/;
Branch: 1 branch
BranchTrueFalseTotal
if /\r$/ 0 0 0
288 0 return 'TYPE_UUENCODED';
289 }
290 27 ▶ if (m/paper deliberately replaced by what little/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/paper deliberately replaced by what little/) 0 27 27
291 0 return 'TYPE_ALWAYS_IGNORE'; # Was 'TYPE_FAILED'
292 }
293 }
294 1 ▶ close $FILE_TO_GUESS || warn "couldn't close file: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $FILE_TO_GUESS or warn "couldn't close file: $!" 1 0 1
295  
296 1 ▶ return 'TYPE_TEX_priority' if $maybe_tex_priority;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_tex_priority 0 1 1
297 1 ▶ return 'TYPE_TEX_priority2' if $maybe_tex_priority2;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_tex_priority2 0 1 1
298 1 ▶ return 'TYPE_TEX' if $maybe_tex;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_tex 0 1 1
299  
300 1 return 'TYPE_FAILED';
301 }
302  
303  
304 # _type_of_latex2e($filehandle)
305 #
306 # Takes an open file handle and searches for some heuristic regexps to
307 # determine whether the contents is of type pdflatex or regular latex2e.
308 #
309 8 ▶sub _type_of_latex2e {
Subroutine _type_of_latex2e: called CC=6 SCAR=17.9
310 8 my ($filehandle) = @_;
311 8 my $lines_to_search=$.+5; #will search for pdfoutput from beginning to 5 lines beyond
312 8 ▶ if (seek($filehandle,0,0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (seek $filehandle, 0, 0) 8 0 8
313 8 local $. = 0; #reset line counter if rewind worked
314 }
315  
316 8 ▶ while (<$filehandle>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $filehandle)) 295 3 298
317 295 ▶ if (/^[^%]*\\includegraphics[^%]*\.(?:pdf|png|gif|jpg)\s?\}/i ||
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^%]*\\includegraphics[^%]*\.(?:pdf|png|gif|jpg)\s?\}/i or $. < $lines_to_search and /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/) 5 290 295
Condition100%6/6
/^[^%]*\\includegraphics[^%]*\.(?:pdf|png|gif|jpg)\s?\}/i or $. < $lines_to_search and /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/
l!l&&r!l&&!r
14290
$. < $lines_to_search and /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/
!ll&&!rl&&r
242484
MC/DC100%3/3
/^[^%]*\\includegraphics[^%]*\.(?:pdf|png|gif|jpg)\s?\}/i or $. < $lines_to_search and /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/
/^[^%]*\\includegraphics[^%]*\.(?:pdf|png|gif|jpg)\s?\}/i $. < $lines_to_search /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/
Truth table100%4/4
A or B and C
A= /^[^%]*\\includegraphics[^%]*\.(?:pdf|png|gif|jpg)\s?\}/iB= $. < $lines_to_searchC= /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/
ABCresult
1XX1
0111
00X0
0100
318 ($. < $lines_to_search && /^[^%]*\\pdfoutput(?:\s+)?=(?:\s+)?1/)) {
319 5 return 'TYPE_PDFLATEX';
320 }
321 }
322 3 return 'TYPE_LATEX2e';
323 }
324  
325  
326 =head3 is_tex_type($type)
327  
328 Returns true (1) if the type name supplied is a TeX type, false ('')
329 otherwise.
330  
331 =cut
332  
333 4 ▶sub is_tex_type {
Subroutine is_tex_type: called CC=1 SCAR=0.0
Pod documented
334 4 my ($type) = @_;
335 4 return exists $TEX_types{$type};
336 }
337  
338  
339 =head3 type_name($type)
340  
341 Returns display string for the type $type. Or 'unknown' if
342 $type is not recognized.
343  
344 =cut
345  
346 4 ▶sub type_name {
Subroutine type_name: called CC=2 SCAR=6.9
Pod documented
347 4 my ($type)=@_;
348 4 ▶ return( $NAME{$type} || 'unknown' );
Condition100%2/2
$arXiv::FileGuess::NAME{$type} || 'unknown'
l!l
31
MC/DC100%1/1
$arXiv::FileGuess::NAME{$type} || 'unknown'
$arXiv::FileGuess::NAME{$type}
Truth table100%2/2
A
A= $arXiv::FileGuess::NAME{$type}
Aresult
11
00
349 }
350  
351 2 1;
352  
353 __END__
↑ Summary arXiv.pm »