summaryrefslogtreecommitdiff
path: root/usr.bin/cleantags/cleantags.sh
blob: 30c6e88f8c413705dc690c3576e07e5a28aeed1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# $NetBSD: cleantags.sh,v 1.2 2011/12/25 23:31:22 christos Exp $
# Remove the $'s from rcs tags

PROG="$(basename "$0")"
PAT='\$(Author|Date|CVSHeader|Header|Id|LocalId|Locker|Log|Name|RCSfile|Revision|Source|State|NetBSD)'
verbose=false

dosed() {
	sed \
	    -e 's/\$\(Author.*\)\$/\1/' \
	    -e 's/\$\(Date.*\)\$/\1/' \
	    -e 's/\$\(CVSHeader.*\)\$/\1/' \
	    -e 's/\$\(Header.*\)\$/\1/' \
	    -e 's/\$\(Id.*\)\$/\1/' \
	    -e 's/\$\(LocalId.*\)\$/\1/' \
	    -e 's/\$\(Locker.*\)\$/\1/' \
	    -e 's/\$\(Log.*\)\$/\1/' \
	    -e 's/\$\(Name.*\)\$/\1/' \
	    -e 's/\$\(RCSfile.*\)\$/\1/' \
	    -e 's/\$\(Revision.*\)\$/\1/' \
	    -e 's/\$\(Source.*\)\$/\1/' \
	    -e 's/\$\(State.*\)\$/\1/' \
	    -e 's/\$\(NetBSD.*\)\$/\1/' \
	    "$1" > "/tmp/$PROG$$" && mv "/tmp/$PROG$$" "$1"
	if $verbose
	then
		echo "$1"
	fi
}

usage() {
	echo "Usage: $PROG [-v] <files>|<directories>" 1>&2
	exit 1
}

while getopts "v" f
do
	case "$f" in
	v)
		verbose=true;;
	*)
		usage;;
	esac
done

shift "$(expr "$OPTIND" - 1)"

if [ -z "$1" ]
then
	usage
fi

for i
do
	if [ -d "$i" ]
	then
		find "$i" -type f -print0 | xargs -0 egrep -l "$PAT" |
		while read f
		do
			dosed "$f"
		done
	elif egrep -qs "$PAT" "$i" 
	then
		dosed "$i"
	fi
done