aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-24 04:15:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-24 04:15:10 -0700
commit30e7238ad917c038105aecf4a1bd3bdefe0e33f7 (patch)
treec2787e8faf26e8f3dec3034f922fb8e80b27fe3f
parent72d01494705ddb72237ee6a85ea27491684c7227 (diff)
downloadcppawk-30e7238ad917c038105aecf4a1bd3bdefe0e33f7.tar.gz
cppawk-30e7238ad917c038105aecf4a1bd3bdefe0e33f7.tar.bz2
cppawk-30e7238ad917c038105aecf4a1bd3bdefe0e33f7.zip
__FILE__ in main program resolves to original name.
-rwxr-xr-xcppawk19
-rw-r--r--testcases5
-rw-r--r--testdir/name.cwk1
3 files changed, 20 insertions, 5 deletions
diff --git a/cppawk b/cppawk
index 876a5bb..3eab7e8 100755
--- a/cppawk
+++ b/cppawk
@@ -37,7 +37,6 @@ prepro_opts="-D__gawk__=1 -D__cppawk_ver=20220324"
awk_file=
awk_opts=
tmp_file=
-delhashbang="sed -e 1s/^#!.*/#/ --"
prepro_only=
selfdir=$(dirname "$0")
@@ -70,6 +69,16 @@ die()
exit 1
}
+delhashbang_setline()
+{
+ sed -e "1s/^#!.*/#/" -e "1i#line 1 \"$1\"" "$1"
+}
+
+delhashbang()
+{
+ sed -e "1s/^#!.*/#/"
+}
+
# Eliminate tracer lines in cpp output which continue a previous line, and
# merge the continued lines into one. Awk needs this because spurious newlines
# break its syntax.
@@ -160,24 +169,24 @@ prepro="command $(quote "$prepro")"
if [ -n "$awk_file" ] ; then
awk_file_dir=$(dirname "$awk_file")
if [ $prepro_only ] ; then
- $delhashbang "$awk_file" \
+ delhashbang_setline "$awk_file" \
| eval "$prepro $incopt\"$awk_file_dir\" $prepro_opts - | collapse"
else
trap 'rm -f $tmp_file' EXIT INT TERM
tmp_file=$(mktemp)
- $delhashbang "$awk_file" \
+ delhashbang_setline "$awk_file" \
| eval "$prepro $incopt\"$awk_file_dir\" $prepro_opts - | collapse" \
> $tmp_file
eval "$awk $awk_opts -f $tmp_file -- \"\$@\""
fi
elif [ $# -gt 0 ] ; then
if [ $prepro_only ] ; then
- printf "%s" "$1" | $delhashbang \
+ printf "%s" "$1" | delhashbang \
| eval "$prepro $incopt"$(pwd)" $prepro_opts - | collapse"
else
trap 'rm -f $tmp_file' EXIT INT TERM
tmp_file=$(mktemp)
- printf "%s" "$1" | $delhashbang \
+ printf "%s" "$1" | delhashbang \
| eval "$prepro $incopt"$(pwd)" $prepro_opts - | collapse" > $tmp_file
shift
eval "$awk $awk_opts -f $tmp_file -- \"\$@\""
diff --git a/testcases b/testcases
index 39519a0..40933af 100644
--- a/testcases
+++ b/testcases
@@ -232,3 +232,8 @@ BEGIN { print __LINE__
:
2
4
+--
+41:
+./cppawk -f testdir/name.cwk
+:
+testdir/name.cwk
diff --git a/testdir/name.cwk b/testdir/name.cwk
new file mode 100644
index 0000000..76613c7
--- /dev/null
+++ b/testdir/name.cwk
@@ -0,0 +1 @@
+BEGIN { print __FILE__ }