#!/bin/sh
###############################################################################
#                                                                             #
#  TakTuk, a middleware for adaptive large scale parallel remote executions   #
#  deployment. Perl implementation, copyright(C) 2006 Guillaume Huard.        #
#                                                                             #
#  This program is free software; you can redistribute it and/or modify       #
#  it under the terms of the GNU General Public License as published by       #
#  the Free Software Foundation; either version 2 of the License, or          #
#  (at your option) any later version.                                        #
#                                                                             #
#  This program is distributed in the hope that it will be useful,            #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of             #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
#  GNU General Public License for more details.                               #
#                                                                             #
#  You should have received a copy of the GNU General Public License          #
#  along with this program; if not, write to the Free Software                #
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA #
#                                                                             #
#  Contact: Guillaume.Huard@imag.fr                                           #
#           ENSIMAG - Laboratoire ID                                          #
#           51 avenue Jean Kuntzmann                                          #
#           38330 Montbonnot Saint Martin                                     #
#                                                                             #
###############################################################################

TAKTUK="@abs_srcdir@/../taktuk"
TAKTUK_RELATIVE="@srcdir@/../../taktuk"
DIR="@abs_srcdir@"

flatten ()
  {
    read toto
    printf "%s" "$toto\\;"
    read toto
    while [ -n "$toto" ]
    do
      printf "%s" "$toto\\;"
      read toto
    done
    echo
  }
  
generate_local_hosts ()
  {
    HOSTS=""
    i=0
    if [ -n "$1" ]
    then
      while [ $i -lt "$1" ]
      do
        HOSTS="$HOSTS -m localhost"
        i=`expr $i + 1`
      done
    fi
    printf "%s\n" "$HOSTS"
  }

generate_local_chain ()
  {
    HOSTS=""
    SUFFIX=""
    i=0
    if [ -n "$1" ]
    then
      while [ $i -lt "$1" ]
      do
        HOSTS="$HOSTS -m localhost -[ "
        SUFFIX="exec [ echo salut ] -] $SUFFIX"
        i=`expr $i + 1`
      done
    fi
    printf "%s\n" "$HOSTS$SUFFIX"
  }

generate_hosts ()
  {
    if [ -n "$1" ]
    then
      generate_local_hosts $1
    elif [ -n "$OAR_NODEFILE" ]
    then
      printf "%s\n" "-f $OAR_NODEFILE"
    else
      printf "%s\n" \
         "Unable to find remote peers specification (are you using OAR ?)" >&2
      printf "%s\n" ""
    fi
  }
