%include "Inc:UTIL.IMP"

%constinteger first part = 1, last part = 3

%routine do usage (%integer first part, last part)
   %bytename bm
   %integer s, l, i, which, j, total, total total, bitmap size
   %string(127) command = ""
   %byte x

   total total = 0
   %for which = first part, 1, last part %cycle
      connect file("$:BITMAP." . to string(which + '0'), 0, s, bitmap size)
      bm == byteinteger(s)
      total = 0
      %for i = 0, 1, bitmap size - 1 %cycle
         x = bm [i]
         %for j = 0, 1, 7 %cycle
            total = total + 1 %if x & 1 # 0
            x = x >> 1
         %repeat
      %repeat
      printstring("Partition ");  write(which, 0)
      printstring(" has ");  write(total, 0)
      printstring(" block");  printsymbol('s') %if total # 1
      printstring(" (")
      print(100 * total / (bitmap size << 3), 0, 2)
      printstring("%) used")
      newline
      total total = total total + total
   %repeat
   printstring("Grand total of ");  write(total total, 0)
   printstring(" blocks (")
   print(100 * total total / (8 * bitmap size * last part), 0, 2)
   printstring("%) used")
   newline
%end

%begin
   do usage(first part, last part)
%end %of %program
