gc_parser, explicit garbage collection
[mala.git] / pipadoc.sh
blob90b768f7b801a36c2d30e94b4a659c18baa12bb4
1 #!/bin/bash
3 # pipadoc - C++ Documentation extractor
5 # Copyright (C) 2002, Pipapo Project, Christian Thaeter
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, contact to any of the Pipapo maintainers.
21 pipadoc_version=0.1
23 COM='//'
24 DOC='_'
25 SUB='='
28 function usage
30 cat <<EOF
32 Extract Documentation-Text from C/C++ files
34 usage: pipadoc files...
35 files are C/C++ sourcefiles with embedded Documentation strings
36 after '//_' or '//__' comments. This Doc-Comments can
37 optionally be followed by a tag. '//_' comments are
38 stable-sorted in alphabetic order on a per-file basis.
39 '//__' comments are globally stable-sorted in alphabetic
40 order.
41 '//_' and '//__' comments without a tag are sorted as
42 '//_5' resp. '//__5'. Output is written to stdout.
43 Pipadoc defines 'PIPADOC' while processing the sourcefiles and
44 further the preprocessing can be tuned with the CPPFLAGS and
45 PIPADOCFLAGS environment variables.
46 Tag Substitutions:
47 It is possible to define substitutions for common tags to make
48 the sourcecode easier readable:
49 '//_=foo=bar=' will replaces any '//foo' with '//bar' in this file.
50 '//__=foo=bar=' will replaces any '//foo' with '//bar' in all proccessed files.
51 example: '//__=AA=__70A5=' all '//AA' comments are processed at '//__70A5'
52 example:
53 pipadoc preamble.cpp title.cpp doc.cpp prolog.cpp
55 EOF
58 if [ $# = 0 ]; then
59 usage;
60 exit;
63 # ----------------------------------------------------------------------------
64 # -------- READING THE SOURCE BEYOND THIS LINE CAN DAMAGE UR HEALTH ----------
65 # ----------------------------------------------------------------------------
112 # YOU ARE WARNED !!!!!!!!!!!!!!!!!!!!!!!!!!!
151 TMP_GSUB=/tmp/pipadoc_$$_gsub
152 TMP_GTMP=/tmp/pipadoc_$$_gtmp
154 for i in "$@"; do
155 echo "$i" >&2
157 TMP_RIP=/tmp/pipadoc_$$_rip
158 TMP_LSUB=/tmp/pipadoc_$$_lsub
160 cat $i | g++ -DPIPADOC -E -C -P -I. $PIPADOCFLAGS $CPPFLAGS - \
161 | egrep "^.*${COM}" | uniq >$TMP_RIP
163 cat $TMP_RIP | egrep "^.*${COM}${DOC}${DOC}${SUB}" |
164 sed -e "s|\(${COM}\)\(${DOC}${DOC}\)\(${SUB}\)\([[:alnum:]][[:alnum:]_]*\)\
165 ${SUB}\([[:alnum:]_]*\)${SUB}|s\3^.*\1\4\3\1\5\3|" >>$TMP_GSUB
167 cat $TMP_RIP | egrep "^.*${COM}${DOC}${SUB}" |
168 sed -e "s|\(${COM}\)\(${DOC}\)\(${SUB}\)\([[:alnum:]][[:alnum:]_]*\)\
169 ${SUB}\([[:alnum:]_]*\)${SUB}|s\3^.*\1\4\3\1\5\3|" >>$TMP_LSUB
171 sed -f $TMP_LSUB $TMP_RIP \
172 -e "s|^.*\(${COM}.*\)|\1|" \
173 -e "\|^${COM}[[:space:]]?*.*$|d" \
174 -e "\|^${COM}${DOC}*${SUB}|d" \
175 -e "s|^\(${COM}${DOC}\)\([[:space:]].*\)$|\15\2|" \
176 | sort +0 -1 -s \
177 | sed -e "s|^\(${COM}${DOC}\)\([^${DOC}][[:alnum:]_]*\)\(.*\)$|\1${DOC}5\3|"
180 rm -f $TMP_LSUB
181 rm -f $TMP_RIP
182 done >>$TMP_GTMP
184 sed -f $TMP_GSUB $TMP_GTMP \
185 -e "s|^${COM}${DOC}${DOC}\([[:space:]]?*\)|${DOC}5\1|" \
186 -e "s|^${COM}${DOC}${DOC}|${DOC}|" \
187 -e "\|^${COM}.*$|d" \
188 | sort +0 -1 -s \
189 | sed -e "s|^${DOC}[[:alnum:]][[:alnum:]_]*[[:space:]]*||" \
190 -e 's|@/|\\|g'
193 rm -f $TMP_GSUB
194 rm -f $TMP_GTMP
196 # arch-tag: c7f177a4-3ebc-4a91-86d3-2901f4c86a62