bye bye
[bpt/guile.git] / libguile / guile-snarf.in
CommitLineData
adb75a41 1#!/bin/sh
9bc6fb0a
TTN
2# Extract the initialization actions from source files.
3#
4# Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002 Free Software Foundation, Inc.
d6a35f3f 5#
d6a35f3f
MV
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.
9bc6fb0a 10#
d6a35f3f
MV
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.
9bc6fb0a 15#
d6a35f3f
MV
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
adb75a41 20
9bc6fb0a
TTN
21# Commentary:
22
77b26c93 23# Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...]
9bc6fb0a
TTN
24#
25# 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
27# INFILE looks like STEM.c and no OUTFILE is specified. Ignore
28# lines from the input matching grep(1) regular expression:
29#
30# ^#include ".*OUTFILE"
31#
32# If there are errors during processing, delete OUTFILE and exit with
33# non-zero status.
34#
77b26c93
TTN
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.
9bc6fb0a
TTN
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
77b26c93
TTN
44## config
45
46deprecated_list="
47 SCM_CONST_LONG
48 SCM_VCELL
49 SCM_VCELL_INIT
50 SCM_GLOBAL_VCELL
51 SCM_GLOBAL_VCELL_INIT
52"
53
9bc6fb0a
TTN
54## funcs
55
56modern_snarf () # writes stdout
57{
58${cpp} -DSCM_MAGIC_SNARF_INITS "$@" > ${temp} && cpp_ok_p=true
d3bd0027 59grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/"
9bc6fb0a
TTN
60}
61
77b26c93 62grep_deprecated () # $1 is the filename
9bc6fb0a 63{
77b26c93
TTN
64regexp="(^greetings!spooks!hows!life)"
65for dep in `echo $deprecated_list` ; do
66 regexp="(^${dep}[^_A-Z])|${regexp}"
67done
77b26c93
TTN
68egrep -n ${regexp} $1 /dev/null > ${temp}
69if [ -s ${temp} ] ; then
70 if $grep_dep_exit_p ; then hey=ERROR ; else hey=WARNING ; fi
71 echo $0: $hey: deprecated macros found:
72 sed -e 's/.clean.c:/:/g' ${temp}
73 $grep_dep_exit_p && exit 1
74fi
9bc6fb0a
TTN
75}
76
77## main
78
79# process command line
80if [ x"$1" = x--help ] ; then
81 @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
82 | sed -e 1,2d -e 's/^. *//g'
83 exit 0
84fi
77b26c93
TTN
85case x"$1" in x-d) grep_dep_p=true ; grep_dep_exit_p=false ; shift ;;
86 x-D) grep_dep_p=true ; grep_dep_exit_p=true ; shift ;;
87 *) grep_dep_p=false ;;
88esac
9bc6fb0a
TTN
89if [ x"$1" = x-o ]
90 then outfile=$2 ; shift ; shift ; infile=$1 ; shift
91 else infile=$1 ; shift ; outfile=`basename $infile .c`.x
92fi
93
94[ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; }
95[ ! -f "$infile" ] && { echo $0: No such file: $infile ; exit 1 ; }
96
97# set vars and handler -- handle CPP override
98cpp_ok_p=false
7677589a 99temp="/tmp/snarf.$$"
9bc6fb0a
TTN
100if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
101self_blind_regexp='^#include ".*'`basename $outfile`'"'
102clean_infile=$infile.clean.c # temp file in same dir as infile
103 # so that #include "foo" works
104 # (e.g., see libguile/eval.c).
105 # use .c to satisfy cpp heuristics.
106trap "rm -f $temp $clean_infile" 0 1 2 15
107
108# clean input file
109grep -v "$self_blind_regexp" $infile > $clean_infile
77b26c93
TTN
110
111# grep deprecated
112$grep_dep_p && grep_deprecated $clean_infile
7677589a 113
9bc6fb0a
TTN
114# do the snarfing -- output something extra for needy cpp programs (AIX)
115{ echo "/* source: $infile */" ;
116 echo "/* cpp-options: $@ */" ;
117 modern_snarf "$@" $clean_infile ;
118} > $outfile
7677589a 119
9bc6fb0a
TTN
120# zonk outfile if errors occurred
121if $cpp_ok_p ; then
122 exit 0
123else
124 rm -f $outfile
125 exit 1
126fi
63a646c5 127
9bc6fb0a 128# guile-snarf ends here