#!/bin/sh

if [ "$#" -eq 0 ]
then
  echo "Must supply path for postings files"
  exit 1
fi

target="$1"

target=${target%/}

osname=`uname -s | sed -e 's/_NT-.*$/_NT/; s/^MINGW[0-9]*/CYGWIN/'`
if [ "$osname" = "CYGWIN_NT" -a -x /bin/cygpath ]
then
  target=`cygpath -w "$target"`
fi

target=${target%/}

for fld in NORM STEM YEAR
do
  echo "$fld"
  find "." -name "*.mrg.gz" |
  sort |
  xargs -n 100 echo |
  while read files
  do
    rchive -promote "$target" "$fld" $files
  done
done
