#!/bin/sh
# Copyright (C) 2007 Osamu Aoki <osamu@debian.org>
#
# This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of
# the GNU General Public License version 2 or later.
#

set -e
#<xsl:variable name="uletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !#$%()=-~^|\/+*,.?;:@`&quot;&apos;&amp;&gt;&lt;</xsl:variable>
#<xsl:variable name="lletters">abcdefghijklmnopqrstuvwxyzabcdefghij</xsl:variable>
packages=$1
bkups=$2
while read X ; do
  echo "process: $X" >&2
  PKG=$(echo $X |tr "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" "abcdefghijklmnopqrstuvwxyzabcdefghij"| \
                 tr -d " \!#\$%()=\-~^|\\/+*,.?;:@\`\"'&><")
  if SIZE=$(grep-dctrl -e -n --field=Package --show-field=Installed-Size  \
                    --pattern="^$(echo $X|sed -e 's/\+/\\+/g')\$" $packages ) ; then
    echo "<!ENTITY size-${PKG} \"${SIZE}\">"
  elif SIZE=$(grep-dctrl -e -n --field=Package --show-field=Installed-Size  \
                    --pattern="^$(echo $X|sed -e 's/\+/\\+/g')\$" $bkups ) ; then
    echo "<!ENTITY size-${PKG} \"${SIZE}(*)\">"
  else
    echo "<!ENTITY size-${PKG} \"NOT_FOUND\">"
    echo  "" >&2
    echo  "... ERROR ...: $X, probablly a removed or non-amd64 package." >&2
    echo  ".............:         See http://packages.qa.debian.org/common/index.html" >&2
  fi
done

echo $0 done >&2
#
#
# vim: set sts=2 ai expandtab:
