#!/bin/sh

echo "  Rebuilding locale stuff for $1"

LIST=/tmp/$$.list
TMP=/tmp/$$.tmp

# Find all files that contains the locale project id and
# dump them into the LIST temp file.
for a in `grep -cr '"'$1'"'		   \
  	    ../base_server		   \
  	    ../bin			   \
  	    ../config_interface		   \
  	    ../etc			   \
  	    ../modules			   \
  	    ../more_modules		   \
  	    ../protocols		   \
  	    ../site_templates		   \
  	    ../tools			   \
         |grep -v ':0'|sed -e 's/:.*//'|   \
         grep -v '#'|grep -v '~'` ;  do
  echo "  <file>$a</file>" >> $LIST
done

# Sort the LIST file. Add a header and a footer and
# create another temp file TMP with the result.
grep -v '<file>' $2 | grep -v '</project>' > $TMP
cat $LIST | sort >> $TMP
echo "</project>" >> $TMP

# Replace the old configuration file.
if mv $2 $2~ ; then 
  if cp $TMP $2 ; then
    rm $TMP
  else
    echo "Cannot copy $TMP to $2!"
    mv $2~ $2
  fi
else
  echo "Cannot move $2 out of the way!"
fi
 