[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: texi2dvi -b not so batch
From: |
Akim Demaille |
Subject: |
Re: texi2dvi -b not so batch |
Date: |
Wed, 09 Feb 2005 18:02:56 +0100 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) |
>>> "Karl" == Karl Berry <address@hidden> writes:
> Hi Akim,
> * util/texi2dvi: More uses of the verbose function.
> By reporting actual errors using $verbose, it means that the
> errors aren't shown unless --verbose is given. E.g.,
> ./texi2dvi nonesuch.texi
> after your patch is silent. That doesn't seem right.
Stupid me :( Sorry, brains off.
> Ok on making the run_tex function, and redirecting from /dev/null, but I
> think I'll ask you to disentangle the patch instead of trying to do so
> myself ...
sure!
Index: ChangeLog
from Akim Demaille <address@hidden>
* util/texi2dvi (report): New. Use it.
(fatal): Take the exit status as argument.
Use report.
(run_tex): New function to factor the two tex invocations.
Move the handling of tex arguments in here to improve locallity.
Enforce the batch mode by branching /dev/null to its stdin.
Index: util/texi2dvi
===================================================================
RCS file: /cvsroot/texinfo/texinfo/util/texi2dvi,v
retrieving revision 1.40
diff -u -u -r1.40 texi2dvi
--- util/texi2dvi 28 Jan 2005 14:41:58 -0000 1.40
+++ util/texi2dvi 9 Feb 2005 16:54:00 -0000
@@ -141,6 +141,15 @@
$foundprog
}
+# Report some information.
+report ()
+{
+ for i in "$@"
+ do
+ echo >&2 "$0: $i"
+ done
+}
+
# Report some verbose information.
verbose ()
{
@@ -150,8 +159,10 @@
# Report an error and exit with failure.
fatal ()
{
- echo >&2 "$0: $*"
- exit 1
+ s=$1
+ shift
+ report "$@"
+ exit $s
}
# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
@@ -224,9 +235,9 @@
done
break;;
-*)
- echo "$0: Unknown or ambiguous option \`$1'." >&2
- echo "$0: Try \`--help' for more information." >&2
- exit 1;;
+ fatal 1 "Unknown or ambiguous option \`$1'." \
+ "Try \`--help' for more information."
+ ;;
*) set dummy ${1+"$@"} "$1"; shift;;
esac
shift
@@ -237,15 +248,12 @@
# Interpret remaining command line args as filenames.
case $# in
0)
- echo "$0: Missing file arguments." >&2
- echo "$0: Try \`--help' for more information." >&2
- exit 2
+ fatal 2 "Missing file arguments." "Try \`--help' for more information."
;;
1) ;;
*)
if test -n "$oname"; then
- echo "$0: Can't use option \`--output' with more than one argument." >&2
- exit 2
+ fatal 2 "Can't use option \`--output' with more than one argument."
fi
;;
esac
@@ -393,6 +401,41 @@
echo "$_res"
}
+
+# run_tex ()
+# ----------
+# Run TeX as "$tex $tex_args $filename_input", taking care of errors
+# and logs.
+run_tex ()
+{
+ # Note that this will be used via an eval: quote properly.
+ cmd=$tex
+
+ # If possible, make TeX report error locations in GNU format.
+ tex_args=
+ case $tex_help in
+ *file-line-error*) cmd="$cmd --file-line-error";;
+ esac
+
+ # Tell TeX to be batch if requested.
+ if $batch; then
+ # \batchmode does not show terminal output at all, so we don't
+ # want that. And even in batch mode, TeX insists on having input
+ # from the user. Close its stdin to make it impossible.
+ cmd="$cmd </dev/null '${escape}nonstopmode' '${escape}input'"
+ fi
+
+ cmd="$cmd '$filename_input'"
+
+ verbose "Running $cmd ..."
+ if eval "$cmd" >&5; then :; else
+ test "$clean" = t \
+ && cp "$filename_noext.log" "$orig_pwd"
+ fatal 1 "$tex exited with bad status, quitting." \
+ "see $filename_noext.log for errors."
+ fi
+}
+
# File descriptor usage:
# 0 standard input
# 1 standard output (--verbose messages)
@@ -432,7 +475,7 @@
# prompt (assuming they're attending the terminal), this script won't
# be able to find the right xref files and so forth.
if test ! -r "$command_line_filename"; then
- echo "$0: Could not read $command_line_filename, skipping." >&2
+ report "Could not read $command_line_filename, skipping."
continue
fi
@@ -557,7 +600,7 @@
if test $? != 0; then
cat $tmpdir/txiversion.out
cat $tmpdir/txiversion.err >&2
- fatal "texinfo.tex appears to be broken, quitting."
+ fatal 1 "texinfo.tex appears to be broken, quitting."
fi
eval `sed -n 's/^.*\[\(.*\)version
\(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'
$tmpdir/txiversion.out`
verbose "texinfo.tex preloaded as \`$txiformat', version is
\`$txiversion' ..."
@@ -577,16 +620,6 @@
# --help will generate a texput.log.
tex_help=`cd $tmpdir >/dev/null && $tex --help </dev/null 2>&1`
- # If possible, make TeX report error locations in GNU format.
- tex_args=
- case $tex_help in
- *file-line-error*) tex_args="$tex_args --file-line-error";;
- esac
-
- # Tell TeX to be batch if requested. (\batchmode does not show
- # terminal output at all, so we don't want that.)
- $batch && tex_args="$tex_args ${escape}nonstopmode ${escape}input"
-
# Expand macro commands in the original source file using Makeinfo.
# Always use `end' footnote style, since the `separate' style
# generates different output (arguably this is a bug in -E).
@@ -677,7 +710,7 @@
then
verbose "Running $bibtex $filename_noext ..."
$bibtex "$filename_noext" >&5 ||
- fatal "$bibtex exited with bad status, quitting."
+ fatal 1 "$bibtex exited with bad status, quitting."
fi
# What we'll run texindex on -- exclude non-index files.
@@ -699,20 +732,11 @@
if test -n "$texindex" && test -n "$index_files"; then
verbose "Running $texindex $index_files ..."
$texindex $index_files 2>&5 1>&2 ||
- fatal "$texindex exited with bad status, quitting."
+ fatal 1 "$texindex exited with bad status, quitting."
fi
# Finally, run TeX.
- cmd="$tex $tex_args"
- verbose "Running $cmd $filename_input ..."
- if $cmd "$filename_input" >&5; then :; else
- echo "$0: $tex exited with bad status, quitting." >&2
- echo "$0: see $filename_noext.log for errors." >&2
- test "$clean" = t \
- && cp "$filename_noext.log" "$orig_pwd"
- exit 1
- fi
-
+ run_tex
# Decide if looping again is needed.
finished=t
@@ -765,16 +789,8 @@
then
verbose "Running $thumbpdf $filename_noext ..."
$thumbpdf "$filename_noext" >&5 ||
- fatal "$thumbpdf exited with bad status, quitting."
-
- verbose "Running $cmd $filename_input..."
- if $cmd "$filename_input" >&5; then :; else
- echo "$0: $tex exited with bad status, quitting." >&2
- echo "$0: see $filename_noext.log for errors." >&2
- test "$clean" = t \
- && cp "$filename_noext.log" "$orig_pwd"
- exit 1
- fi
+ fatal 1 "$thumbpdf exited with bad status, quitting."
+ run_tex
fi
> Unrelated question: what is file descriptor 6 for?
It is to be able to see the result of command so that throw their
output.
> And does texi2dvi really need file descriptor 5 for "tools output"?
No, not really. But it's the same objective: to be able to trace when
something's broken. Both could arguably be a single thing.