Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/makemail

Copyright © 2009 Alcatel-Lucent.
Distributed under the Lucent Public License version 1.02.
Download the Plan 9 distribution.


#!/bin/rc

rfork ne
ramfs
if(! test -f /bin/bincmp)
	bind -a /usr/rsc/bin/rc /bin
if(! test -f /bin/binhash)
	bind -a /usr/rsc/bin/$cputype /bin

cd /sys/lib/dist/changes
9fs sourcesdump
9fs sources
if(~ $#* 1 && ~ $1 now){
	*=(`{yesterday /n/sources/plan9 | sed 's;/plan9;;'} /n/sources)
}
switch($#*){
case 0
	y=`{date |awk '{print $NF}'}
	x=`{ls /n/sourcesdump/$y | tail -2}
	if(~ $#x 1){
		ly=`{echo $y^-1 | hoc}
		x=(`{ls /n/sourcesdump/$ly | tail -1} $x)
	}
	old=$x(1)
	new=$x(2)
case 2
	old=$1
	new=$2
}
# group changes to common files
fn group {
	switch($4){
	case sys/src/9/*
		echo kernel
	case sys/src/boot/*
		echo 9load
	case 386/*
		echo binaries
	case sys/man/*/*
		echo $4 | sed 's;sys/man/[0-9]+/;;'
	case sys/src/lib*/*
		echo $4 | sed 's;sys/src/;;; s;/.*;;'
	case sys/src/cmd/disk/prep/*
		echo $4 | sed 's;sys/src/cmd/disk/prep/;;; s;/.*;;; s;\.[cy]$;;'
	case sys/src/cmd/ip/*
		echo $4 | sed 's;sys/src/cmd/ip/;;; s;/.*;;; s;\.[cy]$;;'
	case sys/src/cmd/aux/*
		echo $4 | sed 's;sys/src/cmd/aux/;;; s;/.*;;; s;\.[cy]$;;'
	case sys/src/cmd/*/*
		echo $4 | sed 's;sys/src/cmd/;;; s;/.*;;'
	case sys/src/cmd/*
		echo $4 | sed 's;sys/src/cmd/;;; s;\.[cy]$;;'
	case sys/src/games/*/*
		echo $4 | sed 's;sys/src/games/;;; s;/.*;;'
	case sys/lib/kbmap/*
		echo kbmap
	case *
		echo $4
	} | tr '/' '_'	
}

fn summarize {
	# time n a|c|d|m name name mode uid gid mtime size
	switch($3){
	case c
		if(! ~ $4 $didsum){
			didsum=($didsum $4)
			switch($4){
			case 386/9load*
				;
			case 386/* */386/*
				bincmp $old/plan9/$4 $new/plan9/$4 | sed 's/^/	/'
			case *
				diff -c $old/plan9/$4 $new/plan9/$4 |
					sed 's!(^/.*) - !\1 - \
!' |
					sed 's/^/	/' >/tmp/a
				if(test `{wc -l </tmp/a} -gt 100){
					echo '	[diffs elided - too long]'>/tmp/a
					echo '	['diff -c $old/plan9/$4 $new/plan9/$4']' >>/tmp/a
				}
				cat /tmp/a
			}
		}
	}	
}

fn x {
	# time n a|c|d|m name name mode uid gid mtime size
	base=$1.$2
	echo '#' $*
	if(! test -f $base.sum)
		summarize $* >$base.sum
	grp=`{group $*}
	xbase=$base
	if(test -f grp.$grp && ! test -s $base.txt){
		xbase=`{cat grp.$grp}
		echo '@'$xbase >$base.txt
	}
	nnn=1
	while(test -s $xbase.txt && sed 1q $xbase.txt |grep -s '^@' && ! ~ $nnn 100){
		xbase=`{sed 1q $xbase.txt | sed 's/^@//'}
		nnn=`{echo 1+$nnn|hoc}
	}
	if(! test -f grp.$grp)
		echo $xbase >grp.$grp
	if(! test -s $xbase.txt){
		>$xbase.txt
	}
	# Header starts with annotations.
	if(! test -s $xbase.txt.0){
		if(test -s $xbase.txt){
			echo '#RSC# cat >/sys/lib/dist/changes/'$xbase.txt' << EOF' >$xbase.txt.0
			cat $xbase.txt >>$xbase.txt.0
			echo '#RSC# EOF' >>$xbase.txt.0
		}
		if not{
			{
				echo '% cat >/sys/lib/dist/changes/'$xbase.txt' << EOF'
				echo Your text here.
				echo EOF
			} >$xbase.txt.0
		}
	}
	# Next come the ls lines and change summaries.
	if(test -f $xbase.txt.1 && ! cmp -s $base.sum $xbase.txt.1){
		cat $xbase.txt.1 >>$xbase.txt.0
		rm $xbase.txt.1
	}
	echo '#RSC#' $base $* >>$xbase.txt.0
	@{cd $new/plan9; ls -lmd $4 | sed 's/^/ /'} >>$xbase.txt.0
	cp $base.sum $xbase.txt.1
}

rm -f *.sum
rm -f *.txt.[01] grp.* sum.all
whatis old new
diff $old/plan9/dist/replica/plan9.log $new/plan9/dist/replica/plan9.log | 
	sed -n 's/^> //p' | 
	sed '/^[0-9]+ [0-9]+ . (386\/(9pc|9load|init|bin\/|lib\/)|rc\/bin\/stock|acme\/bin\/386|sys\/games\/lib\/fortunes|lib\/face\/)/d' |
	sed 's; ;'' '';g; s;^;'';; s;$;'';; s;^;x ;' |
	rc

for(i in `{ls *.txt.0 >[2]/dev/null}){
	x=`{echo $i | sed 's/0$/1/'}
	if(test -s $x)
		cat $x >>$i
	echo >>$i
}

cat *.txt.0 >sum.all.local
if(grep -s '^% cat >' sum.all.local)
	echo NEED SOME FILES >>sum.all.local
echo ',s/\n\n\n+/\n\n/g
	w
	q' | sam -d sum.all.local >[2]/dev/null

grep -v '^#RSC#' sum.all.local >sum.all

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2009 Alcatel-Lucent. All Rights Reserved.
Comments to webmaster@plan9.bell-labs.com.