#!/usr/bin/perl

# Please change the previous ligne with you perl location

######################################################################
# 
#      ManyPage : Moteur de Publication de site Web
#      ManyPage : Web site Management tools
#
#
# Auteur/Author       		: Pierre Cordani
# Collaborateur/Contributor	: Pascal Vuylsteker, MediaPort team
#
# Documentation : http://www.vrarchitect.net/ManyPage
# Question      : manypage@vuylsteker.net
#
# Creation      : 1/1/00
# Modification  : 1/12/00
# Version       : 0.9
# SoftVersion   : Perl 5
######################################################################
# 
# main.pl       : launching script
# help          : habille.pl -h
# 
# 
######################################################################
#
#  Copyright (C) 2000 Pierre Cordani - Pascal Vuylsteker
#
# 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.
#
# Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier conformŽment
# aux dispositions de la Licence Publique GŽnŽrale GNU, telle que publiŽe par la Free Software
# Foundation ; version 2 de la licence, ou encore (ˆ votre choix) toute version ultŽrieure.
#
###################

#
# Lancement du script d'habillage de facon a permettre un habillage parallele
#

$Autre_habillage = "autre_habillage";
$path = $0;
$path =~ s/(.*)\/.*/$1/;

#Cette partie a ete rajoute rapidement pour imposer l'habillage parallele
if($ARGV[0] =~ /^-(.*)/)
 {
  if(!($1 =~ /.*p.*/))
   {
    $ARGV[0] .= "p";
   }
 }
else
 {
  if($ARGV[0] ne "")
   {
    $ARGV[1] = "$ARGV[0] $ARGV[1]";
    $ARGV[0] = "-p";
   }
 }

if($ARGV[0] =~ /^(-.*)p(.*)/)
 {
  $ARGV[0] = $1.$2;
  if($ARGV[0] eq "-"){$ARGV[0] = ""}
  system ("$path/main.pl @ARGV\n");
  if($ARGV[0] eq ""){$ARGV[0] = "-p"}
  else {$ARGV[0] .= "p"}
  @Res = lecture_autre();
  if($ARGV[0] =~ /.*f.*/)
   {
    $ARGV[0] .= " $ARGV[1]";
   }
  else
   {
    $ARGV[2] = "$ARGV[1] $ARGV[2]";
   }
  local $i = 0;
  while($Res[$i] ne "")
   {
    $ARGV[1] = $Res[$i];
#	print "$Res[$i]\n";
    system ("$path/main.pl @ARGV\n");
	$i++;
   }
 }
else
 {
  system ("$path/main.pl @ARGV\n");
 }

sub lecture_autre
{
 local $a = 0;
 local @Total = ();
 $sauve = $/;
 undef $/;
 open (AUTRE,"$path/$Autre_habillage") or die ("fichier $path/$Autre_habillage impossible a ouvrir");
 local ($Tout) = <AUTRE>;
 local @Info = split(/<\/Autre_habillage>/,$Tout);
 local $i = 0;
 while($Info[$i])
  {
   $Info[$i] =~ s/\s*$//;
   if($Info[$i] ne "")
    { 
	 if($Info[$i] =~ /.*\s*<NOM>\s*(.*?)\s*<\/NOM>.*/)
	  {
	   $Nom = $1;
	  }
	 $Partie = "";
	 while($Info[$i] =~ /(.*)<PARTIE>\s*(.*?)\s*<\/PARTIE>(.*)/s)
	  {
	   $Partie .= "_SEPHAB_".$2 if($Partie ne "");
	   $Partie = $2 if($Partie eq "");
	   $Info[$i] = $1.$3;
	  }
	 $Not_partie = "";
	 while($Info[$i] =~ /(.*)<NOT_PARTIE>\s*(.*?)\s*<\/NOT_PARTIE>(.*)/s)
	  {
	   $Not_partie .= "_SEPHAB_".$2 if($Not_partie ne "");
	   $Not_partie = $2 if($Not_partie eq "");
	   $Info[$i] = $1.$3;
	  }
	 $Total[$a] = "$Nom $Partie"."_BIGSEPHAB_"."$Not_partie";
	 $a++;
	}
   $i++;
  }
 return @Total;
}
