#!/bin/sh -e
# -*- mode: Shell-script; tab-width: 8; fill-column: 70; -*-

PROG="${0##*/}"
#this path should match %docs_modules_prefix macro expansion
docs_modules_prefix="/usr/share/doc/alt-docs/modules"

Fatal() {
  printf "$PROG: Warning: %s\n" "$*" >&2
  exit 1
}

if [ $# -gt 0 ]; then
	arg="$*"
else
	arg=
fi

MODULES="`sed -ne 's,^.* href="adt:\([^" ]\+\)".*$,\1,ip' $arg `"

requires=
# we must replace . with - in ModuleID to get a package name
# we also need modules without commiter_id
for n in $MODULES; do
    # Check for common error:
    echo "$n" | grep -q '\.$' && Fatal "error \"$n\""
    # Spaces will break build, it's normal. Correct html links not contain spaces
	if  echo "$n" | grep -q '\.'
	then
			NAME=${n%.*}
			AUTHOR=${n##*.}
			requires="$requires docs-$NAME-$AUTHOR"
	else
			NAME=$n
			requires="$requires docs-$NAME"
	fi
done

[ -n "$requires" ] || exit 0
 
echo "Requires:$requires"
