diff --git a/hevea-add-verbatim-linenos b/hevea-add-verbatim-linenos index f3dcc3c..56154c0 100755 --- a/hevea-add-verbatim-linenos +++ b/hevea-add-verbatim-linenos @@ -45,4 +45,4 @@ def replace_line(match: re.Match[str]) -> str: with Path(htmlfile).open() as htmlfile_handle: for line in htmlfile_handle: line = lineref_re.sub(replace_line, line) - print(line) + print(line, end="") diff --git a/html-update-link-dates b/html-update-link-dates index af2111f..9de9c8d 100755 --- a/html-update-link-dates +++ b/html-update-link-dates @@ -181,7 +181,7 @@ sub file_size ( $ ) # 5 to the third most significant digit (since we truncate to two # significant digits). my $to_add = "5" . ("0" x (length($size) - 3)); - $trunc_size = sprintf("%f", ($size + $to_add) / $divisor); + my $trunc_size = sprintf("%f", ($size + $to_add) / $divisor); if ($trunc_size =~ m/^([0-9][0-9])([0-9]*)(\.[0-9]*)?$/) { $trunc_size = $1 . "0" x length($2); diff --git a/html-update-toc b/html-update-toc index 765c8fc..d0e5f9f 100755 --- a/html-update-toc +++ b/html-update-toc @@ -101,7 +101,7 @@ FILELOOP: for my $file (@ARGV) } next; } - if (!open(FILE, $file)) + if (!open(FILE, '<', $file)) { print STDERR "Skipping $file: can't open\n"; next; @@ -131,7 +131,13 @@ FILELOOP: for my $file (@ARGV) if ($line =~ /($contents_start)(.*?)($contents_end)/is) { my $oldcontent = $2; - my $newcontent = `$script_dir/html-toc $file`; + open(my $toc_pipe, '-|', "$script_dir/html-toc", $file) + or die "Can't run html-toc: $!"; + my $newcontent = do { local $/; <$toc_pipe> }; + close($toc_pipe) or die( + $! ? "Error closing pipe: $!" + : "html-toc failed for $file (exit status: $?)" + ); if ($newcontent eq "\n") { $newcontent = ""; @@ -156,9 +162,9 @@ FILELOOP: for my $file (@ARGV) # "perl -pi.bak -e '\$/ = \"\\n\\n\"; s/($contents_start_quoted)(.*?)($contents_end_quoted)/\$1$newcontent_quoted\$3/s'" # but that doesn't work: the shell says "word too long". rename($file, "$file.bak") or die "Can't make backup of $file"; - open(OLDFILE, "$file.bak") + open(OLDFILE, '<', "$file.bak") or die "Can't read backup I just made: $file.bak"; - open(FILE, ">$file") + open(FILE, '>', $file) or die "Can't write $file; old version in $file.bak"; while (defined($line = )) {