summaryrefslogtreecommitdiff
path: root/rc/bin/patch/diff
blob: 944b5231bfa2471b6edf75c80c34dcbe6141637b (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
#!/bin/rc
# patch/diff [-w] patch-name
rfork e
fn usage {
	echo 'usage: patch/diff [-bmnwz] patch-name' >[1=2]
	exit usage
}

dopts=(-c)
while (! ~ $#* 0 && ~ $1 -*) {
	switch ($1) {
	case -[bmnw]
		dopts=($dopts $1)
	case -z
		dopts=()
	case *
		usage
	}
	shift
}
if(! ~ $#* 1)
	usage

if(! test -d /n/sources/patch){
	rfork n
	9fs sources
}

if(! test -d /n/sources/patch/$1){
	echo 'no such patch' /n/sources/patch/$1 >[1=2]
	exit nopatch
}

builtin cd /n/sources/patch/$1 || exit nopatch
if(! patch/okay .){
	echo 'bad patch: '$status >[1=2]
	exit badpatch
}

d=/n/sources/patch/$1
fn xxx {
	echo $1
	diff $dopts $2.orig $d/$2 | sed 's/^/	/'
}
cat files | sed 's/^/xxx /' | rc