diff options
author | Marius Vollmer <mvo@zagadka.de> | 2002-03-24 13:47:06 +0000 |
---|---|---|
committer | Marius Vollmer <mvo@zagadka.de> | 2002-03-24 13:47:06 +0000 |
commit | 66c4b1098555447715d70f871815cf99514b6276 (patch) | |
tree | df57f9d86828f8d5637aafcb2d4e5fbdf023f93b /libguile/guile-snarf.in | |
parent | 8660251f7d066bb1a34844ec4460eb38db485f27 (diff) | |
download | guile-66c4b1098555447715d70f871815cf99514b6276.tar.gz |
When the output filename is "-", write to stdout. When no "-o" option
is given, use "-" as the output filename (i.e., stdout). Only 'clean'
the inputfile or remove the output file on error when the output file
name is not "-". Define the preprocessor macro SCM_MAGIC_SNARFER
while snarfing.
Diffstat (limited to 'libguile/guile-snarf.in')
-rw-r--r-- | libguile/guile-snarf.in | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/libguile/guile-snarf.in b/libguile/guile-snarf.in index 8973a52a8..67fbddda7 100644 --- a/libguile/guile-snarf.in +++ b/libguile/guile-snarf.in @@ -23,15 +23,19 @@ # Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...] # # Process INFILE using the C pre-processor and some other programs. -# Write output to a file, named OUTFILE if specified, or STEM.x if -# INFILE looks like STEM.c and no OUTFILE is specified. Ignore -# lines from the input matching grep(1) regular expression: +# Write output to a file named OUTFILE or to the standard output when no +# OUTFILE has been specified or when OUTFILE is "-". When writing +# to a file, ignore lines from the input matching the following grep(1) +# regular expression: # # ^#include ".*OUTFILE" # # If there are errors during processing, delete OUTFILE and exit with # non-zero status. # +# During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is +# defined. +# # Optional arg "-d" means grep INFILE for deprecated macros and # issue a warning if any are found. Alternatively, "-D" means # do the same thing but signal error and exit w/ non-zero status. @@ -55,8 +59,12 @@ deprecated_list=" modern_snarf () # writes stdout { -${cpp} -DSCM_MAGIC_SNARF_INITS "$@" > ${temp} && cpp_ok_p=true -grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/" + ## Apparently, AIX's preprocessor is unhappy if you try to #include an + ## empty file. + echo "/* source: $infile */" ; + echo "/* cpp arguments: $@ */" ; + ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true + grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/" } grep_deprecated () # $1 is the filename @@ -88,7 +96,7 @@ case x"$1" in x-d) grep_dep_p=true ; grep_dep_exit_p=false ; shift ;; esac if [ x"$1" = x-o ] then outfile=$2 ; shift ; shift ; infile=$1 ; shift - else infile=$1 ; shift ; outfile=`basename $infile .c`.x + else outfile="-"; infile=$1 ; shift fi [ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; } @@ -98,30 +106,31 @@ fi cpp_ok_p=false temp="/tmp/snarf.$$" if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi -self_blind_regexp='^#include ".*'`basename $outfile`'"' -clean_infile=$infile.clean.c # temp file in same dir as infile + +trap "rm -f $temp $clean_infile" 0 1 2 15 + +if [ ! "$outfile" = "-" ]; then + self_blind_regexp='^#include ".*'`basename $outfile`'"' + clean_infile=$infile.clean.c # temp file in same dir as infile # so that #include "foo" works # (e.g., see libguile/eval.c). # use .c to satisfy cpp heuristics. -trap "rm -f $temp $clean_infile" 0 1 2 15 -# clean input file -grep -v "$self_blind_regexp" $infile > $clean_infile + # clean input file + grep -v "$self_blind_regexp" $infile > $clean_infile + modern_snarf "$@" $clean_infile > $outfile +else + modern_snarf "$@" $infile +fi # grep deprecated -$grep_dep_p && grep_deprecated $clean_infile - -# do the snarfing -- output something extra for needy cpp programs (AIX) -{ echo "/* source: $infile */" ; - echo "/* cpp-options: $@ */" ; - modern_snarf "$@" $clean_infile ; -} > $outfile +$grep_dep_p && grep_deprecated $infile # zonk outfile if errors occurred if $cpp_ok_p ; then exit 0 else - rm -f $outfile + [ ! "$outfile" = "-" ] && rm -f $outfile exit 1 fi |