Small docstring fixes.
[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
23# Usage: guile-snarf [--compat=1.4] [-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 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#
35# Optional arg "--compat=1.4" means emulate guile-1.4 guile-snarf.
36# This option is easily misunderstood -- see Guile reference manual.
37#
38# If env var CPP is set, use its value instead of the C pre-processor
39# determined at Guile configure-time: "@CPP@".
40
41# Code:
42
43## funcs
44
45modern_snarf () # writes stdout
46{
47${cpp} -DSCM_MAGIC_SNARF_INITS "$@" > ${temp} && cpp_ok_p=true
d3bd0027 48grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/"
9bc6fb0a
TTN
49}
50
51compat_mode_clean_xxx () # modifies $1
52{
53filename=$1
54cp $filename ${temp}
55sed -e 's/SCM_CONST_LONG/SCM_GLOBAL_VCELL_INIT/g' \
56 -e 's/SCM_GLOBAL_VCELL_INIT/SCM_GLOBAL_VARIABLE_INIT/g' \
57 -e 's/SCM_GLOBAL_VCELL/SCM_GLOBAL_VARIABLE/g' \
58 -e 's/SCM_VCELL_INIT/SCM_VARIABLE_INIT/g' \
59 -e 's/SCM_VCELL/SCM_VARIABLE/g' \
60 < ${temp} \
61 > $filename
62}
63
64## main
65
66# process command line
67if [ x"$1" = x--help ] ; then
68 @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
69 | sed -e 1,2d -e 's/^. *//g'
70 exit 0
71fi
72if [ x"$1" = x--compat=1.4 ]
73 then compat_mode_p=true ; shift
74 else compat_mode_p=false
75fi
76if [ x"$1" = x-o ]
77 then outfile=$2 ; shift ; shift ; infile=$1 ; shift
78 else infile=$1 ; shift ; outfile=`basename $infile .c`.x
79fi
80
81[ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; }
82[ ! -f "$infile" ] && { echo $0: No such file: $infile ; exit 1 ; }
83
84# set vars and handler -- handle CPP override
85cpp_ok_p=false
7677589a 86temp="/tmp/snarf.$$"
9bc6fb0a
TTN
87if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
88self_blind_regexp='^#include ".*'`basename $outfile`'"'
89clean_infile=$infile.clean.c # temp file in same dir as infile
90 # so that #include "foo" works
91 # (e.g., see libguile/eval.c).
92 # use .c to satisfy cpp heuristics.
93trap "rm -f $temp $clean_infile" 0 1 2 15
94
95# clean input file
96grep -v "$self_blind_regexp" $infile > $clean_infile
97$compat_mode_p && compat_mode_clean_xxx $clean_infile
7677589a 98
9bc6fb0a
TTN
99# do the snarfing -- output something extra for needy cpp programs (AIX)
100{ echo "/* source: $infile */" ;
101 echo "/* cpp-options: $@ */" ;
102 modern_snarf "$@" $clean_infile ;
103} > $outfile
7677589a 104
9bc6fb0a
TTN
105# zonk outfile if errors occurred
106if $cpp_ok_p ; then
107 exit 0
108else
109 rm -f $outfile
110 exit 1
111fi
63a646c5 112
9bc6fb0a 113# guile-snarf ends here