Develop and Download Open Source Software

Browse CVS Repository

Contents of /geeklogjp/tools/cleanup-cvs-id.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (as text) (vendor branch)
Sat Sep 23 16:32:24 2006 UTC (17 years, 6 months ago) by taca
Branch: MAIN, geeklogjp
CVS Tags: tools-base, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/x-sh
Importing miscellaneous tools.  Currently only cleanup-cvs-id script
which replace CVS(RCS) keywords.

toolsディレクトリをインポートします。今のところ、clean-cvs-idスクリプトを
含んでいるだけです。

(日本語のコミット・メッセージのテストも兼ねています。)


1 #!/bin/sh
2 # $Id$
3
4 # Copyright (C) 2006
5 # Takahiro Kambe. All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. Neither the name of me nor the names of its contributors
17 # may be used to endorse or promote products derived from this software
18 # without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
31
32 #
33 # This shell sciprt replace CVS(RCS) keyword strings to expanded string.
34 # For example, "Id" should be replaced as below:
35 #
36 # Id: foo.pl,v 1.10 2006/09/23 15:13:05 taca Exp
37 #
38 # And add empty "Id" keyword string to first part of files according to
39 # their types.
40 #
41 # referring to NetBSD's /usr/src/dist/file/file2netbsd script.
42 #
43
44 myname=`basename $0 .sh`
45 tmp1=/tmp/${myname}.1.$$
46 tmp2=/tmp/${myname}.2.$$
47 verbose=
48
49 trap "rm -f ${tmp1} ${tmp2}" 0 1 3 15
50
51 log() {
52 if [ "${verbose}" = 1 ]; then
53 echo $@
54 fi
55 }
56
57 move() {
58 src=$1
59 dst=$2
60
61 touch -r ${dst} ${src}
62 mv ${src} ${dst}
63 }
64
65 move_if_change() {
66 src=$1
67 dst=$2
68
69 if cmp -s ${src} ${dst}; then
70 :
71 else
72 move ${src} ${dst}
73 log "Adding Id to ${dst}"
74 fi
75 }
76
77 usage() {
78 echo "Usage: `basename $0 .sh` [-hv] directory"
79 }
80
81 strip_rcsid() {
82 dir=$1
83 out=$2
84
85 rm -f ${out}
86 find ${dir} -type f \! -name '*.bat' \! -name '*.BAT' -print | \
87 xargs egrep -l '\$(Id|Date|Header|Log|Revision)' | \
88 while read f; do
89 sed -e 's/\$\(Id:\) \(.*\) \$/\1 \2/' \
90 -e 's/\$\(Date:\): \(.*\) \$/\1 \2/' \
91 -e 's/\$\(Header:\): \(.*\) \$/\1 \2/' \
92 -e 's/\$\(Log:\) \(.*\) \$/\1 \2/' \
93 -e 's/\$\(Revision:\) \(.*\) \$/\1 \2/' \
94 $f > ${tmp1} && move ${tmp1} $f &&
95 (echo $f >> ${out}; log "removed RCS tag from $f")
96 done
97 rm -f ${tmp1}
98 }
99
100 add_id() {
101 list=$1
102
103 while read f; do
104 case "$f" in
105 *.bat|*.BAT)
106 cp -p $f ${tmp1};;
107 *.[chly]|*.css) sed -e '1{/$Id/!{i\
108 /* $Id$ */\
109
110 };}' $f > ${tmp1} && move_if_change ${tmp1} $f
111 ;;
112 *) awk '
113 NR == 1 { first=$1 }
114 NR == 2 {
115 if (first == "<!--") {
116 print " $" "Id" "$"
117 } else if (first == "<?php") {
118 print ""
119 print "// $" "Id" "$"
120 }
121 }
122 { print }' $f > ${tmp1}
123 ;;
124 esac
125 move_if_change ${tmp1} $f
126 done < ${list}
127
128 }
129
130 while getopts hv f
131 do
132 case $f in
133 h|\?) usage
134 exit 0;;
135 v) verbose=1;;
136 esac
137 done
138 shift `expr $OPTIND - 1`
139 if [ $# -gt 0 ]; then
140 dir=$1
141 else
142 usage
143 exit 1
144 fi
145
146 strip_rcsid ${dir} ${tmp2}
147 add_id ${tmp2}

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26