#!/bin/sh

if [ $# -ne 0 ]; then
   DOCDIRS="$*"
elif [ -f wrapper.tex ]; then
   DOCDIRS="."
elif [ -f docdirs ]; then
   DOCDIRS=`cat docdirs`
else
   DOCDIRS=""
fi


for DIR in $DOCDIRS; do
   if [ -f $DIR/docdirs ]; then
   
     DOC_SUBDIRS=`cat $DIR/docdirs`
     
     rm -f $DIR/AllMains.tex
     rm -f $DIR/AllMains_ref.tex
     touch $DIR/AllMains.tex
     touch $DIR/AllMains_ref.tex
     for SUBDIR in ${DOC_SUBDIRS}; do 
        if [ $SUBDIR != "Title" -a $SUBDIR != "Preface" \
            -a $SUBDIR != "Bibliography" ]; then
          echo "\cgalColumnLayout" >> $DIR/AllMains.tex
          echo "\include{$SUBDIR/main}" >> $DIR/AllMains.tex
          echo "\cgalColumnLayout" >> $DIR/AllMains_ref.tex
          echo "\include{${SUBDIR}_ref/main}" >> $DIR/AllMains_ref.tex
        fi
     done
   fi
done




syntax highlighted by Code2HTML, v. 0.9.1