Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/showdiff

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


#!/bin/rc

rfork e

flag=(-c)
tflag=()
rflag=no
if(~ $1 -a -b){
	flag=(-c $1)
	shift
}
if(~ $1 -r){
	rflag=yes
	shift
}
if(~ $1 -t){
	tflag=(-t)
	shift
}

if(! ~ $#* 1 2 3){
	echo 'usage: showdiff [-a] [-r] [-t] file [[date1] date2]' >[1=2]
	exit usage
}
if(! test -f $1){
	echo no file $1 >[1=2]
	exit nofile
}

# rundiff file1 file2 name date1 date2
fn rundiff {
	diff $flag $1 $2 | sed '
		s;'$1';'$4/sys/src/9/$3';
		s;'$2';'$5/sys/src/9/$3';
	'
}

tmp=/tmp/sd.$pid
fn sigexit { rm /tmp/sd.$pid.* }

switch($#*){
case 1
	if(~ $rflag yes)
		v=`{rc ./show -a $tmp $tflag $1 | awk '{print NR, $3}' | sort -r +1}
	if not
		v=`{rc ./show -a $tmp $tflag $1 | awk '{print NR, $3}'}
	first=yes
	file=$1
	*=($v)
	while(! ~ $#* 0){
		if(~ $first yes)
			first=no
		if not{
			if(~ $rflag yes)
				rundiff $tmp.$1 $tmp.$lastn $file $2 $lastdate
			if not
				rundiff $tmp.$lastn $tmp.$1 $file $lastdate $2
		}
		lastn=$1
		lastdate=$2
		shift
		shift
	}
case 2
	rc ./show -a $tmp $tflag $1 $2 >$tmp.x
	n=`{ls $tmp.[0-9]* | wc -l}
	n=`{echo -1+$n | hoc}
	date=`{rc ./show $tflag $1| sed -n $n^p | awk '{print $3}'}
	mv $tmp.$n $tmp.1
	mv $tmp.x $tmp.2
	rundiff $tmp.1 $tmp.2 $1 $date $2
case 3
	rc ./show $tflag $1 $2 >$tmp.1
	rc ./show $tflag $1 $3 >$tmp.2
	rundiff $tmp.1 $tmp.2 $1 $2 $3
}

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.