#! /usr/local/bin/bash

if test -z "$1"; then
  echo "call: $0 <filename>"
  exit
fi


filelist=$1

ml="kdeadmin kdebase kdegames kdegraphics kdelibs kdemultimedia kdenetwork kdenonbeta kdesdk kdesupport kdetoys kdeutils koffice kde-i18n kdepim kdeaddons kdeartwork kdeedu arts kdekiosk kdeaccessibility kdeextragear-libs-1 kdeextragear-1 kdeextragear-2 kdeextragear-3 kdevelop kdewebdev"

rm "$filelist"_* $filelist

: > $filelist

for dir in $ml; do 
  if test -x $dir; then
    subfile="$filelist"_$dir
    rm -f $subfile
    find $dir/ -name ".directory" -print >> $filelist
    find $dir/ -name "*.kdelnk" -print >> $filelist
    find $dir/ -name "*.desktop" -print >> $filelist
    find $dir/ -name "*.kimap" -print >> $filelist
    find $dir/ -name "*.themerc" -print >> $filelist
    find $dir/ -name "*.kcsrc" -print >> $filelist
    find $dir/ -name "*.setdlg" -print >> $filelist
    find $dir/ -name "index.theme" -print >> $filelist
    find $dir/ -name "eventsrc" -print >> $filelist
fi
done
find kdebase/applnk -name "*.directory" -print >> $filelist
find kdebase/konqueror -name "directory.*" -print >> $filelist
find kdebase/kdesktop -name "directory.*" -print >> $filelist 
find kdebase/drkonqi -name "*rc" -print >> $filelist
find kdelibs/kimgio -name *.kimgio -print >> $filelist
find kdemultimedia/noatun -name *.plugin -print >> $filelist
find kdeaddons/noatun-plugins -name *.plugin -print >> $filelist
cat kdegames/kolf/courses.list >> $filelist
find kdetoys/amor/data -name *rc -print >> $filelist
find kdelibs/kdeprint -name *.print -print >> $filelist
find kdebase -name *.kksrc -print >> $filelist
find kdenetwork/kopete -name *.plugin -print >> $filelist
find kdevelop -name *.kdevtemplate -print >> $filelist

sortedfile=`tempfile`
sort -u $filelist > $sortedfile && mv $sortedfile $filelist

for file in `cat $filelist`; do 
    mod=`echo $file | sed -e "s,^\([^/]*\)/.*,\1,"`
    subfile="$filelist"_$mod
    echo $file >> $subfile
done
