#!/bin/bash
#
# vpd_dump - dump the contents of VPD
#
# This is merely a wrapper around vpdRead, taking the same arguments. Examples:
#   vpd_dump
#   vpd_dump -size 1000
#   vpd_dump -offset 6a0 -size 20

function ascii_from_hex {
  for x
  do
    declare -i n=0x$x
    if [ $n -gt 31 -a $n -lt 127 ]
    then
      printf "%b" `printf "\\%o" $n`
    else
      printf "."
    fi
  done
}

SKIP_ON="*"

/fabos/share/vpdRead $* | sed '/embeddedVpdRead/d' |
while read ADR B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 Ba Bb Bc Bd Be Bf
do
  BYTES="$B0 $B1 $B2 $B3 $B4 $B5 $B6 $B7 $B8 $B9 $Ba $Bb $Bc $Bd $Be $Bf"
  if [ "$BYTES" != "$PREV" ]
  then
    SKIP=
    ASCII=`ascii_from_hex $BYTES`
    echo "$ADR $BYTES $ASCII"
  elif [ "$SKIP" != "$SKIP_ON" ]
  then
    SKIP=$SKIP_ON
    echo "$SKIP"
  fi
  PREV="$BYTES"
done
