#!/bin/sh
#
# $Is$
#
homeidl=$1
homesaxo=$2
homesrc=$3
version=$4
#
#############################################################
# create the file saxoidl.adp from idl.adp and idldoc-lib.adp
#############################################################
# create saxoidl.adp header
[ ! -f ${homeidl}/idl.adp ] && exit 1
[ ! -f ${homesaxo}/idldoc-lib.adp ] && exit 1
#
cat <<EOF > ${homesrc}/idl.adp
<!DOCTYPE DCF>  
<assistantconfig version="3.3.0">  
   <profile>  
      <property name="name">SAXO - IDL ${version} Help</property>  
      <property name="title">SAXO - IDL ${version} Help</property>  
      <property name="startpage">${homesrc}/home.html</property>  
      <property name="aboutmenutext">About SAXO</property>  
      <property name="abouturl">${homesrc}/aboutsaxo.txt</property>  
      <property name="assistantdocs">${homeidl}</property>  
   </profile>  
EOF
# extract part from </profile> to </assistantconfig>
# put the complete path of the references
# and put it at the end of idl.adp
sed -e '1,/<\/profile>/ d' \
    -e '/<\/assistantconfig>/,$ d' \
    -e "s?ref=\"?ref=\"${homeidl}/?g" \
    ${homeidl}/idl.adp  >> ${homesrc}/idl.adp

# extract part from </profile>
# put the complete path of the references
# and put it at the end of idl.adp
sed -e '1,/<\/profile>/ d' \
    -e "s?ref=\"?ref=\"${homesaxo}/?g" \
    ${homesaxo}/idldoc-lib.adp >> ${homesrc}/idl.adp

#############################################################
# create the file home.html from the one installed with IDL
#############################################################
[ ! -f ${homeidl}/home.html ] && exit 1
# put the complete path of the references 
sed -e "s?ref=\"?ref=\"${homeidl}/?g" \
    ${homeidl}/home.html > ${homesrc}/home.html
# add line for SAXO Directory after the first </h3>
cat << EOF > /tmp/toto$$
<a name="SAXOdir"> </a><p class="pIndentedRelative"><img src="images/blueball_idl.gif" id="blueballSAXOdir" border="0" hspace="0" vspace="0"/> &#160;&#160;<a href="${homesaxo}/home.html">SAXO Directory</a></p>
EOF
numline=$( grep -n '</h3>' ${homesrc}/home.html | head -1 | cut -b1-2 )
sed -e "${numline}r /tmp/toto$$" ${homesrc}/home.html > /tmp/toto2$$ 
mv -f /tmp/toto2$$ ${homesrc}/home.html
# add line for SAXO Home Page after the last </h3>
cat << EOF > /tmp/toto$$
<a name="SAXOweb"> </a><p class="pIndentedRelative"><img src="images/blueball_idl.gif" id="blueballSAXOweb" border="0" hspace="0" vspace="0"/> &#160;&#160;<a href="http://forge.ipsl.jussieu.fr/saxo">SAXO Home Page</a> </p>  
EOF
numline=$( grep -n '</h3>' ${homesrc}/home.html | tail -1 | cut -b1-2 )
sed -e "${numline}r /tmp/toto$$" ${homesrc}/home.html > /tmp/toto2$$ 
mv -f /tmp/toto2$$ ${homesrc}/home.html
# put the complete path of the images except for SAXOIDL_OnlineHelp_title.png
sed -e "s?src=\"?src=\"${homeidl}/?g" \
    -e "s?src=\".*IDL_OnlineHelp_Title\.gif\"?src=\"${homesaxo}/../xmldoc/images/SAXOIDL_OnlineHelp_title\.png\"?g" \
    ${homesrc}/home.html > /tmp/toto$$ 
mv -f /tmp/toto$$ ${homesrc}/home.html
#############################################################
# create the file aboutsaxo.txt from overview
#############################################################
[ ! -f ${homeidl}/home.html ] && exit 1
# remove the line with @ in the file overview
sed -e '/@/d' ${homesaxo}/../../overview > ${homesrc}/aboutsaxo.txt
# add a link to saxo page
cat <<EOF >> ${homesrc}/aboutsaxo.txt

More informations on 
http://forge.ipsl.jussieu.fr/saxo

EOF
