1#! /bin/sh
2# This file is part of Imprimatur.
3# Copyright (C) 2006, 2007, 2010, 2011 Sergey Poznyakoff
4#
5# Imprimatur is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3, or (at your option)
8# any later version.
9#
10# Imprimatur is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Imprimatur.  If not, see <http://www.gnu.org/licenses/>.
17
18usage() {
19  cat <<EOT
20usage: $0 item class code-sed doc-sed sources -- makeinfo-args...
21EOT
22}
23
24if [ $# -le 4 ]; then
25  usage
26  exit 2
27fi
28
29item=$1
30shift
31codesexp="$1"
32shift
33docsexp=$1
34shift
35
36source=
37while [ $# -ne 0 ]
38do
39	if [ "$1" = "--" ]; then
40		shift
41		break;
42	fi
43	source="$source $1"
44	shift
45done
46
47TEMPDIR=/tmp/mfck.$$
48mkdir $TEMPDIR || exit 1
49trap 'rm -rf $TEMPDIR' 1 2 13 15
50
51ltrim_ws() {
52	# NOTE: The brackets contain a space and a tab!
53	sed 's/^[ 	][ 	]*//'
54}
55
56sed -n "$codesexp" $source | ltrim_ws | sort | uniq > $TEMPDIR/src
57
58$* | \
59 sed -n '/^@macro/,/^@end macro/d;'"$docsexp" | ltrim_ws \
60  | sort | uniq > $TEMPDIR/doc
61
62join -v1 $TEMPDIR/src $TEMPDIR/doc > $TEMPDIR/src-doc
63join -v2 $TEMPDIR/src $TEMPDIR/doc > $TEMPDIR/doc-src
64(if [ -s $TEMPDIR/src-doc ]; then
65   echo "Not documented $item:"
66   cat $TEMPDIR/src-doc
67 fi
68 if [ -s $TEMPDIR/doc-src ]; then
69   echo "Non-existing $item:"
70   cat $TEMPDIR/doc-src
71 fi) > $TEMPDIR/report
72
73if [ -s $TEMPDIR/report ]; then
74  cat $TEMPDIR/report
75  rm -rf $TEMPDIR
76  exit 1
77else
78  rm -rf $TEMPDIR
79  exit 0
80fi
81