1#!/bin/rc 2 3rfork e 4 5if(! ~ $#* 1){ 6 echo 'usage: patch/apply patch-name' >[1=2] 7 exit usage 8} 9 10if(! test -d /n/sources/patch){ 11 rfork n 12 9fs sources 13} 14 15if(! test -d /n/sources/patch/$1){ 16 echo 'no such patch' /n/sources/patch/$1 >[1=2] 17 exit nopatch 18} 19 20builtin cd /n/sources/patch/$1 || exit nopatch 21if(! patch/okay .){ 22 echo 'bad patch: '$status >[1=2] 23 exit badpatch 24} 25 26if(! echo >.tmp || ! rm .tmp){ 27 echo no write permission >[1=2] 28 exit 'no write permission' 29} 30 31echo -n merge... >[1=2] 32fn xxx { 33 if(! test -f $1) 34 cp $2 $2.new 35 if not 36 ape/diff3 -m $1 $2.orig $2 >$2.new 37 if(grep -s '^<<<<' $2.new){ 38 echo conflicts merging $1';' see `{pwd}^/$2.new >[1=2] 39 40 touch failed 41 } 42} 43rm -f failed 44cat files | sed 's/^/xxx /' | rc 45if(test -f failed){ 46 echo exiting without changes >[1=2] 47 exit failed 48} 49 50echo -n backup... >[1=2] 51fn xxx { 52 # echo cp $1 $2.backup 53 cp $1 $2.backup 54} 55cat files | sed 's/^/xxx /' |rc 56 57echo -n copy... >[1=2] 58fn xxx { 59 # echo cp $2.new $1 60 cp $2.new $1 || touch failed 61} 62cat files | sed 's/^/xxx /' | rc 63 64fn xxx { 65 # echo cp $2.backup $1 66 cp $2.backup $1 67} 68 69if(test -f failed){ 70 echo copying failed, restoring backups >[1=2] 71 cat files | sed 's/^/xxx /' | rc 72 exit failed 73} 74 75echo >[1=2] 76 77echo to update sources: >[1=2] 78cat files | awk '{print " update " $1 }' >[1=2] 79 80