prefix="unknown"
outprefix=""
outsuffix=""
+lineno=""
while test $# -gt 0
do
-cpu) shift ; cpu=$1 ;;
-infile) shift ; infile=$1 ;;
-shell) shift ; SHELL=$1 ;;
+ -awk) shift ; AWK=$1 ; export AWK ;;
+ -lineno) shift ; lineno=$1 ;;
*) echo "unknown option: $1" >&2 ; exit 1 ;;
esac
shift
##########################################################################
+load_infile_section() {
+ if [ -n "${lineno}" ]; then
+ ${SHELL} ${lineno} \
+ "${infile}" "${outprefix}mloop${outsuffix}.tmp" \
+ "$@"
+ else
+ ${SHELL} ${infile} "$@"
+ fi
+}
+
rm -f ${outprefix}eng${outsuffix}.hin
exec 1>${outprefix}eng${outsuffix}.hin
EOF
-${SHELL} $infile support
+load_infile_section support
##########################################################################
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
if [ x$parallel = xread ] ; then
cat << EOF
/* begin full-exec-simple */
EOF
-${SHELL} $infile full-exec-simple
+load_infile_section full-exec-simple
cat << EOF
/* end full-exec-simple */
/* begin extract-scache */
EOF
-${SHELL} $infile extract-scache
+load_infile_section extract-scache
cat << EOF
/* end extract-scache */
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
cat << EOF
/* begin full-exec-scache */
EOF
-${SHELL} $infile full-exec-scache
+load_infile_section full-exec-scache
cat << EOF
/* end full-exec-scache */
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
cat << EOF
/* begin fast-exec-scache */
EOF
-${SHELL} $infile fast-exec-scache
+load_infile_section fast-exec-scache
cat << EOF
/* end fast-exec-scache */
/* begin extract-scache */
EOF
-${SHELL} $infile extract-scache
+load_infile_section extract-scache
cat << EOF
/* end extract-scache */
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
if [ x$parallel = xread ] ; then
cat << EOF
/* begin full-exec-scache */
EOF
-${SHELL} $infile full-exec-scache
+load_infile_section full-exec-scache
cat << EOF
/* end full-exec-scache */
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
if [ x$parallel = xread ] ; then
cat << EOF
/* begin fast-exec-scache */
EOF
-${SHELL} $infile fast-exec-scache
+load_infile_section fast-exec-scache
cat << EOF
/* end fast-exec-scache */
/* begin extract-pbb */
EOF
-${SHELL} $infile extract-pbb
+load_infile_section extract-pbb
cat << EOF
/* end extract-pbb */
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
cat << EOF
/* begin full-exec-pbb */
EOF
-${SHELL} $infile full-exec-pbb
+load_infile_section full-exec-pbb
cat << EOF
/* end full-exec-pbb */
# Any initialization code before looping starts.
# Note that this code may declare some locals.
-${SHELL} $infile init
+load_infile_section init
cat << EOF
/* begin fast-exec-pbb */
EOF
-${SHELL} $infile fast-exec-pbb
+load_infile_section fast-exec-pbb
cat << EOF
/* end fast-exec-pbb */
--- /dev/null
+#!/bin/sh
+# Replace $LINENO on the fly.
+# Copyright (C) 2023 Free Software Foundation, Inc.
+#
+# This file is part of the GNU simulators.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Since $LINENO is not reliable in shells/subshells, generate it on the fly.
+
+if [ $# -lt 2 ]; then
+ cat <<EOF >&2
+Usage: $0 <script> <tempfile> [script args]
+
+Rewrite the $LINENO usage in <script> with the line number. The temp script is
+written to <tempfile>, and then removed when done.
+EOF
+ exit 1
+fi
+
+input=$1
+shift
+output=$1
+shift
+
+${AWK:-awk} '{
+ gsub("[$]LINENO", NR + 1)
+ gsub("\"[$]0\"", "\"" FILENAME "\"")
+ print
+}' "${input}" >"${output}"
+${SHELL} "${output}" "$@"
+
+rm -f "${output}"