guile-snarf fix
[bpt/guile.git] / libguile / guile-snarf.in
dissimilarity index 75%
index 67fbddd..36cb995 100644 (file)
-#!/bin/sh
-# Extract the initialization actions from source files.
-#
-#  Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this software; see the file COPYING.  If not, write to
-# the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA 02111-1307 USA
-
-# Commentary:
-
-# Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...]
-#
-# Process INFILE using the C pre-processor and some other programs.
-# Write output to a file named OUTFILE or to the standard output when no
-# OUTFILE has been specified or when OUTFILE is "-".  When writing
-# to a file, ignore lines from the input matching the following grep(1)
-# regular expression:
-#
-#       ^#include ".*OUTFILE"
-#
-# If there are errors during processing, delete OUTFILE and exit with
-# non-zero status.
-#
-# During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
-# defined.
-#
-# Optional arg "-d" means grep INFILE for deprecated macros and
-# issue a warning if any are found.  Alternatively, "-D" means
-# do the same thing but signal error and exit w/ non-zero status.
-#
-# If env var CPP is set, use its value instead of the C pre-processor
-# determined at Guile configure-time: "@CPP@".
-
-# Code:
-
-## config
-
-deprecated_list="
- SCM_CONST_LONG
- SCM_VCELL
- SCM_VCELL_INIT
- SCM_GLOBAL_VCELL
- SCM_GLOBAL_VCELL_INIT
-"
-
-## funcs
-
-modern_snarf ()                         # writes stdout
-{
-    ## Apparently, AIX's preprocessor is unhappy if you try to #include an
-    ## empty file.
-    echo "/* source: $infile */" ;
-    echo "/* cpp arguments: $@ */" ;
-    ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
-    grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/"
-}
-
-grep_deprecated ()                      # $1 is the filename
-{
-regexp="(^greetings!spooks!hows!life)"
-for dep in `echo $deprecated_list` ; do
-    regexp="(^${dep}[^_A-Z])|${regexp}"
-done
-egrep -n ${regexp} $1 /dev/null > ${temp}
-if [ -s ${temp} ] ; then
-    if $grep_dep_exit_p ; then hey=ERROR ; else hey=WARNING ; fi
-    echo $0: $hey: deprecated macros found:
-    sed -e 's/.clean.c:/:/g' ${temp}
-    $grep_dep_exit_p && exit 1
-fi
-}
-
-## main
-
-# process command line
-if [ x"$1" = x--help ] ; then
-    @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
-        | sed -e 1,2d -e 's/^. *//g'
-    exit 0
-fi
-case x"$1" in x-d) grep_dep_p=true ; grep_dep_exit_p=false ; shift ;;
-              x-D) grep_dep_p=true ; grep_dep_exit_p=true  ; shift ;;
-              *)   grep_dep_p=false                                ;;
-esac
-if [ x"$1" = x-o ]
-    then outfile=$2 ; shift ; shift ; infile=$1 ; shift
-    else outfile="-"; infile=$1 ; shift 
-fi
-
-[ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; }
-[ ! -f "$infile" ] && { echo $0: No such file: $infile ; exit 1 ; }
-
-# set vars and handler -- handle CPP override
-cpp_ok_p=false
-temp="/tmp/snarf.$$"
-if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
-
-trap "rm -f $temp $clean_infile" 0 1 2 15
-
-if [ ! "$outfile" = "-" ]; then
-    self_blind_regexp='^#include ".*'`basename $outfile`'"'
-    clean_infile=$infile.clean.c        # temp file in same dir as infile
-                                        # so that #include "foo" works
-                                        # (e.g., see libguile/eval.c).
-                                        # use .c to satisfy cpp heuristics.
-
-    # clean input file
-    grep -v "$self_blind_regexp" $infile > $clean_infile
-    modern_snarf "$@" $clean_infile > $outfile
-else
-    modern_snarf "$@" $infile
-fi
-
-# grep deprecated
-$grep_dep_p && grep_deprecated $infile
-
-# zonk outfile if errors occurred
-if $cpp_ok_p ; then
-    exit 0
-else
-    [ ! "$outfile" = "-" ] && rm -f $outfile
-    exit 1
-fi
-
-# guile-snarf ends here
+#!/bin/sh
+# Extract the initialization actions from source files.
+#
+#  Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002, 2004, 2006, 2008,
+#    2009, 2014 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; see the file COPYING.LESSER.  If
+# not, write to the Free Software Foundation, Inc., 51 Franklin
+# Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+# Commentary:
+
+# Usage: guile-snarf [-o OUTFILE] [CPP-ARGS ...]
+# Initialization actions are extracted to OUTFILE or to standard
+# output when no OUTFILE has been specified or when OUTFILE is "-".
+# The C preprocessor is called with CPP-ARGS (which usually include a
+# input file) and the output is filtered for the actions.
+# 
+# If there are errors during processing, OUTFILE is deleted and the
+# program exits with non-zero status.
+# 
+# During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
+# defined.  You can use this to avoid including snarfer output files
+# that don't yet exist by writing code like this:
+# 
+#   #ifndef SCM_MAGIC_SNARFER
+#   #include "foo.x"
+#   #endif
+# 
+# If the environment variable CPP is set, use its value instead of the
+# C pre-processor determined at Guile configure-time: "@CPP@".
+
+# Code:
+
+## funcs
+
+modern_snarf ()                         # writes stdout
+{
+    ## Apparently, AIX's preprocessor is unhappy if you try to #include an
+    ## empty file.
+    echo "/* cpp arguments: $@ */" ;
+    ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
+    sed -ne '/^#define /d
+s/ *\^ *\^ */\
+/
+s/.*\n//
+t x
+d
+: x
+s/ *\^ *: *\^ */;\
+/
+t y
+N
+s/\n\(#.*\)/ /
+s/\n/ /
+t x
+: y
+P
+D' ${temp}
+}
+
+## main
+
+# process command line
+if [ x"$1" = x--help ] ; then
+    @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
+        | sed -e 1,2d -e 's/^. *//g'
+    exit 0
+fi
+if [ x"$1" = x-o ]
+    then outfile="$2" ; shift ; shift ;
+    else  outfile="-" ;
+fi
+
+# set vars and handler -- handle CPP override
+cpp_ok_p=false
+
+if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
+tempdir="$TMPDIR/guile-snarf.$$"
+(umask 077 && mkdir $tempdir) || exit 1
+temp="$tempdir/tmp"
+
+if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
+
+trap "rm -rf $tempdir" 0 1 2 15
+
+if [ ! "$outfile" = "-" ] ; then
+    modern_snarf "$@" > $outfile
+else
+    modern_snarf "$@"
+fi
+
+# zonk outfile if errors occurred
+if $cpp_ok_p ; then
+    exit 0
+else
+    [ ! "$outfile" = "-" ] && rm -f $outfile
+    exit 1
+fi
+
+# guile-snarf ends here