pty: Activate the signature wrapper of forkpty.
[gnulib.git] / config / srclist-update
1 #!/bin/sh
2 # Check for files in directory $1 being up to date, according to the
3 # list on stdin.  Don't actually make any changes, just show the diffs.
4 #
5 # Empty (or only whitespace) input lines are ignored.
6 # Lines beginning with # are ignored.
7 # Lines with just one word are ignored.
8 # Otherwise, the line has two or more whitespace-separated words:
9 #   the first word is the source, the second word is the destination,
10 #   other optional words are options.
11 # The possible options are "gpl" (to replace the license with the GPL)
12 #   and "doclicense" (to replace @include doclicense.texi with fdl.texi).
13 #   Unrecognized options are ignored.
14 # $VARIABLE expansions are done (with sh eval).
15 #
16 # This script is used in gnulib and texinfo; the input files are named
17 # srclist.txt.
18 #
19 # Copyright (C) 2002-2003, 2005, 2007-2013 Free Software Foundation, Inc.
20 #
21 # This program is free software: you can redistribute it and/or modify
22 # it under the terms of the GNU General Public License as published by
23 # the Free Software Foundation; either version 3 of the License, or
24 # (at your option) any later version.
25 #
26 # This program is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 # GNU General Public License for more details.
30 #
31 # You should have received a copy of the GNU General Public License
32 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
33
34 # Originally written by Karl Berry.
35
36
37 if test -n "$1"; then
38   cd "$1" || exit 1
39 fi
40
41 verbose=false
42 #chicken="echo (would)"
43
44 : ${TMPDIR=/tmp}
45 dsttmp=$TMPDIR/srclist.dst
46
47 # Source `dirname $0`/srclistvars.sh first, if it exists.
48 mydir=`dirname $0`
49 test -r $mydir/srclistvars.sh && . $mydir/srclistvars.sh
50
51
52\f
53 # sed command to fix the license to be GPL.
54 fixlicense='
55   /^[[:space:]]*#[[:space:]]*Th[ei][ s].* is free software/,/^[[:space:]]*#.*USA\./c\
56 #   This program is free software: you can redistribute it and/or modify\
57 #   it under the terms of the GNU General Public License as published by\
58 #   the Free Software Foundation; either version 3 of the License, or\
59 #   (at your option) any later version.\
60 #\
61 #   This program is distributed in the hope that it will be useful,\
62 #   but WITHOUT ANY WARRANTY; without even the implied warranty of\
63 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
64 #   GNU General Public License for more details.\
65 #\
66 #   You should have received a copy of the GNU General Public License\
67 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
68
69   /Th[ei][ s].* is free software/,/\*\//c\
70    This program is free software: you can redistribute it and/or modify\
71    it under the terms of the GNU General Public License as published by\
72    the Free Software Foundation; either version 3 of the License, or\
73    (at your option) any later version.\
74 \
75    This program is distributed in the hope that it will be useful,\
76    but WITHOUT ANY WARRANTY; without even the implied warranty of\
77    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
78    GNU General Public License for more details.\
79 \
80    You should have received a copy of the GNU General Public License\
81    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
82 '
83
84 # sed command to remove lines containing $Id lines.
85 # Quote the $ so that CVS does not expand it in this script.
86 remove_id_lines='/[$]Id:.*[$]/d'
87
88 # $1 is input file, $2 is output.
89 # Remove $Id lines, since they'll differ between source locations.
90 # If $options contains "gpl", change the license to be the standard
91 # GPL.  We use this for libc files, et al.
92 #
93 fixfile() \
94 {
95   sed_command="$remove_id_lines"
96
97   case " $options " in
98   *' gpl '*)
99     sed_command="$sed_command; $fixlicense";;
100
101   *' doclicense '*)
102     sed_command="$sed_command; s/@include doclicense.texi/@include fdl.texi/";;
103   esac
104
105   sed "$sed_command" $1 >$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 src was executable, make dst executable, to placate git.
137   test -x $src && chmod a+x $dst
138
139   if test ! -e $dst; then
140     echo "## $srctmp $dst  # new"
141     $chicken cp -p $srctmp $dst
142   elif cmp -s $srctmp $dsttmp; then
143     $verbose && echo "## $srctmp $dst  # unchanged"
144   else
145     echo "## $srctmp $dst  # changes"
146     diff -C 2 $dst $srctmp
147   fi
148 done
149
150 rm -f $dsttmp