1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License, Version 1.0 only 7# (the "License"). You may not use this file except in compliance 8# with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or http://www.opensolaris.org/os/licensing. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23# 24# Copyright 2003 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27#ident "%Z%%M% %I% %E% SMI" 28# 29# Print sccs history of a file with 30# comment and differences for each delta. 31# 32# With the -r invocation style, only the deltas between the given sids are 33# printed. sccshist -r1.2 -r1.3, for example, prints the SID description for 34# 1.3, followed by the diffs between 1.2 and 1.3. The SID description for 1.2 35# is not printed. 36# 37# With the -n invocation style, deltas to a given number of SIDs are printed. 38# Given a file with 1.5, 1.4, ... 1.1, sccshist -n 2 will print the 1.5 SID 39# header, 1.4 -> 1.5 diffs, the 1.4 SID header, and 1.3 -> 1.4 diffs. 40# 41 42PROGNAME=$(basename "$0") 43 44SCCS=/usr/ccs/bin/sccs 45 46die() 47{ 48 echo "$PROGNAME: $@" >&2 49 exit 1 50} 51 52usage() 53{ 54 echo "Usage: $PROGNAME [-c|-u] [-r lowsid [-r highsid]] file" >&2 55 echo " $PROGNAME [-c|-u] [-n nsids] file" >&2 56 exit 2 57} 58 59lowsid= 60highsid= 61typeset -i nsids=0 62diffflags= 63 64while getopts "cn:r:u" c ; do 65 case $c in 66 c|u) 67 [[ -n "$diffflags" ]] && usage 68 diffflags="-$c" 69 ;; 70 n) 71 expr "X$OPTARG" : 'X[0-9]*$' >/dev/null || usage 72 nsids="$OPTARG" 73 ;; 74 r) 75 if [[ -n "$highsid" ]] ; then 76 usage 77 elif [[ -n "$lowsid" ]] ; then 78 highsid="$OPTARG" 79 else 80 lowsid="$OPTARG" 81 fi 82 ;; 83 *) 84 usage 85 ;; 86 esac 87done 88shift $(($OPTIND - 1)) 89 90[[ -n "$lowsid" && $nsids -ne 0 ]] && usage 91[[ $# -ne 1 ]] && usage 92 93FILE=$1 94 95[[ -r "$FILE" ]] || die "failed to open $FILE" 96 97tmpf1=/tmp/sid1.$$ 98tmpf2=/tmp/sid2.$$ 99trap "rm -f $tmpf1 $tmpf2 ; exit" 0 1 2 3 15 100 101# 102# The main processing loop. A new SID triggers a printing of the diffs between 103# the new SID and the last one. If there is no previous SID (if we're looking 104# at the first one), no diff is printed. 105# 106if [[ -z "$highsid" ]] ; then 107 printing=1 108else 109 printing=0 110fi 111 112typeset -i last=0 113typeset -i count=0 114 115$SCCS prt $FILE | while read LINE ; do 116 set - $LINE 117 118 if [[ $printing -eq 0 ]] ; then 119 if [[ "$2" = "$highsid" ]] ; then 120 printing=1 121 else 122 continue 123 fi 124 fi 125 126 if [[ $1 != "D" ]] ; then 127 echo "$LINE" 128 continue 129 fi 130 131 # We calculate `last' before printing the diff, and defer breaking out 132 # of the loop until after the diff, because we want to act upon the 133 # value during the diff. 134 [[ -n "$lowsid" && $printing -eq 1 && "$2" = "$lowsid" ]] && last=1 135 if [[ "$nsids" -ne 0 ]] ; then 136 count=$(($count + 1)) 137 [[ $count -gt $nsids ]] && last=1 138 fi 139 140 $SCCS get -s -p -k -r$2 $FILE > $tmpf1 141 if [[ -r $tmpf2 ]] ; then 142 diff -wt $diffflags $tmpf1 $tmpf2 143 if [[ $last -eq 0 ]] ; then 144 echo "________________________________________________________" 145 fi 146 fi 147 mv $tmpf1 $tmpf2 148 149 [[ $last -eq 1 ]] && break 150 151 echo "$LINE" # The new SID delta line 152done 153