Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/show.u

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/usr/local/plan9/bin/rc

. 9.rc

fn usage {
	echo 'usage: show [-a prefix] [-t] file yyyy/mmdd[n]' >[1=2]
	exit usage
}

filter=cat
aflag=''
if(~ $1 -a){
	shift
	aflag=$1
	shift
}

tflag=0
if(~ $1 -t){
	tflag=1
	shift
}


if(! ~ $#* 1 2)
	usage
if(~ $#* 2 && ! ~ $2 - [0-9][0-9][0-9][0-9]/[0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9]/[0-9][0-9][0-9][0-9][0-9])
	usage
if(~ $2 -)
	*=($1 9999/9999)

if(! test -f $1){
	echo 'no such file'
	exit no file
}
if(~ $#* 1){
	sed -n 's:^## diffname [^ ]* :show '^$1^' :p' $1
	if(~ $aflag '')
		exit 0
	*=($1 9999/9999)
	filter=catnull
}

fn catnull { cat >/dev/null }

y=`{echo $2 | tr / ' '}
awk -v 'y='^$y(1) -v 'd=x'^$y(2) -v 'aflag='$aflag -v 'tflag='$tflag ' 
	BEGIN { indiff=0; print "."; }
	END { if(indiff && aflag) print "w " aflag "." indiff; print "w"; }
	/^## diffname/ { 
		if(indiff && aflag)
			print "w " aflag "." indiff;
		indiff++;
		date = $4;
		split(date, a, "/");
		if(a[1] > y || (a[1] == y && "x"a[2] > d)){
			indiff = 0;
			exit;
		}
		next
	}
	/^## diff/ { next }
	{ 
		if(tflag && insert && $0 != ".")
			print date, $0;
		else
			print;
		if(!insert && /[ac]$/)
			insert=1;
		if(insert && $0==".")
			insert=0;
	}
' $1 |ed -o - | $filter

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.