#!/bin/csh -f
#
# sumpat - summarize a pattern as start,end,length for each portion
#
# We detect portions directly, not based on the portion markers in the
# pattern. Blank line inserted between processors.
#
# usage:
#   sumpat filename

if ($#argv != 1) then
	   echo usage: sumpat filename
	   exit 1
endif

# Output of extract is one line per chunk, with blank lines between
# processors. No marks for portion changes. Each line contains
#   R/W start length
# where R/W is either R or W, and start and length are in bytes.

extract $1 \
 | awk '\
    BEGIN {new=1}\
    NF == 0 {\
    	   if (new == 0)\
    	   	  	 print first,pos-1,pos-first;\
    	   new=1;\
    	   print "";\
    }\
    NF > 0 {\
    	   if (new) {\
    	   	  first = $2;\
    	   	  new = 0;\
    	   } else if ($2 != pos) {\
    	   	  	 print first,pos-1,pos-first;\
    	   	  	 first = $2;\
    	   }\
    	   pos = $2 + $3;\
    }'
