23 |
# Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...] |
# Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...] |
24 |
# |
# |
25 |
# Process INFILE using the C pre-processor and some other programs. |
# Process INFILE using the C pre-processor and some other programs. |
26 |
# Write output to a file, named OUTFILE if specified, or STEM.x if |
# Write output to a file named OUTFILE or to the standard output when no |
27 |
# INFILE looks like STEM.c and no OUTFILE is specified. Ignore |
# OUTFILE has been specified or when OUTFILE is "-". When writing |
28 |
# lines from the input matching grep(1) regular expression: |
# to a file, ignore lines from the input matching the following grep(1) |
29 |
|
# regular expression: |
30 |
# |
# |
31 |
# ^#include ".*OUTFILE" |
# ^#include ".*OUTFILE" |
32 |
# |
# |
33 |
# If there are errors during processing, delete OUTFILE and exit with |
# If there are errors during processing, delete OUTFILE and exit with |
34 |
# non-zero status. |
# non-zero status. |
35 |
# |
# |
36 |
|
# During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is |
37 |
|
# defined. |
38 |
|
# |
39 |
# Optional arg "-d" means grep INFILE for deprecated macros and |
# Optional arg "-d" means grep INFILE for deprecated macros and |
40 |
# issue a warning if any are found. Alternatively, "-D" means |
# issue a warning if any are found. Alternatively, "-D" means |
41 |
# do the same thing but signal error and exit w/ non-zero status. |
# do the same thing but signal error and exit w/ non-zero status. |
59 |
|
|
60 |
modern_snarf () # writes stdout |
modern_snarf () # writes stdout |
61 |
{ |
{ |
62 |
${cpp} -DSCM_MAGIC_SNARF_INITS "$@" > ${temp} && cpp_ok_p=true |
## Apparently, AIX's preprocessor is unhappy if you try to #include an |
63 |
grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/" |
## empty file. |
64 |
|
echo "/* source: $infile */" ; |
65 |
|
echo "/* cpp arguments: $@ */" ; |
66 |
|
${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true |
67 |
|
grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/" |
68 |
} |
} |
69 |
|
|
70 |
grep_deprecated () # $1 is the filename |
grep_deprecated () # $1 is the filename |
96 |
esac |
esac |
97 |
if [ x"$1" = x-o ] |
if [ x"$1" = x-o ] |
98 |
then outfile=$2 ; shift ; shift ; infile=$1 ; shift |
then outfile=$2 ; shift ; shift ; infile=$1 ; shift |
99 |
else infile=$1 ; shift ; outfile=`basename $infile .c`.x |
else outfile="-"; infile=$1 ; shift |
100 |
fi |
fi |
101 |
|
|
102 |
[ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; } |
[ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; } |
106 |
cpp_ok_p=false |
cpp_ok_p=false |
107 |
temp="/tmp/snarf.$$" |
temp="/tmp/snarf.$$" |
108 |
if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi |
if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi |
109 |
self_blind_regexp='^#include ".*'`basename $outfile`'"' |
|
110 |
clean_infile=$infile.clean.c # temp file in same dir as infile |
trap "rm -f $temp $clean_infile" 0 1 2 15 |
111 |
|
|
112 |
|
if [ ! "$outfile" = "-" ]; then |
113 |
|
self_blind_regexp='^#include ".*'`basename $outfile`'"' |
114 |
|
clean_infile=$infile.clean.c # temp file in same dir as infile |
115 |
# so that #include "foo" works |
# so that #include "foo" works |
116 |
# (e.g., see libguile/eval.c). |
# (e.g., see libguile/eval.c). |
117 |
# use .c to satisfy cpp heuristics. |
# use .c to satisfy cpp heuristics. |
|
trap "rm -f $temp $clean_infile" 0 1 2 15 |
|
118 |
|
|
119 |
# clean input file |
# clean input file |
120 |
grep -v "$self_blind_regexp" $infile > $clean_infile |
grep -v "$self_blind_regexp" $infile > $clean_infile |
121 |
|
modern_snarf "$@" $clean_infile > $outfile |
122 |
|
else |
123 |
|
modern_snarf "$@" $infile |
124 |
|
fi |
125 |
|
|
126 |
# grep deprecated |
# grep deprecated |
127 |
$grep_dep_p && grep_deprecated $clean_infile |
$grep_dep_p && grep_deprecated $infile |
|
|
|
|
# do the snarfing -- output something extra for needy cpp programs (AIX) |
|
|
{ echo "/* source: $infile */" ; |
|
|
echo "/* cpp-options: $@ */" ; |
|
|
modern_snarf "$@" $clean_infile ; |
|
|
} > $outfile |
|
128 |
|
|
129 |
# zonk outfile if errors occurred |
# zonk outfile if errors occurred |
130 |
if $cpp_ok_p ; then |
if $cpp_ok_p ; then |
131 |
exit 0 |
exit 0 |
132 |
else |
else |
133 |
rm -f $outfile |
[ ! "$outfile" = "-" ] && rm -f $outfile |
134 |
exit 1 |
exit 1 |
135 |
fi |
fi |
136 |
|
|