Normalize leading white space and remove trailing white space.
[gnulib.git] / config / srclist-update
1 #!/bin/sh
2 # $Id: srclist-update,v 1.11 2003-08-13 06:48:58 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 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 # 02111-1307, USA.
23
24 # Written by Karl Berry.
25
26
27 if test -n "$1"; then
28   cd "$1" || exit 1
29 fi
30
31 verbose=false
32 #chicken="echo (would)"
33
34 : ${TMPDIR=/tmp}
35 dsttmp=$TMPDIR/srclist.dst
36
37 mydir=`dirname $0`
38 test -r $mydir/srclistvars.sh && . $mydir/srclistvars.sh
39
40
41\f
42 # $1 is input, output to stdout with gpl.
43 #
44 fixlicense() \
45 {
46     sed '
47
48   /^\([[:space:]]*#[[:space:]]*\)Th[ei][ s].* is free software/,/^[[:space:]]*#.*USA\./c\
49 #       This program is free software; you can redistribute it and/or modify\
50 #       it under the terms of the GNU General Public License as published by\
51 #       the Free Software Foundation; either version 2, or (at your option)\
52 #       any later version.\
53 #\
54 #       This program is distributed in the hope that it will be useful,\
55 #       but WITHOUT ANY WARRANTY; without even the implied warranty of\
56 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
57 #       GNU General Public License for more details.\
58 #\
59 #       You should have received a copy of the GNU General Public License along\
60 #       with this program; if not, write to the Free Software Foundation,\
61 #       Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
62
63   /Th[ei][ s].* is free software/,/USA\.  *\*\//c\
64    This program is free software; you can redistribute it and/or modify\
65    it under the terms of the GNU General Public License as published by\
66    the Free Software Foundation; either version 2, or (at your option)\
67    any later version.\
68 \
69    This program is distributed in the hope that it will be useful,\
70    but WITHOUT ANY WARRANTY; without even the implied warranty of\
71    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
72    GNU General Public License for more details.\
73 \
74    You should have received a copy of the GNU General Public License along\
75    with this program; if not, write to the Free Software Foundation,\
76    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
77 ' $1
78 }
79
80
81
82 # sed command to remove lines containing $Id lines.
83 # Quote the $Id so that CVS does not expand it in this script.
84 remove_id_lines='/[$]Id:.*[$]/d'
85
86 # sed command to remove trailing blanks.
87 # Do not use [[:space:]] in this pattern, as that would kill formfeeds.
88 remove_trailing_blanks='s/[      ][      ]*$//'
89
90 # $1 is input file, $2 is output.
91 # Remove $Id lines, since they'll differ between source locations.
92 # If $options contains "gpl", change the license to be the standard
93 # GPL.  We use this for libc files, et al.
94 # Also, normalize white space simple-mindedly.
95 #
96 fixfile() \
97 {
98   case " $options " in
99   *' gpl '*)
100     fixlicense $1;;
101   *)
102     cat $1;;
103   esac \
104   | unexpand \
105   | sed "$remove_id_lines; $remove_trailing_blanks" >$2
106 }
107
108
109\f
110 cat | while read src dst options; do
111   #echo "src=$src, dst=$dst, options=$options" >&2
112   case $src:$dst in
113     *: ) continue;;    # skip lines without second element
114     '#'* ) continue;;  # skip comment-only lines
115   esac
116
117   # Expand variables and make sure we have an input file.
118   eval src=$src
119   if test ! -r $src; then
120     echo "$0: cannot read $src" >&2
121     continue
122   fi
123
124   # Ignore subdirs in src dir.  E.g., if input spec is
125   #   src/subdir/foo.c dst
126   # then write destination file dst/foo.c.
127   eval dst=$dst
128   test -d $dst && dst=$dst/`basename $src`
129
130   # Fix files in both src and dst, for the sake
131   # of a clean comparison.
132   srctmp=$TMPDIR/`basename $src`
133   fixfile $src $srctmp
134   test -r $dst && fixfile $dst $dsttmp
135
136   if test ! -e $dst; then
137     echo "## $srctmp $dst  # new"
138     $chicken cp -p $srctmp $dst
139   elif cmp -s $srctmp $dsttmp; then
140     $verbose && echo "## $srctmp $dst  # unchanged"
141   else
142     echo "## $srctmp $dst  # changes"
143     diff -C 2 $dst $srctmp
144   fi
145 done
146
147 rm -f $dsttmp