2 # Extract the initialization actions from source files.
4 # Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this software; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 # Boston, MA 02111-1307 USA
23 # Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...]
25 # Process INFILE using the C pre-processor and some other programs.
26 # Write output to a file named OUTFILE or to the standard output when no
27 # OUTFILE has been specified or when OUTFILE is "-". When writing
28 # to a file, ignore lines from the input matching the following grep(1)
31 # ^#include ".*OUTFILE"
33 # If there are errors during processing, delete OUTFILE and exit with
36 # During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
39 # Optional arg "-d" means grep INFILE for deprecated macros and
40 # issue a warning if any are found. Alternatively, "-D" means
41 # do the same thing but signal error and exit w/ non-zero status.
43 # If env var CPP is set, use its value instead of the C pre-processor
44 # determined at Guile configure-time: "@CPP@".
60 modern_snarf
() # writes stdout
62 ## Apparently, AIX's preprocessor is unhappy if you try to #include an
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/\^\ *:\ *\^.*/;/"
70 grep_deprecated
() # $1 is the filename
72 regexp
="(^greetings!spooks!hows!life)"
73 for dep
in `echo $deprecated_list` ; do
74 regexp
="(^${dep}[^_A-Z])|${regexp}"
76 egrep -n ${regexp} $1 /dev
/null
> ${temp}
77 if [ -s ${temp} ] ; then
78 if $grep_dep_exit_p ; then hey
=ERROR
; else hey
=WARNING
; fi
79 echo $0: $hey: deprecated macros found
:
80 sed -e 's/.clean.c:/:/g' ${temp}
81 $grep_dep_exit_p && exit 1
87 # process command line
88 if [ x
"$1" = x--help
] ; then
89 @AWK@
'/^#.Commentary:/,/^#.Code:/' $0 |
grep -v Code
: \
90 |
sed -e 1,2d
-e 's/^. *//g'
93 case x
"$1" in x-d
) grep_dep_p
=true
; grep_dep_exit_p
=false
; shift ;;
94 x-D
) grep_dep_p
=true
; grep_dep_exit_p
=true
; shift ;;
95 *) grep_dep_p
=false
;;
98 then outfile
=$2 ; shift ; shift ; infile
=$1 ; shift
99 else outfile
="-"; infile
=$1 ; shift
102 [ x
"$infile" = x
] && { echo $0: No input
file ; exit 1 ; }
103 [ ! -f "$infile" ] && { echo $0: No such
file: $infile ; exit 1 ; }
105 # set vars and handler -- handle CPP override
108 if [ x
"$CPP" = x
] ; then cpp
="@CPP@" ; else cpp
="$CPP" ; fi
110 trap "rm -f $temp" 0 1 2 15
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
116 # (e.g., see libguile/eval.c).
117 # use .c to satisfy cpp heuristics.
120 trap "rm -f $cleanfile" 0 1 2 15
121 grep -v "$self_blind_regexp" $infile > $clean_infile
122 modern_snarf
"$@" $clean_infile > $outfile
124 modern_snarf
"$@" $infile
128 $grep_dep_p && grep_deprecated
$infile
130 # zonk outfile if errors occurred
134 [ ! "$outfile" = "-" ] && rm -f $outfile
138 # guile-snarf ends here