[PATCH -perfbook 5/7] run{first}latex.sh: Reorder checks of fatal error/warning messages

Akira Yokosawa <[email protected]>
Newsgroups org.kernel.vger.perfbook
Message-ID <[email protected]>
Testing $exitcode and "!pdfTeX error:" or "Emergency stop" early
may ignore an earlier warning that tells the reason of such an
error.

Reorder the checks and make the relevant part of the log file be
printed.

$exitcode should be tested as late as possible.

This improves output when a necessary .sty file is missing:

before:

    or enter new name. (Default extension: sty)

    Enter file name:
    ! Emergency stop.
    <read *>

    l.332 \renewcommand
                       {\sfdefault}{qhv}
    End of file on the terminal!

    Here is how much of TeX's memory you used:
    [...]

after:

    LaTeX Info: Redefining \Bbbk on input line 2810.
    LaTeX Info: Redefining \not on input line 2959.
    )

    ! LaTeX Error: File `biolinum.sty' not found.

    Type X to quit or <RETURN> to proceed,
    or enter new name. (Default extension: sty)

    Enter file name:
    ! Emergency stop.
    [...]

Subsequent runs of latex can also abort due to, e.g., a typo in .bib.
Keep tests of "Emergency stop." and $exitcode in runlatex.sh to
catch such errors.

Signed-off-by: Akira Yokosawa <[email protected]>
---
 utilities/runfirstlatex.sh | 34 +++++++++++++++++++++-------------
 utilities/runlatex.sh      | 18 ++++++------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/utilities/runfirstlatex.sh b/utilities/runfirstlatex.sh
index f12f14886747..a89e8a70ab69 100644
--- a/utilities/runfirstlatex.sh
+++ b/utilities/runfirstlatex.sh
@@ -22,7 +22,7 @@
 #
 # Copyright (C) IBM Corporation, 2012-2019
 # Copyright (C) Facebook, 2019
-# Copyright (C) Akira Yokosawa, 2016
+# Copyright (C) Akira Yokosawa, 2016, 2023
 #
 # Authors: Paul E. McKenney <[email protected]>
 #          Akira Yokosawa <[email protected]>
@@ -72,11 +72,6 @@ basename=`echo $1 | sed -e 's/\.tex$//'`
 echo "$LATEX 1 for $basename.pdf"
 $LATEX $LATEX_OPT $basename > /dev/null 2>&1 < /dev/null
 exitcode=$?
-if [ $exitcode -ne 0 ]; then
-	tail -n 20 $basename.log
-	echo "\n!!! $LATEX aborted !!!"
-	exit $exitcode
-fi
 if grep -q 'LaTeX Warning: You have requested' $basename.log
 then
 	grep -A 4 'LaTeX Warning: You have requested' $basename.log
@@ -84,21 +79,34 @@ then
 	echo "### See items 9 and 10 in FAQ-BUILD.txt for how to update.          ###"
 	exit 1
 fi
-if [ $DETECTED_BUGGY -eq 1 ]; then
-	exit 1
+if grep -q 'LaTeX Error:' $basename.log
+then
+	echo "----- !!! Fatal latex error !!! -----"
+	grep -B 5 -A 8 'LaTeX Error:' $basename.log
+	echo "----- See $basename.log for the full log. -----"
+	exit 2
 fi
-if grep -q '! Emergency stop.' $basename.log
+if grep -q 'pdfTeX error:' $basename.log
 then
-	grep -B 15 -A 5 '! Emergency stop.' $basename.log
-	echo "----- Fatal latex error, see $basename.log for details. -----"
+	echo "----- !!! Fatal pdfTeX error !!! -----"
+	grep -B 10 -A 8 '!pdfTeX error:' $basename.log
+	echo "----- See $basename.log for the full log. -----"
 	exit 2
 fi
-if grep -q '!pdfTeX error:' $basename.log
+if grep -q '! Emergency stop.' $basename.log
 then
-	grep -A 2 '!pdfTeX error:' $basename.log
+	grep -B 10 -A 5 '! Emergency stop.' $basename.log
 	echo "----- Fatal latex error, see $basename.log for details. -----"
 	exit 2
 fi
+if [ $exitcode -ne 0 ]; then
+	tail -n 20 $basename.log
+	echo "\n!!! $LATEX aborted !!!"
+	exit $exitcode
+fi
+if [ $DETECTED_BUGGY -eq 1 ]; then
+	exit 1
+fi
 grep 'LaTeX Warning:' $basename.log > $basename-warning.log
 touch $basename-first.log
 exit 0
diff --git a/utilities/runlatex.sh b/utilities/runlatex.sh
index e23bc87ba978..b146da20559f 100644
--- a/utilities/runlatex.sh
+++ b/utilities/runlatex.sh
@@ -24,7 +24,7 @@
 #
 # Copyright (C) IBM Corporation, 2012-2019
 # Copyright (C) Facebook, 2019
-# Copyright (C) Akira Yokosawa, 2016, 2017
+# Copyright (C) Akira Yokosawa, 2016, 2017, 2023
 #
 # Authors: Paul E. McKenney <[email protected]>
 #          Akira Yokosawa <[email protected]>
@@ -78,22 +78,16 @@ iterate_latex () {
 	makeglossaries $basename > /dev/null 2>&1
 	$LATEX $LATEX_OPT $basename > /dev/null 2>&1 < /dev/null
 	exitcode=$?
-	if [ $exitcode -ne 0 ]; then
-		tail -n 20 $basename.log
-		echo "\n!!! $LATEX aborted !!!"
-		exit $exitcode
-	fi
 	if grep -q '! Emergency stop.' $basename.log
 	then
-		grep -B 15 -A 5 '! Emergency stop.' $basename.log
+		grep -B 10 -A 5 '! Emergency stop.' $basename.log
 		echo "----- Fatal latex error, see $basename.log for details. -----"
 		exit 2
 	fi
-	if grep -q '!pdfTeX error:' $basename.log
-	then
-		grep -A 2 '!pdfTeX error:' $basename.log
-		echo "----- Fatal latex error, see $basename.log for details. -----"
-		exit 2
+	if [ $exitcode -ne 0 ]; then
+		tail -n 20 $basename.log
+		echo "\n!!! $LATEX aborted !!!"
+		exit $exitcode
 	fi
 	if test -r $basename-warning.log
 	then
-- 
2.25.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.