diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-03-24 04:15:10 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-03-24 04:15:10 -0700 |
commit | 30e7238ad917c038105aecf4a1bd3bdefe0e33f7 (patch) | |
tree | c2787e8faf26e8f3dec3034f922fb8e80b27fe3f | |
parent | 72d01494705ddb72237ee6a85ea27491684c7227 (diff) | |
download | cppawk-30e7238ad917c038105aecf4a1bd3bdefe0e33f7.tar.gz cppawk-30e7238ad917c038105aecf4a1bd3bdefe0e33f7.tar.bz2 cppawk-30e7238ad917c038105aecf4a1bd3bdefe0e33f7.zip |
__FILE__ in main program resolves to original name.
-rwxr-xr-x | cppawk | 19 | ||||
-rw-r--r-- | testcases | 5 | ||||
-rw-r--r-- | testdir/name.cwk | 1 |
3 files changed, 20 insertions, 5 deletions
@@ -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 -- \"\$@\"" @@ -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__ } |