%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newlength{\desclen}
\newlength{\yearlen}
\newlength{\mmlen}

\newbox\livrable@box
\newbox\tmp@box

\let\specHasManual\relax
\let\specCsgManual\relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\eoa{end-of-args}
\def\@@novers#1-#2\eoa{#1}
\def\@novers#1{\ifx\relax#1\def\next{{\color{red}FIXME}}\else\def\next{\expandafter\@@novers#1\eoa}\fi\next}

\def\@hypertarget@cor{0pt}
\def\setMacroInAuxFile#1#2{%
%\mbox{}{\hypertarget{#1}{}\vspace{-1.0ex}}%
\hypertarget{#1}{}\gdef\@hypertarget@cor{1.5ex}%
\let\@novers\relax%
\global\expandafter\edef\csname NOLNK#1\endcsname{\name}%
\global\expandafter\edef\csname #1\endcsname{\noexpand\hyperlink{#1}{\name}}%
\global\expandafter\edef\csname NOVERS#1\endcsname{\noexpand\hyperlink{#1}{\@novers{\name}}}%
\global\expandafter\edef\csname NOVL#1\endcsname{\@novers{\name}}%
\immediate\write\@auxout{\expandafter\string\expandafter\gdef\expandafter\string\csname NOLNK#1\endcsname{\name}}%
\immediate\write\@auxout{\expandafter\string\expandafter\gdef\expandafter\string\csname #1\endcsname{\string\hyperlink{#1}{\name}}}%
\immediate\write\@auxout{\expandafter\string\expandafter\gdef\expandafter\string\csname NOVERS#1\endcsname{\string\hyperlink{#1}{\@novers{\name}}}}%
\immediate\write\@auxout{\expandafter\string\expandafter\gdef\expandafter\string\csname NOVL#1\endcsname{\@novers{\name}}}%
#2}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcount\supportercnt\supportercnt=1
\newwrite\supporter
\immediate\openout\supporter=anr-supporter.tex
\def\letterOfInterest#1#2{{%
  \let\subsection\relax%
  \let\label\relax%
  \let\begin\relax%
  \let\end\relax%
  \let\includegraphics\relax%
  \let\linewidth\relax%
  \let\newpage\relax%
  \immediate\write\supporter{%
    \subsection{#1} \label{supp:\the\supportercnt}}%
  \immediate\write\supporter{%
    \begin{center}\includegraphics[width=0.9\linewidth]{#2}\end{center}}%
    \newpage%
  }%
  #1 (page \pageref{supp:\the\supportercnt})%
  \advance\supportercnt1%
}
\def\letterOfInterestPlus#1{{%
  \let\begin\relax%
  \let\end\relax%
  \let\includegraphics\relax%
  \let\linewidth\relax%
  \let\newpage\relax%
  \immediate\write\supporter{%
    \begin{center}\includegraphics[width=0.9\linewidth]{#1}\end{center}}%
    \newpage%
  }%
}

\def\letterOfInterestNb{?}
\def\letterOfInterestClose{
  \advance\supportercnt-1
  \immediate\closeout\supporter
  \immediate\write\@auxout{%
    \string\gdef\string\letterOfInterestNb{\the\supportercnt}
  }
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\ganttlf\relax
\newwrite\ganttdata
\immediate\openout\ganttdata=anr.gantt
\def\write@ganttdata#1{{
    \let\xcoach\relax%
    \let\xcoachplus\relax%
    \let\irisa\relax    \let\Sirisa\relax%
    \let\lip\relax      \let\Slip\relax%
    \let\tima\relax     \let\Stima\relax%
    \let\ubs\relax      \let\Subs\relax%
    \let\upmc\relax     \let\Supmc\relax%
    \let\altera\relax   \let\Saltera\relax%
    \let\bull\relax     \let\Sbull\relax%
    \let\thales\relax   \let\Sthales\relax%
    \let\mds\relax      \let\Smds\relax%
    \let\xilinx\relax%
    \immediate\write\ganttdata{#1}
}}

\def\enable{enable}
\def\disable{disable}
\def\leader{leader}
\newenvironment{taskinfo}%
{%
\let\ALL\disable%
\let\IRISA\disable%
\let\LIP\disable%
\let\TIMA\disable%
\let\UBS\disable%
\let\UPMC\disable%
\let\BULL\disable%
\let\THALES\disable%
\let\MDS\disable%
}{%
\ifx\ALL\enable%
  \ifx\IRISA\disable\let\IRISA\enable\fi%
  \ifx\LIP\disable\let\LIP\enable\fi%
  \ifx\UPMC\disable\let\UPMC\enable\fi%
  \ifx\TIMA\disable\let\TIMA\enable\fi%
  \ifx\UBS\disable\let\UBS\enable\fi%
  \ifx\BULL\disable\let\BULL\enable\fi%
  \ifx\THALES\disable\let\THALES\enable\fi%
  \ifx\MDS\disable\let\MDS\enable\fi%
\fi%
\def\@leader{\begin{small}\textcolor{red}{lead.}\end{small}}
\def\@partner{\begin{small}\textcolor{blue}{part.}\end{small}}
\def\@IRISA{\ifx\IRISA\disable{}\else\ifx\IRISA\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@LIP{\ifx\LIP\disable{}\else\ifx\LIP\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@UPMC{\ifx\UPMC\disable{}\else\ifx\UPMC\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@TIMA{\ifx\TIMA\disable{}\else\ifx\TIMA\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@UBS{\ifx\UBS\disable{}\else\ifx\UBS\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@BULL{\ifx\BULL\disable{}\else\ifx\BULL\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@THALES{\ifx\THALES\disable{}\else\ifx\THALES\enable{\@partner}\else{\@leader}\fi\fi}%
\def\@MDS{\ifx\MDS\disable{}\else\ifx\MDS\enable{\@partner}\else{\@leader}\fi\fi}%
\begin{tabular}{|c|c|c|c|c|c|c|c|}\hline
\Sirisa  & \Slip  & \Stima  & \Subs  & \Supmc  & \Smds & \Sbull  & \Sthales \\\hline
\@IRISA  & \@LIP  & \@TIMA  & \@UBS  & \@UPMC  & \@MDS & \@BULL  & \@THALES \\\hline
\end{tabular}\par
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{objectif}%
{\begin{description}\item[Objectives]}
{\end{description}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcount\taskcnt\taskcnt=0
\newcount\subtaskcnt
\newcount\livrablecnt

 \def\@subtask#1{%
    \global\advance\subtaskcnt1
    \def\subtaskname{S\taskname-\the\subtaskcnt}%
    \write@ganttdata{STN=\the\taskcnt\space\the\subtaskcnt\space#1}%
    \item[\subtaskname: #1]%
    \IfFileExists{tmp/st\the\taskcnt-\the\subtaskcnt-partner.tex}%
      {(\input{tmp/st\the\taskcnt-\the\subtaskcnt-partner.tex})}%
      {\message{SKIPPING tmp/st\the\taskcnt-\the\subtaskcnt-partner.tex files}}%
    \mbox{}\\%
}

\newenvironment{workpackage}{%
    \global\advance\taskcnt1%
    \global\subtaskcnt0%
    \def\taskname{T\the\taskcnt}%
    \begin{description}%
    \let\subtask\@subtask%
}{ \end{description}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\writeganttinfo#1#2#3#4#5#6{%
    \write@ganttdata{%
      L=1 T=\the\taskcnt\space S=\the\subtaskcnt\space%
      D=\the\livrablecnt\space V=\vers\space%
      BM=#1 EM=#2 R=#3 PART={#4} KIND={#5} TITLE=#6%
    }%
}

\def\livrable@description@width{13.5cm}
\def\livrable@description@width{10.4cm}
\newif\if@livrable@firsttable@
\newif\if@livrable@table@MustBeOpened@
\newif\if@livrable@table@MustBeClosed@
\newif\if@livrable@table@MustBeClosed@after@
\let\librable@table@print@addon\relax
\def\livrable@table@begin{\begin{tabular}{|p{3.5em}|c|c|c|l|}\hline}
\def\livrable@table@line#1#2#3#4#5#6{
    \makebox[3.5em][c]{\begin{small}#1\end{small}} &
    \makebox[2.2em]{\begin{small}#2\end{small}} &
    \makebox[1.5em]{\begin{small}#3\end{small}} &
    \makebox[2.2em]{\begin{small}#4\end{small}} & 
    #5\\#6}
\def\livrable@table@end{\end{tabular}\\}
\def\livrable@print@table{%
    \if@livrable@table@MustBeOpened@%
        \livrable@table@begin%
        \global\@livrable@table@MustBeOpened@false%
    \fi%
    \if@livrable@firsttable@%
        \livrable@table@line{number}{date}{type}{resp.}{description}{\hline\hline}%
    \fi%
    \global\@livrable@firsttable@false%
    \livrable@table@line%
        {\textsc{\name}}%
        {\textsc{T0+\livrableEndDate}}%
        {\textsc{\livrableType}}%
        {\textsc{\livrableLeader}}%
        %{\mbox{\copy\livrable@box}}{\hline}%
        %{\raisebox{\@hypertarget@cor}[\ht\livrable@box][\ht\livrable@box]{\copy\livrable@box}\librable@table@print@addon\vspace*{1pt}}{\hline}%
        {\raisebox{\@hypertarget@cor}{\copy\livrable@box}\librable@table@print@addon\vspace*{1pt}}{\hline}%
%        {}{\cline{2-5}}%
%    %& \multicolumn{4}{l|}{\raisebox{\@hypertarget@cor}{\copy\livrable@box}}\\\hline%
%    & \multicolumn{4}{l|}{{\copy\livrable@box}}\\\hline%
    \if@livrable@table@MustBeClosed@%
        \livrable@table@end%
        \global\@livrable@table@MustBeOpened@true%
        \global\@livrable@table@MustBeClosed@false%
    \fi%
    \if@livrable@table@MustBeClosed@after@%
        \global\@livrable@table@MustBeClosed@true%
        \global\@livrable@table@MustBeClosed@after@false%
    \fi%
    \global\def\@hypertarget@cor{0pt}%
    \global\let\librable@table@print@addon\relax%
}

\def\@livrable@desc@box@start{%
  \begin{lrbox}{\livrable@box}\begin{minipage}[t]{\livrable@description@width}%
  \fontsize{11.0pt}{10pt}\selectfont%
  \let\ia@description\description%
  \def\description{\vspace*{-1.5ex}\ia@description\itemsep=1pt\topsep2pt\parskip0pt}%
  %\let\ia@enddescription\enddescription%
  %\newenvironment{description}{%
  %}{\ia@enddescription}%
}

\def\@livrable@desc@box@start@eatCR#1{\@livrable@desc@box@start#1}
%\def\tmp{
%}
%\def\eat{\message{AAAAAAAAAAAAA:EAT}\@livrable@desc@box@start}
%\if\noexpand\nexttok\tmp
%    \message{AAAAAAAAAAAAAAAAAAAAA:OUI}%
%    \def\cont{\eat}%
%\else%
%    \message{AAAAAAAAAAAAAAAAAAAAA:NON}%
%    \def\cont{\@livrable@desc@box@start}%
%\fi%
%\cont}


\def\@itemV@next#1#2#3#4#5{\livrable@print@table\@itemV@first{#1}{#2}{#3}{#4}{#5}}
\def\@itemV@first#1#2#3#4#5{%
    \def\vers{V\the\verscnt}%
    \global\edef\name{D\the\taskcnt\the\subtaskcnt\the\livrablecnt-\vers}%
    \global\def\librable@table@print@addon{\hypertarget{\name}{}}%
    \gdef\livrableEndDate{#2}%
    \gdef\livrableType{#3}%
    \gdef\livrableLeader{#4}%
    \def\itemV{\end{minipage}\end{lrbox}\global\advance\verscnt1\global\setbox\livrable@box=\copy\livrable@box\@itemV@next}%
    \def\itemL{\end{minipage}\end{lrbox}\global\advance\verscnt1\global\setbox\livrable@box=\copy\livrable@box\@itemL@next}%
    \writeganttinfo{#1}{#2}{none}{#4}{#3}{#5}%
    \futurelet\nexttok\@livrable@desc@box@start@eatCR%
}
% \parskip0pt \topsep0pt \parsep0pt \itemsep0pt \partopsep0pt

\def\@itemL@next#1#2#3#4#5#6{\global\@livrable@table@MustBeClosed@after@true\livrable@print@table\@itemL@first{#1}{#2}{#3}{#4}{#5}{#6}}
\def\@itemL@first#1#2#3#4#5#6{%
    \def\vers{VF}%
    \global\edef\name{D\the\taskcnt\the\subtaskcnt\the\livrablecnt-\vers}%
    \global\def\librable@table@print@addon{\hypertarget{\name}{}\hypertarget{\expandafter\@@novers\name\eoa}{}}%
    \gdef\livrableEndDate{#2}%
    \gdef\livrableType{#3}%
    \gdef\livrableLeader{#4}%
    \def\itemV{\end{minipage}\end{lrbox}\global\advance\livrablecnt1\global\verscnt1\global\setbox\livrable@box\copy\livrable@box\@itemV@next}%
    \def\itemL{\end{minipage}\end{lrbox}\global\advance\livrablecnt1\global\verscnt1\global\setbox\livrable@box\copy\livrable@box\@itemL@next}%
    \writeganttinfo{#1}{#2}{#6}{#4}{#3}{#5}%
    %\gdef\baselinestretch{2.50}XXX\\%
    \global\@livrable@table@MustBeClosed@true
    \futurelet\nexttok\@livrable@desc@box@start@eatCR%
}

\newenvironment{livrable}{%
 \newcount\verscnt\verscnt=1
 \livrablecnt0
 \def\livrableTableDef{\begin{tabular}{|p{3.5em}|c|c|c|p{.625\linewidth}|}\hline}
 \ifvmode \else\par\fi
\def\OtherPartner##1##2##3##4##5{{%
\let\xcoach\relax%
\let\xcoachplus\relax%
\let\irisa\relax\let\Sirisa\relax%
\let\lip\relax\let\Slip\relax%
\let\tima\relax\let\Stima\relax%
\let\ubs\relax\let\Subs\relax%
\let\upmc\relax\let\Supmc\relax%
\let\altera\relax\let\Saltera\relax%
\let\bull\relax\let\Sbull\relax%
\let\thales\relax\let\Sthales\relax%
\let\mds\relax\let\Smds\relax%
\immediate\write\ganttdata{%
  L=0 T=\the\taskcnt\space S=\the\subtaskcnt\space%
  D=\the\livrablecnt\space BM=##1 EM=##2 R=##4 PART={##3} TITLE=%
}%
}##5}
 \let\itemV\@itemV@first
 \let\itemL\@itemL@first
 \@livrable@firsttable@true
 \@livrable@table@MustBeOpened@true
 \@livrable@table@MustBeClosed@false
 \@livrable@table@MustBeClosed@after@false
 \def\@hypertarget@cor{0pt}
}{%
 \end{minipage}\end{lrbox}\global\setbox\livrable@box=\copy\livrable@box%
 \@livrable@table@MustBeClosed@true\livrable@print@table%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
