1#!/bin/sh 2# Extract the initialization actions from source files. 3# 4# Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002, 2004, 2006, 2008 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., 51 Franklin Street, Fifth Floor, 19# Boston, MA 02110-1301 USA 20 21# Commentary: 22 23# Usage: guile-snarf [-o OUTFILE] [CPP-ARGS ...] 24 25# Initialization actions are extracted to OUTFILE or to standard 26# output when no OUTFILE has been specified or when OUTFILE is "-". 27# The C preprocessor is called with CPP-ARGS (which usually include a 28# input file) and the output is filtered for the actions. 29# 30# If there are errors during processing, OUTFILE is deleted and the 31# program exits with non-zero status. 32# 33# During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is 34# defined. You can use this to avoid including snarfer output files 35# that don't yet exist by writing code like this: 36# 37# #ifndef SCM_MAGIC_SNARFER 38# #include "foo.x" 39# #endif 40# 41# If the environment variable CPP is set, use its value instead of the 42# C pre-processor determined at Guile configure-time: "@CPP@". 43 44# Code: 45 46## funcs 47 48modern_snarf () # writes stdout 49{ 50 ## Apparently, AIX's preprocessor is unhappy if you try to #include an 51 ## empty file. 52 echo "/* cpp arguments: $@ */" ; 53 ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true 54 sed -e 's/\^ *\^/\ 55^^/g' ${temp} | grep "^.*\^ *\^" | sed -e "s/^.*\^ *\^//" -e "s/\^\ *:\ *\^.*/;/" 56} 57 58## main 59 60# process command line 61if [ x"$1" = x--help ] ; then 62 @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \ 63 | sed -e 1,2d -e 's/^. *//g' 64 exit 0 65fi 66if [ x"$1" = x-o ] 67 then outfile="$2" ; shift ; shift ; 68 else outfile="-" ; 69fi 70 71# set vars and handler -- handle CPP override 72cpp_ok_p=false 73 74if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi 75tempdir="$TMPDIR/guile-snarf.$$" 76(umask 077 && mkdir $tempdir) || exit 1 77temp="$tempdir/tmp" 78 79if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi 80 81trap "rm -rf $tempdir" 0 1 2 15 82 83if [ ! "$outfile" = "-" ] ; then 84 modern_snarf "$@" > $outfile 85else 86 modern_snarf "$@" 87fi 88 89# zonk outfile if errors occurred 90if $cpp_ok_p ; then 91 exit 0 92else 93 [ ! "$outfile" = "-" ] && rm -f $outfile 94 exit 1 95fi 96 97# guile-snarf ends here 98