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