cbe1af5292dcb78d340862cd83425bb1e2b4753b
[pspp] / config / srclist-update
1 #!/bin/sh
2 # $Id: srclist-update,v 1.6 2003-07-08 23:33:45 eggert Exp $
3 #
4 # Check for files in directory $1 being up to date, according to the
5 # list on stdin.  Don't actually make any changes, just show the diffs.
6 #
7 # Source `dirname $0`/srclistvars.sh first, if it exists.
8
9 if test -n "$1"; then
10   cd "$1" || exit 1
11 fi
12
13 verbose=false
14 #chicken="echo (would)"
15
16 : ${TMPDIR=/tmp}
17 srctmp=$TMPDIR/srclist.src
18 dsttmp=$TMPDIR/srclist.dst
19
20 mydir=`dirname $0`
21 test -r $mydir/srclistvars.sh && . $mydir/srclistvars.sh
22
23
24\f
25 # $1 is input, output to stdout with gpl.
26 #
27 fixlicense() \
28 {
29     sed '/The .* is free software/,/USA\.  *\*\//c\
30    This program is free software; you can redistribute it and/or modify\
31    it under the terms of the GNU General Public License as published by\
32    the Free Software Foundation; either version 2, or (at your option)\
33    any later version.\
34 \
35    This program is distributed in the hope that it will be useful,\
36    but WITHOUT ANY WARRANTY; without even the implied warranty of\
37    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
38    GNU General Public License for more details.\
39 \
40    You should have received a copy of the GNU General Public License along\
41    with this program; if not, write to the Free Software Foundation,\
42    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
43 ' $1
44 }
45
46
47 # $1 is input file, $2 is output.
48 # Remove $Id lines, since they'll differ between source locations.
49 # If $options contains "gpl", change the license to be the standard
50 # GPL.  We use this for libc files.
51 #
52 fixfile() \
53 {
54   case " $options " in
55   *' gpl '*)
56     fixlicense $1;;
57   *)
58     cat $1;;
59   esac \
60   | grep -v '\$Id: srclist-update,v 1.6 2003-07-08 23:33:45 eggert Exp $' >$2
61 }
62
63
64\f
65 cat | while read src dst options; do
66   case $src:$dst in
67     *: ) continue;;  # skip lines without second element
68     '#'* ) continue;;  # skip comment-only lines
69   esac
70
71   eval src=$src
72   if test ! -r $src; then
73     echo "$0: cannot read $src" >&2
74     continue
75   fi
76
77   # Ignore subdirs in src dir.  E.g., if input spec is
78   #   src/subdir/foo.c dst
79   # write destination file dst/foo.c.
80   eval dst=$dst
81   test -d $dst && dst=$dst/`basename $src`
82
83   # Make changes for sake of comparison.
84   fixfile $src $srctmp
85   test -r $dst && fixfile $dst $dsttmp
86
87   # don't show license differences.
88   gplsrc=$TMPDIR/`basename $src`
89   fixlicense $src >$gplsrc
90   cmp -s $src $gplsrc && gplsrc=$src
91
92   if test ! -e $dst; then
93     echo "## $gplsrc $dst  # new"
94     $chicken cp -p $gplsrc $dst
95   elif cmp -s $srctmp $dsttmp; then
96     $verbose && echo "## $gplsrc $dst  # unchanged"
97   else
98     echo "## $gplsrc $dst  # changes"
99     diff -C 2 $dst $gplsrc
100   fi
101 done
102
103 rm -f $srctmp $dsttmp