1 |
#!/bin/sh |
#!/bin/sh |
2 |
# Extract the initialization actions for builtin things. |
# Extract the initialization actions from source files. |
3 |
|
# |
4 |
|
# Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002 Free Software Foundation, Inc. |
5 |
|
# |
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) |
9 |
|
# any later version. |
10 |
|
# |
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. |
15 |
|
# |
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 |
20 |
|
|
21 |
|
# Commentary: |
22 |
|
|
23 |
|
# Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...] |
24 |
|
# |
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 "-". |
28 |
|
# |
29 |
|
# If there are errors during processing, delete OUTFILE and exit with |
30 |
|
# non-zero status. |
31 |
|
# |
32 |
|
# During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is |
33 |
|
# defined. |
34 |
|
# |
35 |
|
# Optional arg "-d" means grep INFILE for deprecated macros and |
36 |
|
# issue a warning if any are found. Alternatively, "-D" means |
37 |
|
# do the same thing but signal error and exit w/ non-zero status. |
38 |
|
# |
39 |
|
# If env var CPP is set, use its value instead of the C pre-processor |
40 |
|
# determined at Guile configure-time: "@CPP@". |
41 |
|
|
42 |
|
# Code: |
43 |
|
|
44 |
|
## config |
45 |
|
|
46 |
|
deprecated_list=" |
47 |
|
SCM_CONST_LONG |
48 |
|
SCM_VCELL |
49 |
|
SCM_VCELL_INIT |
50 |
|
SCM_GLOBAL_VCELL |
51 |
|
SCM_GLOBAL_VCELL_INIT |
52 |
|
" |
53 |
|
|
54 |
|
## funcs |
55 |
|
|
56 |
|
old_school_snarf () # writes stdout |
57 |
|
{ |
58 |
|
${cpp} -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true |
59 |
|
grep "^ *SCM__I" ${temp} | sed -e 's/^ *SCM__I//' -e 's/SCM__D.*$//g' |
60 |
|
} |
61 |
|
|
62 |
|
modern_snarf () # writes stdout |
63 |
|
{ |
64 |
|
## Apparently, AIX's preprocessor is unhappy if you try to #include an |
65 |
|
## empty file. |
66 |
|
echo "/* source: $infile */" ; |
67 |
|
echo "/* cpp arguments: $@ */" ; |
68 |
|
${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true |
69 |
|
grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/" |
70 |
|
} |
71 |
|
|
72 |
|
grep_deprecated () # $1 is the filename |
73 |
|
{ |
74 |
|
regexp="(^greetings!spooks!hows!life)" |
75 |
|
for dep in `echo $deprecated_list` ; do |
76 |
|
regexp="(^${dep}[^_A-Z])|${regexp}" |
77 |
|
done |
78 |
|
egrep -n ${regexp} $1 /dev/null > ${temp} |
79 |
|
if [ -s ${temp} ] ; then |
80 |
|
if $grep_dep_exit_p ; then hey=ERROR ; else hey=WARNING ; fi |
81 |
|
echo $0: $hey: deprecated macros found: |
82 |
|
sed -e 's/.clean.c:/:/g' ${temp} |
83 |
|
$grep_dep_exit_p && exit 1 |
84 |
|
fi |
85 |
|
} |
86 |
|
|
87 |
|
## main |
88 |
|
|
89 |
|
# process command line |
90 |
|
if [ x"$1" = x--help ] ; then |
91 |
|
@AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \ |
92 |
|
| sed -e 1,2d -e 's/^. *//g' |
93 |
|
exit 0 |
94 |
|
fi |
95 |
|
case x"$1" in x-d) grep_dep_p=true ; grep_dep_exit_p=false ; shift ;; |
96 |
|
x-D) grep_dep_p=true ; grep_dep_exit_p=true ; shift ;; |
97 |
|
*) grep_dep_p=false ;; |
98 |
|
esac |
99 |
|
if [ x"$1" = x-o ] |
100 |
|
then outfile=$2 ; shift ; shift ; infile=$1 ; shift |
101 |
|
else outfile="-"; infile=$1 ; shift |
102 |
|
fi |
103 |
|
|
104 |
|
[ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; } |
105 |
|
[ ! -f "$infile" ] && { echo $0: No such file: $infile ; exit 1 ; } |
106 |
|
|
107 |
|
# set vars and handler -- handle CPP override |
108 |
|
cpp_ok_p=false |
109 |
temp="/tmp/snarf.$$" |
temp="/tmp/snarf.$$" |
110 |
|
if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi |
111 |
|
|
112 |
trap "rm -f $temp" 0 1 2 15 |
trap "rm -f $temp" 0 1 2 15 |
113 |
|
|
114 |
## Let the user override the preprocessor autoconf found. |
if [ ! "$outfile" = "-" ]; then |
115 |
test -n "${CPP+set}" || CPP="@CPP@" |
old_school_snarf "$@" $infile > $outfile |
116 |
|
else |
117 |
|
old_school_snarf "$@" $infile |
118 |
|
fi |
119 |
|
|
120 |
|
# grep deprecated |
121 |
|
$grep_dep_p && grep_deprecated $infile |
122 |
|
|
123 |
|
# zonk outfile if errors occurred |
124 |
|
if $cpp_ok_p ; then |
125 |
|
exit 0 |
126 |
|
else |
127 |
|
[ ! "$outfile" = "-" ] && rm -f $outfile |
128 |
|
exit 1 |
129 |
|
fi |
130 |
|
|
131 |
## We must use a temporary file here, instead of a pipe, because we |
# guile-snarf ends here |
|
## need to know if CPP exits with a non-zero status. |
|
|
${CPP} -DSCM_MAGIC_SNARFER "$@" > ${temp} || exit $? |
|
|
< ${temp} grep "^ *SCM__I" | sed -e "s/^ *SCM__I//" -e 's/SCM__D.*$//g' |
|
|
|
|
|
## Apparently, AIX's preprocessor is unhappy if you try to #include an |
|
|
## empty file. |
|
|
echo |
|