#!/bin/bash

function write_tags
{
   cd "$basedoc"

   echo '<tagfile>'

   for d in $docdirs
   do
      for f in $d/*.html
      do
         awk '
function compound( kind )
{
   if ( match( $0, /title="[^"]*"/) )
   {
      cl = substr($0, RSTART+7, RLENGTH-8);
      print "<compound kind=\"" kind "\" objc=\"yes\">" ;
      print "<name>" cl "</name>" ;
      print "<filename>" FILENAME "</filename>" ;
      print "</compound>"
   }
}

/<a name="\/\/apple_ref\/occ\/cl\// { compound( "class" ) }
/<a name="\/\/apple_ref\/occ\/cat\// { compound( "category" ) }
' $f

      done
   done

   echo '</tagfile>'
}

if [ $# -lt 3 ]
then
   echo "Usage $0 tagfile base dir [dir ...]"
   exit 1
fi

export tagfile=$1
shift
export basedoc=$1
shift
export docdirs=$*

echo -n > $tagfile
write_tags >> $tagfile
