#!/bin/sh

SELF="$( basename $0 )"

EES=ees
if [ "$SELF" = "getmaintreqs" ]; then
  REV=-r
  EES=encies
fi

if [ "$1" = "" -o "$1" = "--help" ]; then
  cat <<EOF
$SELF - get SlackBuild depend$EES by maintainer.

Usage: $SELF <maintainer>

<maintainer> must be a maintainer's name (not email address). It does
not need to be quoted, if it contains spaces (although it can be).
EOF
  exit 0
fi

# dependees maintained by the same maintainer are listed without
# name/email. only "external" dependees (ones maintained by someone else)
# have the name/email displayed.

source ~/sbostuff/sbostuff.sh

maint="$*"
builds="$( getmaintbuilds "$@" )"

for i in $builds; do
  set $( hoorex -m $REV $i )
  if [ "$2" ]; then
    echo -n "$1"
    shift
    echo -n ": "
    can_orphan=yes
    for j in "$@"; do
      echo -n "$j "
      cdsb $j
      source ./$j.info
      if [ "$MAINTAINER" != "$maint" -a "$EMAIL" != "NOEMAIL" ]; then
        can_orphan=no
        echo -n "('$MAINTAINER' $EMAIL)  "
      fi
    done
    echo
    [ "$can_orphan" = "yes" ] && orphanable+="$i "
  else
    orphanable+="$1 "
  fi
done

if [ "$orphanable" != "" ]; then
  echo "These have no depend$EES by other maintainers:"
  echo "$orphanable"
fi
