Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/latexml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ UseLog(undef);
if (!$serialized) { }
elsif ($destination) {
my $OUTPUT;
open($OUTPUT, ">", $destination) or die "Couldn't open output file $destination: $!";
pathname_openfile($OUTPUT, ">", $destination) or die "Couldn't open output file $destination: $!";
print $OUTPUT $serialized;
close($OUTPUT); }
else {
Expand Down Expand Up @@ -163,7 +163,7 @@ sub validate_args {

# Check search paths
@paths = map { pathname_canonical($_) } reverse(@paths);
if (my @baddirs = grep { !-d $_ } @paths) {
if (my @baddirs = grep { !pathname_test_d($_) } @paths) {
push(@fails, "These search path do not exist: " . join(', ', @baddirs)); }

# Find the requested source
Expand All @@ -178,7 +178,7 @@ sub validate_args {
}
elsif (!($pathname = pathname_find($source, types => ['tex', 'bib', ''], paths => ['.', @paths])
|| ($initfile && pathname_kpsewhich($source, types => ['tex', 'ltx'], paths => ['.', @paths])))
|| !-r $pathname) {
|| !pathname_test_r($pathname)) {
push(@fails, "Input file '$source' not readable"); }
else {
$mode = 'BibTeX' if !defined $mode && ($pathname =~ /\.bib$/);
Expand All @@ -197,7 +197,7 @@ sub validate_args {
$destination = pathname_canonical($destination);
if (my $dir = pathname_directory($destination)) {
# -w is not about writeability on Windows, see https://perldoc.perl.org/perlport#-X
if (!(pathname_mkdir($dir) && ($^O eq 'MSWin32' || -w $dir))) {
if (!(pathname_mkdir($dir) && ($^O eq 'MSWin32' || pathname_test_w($dir)))) {
push(@fails, "Couldn't create writable destination directory $dir: $!"); } } }
if($initfile && !$destination){
push(@fails, "No destination for dump of $initfile"); }
Expand Down
10 changes: 5 additions & 5 deletions bin/latexmlc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use JSON::XS qw(decode_json);

# Determine if a socket server is installed locally and obtain its pathname:
my $latexmls;
$latexmls = catfile($RealBin_safe, 'latexmls') if (-e catfile($RealBin_safe, 'latexmls'));
$latexmls = catfile($RealBin_safe, 'latexmls') if pathname_test_e(catfile($RealBin_safe, 'latexmls'));
$latexmls = which('latexmls') unless defined $latexmls;

# Some defaults:
Expand Down Expand Up @@ -84,7 +84,7 @@ if (!$opts->get('base')) {

# Record if destination exists, for summary
my $deststat;
$deststat = (stat($opts->get('destination')))[9] if $opts->get('destination');
$deststat = (pathname_stat($opts->get('destination')))[9] if $opts->get('destination');
$deststat = 0 unless defined $deststat;

push @$keyvals, ['path', $cdir]; #add current path, to ensure never empty
Expand Down Expand Up @@ -117,7 +117,7 @@ if (!$logfile) {
$opts->set('log', $logfile); }
# A bit special: Since LaTeXML.pm will always try to append to the log file
# make sure the file is new before we start.
unlink($logfile) if (-f $logfile);
unlink($logfile) if pathname_test_f($logfile);

#***************************************************************************
# Prepare output variables:
Expand Down Expand Up @@ -185,7 +185,7 @@ if ($result) {
# has ALREADY encoded (in this case to utf8), so NO encode is needed!
if ($destination) {
my $output_handle;
open($output_handle, ">", $destination) or die("Fatal:I/O:forbidden Couldn't open output file " . $destination . ": $!");
pathname_openfile($output_handle, ">", $destination) or die("Fatal:I/O:forbidden Couldn't open output file " . $destination . ": $!");
if ($whatsout eq 'archive') {
binmode($output_handle, ':raw');
}
Expand All @@ -206,7 +206,7 @@ if ($status_code == 3 || ($status =~ /fatal error/)) { # non-zero exit code f
# == Helpers ==
sub summary {
my ($destination, $prior_stat) = @_;
my $new_stat = (stat($destination))[9] || 0;
my $new_stat = (pathname_stat($destination))[9] || 0;
return ($new_stat && ($prior_stat != $new_stat)) ? "\nWrote $destination\n" :
"\nError! Did not write file $destination\n"; }

Expand Down
12 changes: 6 additions & 6 deletions bin/latexmlmath
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ EODoc
# Digest the TeX
#======================================================================
@paths = map { pathname_canonical($_) } @paths;
if (my @baddirs = grep { !-d $_ } @paths) {
if (my @baddirs = grep { !pathname_test_d($_) } @paths) {
warn "$LaTeXML::IDENTITY: these path directories do not exist: " . join(', ', @baddirs) . "\n"; }

my $latexml = LaTeXML::Core->new(preload => ['LaTeX.pool', @preload], searchpaths => [@paths],
Expand Down Expand Up @@ -190,7 +190,7 @@ if ($mathimage) {
DirectMathImages->new(magnification => $mag,
imagename => $mathimage, imagetype => $imagetype,
%OPTIONS));
unlink('LaTeXML.cache'); }
pathname_unlink('LaTeXML.cache'); }

if ($mathsvg) {
my $imagetype = 'svg';
Expand All @@ -201,18 +201,18 @@ if ($mathsvg) {
imagename => $tmpfile, imagetype => $imagetype,
%OPTIONS));
my $SVG;
open($SVG, '<', "$tmpfile.svg") or die "Couldn't read temporary svg output '$tmpfile': $!";
pathname_openfile($SVG, '<', "$tmpfile.svg") or die "Couldn't read temporary svg output '$tmpfile': $!";
while (<$SVG>) {
print $_; }
close($SVG);
unlink "$tmpfile.svg"; }
pathname_unlink("$tmpfile.svg"); }
else {
$mathsvg =~ s/\.svg$//;
my ($result) = $post->ProcessChain(cloneDoc($document),
DirectMathImages->new(magnification => $mag,
imagename => $mathsvg, imagetype => $imagetype,
%OPTIONS)); }
unlink('LaTeXML.cache'); }
pathname_unlink('LaTeXML.cache'); }

if ($pmml) {
require LaTeXML::Post::MathML::Presentation;
Expand Down Expand Up @@ -293,7 +293,7 @@ sub outputText {
if (my $dir = pathname_directory($destination)) {
pathname_mkdir($dir) or die "Couldn't create destination directory $dir: $!"; }
my $OUT;
open($OUT, '>', $destination) or die "Couldn't open output file $destination: $!";
pathname_openfile($OUT, '>', $destination) or die "Couldn't open output file $destination: $!";
binmode($OUT, ":encoding(UTF-8)");
print $OUT $serialized;
close($OUT); }
Expand Down
6 changes: 3 additions & 3 deletions bin/latexmlpost
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ eval { # Catch errors
our %OPTIONS = (
searchpaths => ['.', @paths, $DOCUMENT->getSearchPaths],
);
if (defined $dbfile && !-f $dbfile) {
if (defined $dbfile && !pathname_test_f($dbfile)) {
if (my $dbdir = pathname_directory($dbfile)) {
pathname_mkdir($dbdir); } }
my $DB = LaTeXML::Util::ObjectDB->new(dbfile => $dbfile, %OPTIONS);
Expand Down Expand Up @@ -228,7 +228,7 @@ sub validate_args {

# Check search paths
@paths = map { pathname_canonical($_) } reverse(@paths);
if (my @baddirs = grep { !-d $_ } @paths) {
if (my @baddirs = grep { !pathname_test_d($_) } @paths) {
push(@fails, "These search paths do not exist: " . join(', ', @baddirs)); }

# Find the requested XML file
Expand All @@ -238,7 +238,7 @@ sub validate_args {
elsif ($xmlfile eq '-') { # Any sense in pre-reading it here??
}
elsif (!($pathname = pathname_find($xmlfile, types => ['xml', ''], paths => ['.', @paths]))
|| !-r $pathname) {
|| !pathname_test_r($pathname)) {
push(@fails, "Input file '$xmlfile' not readable"); }
else {
$xmlfile = $pathname; }
Expand Down
6 changes: 3 additions & 3 deletions lib/LaTeXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ sub convert_post {
my @procs = ();
#TODO: Add support for the following:
my $dbfile = $$opts{dbfile};
if (defined $dbfile && !-f $dbfile) {
if (defined $dbfile && !pathname_test_f($dbfile)) {
if (my $dbdir = pathname_directory($dbfile)) {
pathname_mkdir($dbdir); } }
my $DB = LaTeXML::Util::ObjectDB->new(dbfile => $dbfile, %PostOPS);
Expand Down Expand Up @@ -632,7 +632,7 @@ sub convert_post {
NoteLog(($$opts{recursive} ? "recursive " : "") . "processing finished " . localtime());
my $archive_log_status_code = max($$runtime{status_code}, $latexmlpost->getStatusCode);
Note("Status:conversion:" . $archive_log_status_code);
open my $log_fh, '>', $log_file;
pathname_openfile(my $log_fh, '>', $log_file);
print $log_fh $self->flush_log;
close $log_fh;
$self->bind_log; }
Expand Down Expand Up @@ -702,7 +702,7 @@ sub new_latexml {
nomathparse => $$opts{nomathparse}, # Backwards compatibility
mathparse => $$opts{mathparse});

if (my @baddirs = grep { !-d $_ } @{ $$opts{paths} }) {
if (my @baddirs = grep { !pathname_test_d($_) } @{ $$opts{paths} }) {
warn "\n$LaTeXML::IDENTITY : these path directories do not exist: " . join(', ', @baddirs) . "\n"; }

$latexml->withState(sub {
Expand Down
4 changes: 2 additions & 2 deletions lib/LaTeXML/Common/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ sub _read_options_file {
my $OPT;
#### Now can we report status to right places before we've gotten configuration??? (verbosity, logfile...)
#### ProgressSpinup("Loading profile $file");
unless (open($OPT, "<", $file)) {
unless (pathname_openfile($OPT, "<", $file)) {
Error('expected', $file, "Could not open options file '$file'");
return; }
while (my $line = <$OPT>) {
Expand Down Expand Up @@ -662,7 +662,7 @@ sub _read_options_file {
# But also the standard behaviour, where the $env is an array of paths
$env_value = $ENV{$env_name};
next unless $env_value;
@values = grep { -d $_ } reverse(split(':', $env_value));
@values = grep { pathname_test_d($_) } reverse(split(':', $env_value));
next unless @values; }
CORE::push(@$opts, "--$key=$_") foreach (@values); }
else {
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Common/Error.pm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ sub UseLog {
$log_count++;
return if $LOG or not($path); # already opened?
pathname_mkdir(pathname_directory($path)); # and hopefully no errors! :>
open($LOG, ($append ? '>>' : '>'), $path) or die "Cannot open log file $path for writing: $!";
pathname_openfile($LOG, ($append ? '>>' : '>'), $path) or die "Cannot open log file $path for writing: $!";
$LOG_PATH = $path;
binmode($LOG, ":encoding(UTF-8)"); }
return; }
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Common/Font/Metric.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sub read_tfm {
my $pathname = $$self{file};
# Read the TFM raw data.
my $TFM;
if (!open($TFM, '<', $pathname)) {
if (!pathname_openfile($TFM, '<', $pathname)) {
Error('expected', $pathname, undef,
"Couldn't open TFM files '$pathname': $!");
return; }
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Common/Model.pm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ sub loadCompiledSchema {
my ($self, $file) = @_;
ProgressSpinup("Loading compiled schema $file");
my $MODEL;
open($MODEL, '<', $file) or Fatal('I/O', $file, undef, "Cannot open Compiled Model $file for reading", $!);
pathname_openfile($MODEL, '<', $file) or Fatal('I/O', $file, undef, "Cannot open Compiled Model $file for reading", $!);
my $line;
while ($line = <$MODEL>) {
if ($line =~ /^([^\{]+)\{(.*?)\}\((.*?)\)$/) {
Expand Down
3 changes: 2 additions & 1 deletion lib/LaTeXML/Common/XML/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package LaTeXML::Common::XML::Parser;
use strict;
use warnings;
use LaTeXML::Util::Pathname;
use XML::LibXML;

sub new {
Expand All @@ -24,7 +25,7 @@ sub parseFile {
my ($self, $file) = @_;
LaTeXML::Common::XML::initialize_catalogs();
# LaTeXML::Common::XML::initialize_input_callbacks($$self{parser});
if (((-s $file) || 0) > 20_000_000) {
if ((pathname_test_s($file) || 0) > 20_000_000) {
$$self{parser}->set_option('huge', 1); }
return $$self{parser}->parse_file($file); }

Expand Down
6 changes: 3 additions & 3 deletions lib/LaTeXML/Core/Mouth/file.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ sub new {
sub openFile {
my ($self, $pathname) = @_;
my $IN;
if (!-r $pathname) {
if (!pathname_test_r($pathname)) {
Error('I/O', 'unreadable', $self, "File $pathname is not readable. Ignoring."); }
elsif ((!-z $pathname) && (-B $pathname)) {
elsif (!pathname_test_z($pathname) && pathname_test_B($pathname)) {
Error('invalid', 'binary', $self, "Input file $pathname appears to be binary. Ignoring."); }
elsif (open($IN, '<:raw', $pathname)) { }
elsif (pathname_openfile($IN, '<:raw', $pathname)) { }
else {
Error('I/O', 'open', $self, "Can't open $pathname for reading", $!); }
$$self{IN} = $IN;
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Engine/pdfTeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ DefMacro('\pdffilesize{}', sub {
# used in expl3's \__file_full_name:n , among others
my ($gullet, $file) = @_;
if (my $path = FindFile(ToString(Expand($file)))) {
my @stat = stat $path;
my @stat = pathname_stat($path);
return (defined $stat[7]) ? Explode($stat[7]) : (); }
else {
return (); } });
Expand Down
8 changes: 4 additions & 4 deletions lib/LaTeXML/Package.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2087,8 +2087,8 @@ sub FindFile_aux {
return $file; }
if (pathname_is_absolute($file)) { # And if we've got an absolute path,
if (!$options{noltxml}) {
return $file . '.ltxml' if -f ($file . '.ltxml'); } # No need to search, just check if it exists.
return $file if -f $file; # No need to search, just check if it exists.
return $file . '.ltxml' if pathname_test_f($file . '.ltxml'); } # No need to search, just check if it exists.
return $file if pathname_test_f($file); # No need to search, just check if it exists.
return; } # otherwise we're never going to find it.

# Note that the strategy is complicated by the fact that
Expand Down Expand Up @@ -2132,7 +2132,7 @@ sub FindFile_aux {
local $ENV{TEXINPUTS} = join($Config::Config{'path_sep'},
@$paths, $ENV{TEXINPUTS} || $Config::Config{'path_sep'});
if (my $result = (!$options{searchpaths_only}) && pathname_kpsewhich(@candidates)) {
return (-f $result ? $result : undef); }
return pathname_test_f($result) ? $result : undef; }
if ($urlbase && ($path = url_find($file, urlbase => $urlbase))) {
return $path; }
return; }
Expand Down Expand Up @@ -2760,7 +2760,7 @@ sub maybeRequireDependencies {
if (my $path = FindFile($file, type => $type, noltxml => 1)) {
local $/ = undef;
my $IN;
if (open($IN, '<', $path)) {
if (pathname_openfile($IN, '<', $path)) {
my $code = <$IN>;
close($IN);
my @classes = ();
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/listings.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ sub listingsReadRawFile {
my $path = FindFile($filename);
my $text;
my $LST_FH;
if ($path && open($LST_FH, '<', $path)) {
if ($path && pathname_openfile($LST_FH, '<', $path)) {
{ local $/ = undef;
$text = <$LST_FH>;
close($LST_FH); } }
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Post.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ sub openCache {
or return Fatal('internal', 'db', undef,
"Couldn't create DB cache for " . $self->getDestination,
"Message was: " . $!,
(-f $dbfile ? "\n(possibly incompatible db format?)" : ''));
(pathname_test_f($dbfile) ? "\n(possibly incompatible db format?)" : ''));
}
return; }

Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Post/Graphics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ sub findGraphicFile {
my ($self, $doc, $node) = @_;
if (my $source = $node->getAttribute('graphic')) {
# if we already have a usable candidate, save ourselves the work
my @paths = grep { -e $_ } split(',', $node->getAttribute('candidates') || '');
my @paths = grep { pathname_test_e($_) } split(',', $node->getAttribute('candidates') || '');
if (!scalar(@paths)) {
# Find all acceptable image files, in order of search paths
my ($dir, $name, $reqtype) = pathname_split($source);
Expand Down
16 changes: 8 additions & 8 deletions lib/LaTeXML/Post/LaTeXImages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ sub generateImages {
foreach my $key (sort keys %table) {
my $store = $doc->cacheLookup($key);
if ($store && ($store =~ /^(.*);(\d+);(\d+);(\d+)$/)) {
next if -f pathname_absolute($1, $destdir); }
next if pathname_test_f(pathname_absolute($1, $destdir)); }
push(@pending, $table{$key}); }

Debug("LaTeXImages: $nuniq unique; " . scalar(@pending) . " new") if $LaTeXML::DEBUG{images};
Expand All @@ -255,7 +255,7 @@ sub generateImages {
# === Generate the LaTeX file.
my $texfile = pathname_make(dir => $workdir, name => $jobname, type => 'tex');
my $TEX;
if (!open($TEX, '>', $texfile)) {
if (!pathname_openfile($TEX, '>', $texfile)) {
Error('I/O', $texfile, undef, "Cant write to '$texfile'", "Response was: $!");
return $doc; }
my ($pre_preamble, $add_to_body) = $self->pre_preamble($doc);
Expand Down Expand Up @@ -288,7 +288,7 @@ sub generateImages {

# Sometimes latex returns non-zero code, even though it apparently succeeded.
# And sometimes it doesn't produce a dvi, even with 0 return code?
if (($ltxerr != 0) || (!-f "$workdir/$jobname.dvi")) {
if ($ltxerr != 0 || !pathname_test_f("$workdir/$jobname.dvi")) {
$workdir->unlink_on_destroy(0) if $LaTeXML::DEBUG{images}; # Preserve junk
Error('shell', $LATEXCMD, undef,
"LaTeX command '$ltxcommand' failed",
Expand All @@ -302,7 +302,7 @@ sub generateImages {
# Extract dimensions (width x height+depth) from each image from log file.
my @dimensions = ();
my $LOG;
if (open($LOG, '<', "$workdir/$jobname.log")) {
if (pathname_openfile($LOG, '<', "$workdir/$jobname.log")) {
while (<$LOG>) {
if (/^\s*LXIMAGE\s*(\d+)\s*=\s*([\+\-\d\.]+)pt\s*x\s*([\+\-\d\.]+)pt\s*\+\s*([\+\-\d\.]+)pt\s*$/) {
$dimensions[$1] = [$2, $3, $4]; } }
Expand Down Expand Up @@ -334,7 +334,7 @@ sub generateImages {
my ($index, $ndigits) = (0, 1 + int(log($doc->cacheLookup((ref $self) . ':_max_image_') || 1) / log(10)));
foreach my $entry (@pending) {
my $src = "$workdir/" . sprintf($$self{dvicmd_output_name}, ++$index);
if (-f $src) {
if (pathname_test_f($src)) {
my @dests = @{ $$entry{dest} };
push(@dests, $self->generateResourcePathname($doc, $$entry{nodes}[0], undef, $$self{imagetype}))
unless @dests;
Expand Down Expand Up @@ -528,10 +528,10 @@ sub convert_image {

sub DESTROY {
if (my $tmpdir = File::Spec->tmpdir()) {
if (-d $tmpdir && opendir(my $tmpdir_fh, $tmpdir)) {
my @empty_magick = grep { -z $_ } map { "$tmpdir/$_" } readdir($tmpdir_fh);
if (pathname_test_d($tmpdir) && pathname_opendir(my $tmpdir_fh, $tmpdir)) {
my @empty_magick = grep { pathname_test_z($_) } map { "$tmpdir/$_" } readdir($tmpdir_fh);
closedir($tmpdir_fh);
unlink $_ foreach @empty_magick;
pathname_unlink($_) foreach @empty_magick;
} }
return; }

Expand Down
Loading