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