AutoTeX/File.pm

filter: Statementstmt 7.2% 29 / 402 Branchbran 0.0% 0 / 232 Conditioncond 0.0% 0 / 106 MC/DCmcdc 0.0% 0 / 60 Subroutinesub 27.2% 9 / 33 Podpod 100% 24 / 24 totaltotal 7.2% 62 / 857 CC 156 SCAR 66.5
CC
156
Cov
4%
process_tex
1806.0
run_tex_attempt
1482.0
process_dvitype
346.9
CRAP 769.6
« AutoTeX/HyperTeX.pm ↑ Summary AutoTeX/Process.pm »
1 package TeX::AutoTeX::File;
2  
3 #
4 # $Id: File.pm,v 1.36.2.5 2011/01/22 04:53:23 thorstens Exp $
5 # $Revision: 1.36.2.5 $
6 # $Source: /cvsroot/arxivlib/arXivLib/lib/TeX/AutoTeX/File.pm,v $
7 #
8 # $Date: 2011/01/22 04:53:23 $
9 # $Author: thorstens $
10 #
11  
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 ### use warnings;
14 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our ($VERSION) = '$Revision: 1.36.2.5 $' =~ m{ \$Revision: \s+ (\S+) }x;
17  
18 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use TeX::AutoTeX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use TeX::AutoTeX::HyperTeX;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use TeX::AutoTeX::PostScript;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use TeX::AutoTeX::Config qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 $CRYPT
25 $DVIPS
26 $TEXCHR
27 $DIRECTIVE_FILE
28 %TEX_BINARIES
29 $TEX_PATH
30 2 );
31  
32 2 ▶use arXiv::FileGuess qw(guess_file_type is_tex_type type_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
35 0 my ($class, $fileset, $filename) = @_;
36  
37 0 my $self = {
38 flags => {},
39 dvi_flags => q{},
40 fileset => $fileset,
41 binaries => {%TEX_BINARIES},
42 untaint_regexp => qr/[^&\s;]+/,
43 };
44 0 ▶ if ($filename =~ /^($self->{untaint_regexp})$/ && $filename !~ /^\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /^($self->{'untaint_regexp'})$/ and not $filename =~ /^\./) { } 0 0 0
Condition0%0/3
$filename =~ /^($self->{"untaint_regexp"})$/ and not $filename =~ /^\./
!ll&&!rl&&r
000
MC/DC0%0/2
$filename =~ /^($self->{"untaint_regexp"})$/ and not $filename =~ /^\./
$filename =~ /^($self->{"untaint_regexp"})$/ not $filename =~ /^\./
Truth table0%0/3
A and not(B)
A= $filename =~ /^($self->{"untaint_regexp"})$/B= not $filename =~ /^\./
ABresult
0X0
100
111
45 0 $self->{filename} = $1; # untaint
46 } else {
47 0 throw TeX::AutoTeX::InvNameException("Invalid filename: '$filename'.");
48 }
49 0 weaken $self->{fileset};
50 0 bless $self, $class;
51 }
52  
53 0 ▶sub filename {
Subroutine filename: not called CC=1 SCAR=6.9
Pod documented
54 0 my $self = shift;
55 0 return $self->{filename};
56 }
57  
58 0 ▶sub type {
Subroutine type: not called CC=2 SCAR=17.9
Pod documented
59 0 my $self = shift;
60 # we cache the value
61 0 ▶ $self->{type} = $self->determine_type() if !defined $self->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"type"} 0 0 0
62 0 return $self->{type};
63 }
64  
65 0 ▶sub determine_type {
Subroutine determine_type: not called CC=5 SCAR=34.0
Pod documented
66 0 my $self = shift;
67  
68 0 ▶ return 'TYPE_README' if $self->{filename} eq $DIRECTIVE_FILE;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filename"} eq $TeX::AutoTeX::File::DIRECTIVE_FILE 0 0 0
69 0 my $fullname = "$self->{fileset}->{dir}/$self->{filename}";
70 0 ▶ return 'TYPE_DIRECTORY' if -d $fullname;
Branch: 1 branch
BranchTrueFalseTotal
if -d $fullname 0 0 0
71 0 my ($type, $texformat, $error) = guess_file_type($fullname);
72 0 ▶ $self->{fileset}->{log}->error($error) if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
73 0 ▶ $self->{tex_format} = lc $texformat if defined $texformat;
Branch: 1 branch
BranchTrueFalseTotal
if defined $texformat 0 0 0
74 0 return $type;
75 }
76  
77 0 ▶sub filetype_name {
Subroutine filetype_name: not called CC=1 SCAR=6.9
Pod documented
78 0 my $self = shift;
79 0 return arXiv::FileGuess::type_name($self->type());
80 }
81  
82 0 ▶sub type_is_tex {
Subroutine type_is_tex: not called CC=1 SCAR=6.9
Pod documented
83 0 my $self = shift;
84 0 return arXiv::FileGuess::is_tex_type($self->type());
85 }
86  
87 0 ▶sub assign_tex_priority {
Subroutine assign_tex_priority: not called CC=15 SCAR=54.8
Pod documented
88 # TS: 12/2010
89 # trying to solve the dependency tree in general is equivalent to the halting problem
90 # these are heuristics that work in practice on the material arXiv deals with,
91 # but they are also easily fooled
92  
93 0 my $self = shift;
94 0 ▶ if ($self->{flags}->{toplevelfile}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"flags"}{"toplevelfile"}) 0 0 0
95 0 return 4;
96 }
97 # FileGuess incorrectly identifies some files (especially style files)
98 # as tex files that aren't.
99 0 ▶ if (!$self->type_is_tex()
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->type_is_tex or $self->{"filename"} eq "auto_gen_ps.log" or $self->{"filename"} =~ /\.(?:sty|st|cls)$/i) 0 0 0
Condition0%0/6
not $self->type_is_tex or $self->{"filename"} eq "auto_gen_ps.log" or $self->{"filename"} =~ /\.(?:sty|st|cls)$/i
l!l&&r!l&&!r
000
not $self->type_is_tex or $self->{"filename"} eq "auto_gen_ps.log"
l!l&&r!l&&!r
000
MC/DC0%0/3
not $self->type_is_tex or $self->{"filename"} eq "auto_gen_ps.log" or $self->{"filename"} =~ /\.(?:sty|st|cls)$/i
not $self->type_is_tex $self->{"filename"} eq "auto_gen_ps.log" $self->{"filename"} =~ /\.(?:sty|st|cls)$/i
Truth table0%0/4
not(A) or B or C
A= not $self->type_is_texB= $self->{"filename"} eq "auto_gen_ps.log"C= $self->{"filename"} =~ /\.(?:sty|st|cls)$/i
ABCresult
1XX1
01X1
0011
0000
100 || $self->{filename} eq 'auto_gen_ps.log'
101 || $self->{filename} =~ /\.(?:sty|st|cls)$/i){
102 0 return 0;
103 }
104 # take advantage of logic in arXiv::FileGuess
105 0 ▶ if (0 <= index $self->{type}, 'priority2') {
Branch: 3 branches
BranchTrueFalseTotal
if (index($self->{'type'}, 'priority2') != -1) { } 0 0 0
elsif (index($self->{'type'}, 'priority') != -1) { } 0 0 0
elsif ('_MAC' eq substr($self->{'type'}, -4)) { } 0 0 0
106 0 return 1;
107 } elsif (0 <= index $self->{type}, 'priority') {
108 0 return 2;
109 } elsif ('_MAC' eq substr $self->{type}, -4) {
110 0 return 3;
111 }
112 # rate based on filename and contents
113 open(my $CURRENTFILE, '<', "$self->{fileset}->{dir}/$self->{filename}")
114 0 ▶ || $self->{fileset}->{log}->error("Could not open '$self->{filename}': $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $CURRENTFILE, "<", qq[$self->{"fileset"}{"dir"}/$self->{"filename"}] or $self->{"fileset"}{"log"}->error(qq[Could not open '$self->{"filename"}': $!]) 0 0 0
115 0 my $docstycls = 0;
116 # grant higher priority to files that end with tex-related extension
117 0 ▶ $docstycls++ if $self->{filename} =~ /\.(?:la)?tex$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filename"} =~ /\.(?:la)?tex$/i 0 0 0
118 0 ▶ while (<$CURRENTFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $CURRENTFILE)) 0 0 0
119 0 ▶ if (/^\s*\\document(?:style|class)/){
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\\document(?:style|class)/) 0 0 0
120 0 $docstycls++;
121 0 last;
122 }
123 }
124 0 ▶ while (<$CURRENTFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $CURRENTFILE)) 0 0 0
125 0 ▶ if (/^\s*\\begin\s*\{\s*document\s*\}/){
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\\begin\s*\{\s*document\s*\}/) 0 0 0
126 0 $docstycls++;
127 0 last;
128 }
129 }
130 0 ▶ close $CURRENTFILE or $self->{fileset}->{log}->verbose("couldn't close file: $!");
Branch: 1 branch
BranchTrueFalseTotal
close $CURRENTFILE or $self->{"fileset"}{"log"}->verbose("couldn't close file: $!") 0 0 0
131 0 return $docstycls;
132 }
133  
134 0 ▶sub type_override {
Subroutine type_override: not called CC=2 SCAR=17.9
Pod documented
135 0 my ($self, $type) = @_;
136 0 ▶ if (my $override = $self->{fileset}->override($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $override = $self->{"fileset"}->override($type)) 0 0 0
137 0 $self->{type} = $override;
138 0 $self->{fileset}->{log}->verbose(<<"EOM");
139 Directive file has overriden $self->{filename}'s type to be '$type' ($override).
140 EOM
141 0 return;
142 }
143 0 $self->{fileset}->{log}->verbose(<<"EOW");
144 Directive file wanted to override $self->{filename}'s type as '$type',
145 but this type has no override.
146 EOW
147 0 return 1;
148 }
149  
150 0 ▶sub set_flag {
Subroutine set_flag: not called CC=1 SCAR=6.9
Pod documented
151 0 my ($self, $flag) = @_;
152 0 return $self->{flags}->{$flag} = 1;
153 }
154  
155 0 ▶sub check_flag {
Subroutine check_flag: not called CC=1 SCAR=6.9
Pod documented
156 0 my ($self, $flag) = @_;
157 0 return exists $self->{flags}->{$flag};
158 }
159  
160 0 ▶sub set_dvi_flags {
Subroutine set_dvi_flags: not called CC=1 SCAR=6.9
Pod documented
161 0 my $self = shift;
162 0 return $self->{dvi_flags} = shift;
163 }
164  
165 0 ▶sub get_dvi_flags {
Subroutine get_dvi_flags: not called CC=1 SCAR=6.9
Pod documented
166 0 my $self = shift;
167 0 return $self->{dvi_flags};
168 }
169  
170 0 ▶sub process {
Subroutine process: not called CC=4 SCAR=30.0
Pod documented
171 0 my ($self, $process) = @_;
172  
173 0 my $result;
174 0 ▶ if ($self->type_is_tex()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->type_is_tex) { } 0 0 0
elsif ($self->type eq 'TYPE_ENCRYPTED') { } 0 0 0
elsif ($self->type eq 'TYPE_DVI') { } 0 0 0
175 0 $result = $self->process_tex($process);
176 } elsif ($self->type() eq 'TYPE_ENCRYPTED') {
177 0 $result = $self->process_encrypted($process);
178 } elsif ($self->type() eq 'TYPE_DVI') {
179 0 $result = $self->process_dvitype($process);
180 }
181 0 return $result;
182 }
183  
184 0 ▶sub process_tex {
Subroutine process_tex: not called CC=42 SCAR=75.0
Pod documented
185 0 my ($self, $process) = @_;
186  
187 0 my $log = $self->{fileset}->{log};
188 0 my $dir = $self->{fileset}->{dir};
189  
190 0 my $tex_passes = 4;
191 my ($new_type, $dont_hyper, $try_amslplain) =
192 TeX::AutoTeX::HyperTeX::copy_source_from_hyper(
193 $self->type(),
194 $self->{filename},
195 $dir,
196 $log,
197 $self->{fileset}->{local_hyper_transform}
198 0 );
199 0 ▶ if ($self->{type} ne $new_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} ne $new_type) 0 0 0
200 0 $log->verbose(<<"EOM");
201 Changing type from '$self->{type}' to '$new_type' on recommendation of
202 TeX::AutoTeX::HyperTeX::copy_source_from_hyper.
203 EOM
204 0 $self->{type} = $new_type;
205 }
206  
207 0 ▶ my $try_hyper = $dont_hyper ? 0 : !$process->{nohypertex};
Branch: 1 branch
BranchTrueFalseTotal
$dont_hyper ? : 0 0 0
208 0 ▶ $log->verbose('Will not attempt to use hypertex.') unless $try_hyper;
Branch: 1 branch
BranchTrueFalseTotal
unless $try_hyper 0 0 0
209  
210 # initalize @to_try with the different formats in the order we want to try them
211 0 my @to_try;
212 0 ▶ if ($process->{branch} eq '3' || $process->{branch} =~ m{texlive/}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($process->{'branch'} eq '3' or $process->{'branch'} =~ m[texlive/]) { } 0 0 0
elsif ($process->{'branch'} eq '2') { } 0 0 0
Condition0%0/3
$process->{"branch"} eq 3 or $process->{"branch"} =~ m[texlive/]
l!l&&r!l&&!r
000
MC/DC0%0/2
$process->{"branch"} eq 3 or $process->{"branch"} =~ m[texlive/]
$process->{"branch"} eq 3 $process->{"branch"} =~ m[texlive/]
Truth table0%0/3
A or B
A= $process->{"branch"} eq 3B= $process->{"branch"} =~ m[texlive/]
ABresult
1X1
011
000
213 0 ▶ if ($self->type() eq 'TYPE_LATEX' || $self->type() eq 'TYPE_LATEX2e') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->type eq 'TYPE_LATEX' or $self->type eq 'TYPE_LATEX2e') { } 0 0 0
elsif ($self->type eq 'TYPE_PDFLATEX') { } 0 0 0
Condition0%0/3
$self->type eq "TYPE_LATEX" or $self->type eq "TYPE_LATEX2e"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->type eq "TYPE_LATEX" or $self->type eq "TYPE_LATEX2e"
$self->type eq "TYPE_LATEX" $self->type eq "TYPE_LATEX2e"
Truth table0%0/3
A or B
A= $self->type eq "TYPE_LATEX"B= $self->type eq "TYPE_LATEX2e"
ABresult
1X1
011
000
214 0 ▶ @to_try = map {$try_hyper ? ("h$_", $_) : $_ } qw(latex pdflatex tex);
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
215 } elsif ($self->type() eq 'TYPE_PDFLATEX') {
216 0 ▶ @to_try = map {$try_hyper ? ("h$_", $_) : $_ } qw(pdflatex tex);
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
217 } else {
218 # we always try tex, in case of amslplain or such
219 0 ▶ @to_try = $try_hyper ? qw(htex tex) : 'tex';
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
220 # we always try latex, not just tex, because sometimes latex papers are misidentified as tex
221 0 ▶ push @to_try, $try_hyper ? qw(hlatex latex) : 'latex';
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
222 }
223 } elsif ($process->{branch} eq '2') {
224 # deal with legacy stuff
225 0 ▶ if (exists $self->{tex_format}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $self->{'tex_format'}) { } 0 0 0
elsif ($self->type eq 'TYPE_LATEX') { } 0 0 0
elsif ($self->type eq 'TYPE_LATEX2e') { } 0 0 0
226 0 ▶ if ($self->{tex_format} eq 'bigtex') {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'tex_format'} eq 'bigtex') { } 0 0 0
elsif ($self->{'tex_format'} eq 'biglatex') { } 0 0 0
elsif ($self->{'tex_format'} eq 'latex209') { } 0 0 0
elsif ($self->{'tex_format'} eq 'latex') { } 0 0 0
227 0 $log->verbose('Using bigtex');
228 0 $self->{binaries}->{HTEX} = $self->{binaries}->{TEX} = $self->{binaries}->{BIGTEX};
229 } elsif ($self->{tex_format} eq 'biglatex') {
230 0 $log->verbose('Using biglatex');
231 0 $self->{binaries}->{HLATEX2E} = $self->{binaries}->{LATEX2E} = $self->{binaries}->{BIGLATEX};
232 } elsif ($self->{tex_format} eq 'latex209') {
233 0 ▶ @to_try = $try_hyper? qw(hlatex209 latex209) : 'latex209';
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
234 } elsif ($self->{tex_format} eq 'latex') {
235 0 ▶ @to_try = $try_hyper ? qw(hlatex2e hlatex209 latex2e latex209) : qw(latex2e latex209);
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
236 }
237 } elsif ($self->type() eq 'TYPE_LATEX') {
238 0 ▶ @to_try = $try_hyper ? qw(hlatex2e hlatex209 latex2e latex209) : qw(latex2e latex209);
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
239 } elsif ($self->type() eq 'TYPE_LATEX2e') {
240 0 ▶ @to_try = $try_hyper ? qw(hlatex2e latex2e) : 'latex2e';
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
241 }
242 # under some circumstances, what looked like latex files are actually
243 # tex files with amsart.
244 0 ▶ if ($try_amslplain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try_amslplain) 0 0 0
245 0 ▶ push @to_try, $try_hyper ? qw(hamslplain amslplain) : 'amslplain';
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
246 }
247 0 ▶ if (@to_try == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@to_try == 0) { } 0 0 0
248 # we always try latex, not just tex, because sometimes latex papers are misidentified as tex
249 0 ▶ @to_try = map { $try_hyper ? ("h$_", $_) : $_ } qw(tex latex2e);
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
250 } else {
251 0 ▶ push @to_try, $try_hyper ? qw(htex tex) : 'tex';
Branch: 1 branch
BranchTrueFalseTotal
$try_hyper ? : 0 0 0
252 }
253 } else {
254 0 $log->verbose('unknown TeX branch');
255 }
256  
257 0 my $failed = 0;
258 0 my %written = ();
259 0 foreach my $tex_type (@to_try) {
260 0 ▶ if ('h' eq substr $tex_type, 0, 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ('h' eq substr($tex_type, 0, 1)) { } 0 0 0
261 0 $self->swap_source('hyper');
262 } else {
263 0 $self->swap_source('nohyper');
264 }
265  
266 0 my ($stime, $program, $old_format);
267 # get the appropriate program name from the variables set in TeX::AutoTeX::Config
268 0 ▶ if ($tex_type =~ /amslplain/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tex_type =~ /amslplain/) { } 0 0 0
269 0 $old_format = $self->{tex_format};
270 0 $self->{tex_format} = 'amslplain';
271 0 ▶ if ('h' eq substr $tex_type, 0, 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ('h' eq substr($tex_type, 0, 1)) { } 0 0 0
272 0 $program = $self->{binaries}->{HTEX};
273 } else {
274 0 $program = $self->{binaries}->{TEX};
275 }
276 } else {
277 0 $program = $self->{binaries}->{uc($tex_type)};
278 }
279 0 ▶ if (! $self->{fileset}->{utime}) {# set mtime and atime on all (non-dot-)files in CWD back 10 seconds
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"fileset"}{"utime"}) 0 0 0
280 0 my $setbacktime = time() - 10;
281 ### {#TS: extensive logging
282 ### my @allfiles = glob("*");
283 ### local $" = "]\n\t[";
284 ### $log->verbose("current file contents:\n\t[@allfiles]");
285 ### }
286 0 ▶ opendir my $CDIR, $dir or $log->verbose("opening directory '$dir' for reading failed: $!");
Branch: 1 branch
BranchTrueFalseTotal
opendir my $CDIR, $dir or $log->verbose("opening directory '${dir}' for reading failed: $!") 0 0 0
287 my $numfiles = utime $setbacktime, $setbacktime,
288 0 map { "$dir/$_" }
289 0 map { /^($self->{untaint_regexp})$/o }
290 0 ▶ grep { !/^\./ && -f "$dir/$_" }
Condition0%0/3
!/^\./ && -f "$dir/$_"
!ll&&!rl&&r
000
MC/DC0%0/2
!/^\./ && -f "$dir/$_"
!/^\./ -f "$dir/$_"
Truth table0%0/3
not(A) && B
A= !/^\./B= -f "$dir/$_"
ABresult
0X0
100
111
291 readdir $CDIR;
292 0 ▶ closedir $CDIR or $log->verbose("closing directory $dir failed: $!");
Branch: 1 branch
BranchTrueFalseTotal
closedir $CDIR or $log->verbose("closing directory $dir failed: $!") 0 0 0
293 #TS Note:
294 # if we don't reset (a|m)time each time the loop processes a new file
295 # the .with_hyper and .without_hyper files will not have proper stat
296 # values and will be removed. if we globally reset (a|m)time, things go
297 # awry with inclusion checking. Therefore make sure to reset utime in
298 # swap_source for hyper files in HyperTeX.pm.
299 0 $self->{fileset}->{utime}++;
300 }
301 0 $stime = time;
302 0 $failed = $self->run_tex_attempt($program, $tex_passes, $process, $stime, \%written, $tex_type);
303 0 ▶ if ($tex_type =~ /amslplain/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tex_type =~ /amslplain/) 0 0 0
304 0 $self->{tex_format} = $old_format;
305 }
306 0 $self->clean_aux_files($stime);
307 0 ▶ if (!$failed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($failed) 0 0 0
308 0 my $logfile = $self->basename() . '.log';
309 0 ▶ unlink "$dir/$logfile" or
Branch: 1 branch
BranchTrueFalseTotal
unlink "$dir/$logfile" or $log->error("Could not remove file '${logfile}'.") 0 0 0
310 $log->error("Could not remove file '$logfile'.");
311 0 last;
312 }
313 }
314 0 ▶ if ($failed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($failed) 0 0 0
315 0 $log->verbose("We failed utterly to process the TeX file '$self->{filename}'");
316 }
317 # ensure that no copies of the tex file are left behind
318 0 unlink map {"$dir/$self->{filename}.$_"} qw(with_hyper without_hyper);
319 0 return $failed;
320 }
321  
322 0 ▶sub process_encrypted {
Subroutine process_encrypted: not called CC=8 SCAR=42.8
Pod documented
323 0 my ($self, $process) = @_;
324  
325 0 my $log = $self->{fileset}->{log};
326 0 my $dir = $self->{fileset}->{dir};
327 0 my $file = $self->{filename};
328  
329 0 $log->verbose( "Decrypting file '$file'");
330 0 my $newfile = $file;
331 0 ▶ if ('.cry' ne lc substr $newfile, -4, 4, q{}) {
Branch: 1 branch
BranchTrueFalseTotal
if (".cry" ne lc substr($newfile, -4, 4, "")) 0 0 0
332 # throw exception
333 0 $log->error("filename '$file' does not end in '.cry'.");
334 }
335  
336 # arXiv specific
337 0 my $key = $process->{decryption_key};
338 0 $log->verbose("running: '$CRYPT $newfile $key'");
339  
340 # ensure proper path so that correct programs decry and cipher are found
341 0 ▶ if (index($ENV{PATH}, $TEX_PATH) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($ENV{"PATH"}, $TeX::AutoTeX::File::TEX_PATH) != 0) 0 0 0
342 0 local $ENV{PATH} = "$TEX_PATH/bin:" . $ENV{PATH};
343 }
344 0 my $fullname = "$dir/$newfile";
345 # The following two lines are necessary to get decry to work
346 {
347 0 open my $OUTFH, '>', $fullname; close $OUTFH;
348 0 chmod oct(666), $fullname;
349 }
350 0 $log->verbose("path is: '$ENV{PATH}'");
351 0 ▶ my $response = `$CRYPT $fullname $key` || "[no response, exit code $?]";
Condition0%0/2
`$TeX::AutoTeX::File::CRYPT $fullname $key` || "[no response, exit code $?]"
l!l
00
MC/DC0%0/1
`$TeX::AutoTeX::File::CRYPT $fullname $key` || "[no response, exit code $?]"
`$TeX::AutoTeX::File::CRYPT $fullname $key`
Truth table0%0/2
A
A= `$TeX::AutoTeX::File::CRYPT $fullname $key`
Aresult
11
00
352 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
353 0 $log->error("$CRYPT error response: '$response'");
354 }
355 0 ▶ if (! -T $fullname || -z _) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -T $fullname or -z _) 0 0 0
Condition0%0/3
not -T $fullname or -z _
l!l&&r!l&&!r
000
MC/DC0%0/2
not -T $fullname or -z _
not -T $fullname -z _
Truth table0%0/3
not(A) or B
A= not -T $fullnameB= -z _
ABresult
1X1
011
000
356 0 $log->error("'$file' didn't decrypt to a text file.");
357 }
358 0 ▶ unlink "$dir/$file" or $log->error("unable to remove '$file': $!");
Branch: 1 branch
BranchTrueFalseTotal
unlink "$dir/$file" or $log->error("unable to remove '${file}': $!") 0 0 0
359 0 return;
360 }
361  
362 0 ▶sub process_dvitype {
Subroutine process_dvitype: not called CC=19 SCAR=58.5
Pod documented
363 0 my ($self, $process) = @_;
364  
365 0 my $log = $self->{fileset}->{log};
366 0 my $dir = $self->{fileset}->{dir};
367 0 my $file = $self->{filename};
368  
369 0 ▶ my $dvi_flags = $process->{branch} =~ m{texlive/}? '-R2' : '-R';
Branch: 1 branch
BranchTrueFalseTotal
$process->{'branch'} =~ m[texlive/] ? : 0 0 0
370 0 ▶ $dvi_flags .= " $self->{dvi_flags}" if $self->{dvi_flags};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dvi_flags"} 0 0 0
371 0 ▶ $dvi_flags .= ' -t landscape' if $self->{flags}->{landscape};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flags"}{"landscape"} 0 0 0
372 0 ▶ $dvi_flags .= $self->{flags}->{keepcomments}? ' -K0' : ' -K1';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'flags'}{'keepcomments'} ? : 0 0 0
373  
374 0 my $response;
375 0 ▶ my $setenv = qq{export HOME=/tmp @{[$ENV{TEXMFCNF}? "TEXMFCNF=$ENV{TEXMFCNF}": q{}]} PATH=$process->{tex_env_path}};
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'TEXMFCNF'} ? : 0 0 0
376 0 my $crdir = substr $dir, length $TEX_PATH;
377 0 while (1) {
378 0 $log->verbose(" ~~~~~~~~~~~ Processing file '$file'");
379 0 my $dvipscommand = qq#$TEXCHR $TEX_PATH "($setenv; cd $crdir && $DVIPS $dvi_flags -z '$file' -o )" 2>&1#;
380 0 $log->verbose('Running: ' . substr $dvipscommand, length "$TEXCHR $TEX_PATH ");
381 0 my $dvipstime = time;
382 0 $response = `$dvipscommand`;
383 0 ▶ last if !$?;
Branch: 1 branch
BranchTrueFalseTotal
unless $? 0 0 0
384 0 $log->verbose("$DVIPS $dvi_flags -z produced an error: $?\nResponse was $response\nRetrying without '-z'");
385 0 ▶ if (-e "$dir/head.tmp" && -e "$dir/body.tmp") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$dir/head.tmp" and -e "$dir/body.tmp") 0 0 0
Condition0%0/3
-e "$dir/head.tmp" and -e "$dir/body.tmp"
!ll&&!rl&&r
000
MC/DC0%0/2
-e "$dir/head.tmp" and -e "$dir/body.tmp"
-e "$dir/head.tmp" -e "$dir/body.tmp"
Truth table0%0/3
A and B
A= -e "$dir/head.tmp"B= -e "$dir/body.tmp"
ABresult
0X0
100
111
386 0 unlink "$dir/head.tmp", "$dir/body.tmp";
387 0 $log->verbose('removed dvips leftover head.tmp and body.tmp');
388 }
389 # dvips -z may have core-dumped. remove only newly generated core file(s)
390 0 ▶ if (my @corefiles = glob "$dir/core\.[0-9]*") {
Subroutine BEGIN: called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if (my(@corefiles) = glob("$dir/core.[0-9]*")) 0 0 0
391 @corefiles =
392 0 map { m/(.*)/ }
393 0 ▶ grep { m{^$dir/core\.\d+$} && (stat "$dir/$_")[9] >= $dvipstime }
Condition0%0/3
m[^$dir/core\.\d+$] && (stat "$dir/$_")[9] >= $dvipstime
!ll&&!rl&&r
000
MC/DC0%0/2
m[^$dir/core\.\d+$] && (stat "$dir/$_")[9] >= $dvipstime
m[^$dir/core\.\d+$] (stat "$dir/$_")[9] >= $dvipstime
Truth table0%0/3
A && B
A= m[^$dir/core\.\d+$]B= (stat "$dir/$_")[9] >= $dvipstime
ABresult
0X0
100
111
394 @corefiles;
395 0 ▶ if (@corefiles) {
Branch: 1 branch
BranchTrueFalseTotal
if (@corefiles) 0 0 0
396 0 unlink @corefiles;
397 0 $log->verbose("removed one or more core files: @corefiles");
398 }
399 }
400 0 $dvipscommand = qq#$TEXCHR $TEX_PATH "($setenv; cd $crdir && $DVIPS $dvi_flags '$file' -o )" 2>&1#;
401 0 $log->verbose('Running: ' . substr $dvipscommand, length "$TEXCHR $TEX_PATH ");
402 0 $response = `$dvipscommand`;
403 0 ▶ last if !$?;
Branch: 1 branch
BranchTrueFalseTotal
unless $? 0 0 0
404 0 $log->verbose("$DVIPS $dvi_flags produced an error: $?\nResponse was $response.");
405 0 $log->error('Failed to produce postscript from dvi.');
406 }
407 0 $log->verbose("dvi(h)ps said ...\n$response.");
408  
409 0 my %commondvipsheaders;
410 0 @commondvipsheaders{qw(
411 tex.pro
412 texc.pro
413 texps.pro
414 hps.pro
415 special.pro
416 color.pro
417 finclude.pro
418 alt-rule.pro
419 head.tmp
420 body.tmp
421 8r.enc
422 texnansi.enc
423 )} = ();
424  
425 0 ▶ while ($response =~ m{<(?:\.//?)*([^><\n]+)>}g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response =~ m[<(?:\.//?)*([^><\n]+)>]g) 0 0 0
426 0 my $included = $1;
427 0 ▶ if ($included !~ m{^/}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($included =~ m[^/]) 0 0 0
428 0 ▶ if (-e "$dir/$included") {
Branch: 2 branches
BranchTrueFalseTotal
if (-e "$dir/$included") { } 0 0 0
elsif (not exists $commondvipsheaders{$included} || '.pfb' eq substr($included, -4)) { } 0 0 0
429 0 $self->{fileset}->new_File($included)->set_flag('used_by_dvips');
430 0 $log->verbose("'$included' no longer required ... it's in the postscript file.");
431 ▶ } elsif (!(exists $commondvipsheaders{$included} || '.pfb' eq substr $included, -4)) {
Condition0%0/3
exists $commondvipsheaders{$included} || '.pfb' eq substr($included, -4)
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $commondvipsheaders{$included} || '.pfb' eq substr($included, -4)
exists $commondvipsheaders{$included} '.pfb' eq substr($included, -4)
Truth table0%0/3
A || B
A= exists $commondvipsheaders{$included}B= '.pfb' eq substr($included, -4)
ABresult
1X1
011
000
432 0 $log->verbose("'$included' was apparently included, but cannot be deleted, because it cannot be found in cwd.");
433 }
434 }
435 }
436 0 my $psfile = $file;
437 0 substr $psfile, -3, 3, 'ps';
438 # Change %%Title if wanted
439 0 ▶ if (my $stampref = $process->get_stamp()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stampref = $process->get_stamp) 0 0 0
440 0 TeX::AutoTeX::PostScript::fix_ps_title(
441 $psfile,
442 $dir,
443 $stampref->[0],
444 $log
445 );
446 0 TeX::AutoTeX::PostScript::stamp_postscript(
447 $psfile,
448 $dir,
449 $stampref,
450 $log
451 );
452 }
453 0 $self->{fileset}->new_File($psfile)->set_flag('main_postscript');
454  
455 0 return;
456 }
457  
458 0 ▶sub slurp_log {
Subroutine slurp_log: not called CC=2 SCAR=17.9
Pod documented
459 0 my $self = shift;
460 0 my $log = $self->basename() . '.log';
461  
462 open(my $LOG, '<', "$self->{fileset}->{dir}/$log")
463 0 ▶ || $self->{fileset}->{log}->error("Could not open log file '$log' produced by (la)tex.");
Branch: 1 branch
BranchTrueFalseTotal
open my $LOG, "<", qq[$self->{"fileset"}{"dir"}/$log] or $self->{"fileset"}{"log"}->error("Could not open log file '${log}' produced by (la)tex.") 0 0 0
464 0 local $/ = undef;
465 0 my $log_contents = <$LOG>;
466 0 close $LOG;
467 0 return \$log_contents;
468 }
469  
470 0 ▶sub clean_aux_files {
Subroutine clean_aux_files: not called CC=6 SCAR=37.4
Pod documented
471 0 my ($self, $stime) = @_;
472  
473 opendir(my $WORKING_DIR, $self->{fileset}->{dir})
474 0 ▶ || $self->{fileset}->{log}->error("Can't open processing directory: $!");
Branch: 1 branch
BranchTrueFalseTotal
opendir my $WORKING_DIR, $self->{"fileset"}{"dir"} or $self->{"fileset"}{"log"}->error("Can't open processing directory: $!") 0 0 0
475 0 ▶ if (my @auxfiles =
Branch: 1 branch
BranchTrueFalseTotal
if (my(@auxfiles) = grep({/\.aux$/ and -f qq[$self->{"fileset"}{"dir"}/$_] and (stat _)[9] >= $stime;} readdir $WORKING_DIR)) 0 0 0
476 0 ▶ grep { /\.aux$/ && -f "$self->{fileset}->{dir}/$_" && (stat(_))[9] >= $stime }
Condition0%0/6
/\.aux$/ && -f "$self->{'fileset'}{'dir'}/$_" && (stat _)[9] >= $stime
!ll&&!rl&&r
000
/\.aux$/ and -f qq[$self->{"fileset"}{"dir"}/$_]
!ll&&!rl&&r
000
MC/DC0%0/3
/\.aux$/ && -f "$self->{'fileset'}{'dir'}/$_" && (stat _)[9] >= $stime
/\.aux$/ -f qq[$self->{"fileset"}{"dir"}/$_] (stat _)[9] >= $stime
Truth table0%0/4
A and B && C
A= /\.aux$/B= -f qq[$self->{"fileset"}{"dir"}/$_]C= (stat _)[9] >= $stime
ABCresult
0XX0
10X0
1100
1111
477 readdir $WORKING_DIR) {
478 my $numauxfiles = unlink(
479 0 map { "$self->{fileset}->{dir}/$_" }
480 0 map { m/(.*)/ }
481 @auxfiles
482 )
483 0 ▶ || $self->{fileset}->{log}->error("Could not remove one of the auxfiles: @auxfiles.");
Condition0%0/3
unlink(map({"$self->{'fileset'}{'dir'}/$_";} map({/(.*)/;} @auxfiles))) || $self->{'fileset'}{'log'}->error("Could not remove one of the auxfiles: @auxfiles.")
l!l&&r!l&&!r
000
MC/DC0%0/2
unlink(map({"$self->{'fileset'}{'dir'}/$_";} map({/(.*)/;} @auxfiles))) || $self->{'fileset'}{'log'}->error("Could not remove one of the auxfiles: @auxfiles.")
unlink(map({"$self->{'fileset'}{'dir'}/$_";} map({/(.*)/;} @auxfiles))) $self->{'fileset'}{'log'}->error("Could not remove one of the auxfiles: @auxfiles.")
Truth table0%0/3
A || B
A= unlink(map({"$self->{'fileset'}{'dir'}/$_";} map({/(.*)/;} @auxfiles)))B= $self->{'fileset'}{'log'}->error("Could not remove one of the auxfiles: @auxfiles.")
ABresult
1X1
011
000
484 0 $self->{fileset}->{log}->verbose("unlinked $numauxfiles '.aux' files");
485 }
486 0 closedir($WORKING_DIR);
487 0 return;
488 }
489  
490 0 ▶sub swap_source {
Subroutine swap_source: not called CC=7 SCAR=40.3
Pod documented
491 0 my ($self, $hyper) = @_;
492  
493 0 my $file = $self->{filename};
494 0 my $dir = $self->{fileset}->{dir};
495  
496 # remove aux files if any
497 0 my $basename = $self->basename();
498 0 foreach my $auxfile (grep {-e "$dir/$_"} map {"$basename.$_"} qw(aux lot lof toc)) {
499 0 ▶ unlink "$dir/$auxfile" or $self->{fileset}->{log}->error("failed to remove '$auxfile'.");
Branch: 1 branch
BranchTrueFalseTotal
unlink "$dir/$auxfile" or $self->{"fileset"}{"log"}->error("failed to remove '${auxfile}'.") 0 0 0
500 0 $self->{fileset}->{log}->verbose("removed aux file '$auxfile'");
501 }
502  
503 # remove the existing file to be processed, then link the
504 # with/without hyper version to it
505 0 ▶ unlink "$dir/$file" or $self->{fileset}->{log}->error("failed to remove '$file'.");
Branch: 1 branch
BranchTrueFalseTotal
unlink "$dir/$file" or $self->{"fileset"}{"log"}->error("failed to remove '${file}'.") 0 0 0
506  
507 # note that (hard-)linking does not change atime or mtime
508 0 ▶ if ($hyper eq 'hyper') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hyper eq 'hyper') { } 0 0 0
509 link "$dir/$file.with_hyper", "$dir/$file"
510 0 ▶ or $self->{fileset}->{log}->verbose("failed to rename '$file'");
Branch: 1 branch
BranchTrueFalseTotal
link "$dir/$file.with_hyper", "$dir/$file" or $self->{"fileset"}{"log"}->verbose("failed to rename '${file}'") 0 0 0
511 } else {
512 link "$dir/$file.without_hyper", "$dir/$file"
513 0 ▶ or $self->{fileset}->{log}->verbose("failed to rename '$file'");
Branch: 1 branch
BranchTrueFalseTotal
link "$dir/$file.without_hyper", "$dir/$file" or $self->{"fileset"}{"log"}->verbose("failed to rename '${file}'") 0 0 0
514 }
515 0 return;
516 }
517  
518 0 ▶sub run_tex_attempt {
Subroutine run_tex_attempt: not called CC=38 SCAR=73.0
Pod documented
519 0 my $self = shift;
520 0 my ($program, $tex_passes, $process, $stime, $written, $tex_type) = @_;
521  
522 0 my $log = $self->{fileset}->{log};
523  
524 0 ▶ if (!defined $TEXCHR) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $TeX::AutoTeX::File::TEXCHR) 0 0 0
525 0 throw TeX::AutoTeX::TexChrException('TEXCHR not set.');
526 }
527 0 ▶ if ($process->{branch} eq '2' && !defined $ENV{TEXMFCNF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->{"branch"} eq 2 and not defined $ENV{"TEXMFCNF"}) 0 0 0
Condition0%0/3
$process->{"branch"} eq 2 and not defined $ENV{"TEXMFCNF"}
!ll&&!rl&&r
000
MC/DC0%0/2
$process->{"branch"} eq 2 and not defined $ENV{"TEXMFCNF"}
$process->{"branch"} eq 2 not defined $ENV{"TEXMFCNF"}
Truth table0%0/3
A and not(B)
A= $process->{"branch"} eq 2B= not defined $ENV{"TEXMFCNF"}
ABresult
0X0
100
111
528 0 throw TeX::AutoTeX::TexMFCnfException('TEXMFCNF not set for /2 branch.');
529 }
530 #TS: find the source of STDIN input to be used. this was historically used for
531 # macros which required user input -- e.g. big or little (b/l)
532 0 my $latex_input = $self->basename() . '.inp';
533 0 ▶ my $feeder = -e "$self->{fileset}->{dir}/$latex_input" ? qq{'$latex_input'} : '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
-e "$self->{'fileset'}{'dir'}/$latex_input" ? : 0 0 0
534  
535 0 ▶ my $tex_format = $self->{tex_format} || q{};
Condition0%0/2
$self->{'tex_format'} || ''
l!l
00
MC/DC0%0/1
$self->{'tex_format'} || ''
$self->{'tex_format'}
Truth table0%0/2
A
A= $self->{'tex_format'}
Aresult
11
00
536 0 my $escaped_tex_format = q{};
537  
538 0 ▶ if (!$tex_format && $tex_type eq 'htex') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tex_format and $tex_type eq "htex") 0 0 0
Condition0%0/3
not $tex_format and $tex_type eq "htex"
!ll&&!rl&&r
000
MC/DC0%0/2
not $tex_format and $tex_type eq "htex"
not $tex_format $tex_type eq "htex"
Truth table0%0/3
not(A) and B
A= not $tex_formatB= $tex_type eq "htex"
ABresult
0X0
100
111
539 0 $tex_format = 'htex';
540 }
541 0 ▶ if ($tex_format !~ /209$/ && $tex_type =~ /209/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tex_format =~ /209$/ and $tex_type =~ /209/) 0 0 0
Condition0%0/3
not $tex_format =~ /209$/ and $tex_type =~ /209/
!ll&&!rl&&r
000
MC/DC0%0/2
not $tex_format =~ /209$/ and $tex_type =~ /209/
not $tex_format =~ /209$/ $tex_type =~ /209/
Truth table0%0/3
not(A) and B
A= not $tex_format =~ /209$/B= $tex_type =~ /209/
ABresult
0X0
100
111
542 0 $tex_format .= '209';
543 }
544 0 ▶ if ($tex_format =~ /^latex209/ && $program =~ /^h/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tex_format =~ /^latex209/ and $program =~ /^h/) 0 0 0
Condition0%0/3
$tex_format =~ /^latex209/ and $program =~ /^h/
!ll&&!rl&&r
000
MC/DC0%0/2
$tex_format =~ /^latex209/ and $program =~ /^h/
$tex_format =~ /^latex209/ $program =~ /^h/
Truth table0%0/3
A and B
A= $tex_format =~ /^latex209/B= $program =~ /^h/
ABresult
0X0
100
111
545 0 $tex_format = 'hlatex209';
546 }
547 0 ▶ if ($tex_format){
Branch: 1 branch
BranchTrueFalseTotal
if ($tex_format) 0 0 0
548 ## TS: FIXME
549 ## static lookup table instead of (convoluted) regexp. should go into
550 ## TeX::AutoTeX::Config? here is the list of all formats available in
551 ## arXiv's tex installation. For texlive 2009 and newer arXiv doesn't
552 ## build custom formats any longer.
553 0 my %known_formats;
554 0 @{$known_formats{'3'}}{qw(
555 amstex
556 htex
557 tex
558 latex
559 biglatex
560 pdfamstex
561 pdflatex
562 pdftex
563 )} = ();
564  
565 0 @{$known_formats{'2'}}{qw(
566 amslatex1.1
567 amslplain
568 amstex
569 biglatex
570 bigtex
571 cp-aa
572 hlatex209
573 hlatex2e
574 hlatex
575 hlplain
576 hplain
577 htex
578 latex209
579 latex2e
580 latex
581 lplain
582 plain
583 tex
584 texsis
585 )} = ();
586  
587 0 ▶ if (exists $known_formats{$process->{branch}}{$tex_format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $known_formats{$process->{'branch'}}{$tex_format}) { } 0 0 0
588 0 $log->verbose("Using format file $tex_format");
589 0 $escaped_tex_format = q{&} . $tex_format;
590 # escape (&) in $tex_format and remove double quotes
591 # TS: where would those come from after the lookup table replaced older code?
592 0 $escaped_tex_format =~ s/&/\\\&/g;
593 0 $escaped_tex_format =~ s/"//g; # "
594 } else {
595 0 $log->verbose("'$tex_format' is not a valid TeX format; will ignore.");
596 }
597 }
598  
599 0 ▶ my $setenv = qq{export HOME=/tmp @{[$ENV{TEXMFCNF}? "TEXMFCNF=$ENV{TEXMFCNF}": q{}]} PATH=$process->{tex_env_path}};
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'TEXMFCNF'} ? : 0 0 0
600 0 ▶ $log->verbose(qq{TEXMFCNF is @{[$ENV{TEXMFCNF}? "set to: '$ENV{TEXMFCNF}'": 'unset.']}});
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'TEXMFCNF'} ? : 0 0 0
601 0 my $crdir = substr $self->{fileset}->{dir}, length $TEX_PATH;
602 0 my $runtexcommand = qq#$TEXCHR $TEX_PATH "($setenv; cd $crdir && $program $escaped_tex_format '$self->{filename}' < $feeder)" 2>&1#;
603  
604 0 my $passes = 0;
605 0 my $rerun = 0;
606 0 my $extra_pass = 0;
607 0 my $xfontcreate = 0;
608 0 my $lastlog_ref;
609 my $failed;
610  
611 0 my @ORDER = qw(first second third fourth fifth sixth seventh);
612  
613 PASSES:
614 0 ▶ while ($passes < $tex_passes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($passes < $tex_passes) 0 0 0
615 0 $log->verbose(" ~~~~~~~~~~~ Running $tex_type for the $ORDER[$passes] time ~~~~~~~~");
616 0 $log->verbose('Running: ' . substr $runtexcommand, length "$TEXCHR $TEX_PATH ");
617 0 my $out = `$runtexcommand`;
618 0 $log->verbose($out);
619 0 $lastlog_ref = $self->slurp_log();
620  
621 # TS: This is due to peculiarities of feynmf and similar dynamical font
622 # creation. If we get an error exit status from latex then we need to
623 # check for new font files and possibly rerun. Only do this once, in
624 # case the non-zero exit status is due to some problem other than
625 # font-creation and persistent, otherwise this could loop indefinitely.
626 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
627 0 ▶ if (!$xfontcreate && $self->extra_fontcreation_pass($stime)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $xfontcreate and $self->extra_fontcreation_pass($stime)) { } 0 0 0
Condition0%0/3
not $xfontcreate and $self->extra_fontcreation_pass($stime)
!ll&&!rl&&r
000
MC/DC0%0/2
not $xfontcreate and $self->extra_fontcreation_pass($stime)
not $xfontcreate $self->extra_fontcreation_pass($stime)
Truth table0%0/3
not(A) and B
A= not $xfontcreateB= $self->extra_fontcreation_pass($stime)
ABresult
0X0
100
111
628 0 $xfontcreate++;
629 0 redo PASSES;
630 } else {
631 #the message below is slightly misleading because $program for
632 #latex2e hyper/nohyper is the same.
633 0 $log->verbose("$program '$self->{filename}' failed.");
634 0 $self->trash_tex_aux_files($stime, $written);
635 0 my $dvi = $self->basename() . '.dvi';
636 0 ▶ if (-e "$self->{fileset}->{dir}/$dvi") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e qq[$self->{"fileset"}{"dir"}/$dvi]) 0 0 0
637 0 $log->verbose("removing leftover dvi file '$dvi'");
638 0 ▶ unlink "$self->{fileset}->{dir}/$dvi" or
Branch: 1 branch
BranchTrueFalseTotal
unlink qq[$self->{"fileset"}{"dir"}/$dvi] or $log->verbose("Could not remove file '${dvi}'.") 0 0 0
639 $log->verbose("Could not remove file '$dvi'.");
640 }
641 0 $failed = 1;
642 0 last;
643 }
644 }
645  
646 0 ▶ if ($passes == 0 && ($tex_type eq 'hlatex2e' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($passes == 0 and $tex_type eq "hlatex2e" || $tex_type eq "latex2e" || $tex_type =~ /h?pdflatex/o) 0 0 0
Condition0%0/9
$passes == 0 and $tex_type eq "hlatex2e" || $tex_type eq "latex2e" || $tex_type =~ /h?pdflatex/o
!ll&&!rl&&r
000
$tex_type eq "hlatex2e" or $tex_type eq "latex2e" or $tex_type =~ /h?pdflatex/o
l!l&&r!l&&!r
000
$tex_type eq "hlatex2e" or $tex_type eq "latex2e"
l!l&&r!l&&!r
000
MC/DC0%0/4
$passes == 0 and $tex_type eq "hlatex2e" || $tex_type eq "latex2e" || $tex_type =~ /h?pdflatex/o
$passes == 0 $tex_type eq "hlatex2e" $tex_type eq "latex2e" $tex_type =~ /h?pdflatex/o
Truth table0%0/5
A and B or C or D
A= $passes == 0B= $tex_type eq "hlatex2e"C= $tex_type eq "latex2e"D= $tex_type =~ /h?pdflatex/o
ABCDresult
0XXX0
10000
11XX1
101X1
10011
647 $tex_type eq 'latex2e' ||
648 $tex_type =~ /h?pdflatex/o)) {
649 0 ▶ if (0 <= index ${$lastlog_ref}, 'LaTeX Warning: Writing file `') {
Branch: 1 branch
BranchTrueFalseTotal
if (index(${$lastlog_ref;}, "LaTeX Warning: Writing file `") != -1) 0 0 0
650 0 ▶ while(${$lastlog_ref} =~ /LaTeX Warning: Writing file \`([^']*)\'\./g) { # ')){
Branch: 1 branch
BranchTrueFalseTotal
if (${$lastlog_ref;} =~ /LaTeX Warning: Writing file \`([^']*)\'\./g) 0 0 0
651 0 $written->{$1}++;
652 }
653 }
654 }
655  
656 # TS: added $tex_format b/c otherwise &amslplain will only be processed twice
657 0 ▶ if ($tex_type =~ /latex/i || $tex_format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tex_type =~ /latex/i or $tex_format) { } 0 0 0
Condition0%0/3
$tex_type =~ /latex/i or $tex_format
l!l&&r!l&&!r
000
MC/DC0%0/2
$tex_type =~ /latex/i or $tex_format
$tex_type =~ /latex/i $tex_format
Truth table0%0/3
A or B
A= $tex_type =~ /latex/iB= $tex_format
ABresult
1X1
011
000
658 0 ▶ if (0 <= index(${$lastlog_ref}, q{Label(s) may have changed. Rerun}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (index(${$lastlog_ref;}, 'Label(s) may have changed. Rerun') != -1 or index(${$lastlog_ref;}, 'Warning: Citation(s) may have changed.') != -1 or index(${$lastlog_ref;}, 'Table widths have changed. Rerun LaTeX.') != -1 or index(${$lastlog_ref;}, 'Rerun to get citations correct.') != -1) { } 0 0 0
Condition0%0/9
index(${$lastlog_ref;}, "Label(s) may have changed. Rerun") != -1 or index(${$lastlog_ref;}, "Warning: Citation(s) may have changed.") != -1 or index(${$lastlog_ref;}, "Table widths have changed. Rerun LaTeX.") != -1 or index(${$lastlog_ref;}, "Rerun to get citations correct.") != -1
l!l&&r!l&&!r
000
index(${$lastlog_ref;}, "Label(s) may have changed. Rerun") != -1 or index(${$lastlog_ref;}, "Warning: Citation(s) may have changed.") != -1 or index(${$lastlog_ref;}, "Table widths have changed. Rerun LaTeX.") != -1
l!l&&r!l&&!r
000
index(${$lastlog_ref;}, "Label(s) may have changed. Rerun") != -1 or index(${$lastlog_ref;}, "Warning: Citation(s) may have changed.") != -1
l!l&&r!l&&!r
000
MC/DC0%0/4
index(${$lastlog_ref;}, "Label(s) may have changed. Rerun") != -1 or index(${$lastlog_ref;}, "Warning: Citation(s) may have changed.") != -1 or index(${$lastlog_ref;}, "Table widths have changed. Rerun LaTeX.") != -1 or index(${$lastlog_ref;}, "Rerun to get citations correct.") != -1
index(${$lastlog_ref;}, "Label(s) may have changed. Rerun") != -1 index(${$lastlog_ref;}, "Warning: Citation(s) may have changed.") != -1 index(${$lastlog_ref;}, "Table widths have changed. Rerun LaTeX.") != -1 index(${$lastlog_ref;}, "Rerun to get citations correct.") != -1
Truth table0%0/5
A or B or C or D
A= index(${$lastlog_ref;}, "Label(s) may have changed. Rerun") != -1B= index(${$lastlog_ref;}, "Warning: Citation(s) may have changed.") != -1C= index(${$lastlog_ref;}, "Table widths have changed. Rerun LaTeX.") != -1D= index(${$lastlog_ref;}, "Rerun to get citations correct.") != -1
ABCDresult
1XXX1
01XX1
001X1
00011
00000
659 0 0 <= index(${$lastlog_ref}, q{Warning: Citation(s) may have changed.}) ||
660 0 0 <= index(${$lastlog_ref}, q{Table widths have changed. Rerun LaTeX.}) ||
661 0 0 <= index(${$lastlog_ref}, q{Rerun to get citations correct.})
662 ) {
663 0 $rerun = 1;
664 } else {
665 0 $rerun = $self->extra_pass($stime);
666 }
667 } else {
668 0 $rerun = 0;
669 }
670 # TS: this seems to be contraproductive to the $tex_passes=4 for &amslplain
671 # and possibly others
672 0 ▶ last unless $rerun || $passes == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $rerun or $passes == 0 0 0 0
Condition0%0/3
$rerun or $passes == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$rerun or $passes == 0
$rerun $passes == 0
Truth table0%0/3
A or B
A= $rerunB= $passes == 0
ABresult
1X1
011
000
673 0 $passes++;
674 } # End of while ($passes < $tex_passes)
675  
676 0 ▶ if ($passes == $tex_passes && $rerun) {
Branch: 1 branch
BranchTrueFalseTotal
if ($passes == $tex_passes and $rerun) 0 0 0
Condition0%0/3
$passes == $tex_passes and $rerun
!ll&&!rl&&r
000
MC/DC0%0/2
$passes == $tex_passes and $rerun
$passes == $tex_passes $rerun
Truth table0%0/3
A and B
A= $passes == $tex_passesB= $rerun
ABresult
0X0
100
111
677 0 $log->verbose("WARNING: Reached max number of passes, possibly failed to get CROSS-REFERENCES right.");
678 }
679 0 $self->trash_tex_aux_files($stime, $written);
680 0 return $failed;
681 }
682  
683 0 ▶sub extra_pass {
Subroutine extra_pass: not called CC=4 SCAR=30.0
Pod documented
684 0 my ($self, $younger_than) = @_;
685  
686 0 opendir my $CDIR, $self->{fileset}->{dir};
687 my $tocloflot =
688 0 ▶ grep {/\.(?:toc|lof|lot)$/ && -f "$self->{fileset}->{dir}/$_" && ((stat(_))[9] >= $younger_than)}
Condition0%0/6
/\.(?:toc|lof|lot)$/ && -f "$self->{'fileset'}{'dir'}/$_" && (stat _)[9] >= $younger_than
!ll&&!rl&&r
000
/\.(?:toc|lof|lot)$/ and -f qq[$self->{"fileset"}{"dir"}/$_]
!ll&&!rl&&r
000
MC/DC0%0/3
/\.(?:toc|lof|lot)$/ && -f "$self->{'fileset'}{'dir'}/$_" && (stat _)[9] >= $younger_than
/\.(?:toc|lof|lot)$/ -f qq[$self->{"fileset"}{"dir"}/$_] (stat _)[9] >= $younger_than
Truth table0%0/4
A and B && C
A= /\.(?:toc|lof|lot)$/B= -f qq[$self->{"fileset"}{"dir"}/$_]C= (stat _)[9] >= $younger_than
ABCresult
0XX0
10X0
1100
1111
689 readdir $CDIR;
690 0 closedir $CDIR;
691 0 ▶ if ($tocloflot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tocloflot) 0 0 0
692 #TS: here a toc/lof/lot will always lead to max number of runs
693 # this is more robust than attempting to keep it to minimum
694 # in particular since a long toc etc. can lead to a shift between
695 # 3rd and 4th pass without any indication of such in the log
696  
697 0 $self->{fileset}->{log}->verbose('LaTeX wrote a .toc, .lof, or .lot file - running extra passes');
698 0 return 1;
699 }
700 0 return 0;
701 }
702  
703 0 ▶sub extra_fontcreation_pass {
Subroutine extra_fontcreation_pass: not called CC=4 SCAR=30.0
Pod documented
704 0 my ($self, $younger_than) = @_;
705  
706 0 opendir my $CDIR, $self->{fileset}->{dir};
707 my $mftfm =
708 0 ▶ grep {/\.(?:mf|tfm)$/ && -f "$self->{fileset}->{dir}/$_" && ((stat(_))[9] >= $younger_than)}
Condition0%0/6
/\.(?:mf|tfm)$/ && -f "$self->{'fileset'}{'dir'}/$_" && (stat _)[9] >= $younger_than
!ll&&!rl&&r
000
/\.(?:mf|tfm)$/ and -f qq[$self->{"fileset"}{"dir"}/$_]
!ll&&!rl&&r
000
MC/DC0%0/3
/\.(?:mf|tfm)$/ && -f "$self->{'fileset'}{'dir'}/$_" && (stat _)[9] >= $younger_than
/\.(?:mf|tfm)$/ -f qq[$self->{"fileset"}{"dir"}/$_] (stat _)[9] >= $younger_than
Truth table0%0/4
A and B && C
A= /\.(?:mf|tfm)$/B= -f qq[$self->{"fileset"}{"dir"}/$_]C= (stat _)[9] >= $younger_than
ABCresult
0XX0
10X0
1100
1111
709 readdir $CDIR;
710 0 closedir $CDIR;
711 0 ▶ if ($mftfm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mftfm) 0 0 0
712 0 $self->{fileset}->{log}->verbose(<<"EOM");
713 LaTeX wrote a .tfm or .mf file -- this indicates feynmf or similar dynamic font generation.
714 Ignoring non-zero exit status and starting over retaining the new font files!
715 EOM
716 0 return 1;
717 }
718 0 return 0;
719 }
720  
721 0 ▶sub trash_tex_aux_files {
Subroutine trash_tex_aux_files: not called CC=8 SCAR=42.8
Pod documented
722 0 my $self = shift;
723 0 my ($younger_than, $written) = @_;
724  
725 0 my $dir = $self->{fileset}->{dir};
726 0 opendir(my $TEMPDIR, $dir);
727 my @files =
728 0 map {/^(.*)$/} # untaint
729 0 ▶ grep {!/^\./ # no dot files
Condition0%0/9
!(/^\./ || /\.(mf|log)$/) && -f "$dir/$_" && (stat _)[9] >= $younger_than
!ll&&!rl&&r
000
not /^\./ || /\.(mf|log)$/ and -f "$dir/$_"
!ll&&!rl&&r
000
/^\./ || /\.(mf|log)$/
l!l&&r!l&&!r
000
MC/DC0%0/4
!(/^\./ || /\.(mf|log)$/) && -f "$dir/$_" && (stat _)[9] >= $younger_than
/^\./ /\.(mf|log)$/ -f "$dir/$_" (stat _)[9] >= $younger_than
Truth table0%0/5
not(A || B) and C && D
A= /^\./B= /\.(mf|log)$/C= -f "$dir/$_"D= (stat _)[9] >= $younger_than
ABCDresult
1XXX0
01XX0
000X0
00100
00111
730 && !/\.(mf|log)$/ # need metafont files and associated log for labels
731 && -f "$dir/$_" # recently modified files only
732 && (stat(_))[9] >= $younger_than}
733 readdir $TEMPDIR;
734 0 closedir $TEMPDIR;
735  
736 0 foreach my $file (@files) {
737 # Warn about files written by latex but still delete them.
738 # We do not want people to include figures by dumping them out
739 # from the tex file using the LaTeX2e filecontents environment.
740 # Simeon-21Jul2000
741 0 ▶ if ($written->{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($written->{$file}) 0 0 0
742 0 $self->{fileset}->{log}->verbose("TeX wrote out '$file', going to delete it as we don't permit filecontents inclusion of figures.");
743 0 delete $written->{$file};
744 }
745 0 my $fmt = $self->{fileset}->new_File($file)->type();
746 0 ▶ next if grep {$fmt eq 'TYPE_' . $_} qw(DVI POSTSCRIPT PDF);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$fmt eq 'TYPE_' . $_;} "DVI", "POSTSCRIPT", "PDF" 0 0 0
747  
748 0 my $age = (stat("$dir/$file"))[9]; #TS FIXME: expensive stat for logging
749 0 $self->{fileset}->{log}->verbose("Removing (La)TeX AUX file called '$file' ($age >= $younger_than)");
750 unlink "$dir/$file"
751 0 ▶ or $self->{fileset}->{log}->error("failed to remove '$file': $!");
Branch: 1 branch
BranchTrueFalseTotal
unlink "$dir/$file" or $self->{"fileset"}{"log"}->error("failed to remove '${file}': $!") 0 0 0
752 }
753 0 return 0;
754 }
755  
756 #######################################################################
757 # basename()
758 # takes filename from AutoTeX::File object, removes its extension if it has
759 # one, caches and returns result.
760 # a special case is a filename ending in '.'. in this
761 # context, it should also be removed.
762 # substr/rindex is 3x faster than regexp s/\.[^.]*$//;
763  
764 0 ▶sub basename {
Subroutine basename: not called CC=3 SCAR=24.8
Pod documented
765 0 my $self = shift;
766 0 ▶ if (!defined $self->{basename}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"basename"}) 0 0 0
767 0 ▶ if (0 < index $self->{filename}, q{.}) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < index($self->{'filename'}, '.')) { } 0 0 0
768 0 $self->{basename} = substr $self->{filename}, 0, rindex($self->{filename}, q{.});
769 } else {
770 0 $self->{basename} = $self->{filename};
771 }
772 }
773 0 return $self->{basename};
774 }
775  
776 2 1;
777  
778 __END__
« AutoTeX/HyperTeX.pm ↑ Summary AutoTeX/Process.pm »