guile-doc-snarf
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /bin/sh
# Copyright (C) 2002, 2006, 2007 Sergey Poznyakoff
#
# This is a snarfer for guile version 1.6
#
# 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 3 of the License, 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 program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
OUTFILE=/dev/tty
DOCFILE=0
BASEDIR=`dirname $0`
test -n "${CPP+set}" || CPP="gcc -E"
test -n "${AWK+set}" || AWK=awk
temp=/tmp/snarf.$$
trap "rm -f $temp" 0 1 2 15
# process aruments
while [ $# -gt 0 ];
do
case $1 in
-o) OUTFILE=$2; shift 2;;
-d) DOCFILE=1; shift;;
*) break;;
esac
done
INFILE=$1; shift
cpp_exit=1
snarf_x() {
echo "/* source: $INFILE */" ;
echo "/* cpp arguments: $@ */" ;
$CPP -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp}
cpp_exit=$?
grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/"
}
snarf_doc() {
$CPP -DSCM_MAGIC_SNARF_DOCS "$@" > ${temp}
cpp_exit=$?
sed -n '
/^ *^^ {.*/{
# First, remove the delimiting braces
s/^ *^^ {//
s/\^^ }/^^/
# Initialize the hold space
h
:beg
# Delete everything after the first ^^
s/\^^.*//
# Exchange spaces
x
# Delete up to the first ^^
s/[^^]*\^^//
# Append to the hold space and exchange
H
x
# Branch if the last substitution was successful
tbeg
# Otherwise, print the pattern space
p
}' $temp | \
$AWK -f $BASEDIR/guile-doc-snarf.awk
}
case "$DOCFILE" in
0) snarf_x $INFILE "$@" > $OUTFILE;;
1) snarf_doc $INFILE "$@" > $OUTFILE;;
esac
if [ $cpp_exit -ne 0 ]; then
[ "$OUTFILE" != "/dev/tty" ] && rm $OUTFILE
fi
exit $cpp_exit