Browse Source

Markdown.pl: do not ignore input file errors

Rework the code that iterates through all the files given on
the command line and make sure any errors are reported with
a fatal result.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 5 years ago
parent
commit
1b55444333
  1. 28
      Markdown.pl

28
Markdown.pl

@ -44,6 +44,13 @@ $INC{__PACKAGE__.'.pm'} = $INC{basename(__FILE__)} unless exists $INC{__PACKAGE_
close(DATA) if fileno(DATA); close(DATA) if fileno(DATA);
exit(&_main(@ARGV)||0) unless caller; exit(&_main(@ARGV)||0) unless caller;
sub fauxdie($) {
my $msg = join(" ", @_);
$msg =~ s/\s+$//os;
printf STDERR "%s: fatal: %s\n", basename($0), $msg;
exit 1;
}
my $encoder; my $encoder;
BEGIN { BEGIN {
$encoder = Encode::find_encoding('Windows-1252') || $encoder = Encode::find_encoding('Windows-1252') ||
@ -410,19 +417,25 @@ HTML4
#### Process incoming text: ########################### #### Process incoming text: ###########################
my ($didhdr, $hdr, $result, $ftr) = (0, "", "", ""); my ($didhdr, $hdr, $result, $ftr) = (0, "", "", "");
for (;;) { @ARGV or push(@ARGV, "-");
local $_; foreach (@ARGV) {
my ($fh, $contents, $oneresult);
$_ eq "-" or open $fh, '<', $_ or fauxdie "could not open \"$_\": $!\n";
{ {
local $/; # Slurp the whole file local $/; # Slurp the whole file
$_ = <>; $_ eq "-" and $contents = <STDIN>;
$_ ne "-" and $contents = <$fh>;
} }
defined($_) or last; defined($contents) or fauxdie "could not read \"$_\": $!\n";
$result = Markdown($_, \%options); $_ eq "-" or close($fh);
if ($result ne "") { $oneresult = Markdown($contents, \%options);
$oneresult =~ s/\s+$//os;
if ($oneresult ne "") {
if (!$didhdr) { if (!$didhdr) {
$hdr = &$hdrf(); $hdr = &$hdrf();
$didhdr = 1; $didhdr = 1;
} }
$result .= $oneresult . "\n";
} }
} }
$hdr = &$hdrf() unless $didhdr; $hdr = &$hdrf() unless $didhdr;
@ -457,7 +470,8 @@ sub _xmlcheck {
sub _trimerr { sub _trimerr {
my $err = shift; my $err = shift;
1 while $err =~ s{\s+at\s+\.?/[^,\s\n]+\sline\s+[0-9]+\.?(\n|$)}{$1}is; 1 while $err =~ s{\s+at\s+\.?/[^,\s\n]+\sline\s+[0-9]+\.?(\n|$)}{$1}is;
$err; $err =~ s/\s+$//os;
$err . "\n";
} }

Loading…
Cancel
Save